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.am6
-rw-r--r--src/client/targeticonbutton.cc40
-rw-r--r--src/client/targeticonbutton.h33
-rw-r--r--src/client/worldview.cc27
-rw-r--r--src/client/worldview.h4
-rw-r--r--src/ui/iconbutton.cc29
-rw-r--r--src/ui/iconbutton.h38
-rw-r--r--src/ui/palette.cc4
-rw-r--r--src/ui/palette.h16
-rw-r--r--src/ui/ui.cc4
10 files changed, 175 insertions, 26 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index f8d3c10..68c4a78 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -9,12 +9,14 @@ endif
libclient_la_SOURCES = action.cc buymenu.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 trademenu.cc video.cc worldview.cc
+ notifications.cc playerview.cc soundext.cc targeticonbutton.cc targets.cc trademenu.cc \
+ video.cc worldview.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS)
noinst_HEADERS = action.h chat.h client.h clientext.h hud.h entitymenu.h \
input.h joystick.h key.h keyboard.h map.h notifications.h soundext.h \
- targets.h video.h infowidget.h playerview.h worldview.h trademenu.h buymenu.h
+ targets.h video.h infowidget.h playerview.h worldview.h trademenu.h buymenu.h \
+ targeticonbutton.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
diff --git a/src/client/targeticonbutton.cc b/src/client/targeticonbutton.cc
new file mode 100644
index 0000000..cd3716f
--- /dev/null
+++ b/src/client/targeticonbutton.cc
@@ -0,0 +1,40 @@
+/*
+ client/targeticonbutton.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "audio/audio.h"
+#include "client/targeticonbutton.h"
+#include "client/targets.h"
+#include "core/commandbuffer.h"
+
+namespace client {
+
+TargetIconButton::TargetIconButton(Widget *parent, const char *icon, const char *command, unsigned int flags) : IconButton(parent, icon, command)
+{
+ set_label("targeticonbutton");
+ entity_flags = flags;
+}
+
+bool TargetIconButton::on_keypress(const int key, const unsigned int modifier)
+{
+ if (key == 512 + SDL_BUTTON_LEFT) {
+ if (enabled() && command().size() && targets::current()) {
+ core::cmd() << "@" << command() << " " << targets::current_id() << std::endl;
+ audio::play("ui/button");
+ }
+ return true;
+ }
+
+ return false;
+}
+
+void TargetIconButton::draw()
+{
+ enable(targets::current() && ((targets::current()->flags() & entity_flags) == entity_flags));
+
+ ui::IconButton::draw();
+}
+
+}
diff --git a/src/client/targeticonbutton.h b/src/client/targeticonbutton.h
new file mode 100644
index 0000000..a08c5c9
--- /dev/null
+++ b/src/client/targeticonbutton.h
@@ -0,0 +1,33 @@
+/*
+ client/targeticonbutton.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_TARGETICONBUTTON_H__
+#define __INCLUDED_CLIENT_TARGETICONBUTTON_H__
+
+#include "ui/iconbutton.h"
+
+namespace client {
+
+class TargetIconButton : public ui::IconButton {
+
+public:
+ /// special icon button that sends target '@' commands.
+ TargetIconButton(Widget *parent, const char *icon, const char *command, unsigned int flags = 0);
+
+ /// called when the widget receives a key press
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
+protected:
+ /// update enabled/disabled state and draw the IconButton
+ virtual void draw();
+
+private:
+ unsigned int entity_flags;
+};
+
+}
+
+#endif // __INCLUDED_CLIENT_TARGETICONBUTTON_H__
diff --git a/src/client/worldview.cc b/src/client/worldview.cc
index dc8370d..cb46a17 100644
--- a/src/client/worldview.cc
+++ b/src/client/worldview.cc
@@ -5,6 +5,7 @@
*/
#include "core/application.h"
+#include "client/targeticonbutton.h"
#include "client/worldview.h"
#include "client/video.h"
#include "ui/ui.h"
@@ -28,6 +29,10 @@ WorldView::WorldView(ui::Widget *parent) : ui::Widget(parent)
// icon buttons
view_menubutton = new ui::IconButton(this, "icons/button_menu", "ui_menu");
+
+ view_launchbutton = new ui::IconButton(this, "icons/button_launch", "launch");
+ view_dockbutton = new TargetIconButton(this, "icons/button_dock", "dock", core::Entity::Dockable);
+
view_chatbutton = new ui::IconButton(this, "icons/button_chat", "ui_chat");
view_mapbutton = new ui::IconButton(this, "icons/button_map", "ui_map");
}
@@ -63,13 +68,16 @@ void WorldView::resize()
// icons
const float icon_margin = 4.0f;
const float icon_size = 48.0f;
- const float icon_count = 4;
+ const float icon_count = 6;
const float l = (width() -((icon_count +1) * icon_margin) - (icon_count * icon_size)) * 0.5f;
view_menubutton->set_geometry(l, icon_margin, icon_size, icon_size);
// spacer
- view_chatbutton->set_geometry( l + 2.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
- view_mapbutton->set_geometry( l + 3.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ view_dockbutton->set_geometry( l + 2.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ view_launchbutton->set_geometry( l + 2.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ // spacer
+ view_chatbutton->set_geometry( l + 4.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ view_mapbutton->set_geometry( l + 5.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
}
void WorldView::clear()
@@ -91,13 +99,24 @@ void WorldView::draw()
view_statsinfo->set_visible(draw_stats->value() ? true : false);
view_keyinfo->set_visible(draw_keypress->value() ? true : false);
- if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol()) {
+ if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size()) ) {
view_playerview->hide();
view_menubutton->hide();
+ view_dockbutton->hide();
+ view_launchbutton->hide();
view_chatbutton->hide();
view_mapbutton->hide();
} else {
view_playerview->show();
+
+ if (core::localcontrol()->state() == core::Entity::Docked) {
+ view_launchbutton->show();
+ view_dockbutton->hide();
+ } else {
+ view_launchbutton->hide();
+ view_dockbutton->show();
+ }
+
view_menubutton->show();
view_chatbutton->show();
view_mapbutton->show();
diff --git a/src/client/worldview.h b/src/client/worldview.h
index 1889186..e42ac86 100644
--- a/src/client/worldview.h
+++ b/src/client/worldview.h
@@ -39,6 +39,10 @@ private:
PlayerView *view_playerview;
ui::IconButton *view_menubutton;
+
+ ui::IconButton *view_dockbutton;
+ ui::IconButton *view_launchbutton;
+
ui::IconButton *view_chatbutton;
ui::IconButton *view_mapbutton;
};
diff --git a/src/ui/iconbutton.cc b/src/ui/iconbutton.cc
index 1999072..2c4661e 100644
--- a/src/ui/iconbutton.cc
+++ b/src/ui/iconbutton.cc
@@ -21,9 +21,10 @@ IconButton::IconButton(Widget *parent, const char *icon, const char *command) :
{
set_label("iconbutton");
set_background(false);
- set_border(true);
+ set_border(false);
set_command(command);
set_icon(icon);
+ iconbutton_enabled = true;
}
IconButton::~IconButton()
@@ -62,22 +63,35 @@ void IconButton::set_icon(const std::string &icon)
iconbutton_icon.assign(icon);
}
+void IconButton::enable(bool enabled)
+{
+ iconbutton_enabled = enabled;
+}
+
+void IconButton::disable(bool disabled)
+{
+ iconbutton_enabled = !disabled;
+}
+
void IconButton::draw()
{
if (!icon().size())
return;
-
- if (has_mouse_focus())
+
+ if (disabled()) {
+ paint::color(palette()->disabled());
+ } else if (has_mouse_focus()) {
paint::color(palette()->highlight());
- else
+ } else {
paint::color(palette()->foreground());
+ }
paint::bitmap(location(), size(), icon());
}
void IconButton::draw_border()
{
- if (has_mouse_focus()) {
+ if (enabled() && has_mouse_focus()) {
math::Color color(palette()->foreground());
float t = core::application()->time();
t = t - floorf(t);
@@ -92,7 +106,7 @@ void IconButton::draw_border()
bool IconButton::on_keypress(const int key, const unsigned int modifier)
{
if (key == 512 + SDL_BUTTON_LEFT) {
- if (iconbutton_command.size()) {
+ if (enabled() && iconbutton_command.size()) {
core::cmd() << iconbutton_command << std::endl;
audio::play("ui/button");
}
@@ -109,7 +123,8 @@ bool IconButton::on_keyrelease(const int key, const unsigned int modifier)
void IconButton::on_mouseover(const math::Vector2f &cursor)
{
- audio::play("ui/select");
+ if (enabled())
+ audio::play("ui/select");
}
}
diff --git a/src/ui/iconbutton.h b/src/ui/iconbutton.h
index d545697..10b073f 100644
--- a/src/ui/iconbutton.h
+++ b/src/ui/iconbutton.h
@@ -18,29 +18,44 @@ public:
IconButton(Widget *parent, const char *icon=0, const char *command=0);
~IconButton();
+ /// the command this button executes
+ inline const std::string & command() const {
+ return iconbutton_command;
+ }
+
+ /// the icon texture
+ inline const std::string & icon() const {
+ return iconbutton_icon;
+ }
+
+ /// enabled or disabled
+ inline const bool enabled() const {
+ return iconbutton_enabled;
+ }
+
+ /// enabled or disabled
+ inline const bool disabled() const {
+ return !iconbutton_enabled;
+ }
+
+ /// enable or disable the button
+ void enable(bool enabled=true);
+
+ /// enable or disable the button
+ void disable(bool disabled=true);
+
/// set the command this button will execute
void set_command(const std::string &command);
/// set the command this button will execute
void set_command(const char *command);
- /// the command this button executes
- inline const std::string & command() const {
- return iconbutton_command;
- }
-
-
/// set the icon texture
void set_icon(const std::string & icon);
/// set the icon texture
void set_icon(const char *icon);
- /// the icon texture
- inline const std::string & icon() const {
- return iconbutton_icon;
- }
-
/// print button description
virtual void print(const size_t indent) const;
@@ -63,6 +78,7 @@ protected:
private:
std::string iconbutton_command;
std::string iconbutton_icon;
+ bool iconbutton_enabled;
};
}
diff --git a/src/ui/palette.cc b/src/ui/palette.cc
index 01fd99a..2dec462 100644
--- a/src/ui/palette.cc
+++ b/src/ui/palette.cc
@@ -16,6 +16,7 @@ Palette::Palette() :
palette_border(0.0f, 0.8f, 0.0f, 0.5f),
palette_text(0.75f, 1.0f),
palette_highlight(1.0f, 1.0f, 0.5f),
+ palette_disabled(0.5f, 0.5f, 0.5f, 1.0f),
palette_pointer(0.0f, 0.75f, 0.0f, 1.0f),
palette_active(0.0f, 1.0f, 0.0f, 1.0f),
palette_debug(0.50f, 0.75f),
@@ -50,6 +51,9 @@ const math::Color &Palette::color(Color palettecolor) const
case Highlight:
return highlight();
break;
+ case Disabled:
+ return disabled();
+ break;
case Pointer:
return pointer();
break;
diff --git a/src/ui/palette.h b/src/ui/palette.h
index 1aabc59..61a0b72 100644
--- a/src/ui/palette.h
+++ b/src/ui/palette.h
@@ -24,8 +24,8 @@ public:
~Palette();
/// color index
- enum Color { Foreground=0, Background=1, Border=2, Text=3, Highlight=4, Pointer=5, Active=6, Debug=7, Mission=8,
- Bold=9, Fancy=10, Warning=11, Error=12 };
+ enum Color { Foreground=0, Background=1, Border=2, Text=3, Highlight=4, Disabled=5, Pointer=6, Active=7,
+ Debug=8, Mission=9, Bold=10, Fancy=11, Warning=12, Error=13 };
/* ---- mutators ------------------------------------------- */
@@ -59,6 +59,12 @@ public:
palette_highlight.assign(color);
}
+ /// set disabled color
+ inline void set_disabled(const math::Color &color)
+ {
+ palette_disabled.assign(color);
+ }
+
/// set pointer color
inline void set_pointer(const math::Color &color)
{
@@ -134,6 +140,11 @@ public:
return palette_highlight;
}
+ /// disabled color
+ inline const math::Color &disabled() const {
+ return palette_disabled;
+ }
+
/// pointer color
inline const math::Color &pointer() const {
return palette_pointer;
@@ -184,6 +195,7 @@ private:
math::Color palette_border;
math::Color palette_text;
math::Color palette_highlight;
+ math::Color palette_disabled;
math::Color palette_pointer;
math::Color palette_active;
math::Color palette_debug;
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index 55702c3..b7d1155 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -304,9 +304,13 @@ void UI::load_settings()
continue;
} else if (ini.got_key_color("text", color)) {
ui_palette->set_text(color);
+ continue;
} else if (ini.got_key_color("highlight", color)) {
ui_palette->set_highlight(color);
continue;
+ } else if (ini.got_key_color("disabled", color)) {
+ ui_palette->set_disabled(color);
+ continue;
} else if (ini.got_key_color("pointer", color)) {
ui_palette->set_pointer(color);
continue;