Initial commit. Needs debugging.

This commit is contained in:
J-D-K
2026-03-20 12:41:04 -04:00
parent d39fd80a20
commit 347f1bc75f
112 changed files with 1331 additions and 1109 deletions

View File

@@ -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()