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/buymenu.cc8
-rw-r--r--src/client/client.cc3
-rw-r--r--src/client/map.cc22
-rw-r--r--src/client/playerview.cc6
-rw-r--r--src/client/targets.cc17
-rw-r--r--src/client/targets.h5
-rw-r--r--src/core/info.h1
-rw-r--r--src/core/item.cc26
-rw-r--r--src/core/item.h43
-rw-r--r--src/core/parser.cc4
-rw-r--r--src/game/base/game.cc22
-rw-r--r--src/game/base/shipdealer.cc2
-rw-r--r--src/game/base/shipmodel.cc6
-rwxr-xr-xsrc/ui/modelview.cc27
-rwxr-xr-xsrc/ui/modelview.h12
-rw-r--r--src/ui/ui.cc6
-rw-r--r--src/ui/ui.h3
-rw-r--r--src/ui/widget.cc7
-rw-r--r--src/ui/widget.h2
19 files changed, 161 insertions, 61 deletions
diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc
index fecf4e0..4a4107b 100644
--- a/src/client/buymenu.cc
+++ b/src/client/buymenu.cc
@@ -29,13 +29,13 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
menu_modelpane->set_background(true);
menu_modelpane->set_border(true);
- menu_closebutton = new ui::Button(menu_modelpane, "Close","view hide");
-
menu_modelview = new ui::ModelView(menu_modelpane);
menu_modelview->set_label("modelview");
menu_modelview->set_background(false);
menu_modelview->set_border(true);
+ menu_closebutton = new ui::Button(menu_modelpane, "Close","view hide");
+
// text pane (right)
menu_textpane = new ui::Window(this);
menu_textpane->set_label("textpane");
@@ -48,12 +48,14 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
menu_namelabel->set_border(false);
menu_namelabel->set_font(ui::root()->font_large());
menu_namelabel->set_alignment(ui::AlignCenter);
- menu_buybutton = new ui::Button(menu_textpane, "Buy");
+
menu_scrollpane = new ui::ScrollPane(menu_textpane, menu_infotext);
menu_scrollpane->set_background(false);
menu_scrollpane->set_border(false);
menu_scrollpane->set_alignment(ui::AlignTop);
+ menu_buybutton = new ui::Button(menu_textpane, "Buy");
+
menu_infotimestamp = 0;
menu_inforecord = 0;
diff --git a/src/client/client.cc b/src/client/client.cc
index 47af682..1fa2796 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -426,6 +426,7 @@ void Client::func_ui_help()
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 visible list visible widgets" << std::endl;
con_print << " ui restart reload user interface files" << std::endl;
}
@@ -451,6 +452,8 @@ void Client::func_ui(std::string const &args)
ui::UI::ui_debug = !ui::UI::ui_debug;
} else if (command.compare("list") == 0) {
ui::root()->list();
+ } else if (command.compare("visible") == 0) {
+ ui::root()->list_visible();
} else if (command.compare("restart") == 0) {
ui::root()->load_menus();
ui::root()->load_settings();
diff --git a/src/client/map.cc b/src/client/map.cc
index 805957c..a2a353a 100644
--- a/src/client/map.cc
+++ b/src/client/map.cc
@@ -18,21 +18,6 @@
namespace client {
-bool is_valid_map_target(core::Entity *entity)
-{
- if (entity->serverside()) {
- return false;
- } else if (entity == core::localcontrol()) {
- return false;
- } else if (entity->flag_is_set(core::Entity::ShowOnMap)) {
- return true;
- } else if (entity == core::localplayer()->mission_target()) {
- return true;
- } else {
- return false;
- }
-}
-
Map::Map(ui::Widget *parent) : ui::Window(parent)
{
set_label("map");
@@ -141,7 +126,7 @@ void Map::draw()
bool draw_icon = false;
l.assign(v);
- if (is_valid_map_target(entity)) {
+ if (targets::is_valid_map_target(entity)) {
draw_icon = true;
l.x -= s / scale * entity->location().y;
l.y -= s / scale * entity->location().x;
@@ -253,9 +238,10 @@ bool Map::on_keypress(const int key, const unsigned int modifier)
if (key == 512 + SDL_BUTTON_LEFT) {
if (hover()) {
core::Entity *target = core::localplayer()->zone()->find_entity(hover());
- if (is_valid_map_target(target)) {
+ if (targets::is_valid_map_target(target)) {
map_target = target;
- audio::play("ui/target");
+ targets::select_target(map_target);
+ //audio::play("ui/target");
}
}
return true;
diff --git a/src/client/playerview.cc b/src/client/playerview.cc
index a37cd73..e75cd47 100644
--- a/src/client/playerview.cc
+++ b/src/client/playerview.cc
@@ -21,15 +21,17 @@ PlayerView::PlayerView(ui::Widget *parent) : ui::Widget(parent)
view_lastentity = 0;
+ view_notify = new Notifications(this);
+ view_hud = new HUD(this);
+
label_viewname = new ui::Label(this);
+ label_viewname->set_label("viewnamelabel");
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_entitymenu = new EntityMenu(this);
view_buymenu = new BuyMenu(this);
diff --git a/src/client/targets.cc b/src/client/targets.cc
index 0bec6c5..c634557 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -53,6 +53,21 @@ bool is_valid_hud_target(core::Entity *entity)
}
}
+bool is_valid_map_target(core::Entity *entity)
+{
+ if (entity->serverside()) {
+ return false;
+ } else if (entity == core::localcontrol()) {
+ return false;
+ } else if (entity->flag_is_set(core::Entity::ShowOnMap)) {
+ return true;
+ } else if (entity == core::localplayer()->mission_target()) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
core::Entity* current()
{
return current_target;
@@ -358,7 +373,7 @@ void frame()
}
// find the current target
- if (!core::localplayer()->view() && core::localcontrol() && is_valid_hud_target(entity)) {
+ if (!core::localplayer()->view() && core::localcontrol() && (is_valid_hud_target(entity) || is_valid_map_target(entity))) {
if (entity->id() == current_target_id) {
current_target = entity;
diff --git a/src/client/targets.h b/src/client/targets.h
index 67ee742..d421300 100644
--- a/src/client/targets.h
+++ b/src/client/targets.h
@@ -22,9 +22,12 @@ void shutdown();
void reset();
-/// return true if the entity is a legal target
+/// return true if the entity is a legal hud target
bool is_valid_hud_target(core::Entity *entity);
+/// return true if the entity is a legal map target
+bool is_valid_map_target(core::Entity *entity);
+
/// render targets and sounds
void frame();
diff --git a/src/core/info.h b/src/core/info.h
index cc480bf..678c48d 100644
--- a/src/core/info.h
+++ b/src/core/info.h
@@ -25,6 +25,7 @@ class Info
public:
/// create a new labeled information record
Info(const std::string & label);
+
/// delete the information record
~Info();
diff --git a/src/core/item.cc b/src/core/item.cc
index ed73cb6..116685b 100644
--- a/src/core/item.cc
+++ b/src/core/item.cc
@@ -9,24 +9,24 @@
namespace core
{
-Item::Item(const unsigned int itemclass, const unsigned int itemtype, const char *infolabel)
+ItemClass::ItemClass(const char *label)
{
- item_class = itemclass;
- item_type = itemtype;
- item_amount = 0;
-
- if (infolabel) {
- item_infolabel.assign(infolabel);
+ if (label) {
+ itemclass_label.assign(label);
} else {
- item_infolabel.clear();
+ itemclass_label.clear();
}
}
-Item::~Item()
+ItemType::ItemType(const char *label)
{
- item_class = 0;
- item_type = 0;
- item_amount = 0;
+ if (label) {
+ itemtype_label.assign(label);
+ } else {
+ itemtype_label.clear();
+ }
+
+ itemtype_baseprice = 0;
}
-} \ No newline at end of file
+}
diff --git a/src/core/item.h b/src/core/item.h
index 68b6876..d390c2d 100644
--- a/src/core/item.h
+++ b/src/core/item.h
@@ -11,22 +11,45 @@
namespace core {
-class Item
+/**
+ * @brief a class of items
+ * Examples are armor, cannons, commodities...
+ */
+class ItemClass
{
public:
- Item(const unsigned int itemclass, const unsigned int itemtype, const char *infolabel);
- ~Item();
+ ItemClass(const char *label);
- inline const unsigned int itemclass() const { return item_class; }
- inline const unsigned int itemtype() const { return item_type; }
-
+ inline const std::string &label() { return itemclass_label; }
+
+ inline const std::string &name() { return itemclass_name; }
+
+private:
+ std::string itemclass_label;
+ std::string itemclass_name;
+};
+
+/**
+ * @brief a specific type of item in the game
+ * Examples are tritanium hull armor, ion cannon, gems
+ */
+class ItemType
+{
+public:
+ ItemType(const char *label);
+
+ inline const std::string &label() { return itemtype_label; }
+
+ inline const std::string &name() { return itemtype_name; }
+
+ inline const float base_price() { return itemtype_baseprice; }
private:
- unsigned int item_class;
- unsigned int item_type;
- float item_amount;
+ std::string itemtype_label;
+ std::string itemtype_name;
- std::string item_infolabel;
+ ItemClass *itemtype_class;
+ float itemtype_baseprice;
};
}
diff --git a/src/core/parser.cc b/src/core/parser.cc
index 2cf0e39..0cee506 100644
--- a/src/core/parser.cc
+++ b/src/core/parser.cc
@@ -67,10 +67,10 @@ bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity)
return true;
} else if (inifile.got_key_vector3f("location", entity->entity_location)) {
return true;
- } else if (inifile.got_key_color("color", entity->entity_color)) {
- return true;
} else if (inifile.got_key_color("colorsecond", entity->entity_color_second)) {
return true;
+ } else if (inifile.got_key_color("color", entity->entity_color)) {
+ return true;
}
return false;
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index da060b9..4128af8 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -195,17 +195,27 @@ void Game::func_dock(core::Player *player, core::Entity *entity)
void Game::func_buy(core::Player *player, const std::string &args)
{
std::istringstream is(args);
+ std::string itemclass;
std::string itemtype;
- if (!(is >> itemtype)) {
- player->send("usage: buy [string] [string] buy type of item, name of item");
+
+ if (!(is >> itemclass)) {
+ player->send("usage: buy [string] [string] buy an item of a specified class and type");
return;
+ } else {
+ aux::to_label(itemclass);
+ }
+
+ if (!(is >> itemtype)) {
+ itemtype.clear();
+ } else {
+ aux::to_label(itemtype);
}
- aux::to_label(itemtype);
- if ((args.size() > 5 ) && (itemtype.compare("ship") == 0)) {
- ShipDealer::func_buy(player, args.substr(5, args.size() - 5));
+
+ if (itemclass.compare("ship") == 0) {
+ ShipDealer::func_buy(player, itemtype);
} else {
- player->send("unkown item type '" + itemtype + "'");
+ player->send("unkown item class '" + itemclass + "'");
}
return;
diff --git a/src/game/base/shipdealer.cc b/src/game/base/shipdealer.cc
index e28b922..feef432 100644
--- a/src/game/base/shipdealer.cc
+++ b/src/game/base/shipdealer.cc
@@ -88,7 +88,7 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args)
helpstr.append("^N|^B");
helpstr.append((*smit).second->label());
}
- player->send("Usage: buy [^B" + helpstr + "^N]");
+ player->send("Usage: buy ship [^B" + helpstr + "^N]");
return;
}
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index b3802f7..9d905d6 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -107,6 +107,9 @@ ShipModel *ShipModel::find(ShipModel *shipmodel)
ShipModel *ShipModel::find(const std::string label)
{
+ if (!label.size())
+ return 0;
+
std::map<std::string, ShipModel *>::iterator it = registry.find(label);
if (it == registry.end())
return 0;
@@ -116,6 +119,9 @@ ShipModel *ShipModel::find(const std::string label)
ShipModel *ShipModel::search(const std::string searchname)
{
+ if (!searchname.size())
+ return 0;
+
std::string strsearchkey(aux::lowercase(searchname));
if (strsearchkey.size() < 3) {
return 0;
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index 11dd318..e3816cd 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -22,6 +22,8 @@ ModelView::ModelView(Widget *parent, const char *modelname) : Widget(parent)
set_label("modelview");
set_modelname(modelname);
+
+ modelview_zoom = 1.0f;
}
ModelView::~ModelView()
@@ -51,6 +53,29 @@ void ModelView::set_color(const math::Color & color)
modelview_color.assign(color);
}
+void ModelView::set_zoom(const float zoom)
+{
+ modelview_zoom = zoom;
+ math::clamp(modelview_zoom, 1.0f, 10.0f);
+}
+
+bool ModelView::on_keypress(const int key, const unsigned int modifier)
+{
+ if (key == 512 + SDL_BUTTON_WHEELUP) {
+ modelview_zoom -= 0.1f;
+ if (modelview_zoom < 1.0f)
+ modelview_zoom = 1.0f;
+ return true;
+ } else if (key == 512 + SDL_BUTTON_WHEELDOWN) {
+ modelview_zoom += 0.1f;
+ if (modelview_zoom > 10.0f)
+ modelview_zoom = 10.0f;
+ return true;
+ }
+
+ return false;
+}
+
void ModelView::draw()
{
if (!modelview_modelname.size())
@@ -68,7 +93,7 @@ void ModelView::draw()
gl::clear(GL_DEPTH_BUFFER_BIT);
// gl 3d mode
- render::Camera::frustum_default(model->radius(), center.x, center.y);
+ render::Camera::frustum_default(model->radius() * modelview_zoom, center.x, center.y);
gl::disable(GL_BLEND);
gl::depthmask(GL_TRUE); // enable writing to the depth buffer
diff --git a/src/ui/modelview.h b/src/ui/modelview.h
index 1fbb4d9..c9855db 100755
--- a/src/ui/modelview.h
+++ b/src/ui/modelview.h
@@ -33,6 +33,14 @@ public:
/// print modelview description
virtual void print(const size_t indent) const;
+
+ /**
+ * @brief set the zoom out factor
+ * @param zoom the new zoom factor
+ * The zoom factor will be clamped to the range [1.0-10.0]
+ * 1.0 is not zoomed out, 10.0 is zoomed out by a factor of 10
+ */
+ void set_zoom(const float zoom);
protected:
/// draw the widget
@@ -41,9 +49,13 @@ protected:
/// draw border
void draw_border();
+ /// keypress event handler
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
private:
std::string modelview_modelname;
math::Color modelview_color;
+ float modelview_zoom;
};
}
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index b7d1155..b60a65e 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -375,6 +375,12 @@ void UI::list() const
con_print << n << " user interface widgets" << std::endl;
}
+void UI::list_visible() const
+{
+ size_t n = Widget::list(0, true);
+ con_print << n << " visible user interface widgets" << std::endl;
+}
+
UI::Menus::iterator UI::find_menu(Window *menu)
{
Menus::iterator it;
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 6216ba7..2e4bc50 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -27,6 +27,9 @@ public:
/// list widgets
void list() const;
+
+ /// list visible widgets
+ void list_visible() const;
/// list meus
void list_menus() const;
diff --git a/src/ui/widget.cc b/src/ui/widget.cc
index 15fa10f..cc53c9f 100644
--- a/src/ui/widget.cc
+++ b/src/ui/widget.cc
@@ -47,12 +47,15 @@ void Widget::remove_children()
widget_children.clear();
}
-size_t Widget::list(const size_t indent) const
+size_t Widget::list(const size_t indent, const bool visible_only) const
{
+ if (visible_only && !visible())
+ return 0;
+
print(indent);
size_t n = 1;
for (Children::const_iterator it = widget_children.begin(); it != widget_children.end(); it++) {
- n += (*it)->list(indent+1);
+ n += (*it)->list(indent+1, visible_only);
}
return n;
}
diff --git a/src/ui/widget.h b/src/ui/widget.h
index d8969cc..2de7a3d 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -231,7 +231,7 @@ protected:
Widget *find_mouse_focus(const math::Vector2f & cursor);
/// list widget content
- size_t list(const size_t indent) const;
+ size_t list(const size_t indent, const bool visible_only = false) const;
/// print widget description
virtual void print(const size_t indent) const;