Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Makefile.am2
-rw-r--r--src/client/audiosettingsmenu.cc217
-rw-r--r--src/client/audiosettingsmenu.h85
-rw-r--r--src/client/mainmenu.cc8
4 files changed, 310 insertions, 2 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 743a9c6..8e0124f 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -10,6 +10,7 @@ endif
noinst_HEADERS = \
action.h \
+ audiosettingsmenu.h \
buttonmenu.h \
buymenu.h \
chat.h \
@@ -49,6 +50,7 @@ noinst_HEADERS = \
libclient_la_SOURCES = \
action.cc \
+ audiosettingsmenu.cc \
buttonmenu.cc \
buymenu.cc \
chat.cc \
diff --git a/src/client/audiosettingsmenu.cc b/src/client/audiosettingsmenu.cc
new file mode 100644
index 0000000..d247cbe
--- /dev/null
+++ b/src/client/audiosettingsmenu.cc
@@ -0,0 +1,217 @@
+/*
+ client/audiosettingsmenu.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "client/audiosettingsmenu.h"
+#include "core/cvar.h"
+#include "ui/button.h"
+#include "ui/slider.h"
+#include "ui/iconbutton.h"
+#include "ui/inputbox.h"
+#include "ui/label.h"
+#include "ui/ui.h"
+#include "math/functions.h"
+
+#include <iostream>
+
+namespace client {
+
+AudioSettingsMenu::AudioSettingsMenu(ui::Widget *parent, const char *label) : ui::Window(parent)
+{
+ set_label(label);
+ set_border(true);
+ set_background(true);
+ set_font(ui::root()->font_small());
+
+ // window title
+ _titlelabel = new ui::Label(this);
+ _titlelabel->set_label("title");
+ _titlelabel->set_background(false);
+ _titlelabel->set_border(false);
+ _titlelabel->set_font(ui::root()->font_large());
+ _titlelabel->set_alignment(ui::AlignCenter);
+ _titlelabel->set_text("AUDIO SETTINGS");
+
+ // close button
+ _closebutton = new ui::IconButton(_titlelabel, "bitmaps/icons/window_close");
+
+ // content frame
+ _frame = new ui::Widget(this);
+ _frame->set_label("frame");
+ _frame->set_background(true);
+ _frame->set_border(true);
+ _frame->set_focus();
+
+ // master volume
+ _mastervolumelabel = new ui::Label(_frame);
+ _mastervolumelabel->set_label("snd_volume");
+ _mastervolumelabel->set_background(false);
+ _mastervolumelabel->set_border(false);
+ _mastervolumelabel->set_text("Master volume");
+
+ _mastervolumeslider = new ui::Slider(_frame);
+ _mastervolumeslider->set_background(false);
+ _mastervolumeslider->set_border(true);
+ _mastervolumeslider->set_range(0.0f, 100.0f);
+
+ // engine volume
+ _enginevolumelabel = new ui::Label(_frame);
+ _enginevolumelabel->set_label("snd_engines");
+ _enginevolumelabel->set_background(false);
+ _enginevolumelabel->set_border(false);
+ _enginevolumelabel->set_text("Engine volume");
+
+ _enginevolumeslider = new ui::Slider(_frame);
+ _enginevolumeslider->set_background(false);
+ _enginevolumeslider->set_border(true);
+ _enginevolumeslider->set_range(0.0f, 100.0f);
+
+
+ // apply button
+ _applybutton = new ui::Button(_frame, "Apply");
+ _applybutton->set_label("apply");
+
+ // reset button
+ _resetbutton = new ui::Button(_frame, "Reset");
+ _resetbutton->set_label("reset");
+
+}
+
+AudioSettingsMenu::~AudioSettingsMenu()
+{
+}
+
+void AudioSettingsMenu::show()
+{
+ refresh();
+ ui::Window::show();
+}
+
+void AudioSettingsMenu::refresh()
+{
+ math::Color color;
+
+ // master volume
+ if (core::Cvar *cv_volume = core::Cvar::find("snd_volume"))
+ {
+ float v = cv_volume->value();
+ math::clamp(v, 0.0f, 1.0f);
+ _mastervolumeslider->set_value(v * 100.0f);
+
+ }
+ else
+ {
+ _mastervolumeslider->set_value(0.0f);
+ }
+
+ // engine volume
+ if (core::Cvar *cv_engines = core::Cvar::find("snd_engines"))
+ {
+ float v = cv_engines->value();
+ math::clamp(v, 0.0f, 1.0f);
+ _enginevolumeslider->set_value(v * 100.0f);
+
+ }
+ else
+ {
+ _enginevolumeslider->set_value(0.0f);
+ }
+}
+
+void AudioSettingsMenu::apply()
+{
+ // set master volume
+ if (core::Cvar *cv_volume = core::Cvar::find("snd_volume"))
+ {
+ float v = _mastervolumeslider->value();
+ cv_volume->assign(v * 0.01f);
+ }
+
+ // set engine volume
+ if (core::Cvar *cv_engines = core::Cvar::find("snd_engines"))
+ {
+ float v = _enginevolumeslider->value();
+ cv_engines->assign(v * 0.01f);
+ }
+}
+
+void AudioSettingsMenu::resize()
+{
+ const float padding = ui::UI::padding;
+ const float margin = ui::UI::margin;
+
+ // resize title label
+ _titlelabel->set_size(width() - padding * 2.0f, _titlelabel->font()->height());
+ _titlelabel->set_location(padding, padding);
+
+ // resize close button
+ _closebutton->set_size(_titlelabel->font()->height(), _titlelabel->font()->height());
+ _closebutton->set_location(_titlelabel->width() - _closebutton->width(), 0);
+
+ // resize content frame
+ _frame->set_location(_titlelabel->left(), _titlelabel->bottom() + padding);
+ _frame->set_size(_titlelabel->width(), height() - _titlelabel->bottom() - padding * 2.0f);
+
+ //---- inside _frame ----
+
+ // resize master volume label
+ _mastervolumelabel->set_location(padding, padding);
+ _mastervolumelabel->set_size(ui::UI::elementsize.width(), _mastervolumelabel->font()->height() + margin);
+ // resize master volume slider
+ _mastervolumeslider->set_location(_mastervolumelabel->right() + padding, _mastervolumelabel->top());
+ _mastervolumeslider->set_size(_frame->width() - _mastervolumelabel->right() - 2.0f * padding, _mastervolumelabel->height());
+
+ // resize master volume label
+ _enginevolumelabel->set_location(padding, _mastervolumelabel->bottom() + margin);
+ _enginevolumelabel->set_size(ui::UI::elementsize.width(), _enginevolumelabel->font()->height() + margin);
+ // resize master volume slider
+ _enginevolumeslider->set_location(_enginevolumelabel->right() + padding, _enginevolumelabel->top());
+ _enginevolumeslider->set_size(_frame->width() - _enginevolumelabel->right() - 2.0f * padding, _enginevolumelabel->height());
+
+ // resize apply button
+ _applybutton->set_size(ui::UI::elementsize);
+ _applybutton->set_location(
+ (_frame->width() - 2.0f * ui::UI::elementsize.width() - padding) * 0.5f,
+ _frame->height() - _applybutton->height() - padding
+ );
+
+ // resize reset button
+ _resetbutton->set_size(ui::UI::elementsize);
+ _resetbutton->set_location(_applybutton->right() + padding, _applybutton->top());
+
+
+}
+
+bool AudioSettingsMenu::on_emit(ui::Widget *sender, const ui::Widget::Event event, void *data)
+{
+ if (sender == _closebutton)
+ {
+ if (event == ui::Widget::EventButtonClicked)
+ {
+ parent()->hide();
+ return true;
+ }
+ }
+ else if (sender == _applybutton)
+ {
+ if (event == ui::Widget::EventButtonClicked)
+ {
+ apply();
+ return true;
+ }
+ }
+ else if (sender == _resetbutton)
+ {
+ if (event == ui::Widget::EventButtonClicked)
+ {
+ refresh();
+ return true;
+ }
+ }
+
+ return Window::on_emit(sender, event, data);
+}
+
+} // namespace client
diff --git a/src/client/audiosettingsmenu.h b/src/client/audiosettingsmenu.h
new file mode 100644
index 0000000..8aef1ae
--- /dev/null
+++ b/src/client/audiosettingsmenu.h
@@ -0,0 +1,85 @@
+/*
+ client/audiosettingsmenu.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_AUDIOSETTINGSMENU_H__
+#define __INCLUDED_CLIENT_AUDIOSETTINGSMENU_H__
+
+#include "ui/window.h"
+
+namespace ui
+{
+ class Button;
+ class IconButton;
+ class Label;
+ class Slider;
+
+}
+
+namespace client
+{
+
+/**
+ * @brief the audio settings menu
+ * */
+class AudioSettingsMenu : public ui::Window
+{
+public:
+ /**
+ * @brief default constructor
+ * */
+ AudioSettingsMenu(ui::Widget *parent = 0, const char *label = 0);
+
+ /**
+ * @brief default destructor
+ * */
+ virtual ~AudioSettingsMenu();
+
+ /**
+ * @brief show window
+ * */
+ virtual void show();
+
+protected:
+ /**
+ * @brief emit event handler
+ * */
+ virtual bool on_emit(ui::Widget *sender, const ui::Widget::Event event, void *data);
+
+ /**
+ * @brief resize event handler
+ * */
+ virtual void resize();
+
+private:
+ /**
+ * @brief refresh widget content
+ * */
+ void refresh();
+
+ /**
+ * @brief apply changes
+ * */
+ void apply();
+
+ ui::Label *_titlelabel;
+ ui::IconButton *_closebutton;
+
+ ui::Widget *_frame;
+
+ ui::Label *_mastervolumelabel;
+ ui::Slider *_mastervolumeslider;
+
+ ui::Label *_enginevolumelabel;
+ ui::Slider *_enginevolumeslider;
+
+ ui::Button *_applybutton;
+ ui::Button *_resetbutton;
+};
+
+}
+
+#endif // __INCLUDED_CLIENT_AUDIOSETTINGSMENU_H__
+
diff --git a/src/client/mainmenu.cc b/src/client/mainmenu.cc
index 32f3045..d9250bc 100644
--- a/src/client/mainmenu.cc
+++ b/src/client/mainmenu.cc
@@ -4,6 +4,7 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "client/audiosettingsmenu.h"
#include "client/buttonmenu.h"
#include "client/controlsettingsmenu.h"
#include "client/mainmenu.h"
@@ -194,14 +195,17 @@ void MainMenu::load()
mainmenu_joinmenu = (ui::Widget *) new ButtonMenu(this, "join");
static_cast<ButtonMenu *>(mainmenu_joinmenu)->set_compact();
+ // audio settings menu
+ new AudioSettingsMenu(this, "audio");
// control settings menu
new ControlSettingsMenu(this, "controls");
// player settings menu
- new PlayerSettingsMenu(this, "player");
+ new PlayerSettingsMenu(this, "player");
// load custom menus, this needs to be done before the
- // non-buttonmenu child widgets are created
+ // non-buttonmenu child widgets are created
+ // -- why?
load_definitions();
// options menu