Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-10-13 15:38:03 +0000
committerStijn Buys <ingar@osirion.org>2012-10-13 15:38:03 +0000
commit5dea1a263136c4cbe011de3325605dd3dc4523af (patch)
tree6da09a6007a148d5fe13254f275bb68b71242429
parent3b8ea0849fac5532d61a90608bda876cf518ba1b (diff)
Added dialog infrastructure.
-rw-r--r--src/client/Makefile.am2
-rw-r--r--src/client/dialog.cc72
-rw-r--r--src/client/dialog.h48
-rw-r--r--src/client/mainmenu.cc49
-rw-r--r--src/client/mainmenu.h3
-rw-r--r--src/client/mainwindow.cc3
6 files changed, 171 insertions, 6 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 7b3c69b..1baefd8 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -15,6 +15,7 @@ noinst_HEADERS = \
chat.h \
client.h \
clientext.h \
+ dialog.h \
entitymenu.h \
galaxymapwidget.h \
gamewindow.h \
@@ -46,6 +47,7 @@ libclient_la_SOURCES = \
chat.cc \
client.cc \
clientext.cc \
+ dialog.cc \
entitymenu.cc \
galaxymapwidget.cc \
gamewindow.cc \
diff --git a/src/client/dialog.cc b/src/client/dialog.cc
new file mode 100644
index 0000000..f113433
--- /dev/null
+++ b/src/client/dialog.cc
@@ -0,0 +1,72 @@
+/*
+ client/dialog.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 "client/dialog.h"
+#include "ui/ui.h"
+
+namespace client
+{
+
+Dialog::Dialog(ui::Widget * parent) :
+ ui::Window(parent)
+{
+ set_border(false);
+ set_background(false);
+ set_label("dialog");
+
+ dialog_widget = new ui::Widget(this);
+ dialog_widget->set_border(true);
+ dialog_widget->set_background(true);
+
+ dialog_label = new ui::Label(dialog_widget);
+ dialog_label->set_border(false);
+ dialog_label->set_background(false);
+ dialog_label->set_alignment(ui::AlignTop | ui::AlignHCenter);
+
+ dialog_button = new ui::Button(dialog_widget);
+}
+
+Dialog::~Dialog()
+{
+}
+
+void Dialog::set_text(const std::string &text)
+{
+ dialog_label->set_text(text);
+}
+
+void Dialog::set_button(const std::string &text)
+{
+ dialog_button->set_text(text);
+}
+
+void Dialog::set_command(const std::string &command)
+{
+ dialog_button->set_command(command);
+}
+
+void Dialog::resize()
+{
+ const float padding = ui::root()->font_large()->height();
+
+ dialog_widget->set_size(
+ ui::UI::elementsize.width() * 3.0f,
+ ui::UI::elementsize.width() * 2.0f
+ );
+ dialog_widget->set_location(
+ (width() - dialog_widget->width()) * 0.5f,
+ (height() - dialog_widget->height()) * 0.5f
+ );
+
+ dialog_label->set_size(dialog_widget->width() - padding * 2.0f, dialog_widget->height() - padding * 2.0f);
+ dialog_label->set_location(padding, padding);
+
+ dialog_button->set_size(ui::UI::elementsize);
+ dialog_button->set_location((dialog_widget->width() - dialog_button->width()) * 0.5f,
+ dialog_widget->height() - dialog_button->height() - padding);
+}
+
+} // namespace client
diff --git a/src/client/dialog.h b/src/client/dialog.h
new file mode 100644
index 0000000..63926f9
--- /dev/null
+++ b/src/client/dialog.h
@@ -0,0 +1,48 @@
+/*
+ client/dialog.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_DIALOG_H__
+#define __INCLUDED_CLIENT_DIALOG_H__
+
+#include "ui/window.h"
+#include "ui/button.h"
+#include "ui/label.h"
+
+namespace client
+{
+
+/**
+ * @brief a generic dialog window class
+ * */
+class Dialog : public ui::Window
+{
+public:
+ Dialog(ui::Widget *parent = 0);
+ virtual ~Dialog();
+
+ void set_text(const std::string &text);
+
+ void set_button(const std::string &text);
+
+ void set_command(const std::string &command);
+
+protected:
+ virtual void resize();
+
+private:
+
+ /// the actual dialog widget
+ ui::Widget *dialog_widget;
+
+ ui::Label *dialog_label;
+ ui::Button *dialog_button;
+};
+
+}
+
+#endif // __INCLUDED_CLIENT_DIALOG_H__
+
+
diff --git a/src/client/mainmenu.cc b/src/client/mainmenu.cc
index cfed85f..7271bcf 100644
--- a/src/client/mainmenu.cc
+++ b/src/client/mainmenu.cc
@@ -5,6 +5,7 @@
*/
#include "client/buttonmenu.h"
+#include "client/dialog.h"
#include "client/mainmenu.h"
#include "client/savegamemenu.h"
#include "core/core.h"
@@ -62,6 +63,7 @@ void MainMenu::load_definitions()
con_debug << " Loading menu definitions..." << std::endl;
+ Dialog *dialog = 0;
ui::Label *label = 0;
ui::Button *button = 0;
ButtonMenu *menu = 0;
@@ -72,6 +74,13 @@ void MainMenu::load_definitions()
if (ini.got_section()) {
if (ini.got_section("menu")) {
+ dialog = 0;
+ menu = 0;
+ continue;
+
+ // dialog
+ } else if (ini.got_section("dialog")) {
+ dialog = 0;
menu = 0;
continue;
@@ -83,6 +92,7 @@ void MainMenu::load_definitions()
} else {
button = menu->add_button();
}
+ continue;
// menu label
} else if (ini.got_section("label")) {
@@ -92,6 +102,7 @@ void MainMenu::load_definitions()
} else {
label = menu->add_label();
}
+ continue;
} else {
ini.unknown_section();
@@ -99,18 +110,46 @@ void MainMenu::load_definitions()
}
} else if (ini.got_key()) {
-
- if (ini.in_section("menu")) {
+
+ if (ini.in_section("dialog")) {
+ if (!dialog) {
+ if (ini.got_key_label("label", strval)) {
+ dialog = new Dialog(this);
+ dialog->set_label(strval);
+ }
+ } else {
+
+ if (ini.got_key_label("label", strval)) {
+ dialog->set_label(strval);
+
+ } else if (ini.got_key_string("text", strval)) {
+ dialog->set_text(strval);
+
+ } else if (ini.got_key_string("button", strval)) {
+ dialog->set_button(strval);
+
+ } else if (ini.got_key_string("command", strval)) {
+ for (size_t i = 0; i <= strval.size(); i++) {
+ if (strval[i] == ',') strval[i] = ';';
+ }
+ aux::strip_quotes(strval);
+ dialog->set_command(strval);
+ } else {
+ ini.unknown_key();
+ }
+ }
+
+ } else if (ini.in_section("menu")) {
- if (ini.got_key_string("label", strval)) {
- aux::to_label(strval);
+ if (ini.got_key_label("label", strval)) {
for (ui::Widget::Children::iterator child = children().begin(); child != children().end(); ++child) {
if ((*child)->label().compare(strval) == 0) {
+ // assert child is a menu
menu = static_cast<ButtonMenu*>((*child));
}
}
-
+
if (!menu) {
menu = new ButtonMenu(this, strval.c_str());
}
diff --git a/src/client/mainmenu.h b/src/client/mainmenu.h
index 0a0354c..8b1ec58 100644
--- a/src/client/mainmenu.h
+++ b/src/client/mainmenu.h
@@ -9,10 +9,11 @@
#include "ui/window.h"
#include "ui/bitmap.h"
+#include "client/dialog.h"
namespace client
{
-
+
/**
* @brief the client's main menu window
* The MainMenu contains a number of child menu windows,
diff --git a/src/client/mainwindow.cc b/src/client/mainwindow.cc
index 66244de..2f3f66a 100644
--- a/src/client/mainwindow.cc
+++ b/src/client/mainwindow.cc
@@ -124,6 +124,9 @@ void MainWindow::draw()
mainwindow_gamewindow->hide();
mainwindow_mainmenu->show();
+ } else if (core::localcontrol()->state() == core::Entity::Destroyed) {
+ mainwindow_mainmenu->show_menu("respawn");
+
} else if (mainwindow_gamewindow->hidden()) {
mainwindow_gamewindow->show();
}