diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index b84da0f..2f9d37a 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,48 +1,29 @@ { "configurations": [ { - "name": "DKP Aarch64 Windows", - "includePath": [ - "C:/devkitPro/devkitA64/aarch64-none-elf/include/**", - "C:/devkitPro/devkitA64/lib/gcc/aarch64-none-elf/8.3.0/include/**", - "C:/devkitPro/libnx/include/**", - "C:/devkitPro/portlibs/switch/include/**", - "C:/devkitPro/portlibs/switch/include/freetype2/**", - "${workspaceFolder}/include/**", - "${workspaceFolder}/libs/libtesla/include/**" - ], - "defines": [ - "SWITCH", - "__SWITCH__", - "__aarch64__" - ], - "compilerPath": "C:/devkitPro/devkitA64/bin/aarch64-none-elf-g++", - "cStandard": "c11", - "cppStandard": "c++17", - "intelliSenseMode": "gcc-x64" - }, - { - "name": "DKP Aarch64 Linux", - "includePath": [ - "/opt/devkitpro/devkitA64/aarch64-none-elf/include/**", - "/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/8.3.0/include/**", - "/opt/devkitpro/libnx/include/**", - "/opt/devkitpro/portlibs/switch/include/**", - "/opt/devkitpro/portlibs/switch/include/**", - "/opt/devkitpro/portlibs/switch/include/freetype2/**", - "${workspaceFolder}/include/**", - "${workspaceFolder}/libs/libtesla/include/**" - ], - "defines": [ - "SWITCH", - "__SWITCH__", - "__aarch64__" - ], - "compilerPath": "/opt/devkitpro/devkitA64/bin/aarch64-none-elf-g++", - "cStandard": "c11", - "cppStandard": "c++17", - "intelliSenseMode": "gcc-x64" + "name": "Switch", + "includePath": [ + "${devkitA64}/aarch64-none-elf/include/**", + "${devkitA64}/lib/gcc/aarch64-none-elf/8.3.0/include/**", + "${devkitpro}/libnx/include/**", + "${devkitpro}/portlibs/switch/include/*", + "${workspaceFolder}/libs/libtesla/include/**" + ], + "defines": [ + "UNICODE", + "_UNICODE", + "__aarch64__", + "__SWITCH__", + "HAVE_LIBNX", + "EXPERIMENTAL", + "DEBUG" + ], + "windowsSdkVersion": "10.0.17763.0", + "compilerPath": "${devkitA64}/bin/aarch64-none-elf-gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-x64" } ], "version": 4 -} +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index c01940e..7f87d11 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,57 +1,84 @@ -{ - "files.associations": { - "chrono": "cpp", - "string_view": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp", - "codecvt": "cpp", - "condition_variable": "cpp", - "iomanip": "cpp", - "mutex": "cpp" - } +{ + "files.associations": { + "new": "cpp", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "fitz.h": "c", + "list": "cpp", + "textures.h": "c", + "sdl_helper.h": "c", + "common.hpp": "c", + "chrono": "cpp", + "codecvt": "cpp", + "ctime": "cpp", + "ratio": "cpp", + "common.h": "c", + "sdl.h": "c", + "bitset": "c", + "cfenv": "c", + "charconv": "c", + "complex": "c", + "condition_variable": "c", + "csetjmp": "c", + "csignal": "c", + "cuchar": "c", + "forward_list": "c", + "unordered_set": "c", + "map": "c", + "regex": "c", + "set": "c", + "future": "c", + "iomanip": "c", + "mutex": "c", + "scoped_allocator": "c", + "shared_mutex": "c", + "thread": "c", + "typeindex": "c", + "valarray": "c", + "status_bar.h": "c", + "sdl_ttf.h": "c", + "sdl_image.h": "c" + } } \ No newline at end of file diff --git a/Makefile b/Makefile index 22af345..896bcae 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,15 @@ SOURCES := source DATA := data INCLUDES := include libs/libtesla/include +VERSION_MAJOR := 0 +VERSION_MINOR := 1 +VERSION_MICRO := 0 + +APP_TITLE := Time Travel Overlay +APP_AUTHOR := SeanOMik +APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}-beta NO_ICON := 1 +#ICON := icon.jpg #--------------------------------------------------------------------------------- # options for code generation diff --git a/README.md b/README.md index f57f076..d05f607 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ -# Tesla-Template -A template repository for Tesla Overlay Homebrews +# Time Travel Overlay +A Time travel overlay for nx-ovlloader. Mainly made for Animal Crossing - New Horizons. + +## State: +Currently it just crashes the switch when you try to go forward a day, not sure how to fix it. \ No newline at end of file diff --git a/libs/libtesla b/libs/libtesla new file mode 160000 index 0000000..ca0b465 --- /dev/null +++ b/libs/libtesla @@ -0,0 +1 @@ +Subproject commit ca0b4657dc340839fae3a98923be9d3fbd67bf4f diff --git a/source/elm_button.hpp b/source/elm_button.hpp new file mode 100644 index 0000000..c3c40ba --- /dev/null +++ b/source/elm_button.hpp @@ -0,0 +1,42 @@ +#pragma once +#include + +class Button : public tsl::elm::Element { +public: + inline Button(u16 x, u16 y, u16 w, u16 h, const std::string &txt, std::function click_action) : Element(), m_text(txt), m_onClick(click_action), x(x), y(y), width(w), height(h) { } + inline Button(const std::string &txt, std::function cb) : Element(), m_text(txt), m_onClick(cb), x(this->getX()), y(this->getY()), width(this->getWidth()), height(tsl::style::ListItemDefaultHeight) { } + + inline virtual ~Button() {} + + inline tsl::elm::Element* requestFocus(tsl::elm::Element *oldFocus, tsl::FocusDirection direction) override { + return this; + } + + inline virtual void draw(tsl::gfx::Renderer *renderer) override { + this->renderer = renderer; + + renderer->drawRect(this->getX(), this->getY(), this->getWidth(), 1, a({ 0x5, 0x5, 0x5, 0xF })); + renderer->drawRect(this->getX(), this->getY() + this->getHeight(), this->getWidth(), 1, a({ 0x5, 0x5, 0x5, 0xF })); + + renderer->drawString(this->m_text.c_str(), false, this->getX() + 20, this->getY() + 45, 23, a({ 0xF, 0xF, 0xF, 0xF })); + } + + inline void layout(u16 parentX, u16 parentY, u16 parentWidth, u16 parentHeight) override { + + } + + inline virtual bool onClick(u64 keys) override { + return m_onClick(keys, *this); + } + + + tsl::gfx::Renderer *renderer; +private: + u16 x; + u16 y; + u16 width; + u16 height; + + std::string m_text; + std::function m_onClick; +}; \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 3b7f313..a470c41 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,49 +1,87 @@ #define TESLA_INIT_IMPL // If you have more than one file using the tesla header, only define this in the main one #include // The Tesla Header -class GuiTest : public tsl::Gui { +#include + +#include "elm_button.hpp" + +Result rc; + +class TimeTravelGui : public tsl::Gui { public: - GuiTest(u8 arg1, u8 arg2, bool arg3) { } + TimeTravelGui() { } // Called when this Gui gets loaded to create the UI // Allocate all your elements on the heap. libtesla will make sure to clean them up when not needed anymore virtual tsl::elm::Element* createUI() override { - auto rootFrame = new tsl::elm::OverlayFrame("Tesla Template", "v1.1.0"); + auto rootFrame = new tsl::elm::OverlayFrame("Time Travel", "v0.1.0-beta"); auto list = new tsl::elm::List(); - list->addItem(new tsl::elm::ListItem("Test List Item")); - list->addItem(new tsl::elm::ToggleListItem("Test Toggle List Item", true)); + if (R_FAILED(rc)) { + printf("setInitialize() failed: 0x%x.\n", rc); + + // If we failed to initialize, display the error. + list->addItem(new tsl::elm::ListItem("Failed to initialize! (0x" + std::to_string(rc) + ")")); + } + + u64 current_time; + if (R_SUCCEEDED(rc)) { + // Set system time + rc = timeGetCurrentTime(TimeType_Default, ¤t_time); + + // If we failed to get the time, display the error. + if (R_FAILED(rc)) { + printf("timeGetCurrentTime() failed: 0x%x.\n", rc); + + list->addItem(new tsl::elm::ListItem("Failed get current time! (0x" + std::to_string(rc) + ")")); + } else { // Only add the +1 day button if it got time correctly. + list->addItem(new Button("+1 Day", [=](u64 keys, Button btn)->bool { + if (keys & KEY_A) { + u64 day_ahead_time = current_time + 86400; // Add one day (in seconds) to the current time + rc = timeSetCurrentTime(TimeType_Default, current_time); + + if (R_SUCCEEDED(rc)) { + list->addItem(new tsl::elm::ListItem("Added 1 day!")); + } else { + printf("timeSetCurrentTime() failed: 0x%x.\n", rc); + + // If we failed to set time, display the error. + list->addItem(new tsl::elm::ListItem("Failed to set time! (0x" + std::to_string(rc) + ")")); + } + + return true; + } + + return false; + }), tsl::style::ListItemDefaultHeight); + } + } rootFrame->setContent(list); return rootFrame; } - - // Called once every frame to update values - virtual void update() override { - - } - - // Called once every frame to handle inputs not handled by other UI elements - virtual bool handleInput(u64 keysDown, u64 keysHeld, touchPosition touchInput, JoystickPosition leftJoyStick, JoystickPosition rightJoyStick) override { - return false; // Return true here to singal the inputs have been consumed - } }; -class OverlayTest : public tsl::Overlay { +class TimeTravelOverlay : public tsl::Overlay { public: // libtesla already initialized fs, hid, pl, pmdmnt, hid:sys, set:sys and the SD card - virtual void initServices() override {} // Called at the start to initialize all services necessary for this Overlay - virtual void exitServices() override {} // Callet at the end to clean up all services previously initialized + virtual void initServices() override { // Called at the start to initialize all services necessary for this Overlay + consoleInit(NULL); + timeInitialize(); - virtual void onShow() override {} // Called before overlay wants to change from invisible to visible state - virtual void onHide() override {} // Called before overlay wants to change from visible to invisible state + rc = setInitialize(); + } + + virtual void exitServices() override { // Called at the end to clean up all services previously initialized + timeExit(); + } virtual std::unique_ptr loadInitialGui() override { - return initially(1, 2, true); // Initial Gui to load. It's possible to pass arguments to it's constructor like this + return initially(); // Initial Gui to load. It's possible to pass arguments to it's constructor like this } }; int main(int argc, char **argv) { - return tsl::loop(argc, argv); + return tsl::loop(argc, argv); }