Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add window to customize specific game controls #851

Closed
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f543a90
Hack in 3DS ocarina controls
lilDavid Jul 12, 2022
b122d59
Temporarily (?) remove L disabling songs
lilDavid Jul 13, 2022
0cfba89
Make ocarina button names less confusing
lilDavid Jul 14, 2022
f57fe6f
Calculate ocarina button mask programmatically
lilDavid Jul 14, 2022
57fca55
Add checkbutton for 3DS controls
lilDavid Jul 14, 2022
cddc5f8
Make ocarina button colors match in 3DS mode
lilDavid Jul 15, 2022
35f97be
Add ocarina customization panel
lilDavid Jul 16, 2022
5103164
Add ocarina customization GUI
lilDavid Jul 17, 2022
a7e6997
Use structs for ocarina note colors
lilDavid Jul 18, 2022
d6e5bbf
Variable colors for custom ocarina controls
lilDavid Jul 18, 2022
5e99c49
Add explicitly setting d-pad controls for ocarina
lilDavid Jul 19, 2022
f469603
Rearrange ocarina panel
lilDavid Jul 19, 2022
1b797c0
Add right stick ocarina controls
lilDavid Jul 19, 2022
b827c48
Fix "gOcarina*BtnMap" CVar
lilDavid Jul 19, 2022
a7989f5
Make ocarina control editor more general-purpose
lilDavid Jul 26, 2022
d09d325
Change custom ocarina controls option to a checkbox
lilDavid Jul 26, 2022
0025eb1
Merge branch 'develop-zhora' into customizable_ocarina
lilDavid Jul 26, 2022
b7fc9d9
Allow resizing detailed control window
lilDavid Jul 26, 2022
230d767
End files with new lines
lilDavid Jul 26, 2022
530d473
Add window close widget to the detailed control editor
lilDavid Jul 29, 2022
f1e886c
Merge branch 'develop-zhora' of https://github.com/lilDavid/Shipwrigh…
lilDavid Jul 31, 2022
803dbc7
Define ocarina note colors with existing Color_RGB8 struct
lilDavid Jul 31, 2022
574307c
Change DetailedControlEditor::DrawOcarinaMapping to more general purp…
lilDavid Aug 1, 2022
aa6ebbd
Merge branch 'develop-zhora' into customizable_ocarina
lilDavid Aug 3, 2022
3880ead
Fix text label in DetailedControlEditor::DrawMapping
lilDavid Aug 3, 2022
59a7bf2
Merge branch 'customizable_ocarina' of https://github.com/lilDavid/Sh…
lilDavid Aug 3, 2022
10c131b
Squashed commit of the following:
lilDavid Aug 9, 2022
1ef8b95
Rework control editor UI for overall menu cleanup
lilDavid Aug 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libultraship/libultraship/GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Game {
gfx_get_current_rendering_api()->set_texture_filter((FilteringMode) CVar_GetS32("gTextureFilter", FILTER_THREE_POINT));
SohImGui::console->opened = CVar_GetS32("gConsoleEnabled", 0);
SohImGui::controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0);
SohImGui::ocarina->Opened = CVar_GetS32("gOcarinaConfigurationEnabled", 0);
UpdateAudio();
});
}
Expand Down
8 changes: 7 additions & 1 deletion libultraship/libultraship/ImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace SohImGui {
Console* console = new Console;
GameOverlay* overlay = new GameOverlay;
InputEditor* controller = new InputEditor;
OcarinaEditor* ocarina = new OcarinaEditor;
static ImVector<ImRect> s_GroupPanelLabelStack;
bool p_open = false;
bool needs_save = false;
Expand Down Expand Up @@ -330,6 +331,7 @@ namespace SohImGui {
console->Init();
overlay->Init();
controller->Init();
ocarina->Init();
ImGuiWMInit();
ImGuiBackendInit();

Expand Down Expand Up @@ -761,12 +763,15 @@ namespace SohImGui {
EnhancementCheckbox("Controller Configuration", "gControllerConfigurationEnabled");
controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0);

EnhancementCheckbox("Ocarina Configuration", "gOcarinaConfigurationEnabled");
ocarina->Opened = CVar_GetS32("gOcarinaConfigurationEnabled", 0);

ImGui::Separator();

// TODO mutual exclusions -- There should be some system to prevent conclifting enhancements from being selected
EnhancementCheckbox("D-pad Support on Pause and File Select", "gDpadPauseName");
Tooltip("Enables Pause and File Select screen navigation with the D-pad\nIf used with D-pad as Equip Items, you must hold C-Up\nto equip instead of navigate");
EnhancementCheckbox("D-pad Support in Ocarina and Text Choice", "gDpadOcarinaText");
EnhancementCheckbox("D-pad Support in Text Choice", "gDpadText");
EnhancementCheckbox("D-pad Support for Browsing Shop Items", "gDpadShop");
EnhancementCheckbox("D-pad as Equip Items", "gDpadEquips");
Tooltip("Allows the D-pad to be used as extra C buttons");
Expand Down Expand Up @@ -1275,6 +1280,7 @@ namespace SohImGui {

console->Draw();
controller->DrawHud();
ocarina->DrawHud();

for (auto& windowIter : customWindows) {
CustomWindow& window = windowIter.second;
Expand Down
2 changes: 2 additions & 0 deletions libultraship/libultraship/ImGuiImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Lib/ImGui/imgui.h"
#include "Console.h"
#include "InputEditor.h"
#include "OcarinaEditor.h"

struct GameAsset {
uint32_t textureId;
Expand Down Expand Up @@ -61,6 +62,7 @@ namespace SohImGui {

extern Console* console;
extern Ship::InputEditor* controller;
extern Ship::OcarinaEditor* ocarina;
extern Ship::GameOverlay* overlay;
extern bool needs_save;
void Init(WindowImpl window_impl);
Expand Down
171 changes: 171 additions & 0 deletions libultraship/libultraship/OcarinaEditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#include "OcarinaEditor.h"
#include "Lib/ImGui/imgui.h"
#include "ImGuiImpl.h"
#include "Lib/ImGui/imgui_internal.h"
#include "Cvar.h"
#include "UltraController.h"
#include "Utils/StringHelper.h"

namespace Ship {

float TableCellWidth = 300.0f; //1 Col

void Table_InitHeader(bool has_header = true) {
if (has_header) {
ImGui::TableHeadersRow();
}
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding(); //This is to adjust Vertical pos of item in a cell to be normlized.
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
}

void Table_NextCol() {
ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
}

void Draw_HelpIcon(const std::string& helptext, bool sameline = true, int Pos = 0) {
// place the ? button to the most of the right side of the cell it is using.
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 15);
ImGui::SmallButton("?");
SohImGui::Tooltip(helptext.c_str());
if (sameline) {
//I do not use ImGui::SameLine(); because it make some element vanish.
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 22);
}
}

// Assumes only addition since this is only used to construct the button map
// So this does not work like a proper linked hash map's insertion
void OcarinaEditor::addButton(uint32_t mask, const char* name) {
buttons.push_back(std::make_pair(mask, name));
buttonmap[mask] = std::prev(buttons.end());
}

void OcarinaEditor::Init() {
addButton(BTN_A, "A");
addButton(BTN_CUP, "C Up");
addButton(BTN_CDOWN, "C Down");
addButton(BTN_CLEFT, "C Left");
addButton(BTN_CRIGHT, "C Right");
addButton(BTN_L, "L");
addButton(BTN_Z, "Z");
addButton(BTN_R, "R");
addButton(BTN_START, "Start");
addButton(BTN_DUP, "D-pad up");
addButton(BTN_DDOWN, "D-pad down");
addButton(BTN_DLEFT, "D-pad left");
addButton(BTN_DRIGHT, "D-pad right");
addButton(0, "None");
}

void OcarinaEditor::DrawMapping(const char* label, const char* id, uint32_t n64Btn, float width) {
std::string cVar = StringHelper::Sprintf("gOcarina%sBtnMap", id);
uint32_t currentButton = CVar_GetS32(cVar.c_str(), n64Btn);

const char* preview;
if (buttonmap.contains(currentButton)) {
preview = buttonmap[currentButton]->second;
} else {
preview = "";
}

ImVec2 len = ImGui::CalcTextSize(label);
ImVec2 pos = ImGui::GetCursorPos();
ImGui::SetCursorPosY(pos.y + len.y / 4);
ImGui::SetCursorPosX(pos.x + abs(len.x - width));
ImGui::Text("%s", label);
ImGui::SameLine();
ImGui::SetCursorPosY(pos.y);

bool dpad = CVar_GetS32("gDpadOcarina", 0);
uint32_t dpadMask = BTN_DUP | BTN_DDOWN | BTN_DLEFT | BTN_DRIGHT;

ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
if (ImGui::BeginCombo(StringHelper::Sprintf("##OcarinaMap%s", id).c_str(), preview)) {
for (auto i = buttons.begin(); i != buttons.end(); i++) {
if (dpad && (i->first & dpadMask) != 0) { // Hide d-pad options if d-pad check button set
continue;
}
if (ImGui::Selectable(i->second, i->first == currentButton)) {
CVar_SetS32(cVar.c_str(), i->first);
}
}
ImGui::EndCombo();
}
}

void OcarinaEditor::DrawHud() {
if (!this->Opened) {
return;
}

ImGui::SetNextWindowSizeConstraints(ImVec2(410, 0), ImVec2(1200, 290));
if (!ImGui::Begin("Ocarina Configuration", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::End();
return;
}

float column2x;
if (ImGui::BeginTable("tableOcarinaScheme", 2, ImGuiTableFlags_BordersH | ImGuiTableFlags_BordersV | ImGuiTableFlags_Hideable)) {
ImGui::TableSetupColumn("N64 Scheme", ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_NoSort, TableCellWidth);
ImGui::TableSetupColumn("Custom Scheme", ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_NoSort, TableCellWidth);
Table_InitHeader();
Draw_HelpIcon("Play the ocarina with A and the C buttons");
SohImGui::EnhancementRadioButton("N64 Controls", "gOcarinaControls", 0);
Table_NextCol();
column2x = ImGui::GetCursorPosX();
Draw_HelpIcon("Customize the ocarina controls to your liking");
SohImGui::EnhancementRadioButton("Custom Controls", "gOcarinaControls", 1);
ImGui::EndTable();
}

if (CVar_GetS32("gOcarinaControls", 0) == 1) {
float width;

SohImGui::BeginGroupPanel("Notes", ImVec2(158, 20));
width = ImGui::CalcTextSize("D5").x + 10;
DrawMapping("D5", "D5", BTN_CUP, width);
DrawMapping("B4", "B4", BTN_CLEFT, width);
DrawMapping("A4", "A4", BTN_CRIGHT, width);
DrawMapping("F4", "F4", BTN_CDOWN, width);
DrawMapping("D4", "D4", BTN_A, width);
ImGui::Dummy(ImVec2(0, 5));
SohImGui::EndGroupPanel(33);

ImGui::SameLine();

const ImVec2 cursor = ImGui::GetCursorPos();
SohImGui::BeginGroupPanel("Misc.", ImVec2(158, 20));
width = ImGui::CalcTextSize("Disable songs").x + 10;
DrawMapping("Disable songs", "Disable", BTN_L, width);
DrawMapping("Pitch up", "Sharp", BTN_R, width);
DrawMapping("Pitch down", "Flat", BTN_Z, width);
ImGui::Dummy(ImVec2(0, 5));
SohImGui::EndGroupPanel();

ImGui::SetCursorPosX(cursor.x);
ImGui::SetCursorPosY(cursor.y + 100);
SohImGui::BeginGroupPanel("Alternate controls", ImVec2(225.5, 20));
float cursorX = ImGui::GetCursorPosX() + 10;
ImGui::SetCursorPosX(cursorX);
SohImGui::EnhancementCheckbox("Play with D-pad", "gDpadOcarina");
ImGui::SetCursorPosX(cursorX);
SohImGui::EnhancementCheckbox("Play with camera stick", "gRStickOcarina");
ImGui::Dummy(ImVec2(0, 5));
SohImGui::EndGroupPanel();
} else {
ImGui::Dummy(ImVec2(0, 5));
SohImGui::EnhancementCheckbox("Play with D-pad", "gDpadOcarina");
ImGui::SameLine();
ImGui::SetCursorPosX(column2x);
SohImGui::EnhancementCheckbox("Play with camera stick", "gRStickOcarina");
ImGui::Dummy(ImVec2(0, 5));
ImGui::TextWrapped("To further modify ocarina controls, select \"Custom Controls\" from the menu at the top.");
}

ImGui::End();
}
}
24 changes: 24 additions & 0 deletions libultraship/libultraship/OcarinaEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <string>
#include <unordered_map>
#include <list>
#include <utility>

#include "Lib/ImGui/imgui.h"

namespace Ship {

class OcarinaEditor {
private:
std::list<std::pair<uint32_t, const char*>> buttons;
std::unordered_map<uint32_t, decltype(buttons)::iterator> buttonmap;
void addButton(uint32_t, const char*);

public:
bool Opened = false;
void Init();
void DrawHud();
void DrawMapping(const char*, const char*, uint32_t, float);
};
}
2 changes: 2 additions & 0 deletions libultraship/libultraship/libultraship.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
<ClCompile Include="Scene.cpp" />
<ClCompile Include="Skeleton.cpp" />
<ClCompile Include="SkeletonLimb.cpp" />
<ClCompile Include="OcarinaEditor.cpp" />
<ClCompile Include="Text.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="TextureMod.cpp" />
Expand All @@ -344,6 +345,7 @@
<ClCompile Include="SDLController.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="OcarinaEditor.h" />
<ClInclude Include="Lib\Mercury\Mercury.h" />
<ClInclude Include="Lib\nlohmann\json.hpp" />
<ClInclude Include="abi.h" />
Expand Down
9 changes: 9 additions & 0 deletions libultraship/libultraship/libultraship.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<Filter Include="Source Files\Controller\InputEditor">
<UniqueIdentifier>{010dc29b-d1f6-4793-a4e7-4156aa4fcdd6}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Controller\OcarinaEditor">
<UniqueIdentifier>{1d1c5826-31e6-4ed1-a821-759aab1e7447}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Factories\MaterialFactory.cpp">
Expand Down Expand Up @@ -366,6 +369,9 @@
<ClCompile Include="Lib\Mercury\Mercury.cpp">
<Filter>Source Files\Lib\Mercury</Filter>
</ClCompile>
<ClCompile Include="OcarinaEditor.cpp">
<Filter>Source Files\Controller\OcarinaEditor</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Lib\tinyxml2\tinyxml2.h">
Expand Down Expand Up @@ -683,5 +689,8 @@
<ClInclude Include="Lib\Mercury\Mercury.h">
<Filter>Source Files\Lib\Mercury</Filter>
</ClInclude>
<ClInclude Include="OcarinaEditor.h">
<Filter>Source Files\Controller\OcarinaEditor</Filter>
</ClInclude>
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions soh/include/z64audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1060,11 +1060,11 @@ typedef struct {
} OcarinaStaff;

typedef enum {
/* 0 */ OCARINA_NOTE_A,
/* 1 */ OCARINA_NOTE_C_DOWN,
/* 2 */ OCARINA_NOTE_C_RIGHT,
/* 3 */ OCARINA_NOTE_C_LEFT,
/* 4 */ OCARINA_NOTE_C_UP,
/* 0 */ OCARINA_NOTE_D4,
/* 1 */ OCARINA_NOTE_F4,
/* 2 */ OCARINA_NOTE_A4,
/* 3 */ OCARINA_NOTE_B4,
/* 4 */ OCARINA_NOTE_D5,
/* -1 */ OCARINA_NOTE_INVALID = 0xFF
} OcarinaNoteIdx;

Expand Down
Loading