diff options
| author | 2022-02-03 12:21:11 -0700 | |
|---|---|---|
| committer | 2022-02-03 12:21:11 -0700 | |
| commit | fc8aef7323cf15997e960d977a47dc06865635da (patch) | |
| tree | 46585847a2c5902d1e687c01d0249489f2df197b /src | |
| parent | Merge pull request #7814 from FernandoS27/another-bug-in-my-schedule (diff) | |
| parent | input_common: Use attributes for analog range modifiers (diff) | |
| download | yuzu-fc8aef7323cf15997e960d977a47dc06865635da.tar.gz yuzu-fc8aef7323cf15997e960d977a47dc06865635da.tar.xz yuzu-fc8aef7323cf15997e960d977a47dc06865635da.zip | |
Merge pull request #7811 from german77/analog-mod
input_common: Use attributes for analog range modifiers
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/helpers/stick_from_buttons.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp index e23394f5f..31e6f62ab 100644 --- a/src/input_common/helpers/stick_from_buttons.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp | |||
| @@ -167,12 +167,34 @@ public: | |||
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) { | 169 | void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) { |
| 170 | modifier_status = button_callback.button_status.value; | 170 | const auto& new_status = button_callback.button_status; |
| 171 | const bool new_button_value = new_status.inverted ? !new_status.value : new_status.value; | ||
| 172 | modifier_status.toggle = new_status.toggle; | ||
| 173 | |||
| 174 | // Update button status with current | ||
| 175 | if (!modifier_status.toggle) { | ||
| 176 | modifier_status.locked = false; | ||
| 177 | if (modifier_status.value != new_button_value) { | ||
| 178 | modifier_status.value = new_button_value; | ||
| 179 | } | ||
| 180 | } else { | ||
| 181 | // Toggle button and lock status | ||
| 182 | if (new_button_value && !modifier_status.locked) { | ||
| 183 | modifier_status.locked = true; | ||
| 184 | modifier_status.value = !modifier_status.value; | ||
| 185 | } | ||
| 186 | |||
| 187 | // Unlock button ready for next press | ||
| 188 | if (!new_button_value && modifier_status.locked) { | ||
| 189 | modifier_status.locked = false; | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 171 | UpdateStatus(); | 193 | UpdateStatus(); |
| 172 | } | 194 | } |
| 173 | 195 | ||
| 174 | void UpdateStatus() { | 196 | void UpdateStatus() { |
| 175 | const float coef = modifier_status ? modifier_scale : 1.0f; | 197 | const float coef = modifier_status.value ? modifier_scale : 1.0f; |
| 176 | 198 | ||
| 177 | bool r = right_status; | 199 | bool r = right_status; |
| 178 | bool l = left_status; | 200 | bool l = left_status; |
| @@ -266,7 +288,7 @@ public: | |||
| 266 | if (down_status) { | 288 | if (down_status) { |
| 267 | --y; | 289 | --y; |
| 268 | } | 290 | } |
| 269 | const float coef = modifier_status ? modifier_scale : 1.0f; | 291 | const float coef = modifier_status.value ? modifier_scale : 1.0f; |
| 270 | status.x.raw_value = static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF); | 292 | status.x.raw_value = static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF); |
| 271 | status.y.raw_value = static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF); | 293 | status.y.raw_value = static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF); |
| 272 | return status; | 294 | return status; |
| @@ -287,9 +309,9 @@ private: | |||
| 287 | bool down_status{}; | 309 | bool down_status{}; |
| 288 | bool left_status{}; | 310 | bool left_status{}; |
| 289 | bool right_status{}; | 311 | bool right_status{}; |
| 290 | bool modifier_status{}; | ||
| 291 | float last_x_axis_value{}; | 312 | float last_x_axis_value{}; |
| 292 | float last_y_axis_value{}; | 313 | float last_y_axis_value{}; |
| 314 | Common::Input::ButtonStatus modifier_status{}; | ||
| 293 | const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; | 315 | const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; |
| 294 | std::chrono::time_point<std::chrono::steady_clock> last_update; | 316 | std::chrono::time_point<std::chrono::steady_clock> last_update; |
| 295 | }; | 317 | }; |