libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
InputEditorWindow.h
Go to the documentation of this file.
1#pragma once
2
3#include "stdint.h"
5#include <imgui.h>
6#include <unordered_map>
7#include <string>
8#include <vector>
9#include <set>
10#include "ship/controller/controldevice/controller/Controller.h"
11
12namespace Ship {
13class ControlDeck;
14class Window;
15} // namespace Ship
16
17namespace LUS {
18
33 public:
41 InputEditorWindow(const std::string& consoleVariable, const std::string& name,
42 std::shared_ptr<Ship::ControlDeck> controlDeck, std::shared_ptr<Ship::Window> window);
43
46
55 void DrawInputChip(const char* buttonName, ImVec4 color);
56
64 void DrawAnalogPreview(const char* label, ImVec2 stick, float deadzone = 0, bool gyro = false);
65
70
71 protected:
73 void OnInit(const nlohmann::json& initArgs = nlohmann::json::object()) override;
74
76 void DrawElement() override;
77
79 void UpdateElement() override;
80
81 private:
90 void DrawStickDirectionLine(const char* axisDirectionName, uint8_t port, uint8_t stick, Ship::Direction direction,
91 ImVec4 color);
92
100 void DrawButtonLine(const char* buttonName, uint8_t port, CONTROLLERBUTTONS_T bitmask, ImVec4 color);
101
108 void DrawButtonLineEditMappingButton(uint8_t port, CONTROLLERBUTTONS_T bitmask, std::string id);
109
115 void DrawButtonLineAddMappingButton(uint8_t port, CONTROLLERBUTTONS_T bitmask);
116
124 void DrawStickDirectionLineEditMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction,
125 std::string id);
126
133 void DrawStickDirectionLineAddMappingButton(uint8_t port, uint8_t stick, Ship::Direction direction);
134
142 void DrawStickSection(uint8_t port, uint8_t stick, int32_t id, ImVec4 color);
143
148 void DrawRumbleSection(uint8_t port);
149
155 void DrawRemoveRumbleMappingButton(uint8_t port, std::string id);
156
161 void DrawAddRumbleMappingButton(uint8_t port);
162
167 void DrawLEDSection(uint8_t port);
168
174 void DrawRemoveLEDMappingButton(uint8_t port, std::string id);
175
180 void DrawAddLEDMappingButton(uint8_t port);
181
186 void DrawGyroSection(uint8_t port);
187
193 void DrawRemoveGyroMappingButton(uint8_t port, std::string id);
194
199 void DrawAddGyroMappingButton(uint8_t port);
200
201 int32_t mGameInputBlockTimer;
202 int32_t mMappingInputBlockTimer;
203 int32_t mRumbleTimer;
204 std::shared_ptr<Ship::ControllerRumbleMapping> mRumbleMappingToTest;
205
206 // mBitmaskToMappingIds[port][bitmask] = { id0, id1, ... }
207 std::unordered_map<uint8_t, std::unordered_map<CONTROLLERBUTTONS_T, std::vector<std::string>>> mBitmaskToMappingIds;
208
209 // mStickDirectionToMappingIds[port][stick][direction] = { id0, id1, ... }
210 std::unordered_map<uint8_t,
211 std::unordered_map<uint8_t, std::unordered_map<Ship::Direction, std::vector<std::string>>>>
212 mStickDirectionToMappingIds;
213
218 void UpdateBitmaskToMappingIds(uint8_t port);
219
224 void UpdateStickDirectionToMappingIds(uint8_t port);
225
232 void GetButtonColorsForPhysicalDeviceType(Ship::PhysicalDeviceType physicalDeviceType, ImVec4& buttonColor,
233 ImVec4& buttonHoveredColor);
234
239 void DrawPortTab(uint8_t portIndex);
240
241 std::set<CONTROLLERBUTTONS_T> mButtonsBitmasks;
242 std::set<CONTROLLERBUTTONS_T> mDpadBitmasks;
243 bool mInputEditorPopupOpen;
244
249 void DrawSetDefaultsButton(uint8_t portIndex);
250
255 void DrawClearAllButton(uint8_t portIndex);
256
261 void DrawDeviceToggles(uint8_t portIndex);
262
264 void OffsetMappingPopup();
265
266 std::shared_ptr<Ship::ControlDeck> mControlDeck;
267 std::shared_ptr<Ship::Window> mWindow;
268};
269} // namespace LUS
#define CONTROLLERBUTTONS_T
Definition ControllerButtonMapping.h:13
An ImGui window for editing, binding, and testing controller mappings.
Definition InputEditorWindow.h:32
InputEditorWindow(const std::string &consoleVariable, const std::string &name, std::shared_ptr< Ship::ControlDeck > controlDeck, std::shared_ptr< Ship::Window > window)
Constructs an InputEditorWindow with constructor-injected dependencies.
virtual ~InputEditorWindow()
Destroys the InputEditorWindow and releases any active rumble test state.
void DrawAnalogPreview(const char *label, ImVec2 stick, float deadzone=0, bool gyro=false)
Renders a circular analog-stick preview widget.
bool TestingRumble()
Returns true while the rumble test is actively playing.
void UpdateElement() override
Refreshes cached mapping-ID tables and manages the rumble test timer.
void DrawInputChip(const char *buttonName, ImVec4 color)
Renders a small coloured chip labelled with buttonName.
void DrawElement() override
Renders the full port-tabbed input editor UI.
void OnInit(const nlohmann::json &initArgs=nlohmann::json::object()) override
Registers button bitmasks and performs initial population of mapping tables.
A floating ImGui window managed by the Ship Gui layer.
Definition GuiWindow.h:39
Definition ControlDeck.h:13
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
PhysicalDeviceType
Identifies the category of a physical input device.
Definition PhysicalDeviceType.h:11
Direction
Identifies the direction component of an axis mapping.
Definition ControllerAxisDirectionMapping.h:18