From 9414c30773f15a0b198779375e1bff9af579bb8a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 4 Nov 2012 00:46:20 -0400 Subject: [PATCH] handle menu choices in run() --- src/client/Client.cc | 41 +++++++++++++++++++++++------------------ src/client/Client.h | 3 +++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 6edc28c..a4effce 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -1,7 +1,6 @@ #include #include "Client.h" #include "Types.h" -#include /* TODO: this should be moved to common somewhere */ #define MAX_SHOT_DISTANCE 250.0 @@ -94,7 +93,22 @@ void Client::run(bool fullscreen, int width, int height, std::string pname) m_clock.restart(); recenter_cursor(); - run_main_menu(); + bool in_game = true; + while (in_game) + { + run_main_menu(); + switch (m_menu_action) + { + case MAIN_MENU_SINGLE: + start_server(); + run_client(); + stop_server(); + break; + case MAIN_MENU_EXIT: + in_game = false; + break; + } + } } void Client::play_single_player_game_button_clicked() @@ -113,7 +127,6 @@ void Client::run_main_menu() m_window->resetGLStates(); m_menu_action = MAIN_MENU_NONE; - sfg::SFGUI sfgui; sfg::Box::Ptr box = sfg::Box::Create(sfg::Box::VERTICAL, 10.0f); sfg::Button::Ptr btn_singleplayer = sfg::Button::Create("Play Single Player Game"); @@ -177,24 +190,11 @@ void Client::run_main_menu() desktop.Update(m_clock.restart().asSeconds()); m_window->clear(); - sfgui.Display(*m_window); + m_sfgui.Display(*m_window); m_window->display(); if (m_menu_action != MAIN_MENU_NONE) - { - switch (m_menu_action) - { - case MAIN_MENU_SINGLE: - start_server(); - run_client(); - m_window->resetGLStates(); - break; - case MAIN_MENU_EXIT: - in_menu = false; - break; - } - m_menu_action = MAIN_MENU_NONE; - } + break; } } @@ -203,6 +203,11 @@ void Client::start_server() /* TODO */ } +void Client::stop_server() +{ + /* TODO */ +} + void Client::run_client() { m_window->setMouseCursorVisible(false); diff --git a/src/client/Client.h b/src/client/Client.h index b8b3909..3a15d89 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -14,6 +14,7 @@ #include "GLMatrix.h" #include "GLBuffer.h" #include "Network.h" +#include #define SHOT_RING_WIDTH 10.0f @@ -35,6 +36,7 @@ class Client protected: void run_main_menu(); void start_server(); + void stop_server(); void run_client(); void connect(int port, const char *host); void disconnect(); @@ -59,6 +61,7 @@ class Client void play_single_player_game_button_clicked(); void exit_button_clicked(); + sfg::SFGUI m_sfgui; int m_menu_action; bool m_mouse_grabbed; double m_player_dir_x;