mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp
synced 2026-07-28 07:09:50 -04:00
Split default input mappings by device, disabled input while menu is open, made config menu open with escape/select, made config menu close with escape
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "recomp_ui.h"
|
||||
#include "../../ultramodern/config.hpp"
|
||||
#include "../../ultramodern/ultramodern.hpp"
|
||||
#include "RmlUi/Core.h"
|
||||
|
||||
ultramodern::GraphicsConfig cur_options;
|
||||
@@ -67,6 +68,19 @@ public:
|
||||
options_handle.DirtyVariable("options_changed");
|
||||
update_graphics_config(new_options);
|
||||
});
|
||||
recomp::register_event(listener, "config_keydown",
|
||||
[](const std::string& param, Rml::Event& event) {
|
||||
if (event.GetId() == Rml::EventId::Keydown) {
|
||||
if (event.GetParameter<Rml::Input::KeyIdentifier>("key_identifier", Rml::Input::KeyIdentifier::KI_UNKNOWN) == Rml::Input::KeyIdentifier::KI_ESCAPE) {
|
||||
if (ultramodern::is_game_started()) {
|
||||
recomp::set_current_menu(recomp::Menu::None);
|
||||
}
|
||||
else {
|
||||
recomp::set_current_menu(recomp::Menu::Launcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
void make_bindings(Rml::Context* context) override {
|
||||
Rml::DataModelConstructor constructor = context->CreateDataModel("graphics_model");
|
||||
|
||||
+27
-1
@@ -602,7 +602,6 @@ namespace recomp {
|
||||
std::unordered_map<Rml::String, UiEventListener> listener_map_;
|
||||
public:
|
||||
Rml::EventListener* InstanceEventListener(const Rml::String& value, Rml::Element* element) override {
|
||||
printf("Instancing event listener for %s\n", value.c_str());
|
||||
// Check if a listener has already been made for the full event string and return it if so.
|
||||
auto find_listener_it = listener_map_.find(value);
|
||||
if (find_listener_it != listener_map_.end()) {
|
||||
@@ -878,6 +877,29 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderTexture* swap_
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If no menu is open and the game has been started and either the escape key or select button are pressed, open the config menu.
|
||||
if (cur_menu == recomp::Menu::None && ultramodern::is_game_started()) {
|
||||
bool open_config = false;
|
||||
|
||||
switch (cur_event.type) {
|
||||
case SDL_EventType::SDL_KEYDOWN:
|
||||
if (cur_event.key.keysym.scancode == SDL_Scancode::SDL_SCANCODE_ESCAPE) {
|
||||
open_config = true;
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_CONTROLLERBUTTONDOWN:
|
||||
if (cur_event.cbutton.button == SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_BACK) {
|
||||
open_config = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (open_config) {
|
||||
cur_menu = recomp::Menu::Config;
|
||||
open_menu.store(recomp::Menu::Config);
|
||||
UIContext.rml.swap_document(cur_menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UIContext.rml.update_focus(mouse_moved);
|
||||
@@ -926,3 +948,7 @@ void recomp::destroy_ui() {
|
||||
Rml::Shutdown();
|
||||
UIContext.rml.unload();
|
||||
}
|
||||
|
||||
recomp::Menu recomp::get_current_menu() {
|
||||
return open_menu.load();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user