Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Malkierian committed Jun 20, 2024
1 parent a7a1af3 commit 86a1a03
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 172 deletions.
2 changes: 1 addition & 1 deletion mm/2s2h/BenGui/BenGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void SetupGuiElements() {
#if defined(__SWITCH__) || defined(__WIIU__)
gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Press - to access enhancements menu");
#else
//gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Press F1 to access enhancements menu");
// gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Press F1 to access enhancements menu");
#endif
}

Expand Down
99 changes: 56 additions & 43 deletions mm/2s2h/BenGui/BenInputEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ void BenInputEditorWindow::UpdateElement() {
if (mGameInputBlockTimer != INT32_MAX) {
mGameInputBlockTimer--;
if (mGameInputBlockTimer <= 0) {
Ship::Context::GetInstance()->GetControlDeck()->UnblockGameInput(INPUT_EDITOR_WINDOW_GAME_INPUT_BLOCK_ID);
Ship::Context::GetInstance()->GetControlDeck()->UnblockGameInput(
INPUT_EDITOR_WINDOW_GAME_INPUT_BLOCK_ID);
mGameInputBlockTimer = INT32_MAX;
}
}
Expand Down Expand Up @@ -165,7 +166,7 @@ void BenInputEditorWindow::DrawAnalogPreview(const char* label, ImVec2 stick, fl
#define BUTTON_COLOR_GAMEPAD_PURPLE_HOVERED ImVec4(0.431f, 0.369f, 0.706f, 1.0f)

void BenInputEditorWindow::GetButtonColorsForShipDeviceIndex(Ship::ShipDeviceIndex lusIndex, ImVec4& buttonColor,
ImVec4& buttonHoveredColor) {
ImVec4& buttonHoveredColor) {
switch (lusIndex) {
case Ship::ShipDeviceIndex::Keyboard:
buttonColor = BUTTON_COLOR_KEYBOARD_BEIGE;
Expand Down Expand Up @@ -231,9 +232,11 @@ void BenInputEditorWindow::DrawButtonLineAddMappingButton(uint8_t port, CONTROLL
}

void BenInputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROLLERBUTTONS_T bitmask, std::string id) {
auto mapping =
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetButton(bitmask)->GetButtonMappingById(
id);
auto mapping = Ship::Context::GetInstance()
->GetControlDeck()
->GetControllerByPort(port)
->GetButton(bitmask)
->GetButtonMappingById(id);
if (mapping == nullptr) {
return;
}
Expand Down Expand Up @@ -420,7 +423,11 @@ void BenInputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROL
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(1.0f, 0.5f));
if (ImGui::Button(StringHelper::Sprintf("%s###removeButtonMappingButton%s", ICON_FA_TIMES, id.c_str()).c_str(),
ImVec2(ImGui::CalcTextSize(ICON_FA_TIMES).x + SCALE_IMGUI_SIZE(10.0f), 0.0f))) {
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetButton(bitmask)->ClearButtonMapping(id);
Ship::Context::GetInstance()
->GetControlDeck()
->GetControllerByPort(port)
->GetButton(bitmask)
->ClearButtonMapping(id);
};
ImGui::PopStyleColor();
ImGui::PopStyleColor();
Expand All @@ -430,7 +437,7 @@ void BenInputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROL
}

void BenInputEditorWindow::DrawButtonLine(const char* buttonName, uint8_t port, CONTROLLERBUTTONS_T bitmask,
ImVec4 color = CHIP_COLOR_N64_GREY) {
ImVec4 color = CHIP_COLOR_N64_GREY) {
ImGui::NewLine();
ImGui::SameLine(SCALE_IMGUI_SIZE(32.0f));
DrawInputChip(buttonName, color);
Expand All @@ -441,7 +448,8 @@ void BenInputEditorWindow::DrawButtonLine(const char* buttonName, uint8_t port,
DrawButtonLineAddMappingButton(port, bitmask);
}

void BenInputEditorWindow::DrawStickDirectionLineAddMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction) {
void BenInputEditorWindow::DrawStickDirectionLineAddMappingButton(uint8_t port, uint8_t stick,
Ship::Direction direction) {
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(1.0f, 0.5f));
auto popupId = StringHelper::Sprintf("addStickDirectionMappingPopup##%d-%d-%d", port, stick, direction);
if (ImGui::Button(
Expand Down Expand Up @@ -483,8 +491,8 @@ void BenInputEditorWindow::DrawStickDirectionLineAddMappingButton(uint8_t port,
}
}

void BenInputEditorWindow::DrawStickDirectionLineEditMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction,
std::string id) {
void BenInputEditorWindow::DrawStickDirectionLineEditMappingButton(uint8_t port, uint8_t stick,
Ship::Direction direction, std::string id) {
std::shared_ptr<Ship::ControllerAxisDirectionMapping> mapping = nullptr;
if (stick == Ship::LEFT) {
mapping = Ship::Context::GetInstance()
Expand Down Expand Up @@ -601,7 +609,7 @@ void BenInputEditorWindow::DrawStickDirectionLineEditMappingButton(uint8_t port,
}

void BenInputEditorWindow::DrawStickDirectionLine(const char* axisDirectionName, uint8_t port, uint8_t stick,
Ship::Direction direction, ImVec4 color = CHIP_COLOR_N64_GREY) {
Ship::Direction direction, ImVec4 color = CHIP_COLOR_N64_GREY) {
ImGui::NewLine();
ImGui::SameLine();
ImGui::BeginDisabled();
Expand All @@ -616,7 +624,8 @@ void BenInputEditorWindow::DrawStickDirectionLine(const char* axisDirectionName,
DrawStickDirectionLineAddMappingButton(port, stick, direction);
}

void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t id, ImVec4 color = CHIP_COLOR_N64_GREY) {
void BenInputEditorWindow::DrawStickSection(uint8_t port, uint8_t stick, int32_t id,
ImVec4 color = CHIP_COLOR_N64_GREY) {
static int8_t sX, sY;
std::shared_ptr<Ship::ControllerStick> controllerStick = nullptr;
if (stick == Ship::LEFT) {
Expand Down Expand Up @@ -760,7 +769,7 @@ void BenInputEditorWindow::UpdateBitmaskToMappingIds(uint8_t port) {
// todo: do we need this now that ControllerButton exists?

for (auto [bitmask, button] :
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetAllButtons()) {
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetAllButtons()) {
for (auto [id, mapping] : button->GetAllButtonMappings()) {
// using a vector here instead of a set because i want newly added mappings
// to go to the end of the list instead of autosorting
Expand All @@ -778,7 +787,8 @@ void BenInputEditorWindow::UpdateStickDirectionToMappingIds(uint8_t port) {
{ std::make_pair<uint8_t, std::shared_ptr<Ship::ControllerStick>>(
Ship::LEFT, Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetLeftStick()),
std::make_pair<uint8_t, std::shared_ptr<Ship::ControllerStick>>(
Ship::RIGHT, Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetRightStick()) }) {
Ship::RIGHT,
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetRightStick()) }) {
for (auto direction : { Ship::LEFT, Ship::RIGHT, Ship::UP, Ship::DOWN }) {
for (auto [id, mapping] : stick.second->GetAllAxisDirectionMappingByDirection(direction)) {
// using a vector here instead of a set because i want newly added mappings
Expand Down Expand Up @@ -838,8 +848,11 @@ bool BenInputEditorWindow::TestingRumble() {
}

void BenInputEditorWindow::DrawRumbleSection(uint8_t port) {
for (auto [id, mapping] :
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetRumble()->GetAllRumbleMappings()) {
for (auto [id, mapping] : Ship::Context::GetInstance()
->GetControlDeck()
->GetControllerByPort(port)
->GetRumble()
->GetAllRumbleMappings()) {
ImGui::AlignTextToFramePadding();
ImGui::SetNextItemOpen(true, ImGuiCond_Once);
auto buttonColor = ImGui::GetStyleColorVec4(ImGuiCol_Button);
Expand Down Expand Up @@ -1015,7 +1028,7 @@ void BenInputEditorWindow::DrawAddLEDMappingButton(uint8_t port) {

void BenInputEditorWindow::DrawLEDSection(uint8_t port) {
for (auto [id, mapping] :
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetLED()->GetAllLEDMappings()) {
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetLED()->GetAllLEDMappings()) {
ImGui::AlignTextToFramePadding();
ImGui::SetNextItemOpen(true, ImGuiCond_Once);
auto open = ImGui::TreeNode(
Expand Down Expand Up @@ -1093,7 +1106,8 @@ void BenInputEditorWindow::DrawAddGyroMappingButton(uint8_t port) {
}

void BenInputEditorWindow::DrawGyroSection(uint8_t port) {
auto mapping = Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetGyro()->GetGyroMapping();
auto mapping =
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(port)->GetGyro()->GetGyroMapping();
if (mapping != nullptr) {
auto id = mapping->GetGyroMappingId();
ImGui::AlignTextToFramePadding();
Expand Down Expand Up @@ -1188,7 +1202,7 @@ void BenInputEditorWindow::DrawButtonDeviceIcons(uint8_t portIndex, std::set<CON
std::vector<std::pair<Ship::ShipDeviceIndex, bool>> lusDeviceIndiciesWithMappings;
for (auto lusIndex : allLusDeviceIndices) {
for (auto [bitmask, button] :
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->GetAllButtons()) {
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->GetAllButtons()) {
if (!bitmasks.contains(bitmask)) {
continue;
}
Expand Down Expand Up @@ -1490,15 +1504,14 @@ void BenInputEditorWindow::DrawPortTabContents(uint8_t portIndex) {
DrawButtonLine("R", portIndex, BTN_R);
DrawButtonLine("Z", portIndex, BTN_Z);
DrawButtonLine(StringHelper::Sprintf("C %s", ICON_FA_ARROW_UP).c_str(), portIndex, BTN_CUP,
CHIP_COLOR_N64_YELLOW);
CHIP_COLOR_N64_YELLOW);
DrawButtonLine(StringHelper::Sprintf("C %s", ICON_FA_ARROW_DOWN).c_str(), portIndex, BTN_CDOWN,
CHIP_COLOR_N64_YELLOW);
CHIP_COLOR_N64_YELLOW);
DrawButtonLine(StringHelper::Sprintf("C %s", ICON_FA_ARROW_LEFT).c_str(), portIndex, BTN_CLEFT,
CHIP_COLOR_N64_YELLOW);
CHIP_COLOR_N64_YELLOW);
DrawButtonLine(StringHelper::Sprintf("C %s", ICON_FA_ARROW_RIGHT).c_str(), portIndex, BTN_CRIGHT,
CHIP_COLOR_N64_YELLOW);
}
else {
CHIP_COLOR_N64_YELLOW);
} else {
DrawButtonDeviceIcons(portIndex, mButtonsBitmasks);
}

Expand All @@ -1508,48 +1521,42 @@ void BenInputEditorWindow::DrawPortTabContents(uint8_t portIndex) {
DrawButtonLine(StringHelper::Sprintf("%s", ICON_FA_ARROW_DOWN).c_str(), portIndex, BTN_DDOWN);
DrawButtonLine(StringHelper::Sprintf("%s", ICON_FA_ARROW_LEFT).c_str(), portIndex, BTN_DLEFT);
DrawButtonLine(StringHelper::Sprintf("%s", ICON_FA_ARROW_RIGHT).c_str(), portIndex, BTN_DRIGHT);
}
else {
} else {
DrawButtonDeviceIcons(portIndex, mDpadBitmasks);
}

if (ImGui::CollapsingHeader("Analog Stick", NULL, ImGuiTreeNodeFlags_DefaultOpen)) {
DrawAnalogStickDeviceIcons(portIndex, Ship::LEFT_STICK);
DrawStickSection(portIndex, Ship::LEFT, 0);
}
else {
} else {
DrawAnalogStickDeviceIcons(portIndex, Ship::LEFT_STICK);
}

if (ImGui::CollapsingHeader("Additional (\"Right\") Stick")) {
DrawAnalogStickDeviceIcons(portIndex, Ship::RIGHT_STICK);
DrawStickSection(portIndex, Ship::RIGHT, 1, CHIP_COLOR_N64_YELLOW);
}
else {
} else {
DrawAnalogStickDeviceIcons(portIndex, Ship::RIGHT_STICK);
}

if (ImGui::CollapsingHeader("Rumble")) {
DrawRumbleDeviceIcons(portIndex);
DrawRumbleSection(portIndex);
}
else {
} else {
DrawRumbleDeviceIcons(portIndex);
}

if (ImGui::CollapsingHeader("Gyro")) {
DrawGyroDeviceIcons(portIndex);
DrawGyroSection(portIndex);
}
else {
} else {
DrawGyroDeviceIcons(portIndex);
}

if (ImGui::CollapsingHeader("LEDs")) {
DrawLEDDeviceIcons(portIndex);
DrawLEDSection(portIndex);
}
else {
} else {
DrawLEDDeviceIcons(portIndex);
}

Expand All @@ -1568,8 +1575,10 @@ void BenInputEditorWindow::DrawSetDefaultsButton(uint8_t portIndex) {

if (ImGui::BeginPopup(popupId.c_str())) {
std::map<Ship::ShipDeviceIndex, std::pair<std::string, int32_t>> indexMappings;
for (auto [lusIndex, mapping] :
Ship::Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
for (auto [lusIndex, mapping] : Ship::Context::GetInstance()
->GetControlDeck()
->GetDeviceIndexMappingManager()
->GetAllDeviceIndexMappings()) {
auto sdlIndexMapping = std::static_pointer_cast<Ship::ShipDeviceIndexToSDLDeviceIndexMapping>(mapping);
if (sdlIndexMapping == nullptr) {
continue;
Expand All @@ -1593,8 +1602,10 @@ void BenInputEditorWindow::DrawSetDefaultsButton(uint8_t portIndex) {
ImGui::CloseCurrentPopup();
}
if (ImGui::Button("Set defaults")) {
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->ClearAllMappingsForDevice(
Ship::ShipDeviceIndex::Keyboard);
Ship::Context::GetInstance()
->GetControlDeck()
->GetControllerByPort(portIndex)
->ClearAllMappingsForDevice(Ship::ShipDeviceIndex::Keyboard);
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->AddDefaultMappings(
Ship::ShipDeviceIndex::Keyboard);
shouldClose = true;
Expand Down Expand Up @@ -1626,8 +1637,10 @@ void BenInputEditorWindow::DrawSetDefaultsButton(uint8_t portIndex) {
ImGui::CloseCurrentPopup();
}
if (ImGui::Button("Set defaults")) {
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->ClearAllMappingsForDevice(
lusIndex);
Ship::Context::GetInstance()
->GetControlDeck()
->GetControllerByPort(portIndex)
->ClearAllMappingsForDevice(lusIndex);
Ship::Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->AddDefaultMappings(
lusIndex);
shouldClose = true;
Expand Down
11 changes: 7 additions & 4 deletions mm/2s2h/BenGui/BenInputEditorWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BenInputEditorWindow : public Ship::GuiWindow {
bool TestingRumble();
void DrawFullContents();
void DrawPortTabContents(uint8_t portIndex);
void DrawContents() override {};
void DrawContents() override{};

protected:
void InitElement() override;
Expand All @@ -39,7 +39,8 @@ class BenInputEditorWindow : public Ship::GuiWindow {
void DrawButtonLineEditMappingButton(uint8_t port, CONTROLLERBUTTONS_T bitmask, std::string id);
void DrawButtonLineAddMappingButton(uint8_t port, CONTROLLERBUTTONS_T bitmask);

void DrawStickDirectionLineEditMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction, std::string id);
void DrawStickDirectionLineEditMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction,
std::string id);
void DrawStickDirectionLineAddMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction);
void DrawStickSection(uint8_t port, uint8_t stick, int32_t id, ImVec4 color);

Expand All @@ -64,13 +65,15 @@ class BenInputEditorWindow : public Ship::GuiWindow {
std::unordered_map<uint8_t, std::unordered_map<CONTROLLERBUTTONS_T, std::vector<std::string>>> mBitmaskToMappingIds;

// mStickDirectionToMappingIds[port][stick][direction] = { id0, id1, ... }
std::unordered_map<uint8_t, std::unordered_map<uint8_t, std::unordered_map<Ship::Direction, std::vector<std::string>>>>
std::unordered_map<uint8_t,
std::unordered_map<uint8_t, std::unordered_map<Ship::Direction, std::vector<std::string>>>>
mStickDirectionToMappingIds;

void UpdateBitmaskToMappingIds(uint8_t port);
void UpdateStickDirectionToMappingIds(uint8_t port);

void GetButtonColorsForShipDeviceIndex(Ship::ShipDeviceIndex lusIndex, ImVec4& buttonColor, ImVec4& buttonHoveredColor);
void GetButtonColorsForShipDeviceIndex(Ship::ShipDeviceIndex lusIndex, ImVec4& buttonColor,
ImVec4& buttonHoveredColor);
void DrawPortTab(uint8_t portIndex);
std::set<CONTROLLERBUTTONS_T> mButtonsBitmasks;
std::set<CONTROLLERBUTTONS_T> mDpadBitmasks;
Expand Down
2 changes: 1 addition & 1 deletion mm/2s2h/BenGui/BenMenuBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace BenGui {
class BenMenuBar : public Ship::GuiMenuBar {
public:
using Ship::GuiMenuBar::GuiMenuBar;
void DrawContents() override {};
void DrawContents() override{};

protected:
void DrawElement() override;
Expand Down
Loading

0 comments on commit 86a1a03

Please sign in to comment.