# Changes

- Remove Scene Logic and only use Update as func
- Begin with UI7 Horizontal scrollin gimpl and add Alignment funcs (not functional yet)
- Generate a Lookup Table for Languages for faster access
This commit is contained in:
tobid7 2024-09-27 16:24:07 +02:00
parent 224daffaf7
commit eac36bcc6e
7 changed files with 134 additions and 108 deletions

View File

@ -8,8 +8,7 @@ class ThemeEditor : public Palladium::Scene {
ThemeEditor(); ThemeEditor();
~ThemeEditor(); ~ThemeEditor();
void Draw(void) const override; void Update() override;
void Logic() override;
private: private:
Theme::Ref edit_theme; Theme::Ref edit_theme;
@ -17,13 +16,13 @@ class ThemeEditor : public Palladium::Scene {
Theme::Ref temp_theme; Theme::Ref temp_theme;
// temp vars for samples // temp vars for samples
mutable bool cm; bool cm;
mutable std::string inpt; std::string inpt;
mutable int menu = 0; int menu = 0;
// Keyboard // Keyboard
mutable PDKeyboardState kbd_state; PDKeyboardState kbd_state;
mutable std::string kbd_text; std::string kbd_text;
mutable std::vector<std::string> theme_list; std::vector<std::string> theme_list;
}; };
} // namespace Palladium } // namespace Palladium

View File

@ -14,7 +14,9 @@ enum UI7MenuFlags_ {
UI7MenuFlags_None = 0, UI7MenuFlags_None = 0,
UI7MenuFlags_NoTitlebar = UI7MAKEFLAG(0), UI7MenuFlags_NoTitlebar = UI7MAKEFLAG(0),
UI7MenuFlags_TitleMid = UI7MAKEFLAG(1), UI7MenuFlags_TitleMid = UI7MAKEFLAG(1),
UI7MenuFlags_Scrolling = MAKEFLAG(2), UI7MenuFlags_HzScrolling = MAKEFLAG(2),
UI7MenuFlags_VtScrolling = MAKEFLAG(3),
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
}; };
enum UI7Horizontal { enum UI7Horizontal {
@ -121,6 +123,11 @@ float GetScrollingOffset();
void SetScrollingOffset(float off); void SetScrollingOffset(float off);
bool IsScrolling(); bool IsScrolling();
} // namespace Menu } // namespace Menu
namespace Next {
// Alignment in ScreenSpace
void Align(UI7Horizontal hz = UI7Horizontal_Left,
UI7Vertical vt = UI7Vertical_Top);
} // namespace Next
// DrawLists // DrawLists
UI7DrawList::Ref GetForegroundList(); UI7DrawList::Ref GetForegroundList();
UI7DrawList::Ref GetBackgroundList(); UI7DrawList::Ref GetBackgroundList();

View File

@ -15,19 +15,19 @@
#include <3ds.h> #include <3ds.h>
#include <citro3d.h> #include <citro3d.h>
/// Palladium Includes /// Palladium Includes
#include <pd/base/Color.hpp>
#include <pd/base/FunctionTrace.hpp>
#include <pd/Hardware.hpp> #include <pd/Hardware.hpp>
#include <pd/base/Memory.hpp>
#include <pd/Overlays.hpp> #include <pd/Overlays.hpp>
#include <pd/Ovl.hpp> #include <pd/Ovl.hpp>
#include <pd/ResultDecoder.hpp> #include <pd/ResultDecoder.hpp>
#include <pd/Sprite.hpp> #include <pd/Sprite.hpp>
#include <pd/Tasks.hpp> #include <pd/Tasks.hpp>
#include <pd/Time.hpp> #include <pd/Time.hpp>
#include <pd/base/Color.hpp>
#include <pd/base/FunctionTrace.hpp>
#include <pd/base/Lang.hpp> #include <pd/base/Lang.hpp>
#include <pd/parameter.hpp> #include <pd/base/Memory.hpp>
#include <pd/base/stringtool.hpp> #include <pd/base/stringtool.hpp>
#include <pd/parameter.hpp>
#include <pd/thread.hpp> #include <pd/thread.hpp>
#define PDVSTRING "1.0.0" #define PDVSTRING "1.0.0"
@ -49,9 +49,7 @@ class Scene {
static std::stack<std::unique_ptr<Scene>> scenes; static std::stack<std::unique_ptr<Scene>> scenes;
/// @brief Deconstructor /// @brief Deconstructor
virtual ~Scene() {} virtual ~Scene() {}
virtual void Logic() = 0; virtual void Update() = 0;
/// @brief Draw Func to Override
virtual void Draw() const = 0;
/// @brief Push a Scene to Stack /// @brief Push a Scene to Stack
/// @param scene Scene to Push /// @param scene Scene to Push
/// @param fade FadeEffect (Not Correctly Implementet yet) /// @param fade FadeEffect (Not Correctly Implementet yet)
@ -59,8 +57,7 @@ class Scene {
/// @brief Go Back a Scene /// @brief Go Back a Scene
static void Back(); static void Back();
/// @brief do the Draw (Called in Palladium::MainLoop()) /// @brief do the Draw (Called in Palladium::MainLoop())
static void doDraw(); static void doUpdate();
static void doLogic();
}; };
/// @brief Integrated Setting Menu of Palladium /// @brief Integrated Setting Menu of Palladium
@ -102,12 +99,9 @@ class RSettings : public Palladium::Scene {
public: public:
/// @brief Constructor /// @brief Constructor
RSettings(); RSettings();
/// @brief Override for Draw
/// @param
void Draw(void) const override;
/// @brief Deconstructor /// @brief Deconstructor
~RSettings(); ~RSettings();
void Logic() override; void Update() override;
}; };
/// @brief Show Up the Palladium-Settings Menu /// @brief Show Up the Palladium-Settings Menu

View File

@ -38,7 +38,8 @@ Palladium::ThemeEditor::~ThemeEditor() {
Palladium::ThemeSet(temp_theme); Palladium::ThemeSet(temp_theme);
} }
void Palladium::ThemeEditor::Draw() const { void Palladium::ThemeEditor::Update() {
// Rendering / UI Logic
Palladium::LI::OnScreen(false); Palladium::LI::OnScreen(false);
if (UI7::BeginMenu("Palladium -> Theme Editor")) { if (UI7::BeginMenu("Palladium -> Theme Editor")) {
UI7::Label("Sample Text"); UI7::Label("Sample Text");
@ -111,9 +112,8 @@ void Palladium::ThemeEditor::Draw() const {
} }
UI7::EndMenu(); UI7::EndMenu();
} }
}
void Palladium::ThemeEditor::Logic() { // Standart Logic
if (kbd_state) { if (kbd_state) {
if (kbd_state == PDKeyboardState_Confirm) { if (kbd_state == PDKeyboardState_Confirm) {
auto path = auto path =

View File

@ -332,6 +332,11 @@ struct UI7Promt {
PD_SMART_CTOR(UI7Promt) PD_SMART_CTOR(UI7Promt)
}; };
struct UI7_ItemOpts {
UI7Vertical vertical_align = UI7Vertical_Top;
UI7Horizontal horizontal_align = UI7Horizontal_Left;
};
struct UI7Menu { struct UI7Menu {
UI7Menu() {} UI7Menu() {}
UI7ID menuid; // menu ID UI7ID menuid; // menu ID
@ -339,14 +344,18 @@ struct UI7Menu {
NVec2 cb; // backup cursor NVec2 cb; // backup cursor
NVec2 slc; // sameline cursor NVec2 slc; // sameline cursor
NVec2 screen_size; // MenuScreenSize NVec2 screen_size; // MenuScreenSize
float scrolling_offset = 0.f; // MenuScrolling Pos NVec2 scrolling_offset; // MenuScrolling Pos
bool enable_scrolling = false; // Menu Scrolling bool vertical_scrolling = false; // Vertical Menu Scrolling
float scrolling_mod = 0.f; // For Menu Scrolling effect bool horizontal_scrolling = false; // Horizontal Menu Scrolling
float tbh; // TabBar Height NVec2 scrolling_mod; // For Menu Scrolling effect
bool show_scroolbar = true; // Show Scrollbar float tbh = 0.f; // TabBar Height
bool scrolling_possible = true; // Scrolling Possible? bool show_vt_scroolbar = true; // Show Vertical Scrollbar
bool show_hz_scroolbar = true; // Show Horizontal Scrollbar
bool vtscrolling_possible = true; // Vertical Scrolling Possible?
bool hzscrolling_possible = true; // Horizontal Scrolling Possible?
bool has_touch = false; // To Disable touch on Top Screen bool has_touch = false; // To Disable touch on Top Screen
NTCtrl::Ref ctrl; // NonTouchControl NTCtrl::Ref ctrl; // NonTouchControl / Not in dev yet
UI7_ItemOpts next_item_opts; // Next Itam Options
// SubMenu // SubMenu
std::string submenu; std::string submenu;
@ -472,12 +481,13 @@ bool UI7CtxBeginMenu(const std::string &lb) {
void UI7CtxEndMenu() { void UI7CtxEndMenu() {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
if (!UI7CtxInMenu()) return; if (!UI7CtxInMenu()) return;
// Draw Scrollbar // Draw Vertical Scrollbar
if (ui7_ctx->cm->enable_scrolling) { if (ui7_ctx->cm->vertical_scrolling) {
ui7_ctx->cm->scrolling_possible = (ui7_ctx->cm->ms[1] < 235 ? false : true); ui7_ctx->cm->vtscrolling_possible =
ui7_ctx->cm->show_scroolbar = ui7_ctx->cm->scrolling_possible; (ui7_ctx->cm->ms[1] < 235 ? false : true);
ui7_ctx->cm->show_vt_scroolbar = ui7_ctx->cm->vtscrolling_possible;
if (ui7_ctx->cm->show_scroolbar) { if (ui7_ctx->cm->show_vt_scroolbar) {
// Screen Width // Screen Width
int sw = Palladium::LI::GetScreenSize().x(); int sw = Palladium::LI::GetScreenSize().x();
// Top Start Pos // Top Start Pos
@ -486,6 +496,8 @@ void UI7CtxEndMenu() {
int slider_w = 4; int slider_w = 4;
// Height of Slider // Height of Slider
int szs = 240 - tsp - 5; int szs = 240 - tsp - 5;
// Modify if we have a horizontal scrollbar
if (ui7_ctx->cm->show_hz_scroolbar) szs -= slider_w - 2;
// Lowest Height of Slider Obj // Lowest Height of Slider Obj
int lszs = 20; // Lowest Slider size int lszs = 20; // Lowest Slider size
// Calculate Slider Height // Calculate Slider Height
@ -499,30 +511,31 @@ void UI7CtxEndMenu() {
// Process MenuDragging // Process MenuDragging
auto objmbg = UI7CtxGetObject("menu_bg" + ui7_ctx->cm->menuid.real_id); auto objmbg = UI7CtxGetObject("menu_bg" + ui7_ctx->cm->menuid.real_id);
// Patch that sets scrolling to 0 if max pos is not out of screen // Patch that sets scrolling to 0 if max pos is not out of screen
if (ui7_ctx->cm->scrolling_offset != 0.f && ui7_ctx->cm->ms[1] < 235) { if (ui7_ctx->cm->scrolling_offset[1] != 0.f && ui7_ctx->cm->ms[1] < 235) {
ui7_ctx->cm->scrolling_offset = 0.f; ui7_ctx->cm->scrolling_offset[1] = 0.f;
} }
/// TODO: Use Deltatime somehow here
// Auto scroll back if last object is on screen // Auto scroll back if last object is on screen
if (ui7_ctx->cm->scrolling_offset > ui7_ctx->cm->ms[1] - 240 && if (ui7_ctx->cm->scrolling_offset[1] > ui7_ctx->cm->ms[1] - 240 &&
ui7_ctx->cm->ms[1] != 0 && ui7_ctx->cm->ms[1] >= 235) { ui7_ctx->cm->ms[1] != 0 && ui7_ctx->cm->ms[1] >= 235) {
ui7_ctx->cm->scrolling_offset -= 0.3 * ui7_ctx->delta; ui7_ctx->cm->scrolling_offset[1] -= 3.f;
// Patch to Scroll to perfect pos // Patch to Scroll to perfect pos
if (ui7_ctx->cm->scrolling_offset < ui7_ctx->cm->ms[1] - 240) { if (ui7_ctx->cm->scrolling_offset[1] < ui7_ctx->cm->ms[1] - 240) {
ui7_ctx->cm->scrolling_offset = ui7_ctx->cm->ms[1] - 240; ui7_ctx->cm->scrolling_offset[1] = ui7_ctx->cm->ms[1] - 240;
} }
} }
// Auto Scroll back if offset gets below 0 // Auto Scroll back if offset gets below 0
if (ui7_ctx->cm->scrolling_offset < 0) { if (ui7_ctx->cm->scrolling_offset[1] < 0) {
ui7_ctx->cm->scrolling_offset += 0.3 * ui7_ctx->delta; ui7_ctx->cm->scrolling_offset[1] += 3.f;
if (ui7_ctx->cm->scrolling_offset > 0) if (ui7_ctx->cm->scrolling_offset[1] > 0)
ui7_ctx->cm->scrolling_offset = 0; ui7_ctx->cm->scrolling_offset[1] = 0;
} }
// Zero out scrolling_mod if it goeas < -40 // Zero out scrolling_mod if it goeas < -40
// or > 40 over the max size // or > 40 over the max size
if (ui7_ctx->cm->scrolling_offset < -40 || if (ui7_ctx->cm->scrolling_offset[1] < -40 ||
ui7_ctx->cm->scrolling_offset > ui7_ctx->cm->ms[1] - 200) { ui7_ctx->cm->scrolling_offset[1] > ui7_ctx->cm->ms[1] - 200) {
ui7_ctx->cm->scrolling_mod = 0.f; ui7_ctx->cm->scrolling_mod[1] = 0.f;
} }
if (ui7_ctx->cm->has_touch) { if (ui7_ctx->cm->has_touch) {
auto np = Palladium::Hid::GetTouchPosition(); auto np = Palladium::Hid::GetTouchPosition();
@ -545,15 +558,15 @@ void UI7CtxEndMenu() {
NVec2(8, 240 - ui7_ctx->cm->tbh - 10))) { NVec2(8, 240 - ui7_ctx->cm->tbh - 10))) {
objmbg->is_dragged = true; objmbg->is_dragged = true;
// Check if and do nothing if the scrolling ofset goes out of screen // Check if and do nothing if the scrolling ofset goes out of screen
if (ui7_ctx->cm->scrolling_offset < ui7_ctx->cm->ms[1] - 200 && if (ui7_ctx->cm->scrolling_offset[1] < ui7_ctx->cm->ms[1] - 200 &&
ui7_ctx->cm->scrolling_offset > -40) { ui7_ctx->cm->scrolling_offset[1] > -40) {
float cursor_mod = (ui7_ctx->cm->mdp[1] - np[1]); float cursor_mod = (ui7_ctx->cm->mdp[1] - np[1]);
if (ui7_ctx->cm->scrolling_mod <= 4.f && if (ui7_ctx->cm->scrolling_mod[1] <= 4.f &&
ui7_ctx->cm->scrolling_mod >= -4 && cursor_mod != 0.0f) { ui7_ctx->cm->scrolling_mod[1] >= -4 && cursor_mod != 0.0f) {
if (cursor_mod > 2) { if (cursor_mod > 2) {
ui7_ctx->cm->scrolling_mod = cursor_mod; ui7_ctx->cm->scrolling_mod[1] = cursor_mod;
} else if (cursor_mod < -2) { } else if (cursor_mod < -2) {
ui7_ctx->cm->scrolling_mod = cursor_mod; ui7_ctx->cm->scrolling_mod[1] = cursor_mod;
} }
} }
} }
@ -563,18 +576,18 @@ void UI7CtxEndMenu() {
} }
} }
// New Scrolling efect // New Scrolling efect
if (ui7_ctx->cm->scrolling_mod != 0) if (ui7_ctx->cm->scrolling_mod[1] != 0)
ui7_ctx->cm->scrolling_offset += ui7_ctx->cm->scrolling_mod; ui7_ctx->cm->scrolling_offset[1] += ui7_ctx->cm->scrolling_mod[1];
// Slow out the effect // Slow out the effect
if (ui7_ctx->cm->scrolling_mod < 0.f) { if (ui7_ctx->cm->scrolling_mod[1] < 0.f) {
ui7_ctx->cm->scrolling_mod += 0.4f; ui7_ctx->cm->scrolling_mod[1] += 0.4f;
if (ui7_ctx->cm->scrolling_mod > 0.f) { if (ui7_ctx->cm->scrolling_mod[1] > 0.f) {
ui7_ctx->cm->scrolling_mod = 0.f; ui7_ctx->cm->scrolling_mod[1] = 0.f;
} }
} else if (ui7_ctx->cm->scrolling_mod > 0.f) { } else if (ui7_ctx->cm->scrolling_mod[1] > 0.f) {
ui7_ctx->cm->scrolling_mod -= 0.4f; ui7_ctx->cm->scrolling_mod[1] -= 0.4f;
if (ui7_ctx->cm->scrolling_mod < 0.f) { if (ui7_ctx->cm->scrolling_mod[1] < 0.f) {
ui7_ctx->cm->scrolling_mod = 0.f; ui7_ctx->cm->scrolling_mod[1] = 0.f;
} }
} }
// Process Slider Dragging // Process Slider Dragging
@ -595,7 +608,7 @@ void UI7CtxEndMenu() {
(szs - slider_rh - 4)), (szs - slider_rh - 4)),
0.0f, 1.0f); 0.0f, 1.0f);
ui7_ctx->cm->scrolling_offset = ui7_ctx->cm->scrolling_offset[1] =
drag_pos * (ui7_ctx->cm->ms[1] - 240.0f); drag_pos * (ui7_ctx->cm->ms[1] - 240.0f);
} }
} else if (Palladium::Hid::IsEvent("touch", Palladium::Hid::Up) && } else if (Palladium::Hid::IsEvent("touch", Palladium::Hid::Up) &&
@ -608,7 +621,7 @@ void UI7CtxEndMenu() {
tsp + tsp +
std::clamp(static_cast<float>( std::clamp(static_cast<float>(
(szs - slider_rh - 4) * (szs - slider_rh - 4) *
(static_cast<float>(ui7_ctx->cm->scrolling_offset) / (static_cast<float>(ui7_ctx->cm->scrolling_offset[1]) /
static_cast<float>(ui7_ctx->cm->ms[1] - 240.f))), static_cast<float>(ui7_ctx->cm->ms[1] - 240.f))),
0.f, static_cast<float>(szs - slider_rh - 4)); 0.f, static_cast<float>(szs - slider_rh - 4));
@ -619,8 +632,8 @@ void UI7CtxEndMenu() {
NVec2(slider_w, slider_rh), slider_clr); NVec2(slider_w, slider_rh), slider_clr);
} else { } else {
// Set scrollingoffset and mod to 0 if not scrolling enabled // Set scrollingoffset and mod to 0 if not scrolling enabled
ui7_ctx->cm->scrolling_offset = 0.f; ui7_ctx->cm->scrolling_offset[1] = 0.f;
ui7_ctx->cm->scrolling_mod = 0.f; ui7_ctx->cm->scrolling_mod[1] = 0.f;
} }
} }
ui7_ctx->active_menus.push_back(ui7_ctx->cm); ui7_ctx->active_menus.push_back(ui7_ctx->cm);
@ -771,6 +784,10 @@ bool Button(const std::string &label, NVec2 size) {
} }
PDColor btn = PDColor_Button; PDColor btn = PDColor_Button;
NVec2 pos = GetCursorPos(); NVec2 pos = GetCursorPos();
if (ui7_ctx->cm->next_item_opts.horizontal_align == UI7Horizontal_Center) {
pos[0] =
((ui7_ctx->cm->screen_size[0] - 10) * 0.5) - ((size[0] - pos[0]) * 0.5);
}
MoveCursor(size); MoveCursor(size);
ui7_ctx->cm->ctrl->AddObj(); ui7_ctx->cm->ctrl->AddObj();
@ -870,7 +887,7 @@ void Progressbar(float value) {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
NVec2 pos = GetCursorPos(); NVec2 pos = GetCursorPos();
NVec2 size = NVec2(Palladium::LI::GetScreenSize().x() - (pos[0] * 2), 20); NVec2 size = NVec2(Palladium::LI::GetScreenSize().x() - (pos[0] * 2), 20);
if (ui7_ctx->cm->show_scroolbar && ui7_ctx->cm->enable_scrolling) if (ui7_ctx->cm->show_vt_scroolbar && ui7_ctx->cm->vertical_scrolling)
size[0] -= 16; size[0] -= 16;
MoveCursor(size); MoveCursor(size);
ui7_ctx->cm->ctrl->AddObj(); ui7_ctx->cm->ctrl->AddObj();
@ -1004,7 +1021,8 @@ bool BeginMenu(const std::string &title, NVec2 size, UI7MenuFlags flags) {
ui7_ctx->cm->tbh = 0.f; ui7_ctx->cm->tbh = 0.f;
} }
if (flags & UI7MenuFlags_TitleMid) txtflags = PDTextFlags_AlignMid; if (flags & UI7MenuFlags_TitleMid) txtflags = PDTextFlags_AlignMid;
ui7_ctx->cm->enable_scrolling = (flags & UI7MenuFlags_Scrolling); ui7_ctx->cm->vertical_scrolling = (flags & UI7MenuFlags_VtScrolling);
ui7_ctx->cm->horizontal_scrolling = (flags & UI7MenuFlags_HzScrolling);
// Render // Render
ui7_ctx->cm->background->AddRectangle(NVec2(), size, PDColor_Background); ui7_ctx->cm->background->AddRectangle(NVec2(), size, PDColor_Background);
@ -1087,7 +1105,7 @@ void ColorSelector(const std::string &label, unsigned int &color) {
InBox(Palladium::Hid::GetLastTouchPosition(), pos, inp)) { InBox(Palladium::Hid::GetLastTouchPosition(), pos, inp)) {
ui7_ctx->cm->submenu = id.ID(); ui7_ctx->cm->submenu = id.ID();
// Nullify scrolling mod to fix freeze // Nullify scrolling mod to fix freeze
ui7_ctx->cm->scrolling_mod = 0.0f; ui7_ctx->cm->scrolling_mod[1] = 0.0f;
Palladium::Hid::Lock(); Palladium::Hid::Lock();
Palladium::Hid::Clear(); Palladium::Hid::Clear();
} }
@ -1308,7 +1326,7 @@ void Separator() {
if (!UI7CtxInMenu()) return; if (!UI7CtxInMenu()) return;
NVec2 pos = GetCursorPos(); NVec2 pos = GetCursorPos();
NVec2 size = NVec2( NVec2 size = NVec2(
ui7_ctx->cm->screen_size[0] - (ui7_ctx->cm->enable_scrolling ? 24 : 10), ui7_ctx->cm->screen_size[0] - (ui7_ctx->cm->vertical_scrolling ? 24 : 10),
1); 1);
MoveCursor(size); MoveCursor(size);
ui7_ctx->cm->ctrl->AddObj(); ui7_ctx->cm->ctrl->AddObj();
@ -1327,20 +1345,20 @@ void Debug() {
float Menu::GetScrollingOffset() { float Menu::GetScrollingOffset() {
if (!UI7CtxValidate()) return 0.f; if (!UI7CtxValidate()) return 0.f;
if (!UI7CtxInMenu()) return 0.f; if (!UI7CtxInMenu()) return 0.f;
return ui7_ctx->cm->scrolling_offset; return ui7_ctx->cm->scrolling_offset[1];
} }
void Menu::SetScrollingOffset(float off) { void Menu::SetScrollingOffset(float off) {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
if (!UI7CtxInMenu()) return; if (!UI7CtxInMenu()) return;
ui7_ctx->cm->scrolling_offset = off; ui7_ctx->cm->scrolling_offset[1] = off;
ui7_ctx->cm->scrolling_mod = 0.f; ui7_ctx->cm->scrolling_mod[1] = 0.f;
} }
bool Menu::IsScrolling() { bool Menu::IsScrolling() {
if (!UI7CtxValidate()) return false; if (!UI7CtxValidate()) return false;
if (!UI7CtxInMenu()) return false; if (!UI7CtxInMenu()) return false;
return ui7_ctx->cm->scrolling_mod != 0.f; return ui7_ctx->cm->scrolling_mod[1] != 0.f;
} }
void MoveCursor(NVec2 size) { void MoveCursor(NVec2 size) {
@ -1356,12 +1374,13 @@ void MoveCursor(NVec2 size) {
ui7_ctx->cm->cursor += NVec2(0, size[1] + 5); ui7_ctx->cm->cursor += NVec2(0, size[1] + 5);
} }
ui7_ctx->cm->ms = NVec2(ui7_ctx->cm->slc[0], ui7_ctx->cm->cursor[1]); ui7_ctx->cm->ms = NVec2(ui7_ctx->cm->slc[0], ui7_ctx->cm->cursor[1]);
ui7_ctx->cm->next_item_opts = UI7_ItemOpts();
} }
bool HandleScrolling(NVec2 &pos, NVec2 size) { bool HandleScrolling(NVec2 &pos, NVec2 size) {
if (ui7_ctx->cm->enable_scrolling) { if (ui7_ctx->cm->vertical_scrolling) {
NVec2 pb = pos; NVec2 pb = pos;
pos -= NVec2(0, ui7_ctx->cm->scrolling_offset); pos -= NVec2(0, ui7_ctx->cm->scrolling_offset[1]);
if (pos[1] > 240 || if (pos[1] > 240 ||
(pos[1] + size[1] < ui7_ctx->cm->tbh - 5 && pb[1] > ui7_ctx->cm->tbh)) (pos[1] + size[1] < ui7_ctx->cm->tbh - 5 && pb[1] > ui7_ctx->cm->tbh))
return true; return true;
@ -1419,4 +1438,11 @@ UI7DrawList::Ref Menu::GetForegroundList() {
if (!UI7CtxInMenu()) return ui7_ctx->bdl; if (!UI7CtxInMenu()) return ui7_ctx->bdl;
return ui7_ctx->cm->front; return ui7_ctx->cm->front;
} }
void Next::Align(UI7Horizontal hz, UI7Vertical vt) {
if (!UI7CtxValidate()) return;
if (!UI7CtxInMenu()) return;
ui7_ctx->cm->next_item_opts.horizontal_align = hz;
ui7_ctx->cm->next_item_opts.vertical_align = vt;
}
} // namespace UI7 } // namespace UI7

View File

@ -2,10 +2,14 @@
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <map>
#include <pd/base/Lang.hpp> #include <pd/base/Lang.hpp>
static nlohmann::json appJson; static nlohmann::json appJson;
/// Lang Map KEY STRING
static std::map<std::string, std::string> lang_table;
std::string Palladium::Lang::GetSys() { std::string Palladium::Lang::GetSys() {
u8 language = 1; u8 language = 1;
CFGU_GetSystemLanguage(&language); CFGU_GetSystemLanguage(&language);
@ -65,10 +69,9 @@ std::string Palladium::Lang::GetSys() {
} }
} }
std::string Palladium::Lang::Get(const std::string &key) { std::string Palladium::Lang::Get(const std::string &key) {
if (!appJson.contains("keys")) return "ERR-01"; auto tmp = lang_table.find(key);
nlohmann::json js = appJson["keys"]; if (tmp == lang_table.end()) return "ERR-02";
if (!js.contains(key)) return key; return tmp->second;
return js.at(key).get<std::string>();
} }
void Palladium::Lang::Load(const std::string &lang) { void Palladium::Lang::Load(const std::string &lang) {
@ -82,7 +85,6 @@ void Palladium::Lang::Load(const std::string &lang) {
if (appJson.is_discarded()) { if (appJson.is_discarded()) {
appJson = {}; appJson = {};
} }
return;
} else { } else {
values.open("romfs:/lang/en/app.json", std::ios::in); values.open("romfs:/lang/en/app.json", std::ios::in);
if (values.is_open()) { if (values.is_open()) {
@ -92,7 +94,12 @@ void Palladium::Lang::Load(const std::string &lang) {
if (appJson.is_discarded()) { if (appJson.is_discarded()) {
appJson = {}; appJson = {};
} }
return; }
lang_table.clear();
if (appJson.contains("keys")) {
for (auto &it : appJson["keys"].items()) {
lang_table[it.key()] = it.value().get<std::string>();
}
} }
} }

View File

@ -212,15 +212,10 @@ void Palladium::Init::NdspFirm() {
} }
} }
void Palladium::Scene::doDraw() { void Palladium::Scene::doUpdate() {
Ftrace::ScopedTrace st("pd-core", f2s(Scene::doDraw)); Ftrace::ScopedTrace st("pd-core", f2s(Scene::doUpdate));
if (!Palladium::Scene::scenes.empty()) Palladium::Scene::scenes.top()->Draw();
}
void Palladium::Scene::doLogic() {
Ftrace::ScopedTrace st("pd-core", f2s(Scene::doLogic));
if (!Palladium::Scene::scenes.empty()) if (!Palladium::Scene::scenes.empty())
Palladium::Scene::scenes.top()->Logic(); Palladium::Scene::scenes.top()->Update();
} }
void Palladium::Scene::Load(std::unique_ptr<Scene> scene, bool fade) { void Palladium::Scene::Load(std::unique_ptr<Scene> scene, bool fade) {
@ -278,8 +273,7 @@ bool Palladium::MainLoop() {
C3D_RenderTargetClear(pd_bottom, C3D_CLEAR_ALL, 0x00000000, 0); C3D_RenderTargetClear(pd_bottom, C3D_CLEAR_ALL, 0x00000000, 0);
frameloop(); frameloop();
if (pdi_enable_scene_system) { if (pdi_enable_scene_system) {
Palladium::Scene::doDraw(); Palladium::Scene::doUpdate();
Palladium::Scene::doLogic();
} }
return pdi_running; return pdi_running;
} }
@ -470,8 +464,7 @@ void Palladium::FrameEnd() {
Ftrace::ScopedTrace st("pd-core", f2s(FrameEnd)); Ftrace::ScopedTrace st("pd-core", f2s(FrameEnd));
C3D_FrameBegin(2); C3D_FrameBegin(2);
if (!pdi_enable_scene_system && pdi_settings) { if (!pdi_enable_scene_system && pdi_settings) {
Palladium::Scene::doDraw(); Palladium::Scene::doUpdate();
Palladium::Scene::doLogic();
} }
UI7::Update(); UI7::Update();
UI7::Debug(); UI7::Debug();
@ -510,7 +503,9 @@ std::vector<std::string> StrHelper(std::string input) {
return test1; return test1;
} }
void Palladium::RSettings::Draw(void) const { void Palladium::RSettings::Update() {
// Rendering / UI Logic
/// TODO: Update code for new system
if (m_state == RSETTINGS) { if (m_state == RSETTINGS) {
LI::OnScreen(false); LI::OnScreen(false);
if (UI7::BeginMenu("Palladium -> Settings")) { if (UI7::BeginMenu("Palladium -> Settings")) {
@ -793,9 +788,7 @@ void Palladium::RSettings::Draw(void) const {
UI7::EndMenu(); UI7::EndMenu();
} }
} }
} // Standart Logic
void Palladium::RSettings::Logic() {
/// Requests /// Requests
for (const auto &it : shared_request) { for (const auto &it : shared_request) {
if (it.first == 0x00000001) { if (it.first == 0x00000001) {