diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 13:24:16 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 21:23:10 +0100 |
commit | 306ad2effe4d0897453e61ad787e01dc47c33076 (patch) | |
tree | 75b8b291af55e80d01d9eb85afd7d465233a1a57 /src/gui | |
parent | 66599a9896e0cf69b58c0a73152aba4750d87af2 (diff) | |
download | mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.gz mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.bz2 mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.xz mana-306ad2effe4d0897453e61ad787e01dc47c33076.zip |
General code cleanups
* Use default member initializers
* Use range-based for loops
* Avoid needless pointer references for ShopItem::mDuplicates
* Removed type aliases that are only used once or twice
* Removed more unused includes
* Removed some unused functions
* Removed superfluous .c_str()
* Rely on default copy and assignment operators for Vector class
* Use std::unique_ptr in some places
* Removed duplicated mPlayerMoney updating in SellDialog
* Removed duplicated Game::handleInput call
* Removed unused SDLInput::mMouseInWindow
* Removed remnant of manual widget positioning in HelpWindow
* Removed superfluous initialization of static pointers
Diffstat (limited to 'src/gui')
34 files changed, 102 insertions, 184 deletions
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 041e08e9..a3d9a1f4 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -265,20 +265,14 @@ void ChatWindow::removeWhisper(const std::string &nick) void ChatWindow::removeAllWhispers() { - TabMap::iterator iter; - std::list<ChatTab*> tabs; + // Swap with empty container before deleting, because each tab will try to + // remove itself from mWhispers when it gets deleted, possibly invalidating + // our iterator. + std::map<const std::string, ChatTab *> whispers; + mWhispers.swap(whispers); - for (iter = mWhispers.begin(); iter != mWhispers.end(); ++iter) - { - tabs.push_back(iter->second); - } - - for (auto &tab : tabs) - { + for (auto &[_, tab] : whispers) delete tab; - } - - mWhispers.clear(); } void ChatWindow::chatInput(const std::string &msg) @@ -460,11 +454,11 @@ void ChatWindow::whisper(const std::string &nick, toLower(playerName); toLower(tempNick); - if (tempNick.compare(playerName) == 0) + if (tempNick == playerName) return; ChatTab *tab = nullptr; - TabMap::const_iterator i = mWhispers.find(tempNick); + auto i = mWhispers.find(tempNick); if (i != mWhispers.end()) tab = i->second; @@ -511,8 +505,7 @@ ChatTab *ChatWindow::addWhisperTab(const std::string &nick, bool switchTo) toLower(playerName); toLower(tempNick); - if (mWhispers.find(tempNick) != mWhispers.end() - || tempNick.compare(playerName) == 0) + if (mWhispers.find(tempNick) != mWhispers.end() || tempNick == playerName) return nullptr; ChatTab *ret = new WhisperTab(nick); diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index b3072d4a..9b46d7ad 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -214,9 +214,8 @@ class ChatWindow : public Window, /** Tabbed area for holding each channel. */ TabbedArea *mChatTabs; - using TabMap = std::map<const std::string, ChatTab *>; /** Manage whisper tabs */ - TabMap mWhispers; + std::map<const std::string, ChatTab *> mWhispers; bool mReturnToggles; /**< Marks whether <Return> toggles the chat log or not */ diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp index 4d3f0f02..c0b471c1 100644 --- a/src/gui/confirmdialog.cpp +++ b/src/gui/confirmdialog.cpp @@ -21,8 +21,6 @@ #include "gui/confirmdialog.h" -#include "gui/gui.h" - #include "gui/widgets/button.h" #include "gui/widgets/textbox.h" diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 3a528f27..1dfc109e 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -50,11 +50,6 @@ HelpWindow::HelpWindow(): mScrollArea = new ScrollArea(mBrowserBox); auto *okButton = new Button(_("Close"), "close", this); - mScrollArea->setDimension(gcn::Rectangle(5, 5, 445, - 335 - okButton->getHeight())); - okButton->setPosition(450 - okButton->getWidth(), - 345 - okButton->getHeight()); - mBrowserBox->setLinkHandler(this); mBrowserBox->setFont(monoFont); diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 30d5c5c4..7790a3c0 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -45,7 +45,7 @@ #define ITEMPOPUP_WRAP_WIDTH 196 -static gcn::Color getColorFromItemType(ItemType type) +static const gcn::Color &getColorFromItemType(ItemType type) { switch (type) { diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 4efa29eb..8150a01a 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -51,8 +51,6 @@ #define CAPTION_CLOSE _("Close") #define CAPTION_SUBMIT _("Submit") -using NpcDialogs = std::map<int, NpcDialog *>; - class NpcEventListener : public EventListener { public: @@ -63,7 +61,7 @@ public: void removeDialog(int id); private: - NpcDialogs mNpcDialogs; + std::map<int, NpcDialog *> mNpcDialogs; }; static NpcEventListener *npcListener = nullptr; diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp index b2622d76..5a710890 100644 --- a/src/gui/okdialog.cpp +++ b/src/gui/okdialog.cpp @@ -21,8 +21,6 @@ #include "gui/okdialog.h" -#include "gui/gui.h" - #include "gui/widgets/button.h" #include "gui/widgets/textbox.h" diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 0c37af19..5dc05790 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -26,21 +26,14 @@ #include "graphics.h" #include "inventory.h" #include "item.h" -#include "log.h" #include "playerinfo.h" -#include "gui/chatwindow.h" - #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" #include "gui/widgets/label.h" #include "gui/widgets/layout.h" -#include "net/inventoryhandler.h" -#include "net/net.h" - #include "resources/image.h" -#include "resources/iteminfo.h" #include "utils/gettext.h" #include "utils/stringutils.h" diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index aee78b29..aaa3165c 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -50,7 +50,7 @@ const int Palette::RAINBOW_COLOR_COUNT = 7; Palette::Palette(int size) : mRainbowTime(tick_time), - mColors(Colors(size)) + mColors(size) { mInstances.insert(this); } diff --git a/src/gui/palette.h b/src/gui/palette.h index 1ea7c467..41378a43 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -72,9 +72,9 @@ class Palette */ const gcn::Color &getColor(int type, int alpha = 255) { - gcn::Color *col = &mColors[type].color; - col->a = alpha; - return *col; + gcn::Color &col = mColors[type].color; + col.a = alpha; + return col; } /** @@ -163,9 +163,8 @@ class Palette committedColor.b; } }; - using Colors = std::vector<ColorElem>; /** Vector containing the colors. */ - Colors mColors; + std::vector<ColorElem> mColors; std::vector<ColorElem*> mGradVector; }; diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index bcc53ccf..8396418c 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -60,9 +60,7 @@ #include <guichan/exception.hpp> -SDLInput::SDLInput() -{ -} +SDLInput::SDLInput() = default; bool SDLInput::isKeyQueueEmpty() { @@ -220,8 +218,6 @@ void SDLInput::pushInput(SDL_Event event) if ((event.active.state & SDL_APPMOUSEFOCUS) && !event.active.gain) { - mMouseInWindow = false; - if (!mMouseDown) { mouseInput.setX(-1); @@ -231,12 +227,6 @@ void SDLInput::pushInput(SDL_Event event) mMouseInputQueue.push(mouseInput); } } - - if ((event.active.state & SDL_APPMOUSEFOCUS) - && event.active.gain) - { - mMouseInWindow = true; - } break; #endif } // end switch diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h index 4fe5be44..a29f17ca 100644 --- a/src/gui/sdlinput.h +++ b/src/gui/sdlinput.h @@ -162,18 +162,18 @@ public: * only use SDL and plan sticking with SDL you can safely ignore this * function as it in the SDL case does nothing. */ - virtual void _pollInput() { } + void _pollInput() override { } // Inherited from Input - virtual bool isKeyQueueEmpty(); + bool isKeyQueueEmpty() override; - virtual gcn::KeyInput dequeueKeyInput(); + gcn::KeyInput dequeueKeyInput() override; - virtual bool isMouseQueueEmpty(); + bool isMouseQueueEmpty() override; - virtual gcn::MouseInput dequeueMouseInput(); + gcn::MouseInput dequeueMouseInput() override; bool isTextQueueEmpty() const; @@ -187,7 +187,7 @@ protected: * @param button an SDL mouse button. * @return a Guichan mouse button. */ - int convertMouseButton(int button); + static int convertMouseButton(int button); /** * Converts an SDL event key to a key value. @@ -196,14 +196,13 @@ protected: * @return a key value. * @see Key */ - int convertKeyCharacter(SDL_Event event); + static int convertKeyCharacter(SDL_Event event); std::queue<gcn::KeyInput> mKeyInputQueue; std::queue<gcn::MouseInput> mMouseInputQueue; std::queue<TextInput> mTextInputQueue; bool mMouseDown = false; - bool mMouseInWindow = true; }; #endif diff --git a/src/gui/selldialog.cpp b/src/gui/selldialog.cpp index ef694f96..5f499982 100644 --- a/src/gui/selldialog.cpp +++ b/src/gui/selldialog.cpp @@ -212,8 +212,6 @@ void SellDialog::action(const gcn::ActionEvent &event) mAmountItems -= sellCount; } - mPlayerMoney += - mAmountItems * mShopItems->at(selectedItem)->getPrice(); mAmountItems = 1; mSlider->setValue(0); diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index 4bb201a5..4db36462 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -73,10 +73,8 @@ class ServersListModel : public gcn::ListModel void setVersionString(int index, const std::string &version); private: - using VersionStrings = std::vector<VersionString>; - ServerInfos *mServers; - VersionStrings mVersionStrings; + std::vector<VersionString> mVersionStrings; ServerDialog *mParent; }; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index de32fcb1..6f2f0d26 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -131,7 +131,7 @@ public: /** * Returns the index corresponding to the given video resolution - * or -1 if not found. + * or 0 ("Custom") if not found. */ int getIndexOf(int width, int height) const { diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index c43183a2..7639f1d6 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -99,8 +99,6 @@ struct SkillInfo void draw(Graphics *graphics, int y, int width); }; -using SkillList = std::vector<SkillInfo *>; - class SkillModel : public gcn::ListModel { public: @@ -119,8 +117,8 @@ public: { mSkills.push_back(info); } private: - SkillList mSkills; - SkillList mVisibleSkills; + std::vector<SkillInfo *> mSkills; + std::vector<SkillInfo *> mVisibleSkills; }; class SkillListBox : public ListBox diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index ebf29ff8..e88c279f 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -75,8 +75,7 @@ class SkillDialog : public Window, public gcn::ActionListener, public EventListe bool hasSkills() { return !mSkills.empty(); } private: - using SkillMap = std::map<int, SkillInfo *>; - SkillMap mSkills; + std::map<int, SkillInfo *> mSkills; TabbedArea *mTabs; Label *mPointsLabel; Button *mIncreaseButton; diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 96a9c389..00211e02 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -48,6 +48,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include <memory> + class SocialTab : public Tab { protected: @@ -79,8 +81,8 @@ protected: TextDialog *mInviteDialog = nullptr; ConfirmDialog *mConfirmDialog = nullptr; - ScrollArea *mScroll; - AvatarListBox *mList; + std::unique_ptr<ScrollArea> mScroll; + std::unique_ptr<AvatarListBox> mList; }; class GuildTab : public SocialTab, public gcn::ActionListener @@ -93,21 +95,13 @@ public: setTabColor(&Theme::getThemeColor(Theme::GUILD)); - mList = new AvatarListBox(guild); - mScroll = new ScrollArea(mList); + mList = std::make_unique<AvatarListBox>(guild); + mScroll = std::make_unique<ScrollArea>(mList.get()); mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); } - ~GuildTab() override - { - delete mList; - mList = nullptr; - delete mScroll; - mScroll = nullptr; - } - void action(const gcn::ActionEvent &event) override { if (event.getId() == "do invite") @@ -176,21 +170,13 @@ public: setTabColor(&Theme::getThemeColor(Theme::PARTY_SOCIAL_TAB)); - mList = new AvatarListBox(party); - mScroll = new ScrollArea(mList); + mList = std::make_unique<AvatarListBox>(party); + mScroll = std::make_unique<ScrollArea>(mList.get()); mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); } - ~PartyTab() override - { - delete mList; - mList = nullptr; - delete mScroll; - mScroll = nullptr; - } - void action(const gcn::ActionEvent &event) override { if (event.getId() == "do invite") @@ -302,10 +288,7 @@ private: }; SocialWindow::SocialWindow() : - Window(_("Social")), - mGuildInvited(0), - mGuildAcceptDialog(nullptr), - mPartyAcceptDialog(nullptr) + Window(_("Social")) { setWindowName("Social"); setVisible(false); @@ -373,7 +356,7 @@ bool SocialWindow::addTab(Guild *guild) auto *tab = new GuildTab(guild); mGuilds[guild] = tab; - mTabs->addTab(tab, tab->mScroll); + mTabs->addTab(tab, tab->mScroll.get()); updateButtons(); @@ -403,7 +386,7 @@ bool SocialWindow::addTab(Party *party) auto *tab = new PartyTab(party); mParties[party] = tab; - mTabs->addTab(tab, tab->mScroll); + mTabs->addTab(tab, tab->mScroll.get()); updateButtons(); @@ -490,7 +473,8 @@ void SocialWindow::action(const gcn::ActionEvent &event) "shorter name.")); return; } - else if (!name.empty()) + + if (!name.empty()) { Net::getGuildHandler()->create(name); SERVER_NOTICE(strprintf(_("Creating guild called %s."), @@ -513,7 +497,8 @@ void SocialWindow::action(const gcn::ActionEvent &event) "shorter name.")); return; } - else if (!name.empty()) + + if (!name.empty()) { Net::getPartyHandler()->create(name); SERVER_NOTICE(strprintf(_("Creating party called %s."), diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h index 7ffcec78..8575f3b2 100644 --- a/src/gui/socialwindow.h +++ b/src/gui/socialwindow.h @@ -64,7 +64,7 @@ public: */ void action(const gcn::ActionEvent &event) override; - void showGuildInvite(const std::string &guildName, const int guildId, + void showGuildInvite(const std::string &guildName, int guildId, const std::string &inviterName); void showGuildCreate(); @@ -79,19 +79,16 @@ protected: void updateButtons(); - int mGuildInvited; - ConfirmDialog *mGuildAcceptDialog; - TextDialog *mGuildCreateDialog; + int mGuildInvited = 0; + ConfirmDialog *mGuildAcceptDialog = nullptr; + TextDialog *mGuildCreateDialog = nullptr; std::string mPartyInviter; - ConfirmDialog *mPartyAcceptDialog; - TextDialog *mPartyCreateDialog; + ConfirmDialog *mPartyAcceptDialog = nullptr; + TextDialog *mPartyCreateDialog = nullptr; - using GuildMap = std::map<Guild *, SocialTab *>; - GuildMap mGuilds; - - using PartyMap = std::map<Party *, SocialTab *>; - PartyMap mParties; + std::map<Guild *, SocialTab *> mGuilds; + std::map<Party *, SocialTab *> mParties; CreatePopup *mCreatePopup; diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index d1350bec..99c3b46a 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -81,8 +81,7 @@ class StatusWindow : public Window, public EventListener gcn::Label *mCharacterPointsLabel; gcn::Label *mCorrectionPointsLabel; - using Attrs = std::map<int, AttrDisplay *>; - Attrs mAttrs; + std::map<int, AttrDisplay *> mAttrs; }; extern StatusWindow *statusWindow; diff --git a/src/gui/tradewindow.h b/src/gui/tradewindow.h index cf2bb70e..e9d8d4f1 100644 --- a/src/gui/tradewindow.h +++ b/src/gui/tradewindow.h @@ -117,9 +117,8 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void setStatus(Status s); - using InventoryPtr = const std::unique_ptr<Inventory>; - InventoryPtr mMyInventory; - InventoryPtr mPartnerInventory; + const std::unique_ptr<Inventory> mMyInventory; + const std::unique_ptr<Inventory> mPartnerInventory; ItemContainer *mMyItemContainer; ItemContainer *mPartnerItemContainer; diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 1fd76bdf..167a66b2 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -80,8 +80,6 @@ class TextChunk gcn::Color color; }; -using CacheIterator = std::list<TextChunk>::iterator; - static int fontCounter; TrueTypeFont::TrueTypeFont(const std::string &filename, int size, int style) @@ -175,8 +173,7 @@ int TrueTypeFont::getWidth(const std::string &text) const mCache.splice(mCache.begin(), mCache, i); if (i->img) return i->img->getWidth(); - else - return 0; + return 0; } } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 96c8afd3..6ea74b5e 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -209,8 +209,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, float decay; unsigned duration; }; - using ShakeEffects = std::list<ShakeEffect>; - ShakeEffects mShakeEffects; + std::list<ShakeEffect> mShakeEffects; bool mPlayerFollowMouse = false; diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index d40a54fb..28d16b72 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -61,8 +61,7 @@ static ButtonData const data[BUTTON_COUNT] = { { "button_disabled.png", 25, 23 } }; -Button::Button(): - mButtonIcon(nullptr) +Button::Button() { init(); adjustSize(); diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp index eaf5be1c..5becadd1 100644 --- a/src/gui/widgets/icon.cpp +++ b/src/gui/widgets/icon.cpp @@ -31,10 +31,8 @@ Icon::Icon(const std::string &file) {} Icon::Icon(Image *image) - : mImage(image) { - if (mImage) - setSize(mImage->getWidth(), mImage->getHeight()); + setImage(image); } void Icon::setImage(Image *image) diff --git a/src/gui/widgets/icon.h b/src/gui/widgets/icon.h index 896b26c1..508d2095 100644 --- a/src/gui/widgets/icon.h +++ b/src/gui/widgets/icon.h @@ -62,7 +62,7 @@ class Icon : public gcn::Widget void draw(gcn::Graphics *g) override; private: - Image *mImage; + Image *mImage = nullptr; }; #endif // ICON_H diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index f7941889..c40a3b2c 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -37,13 +37,15 @@ LayoutCell &ContainerPlacer::operator() LayoutCell::~LayoutCell() { - if (mType == ARRAY) delete mArray; + if (mType == ARRAY) + delete mArray; } LayoutArray &LayoutCell::getArray() { assert(mType != WIDGET); - if (mType == ARRAY) return *mArray; + if (mType == ARRAY) + return *mArray; mArray = new LayoutArray; mType = ARRAY; mExtent[0] = 1; @@ -114,7 +116,8 @@ void LayoutArray::resizeGrid(int w, int h) { bool extW = w && w > (int)mSizes[0].size(), extH = h && h > (int)mSizes[1].size(); - if (!extW && !extH) return; + if (!extW && !extH) + return; if (extH) { @@ -177,8 +180,10 @@ LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) cell.mAlign[1] = LayoutCell::FILL; short &cs = mSizes[0][x]; short &rs = mSizes[1][y]; - if (cs == Layout::AUTO_DEF && w == 1) cs = 0; - if (rs == Layout::AUTO_DEF && h == 1) rs = 0; + if (cs == Layout::AUTO_DEF && w == 1) + cs = 0; + if (rs == Layout::AUTO_DEF && h == 1) + rs = 0; return cell; } @@ -218,7 +223,8 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const for (int gridX = 0; gridX < gridW; ++gridX) { LayoutCell const *cell = mCells[gridY][gridX]; - if (!cell || cell->mType == LayoutCell::NONE) continue; + if (!cell || cell->mType == LayoutCell::NONE) + continue; if (cell->mExtent[dim] == 1) { @@ -249,7 +255,8 @@ std::vector< short > LayoutArray::getSizes(int dim, int upp) const } upp = upp + mSpacing; - if (nbFill == 0) return sizes; + if (nbFill == 0) + return sizes; for (int i = 0; i < nb; ++i) { diff --git a/src/gui/widgets/linkhandler.h b/src/gui/widgets/linkhandler.h index dab42a24..33263a25 100644 --- a/src/gui/widgets/linkhandler.h +++ b/src/gui/widgets/linkhandler.h @@ -31,7 +31,7 @@ class LinkHandler { public: - virtual ~LinkHandler() { } + virtual ~LinkHandler() = default; virtual void handleLink(const std::string &link) = 0; }; diff --git a/src/gui/widgets/shopitems.cpp b/src/gui/widgets/shopitems.cpp index 91829131..031416e0 100644 --- a/src/gui/widgets/shopitems.cpp +++ b/src/gui/widgets/shopitems.cpp @@ -60,7 +60,7 @@ void ShopItems::addItem(int inventoryIndex, int id, int quantity, int price) if (item) { - item->addDuplicate (inventoryIndex, quantity); + item->addDuplicate(inventoryIndex, quantity); } else { @@ -87,15 +87,11 @@ void ShopItems::clear() ShopItem *ShopItems::findItem(int id) { - ShopItem *item; - - std::vector<ShopItem*>::iterator it; - for (it = mShopItems.begin(); it != mShopItems.end(); it++) + for (auto shopItem : mShopItems) { - item = *(it); - if (item->getId() == id) + if (shopItem->getId() == id) { - return item; + return shopItem; } } diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 644adf07..772a8e22 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -48,10 +48,10 @@ int TabbedArea::getNumberOfTabs() const Tab *TabbedArea::getTab(const std::string &name) const { - for (auto itr = mTabs.begin(); itr != mTabs.end(); ++itr) + for (const auto &[tab, _] : mTabs) { - if ((*itr).first->getCaption() == name) - return static_cast<Tab*>((*itr).first); + if (tab->getCaption() == name) + return static_cast<Tab*>(tab); } return nullptr; } @@ -113,8 +113,7 @@ void TabbedArea::removeTab(Tab *tab) mSelectedTab = nullptr; } - TabContainer::iterator iter; - for (iter = mTabs.begin(); iter != mTabs.end(); iter++) + for (auto iter = mTabs.begin(); iter != mTabs.end(); iter++) { if (iter->first == tab) { @@ -124,12 +123,11 @@ void TabbedArea::removeTab(Tab *tab) } } - std::vector<gcn::Tab*>::iterator iter2; - for (iter2 = mTabsToDelete.begin(); iter2 != mTabsToDelete.end(); iter2++) + for (auto iter = mTabsToDelete.begin(); iter != mTabsToDelete.end(); iter++) { - if (*iter2 == tab) + if (*iter == tab) { - mTabsToDelete.erase(iter2); + mTabsToDelete.erase(iter); delete tab; break; } @@ -154,9 +152,8 @@ void TabbedArea::mousePressed(gcn::MouseEvent &mouseEvent) { gcn::Widget *widget = mTabContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY()); - auto *tab = dynamic_cast<gcn::Tab*>(widget); - if (tab) + if (auto *tab = dynamic_cast<gcn::Tab*>(widget)) { setSelectedTab(tab); requestFocus(); @@ -205,9 +202,9 @@ void TabbedArea::widgetResized(const gcn::Event &event) void TabbedArea::updateTabsWidth() { mTabsWidth = 0; - for (const auto &tab : mTabs) + for (const auto &[tab, _] : mTabs) { - mTabsWidth += tab.first->getWidth(); + mTabsWidth += tab->getWidth(); } updateVisibleTabsWidth(); } @@ -255,10 +252,9 @@ void TabbedArea::adjustTabPositions() void TabbedArea::action(const gcn::ActionEvent& actionEvent) { - Widget* source = actionEvent.getSource(); - Tab* tab = dynamic_cast<Tab*>(source); + Widget *source = actionEvent.getSource(); - if (tab) + if (Tab *tab = dynamic_cast<Tab*>(source)) { setSelectedTab(tab); } diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index 18e923bf..8e6dcb5f 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -112,9 +112,8 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener // Inherited from MouseListener void mousePressed(gcn::MouseEvent &mouseEvent) override; - private: - using TabContainer = std::vector<std::pair<gcn::Tab *, gcn::Widget *>>; + private: /** The tab arrows */ Button *mArrowButton[2]; diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 3b997ba8..9235f4b8 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -30,13 +30,10 @@ class TextInput; class ImageRect; class TextField; -using TextHistoryList = std::list<std::string>; -using TextHistoryIterator = TextHistoryList::iterator; - struct TextHistory { - TextHistoryList history; /**< Command history. */ - TextHistoryIterator current; /**< History iterator. */ + std::list<std::string> history; /**< Command history. */ + std::list<std::string>::iterator current; /**< History iterator. */ TextHistory() { current = history.end(); } diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp index cab978de..a5b91de1 100644 --- a/src/gui/worldselectdialog.cpp +++ b/src/gui/worldselectdialog.cpp @@ -46,12 +46,10 @@ class WorldListModel : public gcn::ListModel { public: WorldListModel(Worlds worlds): - mWorlds(worlds) + mWorlds(std::move(worlds)) { } - ~WorldListModel() override {} - int getNumberOfElements() override { return mWorlds.size(); @@ -69,8 +67,8 @@ class WorldListModel : public gcn::ListModel WorldSelectDialog::WorldSelectDialog(Worlds worlds): Window(_("Select World")) { - mWorldListModel = new WorldListModel(worlds); - mWorldList = new ListBox(mWorldListModel); + mWorldListModel = std::make_unique<WorldListModel>(worlds); + mWorldList = new ListBox(mWorldListModel.get()); auto *worldsScroll = new ScrollArea(mWorldList); mChangeLoginButton = new Button(_("Change Login"), "login", this); mChooseWorld = new Button(_("Choose World"), "world", this); @@ -86,7 +84,7 @@ WorldSelectDialog::WorldSelectDialog(Worlds worlds): reflowLayout(0, 0); - if (worlds.size() == 0) + if (worlds.empty()) // Disable Ok button mChooseWorld->setEnabled(false); else @@ -100,10 +98,7 @@ WorldSelectDialog::WorldSelectDialog(Worlds worlds): mChooseWorld->requestFocus(); } -WorldSelectDialog::~WorldSelectDialog() -{ - delete mWorldListModel; -} +WorldSelectDialog::~WorldSelectDialog() = default; void WorldSelectDialog::action(const gcn::ActionEvent &event) { diff --git a/src/gui/worldselectdialog.h b/src/gui/worldselectdialog.h index f2b74582..a1150cb8 100644 --- a/src/gui/worldselectdialog.h +++ b/src/gui/worldselectdialog.h @@ -30,7 +30,7 @@ #include <guichan/keylistener.hpp> #include <guichan/listmodel.hpp> -#include <vector> +#include <memory> class LoginData; class WorldListModel; @@ -57,7 +57,7 @@ class WorldSelectDialog : public Window, public gcn::ActionListener, void mouseClicked(gcn::MouseEvent &mouseEvent) override; private: - WorldListModel *mWorldListModel; + std::unique_ptr<WorldListModel> mWorldListModel; gcn::ListBox *mWorldList; gcn::Button *mChangeLoginButton; gcn::Button *mChooseWorld; |