diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/inventorywindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/logindialog.cpp | 2 | ||||
-rw-r--r-- | src/gui/setup_theme.cpp | 70 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.h | 1 | ||||
-rw-r--r-- | src/gui/widgets/extendedlistbox.cpp | 13 | ||||
-rw-r--r-- | src/gui/widgets/extendedlistbox.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/popuplist.cpp | 8 | ||||
-rw-r--r-- | src/gui/widgets/popuplist.h | 2 |
9 files changed, 73 insertions, 31 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index d875644f6..3bf526b40 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -108,7 +108,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory): mSlotsBar(new ProgressBar(this, 0.0f, 100, 0, Theme::PROG_INVY_SLOTS)), mFilter(nullptr), mSortModel(new SortListModel), - mSortDropDown(new DropDown(this, mSortModel, this, "sort")), + mSortDropDown(new DropDown(this, mSortModel, false, this, "sort")), mNameFilter(new TextField(this, "", true, this, "namefilter", true)), mSortDropDownCell(nullptr), mNameFilterCell(nullptr), diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp index 41016b05c..26093634e 100644 --- a/src/gui/logindialog.cpp +++ b/src/gui/logindialog.cpp @@ -163,7 +163,7 @@ LoginDialog::LoginDialog(LoginData *const data, std::string serverName, mLoginData->updateHost.c_str())); mUpdateListModel = new UpdateListModel(mLoginData); mUpdateHostDropDown = new DropDown(this, mUpdateListModel, - this, "updateselect"); + false, this, "updateselect"); const std::string str = serverConfig.getValue("updateHost2", ""); if (!str.empty()) mUpdateHostDropDown->setSelectedString(str); diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index 277ddadae..2a8836bcb 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -29,6 +29,7 @@ #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" #include "gui/widgets/dropdown.h" +#include "gui/widgets/extendedlistmodel.h" #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/namesmodel.h" @@ -116,46 +117,73 @@ struct Language final { std::string name; std::string value; + std::string icon; }; const int langs_count = 16; const Language LANG_NAME[langs_count] = { - {N_("(default)"), ""}, - {N_("Chinese (China)"), "zh_CN"}, - {N_("Czech"), "cs_CZ"}, - {N_("English"), "C"}, - {N_("Finnish"), "fi_FI"}, - {N_("French"), "fr_FR"}, - {N_("German"), "de_DE"}, - {N_("Indonesian"), "id_ID"}, - {N_("Italian"), "it_IT"}, - {N_("Polish"), "pl_PL"}, - {N_("Japanese"), "ja_JP.utf8"}, - {N_("Dutch (Belgium/Flemish)"), "nl_BE"}, - {N_("Portuguese"), "pt_PT"}, - {N_("Portuguese (Brazilian)"), "pt_BR"}, - {N_("Russian"), "ru_RU"}, - {N_("Spanish (Castilian)"), "es_ES"} + {N_("(default)"), "", ""}, + {N_("Chinese (China)"), "zh_CN", "cn.png"}, + {N_("Czech"), "cs_CZ", "cz.png"}, + {N_("English"), "C", "en.png"}, + {N_("Finnish"), "fi_FI", "fi.png"}, + {N_("French"), "fr_FR", "fr.png"}, + {N_("German"), "de_DE", "de.png"}, + {N_("Indonesian"), "id_ID", "id.png"}, + {N_("Italian"), "it_IT", "it.png"}, + {N_("Polish"), "pl_PL", "pl.png"}, + {N_("Japanese"), "ja_JP", "jp.png"}, + {N_("Dutch (Belgium/Flemish)"), "nl_BE", ""}, + {N_("Portuguese"), "pt_PT", "pt.png"}, + {N_("Portuguese (Brazilian)"), "pt_BR", "pt_BR.png"}, + {N_("Russian"), "ru_RU", "ru.png"}, + {N_("Spanish (Castilian)"), "es_ES", "es.png"} }; -class LangListModel final : public gcn::ListModel +class LangListModel final : public ExtendedListModel { public: + LangListModel() + { + ResourceManager *const resman = ResourceManager::getInstance(); + for (int f = 0; f < langs_count; f ++) + { + mIcons[f] = resman->getImage("graphics/flags/" + + LANG_NAME[f].icon); + } + } + virtual ~LangListModel() - { } + { + for (int f = 0; f < langs_count; f ++) + { + Image *const img = mIcons[f]; + if (img) + img->decRef(); + } + } - virtual int getNumberOfElements() override + int getNumberOfElements() override A_WARN_UNUSED { return langs_count; } - virtual std::string getElementAt(int i) override + std::string getElementAt(int i) override A_WARN_UNUSED { if (i >= getNumberOfElements() || i < 0) return _("???"); return gettext(LANG_NAME[i].name.c_str()); } + + const Image *getImageAt(int i) override A_WARN_UNUSED + { + if (i >= getNumberOfElements() || i < 0) + return nullptr; + return mIcons[i]; + } + + Image *mIcons[langs_count]; }; Setup_Theme::Setup_Theme(const Widget2 *const widget) : @@ -170,7 +198,7 @@ Setup_Theme::Setup_Theme(const Widget2 *const widget) : mFont(config.getStringValue("font")), mLangListModel(new LangListModel), mLangLabel(new Label(this, _("Language"))), - mLangDropDown(new DropDown(this, mLangListModel)), + mLangDropDown(new DropDown(this, mLangListModel, true)), mLang(config.getStringValue("lang")), mBoldFontLabel(new Label(this, _("Bold font"))), mBoldFontDropDown(new DropDown(this, mFontsModel)), diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 384371107..dad85a0af 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -58,6 +58,7 @@ static std::string const dropdownFiles[2] = DropDown::DropDown(const Widget2 *const widget, gcn::ListModel *const listModel, + bool extended, gcn::ActionListener *const listener, const std::string &eventId): gcn::ActionListener(), @@ -67,7 +68,7 @@ DropDown::DropDown(const Widget2 *const widget, gcn::FocusListener(), gcn::SelectionListener(), Widget2(widget), - mPopup(new PopupList(this, listModel)), + mPopup(new PopupList(this, listModel, extended)), mShadowColor(getThemeColor(Theme::DROPDOWN_SHADOW)), mHighlightColor(getThemeColor(Theme::HIGHLIGHT)), mPadding(1), diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 6b3b6503a..1707857cb 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -72,6 +72,7 @@ class DropDown final : public gcn::ActionListener, */ DropDown(const Widget2 *const widget, gcn::ListModel *const listModel = nullptr, + bool extended = false, gcn::ActionListener *const listener = nullptr, const std::string &eventId = ""); diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp index b932f91b0..8c850775a 100644 --- a/src/gui/widgets/extendedlistbox.cpp +++ b/src/gui/widgets/extendedlistbox.cpp @@ -37,12 +37,21 @@ #include "debug.h" ExtendedListBox::ExtendedListBox(const Widget2 *const widget, - gcn::ListModel *const listModel) : + gcn::ListModel *const listModel, + int rowHeight) : ListBox(widget, listModel), - mRowHeight(13), + mRowHeight(rowHeight), mImagePadding(mSkin ? mSkin->getOption("imagePadding") : 0), mSpacing(mSkin ? mSkin->getOption("spacing") : 0) { + if (!mRowHeight) + { + const gcn::Font *font = getFont(); + if (font) + mRowHeight = font->getHeight() + 2 * mPadding; + else + mRowHeight = 13; + } } ExtendedListBox::~ExtendedListBox() diff --git a/src/gui/widgets/extendedlistbox.h b/src/gui/widgets/extendedlistbox.h index 32fd274aa..79ae868cf 100644 --- a/src/gui/widgets/extendedlistbox.h +++ b/src/gui/widgets/extendedlistbox.h @@ -30,7 +30,8 @@ class ExtendedListBox final : public ListBox * Constructor. */ ExtendedListBox(const Widget2 *const widget, - gcn::ListModel *const listModel); + gcn::ListModel *const listModel, + int rowHeight = 13); A_DELETE_COPY(ExtendedListBox) diff --git a/src/gui/widgets/popuplist.cpp b/src/gui/widgets/popuplist.cpp index 260dcb6a9..80fd12e85 100644 --- a/src/gui/widgets/popuplist.cpp +++ b/src/gui/widgets/popuplist.cpp @@ -23,7 +23,7 @@ #include "gui/gui.h" #include "gui/widgets/dropdown.h" -#include "gui/widgets/listbox.h" +#include "gui/widgets/extendedlistbox.h" #include "gui/widgets/scrollarea.h" #include "utils/gettext.h" @@ -31,11 +31,13 @@ #include "debug.h" PopupList::PopupList(DropDown *const widget, - gcn::ListModel *const listModel): + gcn::ListModel *const listModel, + bool extended): Popup("PopupList", "popuplist.xml"), gcn::FocusListener(), mListModel(listModel), - mListBox(new ListBox(widget, listModel)), + mListBox(extended ? new ExtendedListBox(widget, listModel, 0) : + new ListBox(widget, listModel)), mScrollArea(new ScrollArea(mListBox, false)), mDropDown(widget) { diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h index e609b52f6..3ba3773fe 100644 --- a/src/gui/widgets/popuplist.h +++ b/src/gui/widgets/popuplist.h @@ -39,7 +39,7 @@ class PopupList final : public Popup, { public: PopupList(DropDown *const widget, - gcn::ListModel *const listModel); + gcn::ListModel *const listModel, bool extended); ~PopupList(); |