From e2620fcbbe0ae5ac43565879f4b7243c367c84cf Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 20 Feb 2012 02:49:46 +0300 Subject: Move gui opacity option to visual settings page. Add slider class for setup pages. --- src/gui/widgets/setupitem.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/gui/widgets/setupitem.h') diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index 71856d6e2..220a55494 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -41,6 +41,7 @@ class EditDialog; class HorizontContainer; class IntTextField; class Label; +class Slider; class TextField; class SetupItem : public gcn::ActionListener @@ -264,4 +265,37 @@ class SetupItemDropDown : public SetupItem DropDown *mDropDown; }; +class SetupItemSlider : public SetupItem +{ + public: + SetupItemSlider(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, double min, double max, + bool mainConfig = true); + + SetupItemSlider(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, double min, double max, + std::string def, bool mainConfig = true); + + ~SetupItemSlider(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + protected: + HorizontContainer *mHorizont; + Label *mLabel; + Slider *mSlider; + double mMin; + double mMax; +}; + #endif -- cgit v1.2.3-60-g2f50 From 2eef004b8b70861fd377ad50393a9a0ccbbbc152 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 21 Feb 2012 00:10:57 +0300 Subject: Move some settings from video to visual page. --- src/gui/setup_video.cpp | 172 +++++------------------------------------- src/gui/setup_video.h | 21 ------ src/gui/setup_visual.cpp | 48 +++++++++++- src/gui/setup_visual.h | 10 +++ src/gui/widgets/setupitem.cpp | 161 ++++++++++++++++++++++++++++++++++++++- src/gui/widgets/setupitem.h | 51 ++++++++++++- src/utils/mathutils.h | 5 ++ 7 files changed, 286 insertions(+), 182 deletions(-) (limited to 'src/gui/widgets/setupitem.h') diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 65fb460e5..ae7e7a9cc 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -28,7 +28,6 @@ #include "localplayer.h" #include "logger.h" #include "main.h" -#include "particle.h" #include "gui/gui.h" #include "gui/okdialog.h" @@ -214,95 +213,26 @@ public: } }; -static const char *speechModeToString(Being::Speech mode) -{ - switch (mode) - { - case Being::NO_SPEECH: - default: - return _("No text"); - case Being::TEXT_OVERHEAD: - return _("Text"); - case Being::NO_NAME_IN_BUBBLE: - return _("Bubbles, no names"); - case Being::NAME_IN_BUBBLE: - return _("Bubbles with names"); - } -} - -const char *Setup_Video::overlayDetailToString(int detail) -{ - if (detail == -1) - detail = config.getIntValue("OverlayDetail"); - - switch (detail) - { - case 0: - return _("off"); - case 1: - return _("low"); - case 2: - return _("high"); - default: - return ""; - } - return ""; -} - -const char *Setup_Video::particleDetailToString(int detail) -{ - if (detail == -1) - detail = 3 - config.getIntValue("particleEmitterSkip"); - - switch (detail) - { - case 0: - return _("low"); - case 1: - return _("medium"); - case 2: - return _("high"); - case 3: - return _("max"); - default: - return ""; - } - return ""; -} - Setup_Video::Setup_Video(): mFullScreenEnabled(config.getBoolValue("screen")), mOpenGLEnabled(config.getIntValue("opengl")), mCustomCursorEnabled(config.getBoolValue("customcursor")), - mParticleEffectsEnabled(config.getBoolValue("particleeffects")), mFps(config.getIntValue("fpslimit")), mAltFps(config.getIntValue("altfpslimit")), mEnableResize(config.getBoolValue("enableresize")), mNoFrame(config.getBoolValue("noframe")), - mSpeechMode(static_cast( - config.getIntValue("speech"))), mModeListModel(new ModeListModel), mModeList(new ListBox(mModeListModel)), mFsCheckBox(new CheckBox(_("Full screen"), mFullScreenEnabled)), mCustomCursorCheckBox(new CheckBox(_("Custom cursor"), mCustomCursorEnabled)), - mParticleEffectsCheckBox(new CheckBox(_("Particle effects"), - mParticleEffectsEnabled)), mEnableResizeCheckBox(new CheckBox(_("Enable resize"), mEnableResize)), mNoFrameCheckBox(new CheckBox(_("No frame"), mNoFrame)), - mSpeechSlider(new Slider(0, 3)), - mSpeechLabel(new Label("")), mFpsCheckBox(new CheckBox(_("FPS limit:"))), mFpsSlider(new Slider(2, 160)), mFpsLabel(new Label), mAltFpsSlider(new Slider(2, 160)), mAltFpsLabel(new Label(_("Alt FPS limit: "))), - mOverlayDetail(config.getIntValue("OverlayDetail")), - mOverlayDetailSlider(new Slider(0, 2)), - mOverlayDetailField(new Label), - mParticleDetail(3 - config.getIntValue("particleEmitterSkip")), - mParticleDetailSlider(new Slider(0, 3)), - mParticleDetailField(new Label), mDialog(nullptr) { setName(_("Video")); @@ -311,10 +241,6 @@ Setup_Video::Setup_Video(): scrollArea->setWidth(150); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - speechLabel = new Label(_("Overhead text")); - overlayDetailLabel = new Label(_("Ambient FX")); - particleDetailLabel = new Label(_("Particle detail")); - mOpenGLListModel = new OpenGLListModel; mOpenGLDropDown = new DropDown(mOpenGLListModel), mOpenGLDropDown->setSelected(mOpenGLEnabled); @@ -343,49 +269,28 @@ Setup_Video::Setup_Video(): mModeList->setActionEventId("videomode"); mCustomCursorCheckBox->setActionEventId("customcursor"); - mParticleEffectsCheckBox->setActionEventId("particleeffects"); mFpsCheckBox->setActionEventId("fpslimitcheckbox"); - mSpeechSlider->setActionEventId("speech"); mFpsSlider->setActionEventId("fpslimitslider"); mAltFpsSlider->setActionEventId("altfpslimitslider"); - mOverlayDetailSlider->setActionEventId("overlaydetailslider"); - mOverlayDetailField->setActionEventId("overlaydetailfield"); - mParticleDetailSlider->setActionEventId("particledetailslider"); - mParticleDetailField->setActionEventId("particledetailfield"); mOpenGLDropDown->setActionEventId("opengl"); mEnableResizeCheckBox->setActionEventId("enableresize"); mNoFrameCheckBox->setActionEventId("noframe"); mModeList->addActionListener(this); mCustomCursorCheckBox->addActionListener(this); - mParticleEffectsCheckBox->addActionListener(this); mFpsCheckBox->addActionListener(this); - mSpeechSlider->addActionListener(this); mFpsSlider->addActionListener(this); mAltFpsSlider->addActionListener(this); - mOverlayDetailSlider->addActionListener(this); - mOverlayDetailField->addKeyListener(this); - mParticleDetailSlider->addActionListener(this); - mParticleDetailField->addKeyListener(this); mOpenGLDropDown->addActionListener(this); mEnableResizeCheckBox->addActionListener(this); mNoFrameCheckBox->addActionListener(this); - mSpeechLabel->setCaption(speechModeToString(mSpeechMode)); - mSpeechSlider->setValue(mSpeechMode); - - mOverlayDetailField->setCaption(overlayDetailToString(mOverlayDetail)); - mOverlayDetailSlider->setValue(mOverlayDetail); - - mParticleDetailField->setCaption(particleDetailToString(mParticleDetail)); - mParticleDetailSlider->setValue(mParticleDetail); - // Do the layout LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, scrollArea, 1, 6).setPadding(2); - place(0, 6, mOpenGLDropDown, 1); + place(0, 0, scrollArea, 1, 5).setPadding(2); + place(0, 5, mOpenGLDropDown, 1); place(1, 0, mFsCheckBox, 2); @@ -401,26 +306,26 @@ Setup_Video::Setup_Video(): // place(0, 7, mAlphaSlider); // place(1, 7, alphaLabel, 3); - place(0, 9, mFpsSlider); - place(1, 9, mFpsCheckBox).setPadding(3); - place(2, 9, mFpsLabel).setPadding(1); + place(0, 6, mFpsSlider); + place(1, 6, mFpsCheckBox).setPadding(3); + place(2, 6, mFpsLabel).setPadding(1); - place(0, 10, mAltFpsSlider); - place(1, 10, mAltFpsLabel).setPadding(3); + place(0, 7, mAltFpsSlider); + place(1, 7, mAltFpsLabel).setPadding(3); - place(0, 11, mSpeechSlider); - place(1, 11, speechLabel); - place(2, 11, mSpeechLabel, 3).setPadding(2); +// place(0, 11, mSpeechSlider); +// place(1, 11, speechLabel); +// place(2, 11, mSpeechLabel, 3).setPadding(2); - place(0, 12, mOverlayDetailSlider); - place(1, 12, overlayDetailLabel); - place(2, 12, mOverlayDetailField, 3).setPadding(2); +// place(0, 12, mOverlayDetailSlider); +// place(1, 12, overlayDetailLabel); +// place(2, 12, mOverlayDetailField, 3).setPadding(2); - place(0, 13, mParticleEffectsCheckBox, 5); +// place(0, 13, mParticleEffectsCheckBox, 5); - place(0, 14, mParticleDetailSlider); - place(1, 14, particleDetailLabel); - place(2, 14, mParticleDetailField, 3).setPadding(2); +// place(0, 14, mParticleDetailSlider); +// place(1, 14, particleDetailLabel); +// place(2, 14, mParticleDetailField, 3).setPadding(2); int width = 600; @@ -518,11 +423,7 @@ void Setup_Video::apply() // We sync old and new values at apply time mFullScreenEnabled = config.getBoolValue("screen"); mCustomCursorEnabled = config.getBoolValue("customcursor"); - mParticleEffectsEnabled = config.getBoolValue("particleeffects"); - mSpeechMode = static_cast( - config.getIntValue("speech")); - mOverlayDetail = config.getIntValue("OverlayDetail"); mOpenGLEnabled = config.getIntValue("opengl"); mEnableResize = config.getBoolValue("enableresize"); mNoFrame = config.getBoolValue("noframe"); @@ -534,14 +435,10 @@ void Setup_Video::cancel() mFsCheckBox->setSelected(mFullScreenEnabled); mOpenGLDropDown->setSelected(mOpenGLEnabled); mCustomCursorCheckBox->setSelected(mCustomCursorEnabled); - mParticleEffectsCheckBox->setSelected(mParticleEffectsEnabled); mFpsSlider->setValue(mFps); mFpsSlider->setEnabled(mFps > 0); mAltFpsSlider->setValue(mAltFps); mAltFpsSlider->setEnabled(mAltFps > 0); - mSpeechSlider->setValue(mSpeechMode); - mOverlayDetailSlider->setValue(mOverlayDetail); - mParticleDetailSlider->setValue(mParticleDetail); mFpsLabel->setCaption(mFpsCheckBox->isSelected() ? toString(mFps) : _("None")); mAltFpsLabel->setCaption(_("Alt FPS limit: ") + toString(mAltFps)); @@ -558,8 +455,6 @@ void Setup_Video::cancel() config.setValue("screenheight", mainGraphics->mHeight); config.setValue("customcursor", mCustomCursorEnabled); - config.setValue("particleeffects", mParticleEffectsEnabled); - config.setValue("speech", static_cast(mSpeechMode)); config.setValue("opengl", mOpenGLEnabled); config.setValue("enableresize", mEnableResize); config.setValue("noframe", mNoFrame); @@ -627,39 +522,6 @@ void Setup_Video::action(const gcn::ActionEvent &event) { config.setValue("customcursor", mCustomCursorCheckBox->isSelected()); } - else if (id == "particleeffects") - { - config.setValue("particleeffects", - mParticleEffectsCheckBox->isSelected()); - Particle::enabled = mParticleEffectsCheckBox->isSelected(); - - if (Game::instance()) - { - new OkDialog(_("Particle Effect Settings Changed."), - _("Changes will take effect on map change.")); - } - } - else if (id == "speech") - { - Being::Speech val = static_cast( - mSpeechSlider->getValue()); - mSpeechLabel->setCaption(speechModeToString(val)); - mSpeechSlider->setValue(val); - config.setValue("speech", static_cast(val)); - } - else if (id == "overlaydetailslider") - { - int val = static_cast(mOverlayDetailSlider->getValue()); - mOverlayDetailField->setCaption(overlayDetailToString(val)); - config.setValue("OverlayDetail", val); - } - else if (id == "particledetailslider") - { - int val = static_cast(mParticleDetailSlider->getValue()); - mParticleDetailField->setCaption(particleDetailToString(val)); - config.setValue("particleEmitterSkip", 3 - val); - Particle::emitterSkip = 4 - val; - } else if (id == "fpslimitcheckbox" || id == "fpslimitslider") { int tempFps = static_cast(mFpsSlider->getValue()); diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 32a5d444c..0e7bc0f21 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -46,59 +46,38 @@ class Setup_Video : public SetupTab, public gcn::KeyListener void action(const gcn::ActionEvent &event); - static const char *overlayDetailToString(int detail = -1); - - static const char *particleDetailToString(int detail = -1); - virtual void externalUpdated(); private: bool mFullScreenEnabled; int mOpenGLEnabled; bool mCustomCursorEnabled; - bool mParticleEffectsEnabled; int mFps; int mAltFps; bool mEnableResize; bool mNoFrame; - Being::Speech mSpeechMode; ModeListModel *mModeListModel; OpenGLListModel *mOpenGLListModel; - gcn::Label *speechLabel; gcn::Label *scrollRadiusLabel; gcn::Label *scrollLazinessLabel; - gcn::Label *overlayDetailLabel; - gcn::Label *particleDetailLabel; gcn::ListBox *mModeList; gcn::CheckBox *mFsCheckBox; gcn::DropDown *mOpenGLDropDown; gcn::CheckBox *mCustomCursorCheckBox; - gcn::CheckBox *mParticleEffectsCheckBox; gcn::CheckBox *mEnableResizeCheckBox; gcn::CheckBox *mNoFrameCheckBox; - gcn::Slider *mSpeechSlider; - gcn::Label *mSpeechLabel; gcn::CheckBox *mFpsCheckBox; gcn::Slider *mFpsSlider; gcn::Label *mFpsLabel; -// gcn::CheckBox *mAltFpsCheckBox; gcn::Slider *mAltFpsSlider; gcn::Label *mAltFpsLabel; - int mOverlayDetail; - gcn::Slider *mOverlayDetailSlider; - gcn::Label *mOverlayDetailField; - - int mParticleDetail; - gcn::Slider *mParticleDetailSlider; - gcn::Label *mParticleDetailField; - TextDialog *mDialog; }; diff --git a/src/gui/setup_visual.cpp b/src/gui/setup_visual.cpp index 1cf35e4f2..9c172da04 100644 --- a/src/gui/setup_visual.cpp +++ b/src/gui/setup_visual.cpp @@ -30,7 +30,6 @@ #include "gui/widgets/label.h" #include "gui/widgets/layouthelper.h" #include "gui/widgets/scrollarea.h" -#include "gui/widgets/setupitem.h" #include "gui/widgets/slider.h" #include "resources/image.h" @@ -38,6 +37,7 @@ #include "configuration.h" #include "localplayer.h" #include "logger.h" +#include "particle.h" #include "utils/gettext.h" @@ -64,9 +64,46 @@ Setup_Visual::Setup_Visual() new SetupItemSlider(_("Gui opacity"), "", "guialpha", this, "guialphaEvent", 0.1, 1.0); + mSpeachList = new SetupItemNames(); + mSpeachList->push_back(_("No text")); + mSpeachList->push_back(_("Text")); + mSpeachList->push_back(_("Bubbles, no names")); + mSpeachList->push_back(_("Bubbles with names")); + new SetupItemSlider2(_("Overhead text"),"", "speech", this, + "speechEvent", 0, 3, mSpeachList); + + mAmbientFxList = new SetupItemNames(); + mAmbientFxList->push_back(_("off")); + mAmbientFxList->push_back(_("low")); + mAmbientFxList->push_back(_("high")); + new SetupItemSlider2(_("Ambient FX"), "", "OverlayDetail", this, + "OverlayDetailEvent", 0, 2, mAmbientFxList); + + new SetupItemCheckBox(_("Particle effects"), "", + "particleeffects", this, "particleeffectsEvent"); + + mParticleList = new SetupItemNames(); + mParticleList->push_back(_("low")); + mParticleList->push_back(_("medium")); + mParticleList->push_back(_("high")); + mParticleList->push_back(_("max")); + (new SetupItemSlider2(_("Particle detail"), "", "particleEmitterSkip", + this, "particleEmitterSkipEvent", 0, 3, + mParticleList))->setInvertValue(3); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } +Setup_Visual::~Setup_Visual() +{ + delete mSpeachList; + mSpeachList = nullptr; + delete mAmbientFxList; + mAmbientFxList = nullptr; + delete mParticleList; + mParticleList = nullptr; +} + void Setup_Visual::apply() { SetupTabScroll::apply(); @@ -85,4 +122,13 @@ void Setup_Visual::action(const gcn::ActionEvent &event) Image::setEnableAlpha(config.getFloatValue("guialpha") != 1.0f); } } + else if (event.getId() == "particleEmitterSkipEvent") + { + Slider *slider = static_cast(event.getSource()); + if (slider) + { + int val = static_cast(slider->getValue()); + Particle::emitterSkip = 4 - val; + } + } } diff --git a/src/gui/setup_visual.h b/src/gui/setup_visual.h index c76002c06..60d8ac787 100644 --- a/src/gui/setup_visual.h +++ b/src/gui/setup_visual.h @@ -25,6 +25,7 @@ #include "guichanfwd.h" +#include "gui/widgets/setupitem.h" #include "gui/widgets/setuptabscroll.h" #include @@ -34,9 +35,18 @@ class Setup_Visual : public SetupTabScroll public: Setup_Visual(); + ~Setup_Visual(); + void apply(); void action(const gcn::ActionEvent &event A_UNUSED); + + private: + SetupItemNames *mSpeachList; + + SetupItemNames *mAmbientFxList; + + SetupItemNames *mParticleList; }; #endif diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 1d6bf5916..581d9f239 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -25,6 +25,7 @@ #include "logger.h" #include "gui/editdialog.h" +#include "gui/gui.h" #include "gui/widgets/button.h" #include "gui/widgets/checkbox.h" @@ -40,7 +41,9 @@ #include "utils/dtor.h" #include "utils/gettext.h" +#include "utils/mathutils.h" +#include SetupItem::SetupItem(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, @@ -591,10 +594,6 @@ void SetupItemDropDown::toWidget() } - - - - SetupItemSlider::SetupItemSlider(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, double min, double max, @@ -686,3 +685,157 @@ void SetupItemSlider::apply(std::string eventName) fromWidget(); save(); } + +SetupItemSlider2::SetupItemSlider2(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, int min, int max, + SetupItemNames *values, bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, mainConfig), + mHorizont(nullptr), + mLabel(nullptr), + mLabel2(nullptr), + mSlider(nullptr), + mValues(values), + mMin(min), + mMax(max), + mInvert(false), + mInvertValue(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemSlider2::SetupItemSlider2(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, int min, int max, + SetupItemNames *values, std::string def, + bool mainConfig) : + SetupItem(text, description, keyName, parent, eventName, def, mainConfig), + mHorizont(nullptr), + mLabel(nullptr), + mLabel2(nullptr), + mSlider(nullptr), + mValues(values), + mMin(min), + mMax(max), + mInvert(false), + mInvertValue(0) +{ + mValueType = VSTR; + createControls(); +} + +SetupItemSlider2::~SetupItemSlider2() +{ + mHorizont = nullptr; + mWidget = nullptr; + mSlider = nullptr; + mLabel = nullptr; +} + +void SetupItemSlider2::createControls() +{ + load(); + mHorizont = new HorizontContainer(32, 2); + + int width = getMaxWidth(); + + mLabel = new Label(mText); + mLabel2 = new Label(""); + mLabel2->setWidth(width); + mSlider = new Slider(mMin, mMax); + mSlider->setActionEventId(mEventName); + mSlider->addActionListener(mParent); + mSlider->setValue(atof(mValue.c_str())); + mSlider->setHeight(30); + + mWidget = mSlider; + mSlider->setWidth(150); + mSlider->setHeight(40); + mHorizont->add(mLabel); + mHorizont->add(mSlider, -10); + mHorizont->add(mLabel2); + + mParent->getContainer()->add2(mHorizont, true, 4); + mParent->addControl(this); + mParent->addActionListener(this); + mWidget->addActionListener(this); + updateLabel(); +} + +int SetupItemSlider2::getMaxWidth() +{ + if (!mValues || !gui) + return 1; + + int maxWidth = 0; + SetupItemNamesConstIter it = mValues->begin(); + SetupItemNamesConstIter it_end = mValues->end(); + gcn::Font *font = gui->getFont(); + + while (it != it_end) + { + int w = font->getWidth(*it); + if (w > maxWidth) + maxWidth = w; + + ++ it; + } + return maxWidth; +} + +void SetupItemSlider2::fromWidget() +{ + if (!mSlider) + return; + + int val = roundDouble(mSlider->getValue()); + if (mInvert) + val = mInvertValue - val; + mValue = toString(val); +} + +void SetupItemSlider2::toWidget() +{ + if (!mSlider) + return; + + int val = roundDouble(atof(mValue.c_str())); + if (mInvert) + val = mInvertValue - val; + mSlider->setValue(val); + updateLabel(); +} + +void SetupItemSlider2::action(const gcn::ActionEvent &event A_UNUSED) +{ + fromWidget(); + updateLabel(); +} + +void SetupItemSlider2::updateLabel() +{ + int val = mSlider->getValue() - mMin; + if (val < 0) + val = 0; + else if (val >= (signed)mValues->size()) + val = (signed)mValues->size() - 1; + std::string str = mValues->at(val); + mLabel2->setCaption(str); +} + +void SetupItemSlider2::apply(std::string eventName) +{ + if (eventName != mEventName) + return; + + fromWidget(); + save(); +} + +void SetupItemSlider2::setInvertValue(int v) +{ + mInvert = true; + mInvertValue = v; + toWidget(); +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index 220a55494..cf847f55d 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -92,7 +92,6 @@ class SetupItem : public gcn::ActionListener virtual void cancel(std::string eventName); virtual void externalUpdated(std::string eventName); -// virtual int add(ContainerPlacer &place, int x, int y, int width); bool isMainConfig() const { return mMainConfig; } @@ -290,6 +289,8 @@ class SetupItemSlider : public SetupItem void apply(std::string eventName); + void updateLabel(); + protected: HorizontContainer *mHorizont; Label *mLabel; @@ -298,4 +299,52 @@ class SetupItemSlider : public SetupItem double mMax; }; +typedef std::vector SetupItemNames; +typedef SetupItemNames::iterator SetupItemNamesIter; +typedef SetupItemNames::const_iterator SetupItemNamesConstIter; + +class SetupItemSlider2 : public SetupItem +{ + public: + SetupItemSlider2(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, int min, int max, + SetupItemNames *values, bool mainConfig = true); + + SetupItemSlider2(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, int min, int max, + SetupItemNames *values, std::string def, + bool mainConfig = true); + + ~SetupItemSlider2(); + + void createControls(); + + void fromWidget(); + + void toWidget(); + + void action(const gcn::ActionEvent &event); + + void apply(std::string eventName); + + void setInvertValue(int v); + + protected: + void updateLabel(); + + int getMaxWidth(); + + HorizontContainer *mHorizont; + Label *mLabel; + Label *mLabel2; + Slider *mSlider; + SetupItemNames *mValues; + int mMin; + int mMax; + bool mInvert; + int mInvertValue; +}; + #endif diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h index 9f6818146..8ccd71e79 100644 --- a/src/utils/mathutils.h +++ b/src/utils/mathutils.h @@ -112,4 +112,9 @@ inline float weightedAverage(float n1, float n2, float w) return w * n2 + (1.0f - w) * n1; } +inline int roundDouble(double v) +{ + return (v > 0.0) ? (v + 0.5) : (v - 0.5); +} + #endif // UTILS_MATHUTILS_H -- cgit v1.2.3-60-g2f50 From e4dabfe2b75a20378bdb1bf32b53249b5d55740b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 21 Feb 2012 03:33:54 +0300 Subject: Bit cleanup visual settings page. --- src/client.cpp | 20 ++++++++++++++++++++ src/client.h | 2 ++ src/defaults.cpp | 2 ++ src/gui/setup_visual.cpp | 30 +++++------------------------- src/gui/setup_visual.h | 2 -- src/gui/widgets/setupitem.cpp | 30 +++++++++++++++++++++--------- src/gui/widgets/setupitem.h | 12 +++++++++--- 7 files changed, 59 insertions(+), 39 deletions(-) (limited to 'src/gui/widgets/setupitem.h') diff --git a/src/client.cpp b/src/client.cpp index 949dbacd2..d0c573e13 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -563,6 +563,7 @@ void Client::gameInit() } applyGrabMode(); + applyGamma(); // Initialize for drawing mainGraphics->_beginDraw(); @@ -665,6 +666,8 @@ void Client::gameInit() setFramerate(fpsLimit); config.addListener("fpslimit", this); config.addListener("guialpha", this); + config.addListener("gamma", this); + config.addListener("particleEmitterSkip", this); setGuiAlpha(config.getFloatValue("guialpha")); optionChanged("fpslimit"); @@ -704,6 +707,8 @@ void Client::gameClear() logger->log1("Quitting1"); config.removeListener("fpslimit", this); config.removeListener("guialpha", this); + config.removeListener("gamma", this); + config.removeListener("particleEmitterSkip", this); SDL_RemoveTimer(mLogicCounterId); SDL_RemoveTimer(mSecondsCounterId); @@ -1492,6 +1497,15 @@ void Client::optionChanged(const std::string &name) else if (name == "guialpha") { setGuiAlpha(config.getFloatValue("guialpha")); + Image::setEnableAlpha(config.getFloatValue("guialpha") != 1.0f); + } + else if (name == "gamma") + { + applyGamma(); + } + else if (name == "particleEmitterSkip") + { + Particle::emitterSkip = config.getIntValue("particleEmitterSkip") + 1; } } @@ -2437,3 +2451,9 @@ void Client::applyGrabMode() SDL_WM_GrabInput(config.getBoolValue("grabinput") ? SDL_GRAB_ON : SDL_GRAB_OFF); } + +void Client::applyGamma() +{ + float val = config.getFloatValue("gamma"); + SDL_SetGamma(val, val, val); +} \ No newline at end of file diff --git a/src/client.h b/src/client.h index ba6fde480..922b24caf 100644 --- a/src/client.h +++ b/src/client.h @@ -275,6 +275,8 @@ public: static void applyGrabMode(); + void applyGamma(); + void optionChanged(const std::string &name); void action(const gcn::ActionEvent &event); diff --git a/src/defaults.cpp b/src/defaults.cpp index b21941bfb..865330827 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -226,6 +226,8 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "enableresize", true); AddDEF(configData, "noframe", false); AddDEF(configData, "groupFriends", true); + AddDEF(configData, "grabinput", false); + AddDEF(configData, "gamma", 1); return configData; } diff --git a/src/gui/setup_visual.cpp b/src/gui/setup_visual.cpp index 9c172da04..5e072b53b 100644 --- a/src/gui/setup_visual.cpp +++ b/src/gui/setup_visual.cpp @@ -62,7 +62,7 @@ Setup_Visual::Setup_Visual() "", "grabinput", this, "grabinputEvent"); new SetupItemSlider(_("Gui opacity"), "", "guialpha", - this, "guialphaEvent", 0.1, 1.0); + this, "guialphaEvent", 0.1, 1.0, 150, true); mSpeachList = new SetupItemNames(); mSpeachList->push_back(_("No text")); @@ -89,7 +89,10 @@ Setup_Visual::Setup_Visual() mParticleList->push_back(_("max")); (new SetupItemSlider2(_("Particle detail"), "", "particleEmitterSkip", this, "particleEmitterSkipEvent", 0, 3, - mParticleList))->setInvertValue(3); + mParticleList, true))->setInvertValue(3); + + new SetupItemSlider(_("Gamma"), "", "gamma", + this, "gammeEvent", 1, 20, 350, true); setDimension(gcn::Rectangle(0, 0, 550, 350)); } @@ -107,28 +110,5 @@ Setup_Visual::~Setup_Visual() void Setup_Visual::apply() { SetupTabScroll::apply(); - Image::setEnableAlpha(config.getFloatValue("guialpha") != 1.0f); Client::applyGrabMode(); } - -void Setup_Visual::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "guialphaEvent") - { - Slider *slider = static_cast(event.getSource()); - if (slider) - { - config.setValue("guialpha", slider->getValue()); - Image::setEnableAlpha(config.getFloatValue("guialpha") != 1.0f); - } - } - else if (event.getId() == "particleEmitterSkipEvent") - { - Slider *slider = static_cast(event.getSource()); - if (slider) - { - int val = static_cast(slider->getValue()); - Particle::emitterSkip = 4 - val; - } - } -} diff --git a/src/gui/setup_visual.h b/src/gui/setup_visual.h index 60d8ac787..30ae18645 100644 --- a/src/gui/setup_visual.h +++ b/src/gui/setup_visual.h @@ -39,8 +39,6 @@ class Setup_Visual : public SetupTabScroll void apply(); - void action(const gcn::ActionEvent &event A_UNUSED); - private: SetupItemNames *mSpeachList; diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 581d9f239..490c046c3 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -597,13 +597,15 @@ void SetupItemDropDown::toWidget() SetupItemSlider::SetupItemSlider(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, double min, double max, - bool mainConfig) : + int width, bool onTheFly, bool mainConfig) : SetupItem(text, description, keyName, parent, eventName, mainConfig), mHorizont(nullptr), mLabel(nullptr), mSlider(nullptr), mMin(min), - mMax(max) + mMax(max), + mWidth(width), + mOnTheFly(onTheFly) { mValueType = VSTR; createControls(); @@ -612,13 +614,16 @@ SetupItemSlider::SetupItemSlider(std::string text, std::string description, SetupItemSlider::SetupItemSlider(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, double min, double max, - std::string def, bool mainConfig) : + std::string def, int width, bool onTheFly, + bool mainConfig) : SetupItem(text, description, keyName, parent, eventName, def, mainConfig), mHorizont(nullptr), mLabel(nullptr), mSlider(nullptr), mMin(min), - mMax(max) + mMax(max), + mWidth(width), + mOnTheFly(onTheFly) { mValueType = VSTR; createControls(); @@ -645,7 +650,7 @@ void SetupItemSlider::createControls() mSlider->setHeight(30); mWidget = mSlider; - mSlider->setWidth(150); + mSlider->setWidth(mWidth); mSlider->setHeight(40); mHorizont->add(mLabel); mHorizont->add(mSlider, -10); @@ -675,6 +680,8 @@ void SetupItemSlider::toWidget() void SetupItemSlider::action(const gcn::ActionEvent &event A_UNUSED) { fromWidget(); + if (mOnTheFly) + save(); } void SetupItemSlider::apply(std::string eventName) @@ -689,7 +696,8 @@ void SetupItemSlider::apply(std::string eventName) SetupItemSlider2::SetupItemSlider2(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, int min, int max, - SetupItemNames *values, bool mainConfig) : + SetupItemNames *values, bool onTheFly, + bool mainConfig) : SetupItem(text, description, keyName, parent, eventName, mainConfig), mHorizont(nullptr), mLabel(nullptr), @@ -699,7 +707,8 @@ SetupItemSlider2::SetupItemSlider2(std::string text, std::string description, mMin(min), mMax(max), mInvert(false), - mInvertValue(0) + mInvertValue(0), + mOnTheFly(onTheFly) { mValueType = VSTR; createControls(); @@ -709,7 +718,7 @@ SetupItemSlider2::SetupItemSlider2(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, int min, int max, SetupItemNames *values, std::string def, - bool mainConfig) : + bool onTheFly, bool mainConfig) : SetupItem(text, description, keyName, parent, eventName, def, mainConfig), mHorizont(nullptr), mLabel(nullptr), @@ -719,7 +728,8 @@ SetupItemSlider2::SetupItemSlider2(std::string text, std::string description, mMin(min), mMax(max), mInvert(false), - mInvertValue(0) + mInvertValue(0), + mOnTheFly(onTheFly) { mValueType = VSTR; createControls(); @@ -811,6 +821,8 @@ void SetupItemSlider2::action(const gcn::ActionEvent &event A_UNUSED) { fromWidget(); updateLabel(); + if (mOnTheFly) + save(); } void SetupItemSlider2::updateLabel() diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index cf847f55d..b950d1488 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -270,12 +270,14 @@ class SetupItemSlider : public SetupItem SetupItemSlider(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, double min, double max, + int width = 150, bool onTheFly = false, bool mainConfig = true); SetupItemSlider(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, double min, double max, - std::string def, bool mainConfig = true); + std::string def, int width = 150, + bool onTheFly = false, bool mainConfig = true); ~SetupItemSlider(); @@ -297,6 +299,8 @@ class SetupItemSlider : public SetupItem Slider *mSlider; double mMin; double mMax; + int mWidth; + bool mOnTheFly; }; typedef std::vector SetupItemNames; @@ -309,13 +313,14 @@ class SetupItemSlider2 : public SetupItem SetupItemSlider2(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, int min, int max, - SetupItemNames *values, bool mainConfig = true); + SetupItemNames *values, bool onTheFly = false, + bool mainConfig = true); SetupItemSlider2(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, std::string eventName, int min, int max, SetupItemNames *values, std::string def, - bool mainConfig = true); + bool onTheFly = false, bool mainConfig = true); ~SetupItemSlider2(); @@ -345,6 +350,7 @@ class SetupItemSlider2 : public SetupItem int mMax; bool mInvert; int mInvertValue; + bool mOnTheFly; }; #endif -- cgit v1.2.3-60-g2f50 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/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/defaults.cpp | 2 + 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 +++++++++++++++ 10 files changed, 265 insertions(+), 27 deletions(-) create mode 100644 src/gui/widgets/namesmodel.cpp create mode 100644 src/gui/widgets/namesmodel.h (limited to 'src/gui/widgets/setupitem.h') 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(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 From c85d939d9b3f6c10288dc86ffa7811408e349657 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 28 Feb 2012 02:14:15 +0300 Subject: Add different sound effects for different events. Can be configured in audio tab in settings. --- data/sfx/system/CMakeLists.txt | 16 ++++++++++++ data/sfx/system/Makefile.am | 18 +++++++++++++- data/sfx/system/attention.ogg | Bin 0 -> 10439 bytes data/sfx/system/chat1.ogg | Bin 0 -> 8270 bytes data/sfx/system/chat2.ogg | Bin 0 -> 6341 bytes data/sfx/system/complete.ogg | Bin 0 -> 13971 bytes data/sfx/system/email.ogg | Bin 0 -> 21002 bytes data/sfx/system/error.ogg | Bin 0 -> 7192 bytes data/sfx/system/finish.ogg | Bin 0 -> 12576 bytes data/sfx/system/incoming.ogg | Bin 0 -> 15903 bytes data/sfx/system/move.ogg | Bin 0 -> 6443 bytes data/sfx/system/notify.ogg | Bin 0 -> 9485 bytes data/sfx/system/offline.ogg | Bin 0 -> 7119 bytes data/sfx/system/online.ogg | Bin 0 -> 7883 bytes data/sfx/system/reminder.ogg | Bin 0 -> 7279 bytes data/sfx/system/send.ogg | Bin 0 -> 8205 bytes data/sfx/system/start.ogg | Bin 0 -> 8597 bytes data/sfx/system/watcher.ogg | Bin 0 -> 8919 bytes src/client.cpp | 15 +++++++----- src/defaults.cpp | 7 ++++++ src/game.cpp | 6 ++--- src/gui/changeemaildialog.cpp | 3 ++- src/gui/changepassworddialog.cpp | 3 ++- src/gui/charcreatedialog.cpp | 4 +-- src/gui/charselectdialog.cpp | 2 +- src/gui/confirmdialog.cpp | 2 +- src/gui/editserverdialog.cpp | 2 +- src/gui/okdialog.cpp | 10 +++++++- src/gui/okdialog.h | 11 +++++++-- src/gui/register.cpp | 2 +- src/gui/setup_audio.cpp | 50 ++++++++++++++++++++++++++++++++++++++ src/gui/setup_audio.h | 5 ++++ src/gui/setup_keyboard.cpp | 2 +- src/gui/setup_theme.cpp | 4 +-- src/gui/setup_video.cpp | 16 +++++++----- src/gui/shopwindow.cpp | 2 +- src/gui/socialwindow.cpp | 6 ++--- src/gui/unregisterdialog.cpp | 3 ++- src/gui/widgets/chattab.cpp | 2 +- src/gui/widgets/setupitem.cpp | 40 ++++++++++++++++++++++++++++-- src/gui/widgets/setupitem.h | 21 +++++++++++++++- src/gui/widgets/sliderlist.h | 3 +++ src/localplayer.cpp | 5 ++-- src/net/ea/charserverhandler.cpp | 4 +-- src/net/ea/gamehandler.cpp | 2 +- src/net/ea/playerhandler.cpp | 7 +++--- src/net/manaserv/beinghandler.cpp | 3 ++- src/net/manaserv/charhandler.cpp | 4 +-- src/sound.cpp | 6 +++++ src/sound.h | 2 ++ 50 files changed, 237 insertions(+), 51 deletions(-) create mode 100644 data/sfx/system/attention.ogg create mode 100644 data/sfx/system/chat1.ogg create mode 100644 data/sfx/system/chat2.ogg create mode 100644 data/sfx/system/complete.ogg create mode 100644 data/sfx/system/email.ogg create mode 100644 data/sfx/system/error.ogg create mode 100644 data/sfx/system/finish.ogg create mode 100644 data/sfx/system/incoming.ogg create mode 100644 data/sfx/system/move.ogg create mode 100644 data/sfx/system/notify.ogg create mode 100644 data/sfx/system/offline.ogg create mode 100644 data/sfx/system/online.ogg create mode 100644 data/sfx/system/reminder.ogg create mode 100644 data/sfx/system/send.ogg create mode 100644 data/sfx/system/start.ogg create mode 100644 data/sfx/system/watcher.ogg (limited to 'src/gui/widgets/setupitem.h') diff --git a/data/sfx/system/CMakeLists.txt b/data/sfx/system/CMakeLists.txt index bf6f0f0f3..0fa325a45 100644 --- a/data/sfx/system/CMakeLists.txt +++ b/data/sfx/system/CMakeLists.txt @@ -1,5 +1,21 @@ SET (FILES + attention.ogg + chat1.ogg + chat2.ogg + complete.ogg + email.ogg + error.ogg + finish.ogg + incoming.ogg + move.ogg + notify.ogg newmessage.ogg + offline.ogg + online.ogg + reminder.ogg + send.ogg + start.ogg + watcher.ogg ) INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/sfx/system) diff --git a/data/sfx/system/Makefile.am b/data/sfx/system/Makefile.am index e744932c3..d46934461 100644 --- a/data/sfx/system/Makefile.am +++ b/data/sfx/system/Makefile.am @@ -1,7 +1,23 @@ systemdir = $(pkgdatadir)/data/sfx/system system_DATA = \ - newmessage.ogg + attention.ogg \ + chat1.ogg \ + chat2.ogg \ + complete.ogg \ + email.ogg \ + error.ogg \ + finish.ogg \ + incoming.ogg \ + move.ogg \ + newmessage.ogg \ + notify.ogg \ + offline.ogg \ + online.ogg \ + reminder.ogg \ + send.ogg \ + start.ogg \ + watcher.ogg EXTRA_DIST = \ $(system_DATA) \ diff --git a/data/sfx/system/attention.ogg b/data/sfx/system/attention.ogg new file mode 100644 index 000000000..929265775 Binary files /dev/null and b/data/sfx/system/attention.ogg differ diff --git a/data/sfx/system/chat1.ogg b/data/sfx/system/chat1.ogg new file mode 100644 index 000000000..ad6c52a1d Binary files /dev/null and b/data/sfx/system/chat1.ogg differ diff --git a/data/sfx/system/chat2.ogg b/data/sfx/system/chat2.ogg new file mode 100644 index 000000000..155b15e1f Binary files /dev/null and b/data/sfx/system/chat2.ogg differ diff --git a/data/sfx/system/complete.ogg b/data/sfx/system/complete.ogg new file mode 100644 index 000000000..0975ff7c8 Binary files /dev/null and b/data/sfx/system/complete.ogg differ diff --git a/data/sfx/system/email.ogg b/data/sfx/system/email.ogg new file mode 100644 index 000000000..afb25909f Binary files /dev/null and b/data/sfx/system/email.ogg differ diff --git a/data/sfx/system/error.ogg b/data/sfx/system/error.ogg new file mode 100644 index 000000000..69dccfe7c Binary files /dev/null and b/data/sfx/system/error.ogg differ diff --git a/data/sfx/system/finish.ogg b/data/sfx/system/finish.ogg new file mode 100644 index 000000000..d8dbbf80f Binary files /dev/null and b/data/sfx/system/finish.ogg differ diff --git a/data/sfx/system/incoming.ogg b/data/sfx/system/incoming.ogg new file mode 100644 index 000000000..a8ff86676 Binary files /dev/null and b/data/sfx/system/incoming.ogg differ diff --git a/data/sfx/system/move.ogg b/data/sfx/system/move.ogg new file mode 100644 index 000000000..e5c703bbf Binary files /dev/null and b/data/sfx/system/move.ogg differ diff --git a/data/sfx/system/notify.ogg b/data/sfx/system/notify.ogg new file mode 100644 index 000000000..95d8fed4a Binary files /dev/null and b/data/sfx/system/notify.ogg differ diff --git a/data/sfx/system/offline.ogg b/data/sfx/system/offline.ogg new file mode 100644 index 000000000..cc1b8e938 Binary files /dev/null and b/data/sfx/system/offline.ogg differ diff --git a/data/sfx/system/online.ogg b/data/sfx/system/online.ogg new file mode 100644 index 000000000..3e55793fd Binary files /dev/null and b/data/sfx/system/online.ogg differ diff --git a/data/sfx/system/reminder.ogg b/data/sfx/system/reminder.ogg new file mode 100644 index 000000000..d7beeed6f Binary files /dev/null and b/data/sfx/system/reminder.ogg differ diff --git a/data/sfx/system/send.ogg b/data/sfx/system/send.ogg new file mode 100644 index 000000000..b5941323d Binary files /dev/null and b/data/sfx/system/send.ogg differ diff --git a/data/sfx/system/start.ogg b/data/sfx/system/start.ogg new file mode 100644 index 000000000..0b1f85643 Binary files /dev/null and b/data/sfx/system/start.ogg differ diff --git a/data/sfx/system/watcher.ogg b/data/sfx/system/watcher.ogg new file mode 100644 index 000000000..9a0dd1af2 Binary files /dev/null and b/data/sfx/system/watcher.ogg differ diff --git a/src/client.cpp b/src/client.cpp index 978c58eef..5f79176c7 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1327,14 +1327,16 @@ int Client::gameExec() case STATE_LOGIN_ERROR: logger->log1("State: LOGIN ERROR"); - mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog = new OkDialog(_("Error"), + errorMessage, DIALOG_ERROR); mCurrentDialog->addActionListener(&loginListener); mCurrentDialog = nullptr; // OkDialog deletes itself break; case STATE_ACCOUNTCHANGE_ERROR: logger->log1("State: ACCOUNT CHANGE ERROR"); - mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog = new OkDialog(_("Error"), + errorMessage, DIALOG_ERROR); mCurrentDialog->addActionListener(&accountListener); mCurrentDialog = nullptr; // OkDialog deletes itself break; @@ -1370,7 +1372,7 @@ int Client::gameExec() case STATE_CHANGEPASSWORD_SUCCESS: logger->log1("State: CHANGE PASSWORD SUCCESS"); mCurrentDialog = new OkDialog(_("Password Change"), - _("Password changed successfully!")); + _("Password changed successfully!"), DIALOG_ERROR); mCurrentDialog->addActionListener(&accountListener); mCurrentDialog = nullptr; // OkDialog deletes itself loginData.password = loginData.newPassword; @@ -1390,7 +1392,7 @@ int Client::gameExec() case STATE_CHANGEEMAIL_SUCCESS: logger->log1("State: CHANGE EMAIL SUCCESS"); mCurrentDialog = new OkDialog(_("Email Change"), - _("Email changed successfully!")); + _("Email changed successfully!"), DIALOG_ERROR); mCurrentDialog->addActionListener(&accountListener); mCurrentDialog = nullptr; // OkDialog deletes itself break; @@ -1411,7 +1413,7 @@ int Client::gameExec() Net::getLoginHandler()->disconnect(); mCurrentDialog = new OkDialog(_("Unregister Successful"), - _("Farewell, come back any time...")); + _("Farewell, come back any time..."), DIALOG_ERROR); loginData.clear(); //The errorlistener sets the state to STATE_CHOOSE_SERVER mCurrentDialog->addActionListener(&errorListener); @@ -1468,7 +1470,8 @@ int Client::gameExec() case STATE_ERROR: logger->log1("State: ERROR"); logger->log("Error: %s\n", errorMessage.c_str()); - mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog = new OkDialog(_("Error"), + errorMessage, DIALOG_ERROR); mCurrentDialog->addActionListener(&errorListener); mCurrentDialog = nullptr; // OkDialog deletes itself Net::getGameHandler()->disconnect(); diff --git a/src/defaults.cpp b/src/defaults.cpp index 01907bfe8..cd2911192 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -229,6 +229,13 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "grabinput", false); AddDEF(configData, "gamma", 1); AddDEF(configData, "vsync", 0); + AddDEF(configData, "soundwhisper", "newmessage"); + AddDEF(configData, "soundhighlight", "reminder"); + AddDEF(configData, "soundglobal", "email"); + AddDEF(configData, "sounderror", "error"); + AddDEF(configData, "soundtrade", "start"); + AddDEF(configData, "soundinfo", "notify"); + AddDEF(configData, "soundrequest", "attention"); return configData; } diff --git a/src/game.cpp b/src/game.cpp index e016d02ff..ae8682972 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -561,7 +561,7 @@ void Game::logic() { errorMessage = _("The connection to the server was lost."); disconnectedDialog = new OkDialog(_("Network Error"), - errorMessage, false); + errorMessage, DIALOG_ERROR, false); disconnectedDialog->addActionListener(&errorListener); disconnectedDialog->requestMoveToTop(); } @@ -1796,8 +1796,8 @@ void Game::changeMap(const std::string &mapPath) if (!newMap) { logger->log("Error while loading %s", fullMap.c_str()); - new OkDialog(_("Could Not Load Map"), - strprintf(_("Error while loading %s"), fullMap.c_str())); + new OkDialog(_("Could Not Load Map"), strprintf( + _("Error while loading %s"), fullMap.c_str()), DIALOG_ERROR); } if (mCurrentMap) diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index 518ed3da1..1a468d44f 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -154,7 +154,8 @@ void ChangeEmailDialog::action(const gcn::ActionEvent &event) else if (error == 2) mWrongDataNoticeListener->setTarget(this->mSecondEmailField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); if (dlg) dlg->addActionListener(mWrongDataNoticeListener); } diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 8082b8d58..a58d8616b 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -144,7 +144,8 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event) else if (error == 3) mWrongDataNoticeListener->setTarget(this->mSecondPassField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 9f7436ad8..124476f1c 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -270,8 +270,8 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) else { new OkDialog(_("Error"), - _("Your name needs to be at least 4 characters."), - true, this); + _("Your name needs to be at least 4 characters."), + DIALOG_ERROR, true, this); } } else if (id == "cancel") diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index d2b74a632..b1b8009a4 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -253,7 +253,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) } else { - new OkDialog(_("Error"), _("Incorrect password")); + new OkDialog(_("Error"), _("Incorrect password"), DIALOG_ERROR); } mDeleteIndex = -1; } diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp index 22acf5116..b6645db3c 100644 --- a/src/gui/confirmdialog.cpp +++ b/src/gui/confirmdialog.cpp @@ -97,7 +97,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, } setVisible(true); yesButton->requestFocus(); - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundrequest"); } void ConfirmDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/editserverdialog.cpp b/src/gui/editserverdialog.cpp index 53e31c3c8..ca1afeaba 100644 --- a/src/gui/editserverdialog.cpp +++ b/src/gui/editserverdialog.cpp @@ -173,7 +173,7 @@ void EditServerDialog::action(const gcn::ActionEvent &event) { OkDialog *dlg = new OkDialog(_("Error"), _("Please at least type both the address and the port " - "of the server.")); + "of the server."), DIALOG_ERROR); dlg->addActionListener(this); } else diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp index 4a3bdf731..fe22cf008 100644 --- a/src/gui/okdialog.cpp +++ b/src/gui/okdialog.cpp @@ -22,6 +22,8 @@ #include "gui/okdialog.h" +#include "sound.h" + #include "gui/gui.h" #include "gui/widgets/button.h" @@ -34,7 +36,8 @@ #include "debug.h" OkDialog::OkDialog(const std::string &title, const std::string &msg, - bool modal, bool showCenter, Window *parent): + int soundEvent, bool modal, bool showCenter, + Window *parent): Window(title, modal, parent, "ok.xml") { mTextBox = new TextBox; @@ -71,6 +74,11 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, centerHorisontally(); setVisible(true); okButton->requestFocus(); + + if (soundEvent == DIALOG_OK) + sound.playGuiSound("soundinfo"); + else if (soundEvent == DIALOG_ERROR) + sound.playGuiSound("sounderror"); } void OkDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/okdialog.h b/src/gui/okdialog.h index 5705be568..b6f17480b 100644 --- a/src/gui/okdialog.h +++ b/src/gui/okdialog.h @@ -31,6 +31,13 @@ class TextBox; +enum +{ + DIALOG_OK = 0, + DIALOG_ERROR, + DIALOG_SILENCE +}; + /** * An 'Ok' button dialog. * @@ -45,8 +52,8 @@ class OkDialog : public Window, public gcn::ActionListener * @see Window::Window */ OkDialog(const std::string &title, const std::string &msg, - bool modal = true, bool showCenter = true, - Window *parent = nullptr); + int soundEvent = DIALOG_OK, bool modal = true, + bool showCenter = true, Window *parent = nullptr); /** * Called when receiving actions from the widgets. diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 2122e0d6b..bf0cb299e 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -225,7 +225,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event) mWrongDataNoticeListener->setTarget(this->mPasswordField); } - OkDialog *dlg = new OkDialog(_("Error"), errorMsg); + OkDialog *dlg = new OkDialog(_("Error"), errorMsg, DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 1f7db484c..a4c3110d9 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -25,9 +25,11 @@ #include "configuration.h" #include "sound.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/layouthelper.h" +#include "gui/widgets/namesmodel.h" #include "gui/widgets/scrollarea.h" #include "gui/widgets/setupitem.h" @@ -35,6 +37,19 @@ #include "debug.h" +class SoundsModel : public NamesModel +{ +public: + SoundsModel() + { + mNames.push_back(gettext("(no sound)")); + Theme::fillSoundsList(mNames); + } + + virtual ~SoundsModel() + { } +}; + Setup_Audio::Setup_Audio() { setName(_("Audio")); @@ -44,6 +59,10 @@ Setup_Audio::Setup_Audio() ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mScroll, 10, 10); + mSoundModel = new SoundsModel(); + + new SetupItemLabel(_("Basic settings"), "", this); + new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent"); new SetupItemCheckBox(_("Enable music"), "", @@ -61,6 +80,31 @@ Setup_Audio::Setup_Audio() new SetupItemSlider(_("Music volume"), "", "musicVolume", this, "musicVolumeEvent", 0, sound.getMaxVolume(), 150, true); + new SetupItemLabel(_("Sound effects"), "", this); + + new SetupItemSound(_("Information dialog sound"), "", + "soundinfo", this, "soundinfoEvent", mSoundModel); + + new SetupItemSound(_("Request dialog sound"), "", + "soundrequest", this, "soundrequestEvent", mSoundModel); + + new SetupItemSound(_("Whisper message sound"), "", + "soundwhisper", this, "soundwhisperEvent", mSoundModel); + + new SetupItemSound(_("Highlight message sound"), "", + "soundhighlight", this, "soundhighlightEvent", mSoundModel); + + new SetupItemSound(_("Global message sound"), "", + "soundglobal", this, "soundglobalEvent", mSoundModel); + + new SetupItemSound(_("Error message sound"), "", + "sounderror", this, "sounderrorEvent", mSoundModel); + + new SetupItemSound(_("Trade request sound"), "", + "soundtrade", this, "soundtradeEvent", mSoundModel); + + new SetupItemLabel(_("Other"), "", this); + new SetupItemCheckBox(_("Enable mumble voice chat"), "", "enableMumble", this, "enableMumbleEvent"); @@ -70,6 +114,12 @@ Setup_Audio::Setup_Audio() setDimension(gcn::Rectangle(0, 0, 550, 350)); } +Setup_Audio::~Setup_Audio() +{ + delete mSoundModel; + mSoundModel = nullptr; +} + void Setup_Audio::apply() { SetupTabScroll::apply(); diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h index c08c49c7a..21b661bcb 100644 --- a/src/gui/setup_audio.h +++ b/src/gui/setup_audio.h @@ -34,7 +34,12 @@ class Setup_Audio : public SetupTabScroll public: Setup_Audio(); + ~Setup_Audio(); + void apply(); + + private: + gcn::ListModel *mSoundModel; }; #endif diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index bdd7c2083..ef024c5d9 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -131,7 +131,7 @@ void Setup_Keyboard::apply() if (keyboard.hasConflicts()) { new OkDialog(_("Key Conflict(s) Detected."), - keyboard.getBindError()); + keyboard.getBindError(), DIALOG_ERROR); } keyboard.setEnabled(true); keyboard.store(); diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index d3b9d0e3c..7386f496a 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -349,8 +349,8 @@ void Setup_Theme::apply() if (config.getValue("theme", config.getValue("selectedSkin", "")) != mTheme) { - new OkDialog(_("Theme Changed"), - _("Restart your client for the change to take effect.")); + new OkDialog(_("Theme Changed"), _("Restart your client for " + "the change to take effect.")); } config.setValue("selectedSkin", ""); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 6690f1452..24d42c83d 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -393,7 +393,7 @@ void Setup_Video::apply() else { new OkDialog(_("Switching to Full Screen"), - _("Restart needed for changes to take effect.")); + _("Restart needed for changes to take effect.")); } #endif config.setValue("screen", fullscreen); @@ -406,7 +406,7 @@ void Setup_Video::apply() // OpenGL can currently only be changed by restarting, notify user. new OkDialog(_("Changing to OpenGL"), - _("Applying change to OpenGL requires restart.")); + _("Applying change to OpenGL requires restart.")); } mFps = mFpsCheckBox->isSelected() ? @@ -498,13 +498,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) { #if defined(_WIN32) if (width < mainGraphics->mWidth || height < mainGraphics->mHeight) + { new OkDialog(_("Screen Resolution Changed"), - _("Restart your client for the change to take effect.") - + std::string("\n") + - _("Some windows may be moved to fit the lowered resolution.")); + _("Restart your client for the change to take effect.") + + std::string("\n") + _("Some windows may be moved to " + "fit the lowered resolution.")); + } else + { new OkDialog(_("Screen Resolution Changed"), - _("Restart your client for the change to take effect.")); + _("Restart your client for the change to take effect.")); + } #else Client::resize(width, height); #endif diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 1a27b8b0c..33ab32ca5 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -753,7 +753,7 @@ void ShopWindow::processRequest(std::string nick, std::string data, int mode) if (config.getBoolValue("autoShop")) { - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundtrade"); startTrade(); } else diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 287089790..f0ac9e128 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1630,13 +1630,13 @@ void SocialWindow::showPartyCreate() if (player_node->getParty()) { new OkDialog(_("Create Party"), - _("Cannot create party. You are already in a party"), - this); + _("Cannot create party. You are already in a party"), + DIALOG_ERROR, true, true, this); return; } mPartyCreateDialog = new TextDialog(_("Party Name"), - _("Choose your party's name."), this); + _("Choose your party's name."), this); mPartyCreateDialog->setActionEventId("create party"); mPartyCreateDialog->addActionListener(this); } diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index ca21263f1..9ba895ec8 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -134,7 +134,8 @@ void UnRegisterDialog::action(const gcn::ActionEvent &event) { mWrongDataNoticeListener->setTarget(this->mPasswordField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 018e35030..53842e887 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -301,7 +301,7 @@ void ChatTab::chatLog(std::string line, Own own, && !Client::getInputFocused())))) { if (own != BY_SERVER) - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundwhisper"); } } } diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 581002a58..9eedfd58d 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -23,6 +23,7 @@ #include "configuration.h" #include "main.h" #include "logger.h" +#include "sound.h" #include "gui/editdialog.h" #include "gui/gui.h" @@ -872,7 +873,7 @@ SetupItemSliderList::SetupItemSliderList(std::string text, mOnTheFly(onTheFly) { mValueType = VSTR; - createControls(); +// createControls(); } SetupItemSliderList::SetupItemSliderList(std::string text, @@ -892,7 +893,7 @@ SetupItemSliderList::SetupItemSliderList(std::string text, mOnTheFly(onTheFly) { mValueType = VSTR; - createControls(); +// createControls(); } SetupItemSliderList::~SetupItemSliderList() @@ -917,6 +918,8 @@ void SetupItemSliderList::createControls() mHorizont->add(mLabel, 5); mHorizont->add(mSlider); + addMoreControls(); + mParent->getContainer()->add2(mHorizont, true, 4); mParent->addControl(this); mParent->addActionListener(this); @@ -954,3 +957,36 @@ void SetupItemSliderList::apply(std::string eventName) fromWidget(); save(); } + +SetupItemSound::SetupItemSound(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + int width, bool onTheFly, bool mainConfig) : + SetupItemSliderList(text, description, keyName, parent, eventName, + model, width, onTheFly, mainConfig), + mButton(nullptr) +{ + createControls(); +} + +void SetupItemSound::addMoreControls() +{ + mButton = new Button(_("Play"), mEventName + "_PLAY", this); + mHorizont->add(mButton); +} + +void SetupItemSound::action(const gcn::ActionEvent &event) +{ + if (event.getId() == mEventName + "_PLAY") + { + if (mSlider->getSelected()) + { + sound.playGuiSfx(branding.getStringValue("systemsounds") + + mSlider->getSelectedString() + ".ogg"); + } + } + else + { + SetupItemSliderList::action(event); + } +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index f883a5b94..38dec929e 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -377,10 +377,12 @@ class SetupItemSliderList : public SetupItem void toWidget(); - void action(const gcn::ActionEvent &event); + virtual void action(const gcn::ActionEvent &event); void apply(std::string eventName); + virtual void addMoreControls() = 0; + protected: HorizontContainer *mHorizont; Label *mLabel; @@ -390,4 +392,21 @@ class SetupItemSliderList : public SetupItem bool mOnTheFly; }; +class SetupItemSound : public SetupItemSliderList +{ + public: + SetupItemSound(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); + + void action(const gcn::ActionEvent &event); + + void addMoreControls(); + + protected: + Button *mButton; +}; + #endif diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h index a7b1a564c..b2239834d 100644 --- a/src/gui/widgets/sliderlist.h +++ b/src/gui/widgets/sliderlist.h @@ -63,6 +63,9 @@ class SliderList : public Container, void adjustSize(); + int getSelected() + { return mSelectedIndex; } + protected: void updateLabel(); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5114f868c..de1304240 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -2204,7 +2204,8 @@ void LocalPlayer::changeAwayMode() if (outfitWindow) outfitWindow->wearAwayOutfit(); mAwayDialog = new OkDialog(_("Away"), - config.getStringValue("afkMessage"), true, false); + config.getStringValue("afkMessage"), + DIALOG_SILENCE, true, false); mAwayDialog->addActionListener(mAwayListener); sound.volumeOff(); } @@ -4147,7 +4148,7 @@ void LocalPlayer::checkNewName(Being *being) if (!mWaitFor.empty() && mWaitFor == nick) { debugMsg(_("You see ") + mWaitFor); - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundinfo"); mWaitFor = ""; } } diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index 2dc51acf3..67894b0d9 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -167,7 +167,7 @@ void CharServerHandler::processCharCreateFailed(Net::MessageIn &msg) errorMessage = _("Incorrect race."); break; } - new OkDialog(_("Error"), errorMessage); + new OkDialog(_("Error"), errorMessage, DIALOG_ERROR); if (mCharCreateDialog) mCharCreateDialog->unlock(); } @@ -185,7 +185,7 @@ void CharServerHandler::processCharDelete(Net::MessageIn &msg A_UNUSED) void CharServerHandler::processCharDeleteFailed(Net::MessageIn &msg A_UNUSED) { unlockCharSelectDialog(); - new OkDialog(_("Error"), _("Failed to delete character.")); + new OkDialog(_("Error"), _("Failed to delete character."), DIALOG_ERROR); } void CharServerHandler::clear() diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index 6d021d6a9..c8c870dbd 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -101,7 +101,7 @@ void GameHandler::processCharSwitchResponse(Net::MessageIn &msg) void GameHandler::processMapQuitResponse(Net::MessageIn &msg) { if (msg.readInt8()) - new OkDialog(_("Game"), _("Request to quit denied!"), nullptr); + new OkDialog(_("Game"), _("Request to quit denied!"), DIALOG_ERROR); } } // namespace Ea diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 27aa4da80..ddcf7d9c0 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -336,7 +336,7 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) weightNotice = new OkDialog(_("Message"), _("You are carrying more than " "half your weight. You are " - "unable to regain health."), false); + "unable to regain health."), DIALOG_ERROR, false); weightNotice->addActionListener( &weightListener); } @@ -346,7 +346,7 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) weightNotice = new OkDialog(_("Message"), _("You are carrying less than " "half your weight. You " - "can regain health."), false); + "can regain health."), DIALOG_ERROR, false); weightNotice->addActionListener( &weightListener); } @@ -426,8 +426,7 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) if (PlayerInfo::getAttribute(HP) == 0 && !deathNotice) { deathNotice = new OkDialog(_("Message"), - randomDeathMessage(), - false); + randomDeathMessage(), false); deathNotice->addActionListener(&deathListener); player_node->setAction(Being::DEAD); } diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index cef4f497a..9468baaa1 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -335,7 +335,8 @@ void BeingHandler::handleBeingActionChangeMessage(Net::MessageIn &msg) }; std::string message(deadMsg[rand() % 13]); message.append(std::string(" ") + _("Press OK to respawn.")); - OkDialog *dlg = new OkDialog(_("You Died"), message, false); + OkDialog *dlg = new OkDialog(_("You Died"), + message, DIALOG_OK, false); dlg->addActionListener(&(ManaServ::respawnListener)); } } diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index 300af5a2b..7977df909 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -181,7 +181,7 @@ void CharHandler::handleCharacterCreateResponse(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - new OkDialog(_("Error"), errorMessage); + new OkDialog(_("Error"), errorMessage, DIALOG_ERROR); if (mCharCreateDialog) mCharCreateDialog->unlock(); @@ -224,7 +224,7 @@ void CharHandler::handleCharacterDeleteResponse(Net::MessageIn &msg) default: errorMessage = strprintf(_("Unknown error (%d)."), errMsg); } - new OkDialog(_("Error"), errorMessage); + new OkDialog(_("Error"), errorMessage, DIALOG_ERROR); } mSelectedCharacter = 0; unlockCharSelectDialog(); diff --git a/src/sound.cpp b/src/sound.cpp index 25b37d578..2c7ecb53d 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -325,6 +325,12 @@ void Sound::playSfx(const std::string &path, int x, int y) } } +void Sound::playGuiSound(const std::string &name) +{ + playGuiSfx(branding.getStringValue("systemsounds") + + config.getStringValue(name) + ".ogg"); +} + void Sound::playGuiSfx(const std::string &path) { if (!mInstalled || path.empty() || !mPlayGui) diff --git a/src/sound.h b/src/sound.h index 7f9fb64a4..cfa847a0b 100644 --- a/src/sound.h +++ b/src/sound.h @@ -109,6 +109,8 @@ class Sound : public ConfigListener */ void playGuiSfx(const std::string &path); + void playGuiSound(const std::string &name); + void changeAudio(); void volumeOff(); -- cgit v1.2.3-60-g2f50 From 16a5f224128acde7343c53c636ff53e7983ef754 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 28 Feb 2012 22:33:42 +0300 Subject: Adjust label size in setupitem controls. --- src/gui/setup_visual.cpp | 2 ++ src/gui/widgets/setupitem.cpp | 12 ++++++++++++ src/gui/widgets/setupitem.h | 2 ++ src/gui/widgets/setuptabscroll.cpp | 7 ++----- src/gui/widgets/setuptabscroll.h | 4 ++++ 5 files changed, 22 insertions(+), 5 deletions(-) (limited to 'src/gui/widgets/setupitem.h') diff --git a/src/gui/setup_visual.cpp b/src/gui/setup_visual.cpp index f7a083498..55e219bd7 100644 --- a/src/gui/setup_visual.cpp +++ b/src/gui/setup_visual.cpp @@ -39,6 +39,8 @@ Setup_Visual::Setup_Visual() ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mScroll, 10, 10); + mPreferredFirstItemSize = 150; + new SetupItemCheckBox(_("Show pickup notifications in chat"), "", "showpickupchat", this, "showpickupchatEvent"); diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index b3a018813..93854e823 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -171,6 +171,12 @@ void SetupItem::externalUpdated(std::string eventName A_UNUSED) toWidget(); } +void SetupItem::fixFirstItemSize(gcn::Widget *widget) +{ + if (widget->getWidth() < mParent->getPreferredFirstItemSize()) + widget->setWidth(mParent->getPreferredFirstItemSize()); +} + SetupItemCheckBox::SetupItemCheckBox(std::string text, std::string description, std::string keyName, SetupTabScroll *parent, @@ -279,6 +285,7 @@ void SetupItemTextField::createControls() mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); mWidget = mTextField; mTextField->setWidth(200); + fixFirstItemSize(mLabel); mHorizont->add(mLabel); mHorizont->add(mTextField); mHorizont->add(mButton); @@ -402,6 +409,7 @@ void SetupItemIntTextField::createControls() mButton = new Button(_("Edit"), mEventName + "_EDIT", mParent); mWidget = mTextField; mTextField->setWidth(50); + fixFirstItemSize(mLabel); mHorizont->add(mLabel); mHorizont->add(mTextField); mHorizont->add(mButton); @@ -572,6 +580,7 @@ void SetupItemDropDown::createControls() mWidget = mDropDown; // mTextField->setWidth(50); + fixFirstItemSize(mLabel); mHorizont->add(mLabel); mHorizont->add(mDropDown); @@ -656,6 +665,7 @@ void SetupItemSlider::createControls() mWidget = mSlider; mSlider->setWidth(mWidth); mSlider->setHeight(40); + fixFirstItemSize(mLabel); mHorizont->add(mLabel); mHorizont->add(mSlider, -10); @@ -767,6 +777,7 @@ void SetupItemSlider2::createControls() mWidget = mSlider; mSlider->setWidth(150); mSlider->setHeight(40); + fixFirstItemSize(mLabel); mHorizont->add(mLabel); mHorizont->add(mSlider, -10); mHorizont->add(mLabel2); @@ -917,6 +928,7 @@ void SetupItemSliderList::createControls() mSlider->adjustSize(); mWidget = mSlider; + fixFirstItemSize(mLabel); mHorizont->add(mLabel, 5); mHorizont->add(mSlider); diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index 38dec929e..86fdf95f9 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -97,6 +97,8 @@ class SetupItem : public gcn::ActionListener bool isMainConfig() const { return mMainConfig; } + void fixFirstItemSize(gcn::Widget *widget); + protected: std::string mText; diff --git a/src/gui/widgets/setuptabscroll.cpp b/src/gui/widgets/setuptabscroll.cpp index 34cc993a9..f3f8b1526 100644 --- a/src/gui/widgets/setuptabscroll.cpp +++ b/src/gui/widgets/setuptabscroll.cpp @@ -28,17 +28,14 @@ #include "debug.h" SetupTabScroll::SetupTabScroll() : - SetupTab() + SetupTab(), + mPreferredFirstItemSize(200) { mContainer = new VertContainer(25, false, 8); mScroll = new ScrollArea(mContainer); mScroll->setOpaque(false); mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO); - -// LayoutHelper h(this); -// ContainerPlacer place = h.getPlacer(0, 0); -// place(0, 0, mScroll, 10, 10); } SetupTabScroll::~SetupTabScroll() diff --git a/src/gui/widgets/setuptabscroll.h b/src/gui/widgets/setuptabscroll.h index d471ecfbc..e7151769e 100644 --- a/src/gui/widgets/setuptabscroll.h +++ b/src/gui/widgets/setuptabscroll.h @@ -55,11 +55,15 @@ class SetupTabScroll : public SetupTab virtual void action(const gcn::ActionEvent &event A_UNUSED) { } + int getPreferredFirstItemSize() + { return mPreferredFirstItemSize; } + protected: VertContainer *mContainer; ScrollArea *mScroll; std::map mItems; std::set mAllItems; + int mPreferredFirstItemSize; }; #endif -- cgit v1.2.3-60-g2f50