diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-31 00:19:18 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-31 00:19:18 +0300 |
commit | 694e07d193e7c5758a7d672b45668651b034003d (patch) | |
tree | 20a4aec8dee2b3b5475db9f3667e797fb43c603b /src/gui | |
parent | c9a84749b3b71d4df6cc3b9b488d60dc4a013a20 (diff) | |
download | manaplus-694e07d193e7c5758a7d672b45668651b034003d.tar.gz manaplus-694e07d193e7c5758a7d672b45668651b034003d.tar.bz2 manaplus-694e07d193e7c5758a7d672b45668651b034003d.tar.xz manaplus-694e07d193e7c5758a7d672b45668651b034003d.zip |
Convert InputAction enum into strong typed enum.
Diffstat (limited to 'src/gui')
41 files changed, 152 insertions, 137 deletions
diff --git a/src/gui/buttoninfo.h b/src/gui/buttoninfo.h index a6c7eb9e0..15f0c3052 100644 --- a/src/gui/buttoninfo.h +++ b/src/gui/buttoninfo.h @@ -21,6 +21,8 @@ #ifndef GUI_BUTTONINFO_H #define GUI_BUTTONINFO_H +#include "enums/input/inputaction.h" + #include "enums/simpletypes/visible.h" #include "localconsts.h" @@ -29,7 +31,9 @@ class Button; struct ButtonInfo final { - ButtonInfo(Button *const button0, const int key0, const Visible visible0) : + ButtonInfo(Button *const button0, + const InputActionT key0, + const Visible visible0) : button(button0), key(key0), visible(visible0) @@ -39,7 +43,7 @@ struct ButtonInfo final A_DELETE_COPY(ButtonInfo) Button *button; - int key; + InputActionT key; Visible visible; }; #endif // GUI_BUTTONINFO_H diff --git a/src/gui/buttontext.h b/src/gui/buttontext.h index d2c5a2d39..50df128dd 100644 --- a/src/gui/buttontext.h +++ b/src/gui/buttontext.h @@ -21,13 +21,16 @@ #ifndef GUI_BUTTONTEXT_H #define GUI_BUTTONTEXT_H +#include "enums/input/inputaction.h" + #include "localconsts.h" #include <string> struct ButtonText final { - ButtonText(const std::string &text0, const int key0) : + ButtonText(const std::string &text0, + const InputActionT key0) : text(text0), key(key0) { @@ -36,7 +39,7 @@ struct ButtonText final A_DELETE_COPY(ButtonText) std::string text; - int key; + InputActionT key; }; #endif // GUI_BUTTONTEXT_H diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index f978fc091..ac61261d3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -437,8 +437,8 @@ bool Gui::handleKeyInput() // tabbing is enable check for tab press and // change focus. if (!eventConsumed && keyInput.getActionId() - == static_cast<int>(InputAction::GUI_TAB) - && keyInput.getType() == KeyEventType::PRESSED) + == InputAction::GUI_TAB && + keyInput.getType() == KeyEventType::PRESSED) { if (inputManager.isActionActive(InputAction::GUI_MOD)) mFocusHandler->tabPrevious(); diff --git a/src/gui/models/touchactionmodel.cpp b/src/gui/models/touchactionmodel.cpp index d9cced32a..7daff84ca 100644 --- a/src/gui/models/touchactionmodel.cpp +++ b/src/gui/models/touchactionmodel.cpp @@ -68,16 +68,16 @@ TouchActionsModel::TouchActionsModel() : } } -int TouchActionsModel::getActionFromSelection(const int sel) const +InputActionT TouchActionsModel::getActionFromSelection(const int sel) const { if (sel < 0 || sel > static_cast<signed int>(mActionId.size())) - return -1; + return InputAction::NO_VALUE; return mActionId[sel]; } -int TouchActionsModel::getSelectionFromAction(const int action) const +int TouchActionsModel::getSelectionFromAction(const InputActionT action) const { - const std::map<int, int>::const_iterator it + const std::map<InputActionT, int>::const_iterator it = mActionToSelection.find(action); if (it == mActionToSelection.end()) return 0; diff --git a/src/gui/models/touchactionmodel.h b/src/gui/models/touchactionmodel.h index 287232aae..05234907c 100644 --- a/src/gui/models/touchactionmodel.h +++ b/src/gui/models/touchactionmodel.h @@ -21,6 +21,8 @@ #ifndef GUI_MODELS_TOUCHACTIONMODEL_H #define GUI_MODELS_TOUCHACTIONMODEL_H +#include "enums/input/inputaction.h" + #include "gui/models/namesmodel.h" #include "gui/widgets/setupitem.h" @@ -35,13 +37,13 @@ class TouchActionsModel final : public NamesModel ~TouchActionsModel() { } - int getActionFromSelection(const int sel) const; + InputActionT getActionFromSelection(const int sel) const; - int getSelectionFromAction(const int action) const; + int getSelectionFromAction(const InputActionT action) const; private: - std::vector<int> mActionId; - std::map<int, int> mActionToSelection; + std::vector<InputActionT> mActionId; + std::map<InputActionT, int> mActionToSelection; }; #endif // GUI_MODELS_TOUCHACTIONMODEL_H diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index 37c8e0d78..0e0e93e3f 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -1526,7 +1526,7 @@ void PopupMenu::handleLink(const std::string &link, { const int id = atoi(link.substr(12).c_str()); if (id >= 0) - inputManager.executeAction(id); + inputManager.executeAction(static_cast<InputActionT>(id)); } else if (!link.compare(0, 6, "mute_+")) { @@ -2179,7 +2179,8 @@ void PopupMenu::showWindowsPopup() if (!btn) continue; - mBrowserBox->addRow(strprintf("show window_%d", btn->key), + mBrowserBox->addRow(strprintf("show window_%d", + static_cast<int>(btn->key)), btn->text.c_str()); } mBrowserBox->addRow("##3---"); diff --git a/src/gui/popups/statuspopup.cpp b/src/gui/popups/statuspopup.cpp index 2bc4a9170..c54a57874 100644 --- a/src/gui/popups/statuspopup.cpp +++ b/src/gui/popups/statuspopup.cpp @@ -124,11 +124,11 @@ void StatusPopup::view(const int x, const int y) void StatusPopup::setLabelText(const int num, const std::string &text, - const InputAction::Type key) const + const InputActionT key) const { Label *const label = mLabels[num]; label->setCaption(strprintf("%s %s", text.c_str(), - inputManager.getKeyValueString(static_cast<int>(key)).c_str())); + inputManager.getKeyValueString(key).c_str())); label->adjustSize(); } diff --git a/src/gui/popups/statuspopup.h b/src/gui/popups/statuspopup.h index cdfbde656..43b793821 100644 --- a/src/gui/popups/statuspopup.h +++ b/src/gui/popups/statuspopup.h @@ -62,8 +62,9 @@ class StatusPopup final : public Popup private: void updateLabels() const; - void setLabelText(const int num, const std::string &text, - const InputAction::Type key) const; + void setLabelText(const int num, + const std::string &text, + const InputActionT key) const; Label *mLabels[STATUSPOPUP_NUM_LABELS]; }; diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 16204e5e1..8405dda90 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -292,8 +292,8 @@ void SDLInput::pushInput(const SDL_Event &event) void SDLInput::convertKeyEventToKey(const SDL_Event &event, KeyInput &keyInput) { keyInput.setKey(Key(convertKeyCharacter(event))); - const int actionId = inputManager.getActionByKey(event); - if (actionId >= 0) + const InputActionT actionId = inputManager.getActionByKey(event); + if (actionId > InputActionT::NO_VALUE) keyInput.setActionId(actionId); } diff --git a/src/gui/setupactiondata.h b/src/gui/setupactiondata.h index f72614c11..03915d37a 100644 --- a/src/gui/setupactiondata.h +++ b/src/gui/setupactiondata.h @@ -24,6 +24,8 @@ #ifndef GUI_SETUPACTIONDATA_H #define GUI_SETUPACTIONDATA_H +#include "enums/input/inputaction.h" + #include <string> #include "localconsts.h" @@ -32,7 +34,7 @@ struct SetupActionData final { #ifdef ADVGCC SetupActionData(const std::string &name0, - const int actionId0, + const InputActionT actionId0, const std::string &text0) : name(name0), actionId(actionId0), @@ -43,7 +45,7 @@ struct SetupActionData final #endif std::string name; - const int actionId; + const InputActionT actionId; std::string text; }; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 78b66b930..5c0c7328c 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -455,20 +455,18 @@ bool Viewport::leftMouseAction() type == ActorType::Npc)) { if ((localPlayer->withinAttackRange(mHoverBeing) || - inputManager.isActionActive(static_cast<int>( - InputAction::ATTACK)))) + inputManager.isActionActive(InputAction::ATTACK))) { validateSpeed(); if (!mStatsReUpdated && localPlayer != mHoverBeing) { localPlayer->attack(mHoverBeing, !inputManager.isActionActive( - static_cast<int>(InputAction::STOP_ATTACK))); + InputAction::STOP_ATTACK)); return true; } } - else if (!inputManager.isActionActive(static_cast<int>( - InputAction::ATTACK))) + else if (!inputManager.isActionActive(InputAction::ATTACK)) { validateSpeed(); if (!mStatsReUpdated && localPlayer != mHoverBeing) @@ -498,8 +496,7 @@ bool Viewport::leftMouseAction() return true; } // Just walk around - else if (!inputManager.isActionActive(static_cast<int>( - InputAction::ATTACK))) + else if (!inputManager.isActionActive(InputAction::ATTACK)) { validateSpeed(); localPlayer->stopAttack(); @@ -964,9 +961,8 @@ void Viewport::returnCamera() void Viewport::validateSpeed() { - if (!inputManager.isActionActive(static_cast<int>( - InputAction::TARGET_ATTACK)) && !inputManager.isActionActive( - static_cast<int>(InputAction::ATTACK))) + if (!inputManager.isActionActive(InputAction::TARGET_ATTACK) && + !inputManager.isActionActive(InputAction::ATTACK)) { if (Game::instance()) Game::instance()->setValidSpeed(); diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 9a6d43518..73a289630 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -843,7 +843,7 @@ void Button::adjustSize() void Button::keyPressed(KeyEvent& event) { - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); if (action == InputAction::GUI_SELECT) { @@ -854,7 +854,7 @@ void Button::keyPressed(KeyEvent& event) void Button::keyReleased(KeyEvent& event) { - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); if (action == InputAction::GUI_SELECT && mKeyPressed) { diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 6459c5f1c..20a58bdf1 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -267,7 +267,7 @@ void CheckBox::mouseExited(MouseEvent& event) void CheckBox::keyPressed(KeyEvent& event) { - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); if (action == InputAction::GUI_SELECT) { diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 0d08dac60..890a2af1f 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -334,7 +334,7 @@ void DropDown::keyPressed(KeyEvent& event) if (event.isConsumed()) return; - const int actionId = event.getActionId(); + const InputActionT actionId = event.getActionId(); switch (actionId) { case InputAction::GUI_SELECT: diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index eb6efedb6..7cba5872e 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -33,6 +33,8 @@ #include "gui/popups/textpopup.h" +#include "input/inputactionoperators.h" + #include "resources/emotesprite.h" #include "resources/image.h" diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index ba29033a9..d5242520f 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -474,7 +474,7 @@ Rect GuiTable::getChildrenArea() // -- KeyListener notifications void GuiTable::keyPressed(KeyEvent& event) { - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); if (action == InputAction::GUI_SELECT) { diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp index 1ba53b1af..b0e902223 100644 --- a/src/gui/widgets/inttextfield.cpp +++ b/src/gui/widgets/inttextfield.cpp @@ -53,7 +53,7 @@ IntTextField::IntTextField(const Widget2 *const widget, void IntTextField::keyPressed(KeyEvent &event) { - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); if (action == InputAction::GUI_DELETE || action == InputAction::GUI_BACKSPACE) diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 15af7c286..eba9fd848 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -42,6 +42,8 @@ #include "gui/windows/inventorywindow.h" #include "gui/windows/skilldialog.h" +#include "input/inputactionoperators.h" + #include "resources/skillconsts.h" #include "utils/stringutils.h" diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 5ab8945a9..8e0bd2921 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -237,7 +237,7 @@ void ListBox::draw(Graphics *graphics) void ListBox::keyPressed(KeyEvent &event) { - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); if (action == InputAction::GUI_SELECT) { distributeActionEvent(); diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index 9fd9d81aa..a3c4d1797 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -266,7 +266,7 @@ void RadioButton::mouseExited(MouseEvent& event A_UNUSED) void RadioButton::keyPressed(KeyEvent& event) { - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); if (action == InputAction::GUI_SELECT) { setSelected(true); diff --git a/src/gui/widgets/setuptouchitem.cpp b/src/gui/widgets/setuptouchitem.cpp index 8d1b63dd7..eb8741abc 100644 --- a/src/gui/widgets/setuptouchitem.cpp +++ b/src/gui/widgets/setuptouchitem.cpp @@ -100,7 +100,7 @@ void SetupActionDropDown::createControls() mDropDown->addActionListener(mParent); mDropDown->setWidth(mWidth); mDropDown->setSelected(mModel->getSelectionFromAction( - atoi(mValue.c_str()))); + static_cast<InputActionT>(atoi(mValue.c_str())))); mWidget = mDropDown; fixFirstItemSize(mLabel); @@ -118,8 +118,8 @@ void SetupActionDropDown::fromWidget() if (!mDropDown || !mModel) return; - mValue = toString(mModel->getActionFromSelection( - mDropDown->getSelected())); + mValue = toString(static_cast<int>(mModel->getActionFromSelection( + mDropDown->getSelected()))); } void SetupActionDropDown::toWidget() @@ -128,5 +128,5 @@ void SetupActionDropDown::toWidget() return; mDropDown->setSelected(mModel->getSelectionFromAction( - atoi(mValue.c_str()))); + static_cast<InputActionT>(atoi(mValue.c_str())))); } diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index c11dc2627..4adc3003f 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -423,7 +423,7 @@ void Slider::mouseWheelMovedDown(MouseEvent &event) void Slider::keyPressed(KeyEvent& event) { - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); if (mOrientation == HORIZONTAL) { diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 79205617f..4acc9ffd2 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -738,7 +738,7 @@ void TabbedArea::keyPressed(KeyEvent& event) if (mBlockSwitching || event.isConsumed() || !isFocused()) return; - const int actionId = event.getActionId(); + const InputActionT actionId = event.getActionId(); if (actionId == InputAction::GUI_LEFT) { diff --git a/src/gui/widgets/tabs/setup_input.cpp b/src/gui/widgets/tabs/setup_input.cpp index f1752d781..24a385c0f 100644 --- a/src/gui/widgets/tabs/setup_input.cpp +++ b/src/gui/widgets/tabs/setup_input.cpp @@ -27,6 +27,7 @@ #include "enums/gui/dialogtype.h" +#include "input/inputactionoperators.h" #include "input/inputmanager.h" #include "input/keyboardconfig.h" @@ -147,7 +148,7 @@ Setup_Input::~Setup_Input() void Setup_Input::apply() { keyUnresolved(); - int key1, key2; + InputActionT key1, key2; if (inputManager.hasConflicts(key1, key2)) { @@ -193,7 +194,7 @@ void Setup_Input::action(const ActionEvent &event) if (i >= 0 && i < mActionDataSize[selectedData]) { if (setupActionData[selectedData][i].actionId - == static_cast<int>(InputAction::NO_VALUE)) + == InputAction::NO_VALUE) { mAssignKeyButton->setEnabled(false); mUnassignKeyButton->setEnabled(false); @@ -215,7 +216,7 @@ void Setup_Input::action(const ActionEvent &event) if (i >= 0 && i < mActionDataSize[selectedData]) { const SetupActionData &key = setupActionData[selectedData][i]; - const int ik = key.actionId; + const InputActionT ik = key.actionId; inputManager.setNewKeyIndex(ik); mKeyListModel->setElementAt(i, std::string( gettext(key.name.c_str())).append(": ?")); @@ -227,12 +228,11 @@ void Setup_Input::action(const ActionEvent &event) if (i >= 0 && i < mActionDataSize[selectedData]) { const SetupActionData &key = setupActionData[selectedData][i]; - const int ik = key.actionId; + const InputActionT ik = key.actionId; inputManager.setNewKeyIndex(ik); refreshAssignedKey(mKeyList->getSelected()); inputManager.unassignKey(); - inputManager.setNewKeyIndex(static_cast<int>( - InputAction::NO_VALUE)); + inputManager.setNewKeyIndex(InputAction::NO_VALUE); } mAssignKeyButton->setEnabled(true); } @@ -248,7 +248,7 @@ void Setup_Input::action(const ActionEvent &event) if (i >= 0 && i < mActionDataSize[selectedData]) { const SetupActionData &key = setupActionData[selectedData][i]; - const int ik = key.actionId; + const InputActionT ik = key.actionId; inputManager.makeDefault(ik); refreshKeys(); } @@ -277,7 +277,7 @@ void Setup_Input::refreshAssignedKey(const int index) { const int selectedData = mKeyListModel->getSelectedData(); const SetupActionData &key = setupActionData[selectedData][index]; - if (key.actionId == static_cast<int>(InputAction::NO_VALUE)) + if (key.actionId == InputAction::NO_VALUE) { const std::string str(" \342\200\225\342\200\225\342\200\225" "\342\200\225\342\200\225 "); @@ -297,7 +297,7 @@ void Setup_Input::refreshAssignedKey(const int index) } } -void Setup_Input::newKeyCallback(const int index) +void Setup_Input::newKeyCallback(const InputActionT index) { mKeySetting = false; const int i = keyToSetupData(index); @@ -306,7 +306,7 @@ void Setup_Input::newKeyCallback(const int index) mAssignKeyButton->setEnabled(true); } -int Setup_Input::keyToSetupData(const int index) const +int Setup_Input::keyToSetupData(const InputActionT index) const { const int selectedData = mKeyListModel->getSelectedData(); for (int i = 0; i < mActionDataSize[selectedData]; i++) @@ -318,7 +318,7 @@ int Setup_Input::keyToSetupData(const int index) const return -1; } -std::string Setup_Input::keyToString(const int index) const +std::string Setup_Input::keyToString(const InputActionT index) const { for (int f = 0; f < setupGroups; f ++) { @@ -345,13 +345,13 @@ void Setup_Input::keyUnresolved() if (mKeySetting) { newKeyCallback(inputManager.getNewKeyIndex()); - inputManager.setNewKeyIndex(static_cast<int>(InputAction::NO_VALUE)); + inputManager.setNewKeyIndex(InputAction::NO_VALUE); } } void Setup_Input::fixTranslation(SetupActionData *const actionDatas, - const int actionStart, - const int actionEnd, + const InputActionT actionStart, + const InputActionT actionEnd, const std::string &text) { int k = 0; @@ -360,7 +360,7 @@ void Setup_Input::fixTranslation(SetupActionData *const actionDatas, { SetupActionData &data = actionDatas[k]; - const int actionId = data.actionId; + const InputActionT actionId = data.actionId; if (actionId >= actionStart && actionId <= actionEnd) { data.name = strprintf(gettext(text.c_str()), @@ -373,22 +373,22 @@ void Setup_Input::fixTranslation(SetupActionData *const actionDatas, void Setup_Input::fixTranslations() { fixTranslation(setupActionDataShortcuts, - static_cast<int>(InputAction::SHORTCUT_1), - static_cast<int>(InputAction::SHORTCUT_20), + InputAction::SHORTCUT_1, + InputAction::SHORTCUT_20, "Item Shortcut %d"); fixTranslation(setupActionDataEmotes, - static_cast<int>(InputAction::EMOTE_1), - static_cast<int>(InputAction::EMOTE_48), + InputAction::EMOTE_1, + InputAction::EMOTE_48, "Emote Shortcut %d"); fixTranslation(setupActionDataOutfits, - static_cast<int>(InputAction::OUTFIT_1), - static_cast<int>(InputAction::OUTFIT_48), + InputAction::OUTFIT_1, + InputAction::OUTFIT_48, "Outfit Shortcut %d"); fixTranslation(setupActionDataMove, - static_cast<int>(InputAction::MOVE_TO_POINT_1), - static_cast<int>(InputAction::MOVE_TO_POINT_48), + InputAction::MOVE_TO_POINT_1, + InputAction::MOVE_TO_POINT_48, "Move to point Shortcut %d"); } diff --git a/src/gui/widgets/tabs/setup_input.h b/src/gui/widgets/tabs/setup_input.h index 569c21e2b..eb97dd644 100644 --- a/src/gui/widgets/tabs/setup_input.h +++ b/src/gui/widgets/tabs/setup_input.h @@ -24,6 +24,8 @@ #ifndef GUI_WIDGETS_TABS_SETUP_INPUT_H #define GUI_WIDGETS_TABS_SETUP_INPUT_H +#include "enums/input/inputaction.h" + #include "gui/widgets/tabs/setuptab.h" class Button; @@ -63,7 +65,7 @@ class Setup_Input final : public SetupTab /** * The callback function when a new key has been pressed. */ - void newKeyCallback(const int index); + void newKeyCallback(const InputActionT index); /** * Shorthand method to update all the keys. @@ -75,16 +77,16 @@ class Setup_Input final : public SetupTab */ void keyUnresolved(); - int keyToSetupData(const int index) const A_WARN_UNUSED; + int keyToSetupData(const InputActionT index) const A_WARN_UNUSED; - std::string keyToString(const int index) const A_WARN_UNUSED; + std::string keyToString(const InputActionT index) const A_WARN_UNUSED; private: static void fixTranslations(); static void fixTranslation(SetupActionData *const actionDatas, - const int actionStart, - const int actionEnd, + const InputActionT actionStart, + const InputActionT actionEnd, const std::string &text); KeyListModel *mKeyListModel; diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index 0919656ad..248fbcb9e 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -257,7 +257,7 @@ void TextBox::setText(const std::string& text) void TextBox::keyPressed(KeyEvent& event) { const Key &key = event.getKey(); - const int action = event.getActionId(); + const InputActionT action = event.getActionId(); switch (action) { diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 8639d8f80..0d7b3d883 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -365,9 +365,8 @@ void TextField::keyPressed(KeyEvent &event) bool consumed(false); #endif - const int action = event.getActionId(); - if (!inputManager.isActionActive(static_cast<int>( - InputAction::GUI_CTRL))) + const InputActionT action = event.getActionId(); + if (!inputManager.isActionActive(InputAction::GUI_CTRL)) { if (!handleNormalKeys(action, consumed)) { @@ -389,7 +388,7 @@ void TextField::keyPressed(KeyEvent &event) fixScroll(); } -bool TextField::handleNormalKeys(const int action, bool &consumed) +bool TextField::handleNormalKeys(const InputActionT action, bool &consumed) { switch (action) { @@ -473,7 +472,7 @@ bool TextField::handleNormalKeys(const int action, bool &consumed) return true; } -void TextField::handleCtrlKeys(const int action, bool &consumed) +void TextField::handleCtrlKeys(const InputActionT action, bool &consumed) { switch (action) { diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index ffd956ed2..79ad3f110 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -238,9 +238,9 @@ class TextField notfinal : public Widget, void fontChanged() override; - bool handleNormalKeys(const int action, bool &consumed); + bool handleNormalKeys(const InputActionT action, bool &consumed); - void handleCtrlKeys(const int action, bool &consumed); + void handleCtrlKeys(const InputActionT action, bool &consumed); static Skin *mSkin; diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 012fd5a49..b1d225bf2 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -238,13 +238,13 @@ void WindowMenu::addButton(const char *const text, const std::string &description, int &restrict x, int &restrict h, - const int key, + const InputActionT key, const Visible visible) { Button *const btn = new Button(this, gettext(text), text, this); btn->setPosition(x, mPadding); btn->setDescription(description); - btn->setTag(key); + btn->setTag(static_cast<int>(key)); add(btn); btn->setFocusable(false); x += btn->getWidth() + mSpacing; @@ -301,7 +301,7 @@ void WindowMenu::mouseMoved(MouseEvent &event) const int x = event.getX(); const int y = event.getY(); - const int key = btn->getTag(); + const InputActionT key = static_cast<InputActionT>(btn->getTag()); const Rect &rect = mDimension; if (key != InputAction::NO_VALUE) { diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h index 03bd86592..d91526750 100644 --- a/src/gui/windowmenu.h +++ b/src/gui/windowmenu.h @@ -23,6 +23,8 @@ #ifndef GUI_WINDOWMENU_H #define GUI_WINDOWMENU_H +#include "enums/input/inputaction.h" + #include "enums/simpletypes/visible.h" #include "gui/widgets/container.h" @@ -95,7 +97,7 @@ class WindowMenu final : public Container, inline void addButton(const char *const text, const std::string &description, int &restrict x, int &restrict h, - const int key, + const InputActionT key, const Visible visible = Visible_true); void updateButtons(); diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp index 87dc25115..436c4d841 100644 --- a/src/gui/windows/charcreatedialog.cpp +++ b/src/gui/windows/charcreatedialog.cpp @@ -685,7 +685,7 @@ void CharCreateDialog::updatePlayer() void CharCreateDialog::keyPressed(KeyEvent &event) { - const int actionId = event.getActionId(); + const InputActionT actionId = event.getActionId(); switch (actionId) { case InputAction::GUI_CANCEL: diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp index dd82091b0..0ffba7984 100644 --- a/src/gui/windows/charselectdialog.cpp +++ b/src/gui/windows/charselectdialog.cpp @@ -353,7 +353,7 @@ void CharSelectDialog::use(const int selected) void CharSelectDialog::keyPressed(KeyEvent &event) { - const int actionId = event.getActionId(); + const InputActionT actionId = event.getActionId(); switch (actionId) { case InputAction::GUI_CANCEL: diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index 747ba498e..7a62ad755 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -698,8 +698,7 @@ void ChatWindow::mousePressed(MouseEvent &event) { event.consume(); ChatTab *const cTab = dynamic_cast<ChatTab*>(tab); - if (inputManager.isActionActive(static_cast<int>( - InputAction::CHAT_MOD))) + if (inputManager.isActionActive(InputAction::CHAT_MOD)) { inputManager.executeChatCommand( InputAction::CLOSE_CHAT_TAB, @@ -752,16 +751,16 @@ void ChatWindow::mouseDragged(MouseEvent &event) } #define ifKey(key, str) \ - else if (actionId == static_cast<int>(key)) \ + else if (actionId == key) \ { \ temp = str; \ } void ChatWindow::keyPressed(KeyEvent &event) { - const int actionId = event.getActionId(); + const InputActionT actionId = event.getActionId(); std::string temp; - if (actionId == static_cast<int>(InputAction::GUI_DOWN)) + if (actionId == InputAction::GUI_DOWN) { if (mCurHist != mHistory.end()) { @@ -788,8 +787,9 @@ void ChatWindow::keyPressed(KeyEvent &event) mChatInput->setText(""); } } - else if (actionId == static_cast<int>(InputAction::GUI_UP) && - mCurHist != mHistory.begin() && !mHistory.empty()) + else if (actionId == InputAction::GUI_UP && + mCurHist != mHistory.begin() && + !mHistory.empty()) { // Move backward through the history --mCurHist; @@ -798,7 +798,7 @@ void ChatWindow::keyPressed(KeyEvent &event) mChatInput->setCaretPosition(static_cast<unsigned>( mChatInput->getText().length())); } - else if (actionId == static_cast<int>(InputAction::GUI_INSERT) && + else if (actionId == InputAction::GUI_INSERT && mChatInput->getText() != "") { // Add the current message to the history and clear the text @@ -807,18 +807,18 @@ void ChatWindow::keyPressed(KeyEvent &event) mCurHist = mHistory.end(); mChatInput->setText(""); } - else if (actionId == static_cast<int>(InputAction::GUI_TAB) && + else if (actionId == InputAction::GUI_TAB && !mChatInput->getText().empty()) { autoComplete(); return; } - else if (actionId == static_cast<int>(InputAction::GUI_CANCEL) && + else if (actionId == InputAction::GUI_CANCEL && mChatInput->isVisibleLocal()) { mChatInput->processVisible(Visible_false); } - else if (actionId == static_cast<int>(InputAction::CHAT_PREV_HISTORY) && + else if (actionId == InputAction::CHAT_PREV_HISTORY && mChatInput->isVisibleLocal()) { const ChatTab *const tab = getFocused(); @@ -850,7 +850,7 @@ void ChatWindow::keyPressed(KeyEvent &event) mChatInput->getText().length())); } } - else if (actionId == static_cast<int>(InputAction::CHAT_NEXT_HISTORY) && + else if (actionId == InputAction::CHAT_NEXT_HISTORY && mChatInput->isVisibleLocal()) { const ChatTab *const tab = getFocused(); @@ -886,7 +886,7 @@ void ChatWindow::keyPressed(KeyEvent &event) mChatInput->getText().length())); } } - else if (actionId == static_cast<int>(InputAction::GUI_F1)) + else if (actionId == InputAction::GUI_F1) { if (emoteWindow) { @@ -908,9 +908,9 @@ void ChatWindow::keyPressed(KeyEvent &event) ifKey(InputAction::GUI_F11, "\u2618") ifKey(InputAction::GUI_F12, "\u2592") - if (inputManager.isActionActive(static_cast<int>(InputAction::GUI_CTRL))) + if (inputManager.isActionActive(InputAction::GUI_CTRL)) { - if (actionId == static_cast<int>(InputAction::GUI_B)) + if (actionId == InputAction::GUI_B) { std::string inputText = mChatInput->getTextBeforeCaret(); toLower(inputText); diff --git a/src/gui/windows/editserverdialog.cpp b/src/gui/windows/editserverdialog.cpp index e6fd2e16c..18319dbde 100644 --- a/src/gui/windows/editserverdialog.cpp +++ b/src/gui/windows/editserverdialog.cpp @@ -299,14 +299,14 @@ void EditServerDialog::keyPressed(KeyEvent &event) if (event.isConsumed()) return; - const int actionId = event.getActionId(); + const InputActionT actionId = event.getActionId(); - if (actionId == static_cast<int>(InputAction::GUI_CANCEL)) + if (actionId == InputAction::GUI_CANCEL) { scheduleDelete(); } - else if (actionId == static_cast<int>(InputAction::GUI_SELECT) - || actionId == static_cast<int>(InputAction::GUI_SELECT2)) + else if (actionId == InputAction::GUI_SELECT || + actionId == InputAction::GUI_SELECT2) { action(ActionEvent(nullptr, mOkButton->getActionEventId())); } diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index ed3742c9b..c5934b7ba 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -491,8 +491,7 @@ void InventoryWindow::action(const ActionEvent &event) if (PlayerInfo::isItemProtected(item->getId())) return; - if (inputManager.isActionActive(static_cast<int>( - InputAction::STOP_ATTACK))) + if (inputManager.isActionActive(InputAction::STOP_ATTACK)) { PlayerInfo::dropItem(item, item->getQuantity(), Sfx_true); } @@ -551,12 +550,12 @@ void InventoryWindow::mouseClicked(MouseEvent &event) if (clicks == 2 && gui) gui->resetClickCount(); - const bool mod = (isStorageActive() && inputManager.isActionActive( - static_cast<int>(InputAction::STOP_ATTACK))); + const bool mod = (isStorageActive() && + inputManager.isActionActive(InputAction::STOP_ATTACK)); - const bool mod2 = (tradeWindow && tradeWindow->isWindowVisible() - && inputManager.isActionActive(static_cast<int>( - InputAction::STOP_ATTACK))); + const bool mod2 = (tradeWindow && + tradeWindow->isWindowVisible() && + inputManager.isActionActive(InputAction::STOP_ATTACK)); if (!mod && !mod2 && event.getButton() == MouseButton::RIGHT) { @@ -707,13 +706,13 @@ void InventoryWindow::mouseExited(MouseEvent &event A_UNUSED) void InventoryWindow::keyPressed(KeyEvent &event) { - if (event.getActionId() == static_cast<int>(InputAction::GUI_MOD)) + if (event.getActionId() == InputAction::GUI_MOD) mSplit = true; } void InventoryWindow::keyReleased(KeyEvent &event) { - if (event.getActionId() == static_cast<int>(InputAction::GUI_MOD)) + if (event.getActionId() == InputAction::GUI_MOD) mSplit = false; } diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp index f2b41c7b5..5230ef4fe 100644 --- a/src/gui/windows/logindialog.cpp +++ b/src/gui/windows/logindialog.cpp @@ -252,13 +252,13 @@ void LoginDialog::keyPressed(KeyEvent &event) return; } - const int actionId = event.getActionId(); - if (actionId == static_cast<int>(InputAction::GUI_CANCEL)) + const InputActionT actionId = event.getActionId(); + if (actionId == InputAction::GUI_CANCEL) { action(ActionEvent(nullptr, mServerButton->getActionEventId())); } - else if (actionId == static_cast<int>(InputAction::GUI_SELECT) - || actionId == static_cast<int>(InputAction::GUI_SELECT2)) + else if (actionId == InputAction::GUI_SELECT || + actionId == InputAction::GUI_SELECT2) { action(ActionEvent(nullptr, mLoginButton->getActionEventId())); } diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp index b3a17915d..c1d9b1d24 100644 --- a/src/gui/windows/outfitwindow.cpp +++ b/src/gui/windows/outfitwindow.cpp @@ -30,6 +30,7 @@ #include "being/playerinfo.h" +#include "input/inputactionoperators.h" #include "input/inputmanager.h" #include "gui/viewport.h" @@ -590,8 +591,7 @@ std::string OutfitWindow::keyName(const int number) { if (number < 0 || number >= SHORTCUT_EMOTES) return ""; - return inputManager.getKeyStringLong(static_cast<int>( - InputAction::EMOTE_1) + number); + return inputManager.getKeyStringLong(InputAction::EMOTE_1 + number); } void OutfitWindow::next() diff --git a/src/gui/windows/quitdialog.cpp b/src/gui/windows/quitdialog.cpp index bd710670c..d16a22ff8 100644 --- a/src/gui/windows/quitdialog.cpp +++ b/src/gui/windows/quitdialog.cpp @@ -202,7 +202,7 @@ void QuitDialog::action(const ActionEvent &event) void QuitDialog::keyPressed(KeyEvent &event) { - const int actionId = event.getActionId(); + const InputActionT actionId = event.getActionId(); int dir = 0; switch (actionId) diff --git a/src/gui/windows/registerdialog.cpp b/src/gui/windows/registerdialog.cpp index 85ad80988..1f0dc68e2 100644 --- a/src/gui/windows/registerdialog.cpp +++ b/src/gui/windows/registerdialog.cpp @@ -279,13 +279,13 @@ void RegisterDialog::keyPressed(KeyEvent &event) mRegisterButton->setEnabled(canSubmit()); return; } - const int actionId = event.getActionId(); - if (actionId == static_cast<int>(InputAction::GUI_CANCEL)) + const InputActionT actionId = event.getActionId(); + if (actionId == InputAction::GUI_CANCEL) { action(ActionEvent(nullptr, mCancelButton->getActionEventId())); } - else if (actionId == static_cast<int>(InputAction::GUI_SELECT) - || actionId == static_cast<int>(InputAction::GUI_SELECT2)) + else if (actionId == InputAction::GUI_SELECT || + actionId == InputAction::GUI_SELECT2) { action(ActionEvent(nullptr, mRegisterButton->getActionEventId())); } diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index ca094f1b6..1a6a75093 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -329,8 +329,8 @@ void UpdaterWindow::action(const ActionEvent &event) void UpdaterWindow::keyPressed(KeyEvent &event) { - const int actionId = event.getActionId(); - if (actionId == static_cast<int>(InputAction::GUI_CANCEL)) + const InputActionT actionId = event.getActionId(); + if (actionId == InputAction::GUI_CANCEL) { action(ActionEvent(nullptr, mCancelButton->getActionEventId())); if (client->getState() != STATE_GAME) @@ -338,8 +338,8 @@ void UpdaterWindow::keyPressed(KeyEvent &event) else deleteSelf(); } - else if (actionId == static_cast<int>(InputAction::GUI_SELECT) - || actionId == static_cast<int>(InputAction::GUI_SELECT2)) + else if (actionId == InputAction::GUI_SELECT || + actionId == InputAction::GUI_SELECT2) { if (mDownloadStatus == UPDATE_COMPLETE || mDownloadStatus == UPDATE_ERROR) diff --git a/src/gui/windows/worldselectdialog.cpp b/src/gui/windows/worldselectdialog.cpp index ee5af8123..a2604cf80 100644 --- a/src/gui/windows/worldselectdialog.cpp +++ b/src/gui/windows/worldselectdialog.cpp @@ -120,15 +120,15 @@ void WorldSelectDialog::action(const ActionEvent &event) void WorldSelectDialog::keyPressed(KeyEvent &event) { - const int actionId = event.getActionId(); + const InputActionT actionId = event.getActionId(); - if (actionId == static_cast<int>(InputAction::GUI_CANCEL)) + if (actionId == InputAction::GUI_CANCEL) { action(ActionEvent(nullptr, mChangeLoginButton->getActionEventId())); } - else if (actionId == static_cast<int>(InputAction::GUI_SELECT) - || actionId == static_cast<int>(InputAction::GUI_SELECT2)) + else if (actionId == InputAction::GUI_SELECT || + actionId == InputAction::GUI_SELECT2) { action(ActionEvent(nullptr, mChooseWorld->getActionEventId())); } |