From 50ba3d5e1e9f9eeda049a348efa4645af07610bc Mon Sep 17 00:00:00 2001 From: oroborus Date: Thu, 14 Aug 2008 14:47:44 +0000 Subject: - novy widget widget_choicegroup - moznost ukladat a nacitavat rozohranu hru ( uklada sa pomocou F2) ( neda sa ulozit sietovy multiplayer, a este nie je dokonce ulozenie hranie s AI ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@195 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/screen/screen_gameType.c | 168 ++++++++++++++++++++++++++++++------------- 1 file changed, 120 insertions(+), 48 deletions(-) (limited to 'src/screen/screen_gameType.c') diff --git a/src/screen/screen_gameType.c b/src/screen/screen_gameType.c index bafa747..986b5dd 100644 --- a/src/screen/screen_gameType.c +++ b/src/screen/screen_gameType.c @@ -5,6 +5,8 @@ #include "main.h" #include "list.h" +#include "director.h" +#include "homeDirector.h" #include "net_multiplayer.h" #include "tux.h" @@ -24,7 +26,8 @@ #include "widget_button.h" #include "widget_image.h" #include "widget_textfield.h" -#include "widget_check.h" +#include "widget_choicegroup.h" +#include "widget_select.h" static widget_image_t *image_backgorund; @@ -35,17 +38,23 @@ static widget_button_t *button_browser; static widget_label_t *label_none; static widget_label_t *label_server; static widget_label_t *label_client; +static widget_label_t *label_load_session; static widget_label_t *label_ip; static widget_label_t *label_port; +static widget_label_t *label_session; -static widget_check_t *check_none; -static widget_check_t *check_server; -static widget_check_t *check_client; +static list_t *listChoiceGroup; +static widget_choicegroup_t *check_none; +static widget_choicegroup_t *check_server; +static widget_choicegroup_t *check_client; +static widget_choicegroup_t *check_load_session; static widget_textfield_t *textfield_ip; static widget_textfield_t *textfield_port; +static widget_select_t *selectSession; + void startScreenGameType() { #ifndef NO_SOUND @@ -59,13 +68,24 @@ void startScreenGameType() void drawScreenGameType() { + int i; + drawWidgetImage(image_backgorund); + for( i = 0 ; i < listChoiceGroup->count ; i++ ) + { + widget_choicegroup_t *this; + + this = (widget_choicegroup_t *)listChoiceGroup->list[i]; + drawWidgetChoicegroup(this); + } + drawWidgetLabel(label_none); drawWidgetLabel(label_server); drawWidgetLabel(label_client); + drawWidgetLabel(label_load_session); - if( check_none->status == FALSE ) + if( check_server->status == TRUE || check_client->status == TRUE ) { drawWidgetLabel(label_port); drawWidgetTextfield(textfield_port); @@ -73,6 +93,12 @@ void drawScreenGameType() drawWidgetTextfield(textfield_ip); } + if( check_load_session->status == TRUE ) + { + drawWidgetLabel(label_session); + drawWidgetSelect(selectSession); + } + #if 0 if( check_server->status == TRUE ) { @@ -83,11 +109,7 @@ void drawScreenGameType() if( check_client->status == TRUE ) drawWidgetButton(button_browser); - - drawWidgetCheck(check_none); - drawWidgetCheck(check_server); - drawWidgetCheck(check_client); - + drawWidgetButton(button_back); drawWidgetButton(button_play); @@ -95,12 +117,26 @@ void drawScreenGameType() void eventScreenGameType() { - eventWidgetCheck(check_none); - eventWidgetCheck(check_server); - eventWidgetCheck(check_client); + int i; + + for( i = 0 ; i < listChoiceGroup->count ; i++ ) + { + widget_choicegroup_t *this; + + this = (widget_choicegroup_t *)listChoiceGroup->list[i]; + eventWidgetChoicegroup(this); + } + + if( check_server->status == TRUE || check_client->status == TRUE ) + { + eventWidgetTextfield(textfield_ip); + eventWidgetTextfield(textfield_port); + } - eventWidgetTextfield(textfield_ip); - eventWidgetTextfield(textfield_port); + if( check_load_session->status == TRUE ) + { + eventWidgetSelect(selectSession); + } eventWidgetButton(button_back); eventWidgetButton(button_play); @@ -116,34 +152,8 @@ void stopScreenGameType() static void eventWidget(void *p) { widget_button_t *button; - widget_check_t *check; button = (widget_button_t *)(p); - check = (widget_check_t *)(p); - - if( check == check_none ) - { - check_none->status = TRUE; - check_server->status = FALSE; - check_client->status = FALSE; - return; - } - - if( check == check_server ) - { - check_none->status = FALSE; - check_server->status = TRUE; - check_client->status = FALSE; - return; - } - - if( check == check_client ) - { - check_none->status = FALSE; - check_server->status = FALSE; - check_client->status = TRUE; - return; - } if( button == button_back ) { @@ -152,6 +162,16 @@ static void eventWidget(void *p) if( button == button_play ) { + char *str; + + str = getGemeTypeLoadSession(); + + if( str != NULL ) + { + setScreen("world"); + return; + } + if( getSettingGameType() == NET_GAME_TYPE_CLIENT ) { setScreen("world"); @@ -168,6 +188,33 @@ static void eventWidget(void *p) } } +static void loadSession(widget_select_t *p) +{ + director_t *director; + int i; + + director = loadDirector(getHomeDirector()); + + if( director == NULL ) + { + return; + } + + for( i = 0 ; i < director->list->count ; i++ ) + { + char *line; + + line = director->list->list[i]; + + if( strstr(line, ".sav") != NULL ) + { + addToWidgetSelect(p, strdup(line)); + } + } + + destroyDirector(director); +} + void initScreenGameType() { image_t *image; @@ -179,9 +226,11 @@ void initScreenGameType() button_play = newWidgetButton(getMyText("PLAY"), WINDOW_SIZE_X-200, WINDOW_SIZE_Y-100, eventWidget); button_browser = newWidgetButton(getMyText("BROWSER"), 300, 345, eventWidget); - check_none = newWidgetCheck(100, 150, FALSE, eventWidget); - check_server = newWidgetCheck(100, 200, FALSE, eventWidget); - check_client = newWidgetCheck(100, 250, FALSE, eventWidget); + listChoiceGroup = newList(); + check_none = newWidgetChoicegroup(100, 150, FALSE, listChoiceGroup, eventWidget); + check_server = newWidgetChoicegroup(100, 200, FALSE, listChoiceGroup, eventWidget); + check_client = newWidgetChoicegroup(100, 250, FALSE, listChoiceGroup, eventWidget); + check_load_session = newWidgetChoicegroup(100, 300, FALSE, listChoiceGroup, eventWidget); if( isParamFlag("--server") ) { @@ -199,9 +248,11 @@ void initScreenGameType() label_none = newWidgetLabel(getMyText("NONE"), 130, 145, WIDGET_LABEL_LEFT); label_server = newWidgetLabel(getMyText("SERVER"), 130, 195, WIDGET_LABEL_LEFT); label_client = newWidgetLabel(getMyText("CLIENT"), 130, 245, WIDGET_LABEL_LEFT); + label_load_session = newWidgetLabel("load session", 130, 295, WIDGET_LABEL_LEFT); label_ip = newWidgetLabel(getMyText("IP_ADDR"), 300, 145, WIDGET_LABEL_LEFT); label_port = newWidgetLabel(getMyText("NET_PORT"), 300, 245, WIDGET_LABEL_LEFT); + label_session = newWidgetLabel("load session :", 300, 145, WIDGET_LABEL_LEFT); textfield_ip = newWidgetTextfield( getParamElse("--ip", "127.0.0.1"), @@ -213,6 +264,9 @@ void initScreenGameType() WIDGET_TEXTFIELD_FILTER_NUM, 300, 280); + selectSession = newWidgetSelect(300, 175, eventWidget); + loadSession(selectSession); + registerScreen( newScreen("gameType", startScreenGameType, eventScreenGameType, drawScreenGameType, stopScreenGameType) ); } @@ -226,7 +280,8 @@ int setSettingGameType(int status) int getSettingGameType() { - if( check_none->status == TRUE ) + if( check_none->status == TRUE || + check_load_session->status == TRUE ) { return NET_GAME_TYPE_NONE; } @@ -246,6 +301,16 @@ int getSettingGameType() return -1; } +char* getGemeTypeLoadSession() +{ + if( check_load_session->status == TRUE ) + { + return getWidgetSelectItem(selectSession); + } + + return NULL; +} + int setSettingIP(char *address) { strcpy (textfield_ip->text, address); @@ -293,19 +358,26 @@ void quitScreenGameType() destroyWidgetLabel(label_none); destroyWidgetLabel(label_server); destroyWidgetLabel(label_client); + destroyWidgetLabel(label_load_session); destroyWidgetLabel(label_ip); destroyWidgetLabel(label_port); + destroyWidgetLabel(label_session); destroyWidgetTextfield(textfield_ip); destroyWidgetTextfield(textfield_port); + destroyWidgetSelect(selectSession); + destroyWidgetButton(button_back); destroyWidgetButton(button_play); destroyWidgetButton(button_browser); - destroyWidgetCheck(check_none); - destroyWidgetCheck(check_server); - destroyWidgetCheck(check_client); + destroyWidgetChoicegroup(check_none); + destroyWidgetChoicegroup(check_server); + destroyWidgetChoicegroup(check_client); + destroyWidgetChoicegroup(check_load_session); + + destroyList(listChoiceGroup); } -- cgit v1.2.3