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.am7
-rw-r--r--src/client/client.cc177
-rw-r--r--src/client/client.h9
-rw-r--r--src/client/entitymenu.cc (renamed from src/ui/menuview.cc)39
-rw-r--r--src/client/entitymenu.h (renamed from src/ui/menuview.h)28
-rw-r--r--src/client/hud.cc218
-rw-r--r--src/client/keyboard.cc4
-rw-r--r--src/client/map.cc9
-rw-r--r--src/client/map.h4
-rw-r--r--src/client/playerview.cc127
-rw-r--r--src/client/playerview.h20
-rw-r--r--src/client/worldview.h3
-rw-r--r--src/ui/Makefile.am8
-rw-r--r--src/ui/menu.cc2
-rw-r--r--src/ui/ui.cc207
-rw-r--r--src/ui/ui.h3
16 files changed, 478 insertions, 387 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index d617b52..e5afbb7 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -7,9 +7,9 @@ else
noinst_LTLIBRARIES = libclient.la
endif
-libclient_la_SOURCES = action.cc chat.cc client.cc clientext.cc hud.cc \
- infowidget.cc input.cc joystick.cc key.cc keyboard.cc map.cc notifications.cc \
- playerview.cc soundext.cc targets.cc video.cc worldview.cc
+libclient_la_SOURCES = action.cc chat.cc client.cc clientext.cc entitymenu.cc \
+ hud.cc infowidget.cc input.cc joystick.cc key.cc keyboard.cc map.cc \
+ notifications.cc playerview.cc soundext.cc targets.cc video.cc worldview.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS)
@@ -19,3 +19,4 @@ noinst_HEADERS = action.h chat.h client.h clientext.h hud.h input.h joystick.h \
libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la $(top_builddir)/src/audio/libaudio.la \
$(top_builddir)/src/render/librender.la $(top_builddir)/src/ui/libui.la
+_SOURCES = entitymenu.h
diff --git a/src/client/client.cc b/src/client/client.cc
index 4533f84..df56700 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -113,11 +113,26 @@ void Client::init(int count, char **arguments)
func = core::Func::add("snd_restart", Client::func_snd_restart);
func->set_info("restart audio subsystem");
+ func = core::Func::add("list_ui", func_list_ui);
+ func->set_info("list user interface widgets");
+
+ func = core::Func::add("list_menu", func_list_menu);
+ func->set_info("list available menus");
+
+ func = core::Func::add("ui", func_ui);
+ func->set_info("[command] user interface functions");
+
+ func = core::Func::add("ui_restart", func_ui_restart);
+ func->set_info("reload user interface files");
+
+ func = core::Func::add("ui_console", func_ui_console);
+ func->set_info("toggle console");
+
func = core::Func::add("ui_chat", Client::func_ui_chat);
func->set_info("toggle chat window");
- func = core::Func::add("ui_chatsmall", Client::func_ui_chatsmall);
- func->set_info("toggle small chat window");
+ func = core::Func::add("ui_chatbar", Client::func_ui_chatbar);
+ func->set_info("toggle chat bar");
func = core::Func::add("ui_map", Client::func_ui_map);
func->set_info("toggle map");
@@ -125,6 +140,9 @@ void Client::init(int count, char **arguments)
func = core::Func::add("ui_menu", Client::func_ui_menu);
func->set_info("toggle main menu");
+ func = core::Func::add("menu", func_menu);
+ func->set_info("[command] menu functions");
+
previous_timestamp = 0;
}
@@ -199,21 +217,13 @@ void Client::frame(unsigned long timestamp)
// show the join menu when player does not control an entity
} else if (core::game()->time() && !core::localcontrol()) {
ui::root()->show_menu("join");
-
- // show the view menu when docked
- } else if (core::localcontrol() && core::localplayer()->view()) {
- ui::root()->show_menuview("main");
}
-
} else {
if (core::localcontrol()) {
+
// hide join menu
if (ui::root()->active()->label().compare("join") == 0) {
- ui::root()->hide_menu();
-
- // hide view menu
- } else if (!core::localplayer()->view() && (ui::root()->active()->label().compare("view") == 0)) {
- ui::root()->hide_menu();
+ ui::root()->hide_menu();
}
}
}
@@ -231,10 +241,16 @@ void Client::shutdown()
core::Func::remove("r_restart");
core::Func::remove("snd_restart");
+ core::Func::remove("list_menu");
+ core::Func::remove("list_ui");
+ core::Func::remove("ui");
+ core::Func::remove("ui_restart");
+ core::Func::remove("ui_console");
core::Func::remove("ui_chat");
- core::Func::remove("ui_chatsmall");
+ core::Func::remove("ui_chatbar");
core::Func::remove("ui_map");
core::Func::remove("ui_menu");
+ core::Func::remove("menu");
audio::shutdown();
@@ -362,26 +378,95 @@ void Client::func_r_restart(std::string const &args)
video::restart();
}
+/* ---- func_ui ---------------------------------------------------- */
+
+void Client::func_list_ui(std::string const &args)
+{
+ if (ui::root()) {
+ ui::root()->list();
+ }
+}
+
+void Client::func_ui_restart(std::string const &args)
+{
+ if (ui::root()) {
+ ui::root()->load_menus();
+ ui::root()->load_settings();
+ ui::root()->apply_render_options();
+ }
+}
+
+
+void Client::func_ui_console(std::string const &args)
+{
+ ui::console()->toggle();
+}
+
+void Client::func_list_menu(std::string const &args)
+{
+ if (ui::root()) {
+ ui::root()->list_menus();
+ }
+}
+
+void Client::func_ui_help()
+{
+ con_print << "^BUser interface functions" << std::endl;
+ con_print << " ui help show this help" << std::endl;
+ con_print << " ui debug toggle debug mode" << std::endl;
+ con_print << " ui list list widgets" << std::endl;
+ con_print << " ui restart reload user interface files" << std::endl;
+}
+
+void Client::func_ui(std::string const &args)
+{
+ if (!ui::root()) {
+ con_warn << "User Interface not available!" << std::endl;
+ return;
+ }
+
+ if (!args.size()) {
+ func_ui_help();
+ return;
+ }
+ std::stringstream argstr(args);
+ std::string command;
+ argstr >> command;
+ aux::to_label(command);
+
+ if (command.compare("help") == 0) {
+ func_ui_help();
+ } else if (command.compare("debug") == 0) {
+ ui::UI::ui_debug = !ui::UI::ui_debug;
+ } else if (command.compare("list") == 0) {
+ ui::root()->list();
+ } else if (command.compare("restart") == 0) {
+ ui::root()->load_menus();
+ ui::root()->load_settings();
+ ui::root()->apply_render_options();
+ } else {
+ func_ui_help();
+ }
+}
+
void Client::func_ui_chat(std::string const &args)
{
if (client()->connected() && client()->worldview()->playerview()->visible()) {
- client()->worldview()->playerview()->chat()->set_small_view(false);
- client()->worldview()->playerview()->chat()->toggle();
+ client()->worldview()->playerview()->toggle_chat();
}
}
-void Client::func_ui_chatsmall(std::string const &args)
+void Client::func_ui_chatbar(std::string const &args)
{
if (client()->connected() && client()->worldview()->playerview()->visible()) {
- client()->worldview()->playerview()->chat()->set_small_view(true);
- client()->worldview()->playerview()->chat()->toggle();
+ client()->worldview()->playerview()->toggle_chatbar();
}
}
void Client::func_ui_map(std::string const &args)
{
if (client()->connected() && client()->worldview()->playerview()->visible()) {
- client()->worldview()->playerview()->map()->toggle();
+ client()->worldview()->playerview()->toggle_map();
}
}
@@ -403,5 +488,59 @@ void Client::func_ui_menu(std::string const &args)
}
}
+void Client::func_menu(std::string const &args)
+{
+ if (!ui::root()) {
+ con_warn << "User Interface not available!" << std::endl;
+ return;
+ }
+
+ if (!args.size()) {
+ con_print << "^Bmenu functions" << std::endl;
+ con_print << " menu help show this help" << std::endl;
+ con_print << " menu list list available menus" << std::endl;
+ con_print << " menu [name] show a menu" << std::endl;
+ con_print << " menu back return to the previous menu" << std::endl;
+ con_print << " menu previous return to the previous menu" << std::endl;
+ con_print << " menu close close the current menu" << std::endl;
+ con_print << " menu hide hide the current menu" << std::endl;
+ ui::root()->list_menus();
+ }
+
+ std::stringstream argstr(args);
+ std::string command;
+ argstr >> command;
+
+ aux::to_label(command);
+
+ if (command.compare("hide") == 0) {
+ ui::root()->hide_menu();
+
+ } else if (command.compare("close") == 0) {
+ ui::root()->hide_menu();
+
+ } else if (command.compare("back") == 0) {
+ ui::root()->previous_menu();
+
+ } else if (command.compare("previous") == 0) {
+ ui::root()->previous_menu();
+
+ } else if (command.compare("list") == 0) {
+ ui::root()->list_menus();
+
+ } else if (command.compare("view") == 0) {
+ if (client()->worldview()) {
+ std::string label;
+ if (!(argstr >> label)) {
+ label.assign("main");
+ }
+ client()->worldview()->playerview()->show_menu(label);
+ }
+ } else {
+ ui::root()->show_menu(command.c_str());
+ }
+}
+
+
} // namespace client
diff --git a/src/client/client.h b/src/client/client.h
index b873a20..375a9ce 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -72,10 +72,17 @@ private:
static void func_snd_restart(std::string const &args);
static void func_r_restart(std::string const &args);
+ static void func_list_ui(std::string const &args);
+ static void func_ui_restart(std::string const &args);
+ static void func_ui_console(std::string const &args);
+ static void func_list_menu(std::string const &args);
+ static void func_ui_help();
+ static void func_ui(std::string const &args);
static void func_ui_chat(std::string const &args);
- static void func_ui_chatsmall(std::string const &args);
+ static void func_ui_chatbar(std::string const &args);
static void func_ui_map(std::string const &args);
static void func_ui_menu(std::string const &args);
+ static void func_menu(std::string const &args);
WorldView *client_worldview;
diff --git a/src/ui/menuview.cc b/src/client/entitymenu.cc
index 43757e1..c7df7ab 100644
--- a/src/ui/menuview.cc
+++ b/src/client/entitymenu.cc
@@ -1,55 +1,54 @@
/*
- ui/menuview.cc
+ client/entitymenu.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
-#include "ui/menuview.h"
#include "ui/ui.h"
+#include "ui/button.h"
+#include "ui/paint.h"
+#include "client/entitymenu.h"
-namespace ui
+namespace client
{
-MenuView::MenuView(Window *parent, const char * label) : Window(parent)
+EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
{
set_border(false);
set_background(false);
set_label(label);
- menu_container = new Container(this);
- menu_label = new Label(this);
-
+ menu_container = new ui::Container(this);
hide();
}
-MenuView::~MenuView()
+EntityMenu::~EntityMenu()
{
}
-void MenuView::resize()
+void EntityMenu::resize()
{
set_size(parent()->size());
- menu_label->set_location(UI::elementsize.width() * 0.25, UI::elementsize.width() * 0.25);
- menu_label->set_size(UI::elementsize.width() * 1.5f, UI::elementsize.height());
+ menu_container->set_location(ui::UI::elementsize.height(), (height() - menu_container->height()) / 2.0f);
+}
- menu_container->set_location(UI::elementsize.width() * 0.25, (height() - menu_container->height()) / 2.0f);
+void EntityMenu::clear()
+{
+ remove_children();
}
-void MenuView::generate(core::Entity *entity, const char *menulabel)
+void EntityMenu::generate(core::Entity *entity, const char *menulabel)
{
+ using namespace ui;
+
if (!menulabel)
return;
//con_debug << "generating menu " << entity->label() << " " << menulabel << std::endl;
- remove_children();
+ clear();
menu_container = new Container(this);
-
- menu_label = new Label(this, entity->name().c_str());
- menu_label->set_background(true);
- menu_label->set_alignment(AlignCenter);
- menu_label->set_font(ui::root()->font_large());
-
+
core::MenuDescription *menudescr = 0;
for (core::Entity::Menus::iterator it = entity->menus().begin(); it != entity->menus().end(); it++) {
if ((*it)->label().compare(menulabel) == 0) {
diff --git a/src/ui/menuview.h b/src/client/entitymenu.h
index 041d71a..ac5a793 100644
--- a/src/ui/menuview.h
+++ b/src/client/entitymenu.h
@@ -1,42 +1,42 @@
/*
- ui/menuview.h
+ client/entitymenu.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_UI_MENUVIEW_H__
-#define __INCLUDED_UI_MENUVIEW_H__
+#ifndef __INCLUDED_CLIENT_ENTITYMENU_H__
+#define __INCLUDED_CLIENT_ENTITYMENU_H__
#include "core/entity.h"
-#include "ui/bitmap.h"
#include "ui/container.h"
-#include "ui/button.h"
#include "ui/label.h"
#include "ui/window.h"
-namespace ui
+namespace client
{
-/// a menu container
-class MenuView : public Window
+/// entity menus
+class EntityMenu : public ui::Window
{
public:
/// create a new menu
- MenuView(Window *parent, const char * label);
- ~MenuView();
+ EntityMenu(ui::Widget *parent, const char * label = 0);
+ ~EntityMenu();
/// generate a menu from menu descriptions
void generate(core::Entity *entity, const char *menulabel);
+ /// clear the current menu
+ void clear();
+
protected:
/// resize event
virtual void resize();
-
+
private:
- Container *menu_container;
- Label *menu_label;
+ ui::Container *menu_container;
};
}
-#endif // __INCLUDED_UI_MENUVIEW_H__
+#endif // __INCLUDED_CLIENT_ENTITYMENU_H__
diff --git a/src/client/hud.cc b/src/client/hud.cc
index beeefd3..014f4df 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -229,150 +229,142 @@ void HUD::draw()
Text::setcolor('N'); //set normal color
- if(core::localplayer()->view()) {
- Text::setcolor('N'); //set normal color
- Text::draw(render::State::width()-4-Text::fontwidth()*32, render::State::height()-Text::fontheight()*3-4, core::localcontrol()->zone()->name());
+ core::Zone *zone = core::localcontrol()->zone();
- Text::setcolor('B'); //set bold color
- Text::draw(render::State::width() - 4-Text::fontwidth()*32, render::State::height() - Text::fontheight()*2 -4, core::localplayer()->view()->name());
+ // draw targets
+ for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) {
+ core::Entity *entity = (*it);
- } else if (core::localcontrol() && core::localcontrol()->zone()) {
- core::Zone *zone = core::localcontrol()->zone();
-
- // draw targets
- for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) {
- core::Entity *entity = (*it);
-
- if (targets::is_legal_target(entity)) {
- if (entity == core::localplayer()->mission_target()) {
- draw_target(entity, true);
- } else if (entity == targets::current()) {
- draw_target(entity, true);
- } else if (entity->type() == core::Entity::Controlable) {
- draw_target(entity, false);
- }
+ if (targets::is_legal_target(entity)) {
+ if (entity == core::localplayer()->mission_target()) {
+ draw_target(entity, true);
+ } else if (entity == targets::current()) {
+ draw_target(entity, true);
+ } else if (entity->type() == core::Entity::Controlable) {
+ draw_target(entity, false);
}
}
+ }
- unsigned int state = core::localcontrol()->eventstate();
- if (state) {
- std::stringstream statestr;
- statestr.clear();
- if (state == core::Entity::ImpulseInitiate) {
- statestr << "^FInitializing kinetic impulse drive " << core::localcontrol()->timer();
- } else if (state == core::Entity::Impulse) {
- //statestr << "^FKinetic impulse";
- } else if (state == core::Entity::JumpInitiate) {
- statestr << "^FInitializing hyperspace jump drive "<< core::localcontrol()->timer();
- } else if (state == core::Entity::Jump) {
- statestr << "^FJumping...";
- }
-
- Text::draw(4, render::State::height() - Text::fontheight()*3-4, statestr);
+ unsigned int state = core::localcontrol()->eventstate();
+ if (state) {
+ std::stringstream statestr;
+ statestr.clear();
+ if (state == core::Entity::ImpulseInitiate) {
+ statestr << "^FInitializing kinetic impulse drive " << core::localcontrol()->timer();
+ } else if (state == core::Entity::Impulse) {
+ //statestr << "^FKinetic impulse";
+ } else if (state == core::Entity::JumpInitiate) {
+ statestr << "^FInitializing hyperspace jump drive "<< core::localcontrol()->timer();
+ } else if (state == core::Entity::Jump) {
+ statestr << "^FJumping...";
}
- core::Entity *target = targets::current();
- std::stringstream strdistance;
+ Text::draw(4, render::State::height() - Text::fontheight()*3-4, statestr);
+ }
- if (target) {
- std::stringstream strtarget;
- strtarget << "^B" << target->name() << "\n^B";
+ core::Entity *target = targets::current();
+ std::stringstream strdistance;
- float d = math::distance(core::localcontrol()->location(), target->location())
- - target->radius() - core::localcontrol()->radius();
+ if (target) {
+ std::stringstream strtarget;
+ strtarget << "^B" << target->name() << "\n^B";
- if (d > 0 ) {
- strtarget << "^Ndist:^B ";
- if (d > 100.0f) {
- strtarget << roundf(d * 0.1f) << "km";
- } else {
- strtarget << roundf(d * 100.0f) << "m";
- }
+ float d = math::distance(core::localcontrol()->location(), target->location())
+ - target->radius() - core::localcontrol()->radius();
- if (core::localcontrol()->speed() > 0.1f) {
- strtarget << "^N eta:^B ";
- float eta = floorf(d / core::localcontrol()->speed() );
- if (eta > 60.0f) {
- float etamin = floorf(eta / 60.0f);
- strtarget << etamin << "min ";
- eta -= etamin * 60;
- }
- strtarget << eta << "sec";
- }
+ if (d > 0 ) {
+ strtarget << "^Ndist:^B ";
+ if (d > 100.0f) {
+ strtarget << roundf(d * 0.1f) << "km";
} else {
- strtarget << " --";
+ strtarget << roundf(d * 100.0f) << "m";
}
- strtarget << '\n';
- Text::draw(width() - 4-Text::fontwidth()*30, height() - Text::fontheight()*2 -4, strtarget);
+
+ if (core::localcontrol()->speed() > 0.1f) {
+ strtarget << "^N eta:^B ";
+ float eta = floorf(d / core::localcontrol()->speed() );
+ if (eta > 60.0f) {
+ float etamin = floorf(eta / 60.0f);
+ strtarget << etamin << "min ";
+ eta -= etamin * 60;
+ }
+ strtarget << eta << "sec";
+ }
+ } else {
+ strtarget << " --";
}
+ strtarget << '\n';
+ Text::draw(width() - 4-Text::fontwidth()*30, height() - Text::fontheight()*2 -4, strtarget);
+ }
- // draw player info
- std::stringstream playerinfostr;
- playerinfostr <<"^B" << core::localcontrol()->name() << '\n' << "^Ncredits: " << core::localplayer()->credits();
- Text::draw(width() - 4-Text::fontwidth()*52, height() - Text::fontheight()*2 -4, playerinfostr);
+ // draw player info
+ std::stringstream playerinfostr;
+ playerinfostr <<"^B" << core::localcontrol()->name() << '\n' << "^Ncredits: " << core::localplayer()->credits();
+ Text::draw(width() - 4-Text::fontwidth()*52, height() - Text::fontheight()*2 -4, playerinfostr);
- Textures::bind("bitmaps/hud/thruster_base"); // 316 x 32 bitmap
- gl::color(1, 1, 1, 1);
- gl::begin(gl::Quads);
+ Textures::bind("bitmaps/hud/thruster_base"); // 316 x 32 bitmap
+ gl::color(1, 1, 1, 1);
+ gl::begin(gl::Quads);
- glTexCoord2f(0, 0);
- gl::vertex(4, height() - 4 - 32, 0);
+ glTexCoord2f(0, 0);
+ gl::vertex(4, height() - 4 - 32, 0);
- glTexCoord2f(1, 0);
- gl::vertex(4 + 316, height() - 4 - 32, 0);
+ glTexCoord2f(1, 0);
+ gl::vertex(4 + 316, height() - 4 - 32, 0);
- glTexCoord2f(1, 1);
- gl::vertex(4 + 316, height() - 4 , 0);
+ glTexCoord2f(1, 1);
+ gl::vertex(4 + 316, height() - 4 , 0);
- glTexCoord2f(0, 1);
- gl::vertex(4, height() - 4 , 0);
+ glTexCoord2f(0, 1);
+ gl::vertex(4, height() - 4 , 0);
- gl::end();
+ gl::end();
- float u = core::localcontrol()->thrust();
- if (core::localcontrol()->eventstate() == core::Entity::Impulse) {
- u = 1.0;
- }
+ float u = core::localcontrol()->thrust();
+ if (core::localcontrol()->eventstate() == core::Entity::Impulse) {
+ u = 1.0;
+ }
- if (( u > 0) || (core::localcontrol()->eventstate() == core::Entity::Impulse)) {
+ if (( u > 0) || (core::localcontrol()->eventstate() == core::Entity::Impulse)) {
- if (core::localcontrol()->eventstate() == core::Entity::Impulse) {
- gl::color(0, .8, 0);
- } else {
- float d = math::absf(input::local_thrust - u);
- if (d > 0.1) {
- d = 0.1f;
- }
- gl::color(1, 1, .5f + d * 5.0f);
+ if (core::localcontrol()->eventstate() == core::Entity::Impulse) {
+ gl::color(0, .8, 0);
+ } else {
+ float d = math::absf(input::local_thrust - u);
+ if (d > 0.1) {
+ d = 0.1f;
}
- Textures::bind("bitmaps/hud/thruster_indicator"); // 316 x 32 bitmap
- gl::begin(gl::Quads);
- glTexCoord2f(0, 0);
- gl::vertex(4, height() - 4 - 32, 0);
-
- glTexCoord2f(u, 0);
- gl::vertex(4.0f + u * 316.0f, height() - 4 - 32, 0);
-
- glTexCoord2f(u, 1);
- gl::vertex(4.0f + u * 316.0f, height() - 4 , 0);
-
- glTexCoord2f(0, 1);
- gl::vertex(4, height() - 4 , 0);
-
- gl::end();
+ gl::color(1, 1, .5f + d * 5.0f);
}
+ Textures::bind("bitmaps/hud/thruster_indicator"); // 316 x 32 bitmap
+ gl::begin(gl::Quads);
+ glTexCoord2f(0, 0);
+ gl::vertex(4, height() - 4 - 32, 0);
+
+ glTexCoord2f(u, 0);
+ gl::vertex(4.0f + u * 316.0f, height() - 4 - 32, 0);
- Text::setfont("gui", 14, 24);
- Text::setcolor('B'); //set normal color
+ glTexCoord2f(u, 1);
+ gl::vertex(4.0f + u * 316.0f, height() - 4 , 0);
- std::stringstream speedstr;
- speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f);
- Text::draw( 316+4+10, height() - 6 -16 - render::Text::fontwidth() /2, speedstr);
+ glTexCoord2f(0, 1);
+ gl::vertex(4, height() - 4 , 0);
- Text::setfont("gui", 12, 18);
- Text::setcolor('N'); //set normal color
+ gl::end();
}
+ Text::setfont("gui", 14, 24);
+ Text::setcolor('B'); //set normal color
+
+ std::stringstream speedstr;
+ speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f);
+ Text::draw( 316+4+10, height() - 6 -16 - render::Text::fontwidth() /2, speedstr);
+
+ Text::setfont("gui", 12, 18);
+ Text::setcolor('N'); //set normal color
+
+
gl::disable(GL_TEXTURE_2D);
}
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
index 9c35771..ba67395 100644
--- a/src/client/keyboard.cc
+++ b/src/client/keyboard.cc
@@ -135,7 +135,7 @@ Keyboard::Keyboard()
add_key("q", SDLK_q, 'q', "+rollleft");
add_key("r", SDLK_r, 'r');
add_key("s", SDLK_s, 's', "+reverse");
- add_key("t", SDLK_t, 't', "ui_chatsmall");
+ add_key("t", SDLK_t, 't', "ui_chatbar");
add_key("u", SDLK_u, 'u');
key = add_key("v", SDLK_v, 'v', "view_next");
key->assign(Key::Shift, "view_prev");
@@ -176,7 +176,7 @@ Keyboard::Keyboard()
add_key("pageup", SDLK_PAGEUP);
add_key("pagedown", SDLK_PAGEDOWN);
- add_key("f1", SDLK_F1);
+ add_key("f1", SDLK_F1, 0, "ui_menu");
add_key("f2", SDLK_F2);
add_key("f3", SDLK_F3, 0, "@dock");
key = add_key("f4", SDLK_F4);
diff --git a/src/client/map.cc b/src/client/map.cc
index 7d1536d..35fb6d1 100644
--- a/src/client/map.cc
+++ b/src/client/map.cc
@@ -15,7 +15,7 @@
namespace client {
-Map::Map(ui::Widget *parent) : ui::Widget(parent)
+Map::Map(ui::Widget *parent) : ui::Window(parent)
{
set_label("map");
set_border(true);
@@ -29,7 +29,7 @@ Map::~Map()
void Map::hide()
{
- ui::Widget::hide();
+ ui::Window::hide();
map_hover = 0;
}
@@ -182,6 +182,11 @@ bool Map::on_keypress(const int key, const unsigned int modifier)
if ((hover()) && (key == 512 + SDL_BUTTON_LEFT)) {
targets::select_target(hover());
return true;
+ } else if (key == SDLK_ESCAPE) {
+ if (visible()) {
+ hide();
+ return true;
+ }
}
return false;
diff --git a/src/client/map.h b/src/client/map.h
index c7c1c29..d75024a 100644
--- a/src/client/map.h
+++ b/src/client/map.h
@@ -7,11 +7,11 @@
#ifndef __INCLUDED_CLIENT_MAP_H__
#define __INCLUDED_CLIENT_MAP_H__
-#include "ui/widget.h"
+#include "ui/window.h"
namespace client {
-class Map : public ui::Widget
+class Map : public ui::Window
{
public:
Map(ui::Widget *parent = 0);
diff --git a/src/client/playerview.cc b/src/client/playerview.cc
index 703f392..f129a1e 100644
--- a/src/client/playerview.cc
+++ b/src/client/playerview.cc
@@ -4,6 +4,7 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "audio/audio.h"
#include "client/playerview.h"
#include "ui/ui.h"
@@ -14,20 +15,27 @@ PlayerView::PlayerView(ui::Widget *parent) : ui::Widget(parent)
set_label("playerview");
set_border(false);
set_background(false);
+
+ view_lastentity = 0;
label_zonename = new ui::Label(this);
label_zonename->set_alignment(ui::AlignCenter);
label_zonename->set_background(true);
+ label_zonename->set_font(ui::root()->font_large());
label_viewname = new ui::Label(this);
label_viewname->set_alignment(ui::AlignCenter);
label_viewname->set_background(true);
+ label_viewname->set_font(ui::root()->font_large());
view_notify = new Notifications(this);
view_chat = new Chat(this);
view_map = new Map(this);
view_hud = new HUD(this);
+ view_menu = new EntityMenu(this);
+
view_hud->lower();
+ view_menu->raise();
}
PlayerView::~PlayerView()
@@ -41,6 +49,9 @@ void PlayerView::clear()
view_chat->hide();
view_map->hide();
+ view_menu->hide();
+
+ view_lastentity = 0;
}
void PlayerView::event_text(const std::string & text)
@@ -49,6 +60,60 @@ void PlayerView::event_text(const std::string & text)
view_notify->event_text(text);
}
+void PlayerView::toggle_map()
+{
+
+ if (!map()->visible()) {
+ if(chat()->visible() && !chat()->small_view())
+ chat()->hide();
+
+ if (view_menu->visible())
+ view_menu->hide();
+ }
+
+ map()->toggle();
+ audio::play("ui/menu");
+
+ if (map()->visible() && chat()->visible() && chat()->small_view()) {
+ chat()->raise();
+ }
+}
+
+void PlayerView::toggle_chat()
+{
+ if (!chat()->visible()) {
+ if(map()->visible())
+ map()->hide();
+
+ if (view_menu->visible())
+ view_menu->hide();
+ }
+ chat()->set_small_view(false);
+ chat()->toggle();
+ audio::play("ui/menu");
+}
+
+void PlayerView::toggle_chatbar()
+{
+ chat()->set_small_view(true);
+ chat()->toggle();
+}
+
+void PlayerView::show_menu(const std::string & label)
+{
+ if (!core::localplayer()->view())
+ return;
+
+ if (!core::localplayer()->view()->menus().size())
+ return;
+
+ view_menu->generate(core::localplayer()->view(), label.c_str());
+ view_menu->show();
+
+ if (chat()->visible() && chat()->small_view())
+ chat()->raise();
+}
+
void PlayerView::resize()
{
//const float largemargin = ui::UI::elementsize.width() * 0.25;
@@ -68,15 +133,62 @@ void PlayerView::resize()
view_notify->set_geometry(view_map->location(), view_map->size());
// reposition labels
- label_viewname->set_size(ui::UI::elementsize.width(), ui::UI::elementsize.height());
+ label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height());
label_viewname->set_location(smallmargin, smallmargin * 0.5f);
- label_zonename->set_size(ui::UI::elementsize.width(), ui::UI::elementsize.height());
+ label_zonename->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height());
label_zonename->set_location(width() - label_zonename->width() - smallmargin, height() - label_zonename->height() - smallmargin * 0.5f);
}
void PlayerView::draw()
{
+ if (core::localplayer()->view()) {
+
+ // docking view
+ if (core::localplayer()->view()->menus().size()) {
+
+ // entity with menus
+ label_viewname->show();
+ label_viewname->set_text(core::localplayer()->view()->name());
+
+ label_zonename->show();
+
+ if (view_lastentity != core::localplayer()->view()) {
+ // initialy show the menu
+ show_menu("main");
+ map()->hide();
+ chat()->hide();
+ audio::play("ui/menu");
+ } else if (!view_menu->visible() && !map()->visible() && (!chat()->visible() || chat()->small_view()) ) {
+ // show the menu if there's no other window open
+ menu()->show();
+ audio::play("ui/menu");
+ }
+
+ } else {
+ // entity without menus, plain view
+ this->hide();
+ return;
+ }
+
+ view_hud->hide();
+ view_lastentity = core::localplayer()->view();
+
+ } else {
+ if (view_menu->visible()) {
+ view_menu->hide();
+ }
+
+ label_viewname->hide();
+ label_zonename->set_visible(view_map->visible());
+ view_hud->show();
+ view_lastentity = 0;
+ }
+
+ if (label_zonename->visible()) {
+ label_zonename->set_text(core::localplayer()->zone()->name());
+ }
+
//const float largemargin = ui::UI::elementsize.width() * 0.25;
const float smallmargin = ui::UI::elementsize.height();
@@ -88,17 +200,6 @@ void PlayerView::draw()
view_chat->set_geometry(view_map->location(), view_map->size());
}
view_chat->event_resize();
-
- if (core::localplayer()->view()) {
- label_viewname->show();
- label_zonename->show();
- } else {
- label_viewname->hide();
- label_zonename->set_visible(view_map->visible());
- }
-
- if (label_zonename->visible())
- label_zonename->set_text(core::localplayer()->zone()->name());
}
}
diff --git a/src/client/playerview.h b/src/client/playerview.h
index e5cb238..9cf8a94 100644
--- a/src/client/playerview.h
+++ b/src/client/playerview.h
@@ -8,6 +8,7 @@
#define __INCLUDED_CLIENT_PLAYERVIEW_H__
#include "client/chat.h"
+#include "client/entitymenu.h"
#include "client/hud.h"
#include "client/map.h"
#include "client/notifications.h"
@@ -27,18 +28,35 @@ public:
void event_text(const std::string & text);
+ /// toggle map window
+ void toggle_map();
+
+ /// togge chat window
+ void toggle_chat();
+
+ /// toggle chat bar
+ void toggle_chatbar();
+
+ /// show entity menus
+ void show_menu(const std::string & label);
+
inline Map *map() { return view_map; }
inline Chat *chat() { return view_chat; }
inline Notifications *notify() { return view_notify; }
+ inline EntityMenu *menu() { return view_menu; }
protected:
virtual void draw();
virtual void resize();
+
private:
Notifications *view_notify;
HUD *view_hud;
Chat *view_chat;
Map *view_map;
+ EntityMenu *view_menu;
+
+ core::Entity *view_lastentity;
ui::Label *label_zonename;
ui::Label *label_viewname;
@@ -48,4 +66,4 @@ private:
}
-#endif // __INCLUDED_CLIENT_PLAYERVIEW_H__ \ No newline at end of file
+#endif // __INCLUDED_CLIENT_PLAYERVIEW_H__
diff --git a/src/client/worldview.h b/src/client/worldview.h
index a83fb81..7921da2 100644
--- a/src/client/worldview.h
+++ b/src/client/worldview.h
@@ -40,4 +40,5 @@ private:
}
-#endif // __INCLUDED_CLIENT_PLAYERVIEW_H__ \ No newline at end of file
+#endif // __INCLUDED_CLIENT_PLAYERVIEW_H__
+
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index a89cdaa..1fb8e24 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -8,10 +8,10 @@ noinst_LTLIBRARIES = libui.la
endif
noinst_HEADERS = bitmap.h button.h console.h container.h definitions.h font.h \
- inputbox.h label.h menu.h menuview.h paint.h palette.h scrollpane.h toolbar.h ui.h \
- widget.h window.h
+ inputbox.h label.h menu.h paint.h palette.h scrollpane.h toolbar.h ui.h widget.h \
+ window.h
libui_la_SOURCES = bitmap.cc button.cc console.cc console.h container.cc \
- font.cc inputbox.cc label.cc menu.cc menuview.cc paint.cc palette.cc \
- scrollpane.cc toolbar.cc ui.cc widget.cc window.cc
+ font.cc inputbox.cc label.cc menu.cc paint.cc palette.cc scrollpane.cc \
+ toolbar.cc ui.cc widget.cc window.cc
libui_la_LDFLAGS = -avoid-version -no-undefined
diff --git a/src/ui/menu.cc b/src/ui/menu.cc
index a7e2d68..f1364ac 100644
--- a/src/ui/menu.cc
+++ b/src/ui/menu.cc
@@ -58,7 +58,7 @@ void Menu::resize()
{
set_size(parent()->size());
menu_background->set_size(size());
- menu_container->set_location(UI::elementsize.width() * 0.25, (height() - menu_container->height()) / 2.0f);
+ menu_container->set_location(ui::UI::elementsize.height(), (height() - menu_container->height()) / 2.0f);
}
}
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index ff6810f..f96f692 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -17,7 +17,6 @@
#include "ui/button.h"
#include "ui/label.h"
#include "ui/menu.h"
-#include "ui/menuview.h"
#include "ui/paint.h"
#include "ui/ui.h"
#include "ui/widget.h"
@@ -34,129 +33,6 @@ math::Vector2f UI::elementsize(256, 48);
UI *global_ui = 0;
-void func_list_ui(std::string const &args)
-{
- if (global_ui) {
- global_ui->list();
- }
-}
-
-void func_ui_restart(std::string const &args)
-{
- if (global_ui) {
- global_ui->load_menus();
- global_ui->load_settings();
- global_ui->apply_render_options();
- }
-}
-
-
-void func_ui_console(std::string const &args)
-{
- console()->toggle();
-}
-
-void func_list_menu(std::string const &args)
-{
- if (global_ui) {
- global_ui->list_menus();
- }
-}
-
-void help()
-{
- con_print << "^BUser interface functions" << std::endl;
- con_print << " ui help show this help" << std::endl;
- con_print << " ui debug toggle debug mode" << std::endl;
- con_print << " ui list list widgets" << std::endl;
- con_print << " ui restart reload user interface files" << std::endl;
-}
-
-void func_ui(std::string const &args)
-{
- if (!global_ui) {
- con_warn << "User Interface not available!" << std::endl;
- return;
- }
-
- if (!args.size()) {
- help();
- return;
- }
- std::stringstream argstr(args);
- std::string command;
- argstr >> command;
- aux::to_label(command);
-
- if (command.compare("help") == 0) {
- help();
- } else if (command.compare("debug") == 0) {
- UI::ui_debug = !UI::ui_debug;
- } else if (command.compare("list") == 0) {
- global_ui->list();
- } else if (command.compare("restart") == 0) {
- global_ui->load_menus();
- global_ui->load_settings();
- global_ui->apply_render_options();
- } else {
- help();
- }
-}
-
-void help_menu()
-{
- con_print << "^Bmenu functions" << std::endl;
- con_print << " menu help show this help" << std::endl;
- con_print << " menu list list available menus" << std::endl;
- con_print << " menu [name] show a menu" << std::endl;
- con_print << " menu back return to the previous menu" << std::endl;
- con_print << " menu previous return to the previous menu" << std::endl;
- con_print << " menu close close the current menu" << std::endl;
- con_print << " menu hide hide the current menu" << std::endl;
- root()->list_menus();
-}
-
-void func_menu(std::string const &args)
-{
- if (!global_ui) {
- con_warn << "User Interface not available!" << std::endl;
- return;
- }
-
- if (!args.size()) {
- return;
- }
- std::stringstream argstr(args);
- std::string command;
- argstr >> command;
-
- aux::to_label(command);
-
- if (command.compare("hide") == 0) {
- root()->hide_menu();
-
- } else if (command.compare("close") == 0) {
- root()->hide_menu();
-
- } else if (command.compare("back") == 0) {
- root()->previous_menu();
-
- } else if (command.compare("previous") == 0) {
- root()->previous_menu();
-
- } else if (command.compare("list") == 0) {
- root()->list_menus();
- } else if (command.compare("view") == 0) {
- std::string label;
- if (!(argstr >> label)) {
- label.assign("main");
- }
- root()->show_menuview(label);
- } else {
- root()->show_menu(command.c_str());
- }
-}
-
UI *root()
{
return global_ui;
@@ -175,36 +51,12 @@ void init()
global_ui->load_menus();
global_ui->load_settings();
-
- core::Func *func = core::Func::add("list_ui", func_list_ui);
- func->set_info("list user interface widgets");
-
- func = core::Func::add("list_menu", func_list_menu);
- func->set_info("list available menus");
-
- func = core::Func::add("ui", func_ui);
- func->set_info("[command] user interface functions");
-
- func = core::Func::add("ui_restart", func_ui_restart);
- func->set_info("reload user interface files");
-
- func = core::Func::add("ui_console", func_ui_console);
- func->set_info("toggle console on or off");
-
- func = core::Func::add("menu", func_menu);
- func->set_info("[command] menu functions");
}
void shutdown()
{
con_print << "^BShutting down user interface..." << std::endl;
-
- core::Func::remove("list_ui");
- core::Func::remove("list_menu");
- core::Func::remove("menu");
- core::Func::remove("ui_console");
- core::Func::remove("ui");
-
+
if (global_ui) {
delete global_ui;
global_ui = 0;
@@ -257,9 +109,6 @@ void UI::load_menus()
}
ui_menus.clear();
- // add specia view menu
- add_menu(new MenuView(this, "view"));
-
std::string filename("menu");
filesystem::IniFile ini;
ini.open(filename);
@@ -588,20 +437,6 @@ void UI::add_menu(Window *menu)
}
-void UI::show_menuview(const std::string &label)
-{
- if (!core::localplayer()->view())
- return;
-
- if (!core::localplayer()->view()->menus().size())
- return;
-
- MenuView *menuview = static_cast<MenuView *>(find_menu("view"));
- menuview->generate(core::localplayer()->view(), label.c_str());
-
- show_menu("view");
-}
-
void UI::show_menu(const char *label)
{
Window *menu = find_menu(label);
@@ -655,7 +490,14 @@ void UI::frame()
if (ui_active_menu && !ui_active_menu->visible()) {
ui_active_menu = 0;
}
-
+
+ ui_input_focus = find_input_focus();
+ Widget *f = find_mouse_focus(mouse_cursor);
+ if (f) {
+ f->event_mouse(mouse_cursor);
+ }
+ ui_mouse_focus = f;
+
event_draw();
if (visible())
@@ -670,11 +512,6 @@ void UI::frame()
void UI::input_mouse(const float x, const float y)
{
mouse_cursor.assign(x, y);
- Widget *f = find_mouse_focus(mouse_cursor);
- if (f) {
- f->event_mouse(mouse_cursor);
- }
- ui_mouse_focus = f;
}
bool UI::input_key(const bool pressed, const int key, const unsigned int modifier)
@@ -688,7 +525,13 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie
}
ui_input_focus = f;
} else {
- // mosue buttons
+ // mouse buttons
+ Widget *f = find_mouse_focus(mouse_cursor);
+ if (f) {
+ f->event_mouse(mouse_cursor);
+ }
+ ui_mouse_focus = f;
+
if (ui_mouse_focus)
handled = ui_mouse_focus->event_key(pressed, key, modifier);
}
@@ -701,21 +544,9 @@ bool UI::on_keypress(const int key, const unsigned int modifier)
case SDLK_ESCAPE:
if (active()) {
- if (active()->label().compare("view") == 0) {
- if (core::application()->connected()) {
- show_menu("game");
- audio::play("ui/menu");
- }
- } else {
- hide_menu();
- audio::play("ui/menu");
- }
- } else {
- if (core::application()->connected()) {
- show_menu("game");
- audio::play("ui/menu");
- }
- }
+ hide_menu();
+ audio::play("ui/menu");
+ }
return true;
break;
default:
diff --git a/src/ui/ui.h b/src/ui/ui.h
index fae827e..6216ba7 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -42,9 +42,6 @@ public:
/// make a window the active window
void show_menu(const char *label);
-
- /// make the entity view menu the active window
- void show_menuview(const std::string &label);
/// hide the active window
void hide_menu();