diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-02-27 02:44:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-02-27 02:45:53 +0300 |
commit | 481bbd254103fc9d6dc98b19a5226f8868c8c5d9 (patch) | |
tree | 426856951ad81ccb69b43fc53a2ae76861f30fff /src | |
parent | e5272cde78d23a297dad05976e8579b3e5759de4 (diff) | |
download | manaplus-481bbd254103fc9d6dc98b19a5226f8868c8c5d9.tar.gz manaplus-481bbd254103fc9d6dc98b19a5226f8868c8c5d9.tar.bz2 manaplus-481bbd254103fc9d6dc98b19a5226f8868c8c5d9.tar.xz manaplus-481bbd254103fc9d6dc98b19a5226f8868c8c5d9.zip |
Add sliderlist setup item.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/defaults.cpp | 2 | ||||
-rw-r--r-- | src/gui/setup_theme.cpp | 29 | ||||
-rw-r--r-- | src/gui/theme.cpp | 19 | ||||
-rw-r--r-- | src/gui/theme.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/namesmodel.cpp | 51 | ||||
-rw-r--r-- | src/gui/widgets/namesmodel.h | 45 | ||||
-rw-r--r-- | src/gui/widgets/setupitem.cpp | 103 | ||||
-rw-r--r-- | src/gui/widgets/setupitem.h | 37 |
10 files changed, 265 insertions, 27 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90c9240d1..7e7d60886 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -167,6 +167,8 @@ SET(SRCS gui/widgets/listbox.cpp gui/widgets/listbox.h gui/widgets/mouseevent.h + gui/widgets/namesmodel.cpp + gui/widgets/namesmodel.h gui/widgets/passwordfield.cpp gui/widgets/passwordfield.h gui/widgets/playerbox.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 55c2700d6..06b457e4b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -170,6 +170,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/listbox.cpp \ gui/widgets/listbox.h \ gui/widgets/mouseevent.h \ + gui/widgets/namesmodel.cpp \ + gui/widgets/namesmodel.h \ gui/widgets/passwordfield.cpp \ gui/widgets/passwordfield.h \ gui/widgets/playerbox.cpp \ diff --git a/src/defaults.cpp b/src/defaults.cpp index df401e119..01907bfe8 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -263,6 +263,8 @@ DefaultsData* getBrandingDefaults() AddDEF(brandingData, "guiThemePath", "themes/"); AddDEF(brandingData, "fontsPath", "fonts/"); + AddDEF(brandingData, "systemsounds", "sfx/system/"); + AddDEF(brandingData, "wallpaperFile", ""); AddDEF(brandingData, "dataPath", ""); return brandingData; diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index d4a1d5652..d3b9d0e3c 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -29,10 +29,11 @@ #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" +#include "gui/widgets/dropdown.h" #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" +#include "gui/widgets/namesmodel.h" #include "gui/widgets/textfield.h" -#include "gui/widgets/dropdown.h" #include "configuration.h" #include "localplayer.h" @@ -53,32 +54,6 @@ const char* ACTION_HELP_FONT = "help font"; const char* ACTION_SECURE_FONT = "secure font"; const char* ACTION_JAPAN_FONT = "japan font"; -class NamesModel : public gcn::ListModel -{ -public: - NamesModel() - { - } - - virtual ~NamesModel() { } - - virtual int getNumberOfElements() - { - return static_cast<int>(mNames.size()); - } - - virtual std::string getElementAt(int i) - { - if (i >= getNumberOfElements() || i < 0) - return _("???"); - - return mNames[i]; - } - -protected: - std::vector<std::string> mNames; -}; - class ThemesModel : public NamesModel { public: diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 85fd215ac..3a09810d0 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -569,6 +569,25 @@ void Theme::fillFontsList(std::vector<std::string> &list) PHYSFS_permitSymbolicLinks(0); } +void Theme::fillSoundsList(std::vector<std::string> &list) +{ + char **skins = PHYSFS_enumerateFiles( + branding.getStringValue("systemsounds").c_str()); + + for (char **i = skins; *i; i++) + { + if (!PHYSFS_isDirectory(( + branding.getStringValue("systemsounds") + *i).c_str())) + { + std::string str = *i; + if (findCutLast(str, ".ogg")) + list.push_back(str); + } + } + + PHYSFS_freeList(skins); +} + void Theme::selectSkin() { prepareThemePath(); diff --git a/src/gui/theme.h b/src/gui/theme.h index 9cb8f6180..c30044dc7 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -131,6 +131,8 @@ class Theme : public Palette, public ConfigListener static void fillFontsList(std::vector<std::string> &list); + static void fillSoundsList(std::vector<std::string> &list); + /** * Returns the patch to the given gui resource relative to the theme * or, if it isn't in the theme, relative to 'graphics/gui'. diff --git a/src/gui/widgets/namesmodel.cpp b/src/gui/widgets/namesmodel.cpp new file mode 100644 index 000000000..abfcd6def --- /dev/null +++ b/src/gui/widgets/namesmodel.cpp @@ -0,0 +1,51 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/widgets/namesmodel.h" + +#include "logger.h" + +#include "utils/gettext.h" + +#include <guichan/exception.hpp> +#include <guichan/font.hpp> + +#include "debug.h" + +NamesModel::NamesModel() +{ +} + +NamesModel::~NamesModel() +{ +} + +int NamesModel::getNumberOfElements() +{ + return static_cast<int>(mNames.size()); +} + +std::string NamesModel::getElementAt(int i) +{ + if (i >= getNumberOfElements() || i < 0) + return _("???"); + + return mNames[i]; +} diff --git a/src/gui/widgets/namesmodel.h b/src/gui/widgets/namesmodel.h new file mode 100644 index 000000000..3f9f10b52 --- /dev/null +++ b/src/gui/widgets/namesmodel.h @@ -0,0 +1,45 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_WIDGETS_NAMESMODEL_H +#define GUI_WIDGETS_NAMESMODEL_H + +//#include "guichanfwd.h" + +#include <guichan/listmodel.hpp> + +#include <vector> + +class NamesModel : public gcn::ListModel +{ + public: + NamesModel(); + + virtual ~NamesModel(); + + virtual int getNumberOfElements(); + + virtual std::string getElementAt(int i); + + protected: + std::vector<std::string> mNames; +}; + +#endif diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 8987719da..581002a58 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -35,6 +35,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/slider.h" +#include "gui/widgets/sliderlist.h" #include "gui/widgets/tabbedarea.h" #include "gui/widgets/textfield.h" #include "gui/widgets/vertcontainer.h" @@ -693,6 +694,7 @@ void SetupItemSlider::apply(std::string eventName) save(); } + SetupItemSlider2::SetupItemSlider2(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, int min, int max, @@ -851,3 +853,104 @@ void SetupItemSlider2::setInvertValue(int v) mInvertValue = v; toWidget(); } + + +SetupItemSliderList::SetupItemSliderList(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + gcn::ListModel *model, + int width, bool onTheFly, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(nullptr), + mLabel(nullptr), + mSlider(nullptr), + mModel(model), + mWidth(width), + mOnTheFly(onTheFly) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemSliderList::SetupItemSliderList(std::string text, + std::string description, + std::string keyName, + SetupTabScroll *parent, + std::string eventName, + gcn::ListModel *model, + std::string def, int width, + bool onTheFly, bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(nullptr), + mLabel(nullptr), + mSlider(nullptr), + mModel(model), + mWidth(width), + mOnTheFly(onTheFly) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemSliderList::~SetupItemSliderList() +{ + mHorizont = nullptr; + mWidget = nullptr; + mSlider = nullptr; + mLabel = nullptr; +} + +void SetupItemSliderList::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + mLabel = new Label(mText); + mSlider = new SliderList(mModel, mParent, mEventName); + mSlider->setSelectedString(mValue); + mSlider->adjustSize(); + + mWidget = mSlider; + mHorizont->add(mLabel, 5); + mHorizont->add(mSlider); + + mParent->getContainer()->add2(mHorizont, true, 4); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); +} + +void SetupItemSliderList::fromWidget() +{ + if (!mSlider) + return; + + mValue = mSlider->getSelectedString(); +} + +void SetupItemSliderList::toWidget() +{ + if (!mSlider) + return; + + mSlider->setSelectedString(mValue); +} + +void SetupItemSliderList::action(const gcn::ActionEvent &event A_UNUSED) +{ + fromWidget(); + if (mOnTheFly) + save(); +} + +void SetupItemSliderList::apply(std::string eventName) +{ + if (eventName != mEventName) + return; + + fromWidget(); + save(); +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index b950d1488..f883a5b94 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -42,6 +42,7 @@ class HorizontContainer; class IntTextField; class Label; class Slider; +class SliderList; class TextField; class SetupItem : public gcn::ActionListener @@ -353,4 +354,40 @@ class SetupItemSlider2 : public SetupItem bool mOnTheFly; }; +class SetupItemSliderList : public SetupItem +{ + public: + SetupItemSliderList(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + int width = 150, bool onTheFly = false, + bool mainConfig = true); + + SetupItemSliderList(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + std::string def, int width = 150, + bool onTheFly = false, bool mainConfig = true); + + ~SetupItemSliderList(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + SliderList *mSlider; + gcn::ListModel *mModel; + int mWidth; + bool mOnTheFly; +}; + #endif |