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/CMakeLists.txt | 4 +- src/base/arena.c | 3 + src/base/arena.h | 4 + src/client/saveDialog.c | 160 +++++++++++++++++++++++++ src/client/saveDialog.h | 21 ++++ src/client/saveLoad.c | 258 ++++++++++++++++++++++++++++++++++++++++ src/client/saveLoad.h | 12 ++ src/screen/screen_gameType.c | 168 ++++++++++++++++++-------- src/screen/screen_gameType.h | 1 + src/screen/screen_world.c | 43 +++++-- src/widget/widget_choicegroup.c | 103 ++++++++++++++++ src/widget/widget_choicegroup.h | 31 +++++ src/widget/widget_select.c | 12 +- src/widget/widget_select.h | 1 + 14 files changed, 758 insertions(+), 63 deletions(-) create mode 100644 src/client/saveDialog.c create mode 100644 src/client/saveDialog.h create mode 100644 src/client/saveLoad.c create mode 100644 src/client/saveLoad.h create mode 100644 src/widget/widget_choicegroup.c create mode 100644 src/widget/widget_choicegroup.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6401af2..fad14e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,11 +9,11 @@ ${WORKDIR}/net/udp ${WORKDIR}/net/tcp ${WORKDIR}/net/dns ) SET ( SRC_client -${WORKDIR}/client/layer ${WORKDIR}/client/term ${WORKDIR}/client/screen ${WORKDIR}/client/interface ${WORKDIR}/client/client ${WORKDIR}/client/chat ${WORKDIR}/client/configFile ${WORKDIR}/client/language ${WORKDIR}/client/font ${WORKDIR}/client/game ${WORKDIR}/client/radar ${WORKDIR}/client/panel ${WORKDIR}/client/image ${WORKDIR}/client/keyboardBuffer ${WORKDIR}/client/pauza +${WORKDIR}/client/layer ${WORKDIR}/client/term ${WORKDIR}/client/screen ${WORKDIR}/client/interface ${WORKDIR}/client/client ${WORKDIR}/client/chat ${WORKDIR}/client/configFile ${WORKDIR}/client/language ${WORKDIR}/client/font ${WORKDIR}/client/game ${WORKDIR}/client/radar ${WORKDIR}/client/panel ${WORKDIR}/client/image ${WORKDIR}/client/keyboardBuffer ${WORKDIR}/client/pauza ${WORKDIR}/client/saveDialog ${WORKDIR}/client/saveLoad ${WORKDIR}/screen/screen_choiceArena ${WORKDIR}/screen/screen_settingKeys ${WORKDIR}/screen/screen_table ${WORKDIR}/screen/screen_setting ${WORKDIR}/screen/screen_credits ${WORKDIR}/screen/screen_world ${WORKDIR}/screen/screen_analyze ${WORKDIR}/screen/screen_mainMenu ${WORKDIR}/screen/screen_browser ${WORKDIR}/screen/screen_gameType -${WORKDIR}/widget/widget_check ${WORKDIR}/widget/widget_button ${WORKDIR}/widget/widget_textfield ${WORKDIR}/widget/widget_label ${WORKDIR}/widget/widget_buttonimage ${WORKDIR}/widget/widget_image ${WORKDIR}/widget/widget_select ${WORKDIR}/widget/widget_catchkey +${WORKDIR}/widget/widget_check ${WORKDIR}/widget/widget_button ${WORKDIR}/widget/widget_textfield ${WORKDIR}/widget/widget_label ${WORKDIR}/widget/widget_buttonimage ${WORKDIR}/widget/widget_image ${WORKDIR}/widget/widget_select ${WORKDIR}/widget/widget_catchkey ${WORKDIR}/widget/widget_choicegroup ) SET ( SRC_audio ${WORKDIR}/audio/audio ${WORKDIR}/audio/music ${WORKDIR}/audio/sound) diff --git a/src/base/arena.c b/src/base/arena.c index f7e917d..019dbb4 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -61,6 +61,9 @@ arena_t* newArena(int w, int h) new->spaceItem = newSpace(w, h, zone_w, zone_h, getStatusItem, setStatusItem); new->spaceShot = newSpace(w, h, zone_w, zone_h, getStatusShot, setStatusShot); + new->countRound = 0; + new->max_countRound = 0; + return new; } diff --git a/src/base/arena.h b/src/base/arena.h index 9512222..2adf0c5 100644 --- a/src/base/arena.h +++ b/src/base/arena.h @@ -29,6 +29,10 @@ typedef struct arena_struct space_t *spaceShot; space_t *spaceTux; space_t *spaceItem; + + int countRound; + int max_countRound; + } arena_t; extern void setCurrentArena(arena_t *p); diff --git a/src/client/saveDialog.c b/src/client/saveDialog.c new file mode 100644 index 0000000..0595d1e --- /dev/null +++ b/src/client/saveDialog.c @@ -0,0 +1,160 @@ + +#include +#include + +#include "main.h" +#include "list.h" +#include "myTimer.h" +#include "tux.h" +#include "space.h" +#include "arena.h" +#include "net_multiplayer.h" + +#include "interface.h" +#include "saveDialog.h" +#include "image.h" +#include "font.h" +#include "saveLoad.h" + +#include "widget_label.h" +#include "widget_button.h" +#include "widget_textfield.h" + +static image_t *g_background; +static bool_t activeSaveDialog; +static my_time_t lastActive; + +static widget_label_t *widgetLabelMsg; +static widget_textfield_t *widgetTextFieldName; + +static widget_button_t *widgetButtonSave; +static widget_button_t *widgetButtonBack; + +static void switchTerm() +{ + if( activeSaveDialog == TRUE ) + { + activeSaveDialog = FALSE; + } + else + { + activeSaveDialog = TRUE; + } +} + +static void eventWidget(void *p) +{ + widget_button_t *button; + + button = (widget_button_t *)p; + + if( button == widgetButtonSave ) + { + saveArena(widgetTextFieldName->text, getCurrentArena()); + switchTerm(); + } + + if( button == widgetButtonBack ) + { + switchTerm(); + } +} + +void initSaveDialog() +{ + activeSaveDialog = FALSE; + lastActive = getMyTime(); + + g_background = getImage(IMAGE_GROUP_BASE, "screen_main"); + + widgetLabelMsg = newWidgetLabel( + "name", + SAVE_DIALOG_LOCATIN_X+20, + SAVE_DIALOG_LOCATIN_Y+20, + WIDGET_LABEL_LEFT); + + widgetTextFieldName = newWidgetTextfield( + "noname", + WIDGET_TEXTFIELD_FILTER_ALPHANUM, + widgetLabelMsg->x+widgetLabelMsg->w+10, + widgetLabelMsg->y); + + widgetButtonSave = newWidgetButton( + "Save", + SAVE_DIALOG_LOCATIN_X+20, + SAVE_DIALOG_LOCATIN_Y+60, + eventWidget); + + widgetButtonBack = newWidgetButton( + "Back", + SAVE_DIALOG_LOCATIN_X+20+WIDGET_BUTTON_WIDTH+20, + SAVE_DIALOG_LOCATIN_Y+60, + eventWidget); +} + +bool_t isSaveDialogActive() +{ + return activeSaveDialog; +} + +void drawSaveDialog() +{ + if( activeSaveDialog == FALSE ) + { + return; + } + + drawImage(g_background, + SAVE_DIALOG_LOCATIN_X, + SAVE_DIALOG_LOCATIN_Y, + SAVE_DIALOG_LOCATIN_X, + SAVE_DIALOG_LOCATIN_Y, + SAVE_DIALOG_SIZE_X, SAVE_DIALOG_SIZE_Y); + + drawWidgetLabel(widgetLabelMsg); + drawWidgetTextfield(widgetTextFieldName); + drawWidgetButton(widgetButtonSave); + drawWidgetButton(widgetButtonBack); +} + +void eventSaveDialog() +{ + my_time_t currentTime; + Uint8 *mapa; + + if( getNetTypeGame() != NET_GAME_TYPE_NONE ) + { + return; + } + + mapa = SDL_GetKeyState(NULL); + + currentTime = getMyTime(); + + if( mapa[SDLK_F2] == SDL_PRESSED ) + { + if( currentTime - lastActive > SAVEDIALOG_ACTIVE_TIME_INTERVAL ) + { + lastActive = currentTime; + switchTerm(); + } + } + + if( activeSaveDialog == FALSE ) + { + return; + } + + eventWidgetTextfield(widgetTextFieldName); + eventWidgetButton(widgetButtonSave); + eventWidgetButton(widgetButtonBack); + +} + +void quitSaveDialog() +{ + destroyWidgetLabel(widgetLabelMsg); + destroyWidgetTextfield(widgetTextFieldName); + destroyWidgetButton(widgetButtonSave); + destroyWidgetButton(widgetButtonBack); +} diff --git a/src/client/saveDialog.h b/src/client/saveDialog.h new file mode 100644 index 0000000..0849bdb --- /dev/null +++ b/src/client/saveDialog.h @@ -0,0 +1,21 @@ + +#ifndef SAVE_DIALOG_H + +#define SAVE_DIALOG_H + +#define SAVEDIALOG_ACTIVE_TIME_INTERVAL 500 + +#define SAVE_DIALOG_SIZE_X 320 +#define SAVE_DIALOG_SIZE_Y 120 + +#define SAVE_DIALOG_LOCATIN_X (WINDOW_SIZE_X/2 - SAVE_DIALOG_SIZE_X/2) +#define SAVE_DIALOG_LOCATIN_Y (WINDOW_SIZE_Y/2 - SAVE_DIALOG_SIZE_Y/2) + + +extern void initSaveDialog(); +extern bool_t isSaveDialogActive(); +extern void drawSaveDialog(); +extern void eventSaveDialog(); +extern void quitSaveDialog(); + +#endif diff --git a/src/client/saveLoad.c b/src/client/saveLoad.c new file mode 100644 index 0000000..a31bc64 --- /dev/null +++ b/src/client/saveLoad.c @@ -0,0 +1,258 @@ + +#include +#include +#include +#include + +#include "textFile.h" +#include "homeDirector.h" + +#include "arena.h" +#include "arenaFile.h" +#include "tux.h" +#include "shot.h" +#include "item.h" + +#include "saveLoad.h" + +#include "screen_choiceArena.h" +#include "screen_world.h" + +static void action_saveTux(space_t *space, tux_t *tux, textFile_t *textFile) +{ + char str[STR_PROTO_SIZE]; + + snprintf(str, STR_PROTO_SIZE, + "TUX %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", + tux->id, tux->x, tux->y, tux->status, tux->position ,tux->control, tux->frame, tux->score, tux->name, + tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE], + tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], tux->shot[GUN_LASSER], + tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL], + tux->bonus_time, tux->pickup_time); + + addList(textFile->text, strdup(str)); +} + +static void action_saveShot(space_t *space, shot_t *shot, textFile_t *textFile) +{ + char str[STR_PROTO_SIZE]; + + snprintf(str, STR_PROTO_SIZE, "SHOT %d %d %d %d %d %d %d %d %d", + shot->id, shot->x, shot->y, shot->px, shot->py, + shot->position, shot->gun, shot->author_id, shot->isCanKillAuthor); + + addList(textFile->text, strdup(str)); +} + +static void action_saveItem(space_t *space, item_t *item, textFile_t *textFile) +{ + char str[STR_PROTO_SIZE]; + + snprintf(str, STR_PROTO_SIZE, "ITEM %d %d %d %d %d %d %d", + item->id, item->type, item->x, item->y, + item->count, item->frame, item->author_id); + + addList(textFile->text, strdup(str)); +} + +static void saveContextArenaToTextFile(textFile_t *textFile, arena_t *arena) +{ + char str[STR_PROTO_SIZE]; + + sprintf(str, "ARENA %s %d %d", + getArenaNetName(getChoiceArenaId()), + arena->countRound, + arena->max_countRound); + + addList(textFile->text, strdup(str)); + + actionSpace(arena->spaceTux, action_saveTux, textFile); + actionSpace(arena->spaceShot, action_saveShot, textFile); + actionSpace(arena->spaceItem, action_saveItem, textFile); +} + +void saveArena(char *filename, arena_t *arena) +{ + textFile_t *textFile; + char path[STR_PATH_SIZE]; + + sprintf(path, "%s/%s.sav", getHomeDirector(), filename); + printf("path = %s\n", path); + + textFile = newTextFile(path); + + if( textFile != NULL ) + { + saveContextArenaToTextFile(textFile, arena); + saveTextFile(textFile); + destroyTextFile(textFile); + } + else + { + fprintf(stderr, "Do not save %s\n", path); + } +} + +static arena_t* loadArenaFromLine(char *line) +{ + char cmd[STR_SIZE]; + char name[STR_SIZE]; + int countRound; + int max_countRound; + arena_t *arena; + + sscanf(line, "%s %s %d %d", cmd, name, &countRound, &max_countRound); + + setWorldArena( getArenaIdFormNetName(name) ); + setMaxCountRound(max_countRound); + arena = getCurrentArena(); + arena->countRound = countRound; + + return arena; +} + +static void loadTuxFromLine(char *line, arena_t *arena) +{ + char cmd[STR_PROTO_SIZE]; + char name[STR_NAME_SIZE]; + int id, x, y, status, position, frame, score, control; + int myGun, myBonus; + int gun1, gun2, gun3, gun4, gun5, gun6, gun7; + int time1, time2; + tux_t *tux; + + sscanf(line, "%s %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d", + cmd, &id, &x, &y, &status, &position, &control, &frame, &score, name, + &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2); + + tux = newTux(); + replaceTuxID(tux, id); + addObjectToSpace(arena->spaceTux, tux); + + tux->control = control; + + if( tux->control == TUX_CONTROL_KEYBOARD_RIGHT ) + { + setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT); + } + + if( tux->control == TUX_CONTROL_KEYBOARD_LEFT ) + { + setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT); + } + + moveObjectInSpace(arena->spaceTux, tux, x, y); + tux->status = status; + tux->position = position; + tux->frame = frame; + tux->score = score; + strcpy(tux->name, name); + tux->gun = myGun; + tux->bonus = myBonus; + tux->shot[GUN_SIMPLE] = gun1; + tux->shot[GUN_DUAL_SIMPLE] = gun2; + tux->shot[GUN_SCATTER] = gun3; + tux->shot[GUN_TOMMY] = gun4; + tux->shot[GUN_LASSER] = gun5; + tux->shot[GUN_MINE] = gun6; + tux->shot[GUN_BOMBBALL] = gun7; + tux->bonus_time = time1; + tux->pickup_time = time2; +} + +static void loadShotFromLine(char *line, arena_t *arena) +{ + char cmd[STR_PROTO_SIZE]; + int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor; + shot_t *shot; + + sscanf(line, "%s %d %d %d %d %d %d %d %d %d", + cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id, &isCanKillAuthor); + + shot = newShot(x, y, px, py, gun, author_id); + + replaceShotID(shot, shot_id); + shot->isCanKillAuthor = isCanKillAuthor; + shot->position = position; + + if( shot->gun == GUN_LASSER ) + { + transformOnlyLasser(shot); + } + + addObjectToSpace(arena->spaceShot, shot); +} + +static void loadItemFromLine(char *line, arena_t *arena) +{ + char cmd[STR_PROTO_SIZE]; + int id, type, x, y, count, frame, author_id, check_id; + item_t *item; + + sscanf(line, "%s %d %d %d %d %d %d %d %d", + cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id); + + item = newItem(x, y, type, author_id); + + replaceItemID(item, id); + item->count = count; + item->frame = frame; + + addObjectToSpace(arena->spaceItem, item); +} + +static arena_t* loadContextArenaFromTextFile(textFile_t *textFile) +{ + arena_t *arena; + int i; + + for( i = 0 ; i < textFile->text->count ; i++ ) + { + char *line; + + line = (char *)textFile->text->list[i]; + + if( strncmp(line, "ARENA", 5) == 0 ) + { + arena = loadArenaFromLine(line); + } + + if( strncmp(line, "TUX", 3) == 0 ) + { + loadTuxFromLine(line, arena); + } + + if( strncmp(line, "SHOT", 4) == 0 ) + { + loadShotFromLine(line, arena); + } + + if( strncmp(line, "ITEM", 4) == 0 ) + { + loadItemFromLine(line, arena); + } + } + + return arena; +} + +void loadArena(char *filename) +{ + textFile_t *textFile; + char path[STR_PATH_SIZE]; + + sprintf(path, "%s/%s", getHomeDirector(), filename); + printf("path = %s\n", path); + + textFile = loadTextFile(path); + + if( textFile != NULL ) + { + loadContextArenaFromTextFile(textFile); + destroyTextFile(textFile); + } + else + { + fprintf(stderr, "Do not load %s\n", path); + } +} diff --git a/src/client/saveLoad.h b/src/client/saveLoad.h new file mode 100644 index 0000000..875e1f8 --- /dev/null +++ b/src/client/saveLoad.h @@ -0,0 +1,12 @@ + +#ifndef SAVELOAD_H + +#define SAVELOAD_H + +#include "textFile.h" +#include "arena.h" + +extern void saveArena(char *filename, arena_t *arena); +extern void loadArena(char *filename); + +#endif 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); } diff --git a/src/screen/screen_gameType.h b/src/screen/screen_gameType.h index 1d9b734..28976e0 100644 --- a/src/screen/screen_gameType.h +++ b/src/screen/screen_gameType.h @@ -10,6 +10,7 @@ extern void eventScreenGameType(); extern void initScreenGameType(); extern int setSettingGameType(int status); extern int getSettingGameType(); +extern char* getGemeTypeLoadSession(); extern int setSettingIP(char *address); extern char* getSettingIP(); extern int setSettingPort(int port); diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c index 12da3a1..e619bbb 100644 --- a/src/screen/screen_world.c +++ b/src/screen/screen_world.c @@ -27,6 +27,8 @@ #include "chat.h" #include "pauza.h" #include "term.h" +#include "saveDialog.h" +#include "saveLoad.h" #ifndef NO_SOUND #include "music.h" @@ -43,8 +45,6 @@ static arena_t *arena; -static int count; -static int max_count; static bool_t isScreenWorldInit = FALSE; static bool_t isEndWorld; @@ -80,7 +80,12 @@ void setWorldArena(int id) void setMaxCountRound(int n) { - max_count = n; + arena->max_countRound = n; +} + +int getMaxCountRound() +{ + return arena->max_countRound; } void setWorldEnd() @@ -99,16 +104,16 @@ static void timer_endArena() void countRoundInc() { - if( count == WORLD_COUNT_ROUND_UNLIMITED || - count >= max_count ) + if( arena->max_countRound == WORLD_COUNT_ROUND_UNLIMITED || + arena->countRound >= arena->max_countRound ) { return; } - count++; + arena->countRound++; //printf("count %d/%d\n", count, max_count); - if( count >= max_count ) + if( arena->countRound >= arena->max_countRound ) { //printf("count %d ending\n", count); #ifndef NO_SOUND @@ -128,12 +133,18 @@ void prepareArena() tuxWithControlRightKeyboard = NULL; tuxWithControlLeftKeyboard = NULL; + if( getGemeTypeLoadSession() != NULL ) + { + loadArena(getGemeTypeLoadSession()); + return; + } + switch( getNetTypeGame() ) { case NET_GAME_TYPE_NONE : setWorldArena( getChoiceArenaId() ); addNewItem(arena->spaceItem, ID_UNKNOWN); - getSettingCountRound(&max_count); + getSettingCountRound(&arena->max_countRound); tux = newTux(); tux->control = TUX_CONTROL_KEYBOARD_RIGHT; @@ -156,12 +167,15 @@ void prepareArena() tux->control = TUX_CONTROL_AI; } } + + //printf("getGemeTypeLoadSession = %s\n", getGemeTypeLoadSession()); + break; case NET_GAME_TYPE_SERVER : setWorldArena( getChoiceArenaId() ); addNewItem(arena->spaceItem, ID_UNKNOWN); - getSettingCountRound(&max_count); + getSettingCountRound(&arena->max_countRound); tux = newTux(); tux->control = TUX_CONTROL_KEYBOARD_RIGHT; @@ -192,6 +206,7 @@ void drawWorld() drawChat(); drawPauza(); drawTerm(); + drawSaveDialog(); } static void netAction(tux_t *tux, int action) @@ -460,7 +475,7 @@ void eventWorld() eventNetMultiplayer(); - if( isPauzeActive() == FALSE ) + if( isPauzeActive() == FALSE && isSaveDialogActive() == FALSE ) { eventArena(arena); //eventModule(); @@ -487,6 +502,8 @@ void eventWorld() eventChat(); eventPauza(); eventTerm(); + eventSaveDialog(); + eventEsc(); } @@ -495,12 +512,12 @@ void startWorld() arena = NULL; isEndWorld = FALSE; - count = 0; - initListID(); initRadar(); initPauza(); initTerm(); + initSaveDialog(); + initModule(); setGameType(); initChat(); @@ -563,6 +580,8 @@ void stoptWorld() quitRadar(); quitPauza(); quitTerm(); + quitSaveDialog(); + #ifndef NO_SOUND stopMusic(); diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c new file mode 100644 index 0000000..5404461 --- /dev/null +++ b/src/widget/widget_choicegroup.c @@ -0,0 +1,103 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "image.h" +#include "widget_choicegroup.h" + +widget_choicegroup_t* newWidgetChoicegroup(int x, int y, bool_t status, list_t *list, void (*fce_event)(void *)) +{ + widget_choicegroup_t *new; + + new = malloc( sizeof(widget_choicegroup_t) ); + new->x = x; + new->y = y; + new->time = 0; + new->status = status; + new->fce_event = fce_event; + new->list = list; + addList(new->list, new); + + return new; +} + +void drawWidgetChoicegroup(widget_choicegroup_t *p) +{ + static image_t *g_choicegroup = NULL; + int x, y; + int offset; + + getMousePosition(&x, &y); + + if( g_choicegroup == NULL ) + { + g_choicegroup = addImageData("check.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE); + } + + if( p->status == TRUE ) + { + offset = 0; + } + else + { + offset = WIDGET_CHOICEGROUP_WIDTH; + } + + drawImage(g_choicegroup, p->x, p->y, offset, 0, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); +} + +static void setActive(widget_choicegroup_t *p) +{ + int i; + + for( i = 0 ; i < p->list->count ; i++ ) + { + widget_choicegroup_t *this; + + this = (widget_choicegroup_t *) p->list->list[i]; + + if( this == p ) + { + this->status = TRUE; + this->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; + this->fce_event(p); + } + else + { + this->status = FALSE; + } + } +} + +void eventWidgetChoicegroup(widget_choicegroup_t *p) +{ + int x, y; + + if( p->time > 0 ) + { + p->time--; + return; + } + + getMousePosition(&x, &y); + + if( x >= p->x && x <= p->x+WIDGET_CHOICEGROUP_WIDTH && + y >= p->y && y <= p->y+WIDGET_CHOICEGROUP_HEIGHT && + isMouseClicked() ) + { + setActive(p); + } +} + +void destroyWidgetChoicegroup(widget_choicegroup_t *p) +{ + int index; + + index = searchListItem(p->list, p); + assert( index != -1 ); + delList(p->list, index); + + free(p); +} diff --git a/src/widget/widget_choicegroup.h b/src/widget/widget_choicegroup.h new file mode 100644 index 0000000..93d88fc --- /dev/null +++ b/src/widget/widget_choicegroup.h @@ -0,0 +1,31 @@ + +#ifndef WIDGET_CHOICEGROUP_H + +#define WIDGET_CHOICEGROUP_H + +#include "main.h" +#include "list.h" + +#define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 + +#define WIDGET_CHOICEGROUP_WIDTH 25 +#define WIDGET_CHOICEGROUP_HEIGHT 25 + +typedef struct widget_choicegroup +{ + int x, y; + bool_t status; + int time; + void (*fce_event)(void *); + list_t *list; +} widget_choicegroup_t; + +extern widget_choicegroup_t* newWidgetChoicegroup(int x, int y, bool_t status, + list_t *list, void (*fce_event)(void *)); + +extern void drawWidgetChoicegroup(widget_choicegroup_t *p); +extern void eventWidgetChoicegroup(widget_choicegroup_t *p); +extern void destroyWidgetChoicegroup(widget_choicegroup_t *p); + +#endif + diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c index 35a462b..3ab5638 100644 --- a/src/widget/widget_select.c +++ b/src/widget/widget_select.c @@ -22,13 +22,23 @@ widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *)) new = malloc( sizeof(widget_select_t) ); new->x = x; new->y = y; - new->select = 0; + new->select = -1; new->fce_event = fce_event; new->list = newList(); return new; } +char* getWidgetSelectItem(widget_select_t *p) +{ + if( p->select == -1 ) + { + return NULL; + } + + return (char *)p->list->list[p->select]; +} + void addToWidgetSelect(widget_select_t *p, char *s) { addList(p->list, strdup(s) ); diff --git a/src/widget/widget_select.h b/src/widget/widget_select.h index a0bb795..0f5f712 100644 --- a/src/widget/widget_select.h +++ b/src/widget/widget_select.h @@ -17,6 +17,7 @@ typedef struct widget_select } widget_select_t; extern widget_select_t* newWidgetSelect(int x, int y, void (*fce_event)(void *)); +extern char* getWidgetSelectItem(widget_select_t *p); extern void addToWidgetSelect(widget_select_t *p, char *s); extern void removeAllFromWidgetSelect(widget_select_t *p); extern void drawWidgetSelect(widget_select_t *p); -- cgit v1.2.3