EvilTurtleProductions Posted June 8, 2022 Share Posted June 8, 2022 So I want the players to be able to change the controls in the options menu, but I've encountered an interesting roadblock of which I'm not sure how to handle it. Since the mouse is handled in separate methods in Window I can't simply pass the Key::whatever value, I also need to switch between the MouseDown or KeyDown function depending on what the setting chosen is. Is there some clever way this can be done neatly? Quote Link to comment Share on other sites More sharing options...
IceBurger Posted June 8, 2022 Share Posted June 8, 2022 Can't you just do "KeyDown(x) or MouseDown(x)"? I don't know much about Lua. You could store the button or key as "M0" or "K62," respectively, and check for an "M" or "K" (that's one way I have done it in other applications) Quote i now hate love C++ Beeeeeeeeeeeeeep~~This is a test of the emergency signature system~~Beeeeeeeeeeeeeep RX 6800XT | i5-13600KF | 32GB DDR5 | 1440p is perfect Link to comment Share on other sites More sharing options...
EvilTurtleProductions Posted June 9, 2022 Author Share Posted June 9, 2022 I've solved it now by using a bool for every control which sets if the control is a mouse or keyboard control (i.e. 'mouse_throw' for 'key_throw' etc). After that it's just checking like this: (window->KeyHit(key_throw) && !mouse_throw) || (window->MouseHit(key_throw) && mouse_throw) And this works fine. Just wondering if there's other ways of doing it Quote Link to comment Share on other sites More sharing options...
klepto2 Posted June 10, 2022 Share Posted June 10, 2022 You could also try another approach: Pseudocode: class GameAction { public: virtual bool IsCalled() = 0; } class KeyHitAction : GameAction { private int key; private Window* window; public: KeyAction(Window* window, int key); virtual bool IsCalled() { return window->KeyHit(key);} } class MouseHitAction : GameAction { private int button; private Window* window; public: KeyAction(Window* window, int button); virtual bool IsCalled() { return window->MouseHit(button);} } std:map<string,GameAction*> actions; actions["THROW"] = KeyHitAction(window,KEY_T); actions["SELECT"] = MouseHitAction(window,MouseButton::Left); //in Loop if(actions["THROW"]->IsCalled()) { } This could easily to be extended to Gamepads and other input devices. Also you could add MouseDownActions or other types of Actions. 1 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted June 10, 2022 Share Posted June 10, 2022 You could store the mouse button value as a negative number in the settings, and then use MouseDown(-key) if the key value is negative, or KeyDown(key) if it is positive. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.