diff options
author | Stijn Buys <ingar@osirion.org> | 2016-07-29 22:21:49 +0200 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2016-07-29 22:21:49 +0200 |
commit | 0707e358b29089bf419327bf034aff39c5f31001 (patch) | |
tree | f0fa349da33842ffa3d437e5bc4322744b0384ca /src/client/graphicssettingsmenu.cc | |
parent | 21e93bd260d2e74221da6f6560643d3c884d0128 (diff) |
Added graphics settings menu.
Diffstat (limited to 'src/client/graphicssettingsmenu.cc')
-rw-r--r-- | src/client/graphicssettingsmenu.cc | 407 |
1 files changed, 407 insertions, 0 deletions
diff --git a/src/client/graphicssettingsmenu.cc b/src/client/graphicssettingsmenu.cc new file mode 100644 index 0000000..ab05635 --- /dev/null +++ b/src/client/graphicssettingsmenu.cc @@ -0,0 +1,407 @@ +/* + client/graphicssettingsmenu.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/graphicssettingsmenu.h" +#include "core/cvar.h" +#include "ui/button.h" +#include "ui/checkbox.h" +#include "ui/iconbutton.h" +#include "ui/label.h" +#include "ui/ui.h" +#include "math/functions.h" + +#include <iostream> + +namespace client { + +GraphicsSettingsMenu::GraphicsSettingsMenu(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("GRAPHICS 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(); + + // options + + _optionslabel = new ui::Label(_frame); + _optionslabel->set_label("options"); + _optionslabel->set_background(false); + _optionslabel->set_border(false); + _optionslabel->set_text("Options"); + + _optionfullscreencheckbox = new ui::Checkbox(_frame); + _optionfullscreencheckbox->set_label("r_fullscreen"); + _optionfullscreencheckbox->set_text("Fullscreen"); + _optionfullscreencheckbox->set_border(true); + + _optiongridcheckbox = new ui::Checkbox(_frame); + _optiongridcheckbox->set_label("r_grid"); + _optiongridcheckbox->set_text("Draw space grid"); + _optiongridcheckbox->set_border(true); + + _optionskycheckbox = new ui::Checkbox(_frame); + _optionskycheckbox->set_label("r_sky"); + _optionskycheckbox->set_text("Draw sky"); + _optionskycheckbox->set_border(true); + + _optionparticlescheckbox = new ui::Checkbox(_frame); + _optionparticlescheckbox->set_label("r_particles"); + _optionparticlescheckbox->set_text("Draw particles"); + _optionparticlescheckbox->set_border(true); + + _optionindicatorscheckbox = new ui::Checkbox(_frame); + _optionindicatorscheckbox->set_label("r_indicators"); + _optionindicatorscheckbox->set_text("Draw direction indicators"); + _optionindicatorscheckbox->set_border(true); + + + _debuglabel = new ui::Label(_frame); + _debuglabel->set_label("debug"); + _debuglabel->set_background(false); + _debuglabel->set_border(false); + _debuglabel->set_text("Debug"); + + _debugstatscheckbox = new ui::Checkbox(_frame); + _debugstatscheckbox->set_label("draw_stats"); + _debugstatscheckbox->set_text("Draw FPS and statistics"); + _debugstatscheckbox->set_border(true); + + _debugwireframecheckbox = new ui::Checkbox(_frame); + _debugwireframecheckbox->set_label("r_wireframe"); + _debugwireframecheckbox->set_text("Draw wireframe"); + _debugwireframecheckbox->set_border(true); + + _debugkeypresscheckbox = new ui::Checkbox(_frame); + _debugkeypresscheckbox->set_label("draw_keypressq"); + _debugkeypresscheckbox->set_text("Draw keypress events"); + _debugkeypresscheckbox->set_border(true); + + _debugphysicscheckbox = new ui::Checkbox(_frame); + _debugphysicscheckbox->set_label("draw_physics"); + _debugphysicscheckbox->set_text("Draw physics entities (singleplayer only)"); + _debugphysicscheckbox->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"); +} + +GraphicsSettingsMenu::~GraphicsSettingsMenu() +{ +} + +void GraphicsSettingsMenu::show() +{ + refresh(); + ui::Window::show(); +} + +void GraphicsSettingsMenu::refresh() +{ + math::Color color; + + // fullscreen + if (core::Cvar *cv_fullscreen = core::Cvar::find("r_fullscreen")) + { + _optionfullscreencheckbox->set_value(cv_fullscreen->value() > 0.0f); + _optionfullscreencheckbox->set_enabled(true); + } + else + { + _optionfullscreencheckbox->set_value(false); + _optionfullscreencheckbox->set_enabled(false); + } + + // space grid + if (core::Cvar *cv_grid = core::Cvar::find("r_grid")) + { + _optiongridcheckbox->set_value(cv_grid->value() > 0.0f); + _optiongridcheckbox->set_enabled(true); + } + else + { + _optiongridcheckbox->set_value(false); + _optiongridcheckbox->set_enabled(false); + } + + // sky + if (core::Cvar *cv_sky = core::Cvar::find("r_sky")) + { + _optionskycheckbox->set_value(cv_sky->value() > 0.0f); + _optionskycheckbox->set_enabled(true); + } + else + { + _optionskycheckbox->set_value(false); + _optionskycheckbox->set_enabled(false); + } + + // particles + if (core::Cvar *cv_particles = core::Cvar::find("r_particles")) + { + _optionparticlescheckbox->set_value(cv_particles->value() > 0.0f); + _optionparticlescheckbox->set_enabled(true); + } + else + { + _optionparticlescheckbox->set_value(false); + _optionparticlescheckbox->set_enabled(false); + } + + // indicators + if (core::Cvar *cv_indicators = core::Cvar::find("r_indicators")) + { + _optionindicatorscheckbox->set_value(cv_indicators->value() > 0.0f); + _optionindicatorscheckbox->set_enabled(true); + } + else + { + _optionindicatorscheckbox->set_value(false); + _optionindicatorscheckbox->set_enabled(false); + } + + // stats + if (core::Cvar *cv_stats = core::Cvar::find("draw_stats")) + { + _debugstatscheckbox->set_value(cv_stats->value() > 0.0f); + _debugstatscheckbox->set_enabled(true); + } + else + { + _debugstatscheckbox->set_value(false); + _debugstatscheckbox->set_enabled(false); + } + + // wireframe + if (core::Cvar *cv_wireframe = core::Cvar::find("r_wireframe")) + { + _debugwireframecheckbox->set_value(cv_wireframe->value() > 0.0f); + _debugwireframecheckbox->set_enabled(true); + } + else + { + _debugwireframecheckbox->set_value(false); + _debugwireframecheckbox->set_enabled(false); + } + + // keypress + if (core::Cvar *cv_keypress = core::Cvar::find("draw_keypress")) + { + _debugkeypresscheckbox->set_value(cv_keypress->value() > 0.0f); + _debugkeypresscheckbox->set_enabled(true); + } + else + { + _debugkeypresscheckbox->set_value(false); + _debugkeypresscheckbox->set_enabled(false); + } + + // physics + if (core::Cvar *cv_physics = core::Cvar::find("r_physics")) + { + _debugphysicscheckbox->set_value(cv_physics->value() > 0.0f); + _debugphysicscheckbox->set_enabled(true); + } + else + { + _debugphysicscheckbox->set_value(false); + _debugphysicscheckbox->set_enabled(false); + } + +} + +void GraphicsSettingsMenu::apply() +{ + + // fullscreen + if (core::Cvar *cv_fullscreen = core::Cvar::find("r_fullscreen")) + { + cv_fullscreen->assign(_optionfullscreencheckbox->value() ? 1.0f : 0.0f); + } + + // space grid + if (core::Cvar *cv_grid = core::Cvar::find("r_grid")) + { + cv_grid->assign(_optiongridcheckbox->value() ? 1.0f : 0.0f); + } + + // sky + if (core::Cvar *cv_sky = core::Cvar::find("r_sky")) + { + cv_sky->assign(_optionskycheckbox->value() ? 1.0f : 0.0f); + } + + // particles + if (core::Cvar *cv_particles = core::Cvar::find("r_particles")) + { + cv_particles->assign(_optionparticlescheckbox->value() ? 1.0f : 0.0f); + } + + // indicators + if (core::Cvar *cv_indicators = core::Cvar::find("r_indicators")) + { + cv_indicators->assign(_optionindicatorscheckbox->value() ? 1.0f : 0.0f); + } + + // stats + if (core::Cvar *cv_stats = core::Cvar::find("draw_stats")) + { + cv_stats->assign(_debugstatscheckbox->value() ? 1.0f : 0.0f); + } + + // wireframe + if (core::Cvar *cv_wireframe = core::Cvar::find("r_wireframe")) + { + cv_wireframe->assign(_debugwireframecheckbox->value() ? 1.0f : 0.0f); + } + + // keypress + if (core::Cvar *cv_keypress = core::Cvar::find("draw_keypress")) + { + cv_keypress->assign(_debugkeypresscheckbox->value() ? 1.0f : 0.0f); + } + + // physics + if (core::Cvar *cv_physics = core::Cvar::find("r_physics")) + { + cv_physics->assign(_debugphysicscheckbox->value() ? 1.0f : 0.0f); + } +} + +void GraphicsSettingsMenu::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 ---- + + const float h = _frame->font()->height() + margin; + const float w = _frame->width() - ui::UI::elementsize.width() - 3.0f * padding; + + // OPTIONS + _optionslabel->set_location(padding, padding); + _optionslabel->set_size(ui::UI::elementsize.width(),h); + + // fullscreen + _optionfullscreencheckbox->set_location(_optionslabel->right() + padding, _optionslabel->top()); + _optionfullscreencheckbox->set_size(w, h); + + // grid + _optiongridcheckbox->set_location(_optionslabel->right() + padding, _optionfullscreencheckbox->bottom() + margin); + _optiongridcheckbox->set_size(w, h); + + // sky + _optionskycheckbox->set_location(_optionslabel->right() + padding, _optiongridcheckbox->bottom() + margin); + _optionskycheckbox->set_size(w, h); + + // particles + _optionparticlescheckbox->set_location(_optionslabel->right() + padding, _optionskycheckbox->bottom() + margin); + _optionparticlescheckbox->set_size(w, h); + + // indicators + _optionindicatorscheckbox->set_location(_optionslabel->right() + padding, _optionparticlescheckbox->bottom() + margin); + _optionindicatorscheckbox->set_size(w, h); + + // DEBUG OPTIONS + _debuglabel->set_location(padding, _optionindicatorscheckbox->bottom() + padding); + _debuglabel->set_size(ui::UI::elementsize.width(), h); + + // stats + _debugstatscheckbox->set_location(_debuglabel->right() + padding, _debuglabel->top()); + _debugstatscheckbox->set_size(w, h); + + // wireframe + _debugwireframecheckbox->set_location(_debuglabel->right() + padding, _debugstatscheckbox->bottom() + margin); + _debugwireframecheckbox->set_size(w,h); + + // keypress + _debugkeypresscheckbox->set_location(_debuglabel->right() + padding, _debugwireframecheckbox->bottom() + margin); + _debugkeypresscheckbox->set_size(w,h); + + // physics + _debugphysicscheckbox->set_location(_debuglabel->right() + padding, _debugkeypresscheckbox->bottom() + margin); + _debugphysicscheckbox->set_size(w,h); + + + // 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 GraphicsSettingsMenu::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 |