mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-05-30 08:26:24 -04:00
945ce3e4bc
* Alternate RMLUI Menu Sounds Those fit more the game I feel like. * swapped tab sounds * pressing A on tab button plays the OK sound * Fix tab sound + Added menu sounds to prelaunch menu * Centralize UI sound definitions * Improvements * Add "Play" button sound * Use kSoundItemFocus in prelaunch * Oops * Update play/enable/disable sounds --------- Co-authored-by: MelonSpeedruns <melonspeedruns@stratobox.net> Co-authored-by: Luke Street <luke@street.dev>
76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
#include "modal.hpp"
|
|
|
|
namespace dusk::ui {
|
|
|
|
Modal::Modal(Props props)
|
|
: WindowSmall("modal", "modal-dialog"), mProps(std::move(props)) {
|
|
auto* title = append(mDialog, "div");
|
|
title->SetClass("preset-title", true);
|
|
title->SetInnerRML(mProps.title);
|
|
|
|
auto* body = append(mDialog, "div");
|
|
body->SetClass("preset-intro", true);
|
|
body->SetInnerRML(mProps.bodyRml);
|
|
|
|
auto* actions = append(mDialog, "div");
|
|
actions->SetClass("modal-actions", true);
|
|
|
|
for (auto& action : mProps.actions) {
|
|
auto btn = std::make_unique<Button>(actions, action.label);
|
|
btn->root()->SetClass("modal-btn", true);
|
|
btn->on_pressed([this, callback = std::move(action.onPressed)] {
|
|
if (callback) {
|
|
callback(*this);
|
|
}
|
|
});
|
|
mButtons.push_back(std::move(btn));
|
|
}
|
|
}
|
|
|
|
bool Modal::focus() {
|
|
if (!mButtons.empty()) {
|
|
return mButtons.front()->focus();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void Modal::dismiss() {
|
|
if (mProps.onDismiss) {
|
|
mProps.onDismiss(*this);
|
|
return;
|
|
}
|
|
pop();
|
|
}
|
|
|
|
bool Modal::handle_nav_command(Rml::Event& event, NavCommand cmd) {
|
|
if (cmd == NavCommand::Cancel || cmd == NavCommand::Menu) {
|
|
mDoAud_seStartMenu(kSoundWindowClose);
|
|
dismiss();
|
|
return true;
|
|
}
|
|
|
|
int direction = 0;
|
|
if (cmd == NavCommand::Left) {
|
|
direction = -1;
|
|
} else if (cmd == NavCommand::Right) {
|
|
direction = 1;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
auto* target = event.GetTargetElement();
|
|
for (int i = 0; i < static_cast<int>(mButtons.size()); ++i) {
|
|
if (mButtons[i]->contains(target)) {
|
|
const int next = i + direction;
|
|
if (next >= 0 && next < static_cast<int>(mButtons.size()) && mButtons[next]->focus()) {
|
|
mDoAud_seStartMenu(kSoundItemFocus);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} // namespace dusk::ui
|