diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-08-21 22:44:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-08-21 23:18:20 +0300 |
commit | 62ffd2023d9073e452fe2e2f50cf6b2f11224d6f (patch) | |
tree | 8c45c7c16b0c20ac6a7b722d69c148149e6b651f | |
parent | cfa5391c1be51ef49380e398a72c813255d6316e (diff) | |
download | manaverse-62ffd2023d9073e452fe2e2f50cf6b2f11224d6f.tar.gz manaverse-62ffd2023d9073e452fe2e2f50cf6b2f11224d6f.tar.bz2 manaverse-62ffd2023d9073e452fe2e2f50cf6b2f11224d6f.tar.xz manaverse-62ffd2023d9073e452fe2e2f50cf6b2f11224d6f.zip |
next code style changes.
34 files changed, 157 insertions, 118 deletions
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 95cf15363..7b5a1595b 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -200,7 +200,7 @@ void ChatLogger::loadLast(std::string name, std::list<std::string> &list, return; char line[710]; - unsigned sz = list.size(); + unsigned sz = static_cast<unsigned>(list.size()); while (logFile.getline(line, 700)) { list.push_back(line); diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 5c27b7440..e90a12a0d 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -434,7 +434,8 @@ void CharCreateDialog::setAttributes(const StringVect &labels, int w = 480; int h = 350; - for (unsigned i = 0, sz = labels.size(); i < sz; i++) + for (unsigned i = 0, sz = static_cast<unsigned>(labels.size()); + i < sz; i++) { mAttributeLabel[i] = new Label(labels[i]); mAttributeLabel[i]->setWidth(70); diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 77c8ea55d..1d82c09d6 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -211,7 +211,8 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) // Check if a button of a character was pressed const gcn::Widget *sourceParent = event.getSource()->getParent(); int selected = -1; - for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i) + for (unsigned int i = 0, sz = static_cast<unsigned int>( + mCharacterEntries.size()); i < sz; ++i) { if (mCharacterEntries[i] == sourceParent) { @@ -540,7 +541,7 @@ bool CharSelectDialog::selectByName(const std::string &name, if (mCharacterEntries[i]) mCharacterEntries[i]->requestFocus(); if (selAction == Choose) - attemptCharacterSelect(i); + attemptCharacterSelect(static_cast<int>(i)); return true; } } diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 21613bc73..cb3ed8da8 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -753,8 +753,8 @@ void ChatWindow::mouseReleased(gcn::MouseEvent &event A_UNUSED) void ChatWindow::keyPressed(gcn::KeyEvent &event) { const int key = event.getKey().getValue(); - int actionId = static_cast<KeyEvent*>(&event)->getActionId(); - if (actionId == Input::KEY_GUI_DOWN) + const int actionId = static_cast<KeyEvent*>(&event)->getActionId(); + if (actionId == static_cast<int>(Input::KEY_GUI_DOWN)) { if (mCurHist != mHistory.end()) { @@ -778,7 +778,7 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mChatInput->setText(""); } } - else if (actionId == Input::KEY_GUI_UP && + else if (actionId == static_cast<int>(Input::KEY_GUI_UP) && mCurHist != mHistory.begin() && !mHistory.empty()) { // Move backward through the history @@ -787,7 +787,7 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mChatInput->setCaretPosition(static_cast<unsigned>( mChatInput->getText().length())); } - else if (actionId == Input::KEY_GUI_INSERT && + else if (actionId == static_cast<int>(Input::KEY_GUI_INSERT) && mChatInput->getText() != "") { // Add the current message to the history and clear the text @@ -796,18 +796,18 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mCurHist = mHistory.end(); mChatInput->setText(""); } - else if (actionId == Input::KEY_GUI_TAB && + else if (actionId == static_cast<int>(Input::KEY_GUI_TAB) && mChatInput->getText() != "") { autoComplete(); return; } - else if (actionId == Input::KEY_GUI_CANCEL && + else if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL) && mChatInput->isVisible()) { mChatInput->processVisible(false); } - else if (actionId == Input::KEY_CHAT_PREV_HISTORY && + else if (actionId == static_cast<int>(Input::KEY_CHAT_PREV_HISTORY) && mChatInput->isVisible()) { ChatTab *tab = getFocused(); @@ -839,7 +839,7 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mChatInput->getText().length())); } } - else if (actionId == Input::KEY_CHAT_NEXT_HISTORY && + else if (actionId == static_cast<int>(Input::KEY_CHAT_NEXT_HISTORY) && mChatInput->isVisible()) { ChatTab *tab = getFocused(); diff --git a/src/gui/editserverdialog.cpp b/src/gui/editserverdialog.cpp index 28103e350..9701e2b3d 100644 --- a/src/gui/editserverdialog.cpp +++ b/src/gui/editserverdialog.cpp @@ -269,14 +269,15 @@ void EditServerDialog::action(const gcn::ActionEvent &event) void EditServerDialog::keyPressed(gcn::KeyEvent &keyEvent) { - int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId(); + const int actionId = static_cast<KeyEvent*>( + &keyEvent)->getActionId(); - if (actionId == Input::KEY_GUI_CANCEL) + if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL)) { scheduleDelete(); } - else if (actionId == Input::KEY_GUI_SELECT - || actionId == Input::KEY_GUI_SELECT2) + else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT) + || actionId == static_cast<int>(Input::KEY_GUI_SELECT2)) { action(gcn::ActionEvent(nullptr, mOkButton->getActionEventId())); } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 84a13ddba..fe6163877 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -366,8 +366,8 @@ bool Gui::handleKeyInput2() // If the key event hasn't been consumed and // tabbing is enable check for tab press and // change focus. - if (!keyEventConsumed && mTabbing - && keyInput.getActionId() == Input::KEY_GUI_TAB + if (!keyEventConsumed && mTabbing && keyInput.getActionId() + == static_cast<int>(Input::KEY_GUI_TAB) && keyInput.getType() == gcn::KeyInput::PRESSED) { if (keyInput.isShiftPressed()) diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 093ca7c24..16adbbb75 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -363,7 +363,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event) } else { - if (inputManager.isActionActive(Input::KEY_MOD)) + if (inputManager.isActionActive(static_cast<int>(Input::KEY_MOD))) { Net::getInventoryHandler()->dropItem( item, item->getQuantity()); @@ -414,10 +414,10 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) gui->resetClickCount(); const bool mod = (isStorageActive() && inputManager.isActionActive( - Input::KEY_MOD)); + static_cast<int>(Input::KEY_MOD))); const bool mod2 = (tradeWindow && tradeWindow->isVisible() - && inputManager.isActionActive(Input::KEY_MOD)); + && inputManager.isActionActive(static_cast<int>(Input::KEY_MOD))); if (!mod && !mod2 && event.getButton() == gcn::MouseEvent::RIGHT) { @@ -534,14 +534,20 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) void InventoryWindow::keyPressed(gcn::KeyEvent &event) { - if (static_cast<KeyEvent*>(&event)->getActionId() == Input::KEY_GUI_MOD) + if (static_cast<KeyEvent*>(&event)->getActionId() + == static_cast<int>(Input::KEY_GUI_MOD)) + { mSplit = true; + } } void InventoryWindow::keyReleased(gcn::KeyEvent &event) { - if (static_cast<KeyEvent*>(&event)->getActionId() == Input::KEY_GUI_MOD) + if (static_cast<KeyEvent*>(&event)->getActionId() + == static_cast<int>(Input::KEY_GUI_MOD)) + { mSplit = false; + } } void InventoryWindow::valueChanged(const gcn::SelectionEvent &event A_UNUSED) diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp index 65b1541f8..0ae29a730 100644 --- a/src/gui/logindialog.cpp +++ b/src/gui/logindialog.cpp @@ -315,13 +315,14 @@ void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent) return; } - int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId(); - if (actionId == Input::KEY_GUI_CANCEL) + const int actionId = static_cast<KeyEvent*>( + &keyEvent)->getActionId(); + if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL)) { action(gcn::ActionEvent(nullptr, mServerButton->getActionEventId())); } - else if (actionId == Input::KEY_GUI_SELECT - || actionId == Input::KEY_GUI_SELECT2) + else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT) + || actionId == static_cast<int>(Input::KEY_GUI_SELECT2)) { action(gcn::ActionEvent(nullptr, mLoginButton->getActionEventId())); } diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp index f1c2cacea..7871ba09c 100644 --- a/src/gui/npcpostdialog.cpp +++ b/src/gui/npcpostdialog.cpp @@ -38,7 +38,7 @@ NpcPostDialog::DialogList NpcPostDialog::instances; -NpcPostDialog::NpcPostDialog(int npcId): +NpcPostDialog::NpcPostDialog(const int npcId): Window(_("NPC"), false, nullptr, "npcpost.xml"), ActionListener(), mNpcId(npcId), @@ -48,16 +48,16 @@ NpcPostDialog::NpcPostDialog(int npcId): setContentSize(400, 180); // create text field for receiver - gcn::Label *senderText = new Label(_("To:")); + gcn::Label *const senderText = new Label(_("To:")); senderText->setPosition(5, 5); mSender->setPosition(senderText->getWidth() + 5, 5); mSender->setWidth(65); // create button for sending - Button *sendButton = new Button(_("Send"), "send", this); + Button *const sendButton = new Button(_("Send"), "send", this); sendButton->setPosition(400 - sendButton->getWidth(), 170 - sendButton->getHeight()); - Button *cancelButton = new Button(_("Cancel"), "cancel", this); + Button *const cancelButton = new Button(_("Cancel"), "cancel", this); cancelButton->setPosition(sendButton->getX() - (cancelButton->getWidth() + 2), sendButton->getY()); @@ -66,7 +66,7 @@ NpcPostDialog::NpcPostDialog(int npcId): mText->setEditable(true); // create scroll box for letter text - ScrollArea *scrollArea = new ScrollArea(mText); + ScrollArea *const scrollArea = new ScrollArea(mText); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); scrollArea->setDimension(gcn::Rectangle( 5, mSender->getHeight() + 5, diff --git a/src/gui/npcpostdialog.h b/src/gui/npcpostdialog.h index b00f7bda0..af5e735a2 100644 --- a/src/gui/npcpostdialog.h +++ b/src/gui/npcpostdialog.h @@ -36,7 +36,7 @@ public: /** * Constructor */ - NpcPostDialog(int npcId); + NpcPostDialog(const int npcId); ~NpcPostDialog(); diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 2127bc6cf..2c4e913f8 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -518,7 +518,8 @@ std::string OutfitWindow::keyName(int number) { if (number < 0 || number >= SHORTCUT_EMOTES) return ""; - return inputManager.getKeyStringLong(Input::KEY_EMOTE_1 + number); + return inputManager.getKeyStringLong(static_cast<int>( + Input::KEY_EMOTE_1) + number); } void OutfitWindow::next() diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 7d484e082..2b6b8363b 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -58,6 +58,7 @@ #include "gui/sdlinput.h" +#include "keydata.h" #include "keyinput.h" #include "inputmanager.h" diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 28e0c43e6..6e6f99841 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -636,7 +636,8 @@ void ServerDialog::loadServers(bool addNew) MutexLocker tempLock(&mMutex); // Add the server to the local list if it's not already present bool found = false; - for (unsigned int i = 0, sz = mServers.size(); i < sz; i++) + for (unsigned int i = 0, sz = static_cast<unsigned int>( + mServers.size()); i < sz; i++) { if (mServers[i] == server) { @@ -713,7 +714,7 @@ void ServerDialog::saveCustomServers(const ServerInfo ¤tServer, int savedServerCount = 0; - for (unsigned i = 0, sz = mServers.size(); + for (unsigned i = 0, sz = static_cast<unsigned>(mServers.size()); i < sz && savedServerCount < MAX_SERVERLIST; ++ i) { const ServerInfo &server = mServers.at(i); diff --git a/src/gui/setup_input.cpp b/src/gui/setup_input.cpp index 7d7c1842b..2d5795e71 100644 --- a/src/gui/setup_input.cpp +++ b/src/gui/setup_input.cpp @@ -54,7 +54,6 @@ class KeyListModel : public gcn::ListModel { public: KeyListModel() : - gcn::ListModel(), mDataNum(0), mSize(0) { @@ -75,13 +74,13 @@ class KeyListModel : public gcn::ListModel /** * Sets element from container. */ - void setElementAt(int i, const std::string &caption) + void setElementAt(const int i, const std::string &caption) { setupActionData[selectedData][i].text = caption; } - void setSize(int size) + void setSize(const int size) { mSize = size; } - void setDataNum(int num) + void setDataNum(const int num) { mDataNum = num; } private: @@ -89,17 +88,22 @@ class KeyListModel : public gcn::ListModel int mSize; }; -Setup_Input::Setup_Input(): +Setup_Input::Setup_Input() : + SetupTab(), mKeyListModel(new KeyListModel), mKeyList(new ListBox(mKeyListModel)), + mAssignKeyButton(new Button(_("Assign"), "assign", this)), + mUnassignKeyButton(new Button(_("Unassign"), "unassign", this)), + mDefaultButton(new Button(_("Default"), "default", this)), + mResetKeysButton(new Button(_("Reset all keys"), "resetkeys", this)), + mTabs(new TabStrip(config.getIntValue("fontSize") + 10)), mKeySetting(false), - mActionDataSize(nullptr) + mActionDataSize(new int [9]) { inputManager.setSetupInput(this); setName(_("Input")); selectedData = 0; - mActionDataSize = new int [9]; for (int f = 0; f < setupGroups; f ++) { @@ -115,25 +119,20 @@ Setup_Input::Setup_Input(): mKeyList->addActionListener(this); - ScrollArea *scrollArea = new ScrollArea(mKeyList, + ScrollArea *const scrollArea = new ScrollArea(mKeyList, true, "setup_input_background.xml"); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mAssignKeyButton = new Button(_("Assign"), "assign", this); mAssignKeyButton->addActionListener(this); mAssignKeyButton->setEnabled(false); - mUnassignKeyButton = new Button(_("Unassign"), "unassign", this); mUnassignKeyButton->addActionListener(this); mUnassignKeyButton->setEnabled(false); - mResetKeysButton = new Button(_("Reset all keys"), "resetkeys", this); mResetKeysButton->addActionListener(this); - mDefaultButton = new Button(_("Default"), "default", this); mDefaultButton->addActionListener(this); - mTabs = new TabStrip(config.getIntValue("fontSize") + 10); mTabs->addActionListener(this); mTabs->setActionEventId("tabs_"); int k = 0; @@ -217,11 +216,11 @@ void Setup_Input::action(const gcn::ActionEvent &event) { if (!mKeySetting) { - int i(mKeyList->getSelected()); + const int i(mKeyList->getSelected()); if (i >= 0 && i < mActionDataSize[selectedData]) { if (setupActionData[selectedData][i].actionId - == Input::KEY_NO_VALUE) + == static_cast<int>(Input::KEY_NO_VALUE)) { mAssignKeyButton->setEnabled(false); mUnassignKeyButton->setEnabled(false); @@ -239,11 +238,11 @@ void Setup_Input::action(const gcn::ActionEvent &event) mKeySetting = true; mAssignKeyButton->setEnabled(false); keyboard.setEnabled(false); - int i(mKeyList->getSelected()); + const int i(mKeyList->getSelected()); if (i >= 0 && i < mActionDataSize[selectedData]) { const SetupActionData &key = setupActionData[selectedData][i]; - int ik = key.actionId; + const int ik = key.actionId; inputManager.setNewKeyIndex(ik); mKeyListModel->setElementAt(i, std::string( gettext(key.name.c_str())) + ": ?"); @@ -251,15 +250,15 @@ void Setup_Input::action(const gcn::ActionEvent &event) } else if (id == "unassign") { - int i(mKeyList->getSelected()); + const int i(mKeyList->getSelected()); if (i >= 0 && i < mActionDataSize[selectedData]) { const SetupActionData &key = setupActionData[selectedData][i]; - int ik = key.actionId; + const int ik = key.actionId; inputManager.setNewKeyIndex(ik); refreshAssignedKey(mKeyList->getSelected()); inputManager.unassignKey(); - inputManager.setNewKeyIndex(Input::KEY_NO_VALUE); + inputManager.setNewKeyIndex(static_cast<int>(Input::KEY_NO_VALUE)); } mAssignKeyButton->setEnabled(true); } @@ -271,11 +270,11 @@ void Setup_Input::action(const gcn::ActionEvent &event) } else if (id == "default") { - int i(mKeyList->getSelected()); + const int i(mKeyList->getSelected()); if (i >= 0 && i < mActionDataSize[selectedData]) { const SetupActionData &key = setupActionData[selectedData][i]; - int ik = key.actionId; + const int ik = key.actionId; inputManager.makeDefault(ik); refreshKeys(); } @@ -300,10 +299,10 @@ void Setup_Input::action(const gcn::ActionEvent &event) } } -void Setup_Input::refreshAssignedKey(int index) +void Setup_Input::refreshAssignedKey(const int index) { const SetupActionData &key = setupActionData[selectedData][index]; - if (key.actionId == Input::KEY_NO_VALUE) + if (key.actionId == static_cast<int>(Input::KEY_NO_VALUE)) { const std::string str = " \342\200\225\342\200\225\342\200\225" "\342\200\225\342\200\225 "; @@ -318,16 +317,16 @@ void Setup_Input::refreshAssignedKey(int index) } } -void Setup_Input::newKeyCallback(int index) +void Setup_Input::newKeyCallback(const int index) { mKeySetting = false; - int i = keyToSetupData(index); + const int i = keyToSetupData(index); if (i >= 0) refreshAssignedKey(i); mAssignKeyButton->setEnabled(true); } -int Setup_Input::keyToSetupData(int index) +int Setup_Input::keyToSetupData(const int index) const { for (int i = 0; i < mActionDataSize[selectedData]; i++) { @@ -338,7 +337,7 @@ int Setup_Input::keyToSetupData(int index) return -1; } -std::string Setup_Input::keyToString(int index) +std::string Setup_Input::keyToString(const int index) const { for (int f = 0; f < setupGroups; f ++) { @@ -363,12 +362,13 @@ void Setup_Input::keyUnresolved() if (mKeySetting) { newKeyCallback(inputManager.getNewKeyIndex()); - inputManager.setNewKeyIndex(Input::KEY_NO_VALUE); + inputManager.setNewKeyIndex(static_cast<int>(Input::KEY_NO_VALUE)); } } -void Setup_Input::fixTranslation(SetupActionData *actionDatas, int actionStart, - int actionEnd, std::string text) +void Setup_Input::fixTranslation(SetupActionData *const actionDatas, + const int actionStart, const int actionEnd, + const std::string &text) const { int k = 0; @@ -388,15 +388,17 @@ void Setup_Input::fixTranslation(SetupActionData *actionDatas, int actionStart, void Setup_Input::fixTranslations() { - fixTranslation(setupActionData1, Input::KEY_SHORTCUT_1, - Input::KEY_SHORTCUT_20, "Item Shortcut %d"); + fixTranslation(setupActionData1, static_cast<int>(Input::KEY_SHORTCUT_1), + static_cast<int>(Input::KEY_SHORTCUT_20), "Item Shortcut %d"); - fixTranslation(setupActionData3, Input::KEY_EMOTE_1, - Input::KEY_EMOTE_48, "Emote Shortcut %d"); + fixTranslation(setupActionData3, static_cast<int>(Input::KEY_EMOTE_1), + static_cast<int>(Input::KEY_EMOTE_48), "Emote Shortcut %d"); - fixTranslation(setupActionData4, Input::KEY_OUTFIT_1, - Input::KEY_OUTFIT_48, "Outfit Shortcut %d"); + fixTranslation(setupActionData4, static_cast<int>(Input::KEY_OUTFIT_1), + static_cast<int>(Input::KEY_OUTFIT_48), "Outfit Shortcut %d"); - fixTranslation(setupActionData7, Input::KEY_MOVE_TO_POINT_1, - Input::KEY_MOVE_TO_POINT_48, "Move to point Shortcut %d"); + fixTranslation(setupActionData7, static_cast<int>( + Input::KEY_MOVE_TO_POINT_1), + static_cast<int>(Input::KEY_MOVE_TO_POINT_48), + "Move to point Shortcut %d"); } diff --git a/src/gui/setup_input.h b/src/gui/setup_input.h index 89b102881..bed487b68 100644 --- a/src/gui/setup_input.h +++ b/src/gui/setup_input.h @@ -24,6 +24,8 @@ #ifndef GUI_SETUP_INPUT_H #define GUI_SETUP_INPUT_H +#include "keydata.h" + #include "gui/widgets/setuptab.h" #include <guichan/actionlistener.hpp> @@ -58,12 +60,12 @@ class Setup_Input : public SetupTab /** * Get an update on the assigned key. */ - void refreshAssignedKey(int index); + void refreshAssignedKey(const int index); /** * The callback function when a new key has been pressed. */ - void newKeyCallback(int index); + void newKeyCallback(const int index); /** * Shorthand method to update all the keys. @@ -75,15 +77,16 @@ class Setup_Input : public SetupTab */ void keyUnresolved(); - int keyToSetupData(int index); + int keyToSetupData(const int index) const; - std::string keyToString(int index); + std::string keyToString(const int index) const; private: void fixTranslations(); - void fixTranslation(SetupActionData *actionDatas, int actionStart, - int actionEnd, std::string text); + void fixTranslation(SetupActionData *const actionDatas, + const int actionStart, const int actionEnd, + const std::string &text) const; class KeyListModel *mKeyListModel; gcn::ListBox *mKeyList; diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 20ef3b3d4..45030087b 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -152,7 +152,8 @@ public: mPlayers = player_names; // set up widgets - for (unsigned int r = 0, sz = player_names->size(); r < sz; ++r) + for (unsigned int r = 0, sz = static_cast<unsigned int>( + player_names->size()); r < sz; ++r) { std::string name = (*player_names)[r]; gcn::Widget *widget = new Label(name); @@ -323,7 +324,7 @@ void Setup_Relations::reset() player_relations.getPlayerIgnoreStrategy()) { - selection = i; + selection = static_cast<int>(i); break; } } diff --git a/src/gui/setupactiondata.h b/src/gui/setupactiondata.h index ee85f6ca5..1cf6dfeed 100644 --- a/src/gui/setupactiondata.h +++ b/src/gui/setupactiondata.h @@ -1533,7 +1533,7 @@ static SetupActionData setupActionData8[] = } }; -static SetupActionData *setupActionData[] = +static SetupActionData *const setupActionData[] = { setupActionData0, setupActionData7, @@ -1546,7 +1546,7 @@ static SetupActionData *setupActionData[] = setupActionData8 }; -static const char *pages[] = +static const char *const pages[] = { N_("Basic"), N_("Move"), diff --git a/src/gui/statuspopup.cpp b/src/gui/statuspopup.cpp index cc0f5c030..dae8b15fe 100644 --- a/src/gui/statuspopup.cpp +++ b/src/gui/statuspopup.cpp @@ -192,10 +192,11 @@ void StatusPopup::setLabelText(gcn::Label *label, const char *text, int key) inputManager.getKeyValueString(key).c_str())); } -void StatusPopup::setLabelText2(gcn::Label *label, std::string text, int key) +void StatusPopup::setLabelText2(gcn::Label *label, std::string text, + Input::KeyAction key) { label->setCaption(strprintf("%s %s", text.c_str(), - inputManager.getKeyValueString(key).c_str())); + inputManager.getKeyValueString(static_cast<int>(key)).c_str())); label->adjustSize(); } diff --git a/src/gui/statuspopup.h b/src/gui/statuspopup.h index 49ca7727f..0921fbb7f 100644 --- a/src/gui/statuspopup.h +++ b/src/gui/statuspopup.h @@ -24,6 +24,8 @@ #ifndef StatusPopup_H #define StatusPopup_H +#include "keydata.h" + #include "gui/widgets/popup.h" #include "resources/iteminfo.h" @@ -67,7 +69,8 @@ class StatusPopup : public Popup void setLabelText(gcn::Label *label, const char *text, int key); - void setLabelText2(gcn::Label *label, std::string text, int key); + void setLabelText2(gcn::Label *label, std::string text, + Input::KeyAction key); gcn::Label *mMoveType; gcn::Label *mCrazyMoveType; diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp index b8ac3c433..82dff1dd8 100644 --- a/src/gui/tradewindow.cpp +++ b/src/gui/tradewindow.cpp @@ -229,7 +229,8 @@ void TradeWindow::reset() setMoney(0); mMoneyField->setEnabled(true); mMoneyField->setText(""); - mMoneyLabel->setForegroundColor(Theme::getThemeColor(Theme::TEXT)); + mMoneyLabel->setForegroundColor(Theme::getThemeColor( + static_cast<int>(Theme::TEXT))); mAddButton->setEnabled(true); mMoneyChangeButton->setEnabled(true); mGotMoney = 0; diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 49977ae4b..81fe7a9cd 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -263,15 +263,15 @@ void UpdaterWindow::action(const gcn::ActionEvent &event) void UpdaterWindow::keyPressed(gcn::KeyEvent &keyEvent) { - int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId(); + const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId(); - if (actionId == Input::KEY_GUI_CANCEL) + if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL)) { action(gcn::ActionEvent(nullptr, mCancelButton->getActionEventId())); Client::setState(STATE_LOGIN); } - else if (actionId == Input::KEY_GUI_SELECT - || actionId == Input::KEY_GUI_SELECT2) + else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT) + || actionId == static_cast<int>(Input::KEY_GUI_SELECT2)) { if (mDownloadStatus == UPDATE_COMPLETE || mDownloadStatus == UPDATE_ERROR) @@ -534,7 +534,7 @@ void UpdaterWindow::loadUpdates() } std::string fixPath = mUpdatesDir + "/fix"; - const unsigned sz = mUpdateFiles.size(); + const unsigned sz = static_cast<unsigned>(mUpdateFiles.size()); for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++) { UpdaterWindow::addUpdateFile(resman, mUpdatesDir, fixPath, @@ -559,8 +559,8 @@ void UpdaterWindow::loadLocalUpdates(std::string dir) } std::string fixPath = dir + "/fix"; - for (unsigned int updateIndex = 0, sz = updateFiles.size(); - updateIndex < sz; updateIndex ++) + for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( + updateFiles.size()); updateIndex < sz; updateIndex ++) { UpdaterWindow::addUpdateFile(resman, dir, fixPath, updateFiles[updateIndex].name, false); @@ -575,8 +575,8 @@ void UpdaterWindow::loadManaPlusUpdates(std::string dir, std::vector<updateFile> updateFiles = loadXMLFile(fixPath + "/" + xmlUpdateFile); - for (unsigned int updateIndex = 0, sz = updateFiles.size(); - updateIndex < sz; updateIndex ++) + for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>( + updateFiles.size()); updateIndex < sz; updateIndex ++) { std::string name = updateFiles[updateIndex].name; if (strStartWith(name, "manaplus_")) diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 194ad7310..6103c8b86 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -499,18 +499,20 @@ void Viewport::mousePressed(gcn::MouseEvent &event) } } else if (player_node->withinAttackRange(mHoverBeing) || - inputManager.isActionActive(Input::KEY_ATTACK)) + inputManager.isActionActive(static_cast<int>( + Input::KEY_ATTACK))) { validateSpeed(); if (player_node != mHoverBeing) { player_node->attack(mHoverBeing, !inputManager.isActionActive( - Input::KEY_STOP_ATTACK)); + static_cast<int>(Input::KEY_STOP_ATTACK))); return; } } - else if (!inputManager.isActionActive(Input::KEY_ATTACK)) + else if (!inputManager.isActionActive(static_cast<int>( + Input::KEY_ATTACK))) { validateSpeed(); if (player_node != mHoverBeing) @@ -528,7 +530,8 @@ void Viewport::mousePressed(gcn::MouseEvent &event) player_node->pickUp(mHoverItem); } // Just walk around - else if (!inputManager.isActionActive(Input::KEY_ATTACK)) + else if (!inputManager.isActionActive(static_cast<int>( + Input::KEY_ATTACK))) { validateSpeed(); player_node->stopAttack(); @@ -929,8 +932,9 @@ void Viewport::returnCamera() void Viewport::validateSpeed() { - if (!inputManager.isActionActive(Input::KEY_TARGET_ATTACK) - && !inputManager.isActionActive(Input::KEY_ATTACK)) + if (!inputManager.isActionActive(static_cast<int>( + Input::KEY_TARGET_ATTACK)) && !inputManager.isActionActive( + static_cast<int>(Input::KEY_ATTACK))) { if (Game::instance()) Game::instance()->setValidSpeed(); diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 2c8f64a02..ea5210eb8 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -228,7 +228,8 @@ void BrowserBox::addRow(const std::string &row, bool atTop) i != i_end; ++ i) { std::string tempRow = *i; - for (unsigned int j = 0, sz = tempRow.size(); j < sz; j++) + for (unsigned int j = 0, sz = static_cast<unsigned int>( + tempRow.size()); j < sz; j++) { std::string character = tempRow.substr(j, 1); x += font->getWidth(character); diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 2347edd0c..a1b496dc5 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -131,7 +131,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) graphics->setColor(getForegroundColor()); g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT); } - unsigned sz = mEmoteImg.size(); + unsigned sz = static_cast<unsigned>(mEmoteImg.size()); for (unsigned i = 0; i < mMaxItems; i++) { if (i < sz && mEmoteImg[i] && mEmoteImg[i]->sprite) diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp index 13f2694b0..d5bb0ae40 100644 --- a/src/gui/worldselectdialog.cpp +++ b/src/gui/worldselectdialog.cpp @@ -141,15 +141,16 @@ void WorldSelectDialog::action(const gcn::ActionEvent &event) void WorldSelectDialog::keyPressed(gcn::KeyEvent &keyEvent) { - int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId(); + const int actionId = static_cast<KeyEvent*>( + &keyEvent)->getActionId(); - if (actionId == Input::KEY_GUI_CANCEL) + if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL)) { action(gcn::ActionEvent(nullptr, mChangeLoginButton->getActionEventId())); } - else if (actionId == Input::KEY_GUI_SELECT - || actionId == Input::KEY_GUI_SELECT2) + else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT) + || actionId == static_cast<int>(Input::KEY_GUI_SELECT2)) { action(gcn::ActionEvent(nullptr, mChooseWorld->getActionEventId())); } diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp index 3a5424851..9be06c582 100644 --- a/src/guichan/focushandler.cpp +++ b/src/guichan/focushandler.cpp @@ -74,7 +74,8 @@ namespace gcn return; int toBeFocusedIndex = -1; - for (unsigned int i = 0, sz = mWidgets.size(); i < sz; ++i) + for (unsigned int i = 0, sz = static_cast<unsigned int>( + mWidgets.size()); i < sz; ++i) { if (mWidgets[i] == widget) { diff --git a/src/guichan/font.cpp b/src/guichan/font.cpp index ea4652814..bb8006b95 100644 --- a/src/guichan/font.cpp +++ b/src/guichan/font.cpp @@ -56,7 +56,8 @@ namespace gcn { int Font::getStringIndexAt(const std::string& text, int x) const { - for (unsigned int i = 0, sz = text.size(); i < sz; ++i) + for (unsigned int i = 0, sz = static_cast<unsigned int>(text.size()); + i < sz; ++i) { if (getWidth(text.substr(0, i)) > x) return i; diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp index 487549b6a..141bbf96e 100644 --- a/src/guichan/widgets/tabbedarea.cpp +++ b/src/guichan/widgets/tabbedarea.cpp @@ -160,7 +160,8 @@ namespace gcn int TabbedArea::getSelectedTabIndex() const { - for (unsigned int i = 0, sz = mTabs.size(); i < sz; i++) + for (unsigned int i = 0, sz = static_cast<unsigned int>(mTabs.size()); + i < sz; i++) { if (mTabs[i].first == mSelectedTab) return i; @@ -258,7 +259,7 @@ namespace gcn { int maxTabHeight = 0; unsigned int i; - const unsigned int sz = mTabs.size(); + const unsigned int sz = static_cast<unsigned int>(mTabs.size()); for (i = 0; i < sz; i++) { if (mTabs[i].first->getHeight() > maxTabHeight) diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 02612ff42..ba94c7d3e 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -694,5 +694,5 @@ int InputManager::getActionByKey(const SDL_Event &event) if (idx >= 0 && checkKey(&keyData[idx])) return idx; } - return -1; + return Input::KEY_NO_VALUE; } diff --git a/src/joystick.h b/src/joystick.h index f5495b83e..4b4c76943 100644 --- a/src/joystick.h +++ b/src/joystick.h @@ -24,6 +24,7 @@ #define JOYSTICK_H #include "inputevent.h" +#include "keydata.h" #include <SDL.h> diff --git a/src/keyevent.h b/src/keyevent.h index b4a4e5b36..f562dc108 100644 --- a/src/keyevent.h +++ b/src/keyevent.h @@ -21,6 +21,8 @@ #ifndef KEYEVENT_H #define KEYEVENT_H +#include "keydata.h" + #include <guichan/key.hpp> #include <guichan/keyevent.hpp> #include <guichan/widget.hpp> diff --git a/src/keyinput.h b/src/keyinput.h index c650bddad..89e29375a 100644 --- a/src/keyinput.h +++ b/src/keyinput.h @@ -21,6 +21,8 @@ #ifndef KEYINPUT_H #define KEYINPUT_H +#include "keydata.h" + #include <guichan/keyinput.hpp> #include <string> diff --git a/src/map.cpp b/src/map.cpp index 3d09a0d4a..cce5d6419 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -811,7 +811,7 @@ Path Map::findPixelPath(int startPixelX, int startPixelY, int endPixelX, float endOffsetX = static_cast<float>(endPixelX % 32); float endOffsetY = static_cast<float>(endPixelY % 32); - int sz = myPath.size(); + int sz = static_cast<int>(myPath.size()); // Find the distance, and divide it by the number of steps int changeX = static_cast<int>((endOffsetX - startOffsetX) / static_cast<float>(sz)); @@ -1359,7 +1359,8 @@ void Map::indexTilesets() return; } - const int size = static_cast<int>(s->getFirstGid()) + s->size(); + const int size = static_cast<int>(s->getFirstGid()) + + static_cast<int>(s->size()); mIndexedTilesetsSize = size; mIndexedTilesets = new Tileset*[size]; std::fill_n(mIndexedTilesets, size, static_cast<Tileset*>(nullptr)); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 57d83fbdc..a4eafda26 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -535,7 +535,7 @@ std::string stringToHexPath(const std::string &str) return ""; std::string hex = strprintf("%%%2x/", static_cast<int>(str[0])); - for (unsigned f = 1, sz = str.size(); f < sz; f ++) + for (unsigned f = 1, sz = static_cast<unsigned>(str.size()); f < sz; f ++) hex += strprintf("%%%2x", static_cast<int>(str[f])); return hex; } |