diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-04-28 13:07:23 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-04-28 13:07:23 +0200 |
commit | 983d2f3377c137adbc8eef5590ffffbd4d1d5b14 (patch) | |
tree | 4d504a0ca98e0bef4b26e59488a5959d5bb2f909 | |
parent | 43786e9b5480c50e7d77467bd72dac875e5db908 (diff) | |
download | mana-983d2f3377c137adbc8eef5590ffffbd4d1d5b14.tar.gz mana-983d2f3377c137adbc8eef5590ffffbd4d1d5b14.tar.bz2 mana-983d2f3377c137adbc8eef5590ffffbd4d1d5b14.tar.xz mana-983d2f3377c137adbc8eef5590ffffbd4d1d5b14.zip |
GUI: Use theme icons for offline/online player indicators
Instead of loading images directly, which is less flexible. In Jewelry
theme, these icons are embedded in the window.png image.
-rw-r--r-- | data/graphics/gui/jewelry/theme.xml | 3 | ||||
-rw-r--r-- | data/graphics/gui/theme.xml | 3 | ||||
-rw-r--r-- | src/gui/widgets/avatarlistbox.cpp | 50 | ||||
-rw-r--r-- | src/gui/widgets/avatarlistbox.h | 8 |
4 files changed, 30 insertions, 34 deletions
diff --git a/data/graphics/gui/jewelry/theme.xml b/data/graphics/gui/jewelry/theme.xml index 63694066..21d75058 100644 --- a/data/graphics/gui/jewelry/theme.xml +++ b/data/graphics/gui/jewelry/theme.xml @@ -530,4 +530,7 @@ <icon name="equip-box-ring" src="equipmentbox.png" x="0" y="32" width="32" height="32" /> <icon name="equip-box-shield" src="equipmentbox.png" x="96" y="32" width="32" height="32" /> <icon name="equip-box-weapon" src="equipmentbox.png" x="64" y="32" width="32" height="32" /> + + <icon name="offline" src="window.png" x="65" y="164" width="13" height="13" /> + <icon name="online" src="window.png" x="49" y="164" width="13" height="13" /> </theme> diff --git a/data/graphics/gui/theme.xml b/data/graphics/gui/theme.xml index bfa1b32c..cd4cb1e5 100644 --- a/data/graphics/gui/theme.xml +++ b/data/graphics/gui/theme.xml @@ -325,4 +325,7 @@ <icon name="equip-box-ring" src="equip-box-ring.png" /> <icon name="equip-box-shield" src="equip-box-shield.png" /> <icon name="equip-box-weapon" src="equip-box-weapon.png" /> + + <icon name="offline" src="circle-gray.png" /> + <icon name="online" src="circle-green.png" /> </theme> diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 271fa34c..4a806d04 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -32,33 +32,21 @@ #include <guichan/font.hpp> -int AvatarListBox::instances = 0; -ResourceRef<Image> AvatarListBox::onlineIcon; -ResourceRef<Image> AvatarListBox::offlineIcon; - AvatarListBox::AvatarListBox(AvatarListModel *model): ListBox(model) { - instances++; - - if (instances == 1) - { - onlineIcon = Theme::getImageFromTheme("circle-green.png"); - offlineIcon = Theme::getImageFromTheme("circle-gray.png"); - } - setWidth(200); } -AvatarListBox::~AvatarListBox() +unsigned int AvatarListBox::getRowHeight() const { - instances--; + auto rowHeight = ListBox::getRowHeight(); - if (instances == 0) - { - onlineIcon = nullptr; - offlineIcon = nullptr; - } + auto theme = gui->getTheme(); + if (auto onlineIcon = theme->getIcon("online")) + rowHeight = std::max<unsigned>(rowHeight, onlineIcon->getHeight() + 2); + + return rowHeight; } void AvatarListBox::draw(gcn::Graphics *gcnGraphics) @@ -71,7 +59,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) graphics->setFont(getFont()); - const int fontHeight = getFont()->getHeight(); + const int rowHeight = getRowHeight(); // Draw filled rectangle around the selected list element if (mSelected >= 0) @@ -79,21 +67,29 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) auto highlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); highlightColor.a = gui->getTheme()->getGuiAlpha(); graphics->setColor(highlightColor); - graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected, - getWidth(), fontHeight)); + graphics->fillRectangle(gcn::Rectangle(0, rowHeight * mSelected, + getWidth(), rowHeight)); } + auto theme = gui->getTheme(); + auto onlineIcon = theme->getIcon("online"); + auto offlineIcon = theme->getIcon("offline"); + // Draw the list elements graphics->setColor(Theme::getThemeColor(Theme::TEXT)); for (int i = 0, y = 0; i < model->getNumberOfElements(); - ++i, y += fontHeight) + ++i, y += rowHeight) { Avatar *a = model->getAvatarAt(i); + int x = 1; + // Draw online status - Image *icon = a->getOnline() ? onlineIcon : offlineIcon; - if (icon) - graphics->drawImage(icon, 2, y + 1); + if (const Image *icon = a->getOnline() ? onlineIcon : offlineIcon) + { + graphics->drawImage(icon, x, y + (rowHeight - icon->getHeight()) / 2); + x += icon->getWidth() + 4; + } if (a->getDisplayBold()) graphics->setFont(boldFont); @@ -111,7 +107,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) } // Draw Name - graphics->drawText(text, 15, y); + graphics->drawText(text, x, y); if (a->getDisplayBold()) graphics->setFont(getFont()); diff --git a/src/gui/widgets/avatarlistbox.h b/src/gui/widgets/avatarlistbox.h index 9b0588ac..1f51935f 100644 --- a/src/gui/widgets/avatarlistbox.h +++ b/src/gui/widgets/avatarlistbox.h @@ -23,7 +23,6 @@ #include "avatar.h" #include "gui/widgets/listbox.h" -#include "resources/resource.h" #include <string> @@ -43,7 +42,7 @@ class AvatarListBox : public ListBox public: AvatarListBox(AvatarListModel *model); - ~AvatarListBox() override; + unsigned int getRowHeight() const override; /** * Draws the list box. @@ -51,9 +50,4 @@ public: void draw(gcn::Graphics *gcnGraphics) override; void mousePressed(gcn::MouseEvent &event) override; - -private: - static int instances; - static ResourceRef<Image> onlineIcon; - static ResourceRef<Image> offlineIcon; }; |