Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@telenet.be>2021-11-21 17:30:54 +0100
committerStijn Buys <ingar@telenet.be>2021-11-21 17:30:54 +0100
commit7823c639c51d0c3b25e9b05821b3c1292b258e22 (patch)
treec03b8291d9053714287dfa99e946d5b8b2fdf5b3
parent16472132ada3393ede71e1c6d648c80841608ebb (diff)
Added connect menu prototype.
-rw-r--r--src/client/Makefile.am2
-rw-r--r--src/client/mainmenu.cc3
-rw-r--r--src/client/serverlistmenu.cc173
-rw-r--r--src/client/serverlistmenu.h70
4 files changed, 247 insertions, 1 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 21704f4..fbb075f 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -43,6 +43,7 @@ noinst_HEADERS = \
playersettingsmenu.h \
reputationwindow.h \
savegamemenu.h \
+ serverlistmenu.h \
soundext.h \
targeticonbutton.h \
targets.h \
@@ -85,6 +86,7 @@ libclient_la_SOURCES = \
playersettingsmenu.cc \
reputationwindow.cc \
savegamemenu.cc \
+ serverlistmenu.cc \
soundext.cc \
targeticonbutton.cc \
targets.cc \
diff --git a/src/client/mainmenu.cc b/src/client/mainmenu.cc
index 823ebfb..0e61655 100644
--- a/src/client/mainmenu.cc
+++ b/src/client/mainmenu.cc
@@ -11,6 +11,7 @@
#include "client/mainmenu.h"
#include "client/playersettingsmenu.h"
#include "client/savegamemenu.h"
+#include "client/serverlistmenu.h"
#include "core/core.h"
#include "core/gameinterface.h"
#include "core/application.h"
@@ -218,7 +219,7 @@ void MainMenu::load()
mainmenu_optionsmenu = 0;
// menu to connect to remote servers
- mainmenu_connectmenu = 0;
+ mainmenu_connectmenu = (ui::Widget *) new ServerListMenu(this, "connect");
// load game menu
mainmenu_loadmenu = (ui::Widget *) new SaveGameMenu(this, "load", SaveGameMenu::Load);
diff --git a/src/client/serverlistmenu.cc b/src/client/serverlistmenu.cc
new file mode 100644
index 0000000..44bd302
--- /dev/null
+++ b/src/client/serverlistmenu.cc
@@ -0,0 +1,173 @@
+/*
+ client/serverlistmenu.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "client/serverlistmenu.h"
+#include "client/closeiconbutton.h"
+
+#include "ui/ui.h"
+
+#include "core/commandbuffer.h"
+
+#include "sys/sys.h"
+
+
+namespace client
+{
+
+ServerListMenu::ServerListMenu(ui::Widget *parent, const char *label) :
+ ui::Window(parent)
+{
+ set_label(label);
+ set_border(true);
+ set_background(true);
+ set_font(ui::root()->font_small());
+
+ // window title
+ serverlistmenu_titlelabel = new ui::Label(this);
+ serverlistmenu_titlelabel->set_label("connect");
+ serverlistmenu_titlelabel->set_text("CONNECT");
+ serverlistmenu_titlelabel->set_background(false);
+ serverlistmenu_titlelabel->set_border(false);
+ serverlistmenu_titlelabel->set_font(ui::root()->font_large());
+ serverlistmenu_titlelabel->set_alignment(ui::AlignCenter);
+
+ // close button
+ serverlistmenu_closebutton = new CloseIconButton(serverlistmenu_titlelabel);
+
+ // server listview
+ serverlistmenu_serverlistview = new ui::ListView(this);
+ serverlistmenu_serverlistview->set_label("files");
+
+ // save button
+ serverlistmenu_connectbutton = new ui::Button(this, "Connect");
+ serverlistmenu_connectbutton->set_label("connect");
+}
+
+ServerListMenu::~ServerListMenu()
+{
+}
+
+void ServerListMenu::resize()
+{
+ const float padding = ui::UI::padding;
+
+ // resize title label
+ serverlistmenu_titlelabel->set_size(width() - padding * 2.0f, serverlistmenu_titlelabel->font()->height());
+ serverlistmenu_titlelabel->set_location(padding, padding);
+
+ // resize close button
+ serverlistmenu_closebutton->set_size(serverlistmenu_titlelabel->font()->height(), serverlistmenu_titlelabel->font()->height());
+ serverlistmenu_closebutton->set_location(serverlistmenu_titlelabel->width() - serverlistmenu_closebutton->width(), 0);
+
+ // resize files listview
+ serverlistmenu_serverlistview->set_size(
+ width() - padding * 2.0f,
+ height() - ui::UI::elementsize.height() - padding * 3.0f - serverlistmenu_titlelabel->bottom()
+ );
+ serverlistmenu_serverlistview->set_location(
+ padding,
+ serverlistmenu_titlelabel->bottom() + padding
+ );
+
+ // resize connect button
+ serverlistmenu_connectbutton->set_size(ui::UI::elementsize);
+ serverlistmenu_connectbutton->set_location(
+ (width() - padding * 2.0f - serverlistmenu_connectbutton->width()) * 0.5f,
+ height() - padding - serverlistmenu_connectbutton->height()
+ );
+}
+
+void ServerListMenu::refresh()
+{
+ const float padding = ui::UI::padding;
+
+ serverlistmenu_serverlistview->clear();
+ serverlistmenu_connectbutton->show();
+ serverlistmenu_connectbutton->disable();
+
+ // FIXME support custom port numbers
+ ui::ListItem *listitem = new ui::ListItem(serverlistmenu_serverlistview, "osirion.org development server");
+ listitem->set_value("osirion.org");
+ listitem->set_sortkey("");
+
+ listitem->set_font(ui::root()->font_tiny());
+ listitem->set_height(listitem->font()->height() + padding);
+
+ serverlistmenu_serverlistview->sort(false);
+ serverlistmenu_serverlistview->event_resize();
+
+}
+
+void ServerListMenu::hide()
+{
+ Window::hide();
+}
+
+void ServerListMenu::show()
+{
+ Window::show();
+ refresh();
+}
+
+void ServerListMenu::show_connect_info()
+{
+ if (!serverlistmenu_serverlistview->selected()) {
+ serverlistmenu_connectbutton->disable();
+ } else {
+ serverlistmenu_connectbutton->enable();
+ }
+}
+
+void ServerListMenu::connect()
+{
+ if (serverlistmenu_serverlistview->selected()) {
+ std::stringstream str;
+ str << "connect " << serverlistmenu_serverlistview->selected()->value();
+ core::CommandBuffer::exec(str.str());
+ }
+}
+
+bool ServerListMenu::on_keypress(const int key, const unsigned int modifier)
+{
+ if (key == SDLK_ESCAPE) {
+ if (visible()) {
+ // hide the parent mainwindow
+ parent()->hide();
+ return true;
+ }
+ }
+ return false;
+}
+
+bool ServerListMenu::on_emit(ui::Widget *sender, const ui::Widget::Event event, void *data)
+{
+ if (sender == serverlistmenu_closebutton) {
+ if (event == ui::Widget::EventButtonClicked) {
+ // hide the parent mainwindow
+ parent()->hide();
+ return true;
+ }
+ } else if (sender == serverlistmenu_connectbutton) {
+ if (event == ui::Widget::EventButtonClicked) {
+ // do the actual connect and close the window
+ parent()->hide();
+ connect();
+ return true;
+ }
+ } else if (sender == serverlistmenu_serverlistview) {
+ if (event == ui::Widget::EventListViewChanged) {
+ show_connect_info();
+ return true;
+ }
+ }
+
+ return Window::on_emit(sender, event, data);
+}
+
+
+} // namespace client
+
+
diff --git a/src/client/serverlistmenu.h b/src/client/serverlistmenu.h
new file mode 100644
index 0000000..6638bd4
--- /dev/null
+++ b/src/client/serverlistmenu.h
@@ -0,0 +1,70 @@
+/*
+ client/serverlistmenu.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_SERVERLISTMENU_H__
+#define __INCLUDED_CLIENT_SERVERLISTMENU_H__
+
+#include "ui/button.h"
+#include "ui/iconbutton.h"
+#include "ui/inputbox.h"
+#include "ui/label.h"
+#include "ui/listview.h"
+#include "ui/window.h"
+
+namespace client
+{
+
+class ServerListMenu : public ui::Window
+{
+public:
+ enum Mode { Save = 0, Load = 1 };
+
+ ServerListMenu(ui::Widget *parent = 0, const char *label = 0);
+ virtual ~ServerListMenu();
+
+protected:
+
+ /// called when the widget receives a key press
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
+ /// called if the widget receives an emit evet
+ virtual bool on_emit(ui::Widget *sender, const ui::Widget::Event event, void *data);
+
+ virtual void resize();
+
+ virtual void show();
+
+ virtual void hide();
+
+ void refresh();
+
+ /**
+ * @brief connect to the currently selected server
+ * */
+ void connect();
+
+ /**
+ * @brief show information for the currently selected server
+ * */
+ void show_connect_info();
+
+private:
+
+ ui::Label *serverlistmenu_titlelabel;
+ ui::IconButton *serverlistmenu_closebutton;
+ ui::ListView *serverlistmenu_serverlistview;
+ ui::Button *serverlistmenu_connectbutton;
+
+
+}; // class ServerListMenu
+
+
+} // namespace client
+
+
+#endif // __INCLUDED_CLIENT_SERVERLISTMENU_H__
+
+