From c677189452d5f4c492445b2bb55e1b54b45e8771 Mon Sep 17 00:00:00 2001 From: J-D-K Date: Wed, 1 Oct 2025 20:08:31 -0400 Subject: [PATCH] Add FadeIn on boot, change FileOptionState transition type, UI tweaks. --- Text/compress_text.py | 31 +++++++-------- include/JSON.hpp | 52 -------------------------- include/appstates/DataLoadingState.hpp | 3 ++ source/JKSV.cpp | 1 + source/appstates/DataLoadingState.cpp | 2 + source/appstates/FileOptionState.cpp | 49 +++++++++++++----------- source/appstates/ProgressState.cpp | 4 +- source/keyboard.cpp | 7 +++- 8 files changed, 54 insertions(+), 95 deletions(-) delete mode 100644 include/JSON.hpp diff --git a/Text/compress_text.py b/Text/compress_text.py index a9a2a2b..d525e61 100644 --- a/Text/compress_text.py +++ b/Text/compress_text.py @@ -6,7 +6,7 @@ import os import sys import shutil -def main(): +def main() -> int: # This is run from the makefile. All paths must be relative to it, not the script. inputDir: str = "./Text/Files" outputDir: str = "./romfs/Text" @@ -18,27 +18,22 @@ def main(): for entry in os.listdir(inputDir): - inputPath: str = f"{inputDir}/{entry}"; + inputPath: str = f"{inputDir}/{entry}" inputSize: int = os.path.getsize(inputPath) - inputFile: object = open(file=inputPath, mode="rb") - if inputFile.closed: - print(f"Error opening {inputPath} for reading!") - continue + with open(file=inputPath, mode="rb") as inputFile: - inputBuffer: bytes = inputFile.read(inputSize) - outputBuffer: bytes = zlib.compress(inputBuffer, 9) + inputBuffer: bytes = inputFile.read() + outputBuffer: bytes = zlib.compress(inputBuffer, 9) - outputPath: str = f"{outputDir}/{entry}.z" - outputFile: object = open(file=outputPath, mode="wb") - if outputFile.closed: - print("Error opening {outputPath} for writing!") - continue + outputPath: str = f"{outputDir}/{entry}.z" + with open(file=outputPath, mode="wb") as outputFile: - inputSizeBytes: bytes = inputSize.to_bytes(4, byteorder="little") - outputSizeBytes: bytes = len(outputBuffer).to_bytes(4, byteorder="little") - outputFile.write(inputSizeBytes) - outputFile.write(outputSizeBytes) - outputFile.write(outputBuffer) + inputSizeBytes: bytes = inputSize.to_bytes(4, byteorder="little") + outputSizeBytes: bytes = len(outputBuffer).to_bytes(4, byteorder="little") + + outputFile.write(inputSizeBytes) + outputFile.write(outputSizeBytes) + outputFile.write(outputBuffer) return 0 diff --git a/include/JSON.hpp b/include/JSON.hpp deleted file mode 100644 index 588f036..0000000 --- a/include/JSON.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once -#include -#include -#include - -namespace json -{ - // Use this instead of default json_object - using Object = std::unique_ptr; - - // Use this instead of json_object_from_x. Pass the function and its arguments instead. - template - static inline json::Object new_object(json_object *(*function)(Args...), Args... args) - { - return json::Object((*function)(args...), json_object_put); - } - - /// @brief Inline wrapper function for getting a json object by it's key. - /// @param json json::Object to get the key from. - /// @param key Key to get. - /// @return json_object on success. NULL on failure. - static inline json_object *get_object(json::Object &json, std::string_view key) - { - return json_object_object_get(json.get(), key.data()); - } - - /// @brief Inline wrapper function to add an object to a json_object - /// @param json Json object to add an object to. - /// @param key Key of the object. - /// @param object Object to add to json. - /// @return True on success. False on failure. - static inline bool add_object(json::Object &json, std::string_view key, json_object *object) - { - return json_object_object_add(json.get(), key.data(), object) == 0; - } - - /// @brief Returns the json string. - static inline const char *get_string(json::Object &json) { return json_object_get_string(json.get()); } - - /// @brief Returns the length of the string. I find json_object_get_string_len is unreliable? - static inline int64_t length(json::Object &json) - { - const char *string = json_object_get_string(json.get()); - return std::char_traits::length(string); - } - - /// @brief Returns the beginning for iterating. - static inline json_object_iterator iter_begin(json::Object &json) { return json_object_iter_begin(json.get()); } - - /// @brief Returns the end for iterating. - static inline json_object_iterator iter_end(json::Object &json) { return json_object_iter_end(json.get()); } -} // namespace json diff --git a/include/appstates/DataLoadingState.hpp b/include/appstates/DataLoadingState.hpp index e7d6857..50aa706 100644 --- a/include/appstates/DataLoadingState.hpp +++ b/include/appstates/DataLoadingState.hpp @@ -40,6 +40,9 @@ class DataLoadingState final : public BaseTask /// @brief Update override. void update() override; + /// @brief Updates the loading glyph. + void sub_update() override; + /// @brief Render override. void render() override; diff --git a/source/JKSV.cpp b/source/JKSV.cpp index f862b43..5860cf2 100644 --- a/source/JKSV.cpp +++ b/source/JKSV.cpp @@ -84,6 +84,7 @@ JKSV::JKSV() sys::threadpool::initialize(); data::launch_initialization(false, finish_initialization); + FadeState::create_and_push(colors::BLACK, 0xFF, 0x00, nullptr); sm_isRunning = true; } diff --git a/source/appstates/DataLoadingState.cpp b/source/appstates/DataLoadingState.cpp index 71a3ad5..dbfadff 100644 --- a/source/appstates/DataLoadingState.cpp +++ b/source/appstates/DataLoadingState.cpp @@ -27,6 +27,8 @@ void DataLoadingState::update() m_context.process_icon_queue(); } +void DataLoadingState::sub_update() { BaseTask::update_loading_glyph(); } + void DataLoadingState::render() { static constexpr int ICON_X_COORD = SCREEN_CENTER - 128; diff --git a/source/appstates/FileOptionState.cpp b/source/appstates/FileOptionState.cpp index c57f4a4..156314f 100644 --- a/source/appstates/FileOptionState.cpp +++ b/source/appstates/FileOptionState.cpp @@ -30,6 +30,10 @@ namespace PROPERTIES, CLOSE }; + + constexpr int LEFT_X = 200; + constexpr int RIGHT_X = 840; + constexpr int TOP_Y = 218; } // Defined at bottom. @@ -38,7 +42,7 @@ static std::string get_size_string(int64_t totalSize); FileOptionState::FileOptionState(FileModeState *spawningState) : m_spawningState(spawningState) , m_target(spawningState->m_target) - , m_transition(m_target ? 1280 : -240, 218, 0, 0, m_target ? 840 : 200, 218, 0, 0, 4) + , m_transition(m_target ? RIGHT_X : LEFT_X, 232, 32, 32, m_target ? RIGHT_X : LEFT_X, 232, 256, 256, 4) , m_dataStruct(std::make_shared()) { FileOptionState::initialize_static_members(); @@ -48,13 +52,16 @@ FileOptionState::FileOptionState(FileModeState *spawningState) void FileOptionState::update() { m_transition.update(); - if (!m_transition.in_place()) - { - const int x = m_transition.get_x(); - sm_dialog->set_x(x); - sm_copyMenu->set_x(x + 9); - return; - } + const int width = m_transition.get_width(); + const int height = m_transition.get_height(); + int x = m_transition.get_x(); + x += 128 - (width / 2); + int y = m_transition.get_centered_y(); + sm_dialog->set_x(x); + sm_dialog->set_y(y); + sm_dialog->set_width(width); + sm_dialog->set_height(height); + if (!m_transition.in_place()) { return; } const bool hasFocus = BaseState::has_focus(); if (m_updateSource) @@ -92,8 +99,9 @@ void FileOptionState::update() void FileOptionState::render() { const bool hasFocus = BaseState::has_focus(); - sm_dialog->render(sdl::Texture::Null, hasFocus); + if (!m_transition.in_place()) { return; } + sm_copyMenu->render(sdl::Texture::Null, hasFocus); } @@ -105,15 +113,15 @@ void FileOptionState::initialize_static_members() { if (sm_copyMenu && sm_dialog) { - const int x = m_transition.get_x(); - - sm_dialog->set_x(x); + const int x = m_transition.get_x(); + const int dialogX = x + (128 - 16); + sm_dialog->set_x(dialogX); sm_copyMenu->set_x(x + 9); return; } - sm_copyMenu = ui::Menu::create(1280, 236, 234, 20, 720); // High target height is a workaround. - sm_dialog = ui::DialogBox::create(1280, 218, 256, 256); + sm_copyMenu = ui::Menu::create(m_target ? RIGHT_X + 9 : LEFT_X + 9, 253, 234, 20, 720); // Target height is a workaround. + sm_dialog = ui::DialogBox::create(2000, 1000, 32, 32); // Create this off screen at first. // This never changes, so... for (int i = 0; const char *menuOption = strings::get_by_name(strings::names::FILEOPTION_MENU, i); i++) @@ -331,9 +339,7 @@ void FileOptionState::get_show_target_properties() const bool isDir = fslib::directory_exists(targetPath); if (isDir) { FileOptionState::get_show_directory_properties(targetPath); } - else { - FileOptionState::get_show_file_properties(targetPath); - } + else { FileOptionState::get_show_file_properties(targetPath); } } void FileOptionState::get_show_directory_properties(const fslib::Path &path) @@ -403,9 +409,9 @@ void FileOptionState::pop_system_error() void FileOptionState::close() { - m_close = true; - const int targetX = m_target ? 1280 : -240; - m_transition.set_target_x(targetX); + m_close = true; + m_transition.set_target_width(32); + m_transition.set_target_height(32); } bool FileOptionState::is_closed() { return m_close && m_transition.in_place(); } @@ -434,7 +440,8 @@ static std::string get_size_string(int64_t totalSize) const double kilobytes = static_cast(totalSize) / static_cast(THRESHOLD_BYTES); sizeString = stringutil::get_formatted_string("%.02f KB", kilobytes); } - else { + else + { const double megabytes = static_cast(totalSize) / static_cast(THRESHOLD_KB); sizeString = stringutil::get_formatted_string("%.02f MB", megabytes); } diff --git a/source/appstates/ProgressState.cpp b/source/appstates/ProgressState.cpp index 4a8e054..646838b 100644 --- a/source/appstates/ProgressState.cpp +++ b/source/appstates/ProgressState.cpp @@ -12,13 +12,13 @@ namespace { - constexpr int COORD_BAR_X = 312; + constexpr int COORD_BAR_X = 296; constexpr int COORD_BAR_Y = 437; constexpr int COORD_TEXT_Y = 442; constexpr int COORD_DISPLAY_CENTER = 640; - constexpr double SIZE_BAR_WIDTH = 656.0f; + constexpr double SIZE_BAR_WIDTH = 688.0f; } ProgressState::ProgressState(sys::threadpool::JobFunction function, sys::Task::TaskData taskData) diff --git a/source/keyboard.cpp b/source/keyboard.cpp index 4442fb5..a50aed7 100644 --- a/source/keyboard.cpp +++ b/source/keyboard.cpp @@ -10,8 +10,11 @@ bool keyboard::get_input(SwkbdType keyboardType, char *stringOut, size_t stringLength) { - SwkbdConfig keyboard; - swkbdCreate(&keyboard, 0); + SwkbdConfig keyboard{}; + + const bool createError = error::libnx(swkbdCreate(&keyboard, 0)); + if (createError) { return false; } + swkbdConfigSetBlurBackground(&keyboard, true); swkbdConfigSetInitialText(&keyboard, defaultText.data()); swkbdConfigSetHeaderText(&keyboard, header.data());