Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/Makefile.am2
-rw-r--r--src/client/buttonmenu.cc15
-rw-r--r--src/client/controlsettingsmenu.cc9
-rw-r--r--src/client/hud.cc2
-rw-r--r--src/client/mainmenu.cc4
-rw-r--r--src/client/notifications.cc8
-rw-r--r--src/client/playersettingsmenu.cc276
-rw-r--r--src/client/playersettingsmenu.h87
-rw-r--r--src/client/savegamemenu.cc2
9 files changed, 387 insertions, 18 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index f3fd69c..743a9c6 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -37,6 +37,7 @@ noinst_HEADERS = \
mapwindow.h \
messagebox.h \
notifications.h \
+ playersettingsmenu.h \
reputationwindow.h \
savegamemenu.h \
soundext.h \
@@ -75,6 +76,7 @@ libclient_la_SOURCES = \
mapwindow.cc \
messagebox.cc \
notifications.cc \
+ playersettingsmenu.cc \
reputationwindow.cc \
savegamemenu.cc \
soundext.cc \
diff --git a/src/client/buttonmenu.cc b/src/client/buttonmenu.cc
index b5e8959..bef2558 100644
--- a/src/client/buttonmenu.cc
+++ b/src/client/buttonmenu.cc
@@ -45,27 +45,26 @@ ui::Button *ButtonMenu::add_button(char const *text, char const *command)
void ButtonMenu::resize()
{
- const float padding = ui::UI::elementsize.height();
-
// reposition all children within the container
- const float x = padding;
- float y = ui::UI::elementsize.height() * 0.5f;
+ const float margin = ui::UI::elementsize.height();
+
+ float y = margin * 0.5f;
for (Children::iterator it = buttonmenu_container->children().begin(); it != buttonmenu_container->children().end(); it++) {
Widget *w = (*it);
w->set_size(ui::UI::elementsize);
- w->set_location(x, y);
+ w->set_location(margin, y);
- y += ui::UI::elementsize.height() + ui::UI::spacing;
+ y += ui::UI::elementsize.height() + ui::UI::padding;
}
// resize container widget
if (!buttonmenu_compact) {
- buttonmenu_container->set_geometry(0, 0, ui::UI::elementsize.width() + 2.0f * padding, height());
+ buttonmenu_container->set_geometry(0, 0, ui::UI::elementsize.width() + 2.0f * margin, height());
} else {
y += ui::UI::elementsize.height() * 0.5f;
- buttonmenu_container->set_geometry(0, (height() - y) * 0.5f, ui::UI::elementsize.width() + 2.0f * padding, y);
+ buttonmenu_container->set_geometry(0, (height() - y) * 0.5f, ui::UI::elementsize.width() + 2.0f * margin, y);
}
diff --git a/src/client/controlsettingsmenu.cc b/src/client/controlsettingsmenu.cc
index e061d93..496805b 100644
--- a/src/client/controlsettingsmenu.cc
+++ b/src/client/controlsettingsmenu.cc
@@ -6,6 +6,7 @@
#include "client/controlsettingsmenu.h"
#include "client/input.h"
+#include "ui/button.h"
#include "ui/iconbutton.h"
#include "ui/label.h"
#include "ui/listview.h"
@@ -144,7 +145,7 @@ public:
protected:
virtual void resize()
{
- const float padding = ui::root()->font_large()->height();
+ const float padding = ui::UI::padding;
set_size(parent()->size());
@@ -274,7 +275,7 @@ ControlSettingsMenu::ControlSettingsMenu(ui::Widget *parent, const char *label)
_titlelabel->set_border(false);
_titlelabel->set_font(ui::root()->font_large());
_titlelabel->set_alignment(ui::AlignCenter);
- _titlelabel->set_text("CONTROLS");
+ _titlelabel->set_text("INPUT CONTROLS");
// close button
_closebutton = new ui::IconButton(_titlelabel, "bitmaps/icons/window_close");
@@ -319,7 +320,7 @@ void ControlSettingsMenu::apply()
void ControlSettingsMenu::resize()
{
- const float padding = ui::root()->font_large()->height();
+ const float padding = ui::UI::padding;
// resize title label
_titlelabel->set_size(width() - padding * 2.0f, _titlelabel->font()->height());
@@ -377,4 +378,4 @@ bool ControlSettingsMenu::on_emit(ui::Widget *sender, const ui::Widget::Event ev
return Window::on_emit(sender, event, data);
}
-} // namespace client \ No newline at end of file
+} // namespace client
diff --git a/src/client/hud.cc b/src/client/hud.cc
index 49f9c9d..de36a17 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -50,7 +50,7 @@ void HUD::resize()
{
const float padding = ui::root()->font_large()->height();
- hud_center->set_size(ui::pointer_size, ui::pointer_size);
+ hud_center->set_size(ui::UI::pointer_size, ui::UI::pointer_size);
hud_center->set_location((size() - hud_center->size()) * 0.5f);
const float w = (width() - 4 * padding) / 3.0f;
diff --git a/src/client/mainmenu.cc b/src/client/mainmenu.cc
index 8813688..32f3045 100644
--- a/src/client/mainmenu.cc
+++ b/src/client/mainmenu.cc
@@ -7,6 +7,7 @@
#include "client/buttonmenu.h"
#include "client/controlsettingsmenu.h"
#include "client/mainmenu.h"
+#include "client/playersettingsmenu.h"
#include "client/savegamemenu.h"
#include "core/core.h"
#include "core/gameinterface.h"
@@ -196,6 +197,9 @@ void MainMenu::load()
// control settings menu
new ControlSettingsMenu(this, "controls");
+ // player settings menu
+ new PlayerSettingsMenu(this, "player");
+
// load custom menus, this needs to be done before the
// non-buttonmenu child widgets are created
load_definitions();
diff --git a/src/client/notifications.cc b/src/client/notifications.cc
index 793303e..6431633 100644
--- a/src/client/notifications.cc
+++ b/src/client/notifications.cc
@@ -56,12 +56,12 @@ void Notifications::draw()
t = notify_timestamp.begin();
}
- const float spacing = ui::UI::spacing;
+ const float padding = ui::UI::padding;
math::Vector2f s(size());
- s[0] -= spacing * 2;
- s[1] -= spacing * 2;
+ s[0] -= padding * 2;
+ s[1] -= padding * 2;
- notify_scrollpane->set_location(spacing, spacing);
+ notify_scrollpane->set_location(padding, padding);
notify_scrollpane->set_size(s.x(), s.y());
}
diff --git a/src/client/playersettingsmenu.cc b/src/client/playersettingsmenu.cc
new file mode 100644
index 0000000..ca7fadf
--- /dev/null
+++ b/src/client/playersettingsmenu.cc
@@ -0,0 +1,276 @@
+/*
+ client/playersettingsmenu.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/playersettingsmenu.h"
+#include "core/cvar.h"
+#include "ui/button.h"
+#include "ui/colorpicker.h"
+#include "ui/iconbutton.h"
+#include "ui/inputbox.h"
+#include "ui/label.h"
+#include "ui/ui.h"
+
+#include <iostream>
+
+namespace client {
+
+PlayerSettingsMenu::PlayerSettingsMenu(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("PLAYER 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();
+
+ // player name
+ _playernamelabel = new ui::Label(_frame);
+ _playernamelabel->set_background(false);
+ _playernamelabel->set_border(false);
+ _playernamelabel->set_text("Name");
+
+ _playernameinput = new ui::InputBox(_frame);
+ _playernameinput ->set_label("cl_name");
+ _playernameinput->set_background(false);
+ _playernameinput->set_border(true);
+ _playernameinput->set_alignment(ui::AlignLeft | ui::AlignVCenter);
+ _playernameinput->set_max(64);
+
+ // primary color
+ _primarycolorlabel = new ui::Label(_frame);
+ _primarycolorlabel ->set_label("cl_color");
+ _primarycolorlabel->set_background(false);
+ _primarycolorlabel->set_border(false);
+ _primarycolorlabel->set_text("Primary color");
+
+ _primarycolorpicker = new ui::ColorPicker(_frame);
+ _primarycolorpicker->set_background(false);
+ _primarycolorpicker->set_border(true);
+
+ // secondary color
+ _secondarycolorlabel = new ui::Label(_frame);
+ _secondarycolorlabel ->set_label("cl_colorsecond");
+ _secondarycolorlabel->set_background(false);
+ _secondarycolorlabel->set_border(false);
+ _secondarycolorlabel->set_text("Secondary color");
+
+ _secondarycolorpicker = new ui::ColorPicker(_frame);
+ _secondarycolorpicker->set_background(false);
+ _secondarycolorpicker->set_border(true);
+
+ // apply button
+ _applybutton = new ui::Button(_frame, "Apply");
+ _applybutton->set_label("apply");
+
+ // reset button
+ _resetbutton = new ui::Button(_frame, "Reset");
+ _resetbutton->set_label("reset");
+
+}
+
+PlayerSettingsMenu::~PlayerSettingsMenu()
+{
+}
+
+void PlayerSettingsMenu::refresh()
+{
+ math::Color color;
+
+ // player name
+ core::Cvar *cv_playername = core::Cvar::find("cl_name");
+ if (cv_playername)
+ {
+ _playernameinput->set_text(cv_playername->str());
+ }
+ else
+ {
+ _playernameinput->clear();
+ }
+
+ // player primary color
+ core::Cvar *cv_primarycolor = core::Cvar::find("cl_color");
+ if (cv_primarycolor)
+ {
+ std::stringstream str(cv_primarycolor->str());
+ if (!(str >> color))
+ {
+ color.assign(1.0f);
+
+ }
+ }
+ else
+ {
+ color.assign(1.0f);
+ }
+ _primarycolorpicker->set_color(color);
+
+ // player secondary color
+ core::Cvar *cv_secondarycolor = core::Cvar::find("cl_colorsecond");
+ if (cv_secondarycolor)
+ {
+ std::stringstream str(cv_secondarycolor->str());
+ if (!(str >> color))
+ {
+ color.assign(0.5f);
+
+ }
+ }
+ else
+ {
+ color.assign(0.5f);
+ }
+ _secondarycolorpicker->set_color(color);
+}
+
+void PlayerSettingsMenu::show()
+{
+ refresh();
+ ui::Window::show();
+}
+
+void PlayerSettingsMenu::apply()
+{
+ // verify player name
+ std::string playername(_playernameinput->text());
+ aux::strip_quotes(playername);
+ aux::trim(playername);
+ if (!playername.size())
+ {
+ playername.assign("Player");
+ }
+ _playernameinput->set_text(playername);
+
+ // apply player name
+ core::Cvar *cv_playername = core::Cvar::find("cl_name");
+ if (cv_playername)
+ {
+ cv_playername->assign(playername);
+ }
+
+ // apply player primary color
+ core::Cvar *cv_primarycolor = core::Cvar::find("cl_color");
+ if (cv_primarycolor)
+ {
+ math::Color color(_primarycolorpicker->color());
+ std::stringstream str;
+ str << color;
+ cv_primarycolor->assign(str.str());
+ }
+
+ // apply player secondary color
+ core::Cvar *cv_secondarycolor = core::Cvar::find("cl_colorsecond");
+ if (cv_secondarycolor)
+ {
+ math::Color color(_secondarycolorpicker->color());
+ std::stringstream str;
+ str << color;
+ cv_secondarycolor->assign(str.str());
+ }
+}
+
+void PlayerSettingsMenu::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 player name label
+ _playernamelabel->set_location(padding, padding);
+ _playernamelabel->set_size(ui::UI::elementsize.width(), _playernamelabel->font()->height() + margin);
+ // resize player name inputbox
+ _playernameinput->set_location(_playernamelabel->right() + padding, _playernamelabel->top());
+ _playernameinput->set_size(_frame->width() - _playernamelabel->right() - 2.0f * padding, _playernamelabel->height());
+
+ // resize primary color label
+ _primarycolorlabel->set_size(ui::UI::elementsize.width(), _primarycolorlabel->font()->height() + margin);
+ _primarycolorlabel->set_location(padding, _playernamelabel->bottom());
+ // resize primary color picker
+ _primarycolorpicker->set_size(_playernameinput->width(), ui::UI::elementsize.height() * 4.0f);
+ _primarycolorpicker->set_location(_primarycolorlabel->right() + padding, _primarycolorlabel->top());
+
+ // resize secondary color label
+ _secondarycolorlabel->set_size(ui::UI::elementsize.width(), _primarycolorlabel->font()->height() + margin);
+ _secondarycolorlabel->set_location(padding,_primarycolorpicker->bottom());
+ // resize secondary color picker
+ _secondarycolorpicker->set_size(_playernameinput->width(), ui::UI::elementsize.height() * 4.0f);
+ _secondarycolorpicker->set_location(_secondarycolorlabel->right() + padding, _secondarycolorlabel->top());
+
+
+ // 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 PlayerSettingsMenu::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/playersettingsmenu.h b/src/client/playersettingsmenu.h
new file mode 100644
index 0000000..25267c2
--- /dev/null
+++ b/src/client/playersettingsmenu.h
@@ -0,0 +1,87 @@
+/*
+ client/playersettingsmenu.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_PLAYERSETTINGSMENU_H__
+#define __INCLUDED_CLIENT_PLAYERSETTINGSMENU_H__
+
+#include "ui/window.h"
+
+namespace ui
+{
+ class Button;
+ class ColorPicker;
+ class IconButton;
+ class InputBox;
+ class Label;
+
+}
+
+namespace client
+{
+
+/**
+ * @brief the player settings menu
+ * */
+class PlayerSettingsMenu : public ui::Window
+{
+public:
+ /**
+ * @brief default constructor
+ * */
+ PlayerSettingsMenu(ui::Widget *parent = 0, const char *label = 0);
+
+ /**
+ * @brief default destructor
+ * */
+ virtual ~PlayerSettingsMenu();
+
+ /**
+ * @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 *_playernamelabel;
+ ui::InputBox *_playernameinput;
+
+ ui::Label *_primarycolorlabel;
+ ui::ColorPicker *_primarycolorpicker;
+ ui::Label *_secondarycolorlabel;
+ ui::ColorPicker *_secondarycolorpicker;
+
+ ui::Button *_applybutton;
+ ui::Button *_resetbutton;
+};
+
+}
+
+#endif // __INCLUDED_CLIENT_PLAYERSETTINGSMENU_H__
diff --git a/src/client/savegamemenu.cc b/src/client/savegamemenu.cc
index fbb8cd5..1b47101 100644
--- a/src/client/savegamemenu.cc
+++ b/src/client/savegamemenu.cc
@@ -108,7 +108,7 @@ SaveGameMenu::~SaveGameMenu()
void SaveGameMenu::resize()
{
- const float padding = ui::root()->font_large()->height();
+ const float padding = ui::UI::padding;
const float icon_size = 24.0f; // small icons
// resize title label