Skip to content

Commit 308fe81

Browse files
committed
start moving towards just using ShipDeviceIndex::SDLGamepad
1 parent 9a974e0 commit 308fe81

File tree

4 files changed

+20
-88
lines changed

4 files changed

+20
-88
lines changed

src/controller/deviceindex/ShipDeviceIndex.h

+4-43
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,10 @@
33
namespace Ship {
44

55
#define SHIPDK_DEVICE_INDEX_VALUES \
6-
X(Mouse, -2) \
7-
X(Keyboard, -1) \
8-
X(Blue, 0) \
9-
X(Red, 1) \
10-
X(Orange, 2) \
11-
X(Green, 3) \
12-
X(Purple0, 4) \
13-
X(Purple1, 5) \
14-
X(Purple2, 6) \
15-
X(Purple3, 7) \
16-
X(Purple4, 8) \
17-
X(Purple5, 9) \
18-
X(Purple6, 10) \
19-
X(Purple7, 11) \
20-
X(Purple8, 12) \
21-
X(Purple9, 13) \
22-
X(Purple10, 14) \
23-
X(Purple11, 15) \
24-
X(Purple12, 16) \
25-
X(Purple13, 17) \
26-
X(Purple14, 18) \
27-
X(Purple15, 19) \
28-
X(Purple16, 20) \
29-
X(Purple17, 21) \
30-
X(Purple18, 22) \
31-
X(Purple19, 23) \
32-
X(Purple20, 24) \
33-
X(Purple21, 25) \
34-
X(Purple22, 26) \
35-
X(Purple23, 27) \
36-
X(Purple24, 28) \
37-
X(Purple25, 29) \
38-
X(Purple26, 30) \
39-
X(Purple27, 31) \
40-
X(Purple28, 32) \
41-
X(Purple29, 33) \
42-
X(Purple30, 34) \
43-
X(Purple31, 35) \
44-
X(Purple32, 36) \
45-
X(Purple33, 37) \
46-
X(Purple34, 38) \
47-
X(Purple35, 39) \
48-
X(Max, 40)
6+
X(Keyboard, 0) \
7+
X(Mouse, 1) \
8+
X(SDLGamepad, 2) \
9+
X(Max, 3)
4910

5011
#define X(name, value) name = value,
5112
enum ShipDeviceIndex { SHIPDK_DEVICE_INDEX_VALUES };

src/controller/deviceindex/ShipDeviceIndexMappingManager.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -601,22 +601,7 @@ ShipDeviceIndexMappingManager::GetShipDeviceIndexOfDisconnectedPhysicalDevice(in
601601
}
602602

603603
ShipDeviceIndex ShipDeviceIndexMappingManager::GetLowestShipDeviceIndexWithNoAssociatedButtonOrAxisDirectionMappings() {
604-
for (uint8_t lusIndex = ShipDeviceIndex::Blue; lusIndex < ShipDeviceIndex::Max; lusIndex++) {
605-
if (Context::GetInstance()->GetControlDeck()->GetControllerByPort(0)->HasMappingsForShipDeviceIndex(
606-
static_cast<ShipDeviceIndex>(lusIndex)) ||
607-
Context::GetInstance()->GetControlDeck()->GetControllerByPort(1)->HasMappingsForShipDeviceIndex(
608-
static_cast<ShipDeviceIndex>(lusIndex)) ||
609-
Context::GetInstance()->GetControlDeck()->GetControllerByPort(2)->HasMappingsForShipDeviceIndex(
610-
static_cast<ShipDeviceIndex>(lusIndex)) ||
611-
Context::GetInstance()->GetControlDeck()->GetControllerByPort(3)->HasMappingsForShipDeviceIndex(
612-
static_cast<ShipDeviceIndex>(lusIndex))) {
613-
continue;
614-
}
615-
return static_cast<ShipDeviceIndex>(lusIndex);
616-
}
617-
618-
// todo: invalid?
619-
return ShipDeviceIndex::Max;
604+
return ShipDeviceIndex::SDLGamepad;
620605
}
621606

622607
void ShipDeviceIndexMappingManager::SaveMappingIdsToConfig() {

src/window/gui/InputEditorWindow.cpp

+14-28
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ void InputEditorWindow::InitElement() {
2323
mButtonsBitmasks = { BTN_A, BTN_B, BTN_START, BTN_L, BTN_R, BTN_Z, BTN_CUP, BTN_CDOWN, BTN_CLEFT, BTN_CRIGHT };
2424
mDpadBitmasks = { BTN_DUP, BTN_DDOWN, BTN_DLEFT, BTN_DRIGHT };
2525

26-
mDeviceIndexVisiblity.clear();
27-
mDeviceIndexVisiblity[ShipDeviceIndex::Keyboard] = true;
28-
mDeviceIndexVisiblity[ShipDeviceIndex::Mouse] = true;
29-
mDeviceIndexVisiblity[ShipDeviceIndex::Blue] = true;
30-
for (auto index = 1; index < ShipDeviceIndex::Max; index++) {
31-
mDeviceIndexVisiblity[static_cast<ShipDeviceIndex>(index)] = false;
32-
}
26+
mDeviceIndexVisibility.clear();
27+
mDeviceIndexVisibility[ShipDeviceIndex::Keyboard] = true;
28+
mDeviceIndexVisibility[ShipDeviceIndex::Mouse] = true;
29+
mDeviceIndexVisibility[ShipDeviceIndex::SDLGamepad] = true;
30+
mDeviceIndexVisibility[ShipDeviceIndex::Max] = false;
3331
}
3432

3533
#define INPUT_EDITOR_WINDOW_GAME_INPUT_BLOCK_ID 95237929
@@ -181,22 +179,10 @@ void InputEditorWindow::GetButtonColorsForShipDeviceIndex(ShipDeviceIndex lusInd
181179
buttonColor = BUTTON_COLOR_MOUSE_BEIGE;
182180
buttonHoveredColor = BUTTON_COLOR_MOUSE_BEIGE_HOVERED;
183181
break;
184-
case ShipDeviceIndex::Blue:
182+
case ShipDeviceIndex::SDLGamepad:
185183
buttonColor = BUTTON_COLOR_GAMEPAD_BLUE;
186184
buttonHoveredColor = BUTTON_COLOR_GAMEPAD_BLUE_HOVERED;
187185
break;
188-
case ShipDeviceIndex::Red:
189-
buttonColor = BUTTON_COLOR_GAMEPAD_RED;
190-
buttonHoveredColor = BUTTON_COLOR_GAMEPAD_RED_HOVERED;
191-
break;
192-
case ShipDeviceIndex::Orange:
193-
buttonColor = BUTTON_COLOR_GAMEPAD_ORANGE;
194-
buttonHoveredColor = BUTTON_COLOR_GAMEPAD_ORANGE_HOVERED;
195-
break;
196-
case ShipDeviceIndex::Green:
197-
buttonColor = BUTTON_COLOR_GAMEPAD_GREEN;
198-
buttonHoveredColor = BUTTON_COLOR_GAMEPAD_GREEN_HOVERED;
199-
break;
200186
default:
201187
buttonColor = BUTTON_COLOR_GAMEPAD_PURPLE;
202188
buttonHoveredColor = BUTTON_COLOR_GAMEPAD_PURPLE_HOVERED;
@@ -248,7 +234,7 @@ void InputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROLLER
248234
if (mapping == nullptr) {
249235
return;
250236
}
251-
if (!mDeviceIndexVisiblity[mapping->GetShipDeviceIndex()]) {
237+
if (!mDeviceIndexVisibility[mapping->GetShipDeviceIndex()]) {
252238
return;
253239
}
254240

@@ -518,7 +504,7 @@ void InputEditorWindow::DrawStickDirectionLineEditMappingButton(uint8_t port, ui
518504
if (mapping == nullptr) {
519505
return;
520506
}
521-
if (!mDeviceIndexVisiblity[mapping->GetShipDeviceIndex()]) {
507+
if (!mDeviceIndexVisibility[mapping->GetShipDeviceIndex()]) {
522508
return;
523509
}
524510

@@ -1429,11 +1415,11 @@ void InputEditorWindow::DrawDeviceVisibilityButtons() {
14291415
GetButtonColorsForShipDeviceIndex(ShipDeviceIndex::Keyboard, keyboardButtonColor, keyboardButtonHoveredColor);
14301416
ImGui::PushStyleColor(ImGuiCol_Button, keyboardButtonColor);
14311417
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, keyboardButtonHoveredColor);
1432-
bool keyboardVisible = mDeviceIndexVisiblity[ShipDeviceIndex::Keyboard];
1418+
bool keyboardVisible = mDeviceIndexVisibility[ShipDeviceIndex::Keyboard];
14331419
if (ImGui::Button(StringHelper::Sprintf("%s %s Keyboard", keyboardVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH,
14341420
ICON_FA_KEYBOARD_O)
14351421
.c_str())) {
1436-
mDeviceIndexVisiblity[ShipDeviceIndex::Keyboard] = !keyboardVisible;
1422+
mDeviceIndexVisibility[ShipDeviceIndex::Keyboard] = !keyboardVisible;
14371423
}
14381424
ImGui::PopStyleColor();
14391425
ImGui::PopStyleColor();
@@ -1443,11 +1429,11 @@ void InputEditorWindow::DrawDeviceVisibilityButtons() {
14431429
GetButtonColorsForShipDeviceIndex(ShipDeviceIndex::Mouse, mouseButtonColor, mouseButtonHoveredColor);
14441430
ImGui::PushStyleColor(ImGuiCol_Button, mouseButtonColor);
14451431
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, mouseButtonHoveredColor);
1446-
bool mouseVisible = mDeviceIndexVisiblity[ShipDeviceIndex::Mouse];
1432+
bool mouseVisible = mDeviceIndexVisibility[ShipDeviceIndex::Mouse];
14471433
if (ImGui::Button(
14481434
StringHelper::Sprintf("%s %s mouse", mouseVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH, ICON_FA_KEYBOARD_O)
14491435
.c_str())) {
1450-
mDeviceIndexVisiblity[ShipDeviceIndex::Mouse] = !mouseVisible;
1436+
mDeviceIndexVisibility[ShipDeviceIndex::Mouse] = !mouseVisible;
14511437
}
14521438
ImGui::PopStyleColor();
14531439
ImGui::PopStyleColor();
@@ -1462,13 +1448,13 @@ void InputEditorWindow::DrawDeviceVisibilityButtons() {
14621448

14631449
ImGui::PushStyleColor(ImGuiCol_Button, buttonColor);
14641450
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, buttonHoveredColor);
1465-
bool visible = mDeviceIndexVisiblity[lusIndex];
1451+
bool visible = mDeviceIndexVisibility[lusIndex];
14661452
if (ImGui::Button(
14671453
StringHelper::Sprintf("%s %s %s (%s)", visible ? ICON_FA_EYE : ICON_FA_EYE_SLASH,
14681454
connected ? ICON_FA_GAMEPAD : ICON_FA_CHAIN_BROKEN, name.c_str(),
14691455
connected ? StringHelper::Sprintf("SDL %d", sdlIndex).c_str() : "Disconnected")
14701456
.c_str())) {
1471-
mDeviceIndexVisiblity[lusIndex] = !visible;
1457+
mDeviceIndexVisibility[lusIndex] = !visible;
14721458
}
14731459
ImGui::PopStyleColor();
14741460
ImGui::PopStyleColor();

src/window/gui/InputEditorWindow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class InputEditorWindow : public GuiWindow {
7676
void DrawSetDefaultsButton(uint8_t portIndex);
7777
void DrawClearAllButton(uint8_t portIndex);
7878

79-
std::map<ShipDeviceIndex, bool> mDeviceIndexVisiblity;
79+
std::map<ShipDeviceIndex, bool> mDeviceIndexVisibility;
8080
void DrawDeviceVisibilityButtons();
8181
void OffsetMappingPopup();
8282
};

0 commit comments

Comments
 (0)