mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-09-07 18:16:00 -05:00
Initial commit. Needs debugging.
This commit is contained in:
126
source/JKSV.cpp
126
source/JKSV.cpp
@@ -11,8 +11,8 @@
|
||||
#include "error.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "input.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "remote/remote.hpp"
|
||||
#include "sdl.hpp"
|
||||
@@ -46,9 +46,9 @@ namespace
|
||||
|
||||
// This function allows any service init to be logged with its name without repeating the code.
|
||||
template <typename... Args>
|
||||
static bool initialize_service(Result (*function)(Args...), const char *serviceName, Args... args)
|
||||
static bool initialize_service(Result (*function)(Args...), const char *serviceName, Args &&...args)
|
||||
{
|
||||
Result error = (*function)(args...);
|
||||
Result error = (*function)(std::forward<Args>(args)...);
|
||||
if (R_FAILED(error))
|
||||
{
|
||||
logger::log("Error initializing %s: 0x%X.", serviceName, error);
|
||||
@@ -60,7 +60,15 @@ static bool initialize_service(Result (*function)(Args...), const char *serviceN
|
||||
// ---- Construction ----
|
||||
|
||||
JKSV::JKSV()
|
||||
: m_sdl2()
|
||||
, m_window(graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT)
|
||||
, m_renderer(m_window)
|
||||
, m_audio()
|
||||
, m_input()
|
||||
{
|
||||
// Ensure SDL initialized correctly. If not, return.
|
||||
if (!m_sdl2.is_initialized() || !m_window.is_initialized() || !m_renderer.is_initialized()) { return; }
|
||||
|
||||
// Set boost mode first.
|
||||
JKSV::set_boost_mode();
|
||||
|
||||
@@ -78,7 +86,6 @@ JKSV::JKSV()
|
||||
ABORT_ON_FAILURE(curl::initialize());
|
||||
|
||||
// Config and input.
|
||||
input::initialize();
|
||||
config::initialize();
|
||||
|
||||
// These are the strings used in the UI.
|
||||
@@ -94,8 +101,8 @@ JKSV::JKSV()
|
||||
sys::threadpool::push_job(remote::initialize, nullptr);
|
||||
|
||||
// Launch the loading init. Finish init is called afterwards.
|
||||
auto init_finish = []() { MainMenuState::create_and_push(); }; // Lambda that's exec'd after state is finished.
|
||||
data::launch_initialization(false, init_finish);
|
||||
auto init_finish = [&]() { MainMenuState::create_and_push(m_renderer); }; // Lambda that's exec'd after state is finished.
|
||||
data::launch_initialization(false, m_renderer, init_finish);
|
||||
|
||||
// This isn't required, but why not?
|
||||
FadeState::create_and_push(colors::BLACK, 0xFF, 0x00, nullptr);
|
||||
@@ -115,8 +122,6 @@ JKSV::~JKSV()
|
||||
config::save();
|
||||
curl::exit();
|
||||
JKSV::exit_services();
|
||||
sdl::text::SystemFont::exit();
|
||||
sdl::exit();
|
||||
|
||||
appletSetCpuBoostMode(ApmCpuBoostMode_Normal);
|
||||
appletUnlockExit();
|
||||
@@ -128,25 +133,35 @@ bool JKSV::is_running() const noexcept { return sm_isRunning && appletMainLoop()
|
||||
|
||||
void JKSV::update()
|
||||
{
|
||||
input::update();
|
||||
// Update the input instance.
|
||||
m_input.update();
|
||||
|
||||
const bool plusPressed = input::button_pressed(HidNpadButton_Plus);
|
||||
// Check if we should close.
|
||||
const bool plusPressed = m_input.button_pressed(HidNpadButton_Plus);
|
||||
const bool isClosable = StateManager::back_is_closable();
|
||||
if (plusPressed && isClosable) { sm_isRunning = false; }
|
||||
|
||||
StateManager::update();
|
||||
// Update states and pop-ups.
|
||||
StateManager::update(m_input);
|
||||
ui::PopMessageManager::update();
|
||||
}
|
||||
|
||||
void JKSV::render()
|
||||
{
|
||||
sdl::frame_begin(colors::CLEAR_COLOR);
|
||||
// Set target to frame buffer and clear.
|
||||
m_renderer.frame_begin(colors::CLEAR_COLOR);
|
||||
|
||||
// Render the base.
|
||||
JKSV::render_base();
|
||||
StateManager::render();
|
||||
ui::PopMessageManager::render();
|
||||
|
||||
sdl::frame_end();
|
||||
// Render the states.
|
||||
StateManager::render(m_renderer);
|
||||
|
||||
// Render pop-ups.
|
||||
ui::PopMessageManager::render(m_renderer);
|
||||
|
||||
// Present to screen.
|
||||
m_renderer.frame_end();
|
||||
}
|
||||
|
||||
void JKSV::request_quit() noexcept { sm_isRunning = false; }
|
||||
@@ -188,18 +203,39 @@ bool JKSV::initialize_services()
|
||||
|
||||
bool JKSV::initialize_sdl()
|
||||
{
|
||||
// Initialize SDL, freetype and the system font.
|
||||
bool sdlInit = sdl::initialize("JKSV", graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT);
|
||||
sdlInit = sdlInit && sdl::text::SystemFont::initialize();
|
||||
if (!sdlInit) { return false; }
|
||||
// These are for loading the header icon.
|
||||
static constexpr std::string_view HEADER_PATH = "romfs:/Textures/HeaderIcon.png";
|
||||
|
||||
// These are our breakpoints for wrapping lines.
|
||||
static constexpr std::array<uint32_t, 7> BREAKPOINTS = {L' ', L' ', L'/', L'_', L'-', L'。', L'、'};
|
||||
|
||||
// These are our color changing points.
|
||||
static constexpr std::array<std::pair<uint32_t, SDL_Color>, 7> COLOR_POINTS = {{{L'#', colors::BLUE},
|
||||
{L'*', colors::DARK_RED},
|
||||
{L'<', colors::YELLOW},
|
||||
{L'>', colors::GREEN},
|
||||
{L'`', colors::BLUE_GREEN},
|
||||
{L'^', colors::PINK},
|
||||
{L'$', colors::GOLD}}};
|
||||
|
||||
// Ensure SDL2 textures and sounds are ready to use.
|
||||
sdl2::Texture::initialize(m_renderer);
|
||||
sdl2::Sound::initialize(m_audio);
|
||||
|
||||
// Register break and color points.
|
||||
sdl2::Font::add_break_points(BREAKPOINTS);
|
||||
sdl2::Font::add_color_points(COLOR_POINTS);
|
||||
|
||||
// Load our fonts.
|
||||
m_titleFont = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::THIRTY_FOUR_PIXEL,
|
||||
graphics::fonts::sizes::THIRTY_FOUR_PIXEL);
|
||||
m_buildFont = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::FOURTEEN_PIXEL,
|
||||
graphics::fonts::sizes::FOURTEEN_PIXEL);
|
||||
|
||||
// Load the icon in the top left.
|
||||
m_headerIcon = sdl::TextureManager::load("headerIcon", "romfs:/Textures/HeaderIcon.png");
|
||||
m_headerIcon = sdl2::TextureManager::create_load_resource(HEADER_PATH, HEADER_PATH);
|
||||
if (!m_headerIcon) { return false; }
|
||||
|
||||
// Push the color changing characters.
|
||||
JKSV::add_color_chars();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -220,17 +256,6 @@ bool JKSV::create_directories()
|
||||
return true;
|
||||
}
|
||||
|
||||
void JKSV::add_color_chars()
|
||||
{
|
||||
sdl::text::add_color_character(L'#', colors::BLUE);
|
||||
sdl::text::add_color_character(L'*', colors::DARK_RED);
|
||||
sdl::text::add_color_character(L'<', colors::YELLOW);
|
||||
sdl::text::add_color_character(L'>', colors::GREEN);
|
||||
sdl::text::add_color_character(L'`', colors::BLUE_GREEN);
|
||||
sdl::text::add_color_character(L'^', colors::PINK);
|
||||
sdl::text::add_color_character(L'$', colors::GOLD);
|
||||
}
|
||||
|
||||
void JKSV::setup_translation_info_strings()
|
||||
{
|
||||
const char *translationFormat = strings::get_by_name(strings::names::TRANSLATION, 0);
|
||||
@@ -269,43 +294,32 @@ void JKSV::render_base()
|
||||
static constexpr int HEADER_Y = 27;
|
||||
|
||||
// Coordinates for the title text.
|
||||
static constexpr int TITLE_X = 130;
|
||||
static constexpr int TITLE_Y = 32;
|
||||
static constexpr int TITLE_SIZE = 34;
|
||||
static constexpr int TITLE_X = 130;
|
||||
static constexpr int TITLE_Y = 32;
|
||||
|
||||
// Coordinates for the translation info and build date.
|
||||
static constexpr int BUILD_X = 8;
|
||||
static constexpr int BUILD_Y = 700;
|
||||
static constexpr int TRANS_Y = 680;
|
||||
static constexpr int BUILD_SIZE = 14;
|
||||
static constexpr int BUILD_X = 8;
|
||||
static constexpr int BUILD_Y = 700;
|
||||
static constexpr int TRANS_Y = 680;
|
||||
|
||||
// This is just the JKSV string.
|
||||
static constexpr std::string_view TITLE_TEXT = "JKSV";
|
||||
|
||||
// Top and bottom framing lines.
|
||||
sdl::render_line(sdl::Texture::Null, LINE_X_BEGIN, LINE_A_Y, LINE_X_END, LINE_A_Y, colors::WHITE);
|
||||
sdl::render_line(sdl::Texture::Null, LINE_X_BEGIN, LINE_B_Y, LINE_X_END, LINE_B_Y, colors::WHITE);
|
||||
m_renderer.render_line(LINE_X_BEGIN, LINE_A_Y, LINE_X_END, LINE_A_Y, colors::WHITE);
|
||||
m_renderer.render_line(LINE_X_BEGIN, LINE_B_Y, LINE_X_END, LINE_B_Y, colors::WHITE);
|
||||
|
||||
// Icon
|
||||
m_headerIcon->render(sdl::Texture::Null, HEADER_X, HEADER_Y);
|
||||
m_headerIcon->render(HEADER_X, HEADER_Y);
|
||||
|
||||
// "JKSV"
|
||||
sdl::text::render(sdl::Texture::Null, TITLE_X, TITLE_Y, TITLE_SIZE, sdl::text::NO_WRAP, colors::WHITE, TITLE_TEXT);
|
||||
m_titleFont->render_text(TITLE_X, TITLE_Y, colors::WHITE, TITLE_TEXT);
|
||||
|
||||
// Translation info in bottom left.
|
||||
if (m_showTranslationInfo)
|
||||
{
|
||||
sdl::text::render(sdl::Texture::Null,
|
||||
BUILD_X,
|
||||
TRANS_Y,
|
||||
BUILD_SIZE,
|
||||
sdl::text::NO_WRAP,
|
||||
colors::WHITE,
|
||||
m_translationInfo);
|
||||
}
|
||||
if (m_showTranslationInfo) { m_buildFont->render_text(BUILD_X, TRANS_Y, colors::WHITE, m_translationInfo); }
|
||||
|
||||
// Build date
|
||||
sdl::text::render(sdl::Texture::Null, BUILD_X, BUILD_Y, BUILD_SIZE, sdl::text::NO_WRAP, colors::WHITE, m_buildString);
|
||||
m_buildFont->render_text(BUILD_X, BUILD_Y, colors::WHITE, m_buildString);
|
||||
}
|
||||
|
||||
void JKSV::exit_services()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "StateManager.hpp"
|
||||
|
||||
void StateManager::update()
|
||||
void StateManager::update(const sdl2::Input &input)
|
||||
{
|
||||
// Grab the instance.
|
||||
StateManager &instance = StateManager::get_instance();
|
||||
@@ -10,7 +10,7 @@ void StateManager::update()
|
||||
|
||||
{
|
||||
auto &back = stateVector.back();
|
||||
if (back->is_active() && back->has_focus()) { back->update(); }
|
||||
if (back->is_active() && back->has_focus()) { back->update(input); }
|
||||
}
|
||||
|
||||
// Purge uneeded states.
|
||||
@@ -39,12 +39,12 @@ void StateManager::update()
|
||||
}
|
||||
}
|
||||
|
||||
void StateManager::render() noexcept
|
||||
void StateManager::render(sdl2::Renderer &renderer) noexcept
|
||||
{
|
||||
StateManager &instance = StateManager::get_instance();
|
||||
auto &stateVector = instance.m_stateVector;
|
||||
|
||||
for (std::shared_ptr<BaseState> &state : stateVector) { state->render(); }
|
||||
for (std::shared_ptr<BaseState> &state : stateVector) { state->render(renderer); }
|
||||
}
|
||||
|
||||
bool StateManager::back_is_closable() noexcept
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
#include "error.hpp"
|
||||
#include "fs/fs.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "keyboard/keyboard.hpp"
|
||||
#include "sdl.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
@@ -43,13 +44,13 @@ BackupMenuState::BackupMenuState(data::User *user, data::TitleInfo *titleInfo, c
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void BackupMenuState::update()
|
||||
void BackupMenuState::update(const sdl2::Input &input)
|
||||
{
|
||||
// Grab focus once and only once.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
// Update the panel first.
|
||||
sm_slidePanel->update(hasFocus);
|
||||
sm_slidePanel->update(input, hasFocus);
|
||||
|
||||
// Grab these.
|
||||
const bool isOpen = sm_slidePanel->is_open();
|
||||
@@ -67,11 +68,11 @@ void BackupMenuState::update()
|
||||
}
|
||||
|
||||
// Input bools.
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input::button_pressed(HidNpadButton_X);
|
||||
const bool yPressed = input::button_pressed(HidNpadButton_Y);
|
||||
const bool zrPressed = input::button_pressed(HidNpadButton_ZR);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input.button_pressed(HidNpadButton_B);
|
||||
const bool yPressed = input.button_pressed(HidNpadButton_Y);
|
||||
const bool zrPressed = input.button_pressed(HidNpadButton_ZR);
|
||||
|
||||
// Conditions.
|
||||
const bool newSelected = selected == 0;
|
||||
@@ -82,7 +83,7 @@ void BackupMenuState::update()
|
||||
const bool uploadBackup = zrPressed && !newSelected;
|
||||
const bool popEmpty = aPressed && !m_saveHasData;
|
||||
|
||||
if (newBackup) { BackupMenuState::name_and_create_backup(); }
|
||||
if (newBackup) { BackupMenuState::name_and_create_backup(input); }
|
||||
else if (overwriteBackup) { BackupMenuState::confirm_overwrite(); }
|
||||
else if (restoreBackup) { BackupMenuState::confirm_restore(); }
|
||||
else if (deleteBackup) { BackupMenuState::confirm_delete(); }
|
||||
@@ -93,10 +94,10 @@ void BackupMenuState::update()
|
||||
|
||||
// Lock and update the menu.
|
||||
std::lock_guard menuGuard{sm_menuMutex};
|
||||
sm_backupMenu->update(hasFocus);
|
||||
sm_backupMenu->update(input, hasFocus);
|
||||
}
|
||||
|
||||
void BackupMenuState::render()
|
||||
void BackupMenuState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Line render coords.
|
||||
static constexpr int LINE_X = 10;
|
||||
@@ -106,32 +107,37 @@ void BackupMenuState::render()
|
||||
static constexpr int CONTROL_X = 32;
|
||||
static constexpr int CONTROL_Y = 673;
|
||||
|
||||
// Clear the render target.
|
||||
sm_slidePanel->clear_target();
|
||||
|
||||
// Grab whether or not the state has focus and the render target for the panel.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
sdl::SharedTexture &target = sm_slidePanel->get_target();
|
||||
|
||||
// Render the top, bottom lines. Control guide string.
|
||||
sdl::render_line(target, LINE_X, LINE_A_Y, sm_panelWidth - LINE_X, LINE_A_Y, colors::WHITE);
|
||||
sdl::render_line(target, LINE_X, LINE_B_Y, sm_panelWidth - LINE_X, LINE_B_Y, colors::WHITE);
|
||||
sdl::text::render(target, CONTROL_X, CONTROL_Y, 22, sdl::text::NO_WRAP, colors::WHITE, m_controlGuide);
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
// This is the target for the menu so it can't render outside of the lines above.
|
||||
sm_menuRenderTarget->clear(colors::TRANSPARENT);
|
||||
|
||||
// Lock and render the menu.
|
||||
{
|
||||
std::lock_guard menuGuard{sm_menuMutex};
|
||||
sm_backupMenu->render(sm_menuRenderTarget, hasFocus);
|
||||
graphics::ScopedRender menuRender{renderer, sm_menuRenderTarget};
|
||||
renderer.frame_begin(colors::TRANSPARENT);
|
||||
|
||||
// Lock and render the menu.
|
||||
{
|
||||
std::lock_guard menuGuard{sm_menuMutex};
|
||||
sm_backupMenu->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
// Get target and change target.
|
||||
{
|
||||
graphics::ScopedRender slideRender{renderer, sm_slidePanel->get_target()};
|
||||
renderer.frame_begin(colors::SLIDE_PANEL_CLEAR);
|
||||
|
||||
// Render the top, bottom lines. Control guide string.
|
||||
renderer.render_line(LINE_X, LINE_A_Y, sm_panelWidth - LINE_X, LINE_A_Y, colors::WHITE);
|
||||
renderer.render_line(LINE_X, LINE_B_Y, sm_panelWidth - LINE_X, LINE_B_Y, colors::WHITE);
|
||||
sm_font->render_text(CONTROL_X, CONTROL_Y, colors::WHITE, m_controlGuide);
|
||||
|
||||
// Render the menu target to the slide panel target.
|
||||
sm_menuRenderTarget->render(0, 43);
|
||||
}
|
||||
}
|
||||
|
||||
// Render the menu target to the slide panel target.
|
||||
sm_menuRenderTarget->render(target, 0, 43);
|
||||
|
||||
// Finally, render the target to the screen.
|
||||
sm_slidePanel->render(sdl::Texture::Null, hasFocus);
|
||||
sm_slidePanel->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
void BackupMenuState::refresh()
|
||||
@@ -196,12 +202,18 @@ void BackupMenuState::save_data_written()
|
||||
|
||||
void BackupMenuState::initialize_static_members()
|
||||
{
|
||||
if (sm_backupMenu && sm_slidePanel && sm_menuRenderTarget && sm_panelWidth) { return; }
|
||||
// Name of the render target for the backup menu.
|
||||
static constexpr std::string_view BACKUP_TARGET = "BackupMenuTarget";
|
||||
|
||||
sm_panelWidth = sdl::text::get_width(22, m_controlGuide) + 64;
|
||||
sm_backupMenu = ui::Menu::create(8, 8, sm_panelWidth - 16, 22, 600);
|
||||
sm_slidePanel = ui::SlideOutPanel::create(sm_panelWidth, ui::SlideOutPanel::Side::Right);
|
||||
sm_menuRenderTarget = sdl::TextureManager::load("backupMenuTarget", sm_panelWidth, 600, SDL_TEXTUREACCESS_TARGET);
|
||||
if (sm_backupMenu && sm_slidePanel && sm_menuRenderTarget && sm_panelWidth && sm_font) { return; }
|
||||
|
||||
sm_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_TWO_PIXEL,
|
||||
graphics::fonts::sizes::TWENTY_TWO_PIXEL);
|
||||
sm_panelWidth = sm_font->get_text_width(m_controlGuide) + 64;
|
||||
sm_backupMenu = ui::Menu::create(8, 8, sm_panelWidth - 16, 22, 600);
|
||||
sm_slidePanel = ui::SlideOutPanel::create(sm_panelWidth, ui::SlideOutPanel::Side::Right);
|
||||
sm_menuRenderTarget =
|
||||
sdl2::TextureManager::create_load_resource(BACKUP_TARGET, sm_panelWidth, 600, SDL_TEXTUREACCESS_TARGET);
|
||||
}
|
||||
|
||||
void BackupMenuState::ensure_target_directory()
|
||||
@@ -262,7 +274,7 @@ void BackupMenuState::initialize_remote_storage()
|
||||
remote->change_directory(remoteDir);
|
||||
}
|
||||
|
||||
void BackupMenuState::name_and_create_backup()
|
||||
void BackupMenuState::name_and_create_backup(const sdl2::Input &input)
|
||||
{
|
||||
// Size of the buffer for naming backups.
|
||||
static constexpr size_t SIZE_NAME_LENGTH = 0x80;
|
||||
@@ -279,7 +291,7 @@ void BackupMenuState::name_and_create_backup()
|
||||
const bool exportZip = autoUpload || config::get_by_key(config::keys::EXPORT_TO_ZIP);
|
||||
|
||||
// Input.
|
||||
const bool zrHeld = input::button_held(HidNpadButton_ZR);
|
||||
const bool zrHeld = input.button_held(HidNpadButton_ZR);
|
||||
|
||||
// Whether or not we should skip the keyboard.
|
||||
const bool autoNamed = (autoName || zrHeld); // This can be eval'd here.
|
||||
@@ -525,7 +537,10 @@ void BackupMenuState::upload_backup()
|
||||
// Push the confirmation.
|
||||
ConfirmProgress::create_push_fade(query, holdRequired, tasks::backup::patch_backup, nullptr, m_dataStruct);
|
||||
}
|
||||
else { ProgressState::create_push_fade(tasks::backup::upload_backup, m_dataStruct); }
|
||||
else
|
||||
{
|
||||
ProgressState::create_push_fade(tasks::backup::upload_backup, m_dataStruct);
|
||||
}
|
||||
}
|
||||
|
||||
void BackupMenuState::pop_save_empty()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "appstates/BaseTask.hpp"
|
||||
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
#include "ui/PopMessageManager.hpp"
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace
|
||||
BaseTask::BaseTask()
|
||||
: BaseState(false)
|
||||
, m_frameTimer(TICKS_GLYPH_TRIGGER)
|
||||
, m_popUnableExit(strings::get_by_name(strings::names::GENERAL_POPS, 0)) {};
|
||||
, m_popUnableExit(strings::get_by_name(strings::names::GENERAL_POPS, 0))
|
||||
{ BaseTask::initialize_static_members(); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
@@ -27,9 +28,9 @@ void BaseTask::update_loading_glyph()
|
||||
else if (++m_currentFrame % 8 == 0) { m_currentFrame = 0; }
|
||||
}
|
||||
|
||||
void BaseTask::pop_on_plus()
|
||||
void BaseTask::pop_on_plus(const sdl2::Input &input)
|
||||
{
|
||||
const bool plusPressed = input::button_pressed(HidNpadButton_Plus);
|
||||
const bool plusPressed = input.button_pressed(HidNpadButton_Plus);
|
||||
|
||||
if (plusPressed) { ui::PopMessageManager::push_message(ui::PopMessageManager::DEFAULT_TICKS, m_popUnableExit); }
|
||||
}
|
||||
@@ -37,15 +38,18 @@ void BaseTask::pop_on_plus()
|
||||
void BaseTask::render_loading_glyph()
|
||||
{
|
||||
// Render coords.
|
||||
static constexpr int RENDER_X = 56;
|
||||
static constexpr int RENDER_Y = 673;
|
||||
static constexpr int RENDER_SIZE = 32;
|
||||
static constexpr int RENDER_X = 56;
|
||||
static constexpr int RENDER_Y = 673;
|
||||
|
||||
sdl::text::render(sdl::Texture::Null,
|
||||
RENDER_X,
|
||||
RENDER_Y,
|
||||
RENDER_SIZE,
|
||||
sdl::text::NO_WRAP,
|
||||
m_colorMod,
|
||||
sm_glyphArray[m_currentFrame]);
|
||||
sm_font->render_text(RENDER_X, RENDER_Y, colors::WHITE, sm_glyphArray[m_currentFrame]);
|
||||
}
|
||||
|
||||
// ---- Private Functions ----
|
||||
|
||||
void BaseTask::initialize_static_members()
|
||||
{
|
||||
if (sm_font) { return; }
|
||||
|
||||
sm_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::THIRTY_TWO_PIXEL,
|
||||
graphics::fonts::sizes::THIRTY_TWO_PIXEL);
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "data/data.hpp"
|
||||
#include "error.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "input.hpp"
|
||||
|
||||
// ---- Construction ----
|
||||
|
||||
@@ -21,24 +20,24 @@ BlacklistEditState::BlacklistEditState()
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void BlacklistEditState::update()
|
||||
void BlacklistEditState::update(const sdl2::Input &input)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
|
||||
sm_slidePanel->update(hasFocus);
|
||||
sm_slidePanel->update(input, hasFocus);
|
||||
|
||||
if (aPressed) { BlacklistEditState::remove_from_blacklist(); }
|
||||
else if (sm_slidePanel->is_closed()) { BlacklistEditState::deactivate_state(); }
|
||||
else if (bPressed || m_blacklist.empty()) { sm_slidePanel->close(); }
|
||||
}
|
||||
|
||||
void BlacklistEditState::render()
|
||||
void BlacklistEditState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
sm_slidePanel->clear_target();
|
||||
sm_slidePanel->render(sdl::Texture::Null, hasFocus);
|
||||
|
||||
sm_slidePanel->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
#include "appstates/DataLoadingState.hpp"
|
||||
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr int SCREEN_CENTER = 640;
|
||||
}
|
||||
#include "mathutil.hpp"
|
||||
|
||||
// ---- Construction ----
|
||||
|
||||
DataLoadingState::DataLoadingState(data::DataContext &context,
|
||||
sdl2::Renderer &renderer,
|
||||
DestructFunction destructFunction,
|
||||
sys::threadpool::JobFunction function,
|
||||
sys::Task::TaskData taskData)
|
||||
: BaseTask()
|
||||
, m_context(context)
|
||||
, m_renderer(renderer)
|
||||
, m_destructFunction(destructFunction)
|
||||
{
|
||||
DataLoadingState::initialize_static_members();
|
||||
@@ -25,27 +24,34 @@ DataLoadingState::DataLoadingState(data::DataContext &context,
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void DataLoadingState::update()
|
||||
void DataLoadingState::update(const sdl2::Input &input)
|
||||
{
|
||||
BaseTask::update_loading_glyph();
|
||||
if (!m_task->is_running()) { DataLoadingState::deactivate_state(); }
|
||||
m_context.process_icon_queue();
|
||||
m_context.process_icon_queue(m_renderer);
|
||||
}
|
||||
|
||||
void DataLoadingState::sub_update() { BaseTask::update_loading_glyph(); }
|
||||
|
||||
void DataLoadingState::render()
|
||||
void DataLoadingState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
static constexpr int ICON_X_COORD = SCREEN_CENTER - 128;
|
||||
static constexpr int ICON_Y_COORD = 226;
|
||||
const std::string status = m_task->get_status();
|
||||
// These are the dimensions of the icon loaded.
|
||||
static constexpr int ICON_WIDTH = 256;
|
||||
static constexpr int ICON_HEIGHT = 259;
|
||||
static constexpr int ICON_X = math::Util<int>::center_within(graphics::SCREEN_WIDTH, ICON_WIDTH);
|
||||
static constexpr int ICON_Y = math::Util<int>::center_within(graphics::SCREEN_HEIGHT, ICON_HEIGHT);
|
||||
|
||||
const int statusWidth = sdl::text::get_width(BaseTask::FONT_SIZE, status);
|
||||
m_statusX = SCREEN_CENTER - (statusWidth / 2);
|
||||
// Grab the status from the task and center it.
|
||||
const std::string status = m_task->get_status();
|
||||
const int statusWidth = sm_font->get_text_width(status);
|
||||
m_statusX = math::Util<int>::center_within(graphics::SCREEN_WIDTH, statusWidth);
|
||||
|
||||
sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::CLEAR_COLOR);
|
||||
sm_jksvIcon->render(sdl::Texture::Null, ICON_X_COORD, ICON_Y_COORD);
|
||||
sdl::text::render(sdl::Texture::Null, m_statusX, 673, BaseTask::FONT_SIZE, sdl::text::NO_WRAP, colors::WHITE, status);
|
||||
// This is to cover up the base rendering.
|
||||
renderer.render_rectangle(0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::CLEAR_COLOR);
|
||||
|
||||
// Render the icon, status and loading glyph.
|
||||
sm_jksvIcon->render(ICON_X, ICON_Y);
|
||||
sm_font->render_text(m_statusX, 673, colors::WHITE, status);
|
||||
BaseTask::render_loading_glyph();
|
||||
}
|
||||
|
||||
@@ -53,15 +59,21 @@ void DataLoadingState::render()
|
||||
|
||||
void DataLoadingState::initialize_static_members()
|
||||
{
|
||||
if (sm_jksvIcon) { return; }
|
||||
// Path for the loading icon.
|
||||
static constexpr std::string_view ICON_PATH = "romfs:/Textures/LoadingIcon.png";
|
||||
|
||||
sm_jksvIcon = sdl::TextureManager::load("LoadingIcon", "romfs:/Textures/LoadingIcon.png");
|
||||
if (sm_jksvIcon && sm_font) { return; }
|
||||
|
||||
// Load icon and font.
|
||||
sm_jksvIcon = sdl2::TextureManager::create_load_resource(ICON_PATH, ICON_PATH);
|
||||
sm_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_PIXEL,
|
||||
graphics::fonts::sizes::TWENTY_PIXEL);
|
||||
}
|
||||
|
||||
void DataLoadingState::deactivate_state()
|
||||
{
|
||||
// This is to catch any stragglers.
|
||||
m_context.process_icon_queue();
|
||||
m_context.process_icon_queue(m_renderer);
|
||||
if (m_destructFunction) { m_destructFunction(); }
|
||||
BaseState::deactivate();
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
#include "appstates/MainMenuState.hpp"
|
||||
#include "data/data.hpp"
|
||||
#include "error.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "graphics/targets.hpp"
|
||||
#include "keyboard/keyboard.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
#include "ui/PopMessageManager.hpp"
|
||||
@@ -14,9 +15,6 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
// This target is shared be a lot of states.
|
||||
constexpr std::string_view SECONDARY_TARGET = "SecondaryTarget";
|
||||
|
||||
// Enum for switch case readability.
|
||||
enum
|
||||
{
|
||||
@@ -35,23 +33,25 @@ static void finish_reinitialization();
|
||||
|
||||
// ---- Construction ----
|
||||
|
||||
ExtrasMenuState::ExtrasMenuState()
|
||||
: m_renderTarget(sdl::TextureManager::load(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET))
|
||||
ExtrasMenuState::ExtrasMenuState(sdl2::Renderer &renderer)
|
||||
: m_renderer(renderer)
|
||||
, m_renderTarget(sdl2::TextureManager::create_load_resource(graphics::targets::names::SECONDARY,
|
||||
graphics::targets::dims::SECONDARY_WIDTH,
|
||||
graphics::targets::dims::SECONDARY_HEIGHT,
|
||||
SDL_TEXTUREACCESS_TARGET))
|
||||
, m_controlGuide(ui::ControlGuide::create(strings::get_by_name(strings::names::CONTROL_GUIDES, 5)))
|
||||
{
|
||||
ExtrasMenuState::initialize_menu();
|
||||
}
|
||||
{ ExtrasMenuState::initialize_menu(); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ExtrasMenuState::update()
|
||||
void ExtrasMenuState::update(const sdl2::Input &input)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
|
||||
m_extrasMenu->update(hasFocus);
|
||||
m_controlGuide->update(hasFocus);
|
||||
m_extrasMenu->update(input, hasFocus);
|
||||
m_controlGuide->update(input, hasFocus);
|
||||
|
||||
if (aPressed)
|
||||
{
|
||||
@@ -71,14 +71,20 @@ void ExtrasMenuState::update()
|
||||
|
||||
void ExtrasMenuState::sub_update() { m_controlGuide->sub_update(); }
|
||||
|
||||
void ExtrasMenuState::render()
|
||||
void ExtrasMenuState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
m_renderTarget->clear(colors::TRANSPARENT);
|
||||
m_extrasMenu->render(m_renderTarget, hasFocus);
|
||||
m_renderTarget->render(sdl::Texture::Null, 201, 91);
|
||||
m_controlGuide->render(sdl::Texture::Null, hasFocus);
|
||||
{ // Set the render target.
|
||||
graphics::ScopedRender scopedRender{renderer, m_renderTarget};
|
||||
renderer.frame_begin(colors::TRANSPARENT);
|
||||
|
||||
// Render the menu to it.
|
||||
m_extrasMenu->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
m_renderTarget->render(201, 91);
|
||||
m_controlGuide->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
@@ -93,7 +99,7 @@ void ExtrasMenuState::initialize_menu()
|
||||
}
|
||||
}
|
||||
|
||||
void ExtrasMenuState::reinitialize_data() { data::launch_initialization(true, finish_reinitialization); }
|
||||
void ExtrasMenuState::reinitialize_data() { data::launch_initialization(true, m_renderer, finish_reinitialization); }
|
||||
|
||||
void ExtrasMenuState::sd_to_sd_browser() { FileModeState::create_and_push("sdmc", "sdmc", false); }
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace
|
||||
}
|
||||
|
||||
// ---- Construction ----
|
||||
FadeState::FadeState(sdl::Color baseColor, uint8_t startAlpha, uint8_t endAlpha, std::shared_ptr<BaseState> nextState)
|
||||
FadeState::FadeState(SDL_Color baseColor, uint8_t startAlpha, uint8_t endAlpha, std::shared_ptr<BaseState> nextState)
|
||||
: m_baseColor(baseColor)
|
||||
, m_alpha(startAlpha)
|
||||
, m_endAlpha(endAlpha)
|
||||
@@ -23,7 +23,7 @@ FadeState::FadeState(sdl::Color baseColor, uint8_t startAlpha, uint8_t endAlpha,
|
||||
m_fadeTimer.start(TICKS_TIMER_TRIGGER);
|
||||
}
|
||||
|
||||
void FadeState::update()
|
||||
void FadeState::update(const sdl2::Input &input)
|
||||
{
|
||||
if (m_alpha == m_endAlpha)
|
||||
{
|
||||
@@ -38,12 +38,13 @@ void FadeState::update()
|
||||
}
|
||||
}
|
||||
|
||||
void FadeState::render()
|
||||
void FadeState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
const uint32_t rawColor = (m_baseColor.raw & 0xFFFFFF00) | m_alpha;
|
||||
const sdl::Color fadeColor{rawColor};
|
||||
// Update alpha.
|
||||
m_baseColor.a = m_alpha;
|
||||
|
||||
sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, fadeColor);
|
||||
// Render overtop of everything.
|
||||
renderer.render_rectangle(0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, m_baseColor);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include "appstates/FileOptionState.hpp"
|
||||
#include "config/config.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "input.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
@@ -39,17 +39,17 @@ FileModeState::FileModeState(std::string_view mountA, std::string_view mountB, i
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void FileModeState::update()
|
||||
void FileModeState::update(const sdl2::Input &input)
|
||||
{
|
||||
switch (m_state)
|
||||
{
|
||||
case State::Rising:
|
||||
case State::Dropping: FileModeState::update_y(); break;
|
||||
case State::Open: FileModeState::update_handle_input(); break;
|
||||
case State::Open: FileModeState::update_handle_input(input); break;
|
||||
}
|
||||
}
|
||||
|
||||
void FileModeState::render()
|
||||
void FileModeState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Coords for divider lines.
|
||||
static constexpr int LINE_A_X = 617;
|
||||
@@ -59,27 +59,25 @@ void FileModeState::render()
|
||||
static constexpr int LINE_Y_A = 0;
|
||||
static constexpr int LINE_Y_B = 538;
|
||||
|
||||
// Grab focus.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
sm_renderTarget->clear(colors::TRANSPARENT);
|
||||
// Switch targets, clear.
|
||||
{
|
||||
graphics::ScopedRender scopedRender{renderer, sm_renderTarget};
|
||||
renderer.frame_begin(colors::TRANSPARENT);
|
||||
|
||||
// This is here so it's rendered underneath the pop-up frame.
|
||||
sm_controlGuide->render(sdl::Texture::Null, hasFocus);
|
||||
// Divider lines & menus.
|
||||
renderer.render_line(LINE_A_X, LINE_Y_A, LINE_A_X, LINE_Y_B, colors::WHITE);
|
||||
renderer.render_line(LINE_B_X, LINE_Y_A, LINE_B_X, LINE_Y_B, colors::DIALOG_DARK);
|
||||
m_dirMenuA->render(renderer, hasFocus && m_target == Target::MountA);
|
||||
m_dirMenuB->render(renderer, hasFocus && m_target == Target::MountB);
|
||||
}
|
||||
|
||||
// Center divider lines.
|
||||
sdl::render_line(sm_renderTarget, LINE_A_X, LINE_Y_A, LINE_A_X, LINE_Y_B, colors::WHITE);
|
||||
sdl::render_line(sm_renderTarget, LINE_B_X, LINE_Y_A, LINE_B_X, LINE_Y_B, colors::DIALOG_DARK);
|
||||
|
||||
// Menus
|
||||
m_dirMenuA->render(sm_renderTarget, hasFocus && m_target == Target::MountA);
|
||||
m_dirMenuB->render(sm_renderTarget, hasFocus && m_target == Target::MountB);
|
||||
|
||||
// Frame.
|
||||
sm_frame->render(sdl::Texture::Null, true);
|
||||
|
||||
// Main target.
|
||||
const int y = m_transition.get_y();
|
||||
sm_renderTarget->render(sdl::Texture::Null, 23, y + 12);
|
||||
// This needs to be in this specific order to look right.
|
||||
sm_controlGuide->render(renderer, hasFocus);
|
||||
sm_frame->render(renderer, hasFocus);
|
||||
sm_renderTarget->render(23, m_transition.get_y() + 12);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
@@ -99,8 +97,9 @@ void FileModeState::initialize_static_members()
|
||||
|
||||
if (sm_frame && sm_renderTarget && sm_controlGuide) { return; }
|
||||
|
||||
sm_frame = ui::Frame::create(PERMA_X, graphics::SCREEN_HEIGHT, FRAME_WIDTH, FRAME_HEIGHT);
|
||||
sm_renderTarget = sdl::TextureManager::load(RENDER_TARGET_NAME, INNER_WIDTH, INNER_HEIGHT, SDL_TEXTUREACCESS_TARGET);
|
||||
sm_frame = ui::Frame::create(PERMA_X, graphics::SCREEN_HEIGHT, FRAME_WIDTH, FRAME_HEIGHT);
|
||||
sm_renderTarget =
|
||||
sdl2::TextureManager::create_load_resource(RENDER_TARGET_NAME, INNER_WIDTH, INNER_HEIGHT, SDL_TEXTUREACCESS_TARGET);
|
||||
sm_controlGuide = ui::ControlGuide::create(strings::get_by_name(strings::names::CONTROL_GUIDES, 4));
|
||||
}
|
||||
|
||||
@@ -147,7 +146,10 @@ void FileModeState::initialize_directory_menu(const fslib::Path &path, fslib::Di
|
||||
{
|
||||
std::string option{};
|
||||
if (entry.is_directory()) { option = DIR_PREFIX; }
|
||||
else { option = FILE_PREFIX; }
|
||||
else
|
||||
{
|
||||
option = FILE_PREFIX;
|
||||
}
|
||||
|
||||
option += entry.get_filename();
|
||||
menu.add_option(option);
|
||||
@@ -170,7 +172,7 @@ void FileModeState::update_y() noexcept
|
||||
else if (finishedDropping) { FileModeState::deactivate_state(); }
|
||||
}
|
||||
|
||||
void FileModeState::update_handle_input() noexcept
|
||||
void FileModeState::update_handle_input(const sdl2::Input &input) noexcept
|
||||
{
|
||||
// Get whether or not the state has focus.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
@@ -181,11 +183,11 @@ void FileModeState::update_handle_input() noexcept
|
||||
fslib::Directory &directory = FileModeState::get_source_directory();
|
||||
|
||||
// Input bools.
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input::button_pressed(HidNpadButton_X);
|
||||
const bool zlZRPressed = input::button_pressed(HidNpadButton_ZL) || input::button_pressed(HidNpadButton_ZR);
|
||||
const bool minusPressed = input::button_pressed(HidNpadButton_Minus);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input.button_pressed(HidNpadButton_X);
|
||||
const bool zlZRPressed = input.button_pressed(HidNpadButton_ZL) || input.button_pressed(HidNpadButton_ZR);
|
||||
const bool minusPressed = input.button_pressed(HidNpadButton_Minus);
|
||||
|
||||
// Conditions
|
||||
if (aPressed) { FileModeState::enter_selected(path, directory, menu); }
|
||||
@@ -199,8 +201,8 @@ void FileModeState::update_handle_input() noexcept
|
||||
}
|
||||
|
||||
// Update the menu and control guide.
|
||||
menu.update(hasFocus);
|
||||
sm_controlGuide->update(hasFocus);
|
||||
menu.update(input, hasFocus);
|
||||
sm_controlGuide->update(input, hasFocus);
|
||||
}
|
||||
|
||||
void FileModeState::enter_selected(fslib::Path &path, fslib::Directory &directory, ui::Menu &menu)
|
||||
@@ -256,14 +258,10 @@ void FileModeState::enter_directory(fslib::Path &path,
|
||||
}
|
||||
|
||||
ui::Menu &FileModeState::get_source_menu() noexcept
|
||||
{
|
||||
return m_target == Target::MountA ? *m_dirMenuA.get() : *m_dirMenuB.get();
|
||||
}
|
||||
{ return m_target == Target::MountA ? *m_dirMenuA.get() : *m_dirMenuB.get(); }
|
||||
|
||||
ui::Menu &FileModeState::get_destination_menu() noexcept
|
||||
{
|
||||
return m_target == Target::MountA ? *m_dirMenuB.get() : *m_dirMenuA.get();
|
||||
}
|
||||
{ return m_target == Target::MountA ? *m_dirMenuB.get() : *m_dirMenuA.get(); }
|
||||
|
||||
fslib::Path &FileModeState::get_source_path() noexcept { return m_target == Target::MountA ? m_pathA : m_pathB; }
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "error.hpp"
|
||||
#include "fs/fs.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "input.hpp"
|
||||
#include "keyboard/keyboard.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "mathutil.hpp"
|
||||
@@ -70,23 +69,26 @@ FileOptionState::FileOptionState(FileModeState *spawningState)
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void FileOptionState::update()
|
||||
void FileOptionState::update(const sdl2::Input &input)
|
||||
{
|
||||
switch (m_state)
|
||||
{
|
||||
case State::Opening:
|
||||
case State::Closing: FileOptionState::update_dimensions(); break;
|
||||
case State::Opened: FileOptionState::update_handle_input(); break;
|
||||
case State::Opened: FileOptionState::update_handle_input(input); break;
|
||||
}
|
||||
}
|
||||
|
||||
void FileOptionState::render()
|
||||
void FileOptionState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Grab focus.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
sm_dialog->render(sdl::Texture::Null, hasFocus);
|
||||
|
||||
// Render the dialog and bail if we're not read for the menu.
|
||||
sm_dialog->render(renderer, hasFocus);
|
||||
if (!m_transition.in_place()) { return; }
|
||||
|
||||
sm_copyMenu->render(sdl::Texture::Null, hasFocus);
|
||||
sm_copyMenu->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
void FileOptionState::update_source() { m_updateSource = true; }
|
||||
@@ -156,7 +158,7 @@ void FileOptionState::update_dimensions() noexcept
|
||||
else if (isClosed) { FileOptionState::deactivate_state(); }
|
||||
}
|
||||
|
||||
void FileOptionState::update_handle_input() noexcept
|
||||
void FileOptionState::update_handle_input(const sdl2::Input &input) noexcept
|
||||
{
|
||||
// Grab whether or not the state has focus since this is actually used a lot.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
@@ -166,12 +168,12 @@ void FileOptionState::update_handle_input() noexcept
|
||||
else if (m_updateDest) { FileOptionState::update_filemode_dest(); }
|
||||
|
||||
// Update the menu input.
|
||||
sm_copyMenu->update(hasFocus);
|
||||
sm_copyMenu->update(input, hasFocus);
|
||||
|
||||
// Local input handling.
|
||||
const int selected = sm_copyMenu->get_selected();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
|
||||
if (aPressed)
|
||||
{
|
||||
@@ -398,7 +400,10 @@ 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::close_dialog() noexcept
|
||||
@@ -460,11 +465,11 @@ void FileOptionState::get_show_file_properties(const fslib::Path &path)
|
||||
const std::string pathString = path.string();
|
||||
const std::string sizeString = get_size_string(fileSize);
|
||||
const std::string message = stringutil::get_formatted_string(messageFormat,
|
||||
pathString.c_str(),
|
||||
sizeString.c_str(),
|
||||
createdBuffer,
|
||||
lastModified,
|
||||
lastAccessed);
|
||||
pathString.c_str(),
|
||||
sizeString.c_str(),
|
||||
createdBuffer,
|
||||
lastModified,
|
||||
lastAccessed);
|
||||
|
||||
MessageState::create_and_push(message);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#include "appstates/TitleSelectState.hpp"
|
||||
#include "appstates/UserOptionState.hpp"
|
||||
#include "config/config.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "remote/remote.hpp"
|
||||
#include "sdl.hpp"
|
||||
@@ -21,18 +21,32 @@
|
||||
#include "tasks/update.hpp"
|
||||
#include "ui/PopMessageManager.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
// Main menu render target.
|
||||
constexpr std::string_view TARGET = "MainMenuTarget";
|
||||
constexpr int TARGET_WIDTH = 200;
|
||||
constexpr int TARGET_HEIGHT = 555;
|
||||
|
||||
// Background.
|
||||
constexpr std::string_view MAIN_BG = "romfs:/Textures/MenuBackground.png";
|
||||
constexpr std::string_view SETT_ICON = "romfs:/Textures/SettingsIcon.png";
|
||||
constexpr std::string_view EXTRA_ICON = "romfs:/Textures/ExtrasIcon.png";
|
||||
|
||||
}
|
||||
|
||||
// ---- Construction ----
|
||||
|
||||
MainMenuState::MainMenuState()
|
||||
: m_renderTarget(sdl::TextureManager::load("mainMenuTarget", 200, 555, SDL_TEXTUREACCESS_TARGET))
|
||||
, m_background(sdl::TextureManager::load("mainBackground", "romfs:/Textures/MenuBackground.png"))
|
||||
, m_settingsIcon(sdl::TextureManager::load("settingsIcon", "romfs:/Textures/SettingsIcon.png"))
|
||||
, m_extrasIcon(sdl::TextureManager::load("extrasIcon", "romfs:/Textures/ExtrasIcon.png"))
|
||||
MainMenuState::MainMenuState(sdl2::Renderer &renderer)
|
||||
: m_renderTarget(sdl2::TextureManager::create_load_resource(TARGET, TARGET_WIDTH, TARGET_HEIGHT, SDL_TEXTUREACCESS_TARGET))
|
||||
, m_background(sdl2::TextureManager::create_load_resource(MAIN_BG, MAIN_BG))
|
||||
, m_settingsIcon(sdl2::TextureManager::create_load_resource(SETT_ICON, SETT_ICON))
|
||||
, m_extrasIcon(sdl2::TextureManager::create_load_resource(EXTRA_ICON, EXTRA_ICON))
|
||||
, m_mainMenu(ui::IconMenu::create(50, 15, 555))
|
||||
, m_controlGuide(ui::ControlGuide::create(strings::get_by_name(strings::names::CONTROL_GUIDES, 0)))
|
||||
, m_dataStruct(std::make_shared<MainMenuState::DataStruct>())
|
||||
{
|
||||
MainMenuState::initialize_settings_extras();
|
||||
MainMenuState::initialize_settings_extras(renderer);
|
||||
MainMenuState::initialize_menu();
|
||||
MainMenuState::initialize_view_states();
|
||||
MainMenuState::initialize_data_struct();
|
||||
@@ -41,14 +55,17 @@ MainMenuState::MainMenuState()
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void MainMenuState::update()
|
||||
void MainMenuState::update(const sdl2::Input &input)
|
||||
{
|
||||
const int selected = m_mainMenu->get_selected();
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool xPressed = input::button_pressed(HidNpadButton_X);
|
||||
const bool yPressed = input::button_pressed(HidNpadButton_Y);
|
||||
|
||||
// Input
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool xPressed = input.button_pressed(HidNpadButton_X);
|
||||
const bool yPressed = input.button_pressed(HidNpadButton_Y);
|
||||
|
||||
// Whether or not to open the options targeting users.
|
||||
const bool toUserOptions = xPressed && selected < sm_userCount;
|
||||
|
||||
if (aPressed) { MainMenuState::push_target_state(); }
|
||||
@@ -60,28 +77,38 @@ void MainMenuState::update()
|
||||
MainMenuState::confirm_update();
|
||||
}
|
||||
|
||||
m_mainMenu->update(hasFocus);
|
||||
m_controlGuide->update(hasFocus);
|
||||
m_mainMenu->update(input, hasFocus);
|
||||
m_controlGuide->update(input, hasFocus);
|
||||
|
||||
for (auto &state : sm_states) { state->sub_update(); }
|
||||
}
|
||||
|
||||
void MainMenuState::sub_update() { m_controlGuide->sub_update(); }
|
||||
|
||||
void MainMenuState::render()
|
||||
void MainMenuState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const int selected = m_mainMenu->get_selected();
|
||||
|
||||
m_background->render(m_renderTarget, 0, 0);
|
||||
m_mainMenu->render(m_renderTarget, hasFocus);
|
||||
m_renderTarget->render(sdl::Texture::Null, 0, 91);
|
||||
m_controlGuide->render(sdl::Texture::Null, hasFocus);
|
||||
{
|
||||
// Switch target.
|
||||
graphics::ScopedRender scopedRender{renderer, m_renderTarget};
|
||||
renderer.frame_begin(colors::CLEAR_COLOR);
|
||||
|
||||
// Render background and menu.
|
||||
m_background->render(0, 0);
|
||||
m_mainMenu->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
// Main FB stuff.
|
||||
m_renderTarget->render(0, 91);
|
||||
m_controlGuide->render(renderer, hasFocus);
|
||||
|
||||
// If we have focus, render the state we're hovering.
|
||||
if (hasFocus)
|
||||
{
|
||||
BaseState *target = sm_states[selected].get();
|
||||
target->render();
|
||||
target->render(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +124,10 @@ void MainMenuState::initialize_view_states()
|
||||
std::shared_ptr<BaseState> state{};
|
||||
|
||||
if (jksmMode) { state = TextTitleSelectState::create(user); }
|
||||
else { state = TitleSelectState::create(user); }
|
||||
else
|
||||
{
|
||||
state = TitleSelectState::create(user);
|
||||
}
|
||||
|
||||
sm_states.push_back(state);
|
||||
}
|
||||
@@ -116,12 +146,12 @@ void MainMenuState::refresh_view_states()
|
||||
|
||||
// ---- Private functions ----
|
||||
|
||||
void MainMenuState::initialize_settings_extras()
|
||||
void MainMenuState::initialize_settings_extras(sdl2::Renderer &renderer)
|
||||
{
|
||||
if (!sm_settingsState || !sm_extrasState)
|
||||
{
|
||||
sm_settingsState = SettingsState::create();
|
||||
sm_extrasState = ExtrasMenuState::create();
|
||||
sm_extrasState = ExtrasMenuState::create(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +216,10 @@ void MainMenuState::backup_all_for_all()
|
||||
{
|
||||
ConfirmProgress::create_push_fade(query, true, tasks::mainmenu::backup_all_for_all_remote, nullptr, m_dataStruct);
|
||||
}
|
||||
else { ConfirmProgress::create_push_fade(query, true, tasks::mainmenu::backup_all_for_all_local, nullptr, m_dataStruct); }
|
||||
else
|
||||
{
|
||||
ConfirmProgress::create_push_fade(query, true, tasks::mainmenu::backup_all_for_all_local, nullptr, m_dataStruct);
|
||||
}
|
||||
}
|
||||
|
||||
void MainMenuState::confirm_update()
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include "StateManager.hpp"
|
||||
#include "appstates/FadeState.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "input.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
|
||||
namespace
|
||||
@@ -55,45 +56,57 @@ MessageState::MessageState(std::string &message)
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void MessageState::update()
|
||||
void MessageState::update(const sdl2::Input &input)
|
||||
{
|
||||
switch (m_state)
|
||||
{
|
||||
case State::Opening:
|
||||
case State::Closing: MessageState::update_dimensions(); break;
|
||||
case State::Displaying: MessageState::update_handle_input(); break;
|
||||
case State::Displaying: MessageState::update_handle_input(input); break;
|
||||
}
|
||||
}
|
||||
|
||||
void MessageState::render()
|
||||
void MessageState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// This is were to render
|
||||
static constexpr int y = 229;
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND);
|
||||
sm_dialog->render(sdl::Texture::Null, hasFocus);
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
// Dim the background and render the dialog. Only continue if we're fully open.
|
||||
renderer.render_rectangle(0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND);
|
||||
sm_dialog->render(renderer, hasFocus);
|
||||
if (!m_transition.in_place()) { return; }
|
||||
|
||||
sdl::text::render(sdl::Texture::Null, 312, y + 24, 20, 656, colors::WHITE, m_message);
|
||||
sdl::render_line(sdl::Texture::Null, 280, y + 192, 999, y + 192, colors::DIV_COLOR);
|
||||
sdl::text::render(sdl::Texture::Null, sm_okX, y + 214, 22, sdl::text::NO_WRAP, colors::WHITE, sm_okText);
|
||||
sm_textFont->render_text_wrapped(312, y + 24, colors::WHITE, 656, m_message);
|
||||
renderer.render_line(280, y + 192, 999, y + 192, colors::DIV_COLOR);
|
||||
sm_optionFont->render_text(sm_okX, y + 214, colors::WHITE, sm_okText);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
|
||||
void MessageState::initialize_static_members()
|
||||
{
|
||||
static constexpr int HALF_WIDTH = 640;
|
||||
static constexpr std::string_view POP_SOUND = "ConfirmPop";
|
||||
static constexpr const char *POP_PATH = "romfs:/Sound/ConfirmPop.wav";
|
||||
static constexpr std::string_view CONFIRM_POP = "romfs:/Sound/ConfirmPop.wav";
|
||||
|
||||
if (sm_okText && sm_dialog && sm_dialogPop) { return; }
|
||||
if (sm_okText && sm_dialog && sm_dialogPop && sm_textFont && sm_optionFont) { return; }
|
||||
|
||||
sm_okText = strings::get_by_name(strings::names::YES_NO_OK, 2);
|
||||
sm_okX = HALF_WIDTH - (sdl::text::get_width(22, sm_okText) / 2);
|
||||
sm_dialog = ui::DialogBox::create(0, 0, 0, 0);
|
||||
sm_dialogPop = sdl::SoundManager::load(POP_SOUND, POP_PATH);
|
||||
// This is needed later, so it comes first.
|
||||
sm_textFont = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_PIXEL,
|
||||
graphics::fonts::sizes::TWENTY_PIXEL);
|
||||
sm_optionFont = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::THIRTY_TWO_PIXEL,
|
||||
graphics::fonts::sizes::TWENTY_TWO_PIXEL);
|
||||
|
||||
// OK text and X coord.
|
||||
sm_okText = strings::get_by_name(strings::names::YES_NO_OK, 2);
|
||||
sm_okX = math::Util<int>::center_within(graphics::SCREEN_WIDTH, sm_textFont->get_text_width(sm_okText));
|
||||
|
||||
// Dialog.
|
||||
sm_dialog = ui::DialogBox::create(0, 0, 0, 0);
|
||||
sm_dialog->set_from_transition(m_transition, true);
|
||||
|
||||
// Sound to play.
|
||||
sm_dialogPop = sdl2::SoundManager::create_load_resource(CONFIRM_POP, CONFIRM_POP);
|
||||
}
|
||||
|
||||
void MessageState::update_dimensions() noexcept
|
||||
@@ -109,10 +122,10 @@ void MessageState::update_dimensions() noexcept
|
||||
else if (closed) { MessageState::deactivate_state(); }
|
||||
}
|
||||
|
||||
void MessageState::update_handle_input() noexcept
|
||||
void MessageState::update_handle_input(const sdl2::Input &input) noexcept
|
||||
{
|
||||
// Input bools.
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
|
||||
// Handle the triggerguard.
|
||||
m_triggerGuard = m_triggerGuard || (aPressed && !m_triggerGuard);
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
#include "appstates/FadeState.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "input.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "sdl.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
#include "stringutil.hpp"
|
||||
@@ -43,17 +44,15 @@ ProgressState::ProgressState(sys::threadpool::JobFunction function, sys::Task::T
|
||||
TARGET_WIDTH,
|
||||
TARGET_HEIGHT,
|
||||
ui::Transition::DEFAULT_THRESHOLD)
|
||||
{
|
||||
initialize_static_members();
|
||||
}
|
||||
{ initialize_static_members(); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ProgressState::update()
|
||||
void ProgressState::update(const sdl2::Input &input)
|
||||
{
|
||||
// These are always updated and aren't conditional.
|
||||
BaseTask::update_loading_glyph();
|
||||
BaseTask::pop_on_plus();
|
||||
BaseTask::pop_on_plus(input);
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
@@ -63,7 +62,7 @@ void ProgressState::update()
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressState::render()
|
||||
void ProgressState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
static constexpr int RIGHT_EDGE_X = (COORD_BAR_X + SIZE_BAR_WIDTH) - 16;
|
||||
|
||||
@@ -71,51 +70,44 @@ void ProgressState::render()
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
// This will dim the background.
|
||||
sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND);
|
||||
renderer.render_rectangle(0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND);
|
||||
|
||||
// Render the glyph and dialog. Don't render anything else unless the task is running.
|
||||
BaseTask::render_loading_glyph();
|
||||
sm_dialog->render(sdl::Texture::Null, hasFocus);
|
||||
sm_dialog->render(renderer, hasFocus);
|
||||
if (m_state != State::Running) { return; }
|
||||
|
||||
// This just makes this easier to work with.
|
||||
const int barWidth = static_cast<int>(SIZE_BAR_WIDTH);
|
||||
|
||||
// Grab and render the status.
|
||||
const std::string status = m_task->get_status();
|
||||
sdl::text::render(sdl::Texture::Null, 312, 255, BaseTask::FONT_SIZE, 656, colors::WHITE, status);
|
||||
sm_font->render_text(312, 255, colors::WHITE, status);
|
||||
|
||||
// This is the divider line.
|
||||
sdl::render_line(sdl::Texture::Null, 280, 421, 999, 421, colors::DIV_COLOR);
|
||||
renderer.render_line(280, 421, 999, 421, colors::DIV_COLOR);
|
||||
|
||||
// Progress showing bar.
|
||||
sdl::render_rect_fill(sdl::Texture::Null, COORD_BAR_X, COORD_BAR_Y, barWidth, 32, colors::BLACK);
|
||||
sdl::render_rect_fill(sdl::Texture::Null, COORD_BAR_X, COORD_BAR_Y, m_progressBarWidth, 32, colors::BAR_GREEN);
|
||||
renderer.render_rectangle(COORD_BAR_X, COORD_BAR_Y, static_cast<int>(SIZE_BAR_WIDTH), 32, colors::BLACK);
|
||||
renderer.render_rectangle(COORD_BAR_X, COORD_BAR_Y, m_progressBarWidth, 32, colors::BAR_GREEN);
|
||||
|
||||
// These are the "caps" to round the edges of the bar.
|
||||
sm_barEdges->render_part(sdl::Texture::Null, COORD_BAR_X, COORD_BAR_Y, 0, 0, 16, 32);
|
||||
sm_barEdges->render_part(sdl::Texture::Null, RIGHT_EDGE_X, COORD_BAR_Y, 16, 0, 16, 32);
|
||||
sm_barEdges->render_part(COORD_BAR_X, COORD_BAR_Y, 0, 0, 16, 32);
|
||||
sm_barEdges->render_part(RIGHT_EDGE_X, COORD_BAR_Y, 16, 0, 16, 32);
|
||||
|
||||
// Progress string.
|
||||
sdl::text::render(sdl::Texture::Null,
|
||||
m_percentageX,
|
||||
COORD_TEXT_Y,
|
||||
BaseTask::FONT_SIZE,
|
||||
sdl::text::NO_WRAP,
|
||||
colors::WHITE,
|
||||
m_percentageString);
|
||||
sm_font->render_text(m_percentageX, COORD_TEXT_Y, colors::WHITE, m_percentageString);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
|
||||
void ProgressState::initialize_static_members()
|
||||
{
|
||||
static constexpr std::string_view BAR_EDGE_NAME = "BarEdges";
|
||||
static constexpr std::string_view BAR_EDGES = "romfs:/Textures/BarEdges/png";
|
||||
|
||||
if (sm_dialog && sm_barEdges) { return; }
|
||||
if (sm_dialog && sm_barEdges && sm_font) { return; }
|
||||
|
||||
sm_dialog = ui::DialogBox::create(0, 0, 0, 0);
|
||||
sm_barEdges = sdl::TextureManager::load(BAR_EDGE_NAME, "romfs:/Textures/BarEdges.png");
|
||||
sm_barEdges = sdl2::TextureManager::create_load_resource(BAR_EDGES, BAR_EDGES);
|
||||
sm_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_PIXEL,
|
||||
graphics::fonts::sizes::TWENTY_PIXEL);
|
||||
sm_dialog->set_from_transition(m_transition, true);
|
||||
}
|
||||
|
||||
@@ -152,9 +144,8 @@ void ProgressState::update_progress() noexcept
|
||||
// This is the actual string that's displayed.
|
||||
m_percentageString = stringutil::get_formatted_string("%u%%", m_progress);
|
||||
|
||||
const int stringWidth = sdl::text::get_width(BaseTask::FONT_SIZE, m_percentageString);
|
||||
// Center the string above.
|
||||
m_percentageX = COORD_DISPLAY_CENTER - (stringWidth / 2);
|
||||
const int stringWidth = sm_font->get_text_width(m_percentageString);
|
||||
m_percentageX = math::Util<int>::center_within(graphics::SCREEN_WIDTH, stringWidth);
|
||||
|
||||
// Handle closing and updating.
|
||||
const bool taskRunning = m_task->is_running();
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "data/data.hpp"
|
||||
#include "error.hpp"
|
||||
#include "fs/fs.hpp"
|
||||
#include "input.hpp"
|
||||
#include "keyboard/keyboard.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
@@ -38,14 +37,14 @@ SaveCreateState::SaveCreateState(data::User *user, TitleSelectCommon *titleSelec
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void SaveCreateState::update()
|
||||
void SaveCreateState::update(const sdl2::Input &input)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
sm_slidePanel->update(hasFocus);
|
||||
sm_slidePanel->update(input, hasFocus);
|
||||
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
const bool panelClosed = sm_slidePanel->is_closed();
|
||||
|
||||
if (m_refreshRequired.load())
|
||||
@@ -60,13 +59,12 @@ void SaveCreateState::update()
|
||||
else if (panelClosed) { SaveCreateState::deactivate_state(); }
|
||||
}
|
||||
|
||||
void SaveCreateState::render()
|
||||
void SaveCreateState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
// Clear slide target, render menu, render slide to frame buffer.
|
||||
sm_slidePanel->clear_target();
|
||||
sm_slidePanel->render(sdl::Texture::Null, hasFocus);
|
||||
sm_slidePanel->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
void SaveCreateState::refresh_required() { m_refreshRequired.store(true); }
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "appstates/BackupMenuState.hpp"
|
||||
#include "appstates/ConfirmState.hpp"
|
||||
#include "config/config.hpp"
|
||||
#include "input.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
#include "stringutil.hpp"
|
||||
#include "tasks/saveimport.hpp"
|
||||
@@ -20,27 +19,26 @@ SaveImportState::SaveImportState(data::User *user)
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void SaveImportState::update()
|
||||
void SaveImportState::update(const sdl2::Input &input)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
sm_slidePanel->update(hasFocus);
|
||||
sm_slidePanel->update(input, hasFocus);
|
||||
if (!sm_slidePanel->is_open()) { return; }
|
||||
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
|
||||
if (aPressed) { SaveImportState::import_backup(); }
|
||||
else if (bPressed) { sm_slidePanel->close(); }
|
||||
else if (sm_slidePanel->is_closed()) { SaveImportState::deactivate_state(); }
|
||||
}
|
||||
|
||||
void SaveImportState::render()
|
||||
void SaveImportState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
sm_slidePanel->clear_target();
|
||||
sm_slidePanel->render(sdl::Texture::Null, hasFocus);
|
||||
sm_slidePanel->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
#include "error.hpp"
|
||||
#include "fs/fs.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "graphics/targets.hpp"
|
||||
#include "keyboard/keyboard.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
@@ -72,7 +73,10 @@ namespace
|
||||
SettingsState::SettingsState()
|
||||
: m_settingsMenu(ui::Menu::create(32, 10, 1000, 23, 555))
|
||||
, m_controlGuide(ui::ControlGuide::create(strings::get_by_name(strings::names::CONTROL_GUIDES, 3)))
|
||||
, m_renderTarget(sdl::TextureManager::load(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET))
|
||||
, m_renderTarget(sdl2::TextureManager::create_load_resource(graphics::targets::names::SECONDARY,
|
||||
graphics::targets::dims::SECONDARY_WIDTH,
|
||||
graphics::targets::dims::SECONDARY_HEIGHT,
|
||||
SDL_TEXTUREACCESS_TARGET))
|
||||
{
|
||||
SettingsState::load_settings_menu();
|
||||
SettingsState::load_extra_strings();
|
||||
@@ -81,33 +85,44 @@ SettingsState::SettingsState()
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void SettingsState::update()
|
||||
void SettingsState::update(const sdl2::Input &input)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input::button_pressed(HidNpadButton_X);
|
||||
const bool minusPressed = input::button_pressed(HidNpadButton_Minus);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input.button_pressed(HidNpadButton_X);
|
||||
const bool minusPressed = input.button_pressed(HidNpadButton_Minus);
|
||||
|
||||
m_settingsMenu->update(hasFocus);
|
||||
m_settingsMenu->update(input, hasFocus);
|
||||
if (aPressed) { SettingsState::toggle_options(); }
|
||||
else if (xPressed) { SettingsState::reset_settings(); }
|
||||
else if (minusPressed) { SettingsState::create_push_description_message(); }
|
||||
else if (bPressed) { BaseState::deactivate(); }
|
||||
|
||||
m_controlGuide->update(hasFocus);
|
||||
m_controlGuide->update(input, hasFocus);
|
||||
}
|
||||
|
||||
void SettingsState::sub_update() { m_controlGuide->sub_update(); }
|
||||
|
||||
void SettingsState::render()
|
||||
void SettingsState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Grab focus state.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
m_renderTarget->clear(colors::TRANSPARENT);
|
||||
m_settingsMenu->render(m_renderTarget, hasFocus);
|
||||
m_renderTarget->render(sdl::Texture::Null, 201, 91);
|
||||
m_controlGuide->render(sdl::Texture::Null, hasFocus);
|
||||
{
|
||||
// Set target and clear.
|
||||
graphics::ScopedRender scopedRender{renderer, m_renderTarget};
|
||||
renderer.frame_begin(colors::TRANSPARENT);
|
||||
|
||||
// Render what we need to.
|
||||
m_settingsMenu->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
// Render the target to the screen.
|
||||
m_renderTarget->render(201, 91);
|
||||
|
||||
// Control guide.
|
||||
m_controlGuide->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
@@ -194,7 +209,10 @@ void SettingsState::change_working_directory()
|
||||
moved = fs::move_directory_recursively(oldPath, newPath);
|
||||
error::fslib(fslib::delete_directory_recursively(oldPath));
|
||||
}
|
||||
else { moved = fslib::rename_directory(oldPath, newPath); }
|
||||
else
|
||||
{
|
||||
moved = fslib::rename_directory(oldPath, newPath);
|
||||
}
|
||||
|
||||
if (!moved)
|
||||
{
|
||||
@@ -292,7 +310,10 @@ void SettingsState::toggle_trash_folder()
|
||||
config::toggle_by_key(config::keys::ENABLE_TRASH_BIN);
|
||||
|
||||
if (trashEnabled) { error::fslib(fslib::delete_directory_recursively(trashPath)); }
|
||||
else { error::fslib(fslib::create_directory(trashPath)); }
|
||||
else
|
||||
{
|
||||
error::fslib(fslib::create_directory(trashPath));
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsState::cycle_anim_scaling()
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
#include "appstates/FadeState.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "input.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "sdl.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
#include "ui/PopMessageManager.hpp"
|
||||
@@ -11,26 +12,25 @@
|
||||
// ---- Construction ----
|
||||
|
||||
TaskState::TaskState(sys::threadpool::JobFunction function, sys::Task::TaskData taskData)
|
||||
{
|
||||
m_task = std::make_unique<sys::Task>(function, taskData);
|
||||
}
|
||||
{ m_task = std::make_unique<sys::Task>(function, taskData); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void TaskState::update()
|
||||
void TaskState::update(const sdl2::Input &input)
|
||||
{
|
||||
BaseTask::pop_on_plus();
|
||||
BaseTask::pop_on_plus(input);
|
||||
BaseTask::update_loading_glyph();
|
||||
if (!m_task->is_running()) { TaskState::deactivate_state(); }
|
||||
}
|
||||
|
||||
void TaskState::render()
|
||||
void TaskState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
const std::string status = m_task->get_status();
|
||||
const int statusX = 640 - (sdl::text::get_width(BaseTask::FONT_SIZE, status.c_str()) / 2);
|
||||
const int statusWidth = sm_font->get_text_width(status);
|
||||
const int statusX = math::Util<int>::center_within(graphics::SCREEN_WIDTH, statusWidth);
|
||||
|
||||
sdl::render_rect_fill(sdl::Texture::Null, 0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND);
|
||||
sdl::text::render(sdl::Texture::Null, statusX, 351, BaseTask::FONT_SIZE, sdl::text::NO_WRAP, colors::WHITE, status);
|
||||
renderer.render_rectangle(0, 0, graphics::SCREEN_WIDTH, graphics::SCREEN_HEIGHT, colors::DIM_BACKGROUND);
|
||||
sm_font->render_text(statusX, 351, colors::WHITE, status);
|
||||
|
||||
BaseTask::render_loading_glyph();
|
||||
}
|
||||
@@ -40,3 +40,13 @@ void TaskState::deactivate_state()
|
||||
FadeState::create_and_push(colors::DIM_BACKGROUND, colors::ALPHA_FADE_END, colors::ALPHA_FADE_BEGIN, nullptr);
|
||||
BaseState::deactivate();
|
||||
}
|
||||
|
||||
// ---- Private Functions ----
|
||||
|
||||
void TaskState::initialize_static_members()
|
||||
{
|
||||
if (sm_font) { return; }
|
||||
|
||||
sm_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_PIXEL,
|
||||
graphics::fonts::sizes::TWENTY_PIXEL);
|
||||
}
|
||||
@@ -7,58 +7,63 @@
|
||||
#include "config/config.hpp"
|
||||
#include "fs/save_mount.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "graphics/targets.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "sdl.hpp"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace
|
||||
{
|
||||
// All of these states share this same target.
|
||||
constexpr std::string_view SECONDARY_TARGET = "SecondaryTarget";
|
||||
} // namespace
|
||||
|
||||
// ---- Construction ----
|
||||
|
||||
TextTitleSelectState::TextTitleSelectState(data::User *user)
|
||||
: TitleSelectCommon()
|
||||
, m_user(user)
|
||||
, m_titleSelectMenu(ui::Menu::create(32, 10, 1000, 23, 555))
|
||||
, m_renderTarget(sdl::TextureManager::load(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET))
|
||||
{
|
||||
TextTitleSelectState::refresh();
|
||||
}
|
||||
, m_renderTarget(sdl2::TextureManager::create_load_resource(graphics::targets::names::SECONDARY,
|
||||
graphics::targets::dims::SECONDARY_WIDTH,
|
||||
graphics::targets::dims::SECONDARY_HEIGHT,
|
||||
SDL_TEXTUREACCESS_TARGET))
|
||||
{ TextTitleSelectState::refresh(); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void TextTitleSelectState::update()
|
||||
void TextTitleSelectState::update(const sdl2::Input &input)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input::button_pressed(HidNpadButton_X);
|
||||
const bool yPressed = input::button_pressed(HidNpadButton_Y);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input.button_pressed(HidNpadButton_X);
|
||||
const bool yPressed = input.button_pressed(HidNpadButton_Y);
|
||||
|
||||
m_titleSelectMenu->update(hasFocus);
|
||||
m_titleSelectMenu->update(input, hasFocus);
|
||||
|
||||
if (aPressed) { TextTitleSelectState::create_backup_menu(); }
|
||||
else if (xPressed) { TextTitleSelectState::create_title_option_menu(); }
|
||||
else if (yPressed) { TextTitleSelectState::add_remove_favorite(); }
|
||||
else if (bPressed) { BaseState::deactivate(); }
|
||||
|
||||
sm_controlGuide->update(hasFocus);
|
||||
sm_controlGuide->update(input, hasFocus);
|
||||
}
|
||||
|
||||
void TextTitleSelectState::render()
|
||||
void TextTitleSelectState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Grab focus.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
m_renderTarget->clear(colors::TRANSPARENT);
|
||||
m_titleSelectMenu->render(m_renderTarget, hasFocus);
|
||||
sm_controlGuide->render(sdl::Texture::Null, hasFocus);
|
||||
m_renderTarget->render(sdl::Texture::Null, 201, 91);
|
||||
{
|
||||
// Switch targets, clear.
|
||||
graphics::ScopedRender scopedRender{renderer, m_renderTarget};
|
||||
renderer.frame_begin(colors::TRANSPARENT);
|
||||
|
||||
// Render menu to target.
|
||||
m_titleSelectMenu->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
// Switch back, render target and guide.
|
||||
m_renderTarget->render(201, 91);
|
||||
sm_controlGuide->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
void TextTitleSelectState::refresh()
|
||||
@@ -77,7 +82,10 @@ void TextTitleSelectState::refresh()
|
||||
|
||||
std::string option{};
|
||||
if (favorite) { option = std::string{STRING_HEART} + title; }
|
||||
else { option = title; }
|
||||
else
|
||||
{
|
||||
option = title;
|
||||
}
|
||||
|
||||
m_titleSelectMenu->add_option(option);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "error.hpp"
|
||||
#include "fs/save_data_functions.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "sdl.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
#include "stringutil.hpp"
|
||||
@@ -36,8 +35,8 @@ namespace
|
||||
} // namespace
|
||||
|
||||
// Defined at bottom
|
||||
static inline std::shared_ptr<ui::TextScroll> create_new_field(std::string_view text, int x, int y, sdl::Color clear);
|
||||
static inline std::shared_ptr<ui::TextScroll> create_new_field(std::string &text, int x, int y, sdl::Color clear);
|
||||
static inline std::shared_ptr<ui::TextScroll> create_new_field(std::string_view text, int x, int y, SDL_Color clear);
|
||||
static inline std::shared_ptr<ui::TextScroll> create_new_field(std::string &text, int x, int y, SDL_Color clear);
|
||||
static bool is_a_best_game(uint64_t applicationID) noexcept;
|
||||
|
||||
// ---- Construction ----
|
||||
@@ -65,35 +64,34 @@ TitleInfoState::TitleInfoState(data::User *user, data::TitleInfo *titleInfo, con
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void TitleInfoState::update()
|
||||
void TitleInfoState::update(const sdl2::Input &input)
|
||||
{
|
||||
switch (m_state)
|
||||
{
|
||||
case State::Opening:
|
||||
case State::Closing: TitleInfoState::update_dimensions(); break;
|
||||
case State::Displaying: TitleInfoState::update_handle_input(); break;
|
||||
case State::Displaying: TitleInfoState::update_handle_input(input); break;
|
||||
}
|
||||
}
|
||||
|
||||
void TitleInfoState::render()
|
||||
void TitleInfoState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Grab cause needed everywhere.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
// Render the frame. Only continue further if we're currently displaying.
|
||||
sm_frame->render(sdl::Texture::Null, hasFocus);
|
||||
sm_frame->render(renderer, hasFocus);
|
||||
if (m_state != State::Displaying) { return; }
|
||||
|
||||
// We only want to render what's been triggered so far for the tiling in effect.
|
||||
for (int i = 0; i < m_fieldDisplayCount; i++) { m_infoFields[i]->render(sdl::Texture::Null, hasFocus); }
|
||||
for (int i = 0; i < m_fieldDisplayCount; i++) { m_infoFields[i]->render(renderer, hasFocus); }
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
|
||||
void TitleInfoState::initialize_static_members()
|
||||
{
|
||||
static constexpr std::string_view CHIME_NAME = "TitleInfoChime";
|
||||
static constexpr const char *CHIME_PATH = "romfs:/Sound/TitleInfo.wav";
|
||||
static constexpr std::string_view CHIME_PATH = "romfs:/Sound/TitleInfo.wav";
|
||||
|
||||
if (sm_frame && sm_openChime)
|
||||
{
|
||||
@@ -106,7 +104,7 @@ void TitleInfoState::initialize_static_members()
|
||||
const int width = m_transition.get_width();
|
||||
const int height = m_transition.get_height();
|
||||
sm_frame = ui::Frame::create(x, y, width, height);
|
||||
sm_openChime = sdl::SoundManager::load(CHIME_NAME, CHIME_PATH);
|
||||
sm_openChime = sdl2::SoundManager::create_load_resource(CHIME_PATH, CHIME_PATH);
|
||||
}
|
||||
|
||||
void TitleInfoState::initialize_info_fields()
|
||||
@@ -166,13 +164,13 @@ void TitleInfoState::create_title(int y)
|
||||
{
|
||||
std::string bestTitle = BESTEST_STAR + " " + title + " " + BESTEST_STAR;
|
||||
field = ui::TextScroll::create(bestTitle,
|
||||
X,
|
||||
y,
|
||||
WIDTH,
|
||||
TITLE_FIELD_HEIGHT,
|
||||
TITLE_FONT_SIZE,
|
||||
colors::WHITE,
|
||||
colors::TRANSPARENT);
|
||||
X,
|
||||
y,
|
||||
WIDTH,
|
||||
TITLE_FIELD_HEIGHT,
|
||||
TITLE_FONT_SIZE,
|
||||
colors::WHITE,
|
||||
colors::TRANSPARENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -377,7 +375,7 @@ void TitleInfoState::update_dimensions() noexcept
|
||||
else if (closed) { TitleInfoState::deactivate_state(); }
|
||||
}
|
||||
|
||||
void TitleInfoState::update_handle_input() noexcept
|
||||
void TitleInfoState::update_handle_input(const sdl2::Input &input) noexcept
|
||||
{
|
||||
// Grab a cache this since it's needed a lot.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
@@ -387,14 +385,14 @@ void TitleInfoState::update_handle_input() noexcept
|
||||
if (m_fieldDisplayCount < currentCount && m_timer.is_triggered()) { ++m_fieldDisplayCount; }
|
||||
|
||||
// Update the actually displayed fields so the text scrolls if need be.
|
||||
for (int i = 0; i < m_fieldDisplayCount; i++) { m_infoFields[i]->update(hasFocus); }
|
||||
for (int i = 0; i < m_fieldDisplayCount; i++) { m_infoFields[i]->update(input, hasFocus); }
|
||||
|
||||
// Input bools.
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
if (bPressed) { TitleInfoState::close(); }
|
||||
}
|
||||
|
||||
inline sdl::Color TitleInfoState::get_field_color() noexcept
|
||||
inline SDL_Color TitleInfoState::get_field_color() noexcept
|
||||
{
|
||||
m_fieldClearSwitch = m_fieldClearSwitch ? false : true;
|
||||
return m_fieldClearSwitch ? colors::DIALOG_DARK : colors::CLEAR_COLOR;
|
||||
@@ -411,15 +409,11 @@ void TitleInfoState::deactivate_state() { BaseState::deactivate(); }
|
||||
|
||||
// ---- Static functions ----
|
||||
|
||||
static inline std::shared_ptr<ui::TextScroll> create_new_field(std::string_view text, int x, int y, sdl::Color clear)
|
||||
{
|
||||
return ui::TextScroll::create(text, x, y, SIZE_FIELD_WIDTH, SIZE_FIELD_HEIGHT, SIZE_FONT, colors::WHITE, clear, false);
|
||||
}
|
||||
static inline std::shared_ptr<ui::TextScroll> create_new_field(std::string_view text, int x, int y, SDL_Color clear)
|
||||
{ return ui::TextScroll::create(text, x, y, SIZE_FIELD_WIDTH, SIZE_FIELD_HEIGHT, SIZE_FONT, colors::WHITE, clear, false); }
|
||||
|
||||
static inline std::shared_ptr<ui::TextScroll> create_new_field(std::string &text, int x, int y, sdl::Color clear)
|
||||
{
|
||||
return ui::TextScroll::create(text, x, y, SIZE_FIELD_WIDTH, SIZE_FIELD_HEIGHT, SIZE_FONT, colors::WHITE, clear, false);
|
||||
}
|
||||
static inline std::shared_ptr<ui::TextScroll> create_new_field(std::string &text, int x, int y, SDL_Color clear)
|
||||
{ return ui::TextScroll::create(text, x, y, SIZE_FIELD_WIDTH, SIZE_FIELD_HEIGHT, SIZE_FONT, colors::WHITE, clear, false); }
|
||||
|
||||
static bool is_a_best_game(uint64_t applicationID) noexcept
|
||||
{
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "fs/fs.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "keyboard/keyboard.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "remote/remote.hpp"
|
||||
@@ -58,16 +57,16 @@ TitleOptionState::TitleOptionState(data::User *user,
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void TitleOptionState::update()
|
||||
void TitleOptionState::update(const sdl2::Input &input)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
sm_slidePanel->unhide_on_focus(hasFocus);
|
||||
sm_slidePanel->update(hasFocus);
|
||||
sm_slidePanel->update(input, hasFocus);
|
||||
|
||||
const bool isOpen = sm_slidePanel->is_open();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
const int selected = sm_titleOptionMenu->get_selected();
|
||||
|
||||
if (m_refreshRequired)
|
||||
@@ -103,12 +102,13 @@ void TitleOptionState::update()
|
||||
|
||||
void TitleOptionState::sub_update() { sm_slidePanel->sub_update(); }
|
||||
|
||||
void TitleOptionState::render()
|
||||
void TitleOptionState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Grab focus.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
sm_slidePanel->clear_target();
|
||||
sm_slidePanel->render(sdl::Texture::Null, hasFocus);
|
||||
// Render panel.
|
||||
sm_slidePanel->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
void TitleOptionState::close_on_update() { m_exitRequired = true; }
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
#include "appstates/MainMenuState.hpp"
|
||||
#include "appstates/TitleOptionState.hpp"
|
||||
#include "config/config.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "graphics/targets.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "sdl.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
@@ -24,21 +25,23 @@ namespace
|
||||
TitleSelectState::TitleSelectState(data::User *user)
|
||||
: TitleSelectCommon()
|
||||
, m_user(user)
|
||||
, m_renderTarget(sdl::TextureManager::load(SECONDARY_TARGET, 1080, 555, SDL_TEXTUREACCESS_TARGET))
|
||||
, m_renderTarget(sdl2::TextureManager::create_load_resource(graphics::targets::names::SECONDARY,
|
||||
graphics::targets::dims::SECONDARY_WIDTH,
|
||||
graphics::targets::dims::SECONDARY_HEIGHT,
|
||||
SDL_TEXTUREACCESS_TARGET))
|
||||
, m_titleView(ui::TitleView::create(m_user)) {};
|
||||
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void TitleSelectState::update()
|
||||
void TitleSelectState::update(const sdl2::Input &input)
|
||||
{
|
||||
if (!TitleSelectState::title_count_check()) { return; }
|
||||
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input::button_pressed(HidNpadButton_X);
|
||||
const bool yPressed = input::button_pressed(HidNpadButton_Y);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
const bool xPressed = input.button_pressed(HidNpadButton_X);
|
||||
const bool yPressed = input.button_pressed(HidNpadButton_Y);
|
||||
|
||||
if (aPressed) { TitleSelectState::create_backup_menu(); }
|
||||
else if (xPressed) { TitleSelectState::create_title_option_menu(); }
|
||||
@@ -49,18 +52,26 @@ void TitleSelectState::update()
|
||||
return;
|
||||
}
|
||||
|
||||
m_titleView->update(hasFocus);
|
||||
sm_controlGuide->update(hasFocus);
|
||||
m_titleView->update(input, hasFocus);
|
||||
sm_controlGuide->update(input, hasFocus);
|
||||
}
|
||||
|
||||
void TitleSelectState::render()
|
||||
void TitleSelectState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Grab focus status.
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
|
||||
m_renderTarget->clear(colors::TRANSPARENT);
|
||||
m_titleView->render(m_renderTarget, hasFocus);
|
||||
sm_controlGuide->render(sdl::Texture::Null, hasFocus);
|
||||
m_renderTarget->render(sdl::Texture::Null, 201, 91);
|
||||
{
|
||||
// Set target, clear.
|
||||
graphics::ScopedRender scopedRender{renderer, m_renderTarget};
|
||||
renderer.frame_begin(colors::TRANSPARENT);
|
||||
|
||||
// Render view.
|
||||
m_titleView->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
m_renderTarget->render(201, 91);
|
||||
sm_controlGuide->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
void TitleSelectState::refresh() { m_titleView->refresh(); }
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "error.hpp"
|
||||
#include "fs/fs.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "input.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "remote/remote.hpp"
|
||||
#include "strings/strings.hpp"
|
||||
@@ -49,15 +48,15 @@ UserOptionState::UserOptionState(data::User *user, TitleSelectCommon *titleSelec
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void UserOptionState::update()
|
||||
void UserOptionState::update(const sdl2::Input &input)
|
||||
{
|
||||
const bool hasFocus = BaseState::has_focus();
|
||||
const bool aPressed = input::button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool aPressed = input.button_pressed(HidNpadButton_A);
|
||||
const bool bPressed = input.button_pressed(HidNpadButton_B);
|
||||
|
||||
// Start by running the unhide check routine and then update the panel.
|
||||
sm_menuPanel->unhide_on_focus(hasFocus);
|
||||
sm_menuPanel->update(hasFocus);
|
||||
sm_menuPanel->update(input, hasFocus);
|
||||
|
||||
// Refresh here if needed to avoid threading issues.
|
||||
if (m_refreshRequired)
|
||||
@@ -86,14 +85,13 @@ void UserOptionState::update()
|
||||
|
||||
void UserOptionState::sub_update() { sm_menuPanel->sub_update(); }
|
||||
|
||||
void UserOptionState::render()
|
||||
void UserOptionState::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
// Render target user's title selection screen.
|
||||
m_titleSelect->render();
|
||||
m_titleSelect->render(renderer);
|
||||
|
||||
// Render panel.
|
||||
sm_menuPanel->clear_target();
|
||||
sm_menuPanel->render(sdl::Texture::Null, BaseState::has_focus());
|
||||
sm_menuPanel->render(renderer, BaseState::has_focus());
|
||||
}
|
||||
|
||||
void UserOptionState::refresh_required() { m_refreshRequired = true; }
|
||||
|
||||
@@ -104,7 +104,8 @@ void data::DataContext::load_application_records(sys::Task *task)
|
||||
NsApplicationRecord record{};
|
||||
|
||||
bool listError{};
|
||||
do {
|
||||
do
|
||||
{
|
||||
listError = error::libnx(nsListApplicationRecord(&record, 1, offset++, &count)) || count <= 0;
|
||||
if (listError) { break; }
|
||||
if (DataContext::title_is_loaded(record.application_id)) { continue; }
|
||||
@@ -217,7 +218,8 @@ bool data::DataContext::read_cache(sys::Task *task)
|
||||
task->set_status(statusLoadingCache);
|
||||
|
||||
NsApplicationControlData controlData{};
|
||||
do {
|
||||
do
|
||||
{
|
||||
const bool dataRead = cacheZip.read(&controlData, SIZE_CTRL_DATA) == SIZE_CTRL_DATA;
|
||||
if (!dataRead) { continue; }
|
||||
|
||||
@@ -270,9 +272,9 @@ bool data::DataContext::write_cache(sys::Task *task)
|
||||
return true;
|
||||
}
|
||||
|
||||
void data::DataContext::process_icon_queue()
|
||||
void data::DataContext::process_icon_queue(sdl2::Renderer &renderer)
|
||||
{
|
||||
std::lock_guard multiGuard{m_iconQueueMutex};
|
||||
for (data::DataCommon *common : m_iconQueue) { common->load_icon(); }
|
||||
for (data::DataCommon *common : m_iconQueue) { common->load_icon(renderer); }
|
||||
m_iconQueue.clear();
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ data::TitleInfo::TitleInfo(uint64_t applicationID) noexcept
|
||||
// This will filter from even trying to fetch control data for system titles.
|
||||
const bool isSystem = applicationID & 0x8000000000000000;
|
||||
const bool getError = !isSystem && error::libnx(nsGetApplicationControlData(NsApplicationControlSource_Storage,
|
||||
m_applicationID,
|
||||
&m_data,
|
||||
SIZE_CTRL_DATA,
|
||||
&controlSize));
|
||||
m_applicationID,
|
||||
&m_data,
|
||||
SIZE_CTRL_DATA,
|
||||
&controlSize));
|
||||
const bool entryError = !getError && error::libnx(nacpGetLanguageEntry(&m_data.nacp, &m_entry));
|
||||
if (isSystem || getError)
|
||||
{
|
||||
@@ -149,8 +149,6 @@ bool data::TitleInfo::has_save_data_type(uint8_t saveType) const noexcept
|
||||
return false;
|
||||
}
|
||||
|
||||
sdl::SharedTexture data::TitleInfo::get_icon() const noexcept { return m_icon; }
|
||||
|
||||
void data::TitleInfo::set_path_safe_title(const char *newPathSafe) noexcept
|
||||
{
|
||||
const size_t length = std::char_traits<char>::length(newPathSafe);
|
||||
@@ -160,20 +158,16 @@ void data::TitleInfo::set_path_safe_title(const char *newPathSafe) noexcept
|
||||
std::memcpy(m_pathSafeTitle, newPathSafe, length);
|
||||
}
|
||||
|
||||
void data::TitleInfo::load_icon()
|
||||
void data::TitleInfo::load_icon(sdl2::Renderer &renderer)
|
||||
{
|
||||
// This is taken from the NacpStruct.
|
||||
static constexpr size_t SIZE_ICON = 0x20000;
|
||||
const std::string textureName = stringutil::get_formatted_string("%04X", m_applicationID & 0xFFFF);
|
||||
|
||||
if (m_hasData)
|
||||
{
|
||||
const std::string textureName = stringutil::get_formatted_string("%016llX", m_applicationID);
|
||||
m_icon = sdl::TextureManager::load(textureName, m_data.icon, SIZE_ICON);
|
||||
}
|
||||
if (m_hasData) { m_icon = sdl2::TextureManager::create_load_resource(textureName, m_data.icon, SIZE_ICON); }
|
||||
else
|
||||
{
|
||||
const std::string text = stringutil::get_formatted_string("%04X", m_applicationID & 0xFFFF);
|
||||
m_icon = gfxutil::create_generic_icon(text, 48, colors::DIALOG_DARK, colors::WHITE);
|
||||
m_icon = gfxutil::create_generic_icon(renderer, textureName, 48, colors::DIALOG_DARK, colors::WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,10 @@ data::User::User(AccountUid accountID, FsSaveDataType saveType) noexcept
|
||||
const bool profileError = error::libnx(accountGetProfile(&profile, m_accountID));
|
||||
const bool baseError = !profileError && error::libnx(accountProfileGet(&profile, nullptr, &profileBase));
|
||||
if (profileError || baseError) { User::create_account(); }
|
||||
else { User::load_account(profile, profileBase); }
|
||||
else
|
||||
{
|
||||
User::load_account(profile, profileBase);
|
||||
}
|
||||
accountProfileClose(&profile);
|
||||
}
|
||||
|
||||
@@ -174,7 +177,10 @@ void data::User::load_user_data()
|
||||
{
|
||||
infoReader.open(SAVE_DATA_SPACE_ORDER[i], m_accountID, SIZE_SAVE_INFO_BUFFER);
|
||||
}
|
||||
else { infoReader.open(SAVE_DATA_SPACE_ORDER[i], m_saveType, SIZE_SAVE_INFO_BUFFER); }
|
||||
else
|
||||
{
|
||||
infoReader.open(SAVE_DATA_SPACE_ORDER[i], m_saveType, SIZE_SAVE_INFO_BUFFER);
|
||||
}
|
||||
if (!infoReader.is_open()) { continue; }
|
||||
|
||||
while (infoReader.read())
|
||||
@@ -218,7 +224,7 @@ void data::User::load_user_data()
|
||||
User::sort_data();
|
||||
}
|
||||
|
||||
void data::User::load_icon()
|
||||
void data::User::load_icon(sdl2::Renderer &renderer)
|
||||
{
|
||||
const std::string iconName =
|
||||
stringutil::get_formatted_string("%016llX%016llX", m_nickname, m_accountID.uid[0], m_accountID.uid[1]);
|
||||
@@ -230,7 +236,7 @@ void data::User::load_icon()
|
||||
const bool sizeError = !profileError && error::libnx(accountProfileGetImageSize(&profile, &iconSize));
|
||||
if (profileError || sizeError)
|
||||
{
|
||||
m_icon = gfxutil::create_generic_icon(m_nickname, SIZE_ICON_FONT, colors::DIALOG_DARK, colors::WHITE);
|
||||
m_icon = gfxutil::create_generic_icon(renderer, m_nickname, SIZE_ICON_FONT, colors::DIALOG_DARK, colors::WHITE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,9 +245,12 @@ void data::User::load_icon()
|
||||
if (loadError) { return; }
|
||||
|
||||
accountProfileClose(&profile);
|
||||
m_icon = sdl::TextureManager::load(iconName, iconBuffer.get(), iconSize);
|
||||
m_icon = sdl2::TextureManager::create_load_resource(iconName, iconBuffer.get(), iconSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_icon = gfxutil::create_generic_icon(renderer, m_nickname, SIZE_ICON_FONT, colors::DIALOG_DARK, colors::WHITE);
|
||||
}
|
||||
else { m_icon = gfxutil::create_generic_icon(m_nickname, SIZE_ICON_FONT, colors::DIALOG_DARK, colors::WHITE); }
|
||||
}
|
||||
|
||||
void data::User::load_account(AccountProfile &profile, AccountProfileBase &profileBase)
|
||||
|
||||
@@ -25,21 +25,19 @@ namespace
|
||||
/// @brief The main routine for the task to load data.
|
||||
static void data_initialize_task(sys::threadpool::JobData taskData);
|
||||
|
||||
void data::launch_initialization(bool clearCache, std::function<void()> onDestruction)
|
||||
void data::launch_initialization(bool clearCache, sdl2::Renderer &renderer, std::function<void()> onDestruction)
|
||||
{
|
||||
auto taskData = std::make_shared<StateDataStruct>();
|
||||
taskData->clearCache = clearCache;
|
||||
|
||||
auto loadingState = DataLoadingState::create(s_context, onDestruction, data_initialize_task, taskData);
|
||||
auto loadingState = DataLoadingState::create(s_context, renderer, onDestruction, data_initialize_task, taskData);
|
||||
StateManager::push_state(loadingState);
|
||||
}
|
||||
|
||||
void data::get_users(data::UserList &userList) { s_context.get_users(userList); }
|
||||
|
||||
data::TitleInfo *data::get_title_info_by_id(uint64_t applicationID) noexcept
|
||||
{
|
||||
return s_context.get_title_by_id(applicationID);
|
||||
}
|
||||
{ return s_context.get_title_by_id(applicationID); }
|
||||
|
||||
void data::load_title_to_map(uint64_t applicationID) { s_context.load_title(applicationID); }
|
||||
|
||||
@@ -48,9 +46,7 @@ bool data::title_exists_in_map(uint64_t applicationID) noexcept { return s_conte
|
||||
void data::get_title_info_list(data::TitleInfoList &listOut) { s_context.get_title_info_list(listOut); }
|
||||
|
||||
void data::get_title_info_by_type(FsSaveDataType saveType, data::TitleInfoList &listOut)
|
||||
{
|
||||
s_context.get_title_info_list_by_type(saveType, listOut);
|
||||
}
|
||||
{ s_context.get_title_info_list_by_type(saveType, listOut); }
|
||||
|
||||
static void data_initialize_task(sys::threadpool::JobData taskData)
|
||||
{
|
||||
|
||||
@@ -1,28 +1,41 @@
|
||||
#include "graphics/gfxutil.hpp"
|
||||
|
||||
namespace
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "stringutil.hpp"
|
||||
|
||||
sdl2::SharedTexture gfxutil::create_generic_icon(sdl2::Renderer &renderer,
|
||||
std::string_view text,
|
||||
int fontSize,
|
||||
SDL_Color background,
|
||||
SDL_Color textColor)
|
||||
{
|
||||
/// @brief Width of generic icons in pixels.
|
||||
constexpr int SIZE_ICON_WIDTH = 256;
|
||||
// Icon dimensions.
|
||||
static constexpr int ICON_WIDTH = 256;
|
||||
static constexpr int ICON_HEIGHT = 256;
|
||||
|
||||
/// @brief Height of generic icons in pixels.
|
||||
constexpr int SIZE_ICON_HEIGHT = 256;
|
||||
} // namespace
|
||||
// Create a new font to render with.
|
||||
const std::string fontName = stringutil::get_formatted_string("IconFont%i", fontSize);
|
||||
sdl2::SharedFont font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(fontName, fontSize);
|
||||
|
||||
sdl::SharedTexture gfxutil::create_generic_icon(std::string_view text,
|
||||
int fontSize,
|
||||
sdl::Color background,
|
||||
sdl::Color foreground)
|
||||
{
|
||||
// Create base icon texture.
|
||||
sdl::SharedTexture icon = sdl::TextureManager::load(text, SIZE_ICON_WIDTH, SIZE_ICON_HEIGHT, SDL_TEXTUREACCESS_TARGET);
|
||||
// Center our text.
|
||||
const int textWidth = font->get_text_width(text);
|
||||
const int textX = math::Util<int>::center_within(ICON_WIDTH, textWidth);
|
||||
const int textY = math::Util<int>::center_within(ICON_HEIGHT, fontSize);
|
||||
|
||||
// Get the centered X and Y coordinates.
|
||||
const int textX = (SIZE_ICON_WIDTH / 2) - (sdl::text::get_width(fontSize, text) / 2);
|
||||
const int textY = (SIZE_ICON_HEIGHT / 2) - (fontSize / 2);
|
||||
// Create the icon.
|
||||
sdl2::SharedTexture icon =
|
||||
sdl2::TextureManager::create_load_resource(text, ICON_WIDTH, ICON_HEIGHT, SDL_TEXTUREACCESS_TARGET);
|
||||
|
||||
icon->clear(background);
|
||||
sdl::text::render(icon, textX, textY, fontSize, sdl::text::NO_WRAP, foreground, text);
|
||||
{
|
||||
// Target the icon we just created.
|
||||
graphics::ScopedRender scopedRender(renderer, icon);
|
||||
|
||||
// Render.
|
||||
renderer.frame_begin(background);
|
||||
font->render_text(textX, textY, textColor, text);
|
||||
}
|
||||
|
||||
// Return.
|
||||
return icon;
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#include "input.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
PadState s_gamepad;
|
||||
}
|
||||
|
||||
void input::initialize()
|
||||
{
|
||||
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
|
||||
padInitializeDefault(&s_gamepad);
|
||||
}
|
||||
|
||||
void input::update() noexcept { padUpdate(&s_gamepad); }
|
||||
|
||||
bool input::button_pressed(HidNpadButton button) noexcept
|
||||
{
|
||||
return (s_gamepad.buttons_cur & button) && !(s_gamepad.buttons_old & button);
|
||||
}
|
||||
|
||||
bool input::button_held(HidNpadButton button) noexcept
|
||||
{
|
||||
return (s_gamepad.buttons_cur & button) && (s_gamepad.buttons_old & button);
|
||||
}
|
||||
|
||||
bool input::button_released(HidNpadButton button) noexcept
|
||||
{
|
||||
return (s_gamepad.buttons_old & button) && !(s_gamepad.buttons_cur & button);
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "StateManager.hpp"
|
||||
#include "appstates/TaskState.hpp"
|
||||
#include "error.hpp"
|
||||
#include "input.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "remote/GoogleDrive.hpp"
|
||||
#include "remote/WebDav.hpp"
|
||||
@@ -136,10 +135,6 @@ static void drive_sign_in(sys::threadpool::JobData taskData)
|
||||
|
||||
while (std::time(NULL) < expiration && !drive->poll_sign_in(deviceCode))
|
||||
{
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool bHeld = input::button_held(HidNpadButton_B);
|
||||
if (bPressed || bHeld) { break; }
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(pollingInterval));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,21 +16,26 @@ ui::BoundingBox::BoundingBox(int x, int y, int width, int height)
|
||||
, m_y(y)
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
{
|
||||
BoundingBox::initialize_static_members();
|
||||
}
|
||||
{ BoundingBox::initialize_static_members(); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ui::BoundingBox::update(bool hasFocus) { m_colorMod.update(); }
|
||||
void ui::BoundingBox::update(const sdl2::Input &input, bool hasFocus) { m_colorMod.update(); }
|
||||
|
||||
void ui::BoundingBox::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::BoundingBox::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
// Sizes of the pieces.
|
||||
static constexpr int CORNER_WIDTH = 8;
|
||||
static constexpr int CORNER_HEIGHT = 8;
|
||||
static constexpr int RECT_WIDTH = 4;
|
||||
static constexpr int RECT_HEIGHT = 4;
|
||||
|
||||
// Set texture color modifier.
|
||||
sm_corners->set_color_mod(m_colorMod);
|
||||
|
||||
const int rightX = (m_x + m_width) - CORNER_WIDTH;
|
||||
const int rightRectX = (m_x + m_width) - RECT_WIDTH;
|
||||
|
||||
// Calculating this all here maker the rest easier.
|
||||
const int rightX = (m_x + m_width) - CORNER_WIDTH;
|
||||
const int rightRectX = (m_x + m_width) - RECT_WIDTH;
|
||||
const int midX = m_x + CORNER_WIDTH;
|
||||
const int midY = m_y + CORNER_HEIGHT;
|
||||
const int midWidth = m_width - (CORNER_WIDTH * 2);
|
||||
@@ -38,16 +43,19 @@ void ui::BoundingBox::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
const int bottomY = (m_y + m_height) - CORNER_HEIGHT;
|
||||
const int bottomRectY = (m_y + m_height) - RECT_HEIGHT;
|
||||
|
||||
sm_corners->render_part(target, m_x, m_y, 0, 0, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
sdl::render_rect_fill(target, midX, m_y, midWidth, RECT_HEIGHT, m_colorMod);
|
||||
sm_corners->render_part(target, rightX, m_y, CORNER_HEIGHT, 0, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
// Top
|
||||
sm_corners->render_part(m_x, m_y, 0, 0, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
renderer.render_rectangle(midX, m_y, midWidth, RECT_HEIGHT, m_colorMod);
|
||||
sm_corners->render_part(rightX, m_y, CORNER_HEIGHT, 0, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
|
||||
// Middle
|
||||
sdl::render_rect_fill(target, m_x, midY, RECT_WIDTH, midHeight, m_colorMod);
|
||||
sdl::render_rect_fill(target, rightRectX, midY, RECT_WIDTH, midHeight, m_colorMod);
|
||||
renderer.render_rectangle(m_x, midY, RECT_WIDTH, midHeight, m_colorMod);
|
||||
renderer.render_rectangle(rightRectX, midY, RECT_WIDTH, midHeight, m_colorMod);
|
||||
|
||||
// Bottom
|
||||
sm_corners->render_part(target, m_x, bottomY, 0, CORNER_HEIGHT, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
sdl::render_rect_fill(target, midX, bottomRectY, midWidth, RECT_HEIGHT, m_colorMod);
|
||||
sm_corners->render_part(target, rightX, bottomY, CORNER_WIDTH, CORNER_HEIGHT, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
sm_corners->render_part(m_x, bottomY, 0, CORNER_HEIGHT, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
renderer.render_rectangle(midX, bottomRectY, midWidth, RECT_HEIGHT, m_colorMod);
|
||||
sm_corners->render_part(rightX, bottomY, CORNER_WIDTH, CORNER_HEIGHT, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
}
|
||||
|
||||
void ui::BoundingBox::set_x(int x) noexcept { m_x = x; }
|
||||
@@ -62,6 +70,9 @@ void ui::BoundingBox::set_height(int height) noexcept { m_height = height; }
|
||||
|
||||
void ui::BoundingBox::initialize_static_members()
|
||||
{
|
||||
// Path to load the corner texture from?
|
||||
static constexpr std::string_view CORNER_PATH = "romfs:/Textures/MenuBounding.png";
|
||||
|
||||
if (sm_corners) { return; }
|
||||
sm_corners = sdl::TextureManager::load("menuCorners", "romfs:/Textures/MenuBounding.png");
|
||||
sm_corners = sdl2::TextureManager::create_load_resource(CORNER_PATH, CORNER_PATH);
|
||||
}
|
||||
|
||||
@@ -10,11 +10,5 @@ void ui::ColorMod::update() noexcept
|
||||
else if (changeUp) { m_direction = true; }
|
||||
}
|
||||
|
||||
ui::ColorMod::operator sdl::Color() const noexcept
|
||||
{
|
||||
uint32_t color{};
|
||||
color |= static_cast<uint32_t>((0x88 + m_colorMod) << 16);
|
||||
color |= static_cast<uint64_t>((0xC5 + (m_colorMod / 2)) << 8);
|
||||
color |= 0xFF;
|
||||
return sdl::Color{color};
|
||||
}
|
||||
ui::ColorMod::operator SDL_Color() const noexcept
|
||||
{ return SDL_Color{0x00, static_cast<uint8_t>(0x88 + m_colorMod), static_cast<uint8_t>(0xC5 + m_colorMod * 0.5), 0xFF}; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ui/ControlGuide.hpp"
|
||||
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
|
||||
@@ -23,18 +24,21 @@ namespace
|
||||
|
||||
ui::ControlGuide::ControlGuide(const char *guide)
|
||||
: m_guide(guide)
|
||||
, m_textWidth(sdl::text::get_width(GUIDE_TEXT_SIZE, m_guide))
|
||||
, m_targetX(GUIDE_X_OFFSET - (m_textWidth + CONTAINER_PADDING))
|
||||
, m_guideWidth(graphics::SCREEN_WIDTH - m_targetX)
|
||||
, m_transition(graphics::SCREEN_WIDTH, TRANS_Y, 0, 0, m_targetX, TRANS_Y, 0, 0, ui::Transition::DEFAULT_THRESHOLD)
|
||||
, m_state(State::Hidden)
|
||||
{
|
||||
// Init static.
|
||||
ui::ControlGuide::initialize_static_members();
|
||||
|
||||
// Grab the width of the text.
|
||||
m_textWidth = sm_font->get_text_width(m_guide);
|
||||
}
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ui::ControlGuide::update(bool hasFocus)
|
||||
void ui::ControlGuide::update(const sdl2::Input &input, bool hasFocus)
|
||||
{
|
||||
switch (m_state)
|
||||
{
|
||||
@@ -46,42 +50,35 @@ void ui::ControlGuide::update(bool hasFocus)
|
||||
|
||||
void ui::ControlGuide::sub_update()
|
||||
{
|
||||
// To do: Maybe this differently?
|
||||
ControlGuide::update(false);
|
||||
// I don't like repeating, but it's the easiest way to adapt this for my SDL2 changes.
|
||||
switch (m_state)
|
||||
{
|
||||
case State::Opening:
|
||||
case State::Hiding: ControlGuide::update_position_state(); break;
|
||||
default: ControlGuide::update_state(false); break;
|
||||
}
|
||||
}
|
||||
|
||||
void ui::ControlGuide::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::ControlGuide::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
// These are for the rectangle that makes up the rest of the container.
|
||||
static constexpr int RECT_OFFSET_X = 16;
|
||||
static constexpr int RECT_HEIGHT = 48;
|
||||
|
||||
// This is where the text is rendered and its size.
|
||||
static constexpr int TEXT_OFFSET_X = 24;
|
||||
static constexpr int TEXT_OFFSET_Y = 10;
|
||||
static constexpr int TEXT_FONT_SIZE = 24;
|
||||
static constexpr int TEXT_OFFSET_X = 24;
|
||||
static constexpr int TEXT_OFFSET_Y = 10;
|
||||
|
||||
// Grab the X and Y.
|
||||
const int guideX = m_transition.get_x();
|
||||
const int guideY = m_transition.get_y();
|
||||
|
||||
// Render the cap and the rectangle.
|
||||
sm_controlCap->render(sdl::Texture::Null, guideX, guideY);
|
||||
sdl::render_rect_fill(sdl::Texture::Null,
|
||||
guideX + RECT_OFFSET_X,
|
||||
guideY,
|
||||
m_guideWidth - RECT_OFFSET_X,
|
||||
RECT_HEIGHT,
|
||||
colors::GUIDE_COLOR);
|
||||
sm_controlCap->render(guideX, guideY);
|
||||
renderer.render_rectangle(guideX + RECT_OFFSET_X, guideY, m_guideWidth - RECT_OFFSET_X, RECT_HEIGHT, colors::GUIDE_COLOR);
|
||||
|
||||
// Guide text.
|
||||
sdl::text::render(sdl::Texture::Null,
|
||||
guideX + TEXT_OFFSET_X,
|
||||
guideY + TEXT_OFFSET_Y,
|
||||
TEXT_FONT_SIZE,
|
||||
sdl::text::NO_WRAP,
|
||||
colors::WHITE,
|
||||
m_guide);
|
||||
sm_font->render_text(guideX + TEXT_OFFSET_X, guideY + TEXT_OFFSET_Y, colors::WHITE, m_guide);
|
||||
}
|
||||
|
||||
// ---- Private functions ----
|
||||
@@ -89,11 +86,14 @@ void ui::ControlGuide::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::ControlGuide::initialize_static_members()
|
||||
{
|
||||
// Name for the texture manager.
|
||||
static constexpr std::string_view NAME_CAP = "ControlGuideCap";
|
||||
static constexpr std::string_view CAP_PATH = "romfs:/Textures/GuideCap.png";
|
||||
|
||||
// If it's already loaded, return.
|
||||
if (sm_controlCap) { return; }
|
||||
sm_controlCap = sdl::TextureManager::load(NAME_CAP, "romfs:/Textures/GuideCap.png");
|
||||
if (sm_controlCap && sm_font) { return; }
|
||||
|
||||
sm_controlCap = sdl2::TextureManager::create_load_resource(CAP_PATH, CAP_PATH);
|
||||
sm_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_FOUR_PIXEL,
|
||||
graphics::fonts::sizes::TWENTY_FOUR_PIXEL);
|
||||
}
|
||||
|
||||
void ui::ControlGuide::reset() noexcept
|
||||
|
||||
@@ -16,36 +16,32 @@ ui::DialogBox::DialogBox(int x, int y, int width, int height, ui::DialogBox::Typ
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
, m_type(type)
|
||||
{
|
||||
ui::DialogBox::initialize_static_members();
|
||||
}
|
||||
{ ui::DialogBox::initialize_static_members(); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ui::DialogBox::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::DialogBox::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
const bool darkDialog = m_type == DialogBox::Type::Dark;
|
||||
sdl::SharedTexture &corners = darkDialog ? sm_darkCorners : sm_lightCorners;
|
||||
const sdl::Color rectColor = darkDialog ? colors::DIALOG_DARK : colors::DIALOG_LIGHT;
|
||||
const bool darkDialog = m_type == DialogBox::Type::Dark;
|
||||
sdl2::SharedTexture &corners = darkDialog ? sm_darkCorners : sm_lightCorners;
|
||||
const SDL_Color rectColor = darkDialog ? colors::DIALOG_DARK : colors::DIALOG_LIGHT;
|
||||
|
||||
// Top
|
||||
corners->render_part(target, m_x, m_y, 0, 0, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
sdl::render_rect_fill(target, m_x + CORNER_WIDTH, m_y, m_width - (CORNER_WIDTH * 2), CORNER_HEIGHT, rectColor);
|
||||
corners->render_part(target, (m_x + m_width) - CORNER_WIDTH, m_y, CORNER_WIDTH, 0, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
corners->render_part(m_x, m_y, 0, 0, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
renderer.render_rectangle(m_x + CORNER_WIDTH, m_y, m_width - (CORNER_WIDTH * 2), CORNER_HEIGHT, rectColor);
|
||||
corners->render_part((m_x + m_width) - CORNER_WIDTH, m_y, CORNER_WIDTH, 0, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
|
||||
// Middle
|
||||
sdl::render_rect_fill(target, m_x, m_y + CORNER_HEIGHT, m_width, m_height - (CORNER_HEIGHT * 2), rectColor);
|
||||
renderer.render_rectangle(m_x, m_y + CORNER_HEIGHT, m_width, m_height - (CORNER_HEIGHT * 2), rectColor);
|
||||
|
||||
// Bottom
|
||||
corners->render_part(target, m_x, (m_y + m_height) - CORNER_HEIGHT, 0, CORNER_HEIGHT, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
sdl::render_rect_fill(target,
|
||||
m_x + CORNER_WIDTH,
|
||||
(m_y + m_height) - CORNER_HEIGHT,
|
||||
m_width - (CORNER_WIDTH * 2),
|
||||
CORNER_HEIGHT,
|
||||
rectColor);
|
||||
corners->render_part(target,
|
||||
(m_x + m_width) - CORNER_WIDTH,
|
||||
corners->render_part(m_x, (m_y + m_height) - CORNER_HEIGHT, 0, CORNER_HEIGHT, CORNER_WIDTH, CORNER_HEIGHT);
|
||||
renderer.render_rectangle(m_x + CORNER_WIDTH,
|
||||
(m_y + m_height) - CORNER_HEIGHT,
|
||||
m_width - (CORNER_WIDTH * 2),
|
||||
CORNER_HEIGHT,
|
||||
rectColor);
|
||||
corners->render_part((m_x + m_width) - CORNER_WIDTH,
|
||||
(m_y + m_height) - CORNER_HEIGHT,
|
||||
CORNER_WIDTH,
|
||||
CORNER_HEIGHT,
|
||||
@@ -78,8 +74,11 @@ void ui::DialogBox::set_from_transition(ui::Transition &transition, bool centere
|
||||
|
||||
void ui::DialogBox::initialize_static_members()
|
||||
{
|
||||
static constexpr std::string_view DARK_PATH = "romfs:/Textures/DialogCornersDark.png";
|
||||
static constexpr std::string_view LIGHT_PATH = "romfs:/Textures/DialogCornersLight.png";
|
||||
|
||||
if (sm_darkCorners && sm_lightCorners) { return; }
|
||||
|
||||
sm_darkCorners = sdl::TextureManager::load("darkCorners", "romfs:/Textures/DialogCornersDark.png");
|
||||
sm_lightCorners = sdl::TextureManager::load("lightCorners", "romfs:/Textures/DialogCornersLight.png");
|
||||
sm_darkCorners = sdl2::TextureManager::create_load_resource(DARK_PATH, DARK_PATH);
|
||||
sm_lightCorners = sdl2::TextureManager::create_load_resource(LIGHT_PATH, LIGHT_PATH);
|
||||
}
|
||||
|
||||
@@ -9,13 +9,11 @@ ui::Frame::Frame(int x, int y, int width, int height)
|
||||
, m_y(y)
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
{
|
||||
Frame::initialize_static_members();
|
||||
}
|
||||
{ Frame::initialize_static_members(); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ui::Frame::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::Frame::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
// This is the size of one of the "tiles" of the frame.
|
||||
static constexpr int TILE = 16;
|
||||
@@ -27,19 +25,19 @@ void ui::Frame::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
const int textureCorner = TILE * 2;
|
||||
|
||||
// Top.
|
||||
sm_frameCorners->render_part(target, m_x, m_y, 0, 0, TILE, TILE);
|
||||
sm_frameCorners->render_part_stretched(target, TILE, 0, TILE, TILE, m_x + TILE, m_y, midWidth, TILE);
|
||||
sm_frameCorners->render_part(target, rightEdge, m_y, 32, 0, TILE, TILE);
|
||||
sm_frameCorners->render_part(m_x, m_y, 0, 0, TILE, TILE);
|
||||
sm_frameCorners->render_part_stretched(TILE, 0, TILE, TILE, m_x + TILE, m_y, midWidth, TILE);
|
||||
sm_frameCorners->render_part(rightEdge, m_y, 32, 0, TILE, TILE);
|
||||
|
||||
// Middle
|
||||
sm_frameCorners->render_part_stretched(target, 0, TILE, TILE, TILE, m_x, m_y + TILE, TILE, midHeight);
|
||||
sdl::render_rect_fill(target, m_x + TILE, m_y + TILE, midWidth, midHeight, colors::SLIDE_PANEL_CLEAR);
|
||||
sm_frameCorners->render_part_stretched(target, textureCorner, TILE, TILE, TILE, rightEdge, m_y + TILE, TILE, midHeight);
|
||||
sm_frameCorners->render_part_stretched(0, TILE, TILE, TILE, m_x, m_y + TILE, TILE, midHeight);
|
||||
renderer.render_rectangle(m_x + TILE, m_y + TILE, midWidth, midHeight, colors::SLIDE_PANEL_CLEAR);
|
||||
sm_frameCorners->render_part_stretched(textureCorner, TILE, TILE, TILE, rightEdge, m_y + TILE, TILE, midHeight);
|
||||
|
||||
// Bottom
|
||||
sm_frameCorners->render_part(target, m_x, bottomEdge, 0, textureCorner, TILE, TILE);
|
||||
sm_frameCorners->render_part_stretched(target, TILE, textureCorner, TILE, TILE, m_x + TILE, bottomEdge, midWidth, TILE);
|
||||
sm_frameCorners->render_part(target, rightEdge, bottomEdge, textureCorner, textureCorner, TILE, TILE);
|
||||
sm_frameCorners->render_part(m_x, bottomEdge, 0, textureCorner, TILE, TILE);
|
||||
sm_frameCorners->render_part_stretched(TILE, textureCorner, TILE, TILE, m_x + TILE, bottomEdge, midWidth, TILE);
|
||||
sm_frameCorners->render_part(rightEdge, bottomEdge, textureCorner, textureCorner, TILE, TILE);
|
||||
}
|
||||
|
||||
void ui::Frame::set_x(int x) noexcept { m_x = x; }
|
||||
@@ -67,9 +65,8 @@ void ui::Frame::set_from_transition(const ui::Transition &transition, bool cente
|
||||
|
||||
void ui::Frame::initialize_static_members()
|
||||
{
|
||||
static constexpr std::string_view FRAME_NAME = "FrameCorners";
|
||||
static constexpr const char *FRAME_PATH = "romfs:/Textures/Frame.png";
|
||||
static constexpr std::string_view FRAME = "romfs:/Textures/Frame.png";
|
||||
|
||||
if (sm_frameCorners) { return; }
|
||||
sm_frameCorners = sdl::TextureManager::load(FRAME_NAME, FRAME_PATH);
|
||||
sm_frameCorners = sdl2::TextureManager::create_load_resource(FRAME, FRAME);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "ui/IconMenu.hpp"
|
||||
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
|
||||
namespace
|
||||
@@ -24,33 +25,38 @@ ui::IconMenu::IconMenu(int x, int y, int renderTargetHeight)
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ui::IconMenu::update(bool hasFocus) { Menu::update(hasFocus); }
|
||||
void ui::IconMenu::update(const sdl2::Input &input, bool hasFocus) { Menu::update(input, hasFocus); }
|
||||
|
||||
void ui::IconMenu::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::IconMenu::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
const int optionCount = m_options.size();
|
||||
const int y = m_transition.get_y();
|
||||
for (int i = 0, tempY = y; i < optionCount; i++, tempY += m_optionHeight)
|
||||
{
|
||||
// Clear target.
|
||||
m_optionTarget->clear(colors::TRANSPARENT);
|
||||
if (i == m_selected)
|
||||
// Set target, clear.
|
||||
{
|
||||
if (hasFocus)
|
||||
graphics::ScopedRender optionScope{renderer, m_optionTarget};
|
||||
renderer.frame_begin(colors::TRANSPARENT);
|
||||
if (i == m_selected)
|
||||
{
|
||||
m_boundingBox->set_x(m_x - 8);
|
||||
m_boundingBox->set_y(tempY - 8);
|
||||
m_boundingBox->render(target, hasFocus);
|
||||
if (hasFocus)
|
||||
{
|
||||
m_boundingBox->set_x(m_x - 8);
|
||||
m_boundingBox->set_y(tempY - 8);
|
||||
m_boundingBox->render(renderer, hasFocus);
|
||||
}
|
||||
// This is always rendered.
|
||||
renderer.render_rectangle(0, 0, 4, 130, colors::BLUE_GREEN);
|
||||
}
|
||||
// This is always rendered.
|
||||
sdl::render_rect_fill(m_optionTarget, 0, 0, 4, 130, colors::BLUE_GREEN);
|
||||
|
||||
m_options[i]->render_stretched(8, 1, ICON_RENDER_WIDTH, ICON_RENDER_HEIGHT);
|
||||
}
|
||||
m_options[i]->render_stretched(m_optionTarget, 8, 1, ICON_RENDER_WIDTH, ICON_RENDER_HEIGHT);
|
||||
m_optionTarget->render(target, m_x, tempY);
|
||||
|
||||
m_optionTarget->render(m_x, tempY);
|
||||
}
|
||||
}
|
||||
|
||||
void ui::IconMenu::add_option(sdl::SharedTexture newOption)
|
||||
void ui::IconMenu::add_option(sdl2::SharedTexture newOption)
|
||||
{
|
||||
Menu::add_option("ICON"); // Parent class needs text for this to work correctly.
|
||||
m_options.push_back(newOption);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "ui/Menu.hpp"
|
||||
|
||||
#include "config/config.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "ui/BoundingBox.hpp"
|
||||
|
||||
@@ -27,20 +27,20 @@ ui::Menu::Menu(int x, int y, int width, int fontSize, int renderTargetHeight)
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ui::Menu::update(bool hasFocus)
|
||||
void ui::Menu::update(const sdl2::Input &input, bool hasFocus)
|
||||
{
|
||||
if (m_options.empty()) { return; }
|
||||
|
||||
m_boundingBox->update(hasFocus);
|
||||
m_optionScroll->update(hasFocus);
|
||||
m_boundingBox->update(input, hasFocus);
|
||||
m_optionScroll->update(input, hasFocus);
|
||||
|
||||
Menu::handle_input();
|
||||
Menu::handle_input(input);
|
||||
Menu::update_scrolling();
|
||||
Menu::update_scroll_text();
|
||||
m_transition.update();
|
||||
}
|
||||
|
||||
void ui::Menu::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::Menu::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
if (m_options.empty()) { return; }
|
||||
|
||||
@@ -52,22 +52,29 @@ void ui::Menu::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
if (tempY < -m_fontSize) { continue; }
|
||||
else if (tempY > m_renderTargetHeight) { break; }
|
||||
|
||||
m_optionTarget->clear(colors::TRANSPARENT);
|
||||
|
||||
if (i == m_selected)
|
||||
{
|
||||
if (hasFocus)
|
||||
graphics::ScopedRender optionScoped{renderer, m_optionTarget};
|
||||
renderer.frame_begin(colors::TRANSPARENT);
|
||||
|
||||
if (i == m_selected)
|
||||
{
|
||||
m_boundingBox->set_x(m_x - 4);
|
||||
m_boundingBox->set_y(tempY - 4);
|
||||
m_boundingBox->render(target, hasFocus);
|
||||
if (hasFocus)
|
||||
{
|
||||
m_boundingBox->set_x(m_x - 4);
|
||||
m_boundingBox->set_y(tempY - 4);
|
||||
m_boundingBox->render(renderer, hasFocus);
|
||||
}
|
||||
renderer.render_rectangle(8, 8, 4, m_optionHeight - 12, colors::BLUE_GREEN);
|
||||
m_optionScroll->render(renderer, hasFocus);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_font->render_text(24, m_textY, colors::WHITE, m_options[i]);
|
||||
}
|
||||
sdl::render_rect_fill(m_optionTarget, 8, 8, 4, m_optionHeight - 12, colors::BLUE_GREEN);
|
||||
m_optionScroll->render(m_optionTarget, hasFocus);
|
||||
}
|
||||
else { sdl::text::render(m_optionTarget, 24, m_textY, m_fontSize, sdl::text::NO_WRAP, colors::WHITE, m_options[i]); }
|
||||
|
||||
// render target to target
|
||||
m_optionTarget->render(target, m_x, tempY);
|
||||
m_optionTarget->render(m_x, tempY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +151,8 @@ void ui::Menu::initialize_option_target()
|
||||
static int MENU_ID{};
|
||||
|
||||
const std::string optionTargetName = "MENU_TARGET_" + std::to_string(MENU_ID++);
|
||||
m_optionTarget = sdl::TextureManager::load(optionTargetName, m_width, m_optionHeight, SDL_TEXTUREACCESS_TARGET);
|
||||
m_optionTarget =
|
||||
sdl2::TextureManager::create_load_resource(optionTargetName, m_width, m_optionHeight, SDL_TEXTUREACCESS_TARGET);
|
||||
}
|
||||
|
||||
void ui::Menu::initialize_ui_elements()
|
||||
@@ -166,11 +174,10 @@ void ui::Menu::initialize_ui_elements()
|
||||
|
||||
void ui::Menu::initialize_sounds()
|
||||
{
|
||||
static constexpr std::string_view CURSOR_NAME = "MenuCursor";
|
||||
static constexpr const char *CURSOR_PATH = "romfs:/Sound/MenuCursor.wav";
|
||||
static constexpr std::string_view CURSOR_PATH = "romfs:/Sound/MenuCursor.wav";
|
||||
|
||||
if (sm_cursor) { return; }
|
||||
sm_cursor = sdl::SoundManager::load(CURSOR_NAME, CURSOR_PATH);
|
||||
sm_cursor = sdl2::SoundManager::create_load_resource(CURSOR_PATH, CURSOR_PATH);
|
||||
}
|
||||
|
||||
void ui::Menu::update_scroll_text()
|
||||
@@ -180,18 +187,18 @@ void ui::Menu::update_scroll_text()
|
||||
if (text != option) { m_optionScroll->set_text(std::string_view{option}, false); }
|
||||
}
|
||||
|
||||
void ui::Menu::handle_input()
|
||||
void ui::Menu::handle_input(const sdl2::Input &input)
|
||||
{
|
||||
// Get the length of the menu.
|
||||
const int optionsSize = m_options.size();
|
||||
|
||||
// Control bools.
|
||||
const bool upPressed = input::button_pressed(HidNpadButton_AnyUp);
|
||||
const bool downPressed = input::button_pressed(HidNpadButton_AnyDown);
|
||||
const bool leftPressed = input::button_pressed(HidNpadButton_AnyLeft);
|
||||
const bool rightPressed = input::button_pressed(HidNpadButton_AnyRight);
|
||||
const bool lShoulderPressed = input::button_pressed(HidNpadButton_L);
|
||||
const bool rShoulderPressed = input::button_pressed(HidNpadButton_R);
|
||||
const bool upPressed = input.button_pressed(HidNpadButton_AnyUp);
|
||||
const bool downPressed = input.button_pressed(HidNpadButton_AnyDown);
|
||||
const bool leftPressed = input.button_pressed(HidNpadButton_AnyLeft);
|
||||
const bool rightPressed = input.button_pressed(HidNpadButton_AnyRight);
|
||||
const bool lShoulderPressed = input.button_pressed(HidNpadButton_L);
|
||||
const bool rShoulderPressed = input.button_pressed(HidNpadButton_R);
|
||||
|
||||
// Wrapping conditions.
|
||||
const bool wrapEnd = upPressed && m_selected - 1 < 0;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "config/config.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/fonts.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "sdl.hpp"
|
||||
@@ -32,9 +33,7 @@ ui::PopMessage::PopMessage(int ticks, std::string &message)
|
||||
, m_ticks(ticks)
|
||||
, m_message(std::move(message))
|
||||
, m_state(State::Rising)
|
||||
{
|
||||
PopMessage::initialize_static_members();
|
||||
}
|
||||
{ PopMessage::initialize_static_members(); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
@@ -62,9 +61,9 @@ void ui::PopMessage::update(double targetY)
|
||||
}
|
||||
}
|
||||
|
||||
void ui::PopMessage::render()
|
||||
void ui::PopMessage::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
PopMessage::render_container();
|
||||
PopMessage::render_container(renderer);
|
||||
|
||||
// Don't continue unless the message is in place or it's not in its closing state.
|
||||
if (m_state != State::Opening && m_state != State::Displaying) { return; }
|
||||
@@ -72,7 +71,7 @@ void ui::PopMessage::render()
|
||||
// This avoids allocating and returning another std::string.
|
||||
const int y = m_transition.get_y();
|
||||
const std::string_view message{m_message.c_str(), static_cast<size_t>(m_substrOffset)};
|
||||
sdl::text::render(sdl::Texture::Null, m_textX, y + 11, FONT_SIZE, sdl::text::NO_WRAP, colors::BLACK, message);
|
||||
sm_font->render_text(m_textX, y + 11, colors::BLACK, message);
|
||||
}
|
||||
|
||||
bool ui::PopMessage::finished() const noexcept { return m_state == State::Finished; }
|
||||
@@ -83,12 +82,13 @@ std::string_view ui::PopMessage::get_message() const noexcept { return m_message
|
||||
|
||||
void ui::PopMessage::initialize_static_members()
|
||||
{
|
||||
static constexpr std::string_view TEX_CAP_NAME = "PopCaps";
|
||||
static constexpr const char *TEX_CAP_PATH = "romfs:/Textures/PopMessage.png";
|
||||
static constexpr std::string_view CAP_PATH = "romfs:/Textures/PopMessage.png";
|
||||
|
||||
if (sm_endCaps) { return; }
|
||||
if (sm_endCaps && sm_font) { return; }
|
||||
|
||||
sm_endCaps = sdl::TextureManager::load(TEX_CAP_NAME, TEX_CAP_PATH);
|
||||
sm_endCaps = sdl2::TextureManager::create_load_resource(CAP_PATH, CAP_PATH);
|
||||
sm_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(graphics::fonts::names::TWENTY_TWO_PIXEL,
|
||||
graphics::fonts::sizes::TWENTY_TWO_PIXEL);
|
||||
}
|
||||
|
||||
void ui::PopMessage::update_y() noexcept
|
||||
@@ -132,7 +132,7 @@ void ui::PopMessage::update_text_offset()
|
||||
|
||||
// Get the substring and calculate the updated width and X of the message.
|
||||
const std::string_view subString{m_message.c_str(), static_cast<size_t>(m_substrOffset)};
|
||||
const int subWidth = sdl::text::get_width(FONT_SIZE, subString);
|
||||
const int subWidth = sm_font->get_text_width(subString);
|
||||
const int containerWidth = subWidth + CONTAINER_PADDING;
|
||||
m_textX = SCREEN_CENTER - (subWidth / 2);
|
||||
|
||||
@@ -171,7 +171,7 @@ void ui::PopMessage::update_display_timer() noexcept
|
||||
}
|
||||
}
|
||||
|
||||
void ui::PopMessage::render_container() noexcept
|
||||
void ui::PopMessage::render_container(sdl2::Renderer &renderer) noexcept
|
||||
{
|
||||
// The width of the CAP graphics.
|
||||
constexpr int CAP_WIDTH = 48;
|
||||
@@ -183,7 +183,7 @@ void ui::PopMessage::render_container() noexcept
|
||||
const int width = m_transition.get_width() + CAP_HALF;
|
||||
|
||||
// Render the container.
|
||||
sm_endCaps->render_part(sdl::Texture::Null, x, y, 0, 0, CAP_HALF, CAP_WIDTH);
|
||||
sdl::render_rect_fill(sdl::Texture::Null, x + CAP_HALF, y, width - CAP_WIDTH, 48, colors::DIALOG_LIGHT);
|
||||
sm_endCaps->render_part(sdl::Texture::Null, x + (width - CAP_HALF), y, CAP_HALF, 0, CAP_HALF, 48);
|
||||
sm_endCaps->render_part(x, y, 0, 0, CAP_HALF, CAP_WIDTH);
|
||||
renderer.render_rectangle(x + CAP_HALF, y, width - CAP_WIDTH, 48, colors::DIALOG_LIGHT);
|
||||
sm_endCaps->render_part(x + (width - CAP_HALF), y, CAP_HALF, 0, CAP_HALF, 48);
|
||||
}
|
||||
|
||||
@@ -54,14 +54,14 @@ void ui::PopMessageManager::update()
|
||||
}
|
||||
}
|
||||
|
||||
void ui::PopMessageManager::render()
|
||||
void ui::PopMessageManager::render(sdl2::Renderer &renderer)
|
||||
{
|
||||
PopMessageManager &manager = PopMessageManager::get_instance();
|
||||
auto &messages = manager.m_messages;
|
||||
std::mutex &messageMutex = manager.m_messageMutex;
|
||||
|
||||
std::lock_guard<std::mutex> messageGuard{messageMutex};
|
||||
for (auto &message : messages) { message.render(); }
|
||||
for (auto &message : messages) { message.render(renderer); }
|
||||
}
|
||||
|
||||
void ui::PopMessageManager::push_message(int displayTicks, std::string_view message)
|
||||
@@ -118,10 +118,9 @@ void ui::PopMessageManager::push_message(int displayTicks, std::string &message)
|
||||
|
||||
void ui::PopMessageManager::initialize_pop_sound()
|
||||
{
|
||||
static constexpr std::string_view POP_NAME = "PopSound";
|
||||
static constexpr const char *POP_PATH = "romfs:/Sound/PopMessage.wav";
|
||||
static constexpr std::string_view POP_PATH = "romfs:/Sound/PopMessage.wav";
|
||||
|
||||
if (m_popSound) { return; }
|
||||
|
||||
m_popSound = sdl::SoundManager::load(POP_NAME, POP_PATH);
|
||||
m_popSound = sdl2::SoundManager::create_load_resource(POP_PATH, POP_PATH);
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "ui/SlideOutPanel.hpp"
|
||||
|
||||
#include "config/config.hpp"
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "graphics/screen.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "mathutil.hpp"
|
||||
#include "stringutil.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
@@ -25,38 +27,47 @@ ui::SlideOutPanel::SlideOutPanel(int width, Side side)
|
||||
0,
|
||||
ui::Transition::DEFAULT_THRESHOLD)
|
||||
, m_state(State::Opening)
|
||||
, m_renderTarget(sdl::TextureManager::load("PANEL_" + std::to_string(sm_targetID++),
|
||||
m_width,
|
||||
graphics::SCREEN_HEIGHT,
|
||||
SDL_TEXTUREACCESS_TARGET)) {};
|
||||
, m_renderTarget(sdl2::TextureManager::create_load_resource(stringutil::get_formatted_string("PANEL_%i", sm_targetID++),
|
||||
m_width,
|
||||
graphics::SCREEN_HEIGHT,
|
||||
SDL_TEXTUREACCESS_TARGET)) {};
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ui::SlideOutPanel::update(bool hasFocus)
|
||||
void ui::SlideOutPanel::update(const sdl2::Input &input, bool hasFocus)
|
||||
{
|
||||
switch (m_state)
|
||||
{
|
||||
case State::Opening:
|
||||
case State::Closing:
|
||||
case State::Hiding: SlideOutPanel::update_position_state(); break;
|
||||
case State::Opened: SlideOutPanel::update_sub_elements(hasFocus); break;
|
||||
case State::Opened: SlideOutPanel::update_sub_elements(input, hasFocus); break;
|
||||
default: return; // Nothing should take place in any other state.
|
||||
}
|
||||
}
|
||||
|
||||
void ui::SlideOutPanel::sub_update() { m_transition.update(); }
|
||||
|
||||
void ui::SlideOutPanel::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::SlideOutPanel::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
// Loop and render all sub-elements to the target.
|
||||
for (auto ¤tElement : m_elements) { currentElement->render(m_renderTarget, hasFocus); }
|
||||
{
|
||||
// Set target.
|
||||
graphics::ScopedRender scopedRender{renderer, m_renderTarget};
|
||||
|
||||
// Loop and render all sub-elements to the target.
|
||||
for (auto ¤tElement : m_elements) { currentElement->render(renderer, hasFocus); }
|
||||
}
|
||||
|
||||
// Render the main target to the target passed (most likely the screen);
|
||||
const int x = m_transition.get_x();
|
||||
m_renderTarget->render(target, x, 0);
|
||||
m_renderTarget->render(x, 0);
|
||||
}
|
||||
|
||||
void ui::SlideOutPanel::clear_target() { m_renderTarget->clear(colors::SLIDE_PANEL_CLEAR); }
|
||||
void ui::SlideOutPanel::clear_target(sdl2::Renderer &renderer)
|
||||
{
|
||||
graphics::ScopedRender scopedRender{renderer, m_renderTarget};
|
||||
renderer.frame_begin(colors::SLIDE_PANEL_CLEAR);
|
||||
}
|
||||
|
||||
void ui::SlideOutPanel::reset() noexcept
|
||||
{
|
||||
@@ -132,7 +143,7 @@ void ui::SlideOutPanel::push_new_element(std::shared_ptr<ui::Element> newElement
|
||||
|
||||
void ui::SlideOutPanel::clear_elements() { m_elements.clear(); }
|
||||
|
||||
sdl::SharedTexture &ui::SlideOutPanel::get_target() noexcept { return m_renderTarget; }
|
||||
sdl2::SharedTexture &ui::SlideOutPanel::get_target() noexcept { return m_renderTarget; }
|
||||
|
||||
// ---- Private functions ----
|
||||
|
||||
@@ -150,7 +161,7 @@ void ui::SlideOutPanel::update_position_state() noexcept
|
||||
else if (hidden) { m_state = State::Hidden; }
|
||||
}
|
||||
|
||||
void ui::SlideOutPanel::update_sub_elements(bool hasFocus) noexcept
|
||||
void ui::SlideOutPanel::update_sub_elements(const sdl2::Input &input, bool hasFocus) noexcept
|
||||
{
|
||||
for (auto &element : m_elements) { element->update(hasFocus); }
|
||||
for (auto &element : m_elements) { element->update(input, hasFocus); }
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "ui/TextScroll.hpp"
|
||||
|
||||
#include "graphics/ScopedRender.hpp"
|
||||
#include "sdl.hpp"
|
||||
#include "stringutil.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -9,8 +11,6 @@ namespace
|
||||
|
||||
/// @brief This is the number of pixels between the two renderings of the text.
|
||||
constexpr int SIZE_TEXT_GAP = 0;
|
||||
|
||||
int TARGET_ID{};
|
||||
} // namespace
|
||||
|
||||
// ---- Construction ----
|
||||
@@ -21,12 +21,10 @@ ui::TextScroll::TextScroll(std::string_view text,
|
||||
int width,
|
||||
int height,
|
||||
int fontSize,
|
||||
sdl::Color textColor,
|
||||
sdl::Color clearColor,
|
||||
SDL_Color textColor,
|
||||
SDL_Color clearColor,
|
||||
bool center)
|
||||
{
|
||||
TextScroll::initialize(text, x, y, width, height, fontSize, textColor, clearColor, center);
|
||||
}
|
||||
{ TextScroll::initialize(text, x, y, width, height, fontSize, textColor, clearColor, center); }
|
||||
|
||||
ui::TextScroll::TextScroll(std::string &text,
|
||||
int x,
|
||||
@@ -34,12 +32,10 @@ ui::TextScroll::TextScroll(std::string &text,
|
||||
int width,
|
||||
int height,
|
||||
int fontSize,
|
||||
sdl::Color textColor,
|
||||
sdl::Color clearColor,
|
||||
SDL_Color textColor,
|
||||
SDL_Color clearColor,
|
||||
bool center)
|
||||
{
|
||||
TextScroll::initialize(text, x, y, width, height, fontSize, textColor, clearColor, center);
|
||||
}
|
||||
{ TextScroll::initialize(text, x, y, width, height, fontSize, textColor, clearColor, center); }
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
@@ -49,24 +45,24 @@ void ui::TextScroll::initialize(std::string_view text,
|
||||
int width,
|
||||
int height,
|
||||
int fontSize,
|
||||
sdl::Color textColor,
|
||||
sdl::Color clearColor,
|
||||
SDL_Color textColor,
|
||||
SDL_Color clearColor,
|
||||
bool center)
|
||||
{
|
||||
m_renderX = x;
|
||||
m_renderY = y;
|
||||
m_fontSize = fontSize;
|
||||
m_textColor = textColor;
|
||||
m_renderX = x;
|
||||
m_renderY = y;
|
||||
m_fontSize = fontSize;
|
||||
m_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(TextScroll::generate_font_name(fontSize), fontSize);
|
||||
m_textColor = textColor;
|
||||
m_clearColor = clearColor;
|
||||
m_targetWidth = width;
|
||||
m_targetHeight = height;
|
||||
m_textY = (m_targetHeight / 2) - (m_fontSize / 2);
|
||||
m_scrollTimer.start(TICKS_SCROLL_TRIGGER);
|
||||
|
||||
{
|
||||
const std::string targetName = "textScroll_" + std::to_string(TARGET_ID++);
|
||||
m_renderTarget = sdl::TextureManager::load(targetName, m_targetWidth, m_targetHeight, SDL_TEXTUREACCESS_TARGET);
|
||||
}
|
||||
m_renderTarget = sdl2::TextureManager::create_load_resource(TextScroll::generate_target_name(),
|
||||
m_targetWidth,
|
||||
m_targetHeight,
|
||||
SDL_TEXTUREACCESS_TARGET);
|
||||
|
||||
TextScroll::set_text(text, center);
|
||||
}
|
||||
@@ -77,24 +73,24 @@ void ui::TextScroll::initialize(std::string &text,
|
||||
int width,
|
||||
int height,
|
||||
int fontSize,
|
||||
sdl::Color textColor,
|
||||
sdl::Color clearColor,
|
||||
SDL_Color textColor,
|
||||
SDL_Color clearColor,
|
||||
bool center)
|
||||
{
|
||||
m_renderX = x;
|
||||
m_renderY = y;
|
||||
m_fontSize = fontSize;
|
||||
m_textColor = textColor;
|
||||
m_renderX = x;
|
||||
m_renderY = y;
|
||||
m_fontSize = fontSize;
|
||||
m_font = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(TextScroll::generate_font_name(fontSize), fontSize);
|
||||
m_textColor = textColor;
|
||||
m_clearColor = clearColor;
|
||||
m_targetWidth = width;
|
||||
m_targetHeight = height;
|
||||
m_textY = (m_targetHeight / 2) - (m_fontSize / 2);
|
||||
m_scrollTimer.start(TICKS_SCROLL_TRIGGER);
|
||||
|
||||
{
|
||||
const std::string targetName = "textScroll_" + std::to_string(TARGET_ID++);
|
||||
m_renderTarget = sdl::TextureManager::load(targetName, m_targetWidth, m_targetHeight, SDL_TEXTUREACCESS_TARGET);
|
||||
}
|
||||
m_renderTarget = sdl2::TextureManager::create_load_resource(TextScroll::generate_target_name(),
|
||||
m_targetWidth,
|
||||
m_targetHeight,
|
||||
SDL_TEXTUREACCESS_TARGET);
|
||||
|
||||
TextScroll::set_text(text, center);
|
||||
}
|
||||
@@ -104,7 +100,7 @@ std::string_view ui::TextScroll::get_text() const noexcept { return m_text; }
|
||||
void ui::TextScroll::set_text(std::string_view text, bool center)
|
||||
{
|
||||
m_text = text;
|
||||
m_textWidth = sdl::text::get_width(m_fontSize, m_text.c_str());
|
||||
m_textWidth = m_font->get_text_width(m_text);
|
||||
m_textScrollTriggered = false;
|
||||
|
||||
if (m_textWidth > m_targetWidth - 16)
|
||||
@@ -128,7 +124,7 @@ void ui::TextScroll::set_text(std::string_view text, bool center)
|
||||
void ui::TextScroll::set_text(std::string &text, bool center)
|
||||
{
|
||||
m_text = std::move(text);
|
||||
m_textWidth = sdl::text::get_width(m_fontSize, m_text.c_str());
|
||||
m_textWidth = m_font->get_text_width(m_text);
|
||||
m_textScrollTriggered = false;
|
||||
|
||||
if (m_textWidth > m_targetWidth - 16)
|
||||
@@ -149,7 +145,7 @@ void ui::TextScroll::set_text(std::string &text, bool center)
|
||||
}
|
||||
}
|
||||
|
||||
void ui::TextScroll::update(bool hasFocus)
|
||||
void ui::TextScroll::update(const sdl2::Input &input, bool hasFocus)
|
||||
{
|
||||
// I don't think this needs to care about having focus.
|
||||
const int invertedWidth = -(m_textWidth + SIZE_TEXT_GAP);
|
||||
@@ -172,25 +168,34 @@ void ui::TextScroll::update(bool hasFocus)
|
||||
}
|
||||
}
|
||||
|
||||
void ui::TextScroll::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::TextScroll::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
m_renderTarget->clear(m_clearColor);
|
||||
// Gap between scrolling text rendering.
|
||||
static constexpr int TEXT_GAP = 8;
|
||||
|
||||
if (!m_textScrolling)
|
||||
{
|
||||
sdl::text::render(m_renderTarget, m_textX, m_textY, m_fontSize, sdl::text::NO_WRAP, m_textColor, m_text);
|
||||
// Scoped render to the target.
|
||||
graphics::ScopedRender scopedRender{renderer, m_renderTarget};
|
||||
renderer.frame_begin(m_clearColor);
|
||||
|
||||
if (!m_textScrolling) { m_font->render_text(m_textX, m_textY, m_textColor, m_text); }
|
||||
else
|
||||
{
|
||||
// We're going to render text twice so it looks like it's scrolling and doesn't end. Ever.
|
||||
m_font->render_text(m_textX, m_textY, m_textColor, m_text);
|
||||
m_font->render_text(m_textX + m_textWidth + TEXT_GAP, m_textY, m_textColor, m_text);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're going to render text twice so it looks like it's scrolling and doesn't end. Ever.
|
||||
sdl::text::render(m_renderTarget, m_textX, m_textY, m_fontSize, sdl::text::NO_WRAP, m_textColor, m_text);
|
||||
sdl::text::render(m_renderTarget,
|
||||
m_textX + m_textWidth + 8,
|
||||
m_textY,
|
||||
m_fontSize,
|
||||
sdl::text::NO_WRAP,
|
||||
m_textColor,
|
||||
m_text);
|
||||
}
|
||||
m_renderTarget->render(target, m_renderX, m_renderY);
|
||||
m_renderTarget->render(m_renderX, m_renderY);
|
||||
}
|
||||
|
||||
// ---- Private Functions ----
|
||||
|
||||
std::string ui::TextScroll::generate_target_name()
|
||||
{
|
||||
static int targetID{};
|
||||
return stringutil::get_formatted_string("TextScroll_%i", targetID++);
|
||||
}
|
||||
|
||||
std::string ui::TextScroll::generate_font_name(int fontSize)
|
||||
{ return stringutil::get_formatted_string("TextScrollFont_%i", fontSize); }
|
||||
@@ -11,7 +11,7 @@ namespace
|
||||
|
||||
// ---- Construction ----
|
||||
|
||||
ui::TitleTile::TitleTile(bool isFavorite, int index, sdl::SharedTexture icon)
|
||||
ui::TitleTile::TitleTile(bool isFavorite, int index, sdl2::SharedTexture &icon)
|
||||
: m_transition(0,
|
||||
0,
|
||||
UNSELECTED_WIDTH_HEIGHT,
|
||||
@@ -22,15 +22,12 @@ ui::TitleTile::TitleTile(bool isFavorite, int index, sdl::SharedTexture icon)
|
||||
UNSELECTED_WIDTH_HEIGHT,
|
||||
m_transition.DEFAULT_THRESHOLD)
|
||||
, m_isFavorite(isFavorite)
|
||||
, m_index(index)
|
||||
, m_icon(icon) {};
|
||||
|
||||
// ---- Public functions ----
|
||||
|
||||
void ui::TitleTile::update(int selected)
|
||||
void ui::TitleTile::update(bool isSelected)
|
||||
{
|
||||
const bool isSelected = selected == m_index;
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
m_transition.set_target_width(SELECTED_WIDTH_HEIGHT);
|
||||
@@ -45,7 +42,7 @@ void ui::TitleTile::update(int selected)
|
||||
m_transition.update_width_height();
|
||||
}
|
||||
|
||||
void ui::TitleTile::render(sdl::SharedTexture &target, int x, int y)
|
||||
void ui::TitleTile::render(int x, int y)
|
||||
{
|
||||
static constexpr std::string_view HEART_CHAR = "\uE017";
|
||||
|
||||
@@ -54,8 +51,9 @@ void ui::TitleTile::render(sdl::SharedTexture &target, int x, int y)
|
||||
const int renderX = x - ((width - 128) / 2);
|
||||
const int renderY = y - ((width - 128) / 2);
|
||||
|
||||
m_icon->render_stretched(target, renderX, renderY, width, height);
|
||||
if (m_isFavorite) { sdl::text::render(target, renderX + 2, renderY + 2, 28, sdl::text::NO_WRAP, colors::PINK, HEART_CHAR); }
|
||||
m_icon->render_stretched(renderX, renderY, width, height);
|
||||
|
||||
if (m_isFavorite) { sm_heartFont->render_text(renderX + 2, renderY + 2, colors::PINK, HEART_CHAR); }
|
||||
}
|
||||
|
||||
void ui::TitleTile::reset() noexcept
|
||||
@@ -69,3 +67,16 @@ void ui::TitleTile::reset() noexcept
|
||||
int ui::TitleTile::get_width() const noexcept { return m_transition.get_width(); }
|
||||
|
||||
int ui::TitleTile::get_height() const noexcept { return m_transition.get_height(); }
|
||||
|
||||
// ---- Private Functions ----
|
||||
|
||||
void ui::TitleTile::initialize_static_members()
|
||||
{
|
||||
// Font name for the manager.
|
||||
static constexpr std::string_view FONT_NAME = "HeartFont";
|
||||
static constexpr int FONT_SIZE = 28;
|
||||
|
||||
if (sm_heartFont) { return; }
|
||||
|
||||
sm_heartFont = sdl2::FontManager::create_load_resource<sdl2::SystemFont>(FONT_NAME, FONT_SIZE);
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "config/config.hpp"
|
||||
#include "error.hpp"
|
||||
#include "graphics/colors.hpp"
|
||||
#include "input.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
|
||||
#include <cmath>
|
||||
@@ -26,19 +25,19 @@ ui::TitleView::TitleView(data::User *user)
|
||||
TitleView::refresh();
|
||||
}
|
||||
|
||||
void ui::TitleView::update(bool hasFocus)
|
||||
void ui::TitleView::update(const sdl2::Input &input, bool hasFocus)
|
||||
{
|
||||
if (m_titleTiles.empty()) { return; }
|
||||
|
||||
m_bounding->update(hasFocus);
|
||||
TitleView::handle_input();
|
||||
m_bounding->update(input, hasFocus);
|
||||
TitleView::handle_input(input);
|
||||
TitleView::handle_scrolling();
|
||||
TitleView::update_tiles();
|
||||
|
||||
m_transition.update();
|
||||
}
|
||||
|
||||
void ui::TitleView::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
void ui::TitleView::render(sdl2::Renderer &renderer, bool hasFocus)
|
||||
{
|
||||
static constexpr int TILE_SPACE_VERT = 144;
|
||||
static constexpr int TILE_SPACE_HOR = 144;
|
||||
@@ -59,8 +58,7 @@ void ui::TitleView::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
continue;
|
||||
}
|
||||
|
||||
ui::TitleTile &tile = m_titleTiles[j];
|
||||
tile.render(target, tempX, tempY);
|
||||
m_titleTiles[i].render(tempX, tempY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,12 +67,11 @@ void ui::TitleView::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
m_bounding->set_x(m_selectedX - 30);
|
||||
m_bounding->set_y(m_selectedY - 30);
|
||||
|
||||
sdl::render_rect_fill(target, m_selectedX - 28, m_selectedY - 28, 184, 184, colors::CLEAR_COLOR);
|
||||
m_bounding->render(target, hasFocus);
|
||||
renderer.render_rectangle(m_selectedX - 28, m_selectedY - 28, 184, 184, colors::CLEAR_COLOR);
|
||||
m_bounding->render(renderer, hasFocus);
|
||||
}
|
||||
|
||||
ui::TitleTile &selectedTile = m_titleTiles[m_selected];
|
||||
selectedTile.render(target, m_selectedX, m_selectedY);
|
||||
m_titleTiles[m_selected].render(m_selectedX, m_selectedY);
|
||||
}
|
||||
|
||||
int ui::TitleView::get_selected() const noexcept { return m_selected; }
|
||||
@@ -83,6 +80,7 @@ void ui::TitleView::set_selected(int selected) noexcept
|
||||
{
|
||||
const int tilesCount = m_titleTiles.size();
|
||||
if (selected < 0 || selected >= tilesCount) { return; }
|
||||
|
||||
m_selected = selected;
|
||||
}
|
||||
|
||||
@@ -98,8 +96,8 @@ void ui::TitleView::refresh()
|
||||
data::TitleInfo *titleInfo = data::get_title_info_by_id(applicationID);
|
||||
if (error::is_null(titleInfo)) { continue; }
|
||||
|
||||
const bool isFavorite = config::is_favorite(applicationID);
|
||||
sdl::SharedTexture icon = titleInfo->get_icon(); // I don't like this but w/e.
|
||||
const bool isFavorite = config::is_favorite(applicationID);
|
||||
sdl2::SharedTexture &icon = titleInfo->get_icon();
|
||||
|
||||
m_titleTiles.emplace_back(isFavorite, i, icon);
|
||||
}
|
||||
@@ -120,23 +118,22 @@ void ui::TitleView::play_sound() noexcept { sm_cursor->play(); }
|
||||
|
||||
void ui::TitleView::initialize_static_members()
|
||||
{
|
||||
static constexpr std::string_view CURSOR_NAME = "MenuCursor";
|
||||
static constexpr const char *CURSOR_PATH = "romfs:/Sound/MenuCursor.wav";
|
||||
static constexpr std::string_view CURSOR_PATH = "romfs:/Sound/MenuCursor.wav";
|
||||
|
||||
if (sm_cursor) { return; }
|
||||
|
||||
sm_cursor = sdl::SoundManager::load(CURSOR_NAME, CURSOR_PATH);
|
||||
sm_cursor = sdl2::SoundManager::create_load_resource(CURSOR_PATH, CURSOR_PATH);
|
||||
}
|
||||
|
||||
void ui::TitleView::handle_input()
|
||||
void ui::TitleView::handle_input(const sdl2::Input &input)
|
||||
{
|
||||
const int totalTiles = m_titleTiles.size() - 1;
|
||||
const bool upPressed = input::button_pressed(HidNpadButton_AnyUp);
|
||||
const bool downPressed = input::button_pressed(HidNpadButton_AnyDown);
|
||||
const bool leftPressed = input::button_pressed(HidNpadButton_AnyLeft);
|
||||
const bool rightPressed = input::button_pressed(HidNpadButton_AnyRight);
|
||||
const bool lShoulderPressed = input::button_pressed(HidNpadButton_L);
|
||||
const bool rShoulderPressed = input::button_pressed(HidNpadButton_R);
|
||||
const bool upPressed = input.button_pressed(HidNpadButton_AnyUp);
|
||||
const bool downPressed = input.button_pressed(HidNpadButton_AnyDown);
|
||||
const bool leftPressed = input.button_pressed(HidNpadButton_AnyLeft);
|
||||
const bool rightPressed = input.button_pressed(HidNpadButton_AnyRight);
|
||||
const bool lShoulderPressed = input.button_pressed(HidNpadButton_L);
|
||||
const bool rShoulderPressed = input.button_pressed(HidNpadButton_R);
|
||||
|
||||
const int previousSelected = m_selected;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user