From 481bbd254103fc9d6dc98b19a5226f8868c8c5d9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 27 Feb 2012 02:44:23 +0300 Subject: Add sliderlist setup item. --- src/gui/setup_theme.cpp | 29 +----------- src/gui/theme.cpp | 19 ++++++++ src/gui/theme.h | 2 + src/gui/widgets/namesmodel.cpp | 51 ++++++++++++++++++++ src/gui/widgets/namesmodel.h | 45 ++++++++++++++++++ src/gui/widgets/setupitem.cpp | 103 +++++++++++++++++++++++++++++++++++++++++ src/gui/widgets/setupitem.h | 37 +++++++++++++++ 7 files changed, 259 insertions(+), 27 deletions(-) create mode 100644 src/gui/widgets/namesmodel.cpp create mode 100644 src/gui/widgets/namesmodel.h (limited to 'src/gui') 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(mNames.size()); - } - - virtual std::string getElementAt(int i) - { - if (i >= getNumberOfElements() || i < 0) - return _("???"); - - return mNames[i]; - } - -protected: - std::vector 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 &list) PHYSFS_permitSymbolicLinks(0); } +void Theme::fillSoundsList(std::vector &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 &list); + static void fillSoundsList(std::vector &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 . + */ + +#include "gui/widgets/namesmodel.h" + +#include "logger.h" + +#include "utils/gettext.h" + +#include +#include + +#include "debug.h" + +NamesModel::NamesModel() +{ +} + +NamesModel::~NamesModel() +{ +} + +int NamesModel::getNumberOfElements() +{ + return static_cast(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 . + */ + +#ifndef GUI_WIDGETS_NAMESMODEL_H +#define GUI_WIDGETS_NAMESMODEL_H + +//#include "guichanfwd.h" + +#include + +#include + +class NamesModel : public gcn::ListModel +{ + public: + NamesModel(); + + virtual ~NamesModel(); + + virtual int getNumberOfElements(); + + virtual std::string getElementAt(int i); + + protected: + std::vector 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 -- cgit v1.2.3-60-g2f50