Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Makefile.am60
-rw-r--r--src/client/client.cc49
-rw-r--r--src/client/client.h9
-rw-r--r--src/client/testmodelview.cc114
-rw-r--r--src/client/testmodelview.h52
5 files changed, 268 insertions, 16 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index d9ca552..c6d0ada 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -8,15 +8,57 @@ noinst_LTLIBRARIES = libclient.la
endif
-noinst_HEADERS = action.h chat.h client.h clientext.h hud.h entitymenu.h \
- input.h inventorylistview.h inventory.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 \
- targeticonbutton.h
-
-libclient_la_SOURCES = action.cc buymenu.cc chat.cc client.cc clientext.cc \
- entitymenu.cc hud.cc infowidget.cc input.cc inventorylistview.cc inventory.cc joystick.cc key.cc \
- keyboard.cc map.cc notifications.cc playerview.cc soundext.cc targeticonbutton.cc \
- targets.cc trademenu.cc video.cc worldview.cc
+noinst_HEADERS = \
+ action.h \
+ buymenu.h \
+ chat.h \
+ client.h \
+ clientext.h \
+ entitymenu.h \
+ hud.h \
+ infowidget.h \
+ input.h \
+ inventory.h \
+ inventorylistview.h \
+ joystick.h \
+ key.h \
+ keyboard.h \
+ map.h \
+ notifications.h \
+ playerview.h \
+ soundext.h \
+ targeticonbutton.h \
+ targets.h \
+ testmodelview.h \
+ trademenu.h \
+ video.h \
+ worldview.h
+
+libclient_la_SOURCES = \
+ action.cc \
+ buymenu.cc \
+ chat.cc \
+ client.cc \
+ clientext.cc \
+ entitymenu.cc \
+ hud.cc \
+ infowidget.cc \
+ input.cc \
+ inventorylistview.cc \
+ inventory.cc \
+ joystick.cc \
+ key.cc \
+ keyboard.cc \
+ map.cc \
+ notifications.cc \
+ playerview.cc \
+ soundext.cc \
+ targeticonbutton.cc \
+ targets.cc \
+ testmodelview.cc \
+ trademenu.cc \
+ video.cc \
+ worldview.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
diff --git a/src/client/client.cc b/src/client/client.cc
index 318a0d4..ec2d002 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -102,8 +102,12 @@ void Client::init(int count, char **arguments)
// initialize user interface
ui::init();
- client_worldview = new WorldView(ui::root());
+ client_worldview = new WorldView(ui::root());
+
+ client_testmodelview = new TestModelView(ui::root());
+ client_testmodelview->hide();
+
// Initialize the video subsystem
if (!video::init()) {
quit(1);
@@ -139,20 +143,23 @@ void Client::init(int count, char **arguments)
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 = core::Func::add("ui_chat", func_ui_chat);
func->set_info("toggle chat window");
- func = core::Func::add("ui_chatbar", Client::func_ui_chatbar);
+ func = core::Func::add("ui_chatbar", func_ui_chatbar);
func->set_info("toggle chat bar");
- func = core::Func::add("ui_inventory", Client::func_ui_inventory);
+ func = core::Func::add("ui_inventory", func_ui_inventory);
func->set_info("toggle inventory");
- func = core::Func::add("ui_map", Client::func_ui_map);
+ func = core::Func::add("ui_map", func_ui_map);
func->set_info("toggle map");
- func = core::Func::add("ui_menu", Client::func_ui_menu);
+ func = core::Func::add("ui_menu", func_ui_menu);
func->set_info("toggle main menu");
+
+ func = core::Func::add("testmodel", func_testmodel);
+ func->set_info("[str] load and view a single 3D model");
func = core::Func::add("menu", func_menu);
func->set_info("[command] menu functions");
@@ -239,6 +246,14 @@ void Client::frame(unsigned long timestamp)
} else if (core::game()->time() && !core::localcontrol()) {
ui::root()->show_menu("join");
}
+
+ if (testmodelview()->visible()) {
+ testmodelview()->raise();
+ }
+ if (ui::console()->visible()) {
+ ui::console()->raise();
+ ui::console()->set_focus();
+ }
} else {
if (core::localcontrol()) {
@@ -572,6 +587,26 @@ void Client::func_menu(std::string const &args)
}
}
+void Client::func_testmodel(std::string const &args)
+{
+ std::string modelname(args);
+ aux::trim(modelname);
+
+ if (!modelname.size()) {
+ con_print << "usage: testmodel [model name]" << std::endl;
+ }
+
+ //video::set_loader_message();
+ //video::frame_loader();
+
+ client()->client_testmodelview->set_modelname(modelname);
+ client()->client_testmodelview->raise(); // raise the window
+ client()->client_testmodelview->show();
-} // namespace client
+ if (ui::console()->visible()) {
+ ui::console()->raise();
+ ui::console()->set_focus();
+ }
+}
+} // namespace client
diff --git a/src/client/client.h b/src/client/client.h
index 288e9fa..a5ce297 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -12,6 +12,7 @@
#include "core/entity.h"
#include "client/clientext.h"
#include "client/soundext.h"
+#include "client/testmodelview.h"
#include "client/worldview.h"
#include "render/renderext.h"
@@ -66,6 +67,11 @@ public:
inline WorldView *worldview() {
return client_worldview;
}
+
+ /// model test widget
+ inline TestModelView *testmodelview() {
+ return client_testmodelview;
+ }
protected:
/// run a client frame
@@ -88,11 +94,14 @@ private:
static void func_ui_inventory(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_testmodel(std::string const &args);
static void func_menu(std::string const &args);
static void func_view(std::string const &args);
WorldView *client_worldview;
+ TestModelView *client_testmodelview;
unsigned long previous_timestamp;
};
diff --git a/src/client/testmodelview.cc b/src/client/testmodelview.cc
new file mode 100644
index 0000000..31dc98f
--- /dev/null
+++ b/src/client/testmodelview.cc
@@ -0,0 +1,114 @@
+/*
+ client/testmodelview.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "ui/ui.h"
+#include "ui/paint.h"
+#include "client/testmodelview.h"
+#include "model/model.h"
+
+namespace client
+{
+
+TestModelView::TestModelView(ui::Widget *parent)
+{
+ set_background(true);
+ set_border(false);
+ set_label("testmodelview");
+ testmodelview_modelview = new ui::ModelView(this);
+ testmodelview_modelview->set_radius(1.0f);
+
+ testmodelview_text = new ui::PlainText(this);
+ testmodelview_text->set_label("text");
+ testmodelview_text->set_background(false);
+ testmodelview_text->set_border(false);
+
+ testmodelview_closebutton = new ui::Button(this);
+ testmodelview_closebutton->set_text("Close");
+ testmodelview_closebutton->set_background(true);
+}
+
+TestModelView::~TestModelView()
+{
+}
+
+void TestModelView::set_modelname(const std::string & modelname)
+{
+ model::Model *model = model::Model::load(modelname);
+ testmodelview_modelview->set_modelname(modelname);
+
+ std::ostringstream str;
+ str << modelname << '\n';
+
+ if (model) {
+ size_t frags = 0;
+
+ for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) {
+ frags += (*git)->size();
+ }
+ str << '\n';
+ str << "tris: " << model->model_tris_count << '\n';
+ str << "quads: " << model->model_quad_count << '\n';
+ str << "fragments: " << frags << '\n';
+ }
+ testmodelview_text->set_text(str.str());
+}
+
+void TestModelView::show()
+{
+ resize();
+ ui::Widget::show();
+}
+
+void TestModelView::hide() {
+ ui::Widget::hide();
+}
+
+void TestModelView::resize()
+{
+ // this view covers the entire screen
+ set_size(parent()->size());
+
+ // resize the label
+ testmodelview_text->set_size(width() - 16.0f, testmodelview_text->font()->height() * 5.0f);
+ testmodelview_text->set_location(8.0f, 8.0f);
+
+ // resize the 3d model view
+ testmodelview_modelview->set_size(width(),height());
+ testmodelview_modelview->set_location(0.0f, 0.0f);
+
+ // reposition close button
+ testmodelview_closebutton->set_size(
+ ui::UI::elementsize.width() * 1.5f,
+ ui::UI::elementsize.height()
+ );
+ testmodelview_closebutton->set_location(
+ width() - testmodelview_closebutton->width() - ui::UI::elementsize.height(),
+ height() - testmodelview_closebutton->height() - ui::UI::elementsize.height() * 0.5f
+ );
+}
+
+void TestModelView::draw_background()
+{
+ math::Color color(palette()->background());
+ color.a = 1.0f;
+ ui::Paint::set_color(color);
+ ui::Paint::draw_rectangle(global_location(), size());
+}
+
+bool TestModelView::on_emit(Widget *sender, const Event event, void *data)
+{
+ if (event == ui::Widget::EventButtonClicked) {
+ // slider value changed
+ if (sender == testmodelview_closebutton) {
+ hide();
+ }
+ return true;
+ }
+ return false;
+}
+
+} // namespace client
+
diff --git a/src/client/testmodelview.h b/src/client/testmodelview.h
new file mode 100644
index 0000000..6b38df6
--- /dev/null
+++ b/src/client/testmodelview.h
@@ -0,0 +1,52 @@
+/*
+ client/testmodelview.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_TESTMODELVIEW_H__
+#define __INCLUDED_CLIENT_TESTMODELVIEW_H__
+
+#include "ui/widget.h"
+#include "ui/button.h"
+#include "ui/plaintext.h"
+#include "ui/modelview.h"
+
+namespace client
+{
+
+/// the world view when connected
+class TestModelView : public ui::Widget
+{
+public:
+ TestModelView(ui::Widget *parent = 0);
+ virtual ~TestModelView();
+
+ void set_modelname(const std::string & modelname);
+
+ /// show the testmodelview
+ virtual void show();
+
+ /// hide the testmodelview
+ virtual void hide();
+
+protected:
+ /// resize te testmodelview
+ virtual void resize();
+
+ /// draw a black background
+ virtual void draw_background();
+
+ /// emit event handler
+ virtual bool on_emit(Widget *sender, const Event event, void *data);
+
+private:
+ ui::ModelView *testmodelview_modelview;
+ ui::Button *testmodelview_closebutton;
+ ui::PlainText *testmodelview_text;
+
+}; // class TestModelView
+
+} // namespace client
+
+#endif // __INCLUDED_CLIENT_TESTMODELVIEW_H__