mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-17 22:12:43 -04:00
Touch controls (#2053)
* WIP touch controls * Action icons * Updates * Don't mutate freeCamera config; allow switching between touch and controller cam * Wow * Fix build & add Skip button * Fix build & add settings * RCSS cleanup * Dpad and fishing, might redo * Add menu mouse controls * More pointer & fix icons * Optimizations & introduce layout system * Update aurora * Implement touch controls layout editor * Cleanup & fixes * Allow disabling mouse/touch in menus * More fixes
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "Z2AudioLib/Z2SeMgr.h"
|
||||
#include "m_Do/m_Do_audio.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace dusk::ui {
|
||||
namespace {
|
||||
@@ -19,11 +20,15 @@ Rml::ElementDocument* load_document(const Rml::String& source) {
|
||||
|
||||
} // namespace
|
||||
|
||||
Document::Document(const Rml::String& source) : mDocument(load_document(source)) {
|
||||
Document::Document(const Rml::String& source, bool passive)
|
||||
: mDocument(load_document(source)), mPassive(passive) {
|
||||
// Block events while hidden (except for Menu command); play nav sounds when visible
|
||||
listen(
|
||||
Rml::EventId::Keydown,
|
||||
[this](Rml::Event& event) {
|
||||
if (mPassive) {
|
||||
return;
|
||||
}
|
||||
const auto cmd = map_nav_event(event);
|
||||
if (cmd != NavCommand::Menu && !visible()) {
|
||||
event.StopImmediatePropagation();
|
||||
@@ -40,11 +45,14 @@ Document::Document(const Rml::String& source) : mDocument(load_document(source))
|
||||
listen(Rml::EventId::Scroll, blockUnlessVisible, true);
|
||||
|
||||
listen(Rml::EventId::Keydown, [this](Rml::Event& event) {
|
||||
const auto cmd = map_nav_event(event);
|
||||
if (cmd == NavCommand::None) {
|
||||
if (mPassive) {
|
||||
auto* doc = top_document();
|
||||
if (doc != nullptr && doc->handle_nav_event(event)) {
|
||||
event.StopPropagation();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (handle_nav_command(event, cmd)) {
|
||||
if (handle_nav_event(event)) {
|
||||
event.StopPropagation();
|
||||
}
|
||||
});
|
||||
@@ -97,6 +105,18 @@ void Document::listen(Rml::Element* element, Rml::EventId event,
|
||||
std::make_unique<ScopedEventListener>(element, event, std::move(callback), capture));
|
||||
}
|
||||
|
||||
void Document::listen(Rml::Element* element, const Rml::String& event,
|
||||
ScopedEventListener::Callback callback, bool capture) {
|
||||
if (element == nullptr) {
|
||||
element = mDocument;
|
||||
}
|
||||
if (element == nullptr || event.empty() || !callback) {
|
||||
return;
|
||||
}
|
||||
mListeners.emplace_back(
|
||||
std::make_unique<ScopedEventListener>(element, event, std::move(callback), capture));
|
||||
}
|
||||
|
||||
bool Document::visible() const {
|
||||
if (mDocument == nullptr) {
|
||||
return false;
|
||||
@@ -104,6 +124,14 @@ bool Document::visible() const {
|
||||
return *mDocument->GetProperty(Rml::PropertyId::Visibility) == Rml::Style::Visibility::Visible;
|
||||
}
|
||||
|
||||
bool Document::handle_nav_event(Rml::Event& event) {
|
||||
const auto cmd = map_nav_event(event);
|
||||
if (cmd == NavCommand::None) {
|
||||
return false;
|
||||
}
|
||||
return handle_nav_command(event, cmd);
|
||||
}
|
||||
|
||||
bool Document::handle_nav_command(Rml::Event& event, NavCommand cmd) {
|
||||
if (cmd == NavCommand::Menu) {
|
||||
mDoAud_seStartMenu(visible() ? kSoundMenuClose : kSoundMenuOpen);
|
||||
|
||||
Reference in New Issue
Block a user