diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-22 13:02:26 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-22 14:32:45 +0100 |
commit | 81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08 (patch) | |
tree | e2619b16a5331e5760d94be389d0a3a01427293f /src/gui | |
parent | d047db79f7034e0e75a85a656d18f40716d197b9 (diff) | |
download | mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.gz mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.bz2 mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.xz mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.zip |
General code cleanups
* Use default member initializers
* Use range-based loops
* Don't use 'else' after 'return'
* Removed some unused includes
* Construct empty strings with std::string() instead of ""
* Clear strings with .clear() instead of assigning ""
* Check whether strings are empty with .empty() instead of comparing to ""
* Removed redundant initializations
Diffstat (limited to 'src/gui')
28 files changed, 48 insertions, 60 deletions
diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index 56faed39..9cb585db 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -53,9 +53,7 @@ BeingPopup::BeingPopup(): add(mBeingParty); } -BeingPopup::~BeingPopup() -{ -} +BeingPopup::~BeingPopup() = default; void BeingPopup::show(int x, int y, Being *b) { @@ -84,7 +82,7 @@ void BeingPopup::show(int x, int y, Being *b) } else { - mBeingParty->setCaption(""); + mBeingParty->setCaption(std::string()); setContentSize(minWidth + 10, height + 10); } diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 8cec4279..fd27c89c 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -71,7 +71,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): updateHair(); - mNameField = new TextField(""); + mNameField = new TextField(std::string()); mNameLabel = new Label(_("Name:")); mNextHairColorButton = new Button("", "nextcolor", this); diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 02a89ff2..4bd712f6 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -345,9 +345,9 @@ CharacterDisplay::CharacterDisplay(CharSelectDialog *charSelectDialog): mPlayerBox(new PlayerBox) { mButton = new Button("", "go", charSelectDialog); - mName = new Label(""); - mLevel = new Label(""); - mMoney = new Label(""); + mName = new Label(std::string()); + mLevel = new Label(std::string()); + mMoney = new Label(std::string()); mDelete = new Button(_("Delete"), "delete", charSelectDialog); diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index e1bbed5f..d51c3a25 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -22,18 +22,14 @@ #include "chatwindow.h" #include "actorspritemanager.h" -#include "channel.h" #include "channelmanager.h" #include "configuration.h" #include "localplayer.h" -#include "party.h" #include "playerrelations.h" #include "gui/recorder.h" #include "gui/setup.h" -#include "gui/sdlinput.h" -#include "gui/widgets/channeltab.h" #include "gui/widgets/chattab.h" #include "gui/widgets/itemlinkhandler.h" #include "gui/widgets/layout.h" @@ -45,7 +41,6 @@ #include "net/chathandler.h" #include "net/net.h" -#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -199,7 +194,7 @@ void ChatWindow::action(const gcn::ActionEvent &event) chatInput(message); // Clear the text from the chat input - mChatInput->setText(""); + mChatInput->setText(std::string()); } if (message.empty() || !mReturnToggles) @@ -294,7 +289,7 @@ void ChatWindow::chatInput(const std::string &msg) void ChatWindow::doPresent() { - std::string response = ""; + std::string response; int playercount = 0; for (auto actor : actorSpriteManager->getAll()) diff --git a/src/gui/connectiondialog.cpp b/src/gui/connectiondialog.cpp index 963005cf..2ff68a15 100644 --- a/src/gui/connectiondialog.cpp +++ b/src/gui/connectiondialog.cpp @@ -32,7 +32,7 @@ ConnectionDialog::ConnectionDialog(const std::string &text, State cancelState): - Window(""), + Window(std::string()), mCancelState(cancelState) { setTitleBarHeight(0); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 43d84f61..047e4170 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -59,12 +59,12 @@ public: mFPSText = _("%d FPS"); } - mFPSLabel = new Label(""); - mMusicFileLabel = new Label(""); - mMapLabel = new Label(""); - mMinimapLabel = new Label(""); - mTileMouseLabel = new Label(""); - mParticleCountLabel = new Label(""); + mFPSLabel = new Label(std::string()); + mMusicFileLabel = new Label(std::string()); + mMapLabel = new Label(std::string()); + mMinimapLabel = new Label(std::string()); + mTileMouseLabel = new Label(std::string()); + mParticleCountLabel = new Label(std::string()); LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 7d6cc618..4a940254 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -73,7 +73,7 @@ Minimap::~Minimap() void Minimap::setMap(Map *map) { // Set the title for the Minimap - std::string caption = ""; + std::string caption; std::string minimapName; if (map) diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 13e1ac0d..0ad9e959 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -106,7 +106,7 @@ NpcDialog::NpcDialog(int npcId) mItemList->setVisible(true); // Setup string input box - mTextField = new TextField(""); + mTextField = new TextField(std::string()); mTextField->setVisible(true); // Setup int input box @@ -211,7 +211,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) } else if (mActionState == NPC_ACTION_INPUT) { - std::string printText = ""; // Text that will get printed in the textbox + std::string printText; // Text that will get printed in the textbox if (mInputState == NPC_INPUT_LIST) { @@ -243,7 +243,7 @@ void NpcDialog::action(const gcn::ActionEvent &event) } if (!mLogInteraction) - setText(""); + setText(std::string()); } else if (event.getId() == "reset") { @@ -569,7 +569,7 @@ void NpcEventListener::event(Event::Channel channel, } catch (BadEvent) { - dialog->textRequest(""); + dialog->textRequest(std::string()); } } else if (event.getType() == Event::Next) diff --git a/src/gui/npcdialog.h b/src/gui/npcdialog.h index fc0325a4..36fda2b1 100644 --- a/src/gui/npcdialog.h +++ b/src/gui/npcdialog.h @@ -124,7 +124,7 @@ class NpcDialog : public Window, /** * Requests a text string from the user. */ - void textRequest(const std::string &defaultText = ""); + void textRequest(const std::string &defaultText = std::string()); bool isInputFocused() const; diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index d1e060f0..0c37af19 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -118,7 +118,7 @@ void OutfitWindow::save() } config.setValue("Outfit" + toString(o), outfitStr); config.setValue("OutfitUnequip" + toString(o), mItemsUnequip[o]); - outfitStr = ""; + outfitStr.clear(); } } diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index 566b160c..07bc5fcd 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -115,5 +115,5 @@ void Recorder::setRecordingFile(const std::string &msg) void Recorder::action(const gcn::ActionEvent &event) { - setRecordingFile(""); + setRecordingFile(std::string()); } diff --git a/src/gui/register.cpp b/src/gui/register.cpp index e394e59b..b57ee975 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -209,8 +209,8 @@ void RegisterDialog::action(const gcn::ActionEvent &event) else if (error == 2) { // Reset password confirmation - mPasswordField->setText(""); - mConfirmField->setText(""); + mPasswordField->setText(std::string()); + mConfirmField->setText(std::string()); mWrongDataNoticeListener->setTarget(this->mPasswordField); } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 9862ee11..69420496 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -169,7 +169,7 @@ Setup_Colors::Setup_Colors() : place(3, 11, mGradDelaySlider); place(5, 11, mGradDelayText).setPadding(1); - mGradTypeText->setCaption(""); + mGradTypeText->setCaption(std::string()); } Setup_Colors::~Setup_Colors() diff --git a/src/gui/setup_interface.cpp b/src/gui/setup_interface.cpp index 619a250c..3697285c 100644 --- a/src/gui/setup_interface.cpp +++ b/src/gui/setup_interface.cpp @@ -113,7 +113,7 @@ Setup_Interface::Setup_Interface(): mPickupParticleCheckBox(new CheckBox(_("as particle"), mPickupParticleEnabled)), mSpeechSlider(new Slider(0, 3)), - mSpeechLabel(new Label("")), + mSpeechLabel(new Label(std::string())), mAlphaSlider(new Slider(0.2, 1.0)), mFontSize(config.getIntValue("fontSize")) { diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 1352aa53..6c902bb7 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -22,7 +22,6 @@ #ifndef GUI_SETUP_VIDEO_H #define GUI_SETUP_VIDEO_H -#include "being.h" #include "guichanfwd.h" #include "gui/widgets/setuptab.h" diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index 26f1e928..e13dcd74 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -21,8 +21,6 @@ #include "gui/shortcutwindow.h" -#include "configuration.h" - #include "gui/setup.h" #include "gui/widgets/layout.h" diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 6ec7f011..96a57e54 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -333,7 +333,7 @@ void SkillDialog::loadSkills() auto *skill = new SkillInfo; skill->id = 1; skill->name = "basic"; - skill->setIcon(""); + skill->setIcon(std::string()); skill->modifiable = true; skill->visible = true; skill->model = model; diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 3fda9aa0..96a9c389 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -360,7 +360,7 @@ SocialWindow::~SocialWindow() mPartyAcceptDialog->scheduleDelete(); mPartyAcceptDialog = nullptr; - mPartyInviter = ""; + mPartyInviter.clear(); } delete mCreatePopup; } @@ -445,7 +445,7 @@ void SocialWindow::action(const gcn::ActionEvent &event) Net::getPartyHandler()->inviteResponse(mPartyInviter, false); } - mPartyInviter = ""; + mPartyInviter.clear(); mPartyAcceptDialog = nullptr; } else if (event.getSource() == mGuildAcceptDialog) diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h index 495d9b54..7ffcec78 100644 --- a/src/gui/socialwindow.h +++ b/src/gui/socialwindow.h @@ -70,7 +70,7 @@ public: void showGuildCreate(); void showPartyInvite(const std::string &inviter, - const std::string &partyName = ""); + const std::string &partyName = std::string()); void showPartyCreate(); diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp index cf237d5a..7094da26 100644 --- a/src/gui/tradewindow.cpp +++ b/src/gui/tradewindow.cpp @@ -165,7 +165,7 @@ void TradeWindow::reset() mOkMe = false; setMoney(0); mMoneyField->setEnabled(true); - mMoneyField->setText(""); + mMoneyField->setText(std::string()); mAddButton->setEnabled(true); mMoneyChangeButton->setEnabled(true); setStatus(PREPARING); @@ -219,7 +219,7 @@ void TradeWindow::setStatus(Status s) break; case PROPOSING: mOkButton->setCaption(CAPTION_CONFIRMED); - mOkButton->setActionEventId(""); + mOkButton->setActionEventId(std::string()); break; case ACCEPTING: mOkButton->setCaption(CAPTION_ACCEPT); @@ -227,7 +227,7 @@ void TradeWindow::setStatus(Status s) break; case ACCEPTED: mOkButton->setCaption(CAPTION_ACCEPTED); - mOkButton->setActionEventId(""); + mOkButton->setActionEventId(std::string()); break; default: break; diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 728b2464..2861f973 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -101,7 +101,7 @@ std::vector<UpdateFile> loadTxtFile(const std::string &fileName) thisFile.hash = hash; thisFile.type = "data"; thisFile.required = true; - thisFile.desc = ""; + thisFile.desc.clear(); if (!thisFile.name.empty()) files.push_back(thisFile); @@ -402,7 +402,7 @@ void UpdaterWindow::logic() { case UPDATE_ERROR: // TODO: Only send complete sentences to gettext - mBrowserBox->addRow(""); + mBrowserBox->addRow(std::string()); mBrowserBox->addRow(_("##1 The update process is incomplete.")); // TRANSLATORS: Continues "you try again later.". mBrowserBox->addRow(_("##1 It is strongly recommended that")); diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 166ad102..5975684d 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -120,7 +120,6 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) CHATLOG tmp; tmp.own = own; - tmp.nick = ""; tmp.text = line; std::string::size_type pos = line.find(" : "); @@ -181,7 +180,7 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) lineColor = "##S"; break; case BY_CHANNEL: - tmp.nick = ""; + tmp.nick.clear(); // TODO: Use a predefined color lineColor = "##2"; // Equiv. to BrowserBox::GREEN break; @@ -193,7 +192,7 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) lineColor = "##I"; break; case BY_LOGGER: - tmp.nick = ""; + tmp.nick.clear(); tmp.text = line; lineColor = "##L"; break; @@ -201,7 +200,7 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord) if (tmp.nick == ": ") { - tmp.nick = ""; + tmp.nick.clear(); lineColor = "##S"; } diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index 2aaa63f7..c77bf814 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -55,7 +55,7 @@ class Popup : public Container, public gcn::MouseListener * debugging purposes. * @param skin The location where the Popup's skin XML can be found. */ - Popup(const std::string &name = "", + Popup(const std::string &name = std::string(), const std::string &skin = "window.xml"); /** diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h index d7289816..2f9e665f 100644 --- a/src/gui/widgets/progressbar.h +++ b/src/gui/widgets/progressbar.h @@ -116,7 +116,7 @@ class ProgressBar : public gcn::Widget */ static void render(Graphics *graphics, const gcn::Rectangle &area, const gcn::Color &color, float progress, - const std::string &text = ""); + const std::string &text = std::string()); private: float mProgress, mProgressToGo; diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index ac1c22c9..419fa16e 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -112,7 +112,7 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) { mMinWidth = minWidth; wrappedStream.clear(); - wrappedStream.str(""); + wrappedStream.str(std::string()); spacePos = 0; lastNewlinePos = 0; newlinePos = text.find("\n", lastNewlinePos); diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 872227ea..3e1665d3 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -207,14 +207,14 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) } else { - setText(""); + setText(std::string()); mHistory->current = prevHist; } } else if (!getText().empty()) { // Always clear (easy access to useful function) - setText(""); + setText(std::string()); } } break; diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index bb39810b..3b997ba8 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -65,7 +65,7 @@ struct TextHistory class AutoCompleteLister { public: - virtual ~AutoCompleteLister() {} + virtual ~AutoCompleteLister() = default; virtual void getAutoCompleteList(std::vector<std::string>&) const {} }; @@ -80,7 +80,8 @@ class TextField : public gcn::TextField /** * Constructor, initializes the text field with the given string. */ - TextField(const std::string &text = "", bool loseFocusOnTab = true); + TextField(const std::string &text = std::string(), + bool loseFocusOnTab = true); ~TextField() override; /** diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h index 3e01bb36..646e5d00 100644 --- a/src/gui/widgets/windowcontainer.h +++ b/src/gui/widgets/windowcontainer.h @@ -55,9 +55,7 @@ class WindowContainer : public Container /** * List of widgets that are scheduled to be deleted. */ - using Widgets = std::list<gcn::Widget *>; - using WidgetIterator = Widgets::iterator; - Widgets mDeathList; + std::list<gcn::Widget *> mDeathList; }; extern WindowContainer *windowContainer; |