From 3c89797394c83db8bc2204fdf5841dd3068f09d0 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sat, 28 Sep 2024 21:26:48 +0200 Subject: Removed getter/setter cruft from ItemInfo Made the class and the code in general more readable by removing all the needless getters and setters. --- src/gui/buydialog.cpp | 4 +--- src/gui/inventorywindow.cpp | 8 ++++---- src/gui/itempopup.cpp | 16 ++++++++-------- src/gui/popupmenu.cpp | 11 +++++------ src/gui/widgets/browserbox.cpp | 2 +- src/gui/widgets/chattab.cpp | 6 +++--- src/gui/widgets/itemcontainer.cpp | 6 +++--- 7 files changed, 25 insertions(+), 28 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp index 1ac5cdaa..135c2119 100644 --- a/src/gui/buydialog.cpp +++ b/src/gui/buydialog.cpp @@ -26,8 +26,6 @@ #include "shopitem.h" #include "units.h" -#include "gui/setup.h" - #include "gui/widgets/button.h" #include "gui/widgets/label.h" #include "gui/widgets/layout.h" @@ -255,7 +253,7 @@ void BuyDialog::updateButtonsAndLabels() } // Calculate how many the player can carry - const int itemWeight = shopItem->getInfo().getWeight(); + const int itemWeight = shopItem->getInfo().weight; if (itemWeight > 0) { const int myTotalWeight = PlayerInfo::getAttribute(TOTAL_WEIGHT); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 8f810622..450ddfe5 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -250,12 +250,12 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) if (event.getSource() == mItems && item && isDoubleClick(item->getInvIndex())) { - if (isMainInventory() && item->getInfo().getActivatable()) + if (isMainInventory() && item->getInfo().activatable) { action(gcn::ActionEvent(mUseButton, mUseButton->getActionEventId())); } - else if (isMainInventory() && item->getInfo().getEquippable()) + else if (isMainInventory() && item->isEquippable()) { action(gcn::ActionEvent(mEquipButton, mEquipButton->getActionEventId())); @@ -366,7 +366,7 @@ void InventoryWindow::updateButtons() mDropButton->setEnabled(true); - if (item->getInfo().getEquippable()) + if (item->isEquippable()) { if (item->isEquipped()) mEquipButton->setCaption(_("Unequip")); @@ -379,7 +379,7 @@ void InventoryWindow::updateButtons() mEquipButton->adjustSize(); - mUseButton->setEnabled(item->getInfo().getActivatable()); + mUseButton->setEnabled(item->getInfo().activatable); if (item->getQuantity() > 1) mDropButton->setCaption(_("Drop...")); diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 8208a5d8..7f1dec3b 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -145,7 +145,7 @@ void ItemPopup::setNoItem() void ItemPopup::setItem(const ItemInfo &item, bool showImage) { - if (item.getName() == mItemName->getCaption()) + if (item.name == mItemName->getCaption()) return; int space = 0; @@ -154,7 +154,7 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage) { ResourceManager *resman = ResourceManager::getInstance(); auto image = resman->getImageRef(paths.getStringValue("itemIcons") + - item.getDisplay().image); + item.display.image); mIcon->setImage(image); if (image) @@ -168,9 +168,9 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage) mIcon->setImage(nullptr); } - mItemType = item.getItemType(); + mItemType = item.type; - std::string caption = item.getName(); + std::string caption = item.name; if (!mItemEquipSlot.empty()) caption += " (" + mItemEquipSlot + ")"; @@ -179,10 +179,10 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage) mItemName->setForegroundColor(getColorFromItemType(mItemType)); mItemName->setPosition(space, 0); - mItemDesc->setTextWrapped(item.getDescription(), ITEMPOPUP_WRAP_WIDTH); - mItemEffect->setTextWrapped(join(item.getEffect(), "\n"), ITEMPOPUP_WRAP_WIDTH); + mItemDesc->setTextWrapped(item.description, ITEMPOPUP_WRAP_WIDTH); + mItemEffect->setTextWrapped(join(item.effect, "\n"), ITEMPOPUP_WRAP_WIDTH); mItemWeight->setTextWrapped(strprintf(_("Weight: %s"), - Units::formatWeight(item.getWeight()).c_str()), + Units::formatWeight(item.weight).c_str()), ITEMPOPUP_WRAP_WIDTH); int minWidth = mItemName->getWidth() + space; @@ -201,7 +201,7 @@ void ItemPopup::setItem(const ItemInfo &item, bool showImage) int nameHeight = std::max(mItemName->getHeight(), mIcon->getHeight()); nameHeight += getPadding(); - if (item.getEffect().empty()) + if (item.effect.empty()) { setContentSize(minWidth, nameHeight + descHeight + weightHeight + getPadding()); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 3c91a273..b1165f27 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -179,11 +179,10 @@ void PopupMenu::showPopup(int x, int y, Being *being) void PopupMenu::showPopup(int x, int y, FloorItem *floorItem) { mFloorItem = floorItem; - ItemInfo info = floorItem->getInfo(); mBrowserBox->clearRows(); // Floor item can be picked up (single option, candidate for removal) - std::string name = info.getName(); + const std::string &name = floorItem->getInfo().name; mBrowserBox->addRow(strprintf("@@pickup|%s@@", strprintf(_("Pick up %s"), name.c_str()).c_str())); mBrowserBox->addRow(strprintf("@@chat|%s@@", _("Add to chat"))); @@ -285,9 +284,9 @@ void PopupMenu::handleLink(const std::string &link) else if (link == "chat") { if (mItem) - chatWindow->addItemText(mItem->getInfo().getName()); + chatWindow->addItemText(mItem->getInfo().name); else if (mFloorItem) - chatWindow->addItemText(mFloorItem->getInfo().getName()); + chatWindow->addItemText(mFloorItem->getInfo().name); } else if (link == "split") @@ -360,14 +359,14 @@ void PopupMenu::showPopup(Window *parent, int x, int y, Item *item, mBrowserBox->addRow(strprintf("@@store|%s@@", _("Store"))); } - if (item->getInfo().getEquippable()) + if (item->isEquippable()) { if (item->isEquipped()) mBrowserBox->addRow(strprintf("@@unequip|%s@@", _("Unequip"))); else mBrowserBox->addRow(strprintf("@@equip|%s@@", _("Equip"))); } - if (item->getInfo().getActivatable()) + if (item->getInfo().activatable) mBrowserBox->addRow(strprintf("@@activate|%s@@", _("Activate"))); if (canDrop) diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 96feddb9..40c9b66a 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -102,7 +102,7 @@ void BrowserBox::addRow(const std::string &row) { const int id = atoi(link.link.c_str()); if (id) - link.caption = itemDb->get(id).getName(); + link.caption = itemDb->get(id).name; else link.caption = link.link; } diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 5097bffa..663464a8 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -282,12 +282,12 @@ void ChatTab::chatInput(const std::string &message) std::string temp = msg.substr(start + 1, end - start - 1); - const ItemInfo itemInfo = itemDb->get(temp); - if (itemInfo.getId() != 0) + const ItemInfo &itemInfo = itemDb->get(temp); + if (itemInfo.id != 0) { msg.insert(end, "@@"); msg.insert(start + 1, "|"); - msg.insert(start + 1, toString(itemInfo.getId())); + msg.insert(start + 1, toString(itemInfo.id)); msg.insert(start + 1, "@@"); } } diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 37a61c80..940c69f4 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -101,7 +101,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) if (!mFilter.empty()) { - if (normalize(item->getInfo().getName()).find(mFilter) == std::string::npos) + if (normalize(item->getInfo().name).find(mFilter) == std::string::npos) continue; mFilteredMap[currentIndex] = item; currentIndex++; @@ -286,7 +286,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) // put item name into chat window if (mDescItems) { - chatWindow->addItemText(item->getInfo().getName()); + chatWindow->addItemText(item->getInfo().name); } if (mSelectedIndex == index) @@ -298,7 +298,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) mSelectionStatus = SEL_SELECTING; itemShortcut->setItemSelected(item->getId()); - if (item->getInfo().getEquippable()) + if (item->isEquippable()) outfitWindow->setItemSelected(item->getId()); } else -- cgit v1.2.3-70-g09d2