Skip to content
9 changes: 9 additions & 0 deletions include/dusk/action_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ enum class ActionBinds {
CALL_MIDNA,
OPEN_DUSKLIGHT_MENU,
TURBO_SPEED_BUTTON,
TOGGLE_TEXTURE_PACK,
COUNT,
};

enum class ActionBindType {
GAMEPLAY,
INTERFACE,
};

struct ActionBindData {
std::array<config::ActionBindConfigVar, 4>* configVars{};
std::string actionName{};
ActionBindType type{};
};

struct ActionBindPressData {
Expand All @@ -40,4 +47,6 @@ bool getActionBindHoldAnyPort(ActionBinds action);

int getActionBindButton(ActionBinds action, u32 port);

ActionBindType getActionBindType(ActionBinds action);

}
1 change: 1 addition & 0 deletions include/dusk/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ struct UserSettings {
std::array<ActionBindConfigVar, 4> callMidna;
std::array<ActionBindConfigVar, 4> openDusklightMenu;
std::array<ActionBindConfigVar, 4> turboSpeedButton;
std::array<ActionBindConfigVar, 4> toggleTexturePack;
} actionBindings;
};

Expand Down
20 changes: 16 additions & 4 deletions src/dusk/action_bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "dusk/action_bindings.h"

#include "aurora/gfx.h"
#include "aurora/lib/input.hpp"
#include "dusk/config.hpp"
#include "dusk/settings.h"
#include "dusk/ui/ui.hpp"

Expand All @@ -10,10 +12,11 @@ static std::array<std::array<ActionBindPressData, static_cast<int>(ActionBinds::

ActionBindsMap& getActionBinds() {
static ActionBindsMap actionBinds = {
{ActionBinds::FIRST_PERSON_CAMERA, {&getSettings().actionBindings.firstPersonCamera, "First Person Camera"}},
{ActionBinds::CALL_MIDNA, {&getSettings().actionBindings.callMidna, "Call Midna"}},
{ActionBinds::OPEN_DUSKLIGHT_MENU, {&getSettings().actionBindings.openDusklightMenu, "Open Dusklight Menu"}},
{ActionBinds::TURBO_SPEED_BUTTON, {&getSettings().actionBindings.turboSpeedButton, "Turbo Speed Button"}},
{ActionBinds::FIRST_PERSON_CAMERA, {&getSettings().actionBindings.firstPersonCamera, "First Person Camera", ActionBindType::GAMEPLAY}},
{ActionBinds::CALL_MIDNA, {&getSettings().actionBindings.callMidna, "Call Midna", ActionBindType::GAMEPLAY}},
{ActionBinds::TURBO_SPEED_BUTTON, {&getSettings().actionBindings.turboSpeedButton, "Turbo Speed Button", ActionBindType::GAMEPLAY}},
{ActionBinds::OPEN_DUSKLIGHT_MENU, {&getSettings().actionBindings.openDusklightMenu, "Open Dusklight Menu", ActionBindType::INTERFACE}},
{ActionBinds::TOGGLE_TEXTURE_PACK, {&getSettings().actionBindings.toggleTexturePack, "Toggle Texture Pack", ActionBindType::INTERFACE}},
};
return actionBinds;
}
Expand Down Expand Up @@ -65,6 +68,15 @@ void updateActionBindings() {
}
}
}

// Interface-specific triggers
if (getActionBindTrig(ActionBinds::TOGGLE_TEXTURE_PACK, port)) {
const bool enabled = !getSettings().game.enableTextureReplacements.getValue();
getSettings().game.enableTextureReplacements.setValue(enabled);
aurora_set_texture_replacements_enabled(enabled);
config::Save();
break;
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/dusk/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ UserSettings g_userSettings = {
ActionBindConfigVar{"actionBindings.turboButton_port2", PAD_NATIVE_BUTTON_INVALID},
ActionBindConfigVar{"actionBindings.turboButton_port3", PAD_NATIVE_BUTTON_INVALID},
},
.toggleTexturePack {
ActionBindConfigVar{"actionBindings.toggleTexturePack_port0", PAD_NATIVE_BUTTON_INVALID},
ActionBindConfigVar{"actionBindings.toggleTexturePack_port1", PAD_NATIVE_BUTTON_INVALID},
ActionBindConfigVar{"actionBindings.toggleTexturePack_port2", PAD_NATIVE_BUTTON_INVALID},
ActionBindConfigVar{"actionBindings.toggleTexturePack_port3", PAD_NATIVE_BUTTON_INVALID},
},
}
};

Expand Down Expand Up @@ -313,6 +319,10 @@ void registerSettings() {
Register(g_userSettings.actionBindings.turboSpeedButton[1]);
Register(g_userSettings.actionBindings.turboSpeedButton[2]);
Register(g_userSettings.actionBindings.turboSpeedButton[3]);
Register(g_userSettings.actionBindings.toggleTexturePack[0]);
Register(g_userSettings.actionBindings.toggleTexturePack[1]);
Register(g_userSettings.actionBindings.toggleTexturePack[2]);
Register(g_userSettings.actionBindings.toggleTexturePack[3]);
}

// Transient settings
Expand Down
39 changes: 31 additions & 8 deletions src/dusk/ui/controller_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,21 @@ void ControllerConfigWindow::render_page(Pane& pane, int port, Page page) {
pane.add_section("Custom Action Bindings");
pane.add_text("A key bound to any action here will REPLACE the default control for"
" that action. Only bind buttons here that aren't used anywhere else.");
for (auto& [configVars, actionName] : getActionBinds() | std::views::values) {
addActionBinding(&configVars->at(port), actionName);

pane.add_section("Gameplay");
for (auto& [configVars, actionName, type] : getActionBinds() | std::views::values) {
if (type == ActionBindType::GAMEPLAY) {
addActionBinding(&configVars->at(port), actionName);
}
}

pane.add_section("Interface");
for (auto& [configVars, actionName, type] : getActionBinds() | std::views::values) {
if (type == ActionBindType::INTERFACE) {
addActionBinding(&configVars->at(port), actionName);
}
}

break;
}

Expand All @@ -952,10 +964,11 @@ void ControllerConfigWindow::render_page(Pane& pane, int port, Page page) {

SDL_Gamepad* gamepad = gamepad_for_port(port);
pane.add_section("Custom Action Bindings");
pane.add_text("A button bound to any action here will REPLACE the default control for"
" that action. Only bind buttons here that aren't used anywhere else. The glyphs"
" shown for in game actions will not change. This is not recommended for "
" regular Gamecube controllers.");
pane.add_rml("A button bound to any action here will REPLACE the default control for"
" that action. Only bind buttons here that aren't used anywhere else."
" <br/><br/> Note: The glyphs shown for in-game actions will not change."
" This is not recommended for regular Gamecube controllers.");

auto addActionBinding = [&](auto actionBind, const std::string& key) {
pane.add_select_button({
.key = key,
Expand All @@ -978,8 +991,18 @@ void ControllerConfigWindow::render_page(Pane& pane, int port, Page page) {
});
};

for (auto& [configVars, actionName] : getActionBinds() | std::views::values) {
addActionBinding(&configVars->at(port), actionName);
pane.add_section("Gameplay");
for (auto& [configVars, actionName, type] : getActionBinds() | std::views::values) {
if (type == ActionBindType::GAMEPLAY) {
addActionBinding(&configVars->at(port), actionName);
}
}

pane.add_section("Interface");
for (auto& [configVars, actionName, type] : getActionBinds() | std::views::values) {
if (type == ActionBindType::INTERFACE) {
addActionBinding(&configVars->at(port), actionName);
}
}
break;
}
Expand Down
Loading