From ddec3945554d2245e048bc11240f9369b76a255c Mon Sep 17 00:00:00 2001 From: Tomas Chvatal Date: Thu, 12 Mar 2009 18:18:04 +0100 Subject: Renaming of screen files. --- src/CMakeLists.txt | 12 +- src/base/arena.c | 4 +- src/base/gun.c | 2 +- src/base/item.c | 4 +- src/base/net_multiplayer.c | 4 +- src/base/proto.c | 10 +- src/base/proto.h | 6 +- src/base/server.c | 2 +- src/base/serverSendMsg.c | 2 +- src/base/shot.c | 2 +- src/base/tux.c | 2 +- src/base/udp_server.c | 2 +- src/client/chat.c | 2 +- src/client/client.c | 4 +- src/client/game.c | 24 +- src/client/layer.c | 2 +- src/client/saveLoad.c | 4 +- src/screen/analyze.c | 185 ++++++++++ src/screen/analyze.h | 24 ++ src/screen/browser.c | 729 ++++++++++++++++++++++++++++++++++++++++ src/screen/browser.h | 33 ++ src/screen/choiceArena.c | 245 ++++++++++++++ src/screen/choiceArena.h | 19 ++ src/screen/credits.c | 163 +++++++++ src/screen/credits.h | 20 ++ src/screen/downArena.c | 391 +++++++++++++++++++++ src/screen/downArena.h | 22 ++ src/screen/gameType.c | 384 +++++++++++++++++++++ src/screen/gameType.h | 21 ++ src/screen/mainMenu.c | 133 ++++++++ src/screen/mainMenu.h | 15 + src/screen/screen_analyze.c | 185 ---------- src/screen/screen_analyze.h | 24 -- src/screen/screen_browser.c | 729 ---------------------------------------- src/screen/screen_browser.h | 33 -- src/screen/screen_choiceArena.c | 245 -------------- src/screen/screen_choiceArena.h | 19 -- src/screen/screen_credits.c | 163 --------- src/screen/screen_credits.h | 20 -- src/screen/screen_downArena.c | 391 --------------------- src/screen/screen_downArena.h | 22 -- src/screen/screen_gameType.c | 384 --------------------- src/screen/screen_gameType.h | 21 -- src/screen/screen_mainMenu.c | 133 -------- src/screen/screen_mainMenu.h | 15 - src/screen/screen_setting.c | 538 ----------------------------- src/screen/screen_setting.h | 22 -- src/screen/screen_settingKeys.c | 589 -------------------------------- src/screen/screen_settingKeys.h | 27 -- src/screen/screen_table.c | 229 ------------- src/screen/screen_table.h | 17 - src/screen/screen_world.c | 609 --------------------------------- src/screen/screen_world.h | 30 -- src/screen/setting.c | 538 +++++++++++++++++++++++++++++ src/screen/setting.h | 22 ++ src/screen/settingKeys.c | 589 ++++++++++++++++++++++++++++++++ src/screen/settingKeys.h | 27 ++ src/screen/table.c | 229 +++++++++++++ src/screen/table.h | 17 + src/screen/world.c | 609 +++++++++++++++++++++++++++++++++ src/screen/world.h | 30 ++ 61 files changed, 4489 insertions(+), 4489 deletions(-) create mode 100644 src/screen/analyze.c create mode 100644 src/screen/analyze.h create mode 100644 src/screen/browser.c create mode 100644 src/screen/browser.h create mode 100644 src/screen/choiceArena.c create mode 100644 src/screen/choiceArena.h create mode 100644 src/screen/credits.c create mode 100644 src/screen/credits.h create mode 100644 src/screen/downArena.c create mode 100644 src/screen/downArena.h create mode 100644 src/screen/gameType.c create mode 100644 src/screen/gameType.h create mode 100644 src/screen/mainMenu.c create mode 100644 src/screen/mainMenu.h delete mode 100644 src/screen/screen_analyze.c delete mode 100644 src/screen/screen_analyze.h delete mode 100644 src/screen/screen_browser.c delete mode 100644 src/screen/screen_browser.h delete mode 100644 src/screen/screen_choiceArena.c delete mode 100644 src/screen/screen_choiceArena.h delete mode 100644 src/screen/screen_credits.c delete mode 100644 src/screen/screen_credits.h delete mode 100644 src/screen/screen_downArena.c delete mode 100644 src/screen/screen_downArena.h delete mode 100644 src/screen/screen_gameType.c delete mode 100644 src/screen/screen_gameType.h delete mode 100644 src/screen/screen_mainMenu.c delete mode 100644 src/screen/screen_mainMenu.h delete mode 100644 src/screen/screen_setting.c delete mode 100644 src/screen/screen_setting.h delete mode 100644 src/screen/screen_settingKeys.c delete mode 100644 src/screen/screen_settingKeys.h delete mode 100644 src/screen/screen_table.c delete mode 100644 src/screen/screen_table.h delete mode 100644 src/screen/screen_world.c delete mode 100644 src/screen/screen_world.h create mode 100644 src/screen/setting.c create mode 100644 src/screen/setting.h create mode 100644 src/screen/settingKeys.c create mode 100644 src/screen/settingKeys.h create mode 100644 src/screen/table.c create mode 100644 src/screen/table.h create mode 100644 src/screen/world.c create mode 100644 src/screen/world.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5a5464..3e9bf09 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,12 +56,12 @@ SET ( SRC_client ${WORKDIR}/client/pauza ${WORKDIR}/client/saveDialog ${WORKDIR}/client/hotKey - ${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}/screen/screen_downArena + ${WORKDIR}/screen/choiceArena + ${WORKDIR}/screen/settingKeys ${WORKDIR}/screen/table + ${WORKDIR}/screen/setting ${WORKDIR}/screen/credits + ${WORKDIR}/screen/world ${WORKDIR}/screen/analyze + ${WORKDIR}/screen/mainMenu ${WORKDIR}/screen/browser + ${WORKDIR}/screen/gameType ${WORKDIR}/screen/downArena ${WORKDIR}/widget/widget_check ${WORKDIR}/widget/widget_button ${WORKDIR}/widget/widget_textfield ${WORKDIR}/widget/widget_label diff --git a/src/base/arena.c b/src/base/arena.c index 4658e08..effbff4 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -14,8 +14,8 @@ #ifndef PUBLIC_SERVER # include "hotKey.h" -# include "screen_world.h" -# include "screen_setting.h" +# include "world.h" +# include "setting.h" # include "layer.h" #endif diff --git a/src/base/gun.c b/src/base/gun.c index 27f88bd..d357349 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -19,7 +19,7 @@ #endif #ifndef PUBLIC_SERVER # include "interface.h" -# include "screen_world.h" +# include "world.h" #endif #ifdef PUBLIC_SERVER # include "publicServer.h" diff --git a/src/base/item.c b/src/base/item.c index 822d6b4..75074bc 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -19,8 +19,8 @@ # include "radar.h" # include "layer.h" -# include "screen_world.h" -# include "screen_setting.h" +# include "world.h" +# include "setting.h" # ifndef NO_SOUND # include "sound.h" diff --git a/src/base/net_multiplayer.c b/src/base/net_multiplayer.c index 198abe7..d21f81d 100644 --- a/src/base/net_multiplayer.c +++ b/src/base/net_multiplayer.c @@ -15,8 +15,8 @@ #include "udp.h" #ifndef PUBLIC_SERVER -# include "screen_setting.h" -# include "screen_choiceArena.h" +# include "setting.h" +# include "choiceArena.h" # include "screen.h" # include "client.h" diff --git a/src/base/proto.c b/src/base/proto.c index 606dd33..f927dfa 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -21,11 +21,11 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -# include "screen_world.h" -# include "screen_setting.h" -# include "screen_choiceArena.h" -# include "screen_analyze.h" -# include "screen_downArena.h" +# include "world.h" +# include "setting.h" +# include "choiceArena.h" +# include "analyze.h" +# include "downArena.h" # include "client.h" # include "term.h" # include "radar.h" diff --git a/src/base/proto.h b/src/base/proto.h index 590317b..8cd7568 100644 --- a/src/base/proto.h +++ b/src/base/proto.h @@ -18,9 +18,9 @@ # include "net_multiplayer.h" # ifndef PUBLIC_SERVER -# include "screen_world.h" -# include "screen_setting.h" -# include "screen_choiceArena.h" +# include "world.h" +# include "setting.h" +# include "choiceArena.h" # include "client.h" # endif diff --git a/src/base/server.c b/src/base/server.c index 6471b46..49a1c79 100644 --- a/src/base/server.c +++ b/src/base/server.c @@ -33,7 +33,7 @@ #include "downServer.h" #ifndef PUBLIC_SERVER -# include "screen_world.h" +# include "world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/base/serverSendMsg.c b/src/base/serverSendMsg.c index e7d1c09..e38975f 100644 --- a/src/base/serverSendMsg.c +++ b/src/base/serverSendMsg.c @@ -11,7 +11,7 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -# include "screen_world.h" +# include "world.h" #endif static void addMsgClient(client_t * p, char *msg, int type, int id) diff --git a/src/base/shot.c b/src/base/shot.c index 977ccb4..306527b 100644 --- a/src/base/shot.c +++ b/src/base/shot.c @@ -14,7 +14,7 @@ #ifndef PUBLIC_SERVER # include "image.h" # include "layer.h" -# include "screen_world.h" +# include "world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/base/tux.c b/src/base/tux.c index 746679d..5bb2305 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -28,7 +28,7 @@ # include "sound.h" # endif -# include "screen_world.h" +# include "world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/base/udp_server.c b/src/base/udp_server.c index 0e211f3..b61cfef 100644 --- a/src/base/udp_server.c +++ b/src/base/udp_server.c @@ -30,7 +30,7 @@ #include "index.h" #ifndef PUBLIC_SERVER -# include "screen_world.h" +# include "world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/client/chat.c b/src/client/chat.c index 6ca9ec9..b446b08 100644 --- a/src/client/chat.c +++ b/src/client/chat.c @@ -11,7 +11,7 @@ #include "serverSendMsg.h" #include "net_multiplayer.h" -#include "screen_world.h" +#include "world.h" #include "proto.h" #include "interface.h" #include "chat.h" diff --git a/src/client/client.c b/src/client/client.c index 74d6b0a..5aa995b 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -23,8 +23,8 @@ #include "client.h" -#include "screen_analyze.h" -#include "screen_world.h" +#include "analyze.h" +#include "world.h" #include "buffer.h" #include "udp.h" diff --git a/src/client/game.c b/src/client/game.c index e96805b..87676d5 100644 --- a/src/client/game.c +++ b/src/client/game.c @@ -20,7 +20,7 @@ #include "interface.h" #include "screen.h" #include "font.h" -#include "screen_settingKeys.h" +#include "settingKeys.h" #include "panel.h" #include "radar.h" @@ -30,17 +30,17 @@ # include "music.h" #endif -#include "screen_world.h" -#include "screen_mainMenu.h" -#include "screen_analyze.h" -#include "screen_setting.h" -#include "screen_settingKeys.h" -#include "screen_gameType.h" -#include "screen_downArena.h" -#include "screen_choiceArena.h" -#include "screen_table.h" -#include "screen_credits.h" -#include "screen_browser.h" +#include "world.h" +#include "mainMenu.h" +#include "analyze.h" +#include "setting.h" +#include "settingKeys.h" +#include "gameType.h" +#include "downArena.h" +#include "choiceArena.h" +#include "table.h" +#include "credits.h" +#include "browser.h" static void initGame() { diff --git a/src/client/layer.c b/src/client/layer.c index 983a9c8..c50be65 100644 --- a/src/client/layer.c +++ b/src/client/layer.c @@ -10,7 +10,7 @@ #include "layer.h" #include "image.h" -#include "screen_world.h" +#include "world.h" static list_t *listLayer; diff --git a/src/client/saveLoad.c b/src/client/saveLoad.c index b5dbdf2..0448a4f 100644 --- a/src/client/saveLoad.c +++ b/src/client/saveLoad.c @@ -16,8 +16,8 @@ #include "saveLoad.h" -#include "screen_choiceArena.h" -#include "screen_world.h" +#include "choiceArena.h" +#include "world.h" static void action_saveTux(space_t * space, tux_t * tux, textFile_t * textFile) { diff --git a/src/screen/analyze.c b/src/screen/analyze.c new file mode 100644 index 0000000..2153e52 --- /dev/null +++ b/src/screen/analyze.c @@ -0,0 +1,185 @@ + +#include +#include +#include + +#include "main.h" +#include "list.h" + +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +#endif + +#include "mainMenu.h" +#include "analyze.h" + +#include "widget.h" +#include "widget_label.h" +#include "widget_button.h" +#include "widget_image.h" + +static widget_t *image_backgorund; + +static list_t *listWidgetLabelName; +static list_t *listWidgetLabelScore; +static list_t *listAnalyze; +static widget_t *widgetLabelMsg; + +static widget_t *button_ok; + +static analyze_t *newAnalyze(char *name, int score) +{ + analyze_t *new; + + new = malloc(sizeof(analyze_t)); + new->name = strdup(name); + new->score = score; + + return new; +} + +static void destroyAnalyze(analyze_t * p) +{ + free(p->name); + free(p); +} + +static void hotkey_escape() +{ + setScreen("mainMenu"); +} + +void startScreenAnalyze() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} + +void drawScreenAnalyze() +{ + widget_t *this; + int i; + + drawWidgetImage(image_backgorund); + + for (i = 0; i < listWidgetLabelName->count; i++) { + this = (widget_t *) (listWidgetLabelName->list[i]); + drawWidgetLabel(this); + } + + for (i = 0; i < listWidgetLabelScore->count; i++) { + this = (widget_t *) (listWidgetLabelScore->list[i]); + drawWidgetLabel(this); + } + + drawWidgetLabel(widgetLabelMsg); + drawWidgetButton(button_ok); +} + +void eventScreenAnalyze() +{ + eventWidgetButton(button_ok); +} + +void stopScreenAnalyze() +{ + destroyWidgetLabel(widgetLabelMsg); + widgetLabelMsg = newWidgetLabel("", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); + + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_ok) { + setScreen("mainMenu"); + } +} + +void restartAnalyze() +{ + destroyListItem(listWidgetLabelName, destroyWidgetLabel); + destroyListItem(listWidgetLabelScore, destroyWidgetLabel); + destroyListItem(listAnalyze, destroyAnalyze); + + listWidgetLabelName = newList(); + listWidgetLabelScore = newList(); + listAnalyze = newList(); +} + +void addAnalyze(char *name, int score) +{ + addList(listAnalyze, newAnalyze(name, score)); +} + +void setMsgToAnalyze(char *msg) +{ + destroyWidgetLabel(widgetLabelMsg); + widgetLabelMsg = newWidgetLabel(msg, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); +} + +void endAnalyze() +{ + int i; + + for (i = 0; i < listAnalyze->count; i++) { + analyze_t *this; + char *str; + + this = (analyze_t *) (listAnalyze->list[i]); + + addList(listWidgetLabelName, newWidgetLabel(this->name, 100, + 200 + 20 * i, WIDGET_LABEL_LEFT)); + + str = getString(this->score); + + addList(listWidgetLabelScore, newWidgetLabel(str, WINDOW_SIZE_X - 100, + 200 + 20 * i, WIDGET_LABEL_RIGHT)); + + free(str); + } +} + +void initScreenAnalyze() +{ + image_t *image; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + listWidgetLabelName = newList(); + listWidgetLabelScore = newList(); + listAnalyze = newList(); + + button_ok = newWidgetButton("OK", WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 100, eventWidget); + + registerScreen( newScreen("analyze", startScreenAnalyze, eventScreenAnalyze, + drawScreenAnalyze, stopScreenAnalyze)); + + widgetLabelMsg = newWidgetLabel("", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); +} + +void quitScreenAnalyze() +{ + destroyWidgetImage(image_backgorund); + + destroyListItem(listWidgetLabelName, destroyWidgetLabel); + destroyListItem(listWidgetLabelScore, destroyWidgetLabel); + destroyListItem(listAnalyze, destroyAnalyze); + + destroyWidgetButton(button_ok); + destroyWidgetLabel(widgetLabelMsg); +} diff --git a/src/screen/analyze.h b/src/screen/analyze.h new file mode 100644 index 0000000..8f975b4 --- /dev/null +++ b/src/screen/analyze.h @@ -0,0 +1,24 @@ + +#ifndef SCREEN_ANALYZE_H + +# define SCREEN_ANALYZE_H + +# include "main.h" + +typedef struct analyze_struct { + char *name; + int score; +} analyze_t; + +extern void startScreenAnalyze(); +extern void drawScreenAnalyze(); +extern void eventScreenAnalyze(); +extern void stopScreenAnalyze(); +extern void restartAnalyze(); +extern void addAnalyze(char *name, int score); +extern void setMsgToAnalyze(char *msg); +extern void endAnalyze(); +extern void initScreenAnalyze(); +extern void quitScreenAnalyze(); + +#endif diff --git a/src/screen/browser.c b/src/screen/browser.c new file mode 100644 index 0000000..91b3350 --- /dev/null +++ b/src/screen/browser.c @@ -0,0 +1,729 @@ + +#include +#include +#include + +#include "main.h" +#include "list.h" +#include "textFile.h" +#include "homeDirector.h" +#include "net_multiplayer.h" + +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef __WIN32__ +# include +# include +# include +# include +# include +# include +#else +# include +# include +#endif + +#include +#include +#include + +#include "udp.h" +#include "dns.h" + +extern int errno; + +#ifndef NO_SOUND +# include "music.h" +#endif + +#include "gameType.h" +#include "browser.h" + +#include "widget.h" +#include "widget_image.h" +#include "widget_label.h" +#include "widget_button.h" +#include "widget_select.h" + +#define SERVER_TIMEOUT 200 + +static widget_t *image_backgorund; + +static widget_t *button_play; +static widget_t *button_back; +static widget_t *button_refresh; + +static widget_t *label_server; +static widget_t *label_version; +static widget_t *label_address; +static widget_t *label_arena; +static widget_t *label_players; +static widget_t *label_ping; + +static widget_t *select_server; + +static server_t server_list; + +/* function prototypes */ +static int LoadServers(); +static int RefreshServers(); +static server_t *server_getcurr(); + +static void hotkey_escape() +{ + setScreen("gameType"); +} + +void startScreenBrowser() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + + registerHotKey(SDLK_ESCAPE, hotkey_escape); + + LoadServers(); +} + +void drawScreenBrowser() +{ + drawWidgetImage(image_backgorund); + + drawWidgetLabel(label_server); + drawWidgetLabel(label_version); + drawWidgetLabel(label_address); + drawWidgetLabel(label_arena); + drawWidgetLabel(label_players); + drawWidgetLabel(label_ping); + + drawWidgetSelect(select_server); + + drawWidgetButton(button_play); + drawWidgetButton(button_back); + drawWidgetButton(button_refresh); +} + +void eventScreenBrowser() +{ + eventWidgetSelect(select_server); + + eventWidgetButton(button_play); + eventWidgetButton(button_back); + eventWidgetButton(button_refresh); +} + +void stopScreenBrowser() +{ + unsigned i = 0; + server_t *server; + + //destroyListItem(select_server->list, free); + //select_server->list = newList(); + removeAllFromWidgetSelect(select_server); + + unregisterHotKey(SDLK_ESCAPE); + + while (1) { + i = 0; + for (server = server_list.next; server != &server_list; + server = server->next) { + server->next->prev = server->prev; + server->prev->next = server->next; + + if (server->name) + free(server->name); + + if (server->version) + free(server->version); + + if (server->arena) + free(server->arena); + + free(server); + + i++; + break; + } + + if (!i) + return; + } +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_play) { + server_t *server = server_getcurr(); + + if (!server) + return; + + /* server je offline */ + if (!server->state) + return; + + struct in_addr srv; + srv.s_addr = server->ip; + + char *address = (char *) inet_ntoa(srv); + + setSettingGameType(NET_GAME_TYPE_CLIENT); + setSettingIP(address); + setSettingPort(server->port); + + setScreen("world"); + } + + if (button == button_back) { + setScreen("gameType"); + } + + if (button == button_refresh) { + RefreshServers(); + } +} + +server_t *server_getcurr() +{ + unsigned i = 0; + server_t *server; + + for (server = server_list.next; server != &server_list; + server = server->next) { + if (i == getWidgetSelectIndex(select_server)) + return server; + + i++; + } + + return 0; +} + +int server_getinfo(server_t * server) +{ + struct sockaddr_in srv; + int mySocket; + + if ((mySocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { + return -1; + } +#ifndef __WIN32__ + // Lets make socket non-blocking + int oldFlag = fcntl(mySocket, F_GETFL, 0); + if (fcntl(mySocket, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + return -1; + } +#else + unsigned long arg = 1; + // Operation is FIONBIO. Parameter is pointer on non-zero number. + if (ioctlsocket(mySocket, FIONBIO, &arg) == SOCKET_ERROR) { + WSACleanup(); + return -1; + } +#endif + + struct timeval tv; + + fd_set myset; + FD_ZERO(&myset); + FD_SET(mySocket, &myset); + + tv.tv_sec = 2; + tv.tv_usec = 0; + + srv.sin_family = AF_INET; + srv.sin_port = htons(server->port); + srv.sin_addr.s_addr = server->ip; + + if (connect(mySocket, (struct sockaddr *) &srv, sizeof(srv)) == -1) { +#ifndef __WIN32__ + if (errno != EINPROGRESS) + return -1; +#else + if (WSAGetLastError() != WSAEWOULDBLOCK) { + WSACleanup(); + return -1; + } +#endif + } + + int ret = select(mySocket + 1, NULL, &myset, NULL, &tv); + + if (ret == -1) + return 0; + + if (ret == 0) + return -2; + + char request[8]; + memcpy(request, "status\n", 7); + + int r = send(mySocket, request, 7, 0); + + if (r == -1) + return -2; + + FD_ZERO(&myset); + FD_SET(mySocket, &myset); + tv.tv_sec = 1; + tv.tv_usec = 0; + + char *str = (char *) malloc(sizeof(char) * 257); + + if (!str) + return -1; + + while (1) { + int sel = select(mySocket + 1, &myset, NULL, NULL, &tv); + + if (sel == 0) { + free(str); +#ifndef __WIN32__ + close(mySocket); +#else + closesocket(mySocket); + WSACleanup(); +#endif + return -2; + } + + if (sel == -1) { + free(str); +#ifndef __WIN32__ + close(mySocket); +#else + closesocket(mySocket); + WSACleanup(); +#endif + return -2; + } + + if ((ret = recv(mySocket, str, 256, 0)) == -1) { + free(str); +#ifndef __WIN32__ + close(mySocket); +#else + closesocket(mySocket); + WSACleanup(); +#endif + return -1; + } + + if (ret > 0) + break; + } + +#ifndef __WIN32__ + close(mySocket); +#else + closesocket(mySocket); + WSACleanup(); +#endif + + server->ping = 1000 - (tv.tv_usec / 1000); + /* + ["name: F\n"] >= svn82 + "version: svnX\n" + "clients: N\n" + "maxclients: M\n" + "uptime: D\n" + */ + + unsigned i = 0; + + while (i < ret) { + if (str[i] == '\n') + str[i] = '\0'; + + i++; + } + + unsigned name = 0; + + if (strstr(str, "name: ")) + name = 1; + + int len = 0; + + if (name) { + len = strlen(str); + if (!strncmp(str, "name: ", 6)) { + unsigned name_len = strlen(str + 6); + server->name = (char *) malloc(sizeof(char) * (name_len + 2)); + + if (!server->name) + return 0; + + memcpy(server->name, str + 6, name_len + 1); + server->name[name_len + 1] = '\0'; + } + } + + /* HACK */ + if (!name) + len = -1; + + if (!strncmp(str + len + 1, "version: ", 9)) { + unsigned ver_len = strlen(str + len + 10); + server->version = (char *) malloc(sizeof(char) * (ver_len + 2)); + + if (!server->version) + return 0; + + memcpy(server->version, str + len + 10, ver_len + 1); + server->version[ver_len + 1] = '\0'; + } + + len += strlen(str + len + 1) + 1; + + + if (!strncmp(str + len + 1, "clients: ", 9)) + server->clients = atoi(str + len + 10); + + len += strlen(str + len + 1) + 1; + + + if (!strncmp(str + len + 1, "maxclients: ", 12)) + server->maxclients = atoi(str + len + 13); + + len += strlen(str + len + 1) + 1; + + + if (!strncmp(str + len + 1, "uptime: ", 8)) + server->uptime = atoi(str + len + 9); + + len += strlen(str + len + 1) + 1; + + + if (!strncmp(str + len + 1, "arena: ", 7)) { + unsigned arena_len = strlen(str + len + 9); + server->arena = (char *) malloc(sizeof(char) * (arena_len + 2)); + + if (!server->arena) + return 0; + + memcpy(server->arena, str + len + 8, arena_len + 1); + server->arena[arena_len + 1] = '\0'; + } + + + free(str); + + server->state = 1; + + return 1; +} + +static int LoadServers() +// Get server list +{ +#ifndef __WIN32__ + int s; +#else + SOCKET s; +#endif + + char buf[1025]; + + /* TODO: dodelat TCP makro */ + struct sockaddr_in server; + char *master_server_ip; + + master_server_ip = getIPFormDNS(NET_MASTER_SERVER_DOMAIN); + + //printf("master_server_ip = %s\n", master_server_ip); + + if (master_server_ip == NULL) // master server is down + { + return -1; + } + + server.sin_family = AF_INET; + server.sin_port = htons(NET_MASTER_PORT); + server.sin_addr.s_addr = inet_addr(master_server_ip); + + free(master_server_ip); + + if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) + return 0; + +#ifndef __WIN32__ + // Lets make socket non-blocking + int oldFlag = fcntl(s, F_GETFL, 0); + if (fcntl(s, F_SETFL, oldFlag | O_NONBLOCK) == -1) { + return -1; + } +#else + unsigned long arg = 1; + // Operation is FIONBIO. Parameter is pointer on non-zero number. + if (ioctlsocket(s, FIONBIO, &arg) == SOCKET_ERROR) { + WSACleanup(); + return -1; + } +#endif + + if (connect(s, (struct sockaddr *) &server, sizeof(server)) == -1) { +#ifndef __WIN32__ + if (errno != EINPROGRESS) + return -1; +#else + if (WSAGetLastError() != WSAEWOULDBLOCK) { + WSACleanup(); + return -1; + } +#endif + } + + struct timeval tv; + + fd_set myset; + + FD_ZERO(&myset); + FD_SET(s, &myset); + + tv.tv_sec = 3; + tv.tv_usec = 0; + + int ret = select(s + 1, NULL, &myset, NULL, &tv); + + if (ret == -1) + return 0; + + if (ret == 0) + return -2; + + /* send request for server list */ + send(s, "l", 1, 0); + + FD_ZERO(&myset); + FD_SET(s, &myset); + + ret = select(s + 1, &myset, NULL, NULL, &tv); + + if (ret == -1) + return 0; + + if (ret == 0) + return -2; + + int len = recv(s, buf, 1024, 0); + +#ifndef __WIN32__ + close(s); +#else + closesocket(s); + WSACleanup(); +#endif + + if (len <= 0) + return 0; + + unsigned i = 0; + char list[256]; + + struct in_addr srv; + + typedef struct { + unsigned port; + unsigned ip; + } response_head; + + while (1) { + response_head *header = (response_head *) ((char *) buf + i); + + server_t *ctx; + + // alloc and init context + ctx = (server_t *) malloc(sizeof(server_t)); + + ctx->ip = header->ip; + ctx->port = header->port; + ctx->name = 0; + ctx->version = 0; + ctx->arena = 0; + + int ret = server_getinfo(ctx); + + srv.s_addr = ctx->ip; + + char *address = (char *) inet_ntoa(srv); + + memset(list, ' ', 254); + list[255] = '\0'; + + if (ret == 1) { + /*sprintf (list, "%s (%s) - %s:%d - %s - %d/%d - %dms", ctx->name ? ctx->name : "Unknown", ctx->version, address, ctx->port, + ctx->arena ? ctx->arena : "Unknown", ctx->clients, ctx->maxclients, ctx->ping); */ + + if (ctx->name) + memcpy(list, ctx->name, strlen(ctx->name)); + else + memcpy(list, "Unknown", 7); + + memcpy(list + 30, ctx->version, strlen(ctx->version)); + + unsigned a_len = strlen(address); + memcpy(list + 38, address, a_len); + memcpy(list + 38 + a_len, ":", 1); + + sprintf(buf, "%d", ctx->port); + + memcpy(list + 39 + a_len, buf, strlen(buf)); + + memcpy(list + 60, ctx->arena, strlen(ctx->arena)); + + sprintf(buf, "%d/%d", ctx->clients, ctx->maxclients); + + memcpy(list + 75, buf, strlen(buf)); + + sprintf(buf, "%dms", ctx->ping); + + memcpy(list + 83, buf, strlen(buf)); + } + + addToWidgetSelect(select_server, list); + + // add into list + ctx->next = &server_list; + ctx->prev = server_list.prev; + ctx->prev->next = ctx; + ctx->next->prev = ctx; + + i += sizeof(response_head) + 1; + + if (buf[i - 1] != '\n' || (i + 1) > len) + break; + } + + return 1; +} + +static int RefreshServers() +{ +/* + destroyListItem(select_server->list, free); + select_server->list = newList(); +*/ + removeAllFromWidgetSelect(select_server); + + struct in_addr srv; + + server_t *server; + for (server = server_list.next; server != &server_list; + server = server->next) { + if (server->name) + free(server->name); + + if (server->version) + free(server->version); + + if (server->arena) + free(server->arena); + + server->name = 0; + server->version = 0; + server->arena = 0; + + char list[256]; + char buf[32]; + + int ret = server_getinfo(server); + + srv.s_addr = server->ip; + + char *address = (char *) inet_ntoa(srv); + + if (ret == 1) { + memset(list, ' ', 254); + list[255] = '\0'; + + if (server->name) + memcpy(list, server->name, strlen(server->name)); + else + memcpy(list, "Unknown", 7); + + memcpy(list + 30, server->version, strlen(server->version)); + + unsigned a_len = strlen(address); + memcpy(list + 38, address, a_len); + memcpy(list + 38 + a_len, ":", 1); + + sprintf(buf, "%d", server->port); + + memcpy(list + 39 + a_len, buf, strlen(buf)); + + memcpy(list + 60, server->arena, strlen(server->arena)); + + sprintf(buf, "%d/%d", server->clients, server->maxclients); + + memcpy(list + 75, buf, strlen(buf)); + + sprintf(buf, "%dms", server->ping); + + memcpy(list + 83, buf, strlen(buf)); + } + + addToWidgetSelect(select_server, list); + + } + + return 1; +} + +void initScreenBrowser() +{ + image_t *image; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = + newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); + button_play = + newWidgetButton(_("Play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, + eventWidget); + button_refresh = + newWidgetButton(_("Refresh"), WINDOW_SIZE_X / 2 - 50, + WINDOW_SIZE_Y - 100, eventWidget); + + label_server = newWidgetLabel(_("server"), 120, 145, WIDGET_LABEL_LEFT); + label_version = newWidgetLabel(_("version"), 290, 145, WIDGET_LABEL_LEFT); + label_address = newWidgetLabel(_("IP"), 400, 145, WIDGET_LABEL_LEFT); + label_arena = newWidgetLabel(_("arena"), 550, 145, WIDGET_LABEL_LEFT); + label_players = newWidgetLabel(_("clients"), 645, 145, WIDGET_LABEL_LEFT); + label_ping = newWidgetLabel(_("ping"), 720, 145, WIDGET_LABEL_LEFT); + + select_server = newWidgetSelect(50, label_server->y + 40, eventWidget); + + registerScreen(newScreen + ("browser", startScreenBrowser, eventScreenBrowser, + drawScreenBrowser, stopScreenBrowser)); + + server_list.next = &server_list; + server_list.prev = &server_list; +} + +void quitScreenBrowser() +{ + destroyWidgetImage(image_backgorund); + + destroyWidgetButton(button_play); + destroyWidgetButton(button_back); + destroyWidgetButton(button_refresh); + + destroyWidgetLabel(label_server); + destroyWidgetLabel(label_version); + destroyWidgetLabel(label_address); + destroyWidgetLabel(label_arena); + destroyWidgetLabel(label_players); + destroyWidgetLabel(label_ping); + + destroyWidgetSelect(select_server); +} diff --git a/src/screen/browser.h b/src/screen/browser.h new file mode 100644 index 0000000..e810e58 --- /dev/null +++ b/src/screen/browser.h @@ -0,0 +1,33 @@ + +#ifndef SCREEN_BROWSER_H + +# define SCREEN_BROWSER_H + +typedef struct server_context { + struct server_context *next, *prev; + + unsigned char state; + + unsigned char ping; + + unsigned ip; + unsigned port; + + char *name; + + char *version; + unsigned char clients; + unsigned char maxclients; + unsigned uptime; + char *arena; +} server_t; + + +extern void startScreenBrowser(); +extern void drawScreenBrowser(); +extern void eventScreenBrowser(); +extern void stopScreenBrowser(); +extern void initScreenBrowser(); +extern void quitScreenBrowser(); + +#endif diff --git a/src/screen/choiceArena.c b/src/screen/choiceArena.c new file mode 100644 index 0000000..bf60c46 --- /dev/null +++ b/src/screen/choiceArena.c @@ -0,0 +1,245 @@ + +#include +#include + +#include "main.h" +#include "list.h" +#include "arenaFile.h" + +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +#endif + +#include "mainMenu.h" +#include "choiceArena.h" + +#include "widget.h" +#include "widget_label.h" +#include "widget_button.h" +#include "widget_image.h" +#include "widget_buttonimage.h" + +static widget_t *image_backgorund; + +static widget_t *button_play; +static widget_t *button_back; +static widget_t *button_next; +static widget_t *button_prev; + +//static list_t *listWidgetButtonimage; // map buttons to be showed and handled - well, show_map_buttons is used instead +static list_t *listAllWidgetButtonimage; // all map buttons +static int handled_map_button_group; // 0 - first 6 buttons, 1 - second 6 buttons, .... +static void activateHandledMapButtonGroup(); +static struct show_map_buttons { + // geez, it'd be nicer to used two lists + // but how the hell is list_t supposed to be used?! :-) + int min; // see activateHandledMapButtonGroup for desc + int max; // + int next; // 0: max is last item+1 in listAllWidgetButtonimage, otherwise 1 + int prev; // 0: min is first item in listAllWidgetButtonimage, otherwise 1 +} show_map_buttons = { 0,0,0,0 } ; +static arenaFile_t *currentArena; + +static void hotkey_escape() +{ + setScreen("gameType"); +} + +void startScreenChoiceArena() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} + +void drawScreenChoiceArena() +{ + int i; + + drawWidgetImage(image_backgorund); + + drawWidgetButton(button_play); + drawWidgetButton(button_back); + if (show_map_buttons.next) { drawWidgetButton(button_next); } + if (show_map_buttons.prev) { drawWidgetButton(button_prev); } + + for (i = show_map_buttons.min ; i < show_map_buttons.max; i++) { + drawWidgetButtonimage((widget_t*)listAllWidgetButtonimage->list[i]); + } +} + +void eventScreenChoiceArena() +{ + int i; + + eventWidgetButton(button_play); + eventWidgetButton(button_back); + if (show_map_buttons.next) { eventWidgetButton(button_next); } + if (show_map_buttons.prev) { eventWidgetButton(button_prev); } + + for (i = show_map_buttons.min ; i < show_map_buttons.max; i++) { + eventWidgetButtonimage((widget_t*)listAllWidgetButtonimage->list[i]); + } +} + +void stopScreenChoiceArena() +{ + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidgetButtonImage(void *p) +{ + widget_t *buttonimage; + int i; + + buttonimage = (widget_t *) (p); + + for (i = show_map_buttons.min; i < show_map_buttons.max; i++) { + widget_t *this; + + this = (widget_t *) (listAllWidgetButtonimage->list[i]); + + if (buttonimage == this) { + setWidgetButtonimageActive(this, TRUE); + currentArena = getArenaFile(i); + } else { + setWidgetButtonimageActive(this, FALSE); + } + } +} + +arenaFile_t *getChoiceArena() +{ + return currentArena; +} + +void setChoiceArena(arenaFile_t * arenaFile) +{ + widget_t *widget_buttonimage; + int id; + + id = getArenaFileID(arenaFile); + currentArena = arenaFile; + + if (id >= 0) { + widget_buttonimage = (widget_t *) listAllWidgetButtonimage->list[id]; + setWidgetButtonimageActive(widget_buttonimage, TRUE); + } +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_play) { + setScreen("world"); + } + + if (button == button_back) { + setScreen("gameType"); + } + if (button == button_next) { + if (show_map_buttons.next) { + handled_map_button_group++; + activateHandledMapButtonGroup(); + } + } + if (button == button_prev) { + if (show_map_buttons.prev) { + handled_map_button_group--; + activateHandledMapButtonGroup(); + } + } +} + +// groups of 6 map buttons to be shown and handled +// the group is set by static global variable handled_map_button_group +// sets static global show_map_buttons.min to index of first button to be drawn in listAllButtonimage +// and show_map_buttons.max to index of last button to be drawn+1 in listAllButtonimage +static void activateHandledMapButtonGroup(void) { + int min = handled_map_button_group * 6; + min = min < 0 ? 0 : min; + min = min <= getArenaCount() ? min : getArenaCount(); + int max = min+6 <= getArenaCount() ? min+6 : getArenaCount(); + + if (min) { show_map_buttons.prev = 1; } + else { show_map_buttons.prev = 0; } + if (max < getArenaCount()) { show_map_buttons.next = 1; } + else { show_map_buttons.next = 0; } + show_map_buttons.min = min; + show_map_buttons.max = max; +} + +void initScreenChoiceArena() +{ + image_t *image; + int i; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); + button_play = newWidgetButton(_("play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, eventWidget); + + button_prev = newWidgetButton(_("prev maps"), 250, WINDOW_SIZE_Y - 100, eventWidget); + button_next = newWidgetButton(_("next maps"), WINDOW_SIZE_X-350, WINDOW_SIZE_Y - 100, eventWidget); + + listAllWidgetButtonimage = newList(); + currentArena = NULL; + + for (i = 0; i < getArenaCount(); i++) { + widget_t *widget_buttonimage; + arenaFile_t *arenaFile; + int x, y; + + arenaFile = getArenaFile(i); + //image = addImageData(getArenaImage(i), IMAGE_NO_ALPHA, "none", IMAGE_GROUP_BASE); + image = loadImageFromArena(arenaFile, getArenaImage(arenaFile), + IMAGE_GROUP_BASE, "none", IMAGE_NO_ALPHA); + + // only 6 map buttons can be shown at once; + // set buttons' positions in each group to the corresponding values + // handled_map_button_group and activateHandledMapButtonGroup is used + // to choose group to be shown and handled + int pos = i % 6 ; + x = 100 + 200 * (pos - 3 * (pos / 3)); + y = 150 + 200 * (pos / 3); + + widget_buttonimage = newWidgetButtonimage(image, x, y, eventWidgetButtonImage); +/* + if( i == choiceArenaId ) + { + widget_buttonimage->active = 1; + } +*/ + addList(listAllWidgetButtonimage, widget_buttonimage); + handled_map_button_group = 0; + activateHandledMapButtonGroup(); + } + + registerScreen( newScreen("chiceArena", startScreenChoiceArena, + eventScreenChoiceArena, drawScreenChoiceArena, + stopScreenChoiceArena)); +} + +void quitScreenChoiceArena() +{ + destroyWidgetImage(image_backgorund); + + destroyWidgetButton(button_play); + destroyWidgetButton(button_back); + + destroyWidgetButton(button_next); + destroyWidgetButton(button_prev); + + destroyListItem(listAllWidgetButtonimage, destroyWidgetButtonimage); +} diff --git a/src/screen/choiceArena.h b/src/screen/choiceArena.h new file mode 100644 index 0000000..dbe12de --- /dev/null +++ b/src/screen/choiceArena.h @@ -0,0 +1,19 @@ + +#ifndef SCREEN_CHOICE_ARENA + +# define SCREEN_CHOICE_ARENA + +# include "main.h" +# include "arenaFile.h" + +# define SCREENSHOT_ARENA_WIDTH 160 +# define SCREENSHOT_ARENA_HEIGHT 107 + +extern void drawScreenChoiceArena(); +extern void eventScreenChoiceArena(); +extern arenaFile_t *getChoiceArena(); +extern void setChoiceArena(arenaFile_t * arenaFile); +extern void initScreenChoiceArena(); +extern void quitScreenChoiceArena(); + +#endif diff --git a/src/screen/credits.c b/src/screen/credits.c new file mode 100644 index 0000000..93745c2 --- /dev/null +++ b/src/screen/credits.c @@ -0,0 +1,163 @@ + +#include +#include + +#include "main.h" +#include "list.h" +#include "textFile.h" + +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +#endif + +#include "credits.h" + +#include "widget.h" +#include "widget_image.h" +#include "widget_label.h" +#include "widget_button.h" + +static widget_t *image_backgorund; +static widget_t *button_back; +static list_t *listWidgetLabel; +static textFile_t *textFile; +static int offset; +static int creditExists; + +static void hotkey_escape() +{ + setScreen("mainMenu"); +} + +void startScreenCredits() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + offset = 0; + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} + +void drawScreenCredits() +{ + int i; + + drawWidgetImage(image_backgorund); + + drawWidgetButton(button_back); + + for (i = 0; i < listWidgetLabel->count; i++) { + int z; + + widget_t *this; + + this = (widget_t *) listWidgetLabel->list[i]; + + z = this->y; + this->y += offset; + + if (this->y > SCREEN_CREDITS_OFFSET_MIN && this->y < SCREEN_CREDITS_OFFSET_MAX) { + drawWidgetLabel(this); + } + + this->y = z; + } + +} + +void eventScreenCredits() +{ + eventWidgetButton(button_back); + + offset -= SCREEN_CREDITS_OFFSET_SPEED; + + if (offset < SCREEN_CREDITS_OFFSET_RESTART) { + offset = 0; + } + + //printf("offset = %d\n", offset); +} + +void stopScreenCredits() +{ + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_back) { + setScreen("mainMenu"); + } +} + +void initScreenCredits() +{ + image_t *image; + int i; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = newWidgetButton(_("back"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 80, eventWidget); + + listWidgetLabel = newList(); + + if (tryExistFile(PATH_DOC SCREEN_CREDITS_FILE) == 0) { + creditExists = 1; + textFile = loadTextFile(PATH_DOC SCREEN_CREDITS_FILE); + + for (i = 0; i < textFile->text->count; i++) { + widget_t *label; + char *line; + + line = (char *) textFile->text->list[i]; + + label = newWidgetLabel(line, WINDOW_SIZE_X / 2 - WINDOW_SIZE_X / 4, + (WINDOW_SIZE_Y - 100) + i * 20, + WIDGET_LABEL_LEFT); + + addList(listWidgetLabel, label); + } + } else { + for (i = 0; i < 5; i++) { + creditExists = 0; + widget_t *label; + char line[STR_SIZE]; + + sprintf(line, _("Credit file not found... %s/%s"), PATH_DOC, + SCREEN_CREDITS_FILE); + + label = newWidgetLabel(line, WINDOW_SIZE_X / 2, + (WINDOW_SIZE_Y - 100) + i * 20, + WIDGET_LABEL_CENTER); + + addList(listWidgetLabel, label); + } + } + + registerScreen(newScreen ("credits", startScreenCredits, eventScreenCredits, + drawScreenCredits, stopScreenCredits)); +} + +void quitScreenCredits() +{ + destroyWidgetImage(image_backgorund); + + destroyWidgetButton(button_back); + destroyListItem(listWidgetLabel, destroyWidgetLabel); + + if (creditExists) { + destroyTextFile(textFile); + } +} diff --git a/src/screen/credits.h b/src/screen/credits.h new file mode 100644 index 0000000..37c25f3 --- /dev/null +++ b/src/screen/credits.h @@ -0,0 +1,20 @@ + +#ifndef SCREEN_CREDITS_H + +# define SCREEN_CREDITS_H + +# define SCREEN_CREDITS_FILE "AUTHORS" + +# define SCREEN_CREDITS_OFFSET_MIN 130 +# define SCREEN_CREDITS_OFFSET_MAX WINDOW_SIZE_Y-120 +# define SCREEN_CREDITS_OFFSET_RESTART -1000 +# define SCREEN_CREDITS_OFFSET_SPEED 2 + +extern void startScreenCredits(); +extern void drawScreenCredits(); +extern void eventScreenCredits(); +extern void stopScreenCredits(); +extern void initScreenCredits(); +extern void quitScreenCredits(); + +#endif diff --git a/src/screen/downArena.c b/src/screen/downArena.c new file mode 100644 index 0000000..3328046 --- /dev/null +++ b/src/screen/downArena.c @@ -0,0 +1,391 @@ + +#include +#include +#include +#include + +#include "main.h" +#include "list.h" +#include "buffer.h" +#include "textFile.h" +#include "arenaFile.h" +#include "homeDirector.h" + +#include "interface.h" +#include "screen.h" +#include "image.h" + +#include "net_multiplayer.h" +#include "udp.h" +#include "tcp.h" + +#include "widget.h" +#include "widget_image.h" +#include "widget_label.h" +#include "widget_button.h" + +#include "setting.h" +#include "downArena.h" +#include "gameType.h" + +static sock_udp_t *sock_server_udp; +static sock_tcp_t *sock_server_tcp; + +static widget_t *image_backgorund; +static widget_t *button_back; +static widget_t *label_status; + +static char str_status[STR_PROTO_SIZE]; +static char arenaNetName[STR_SIZE]; + +static int status_tcp_socket; +static buffer_t *recvBuffer; +static buffer_t *sendBuffer; + +static char path[STR_PATH_SIZE]; +static FILE *file; +static int fileSize; +static int fileOffset; + +static my_time_t timeSendMsg; +static int countSendMsg; + +static void setStatusString(char *s) +{ + printf("status -> %s\n", s); + destroyWidgetLabel(label_status); + label_status = newWidgetLabel(s, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); +} + +static void connectToDownServer() +{ + char status[STR_SIZE]; + char msg[STR_PROTO_SIZE]; + + sock_server_tcp = connectTcpSocket(getSettingIP(), getSettingPort()); + + if( sock_server_tcp == NULL ) + { + sprintf(status, "I do not connect to %s %d TCP down server", getSettingIP(), getSettingPort()); + setStatusString(status); + return; + } + + setTcpSockNonBlock(sock_server_tcp); + + recvBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE); + sendBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE); + status_tcp_socket = DOWN_SERVER_STATUS_OK; + + file = NULL; + countSendMsg = 0; + timeSendMsg = getMyTime(); + + sprintf(msg, "GETARENA %s\n", arenaNetName); + + addBuffer(sendBuffer, msg, strlen(msg)); + + sprintf(status, "Connect to %s %d TCP down server", getSettingIP(), getSettingPort()); + setStatusString(status); +} + +static void closeConnectFromDownServer() +{ + closeTcpSocket(sock_server_tcp); + destroyBuffer(recvBuffer); + destroyBuffer(sendBuffer); + sock_server_tcp = NULL; + recvBuffer = NULL; + sendBuffer = NULL; +} + +static void sendStatusToGameServer() +{ + char *msg = "status\n"; + + if( countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS ) + { + char status[STR_SIZE]; + sprintf(status, "Game server %s %d is down", getSettingIP(), getSettingPort()); + setStatusString(status); + return; + } + + timeSendMsg = getMyTime(); + countSendMsg++; + printf("countSendMsg = %d\n", countSendMsg++); + + if( writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)) < 0 ) + { + char status[STR_SIZE]; + sprintf(status, "I do not send message to %s %d UDP game server", getSettingIP(), getSettingPort()); + setStatusString(status); + } +} + +void startScreenDownArena() +{ + char status[STR_SIZE]; + + strcpy(str_status, "none"); + memset(arenaNetName, 0, STR_SIZE); + + sock_server_udp = connectUdpSocket(getSettingIP(), getSettingPort()); + + if (sock_server_udp == NULL) + { + sprintf(status, "I do not connect to %s %d UDP game server", getSettingIP(), getSettingPort()); + setStatusString(status); + return; + } + + setUdpSockNonBlock(sock_server_udp); + + sprintf(status, "Connect to %s %d UDP game server", getSettingIP(), getSettingPort()); + setStatusString(status); + + sendStatusToGameServer(); +} + +void drawScreenDownArena() +{ + drawWidgetImage(image_backgorund); + drawWidgetLabel(label_status); + drawWidgetButton(button_back); +} + +static void proto_ok(char *line) +{ + //printf("line = %s\n", line); + fileSize = atoi(line + 3); + fileOffset = 0; + + sprintf(path, "%s/%s.zip", getHomeDirector(), arenaNetName); + //printf("path = %s\n", path); + file = fopen(path, "wb"); +} + +static void proto_err(char *line) +{ + //printf("line = %s\n", line); + setStatusString(line + 4); + closeConnectFromDownServer(); +} + +static void eventProto(char *line) +{ + if( strncmp(line, "OK", 2) == 0 ) + { + proto_ok(line); + } + + if( strncmp(line, "ERR", 3) == 0 ) + { + proto_err(line); + } +} + +static int downArenaFile() +{ + char status[STR_SIZE]; + void *data; + int len; + + len = getBufferSize(recvBuffer); + data = getBufferData(recvBuffer); + cutBuffer(recvBuffer, len); + + fwrite(data, len, 1, file); + fileOffset += len; + + sprintf(status, "I down %d / %d", fileOffset, fileSize); + setStatusString(status); + + return len; +} + +static int eventRecvBuffer() +{ + char buffer[STR_PROTO_SIZE]; + char line[STR_PROTO_SIZE]; + int ret; + + memset(buffer, 0, STR_PROTO_SIZE); + + ret = readTcpSocket(sock_server_tcp, buffer, STR_PROTO_SIZE - 1); + //if (ret <= 0) printf("readTcpSocket = %d\n", ret); + + if (ret < 0) { + return -1; + } + + if (addBuffer(recvBuffer, buffer, ret) < 0) { + char status[STR_SIZE]; + sprintf(status, "Error -- recv buffer is full"); + setStatusString(status); + closeConnectFromDownServer(); + return -1; + } + + if (file == NULL && getBufferLine(recvBuffer, line, STR_PROTO_SIZE) >= 0) { + eventProto(line); + return ret; + } + + if (file != NULL) { + return downArenaFile(); + } + + return -1; +} + +static int eventSendBuffer() +{ + void *data; + int len; + int res; + + len = getBufferSize(sendBuffer); + + if (len == 0) { + return -1; + } + + data = getBufferData(sendBuffer); + + res = writeTcpSocket(sock_server_tcp, data, len); + + if (res < 0) { + return -1; + } + + cutBuffer(sendBuffer, res); + return res; +} + +static void readArenaFromStatus() +{ + const char *str_arena = "arena: "; + + char *offset_begin; + char *offset_end; + + offset_begin = strstr(str_status, str_arena); + + if (offset_begin != NULL) { + offset_begin += strlen(str_arena); + offset_end = strstr(offset_begin, "\n"); + + if (offset_end != NULL) { + closeUdpSocket(sock_server_udp); + sock_server_udp = NULL; + strncpy(arenaNetName, offset_begin, offset_end - offset_begin); + + if (getArenaFileFormNetName(arenaNetName) != NULL) { + setScreen("world"); + return; + } + + connectToDownServer(); + + printf("arenaNetName = >>%s<<\n", arenaNetName); + } + } +} + +static void eventStatus() +{ + if( getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT ) + { + sendStatusToGameServer(); + } + + if( readUdpSocket(sock_server_udp, sock_server_udp, str_status, STR_PROTO_SIZE - 1) > 0 ) + { + //printf("str_status = %s\n", str_status); + readArenaFromStatus(); + } +} + +void eventScreenDownArena() +{ + int i; + + if (strcmp(str_status, "none") == 0) { + eventStatus(); + } + + if (recvBuffer != NULL) { + for (i = 0; i < DOWN_ARENA_COUNT_READ_SOCKET; i++) { + if (eventRecvBuffer() <= 0) { + break; + } + } + } + + if (sendBuffer != NULL) { + eventSendBuffer(); + } + + if (file != NULL && fileSize == fileOffset && fileSize > 0) { + fclose(file); + file = NULL; + closeConnectFromDownServer(); + loadArenaFile(path); + setScreen("world"); + } + + eventWidgetButton(button_back); +} + +void stopScreenDownArena() +{ + if (file != NULL) { + unlink(path); + } + + if (sock_server_tcp != NULL) { + closeConnectFromDownServer(); + } + + if (sock_server_udp != NULL) { + closeUdpSocket(sock_server_udp); + } + +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_back) { + setScreen("mainMenu"); + } +} + +void initScreenDownArena() +{ + image_t *image; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = + newWidgetButton(_("back"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 80, eventWidget); + + label_status = + newWidgetLabel("none", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); + + registerScreen( newScreen("downArena", startScreenDownArena, eventScreenDownArena, + drawScreenDownArena, stopScreenDownArena)); +} + +void quitScreenDownArena() +{ + destroyWidgetImage(image_backgorund); + destroyWidgetButton(button_back); + destroyWidgetLabel(label_status); +} diff --git a/src/screen/downArena.h b/src/screen/downArena.h new file mode 100644 index 0000000..d9f25d7 --- /dev/null +++ b/src/screen/downArena.h @@ -0,0 +1,22 @@ + +#ifndef SCREEN_DOWN_ARENA_H + +# define SCREEN_DOWN_ARENA_H + +# define DOWN_SERVER_STATUS_OK 0 +# define DOWN_SERVER_STATUS_ZOMBIE 1 + +# define DOWN_ARENA_BUFFER_SIZE 4096 + +# define DOWN_ARENA_MAX_SEND_MSG_STATUS 10 +# define DOWN_ARENA_MAX_TIEMOUT_LIMIT 500 +# define DOWN_ARENA_COUNT_READ_SOCKET 100 + +extern void startScreenDownArena(); +extern void drawScreenDownArena(); +extern void eventScreenDownArena(); +extern void stopScreenDownArena(); +extern void initScreenDownArena(); +extern void quitScreenDownArena(); + +#endif diff --git a/src/screen/gameType.c b/src/screen/gameType.c new file mode 100644 index 0000000..a8f0b2a --- /dev/null +++ b/src/screen/gameType.c @@ -0,0 +1,384 @@ + +#include +#include +#include + +#include "main.h" +#include "list.h" +#include "director.h" +#include "homeDirector.h" +#include "net_multiplayer.h" +#include "tux.h" + +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +#endif + +#include "gameType.h" +#include "setting.h" + +#include "widget.h" +#include "widget_label.h" +#include "widget_button.h" +#include "widget_image.h" +#include "widget_textfield.h" +#include "widget_choicegroup.h" +#include "widget_check.h" +#include "widget_select.h" + +static widget_t *image_backgorund; + +static widget_t *button_back; +static widget_t *button_play; +static widget_t *button_browser; + +static widget_t *label_none; +static widget_t *label_server; +static widget_t *label_client; +static widget_t *label_load_session; + +static widget_t *label_ip; +static widget_t *label_port; +static widget_t *label_session; + +static list_t *listChoiceGroup; +static widget_t *check_none; +static widget_t *check_server; +static widget_t *check_client; +static widget_t *check_load_session; + +static widget_t *textfield_ip; +static widget_t *textfield_port; + +static widget_t *selectSession; + +static void loadSession(widget_t * p) +{ + director_t *director; + int i; + + director = loadDirector(getHomeDirector()); + + removeAllFromWidgetSelect(p); + + 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, line); + } + } + + destroyDirector(director); +} + +static void hotkey_escape() +{ + setScreen("mainMenu"); +} + +void startScreenGameType() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + + setWidgetChoiceStatus(check_none, TRUE); + setWidgetChoiceStatus(check_server, FALSE); + setWidgetChoiceStatus(check_client, FALSE); + setWidgetChoiceStatus(check_load_session, FALSE); + + loadSession(selectSession); + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} + +void drawScreenGameType() +{ + int i; + + drawWidgetImage(image_backgorund); + + for (i = 0; i < listChoiceGroup->count; i++) { + widget_t *this; + + this = (widget_t *) listChoiceGroup->list[i]; + drawWidgetChoicegroup(this); + } + + drawWidgetLabel(label_none); + drawWidgetLabel(label_server); + drawWidgetLabel(label_client); + drawWidgetLabel(label_load_session); + + if (getWidgetChoiceStatus(check_server) == TRUE || getWidgetChoiceStatus(check_client) == TRUE) { + drawWidgetLabel(label_port); + drawWidgetTextfield(textfield_port); + drawWidgetLabel(label_ip); + drawWidgetTextfield(textfield_ip); + } + + if (getWidgetChoiceStatus(check_load_session) == TRUE) { + drawWidgetLabel(label_session); + drawWidgetSelect(selectSession); + } +#if 0 + if (check_server->status == TRUE) { + setSettingIP(getParamElse("--ip", "127.0.0.1")); + setSettingPort(atoi(getParamElse("--port", "2200"))); + } +#endif + + if (getWidgetChoiceStatus(check_client) == TRUE) + drawWidgetButton(button_browser); + + drawWidgetButton(button_back); + drawWidgetButton(button_play); + +} + +void eventScreenGameType() +{ + int i; + + for (i = 0; i < listChoiceGroup->count; i++) { + widget_t *this; + + this = (widget_t *) listChoiceGroup->list[i]; + eventWidgetChoicegroup(this); + } + + if (getWidgetChoiceStatus(check_server) == TRUE || getWidgetChoiceStatus(check_client) == TRUE) { + eventWidgetTextfield(textfield_ip); + eventWidgetTextfield(textfield_port); + } + + if (getWidgetChoiceStatus(check_load_session) == TRUE) { + eventWidgetSelect(selectSession); + } + + eventWidgetButton(button_back); + eventWidgetButton(button_play); + + if (getWidgetChoiceStatus(check_client) == TRUE) + eventWidgetButton(button_browser); +} + +void stopScreenGameType() +{ + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_back) { + setScreen("mainMenu"); + } + + if (button == button_play) { + char *str; + + str = getGemeTypeLoadSession(); + + if (str != NULL) { + setScreen("world"); + return; + } + + if (getSettingGameType() == NET_GAME_TYPE_CLIENT) { + setScreen("downArena"); + //setScreen("world"); + } else { + setScreen("chiceArena"); + } + } + + if (button == button_browser) { + setScreen("browser"); + } +} + +void initScreenGameType() +{ + image_t *image; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); + button_play = newWidgetButton(_("play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, eventWidget); + button_browser = newWidgetButton(_("browser"), 300, 345, 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")) { + setWidgetChoiceStatus(check_server, TRUE); + } else if (isParamFlag("--client")) { + setWidgetChoiceStatus(check_client, TRUE); + } else { + setWidgetChoiceStatus(check_none, TRUE); + } + + label_none = newWidgetLabel(_("Local game"), 130, 145, WIDGET_LABEL_LEFT); + label_server = newWidgetLabel(_("Set up a server"), 130, 195, WIDGET_LABEL_LEFT); + label_client = newWidgetLabel(_("Network game"), 130, 245, WIDGET_LABEL_LEFT); + label_load_session = newWidgetLabel("load session", 130, 295, WIDGET_LABEL_LEFT); + + label_ip = newWidgetLabel(_("IP"), 300, 145, WIDGET_LABEL_LEFT); + label_port = newWidgetLabel(_("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"), + WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN, + 300, 180); + + textfield_port = newWidgetTextfield(getParamElse("--port", "6800"), + WIDGET_TEXTFIELD_FILTER_NUM, 300, 280); + + selectSession = newWidgetSelect(300, 185, eventWidget); + + registerScreen( newScreen("gameType", startScreenGameType, eventScreenGameType, + drawScreenGameType, stopScreenGameType)); +} + +int setSettingGameType(int status) +{ + if (status == NET_GAME_TYPE_NONE) { + setWidgetChoiceStatus(check_none, TRUE); + return 0; + } + + if (status == NET_GAME_TYPE_SERVER) { + setWidgetChoiceStatus(check_server, TRUE); + return 0; + } + + if (status == NET_GAME_TYPE_CLIENT) { + setWidgetChoiceStatus(check_client, TRUE); + return 0; + } + + return -1; +} + +int getSettingGameType() +{ + if (getWidgetChoiceStatus(check_none) == TRUE || getWidgetChoiceStatus(check_load_session) == TRUE) { + return NET_GAME_TYPE_NONE; + } + + if (getWidgetChoiceStatus(check_server) == TRUE) { + return NET_GAME_TYPE_SERVER; + } + + if (getWidgetChoiceStatus(check_client) == TRUE) { + return NET_GAME_TYPE_CLIENT; + } + + assert(!_("Unknown game type!")); + + return -1; +} + +char *getGemeTypeLoadSession() +{ + if (getWidgetChoiceStatus(check_load_session) == TRUE) { + return getWidgetSelectItem(selectSession); + } + + return NULL; +} + +int setSettingIP(char *address) +{ + char str[STR_SIZE]; + + strcpy(str, address); + setWidgetTextFiledText(textfield_ip, str); + + return 1; +} + +char *getSettingIP() +{ + return getTextFromWidgetTextfield(textfield_ip); +} + +int setSettingPort(int port) +{ + char str[STR_SIZE]; + + sprintf(str, "%d", port); + setWidgetTextFiledText(textfield_port, str); + + return 0; +} + +int getSettingPort() +{ + return atoi(getTextFromWidgetTextfield(textfield_port)); +} + +int getSettingProto() +{ + if (strstr(getTextFromWidgetTextfield(textfield_ip), ".") != NULL) { + return PROTO_UDPv4; + } + + if (strstr(getTextFromWidgetTextfield(textfield_ip), ":") != NULL) { + return PROTO_UDPv6; + } + + DEBUG_MSG(_("Unknown IP protocol!\n")); + + return -1; +} + +void quitScreenGameType() +{ + destroyWidgetImage(image_backgorund); + + 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); + + destroyWidgetChoicegroup(check_none); + destroyWidgetChoicegroup(check_server); + destroyWidgetChoicegroup(check_client); + destroyWidgetChoicegroup(check_load_session); + + destroyList(listChoiceGroup); +} diff --git a/src/screen/gameType.h b/src/screen/gameType.h new file mode 100644 index 0000000..2c836fc --- /dev/null +++ b/src/screen/gameType.h @@ -0,0 +1,21 @@ + +#ifndef SCREEN_GAME_TYPE + +# define SCREEN_GAME_TYPE + +# include "main.h" + +extern void drawScreenGameType(); +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); +extern int getSettingPort(); +extern int getSettingProto(); +extern void quitScreenGameType(); + +#endif diff --git a/src/screen/mainMenu.c b/src/screen/mainMenu.c new file mode 100644 index 0000000..56ebd4c --- /dev/null +++ b/src/screen/mainMenu.c @@ -0,0 +1,133 @@ + +#include +#include + +#include "main.h" + +#include "game.h" +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +#endif + +#include "mainMenu.h" +#include "setting.h" + +#include "widget.h" +#include "widget_label.h" +#include "widget_button.h" +#include "widget_textfield.h" +#include "widget_check.h" +#include "widget_image.h" + +static widget_t *image_backgorund; + +static widget_t *button_play; +static widget_t *button_setting; +static widget_t *button_table; +static widget_t *button_credits; +static widget_t *button_end; + +static void hotkey_escape() +{ + quitGame(); +} + +void startScreenMainMenu() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} + +void drawScreenMainMenu() +{ + drawWidgetImage(image_backgorund); + + drawWidgetButton(button_play); + drawWidgetButton(button_setting); + drawWidgetButton(button_table); + drawWidgetButton(button_credits); + drawWidgetButton(button_end); +} + +void eventScreenMainMenu() +{ + eventWidgetButton(button_play); + eventWidgetButton(button_setting); + eventWidgetButton(button_table); + eventWidgetButton(button_credits); + eventWidgetButton(button_end); +} + +void stopScreenMainMenu() +{ + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_play) { + setScreen("gameType"); + } + + if (button == button_setting) { + setScreen("setting"); + } + + if (button == button_table) { + setScreen("table"); + } + + if (button == button_credits) { + setScreen("credits"); + } + + if (button == button_end) { + quitGame(); + } +} + +void initScreenMainMenu() +{ + image_t *image; + + image = + addImageData("screen_main.png", IMAGE_NO_ALPHA, "screen_main", + IMAGE_GROUP_BASE); + image_backgorund = newWidgetImage(0, 0, image); + + button_play = newWidgetButton(_("Start game"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 200, eventWidget); + button_setting = newWidgetButton(_("Settings"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 250, eventWidget); + button_table = newWidgetButton(_("Highscore"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 300, eventWidget); + button_credits = newWidgetButton(_("Credits"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 350, eventWidget); + button_end = newWidgetButton(_("Quit game"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 400, eventWidget); + +#ifndef NO_SOUND + addMusic("menu.ogg", "menu", MUSIC_GROUP_BASE); +#endif + + registerScreen( newScreen("mainMenu", startScreenMainMenu, eventScreenMainMenu, + drawScreenMainMenu, stopScreenMainMenu)); +} + +void quitScreenMainMenu() +{ + destroyWidgetImage(image_backgorund); + + destroyWidgetButton(button_play); + destroyWidgetButton(button_setting); + destroyWidgetButton(button_table); + destroyWidgetButton(button_credits); + destroyWidgetButton(button_end); +} diff --git a/src/screen/mainMenu.h b/src/screen/mainMenu.h new file mode 100644 index 0000000..ecb369b --- /dev/null +++ b/src/screen/mainMenu.h @@ -0,0 +1,15 @@ + +#ifndef SCREEN_MIAN_MENU_H + +# define SCREEN_MIAN_MENU_H + +# include "main.h" + +extern void startScreenMainMenu(); +extern void drawScreenMainMenu(); +extern void eventScreenMainMenu(); +extern void stopScreenMainMenu(); +extern void initScreenMainMenu(); +extern void quitScreenMainMenu(); + +#endif diff --git a/src/screen/screen_analyze.c b/src/screen/screen_analyze.c deleted file mode 100644 index b249f81..0000000 --- a/src/screen/screen_analyze.c +++ /dev/null @@ -1,185 +0,0 @@ - -#include -#include -#include - -#include "main.h" -#include "list.h" - -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -#endif - -#include "screen_mainMenu.h" -#include "screen_analyze.h" - -#include "widget.h" -#include "widget_label.h" -#include "widget_button.h" -#include "widget_image.h" - -static widget_t *image_backgorund; - -static list_t *listWidgetLabelName; -static list_t *listWidgetLabelScore; -static list_t *listAnalyze; -static widget_t *widgetLabelMsg; - -static widget_t *button_ok; - -static analyze_t *newAnalyze(char *name, int score) -{ - analyze_t *new; - - new = malloc(sizeof(analyze_t)); - new->name = strdup(name); - new->score = score; - - return new; -} - -static void destroyAnalyze(analyze_t * p) -{ - free(p->name); - free(p); -} - -static void hotkey_escape() -{ - setScreen("mainMenu"); -} - -void startScreenAnalyze() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} - -void drawScreenAnalyze() -{ - widget_t *this; - int i; - - drawWidgetImage(image_backgorund); - - for (i = 0; i < listWidgetLabelName->count; i++) { - this = (widget_t *) (listWidgetLabelName->list[i]); - drawWidgetLabel(this); - } - - for (i = 0; i < listWidgetLabelScore->count; i++) { - this = (widget_t *) (listWidgetLabelScore->list[i]); - drawWidgetLabel(this); - } - - drawWidgetLabel(widgetLabelMsg); - drawWidgetButton(button_ok); -} - -void eventScreenAnalyze() -{ - eventWidgetButton(button_ok); -} - -void stopScreenAnalyze() -{ - destroyWidgetLabel(widgetLabelMsg); - widgetLabelMsg = newWidgetLabel("", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); - - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_ok) { - setScreen("mainMenu"); - } -} - -void restartAnalyze() -{ - destroyListItem(listWidgetLabelName, destroyWidgetLabel); - destroyListItem(listWidgetLabelScore, destroyWidgetLabel); - destroyListItem(listAnalyze, destroyAnalyze); - - listWidgetLabelName = newList(); - listWidgetLabelScore = newList(); - listAnalyze = newList(); -} - -void addAnalyze(char *name, int score) -{ - addList(listAnalyze, newAnalyze(name, score)); -} - -void setMsgToAnalyze(char *msg) -{ - destroyWidgetLabel(widgetLabelMsg); - widgetLabelMsg = newWidgetLabel(msg, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); -} - -void endAnalyze() -{ - int i; - - for (i = 0; i < listAnalyze->count; i++) { - analyze_t *this; - char *str; - - this = (analyze_t *) (listAnalyze->list[i]); - - addList(listWidgetLabelName, newWidgetLabel(this->name, 100, - 200 + 20 * i, WIDGET_LABEL_LEFT)); - - str = getString(this->score); - - addList(listWidgetLabelScore, newWidgetLabel(str, WINDOW_SIZE_X - 100, - 200 + 20 * i, WIDGET_LABEL_RIGHT)); - - free(str); - } -} - -void initScreenAnalyze() -{ - image_t *image; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - listWidgetLabelName = newList(); - listWidgetLabelScore = newList(); - listAnalyze = newList(); - - button_ok = newWidgetButton("OK", WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, - WINDOW_SIZE_Y - 100, eventWidget); - - registerScreen( newScreen("analyze", startScreenAnalyze, eventScreenAnalyze, - drawScreenAnalyze, stopScreenAnalyze)); - - widgetLabelMsg = newWidgetLabel("", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); -} - -void quitScreenAnalyze() -{ - destroyWidgetImage(image_backgorund); - - destroyListItem(listWidgetLabelName, destroyWidgetLabel); - destroyListItem(listWidgetLabelScore, destroyWidgetLabel); - destroyListItem(listAnalyze, destroyAnalyze); - - destroyWidgetButton(button_ok); - destroyWidgetLabel(widgetLabelMsg); -} diff --git a/src/screen/screen_analyze.h b/src/screen/screen_analyze.h deleted file mode 100644 index 8f975b4..0000000 --- a/src/screen/screen_analyze.h +++ /dev/null @@ -1,24 +0,0 @@ - -#ifndef SCREEN_ANALYZE_H - -# define SCREEN_ANALYZE_H - -# include "main.h" - -typedef struct analyze_struct { - char *name; - int score; -} analyze_t; - -extern void startScreenAnalyze(); -extern void drawScreenAnalyze(); -extern void eventScreenAnalyze(); -extern void stopScreenAnalyze(); -extern void restartAnalyze(); -extern void addAnalyze(char *name, int score); -extern void setMsgToAnalyze(char *msg); -extern void endAnalyze(); -extern void initScreenAnalyze(); -extern void quitScreenAnalyze(); - -#endif diff --git a/src/screen/screen_browser.c b/src/screen/screen_browser.c deleted file mode 100644 index f09ca18..0000000 --- a/src/screen/screen_browser.c +++ /dev/null @@ -1,729 +0,0 @@ - -#include -#include -#include - -#include "main.h" -#include "list.h" -#include "textFile.h" -#include "homeDirector.h" -#include "net_multiplayer.h" - -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef __WIN32__ -# include -# include -# include -# include -# include -# include -#else -# include -# include -#endif - -#include -#include -#include - -#include "udp.h" -#include "dns.h" - -extern int errno; - -#ifndef NO_SOUND -# include "music.h" -#endif - -#include "screen_gameType.h" -#include "screen_browser.h" - -#include "widget.h" -#include "widget_image.h" -#include "widget_label.h" -#include "widget_button.h" -#include "widget_select.h" - -#define SERVER_TIMEOUT 200 - -static widget_t *image_backgorund; - -static widget_t *button_play; -static widget_t *button_back; -static widget_t *button_refresh; - -static widget_t *label_server; -static widget_t *label_version; -static widget_t *label_address; -static widget_t *label_arena; -static widget_t *label_players; -static widget_t *label_ping; - -static widget_t *select_server; - -static server_t server_list; - -/* function prototypes */ -static int LoadServers(); -static int RefreshServers(); -static server_t *server_getcurr(); - -static void hotkey_escape() -{ - setScreen("gameType"); -} - -void startScreenBrowser() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - registerHotKey(SDLK_ESCAPE, hotkey_escape); - - LoadServers(); -} - -void drawScreenBrowser() -{ - drawWidgetImage(image_backgorund); - - drawWidgetLabel(label_server); - drawWidgetLabel(label_version); - drawWidgetLabel(label_address); - drawWidgetLabel(label_arena); - drawWidgetLabel(label_players); - drawWidgetLabel(label_ping); - - drawWidgetSelect(select_server); - - drawWidgetButton(button_play); - drawWidgetButton(button_back); - drawWidgetButton(button_refresh); -} - -void eventScreenBrowser() -{ - eventWidgetSelect(select_server); - - eventWidgetButton(button_play); - eventWidgetButton(button_back); - eventWidgetButton(button_refresh); -} - -void stopScreenBrowser() -{ - unsigned i = 0; - server_t *server; - - //destroyListItem(select_server->list, free); - //select_server->list = newList(); - removeAllFromWidgetSelect(select_server); - - unregisterHotKey(SDLK_ESCAPE); - - while (1) { - i = 0; - for (server = server_list.next; server != &server_list; - server = server->next) { - server->next->prev = server->prev; - server->prev->next = server->next; - - if (server->name) - free(server->name); - - if (server->version) - free(server->version); - - if (server->arena) - free(server->arena); - - free(server); - - i++; - break; - } - - if (!i) - return; - } -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_play) { - server_t *server = server_getcurr(); - - if (!server) - return; - - /* server je offline */ - if (!server->state) - return; - - struct in_addr srv; - srv.s_addr = server->ip; - - char *address = (char *) inet_ntoa(srv); - - setSettingGameType(NET_GAME_TYPE_CLIENT); - setSettingIP(address); - setSettingPort(server->port); - - setScreen("world"); - } - - if (button == button_back) { - setScreen("gameType"); - } - - if (button == button_refresh) { - RefreshServers(); - } -} - -server_t *server_getcurr() -{ - unsigned i = 0; - server_t *server; - - for (server = server_list.next; server != &server_list; - server = server->next) { - if (i == getWidgetSelectIndex(select_server)) - return server; - - i++; - } - - return 0; -} - -int server_getinfo(server_t * server) -{ - struct sockaddr_in srv; - int mySocket; - - if ((mySocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { - return -1; - } -#ifndef __WIN32__ - // Lets make socket non-blocking - int oldFlag = fcntl(mySocket, F_GETFL, 0); - if (fcntl(mySocket, F_SETFL, oldFlag | O_NONBLOCK) == -1) { - return -1; - } -#else - unsigned long arg = 1; - // Operation is FIONBIO. Parameter is pointer on non-zero number. - if (ioctlsocket(mySocket, FIONBIO, &arg) == SOCKET_ERROR) { - WSACleanup(); - return -1; - } -#endif - - struct timeval tv; - - fd_set myset; - FD_ZERO(&myset); - FD_SET(mySocket, &myset); - - tv.tv_sec = 2; - tv.tv_usec = 0; - - srv.sin_family = AF_INET; - srv.sin_port = htons(server->port); - srv.sin_addr.s_addr = server->ip; - - if (connect(mySocket, (struct sockaddr *) &srv, sizeof(srv)) == -1) { -#ifndef __WIN32__ - if (errno != EINPROGRESS) - return -1; -#else - if (WSAGetLastError() != WSAEWOULDBLOCK) { - WSACleanup(); - return -1; - } -#endif - } - - int ret = select(mySocket + 1, NULL, &myset, NULL, &tv); - - if (ret == -1) - return 0; - - if (ret == 0) - return -2; - - char request[8]; - memcpy(request, "status\n", 7); - - int r = send(mySocket, request, 7, 0); - - if (r == -1) - return -2; - - FD_ZERO(&myset); - FD_SET(mySocket, &myset); - tv.tv_sec = 1; - tv.tv_usec = 0; - - char *str = (char *) malloc(sizeof(char) * 257); - - if (!str) - return -1; - - while (1) { - int sel = select(mySocket + 1, &myset, NULL, NULL, &tv); - - if (sel == 0) { - free(str); -#ifndef __WIN32__ - close(mySocket); -#else - closesocket(mySocket); - WSACleanup(); -#endif - return -2; - } - - if (sel == -1) { - free(str); -#ifndef __WIN32__ - close(mySocket); -#else - closesocket(mySocket); - WSACleanup(); -#endif - return -2; - } - - if ((ret = recv(mySocket, str, 256, 0)) == -1) { - free(str); -#ifndef __WIN32__ - close(mySocket); -#else - closesocket(mySocket); - WSACleanup(); -#endif - return -1; - } - - if (ret > 0) - break; - } - -#ifndef __WIN32__ - close(mySocket); -#else - closesocket(mySocket); - WSACleanup(); -#endif - - server->ping = 1000 - (tv.tv_usec / 1000); - /* - ["name: F\n"] >= svn82 - "version: svnX\n" - "clients: N\n" - "maxclients: M\n" - "uptime: D\n" - */ - - unsigned i = 0; - - while (i < ret) { - if (str[i] == '\n') - str[i] = '\0'; - - i++; - } - - unsigned name = 0; - - if (strstr(str, "name: ")) - name = 1; - - int len = 0; - - if (name) { - len = strlen(str); - if (!strncmp(str, "name: ", 6)) { - unsigned name_len = strlen(str + 6); - server->name = (char *) malloc(sizeof(char) * (name_len + 2)); - - if (!server->name) - return 0; - - memcpy(server->name, str + 6, name_len + 1); - server->name[name_len + 1] = '\0'; - } - } - - /* HACK */ - if (!name) - len = -1; - - if (!strncmp(str + len + 1, "version: ", 9)) { - unsigned ver_len = strlen(str + len + 10); - server->version = (char *) malloc(sizeof(char) * (ver_len + 2)); - - if (!server->version) - return 0; - - memcpy(server->version, str + len + 10, ver_len + 1); - server->version[ver_len + 1] = '\0'; - } - - len += strlen(str + len + 1) + 1; - - - if (!strncmp(str + len + 1, "clients: ", 9)) - server->clients = atoi(str + len + 10); - - len += strlen(str + len + 1) + 1; - - - if (!strncmp(str + len + 1, "maxclients: ", 12)) - server->maxclients = atoi(str + len + 13); - - len += strlen(str + len + 1) + 1; - - - if (!strncmp(str + len + 1, "uptime: ", 8)) - server->uptime = atoi(str + len + 9); - - len += strlen(str + len + 1) + 1; - - - if (!strncmp(str + len + 1, "arena: ", 7)) { - unsigned arena_len = strlen(str + len + 9); - server->arena = (char *) malloc(sizeof(char) * (arena_len + 2)); - - if (!server->arena) - return 0; - - memcpy(server->arena, str + len + 8, arena_len + 1); - server->arena[arena_len + 1] = '\0'; - } - - - free(str); - - server->state = 1; - - return 1; -} - -static int LoadServers() -// Get server list -{ -#ifndef __WIN32__ - int s; -#else - SOCKET s; -#endif - - char buf[1025]; - - /* TODO: dodelat TCP makro */ - struct sockaddr_in server; - char *master_server_ip; - - master_server_ip = getIPFormDNS(NET_MASTER_SERVER_DOMAIN); - - //printf("master_server_ip = %s\n", master_server_ip); - - if (master_server_ip == NULL) // master server is down - { - return -1; - } - - server.sin_family = AF_INET; - server.sin_port = htons(NET_MASTER_PORT); - server.sin_addr.s_addr = inet_addr(master_server_ip); - - free(master_server_ip); - - if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) - return 0; - -#ifndef __WIN32__ - // Lets make socket non-blocking - int oldFlag = fcntl(s, F_GETFL, 0); - if (fcntl(s, F_SETFL, oldFlag | O_NONBLOCK) == -1) { - return -1; - } -#else - unsigned long arg = 1; - // Operation is FIONBIO. Parameter is pointer on non-zero number. - if (ioctlsocket(s, FIONBIO, &arg) == SOCKET_ERROR) { - WSACleanup(); - return -1; - } -#endif - - if (connect(s, (struct sockaddr *) &server, sizeof(server)) == -1) { -#ifndef __WIN32__ - if (errno != EINPROGRESS) - return -1; -#else - if (WSAGetLastError() != WSAEWOULDBLOCK) { - WSACleanup(); - return -1; - } -#endif - } - - struct timeval tv; - - fd_set myset; - - FD_ZERO(&myset); - FD_SET(s, &myset); - - tv.tv_sec = 3; - tv.tv_usec = 0; - - int ret = select(s + 1, NULL, &myset, NULL, &tv); - - if (ret == -1) - return 0; - - if (ret == 0) - return -2; - - /* send request for server list */ - send(s, "l", 1, 0); - - FD_ZERO(&myset); - FD_SET(s, &myset); - - ret = select(s + 1, &myset, NULL, NULL, &tv); - - if (ret == -1) - return 0; - - if (ret == 0) - return -2; - - int len = recv(s, buf, 1024, 0); - -#ifndef __WIN32__ - close(s); -#else - closesocket(s); - WSACleanup(); -#endif - - if (len <= 0) - return 0; - - unsigned i = 0; - char list[256]; - - struct in_addr srv; - - typedef struct { - unsigned port; - unsigned ip; - } response_head; - - while (1) { - response_head *header = (response_head *) ((char *) buf + i); - - server_t *ctx; - - // alloc and init context - ctx = (server_t *) malloc(sizeof(server_t)); - - ctx->ip = header->ip; - ctx->port = header->port; - ctx->name = 0; - ctx->version = 0; - ctx->arena = 0; - - int ret = server_getinfo(ctx); - - srv.s_addr = ctx->ip; - - char *address = (char *) inet_ntoa(srv); - - memset(list, ' ', 254); - list[255] = '\0'; - - if (ret == 1) { - /*sprintf (list, "%s (%s) - %s:%d - %s - %d/%d - %dms", ctx->name ? ctx->name : "Unknown", ctx->version, address, ctx->port, - ctx->arena ? ctx->arena : "Unknown", ctx->clients, ctx->maxclients, ctx->ping); */ - - if (ctx->name) - memcpy(list, ctx->name, strlen(ctx->name)); - else - memcpy(list, "Unknown", 7); - - memcpy(list + 30, ctx->version, strlen(ctx->version)); - - unsigned a_len = strlen(address); - memcpy(list + 38, address, a_len); - memcpy(list + 38 + a_len, ":", 1); - - sprintf(buf, "%d", ctx->port); - - memcpy(list + 39 + a_len, buf, strlen(buf)); - - memcpy(list + 60, ctx->arena, strlen(ctx->arena)); - - sprintf(buf, "%d/%d", ctx->clients, ctx->maxclients); - - memcpy(list + 75, buf, strlen(buf)); - - sprintf(buf, "%dms", ctx->ping); - - memcpy(list + 83, buf, strlen(buf)); - } - - addToWidgetSelect(select_server, list); - - // add into list - ctx->next = &server_list; - ctx->prev = server_list.prev; - ctx->prev->next = ctx; - ctx->next->prev = ctx; - - i += sizeof(response_head) + 1; - - if (buf[i - 1] != '\n' || (i + 1) > len) - break; - } - - return 1; -} - -static int RefreshServers() -{ -/* - destroyListItem(select_server->list, free); - select_server->list = newList(); -*/ - removeAllFromWidgetSelect(select_server); - - struct in_addr srv; - - server_t *server; - for (server = server_list.next; server != &server_list; - server = server->next) { - if (server->name) - free(server->name); - - if (server->version) - free(server->version); - - if (server->arena) - free(server->arena); - - server->name = 0; - server->version = 0; - server->arena = 0; - - char list[256]; - char buf[32]; - - int ret = server_getinfo(server); - - srv.s_addr = server->ip; - - char *address = (char *) inet_ntoa(srv); - - if (ret == 1) { - memset(list, ' ', 254); - list[255] = '\0'; - - if (server->name) - memcpy(list, server->name, strlen(server->name)); - else - memcpy(list, "Unknown", 7); - - memcpy(list + 30, server->version, strlen(server->version)); - - unsigned a_len = strlen(address); - memcpy(list + 38, address, a_len); - memcpy(list + 38 + a_len, ":", 1); - - sprintf(buf, "%d", server->port); - - memcpy(list + 39 + a_len, buf, strlen(buf)); - - memcpy(list + 60, server->arena, strlen(server->arena)); - - sprintf(buf, "%d/%d", server->clients, server->maxclients); - - memcpy(list + 75, buf, strlen(buf)); - - sprintf(buf, "%dms", server->ping); - - memcpy(list + 83, buf, strlen(buf)); - } - - addToWidgetSelect(select_server, list); - - } - - return 1; -} - -void initScreenBrowser() -{ - image_t *image; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = - newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); - button_play = - newWidgetButton(_("Play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, - eventWidget); - button_refresh = - newWidgetButton(_("Refresh"), WINDOW_SIZE_X / 2 - 50, - WINDOW_SIZE_Y - 100, eventWidget); - - label_server = newWidgetLabel(_("server"), 120, 145, WIDGET_LABEL_LEFT); - label_version = newWidgetLabel(_("version"), 290, 145, WIDGET_LABEL_LEFT); - label_address = newWidgetLabel(_("IP"), 400, 145, WIDGET_LABEL_LEFT); - label_arena = newWidgetLabel(_("arena"), 550, 145, WIDGET_LABEL_LEFT); - label_players = newWidgetLabel(_("clients"), 645, 145, WIDGET_LABEL_LEFT); - label_ping = newWidgetLabel(_("ping"), 720, 145, WIDGET_LABEL_LEFT); - - select_server = newWidgetSelect(50, label_server->y + 40, eventWidget); - - registerScreen(newScreen - ("browser", startScreenBrowser, eventScreenBrowser, - drawScreenBrowser, stopScreenBrowser)); - - server_list.next = &server_list; - server_list.prev = &server_list; -} - -void quitScreenBrowser() -{ - destroyWidgetImage(image_backgorund); - - destroyWidgetButton(button_play); - destroyWidgetButton(button_back); - destroyWidgetButton(button_refresh); - - destroyWidgetLabel(label_server); - destroyWidgetLabel(label_version); - destroyWidgetLabel(label_address); - destroyWidgetLabel(label_arena); - destroyWidgetLabel(label_players); - destroyWidgetLabel(label_ping); - - destroyWidgetSelect(select_server); -} diff --git a/src/screen/screen_browser.h b/src/screen/screen_browser.h deleted file mode 100644 index e810e58..0000000 --- a/src/screen/screen_browser.h +++ /dev/null @@ -1,33 +0,0 @@ - -#ifndef SCREEN_BROWSER_H - -# define SCREEN_BROWSER_H - -typedef struct server_context { - struct server_context *next, *prev; - - unsigned char state; - - unsigned char ping; - - unsigned ip; - unsigned port; - - char *name; - - char *version; - unsigned char clients; - unsigned char maxclients; - unsigned uptime; - char *arena; -} server_t; - - -extern void startScreenBrowser(); -extern void drawScreenBrowser(); -extern void eventScreenBrowser(); -extern void stopScreenBrowser(); -extern void initScreenBrowser(); -extern void quitScreenBrowser(); - -#endif diff --git a/src/screen/screen_choiceArena.c b/src/screen/screen_choiceArena.c deleted file mode 100644 index a1b725b..0000000 --- a/src/screen/screen_choiceArena.c +++ /dev/null @@ -1,245 +0,0 @@ - -#include -#include - -#include "main.h" -#include "list.h" -#include "arenaFile.h" - -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -#endif - -#include "screen_mainMenu.h" -#include "screen_choiceArena.h" - -#include "widget.h" -#include "widget_label.h" -#include "widget_button.h" -#include "widget_image.h" -#include "widget_buttonimage.h" - -static widget_t *image_backgorund; - -static widget_t *button_play; -static widget_t *button_back; -static widget_t *button_next; -static widget_t *button_prev; - -//static list_t *listWidgetButtonimage; // map buttons to be showed and handled - well, show_map_buttons is used instead -static list_t *listAllWidgetButtonimage; // all map buttons -static int handled_map_button_group; // 0 - first 6 buttons, 1 - second 6 buttons, .... -static void activateHandledMapButtonGroup(); -static struct show_map_buttons { - // geez, it'd be nicer to used two lists - // but how the hell is list_t supposed to be used?! :-) - int min; // see activateHandledMapButtonGroup for desc - int max; // - int next; // 0: max is last item+1 in listAllWidgetButtonimage, otherwise 1 - int prev; // 0: min is first item in listAllWidgetButtonimage, otherwise 1 -} show_map_buttons = { 0,0,0,0 } ; -static arenaFile_t *currentArena; - -static void hotkey_escape() -{ - setScreen("gameType"); -} - -void startScreenChoiceArena() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} - -void drawScreenChoiceArena() -{ - int i; - - drawWidgetImage(image_backgorund); - - drawWidgetButton(button_play); - drawWidgetButton(button_back); - if (show_map_buttons.next) { drawWidgetButton(button_next); } - if (show_map_buttons.prev) { drawWidgetButton(button_prev); } - - for (i = show_map_buttons.min ; i < show_map_buttons.max; i++) { - drawWidgetButtonimage((widget_t*)listAllWidgetButtonimage->list[i]); - } -} - -void eventScreenChoiceArena() -{ - int i; - - eventWidgetButton(button_play); - eventWidgetButton(button_back); - if (show_map_buttons.next) { eventWidgetButton(button_next); } - if (show_map_buttons.prev) { eventWidgetButton(button_prev); } - - for (i = show_map_buttons.min ; i < show_map_buttons.max; i++) { - eventWidgetButtonimage((widget_t*)listAllWidgetButtonimage->list[i]); - } -} - -void stopScreenChoiceArena() -{ - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidgetButtonImage(void *p) -{ - widget_t *buttonimage; - int i; - - buttonimage = (widget_t *) (p); - - for (i = show_map_buttons.min; i < show_map_buttons.max; i++) { - widget_t *this; - - this = (widget_t *) (listAllWidgetButtonimage->list[i]); - - if (buttonimage == this) { - setWidgetButtonimageActive(this, TRUE); - currentArena = getArenaFile(i); - } else { - setWidgetButtonimageActive(this, FALSE); - } - } -} - -arenaFile_t *getChoiceArena() -{ - return currentArena; -} - -void setChoiceArena(arenaFile_t * arenaFile) -{ - widget_t *widget_buttonimage; - int id; - - id = getArenaFileID(arenaFile); - currentArena = arenaFile; - - if (id >= 0) { - widget_buttonimage = (widget_t *) listAllWidgetButtonimage->list[id]; - setWidgetButtonimageActive(widget_buttonimage, TRUE); - } -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_play) { - setScreen("world"); - } - - if (button == button_back) { - setScreen("gameType"); - } - if (button == button_next) { - if (show_map_buttons.next) { - handled_map_button_group++; - activateHandledMapButtonGroup(); - } - } - if (button == button_prev) { - if (show_map_buttons.prev) { - handled_map_button_group--; - activateHandledMapButtonGroup(); - } - } -} - -// groups of 6 map buttons to be shown and handled -// the group is set by static global variable handled_map_button_group -// sets static global show_map_buttons.min to index of first button to be drawn in listAllButtonimage -// and show_map_buttons.max to index of last button to be drawn+1 in listAllButtonimage -static void activateHandledMapButtonGroup(void) { - int min = handled_map_button_group * 6; - min = min < 0 ? 0 : min; - min = min <= getArenaCount() ? min : getArenaCount(); - int max = min+6 <= getArenaCount() ? min+6 : getArenaCount(); - - if (min) { show_map_buttons.prev = 1; } - else { show_map_buttons.prev = 0; } - if (max < getArenaCount()) { show_map_buttons.next = 1; } - else { show_map_buttons.next = 0; } - show_map_buttons.min = min; - show_map_buttons.max = max; -} - -void initScreenChoiceArena() -{ - image_t *image; - int i; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); - button_play = newWidgetButton(_("play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, eventWidget); - - button_prev = newWidgetButton(_("prev maps"), 250, WINDOW_SIZE_Y - 100, eventWidget); - button_next = newWidgetButton(_("next maps"), WINDOW_SIZE_X-350, WINDOW_SIZE_Y - 100, eventWidget); - - listAllWidgetButtonimage = newList(); - currentArena = NULL; - - for (i = 0; i < getArenaCount(); i++) { - widget_t *widget_buttonimage; - arenaFile_t *arenaFile; - int x, y; - - arenaFile = getArenaFile(i); - //image = addImageData(getArenaImage(i), IMAGE_NO_ALPHA, "none", IMAGE_GROUP_BASE); - image = loadImageFromArena(arenaFile, getArenaImage(arenaFile), - IMAGE_GROUP_BASE, "none", IMAGE_NO_ALPHA); - - // only 6 map buttons can be shown at once; - // set buttons' positions in each group to the corresponding values - // handled_map_button_group and activateHandledMapButtonGroup is used - // to choose group to be shown and handled - int pos = i % 6 ; - x = 100 + 200 * (pos - 3 * (pos / 3)); - y = 150 + 200 * (pos / 3); - - widget_buttonimage = newWidgetButtonimage(image, x, y, eventWidgetButtonImage); -/* - if( i == choiceArenaId ) - { - widget_buttonimage->active = 1; - } -*/ - addList(listAllWidgetButtonimage, widget_buttonimage); - handled_map_button_group = 0; - activateHandledMapButtonGroup(); - } - - registerScreen( newScreen("chiceArena", startScreenChoiceArena, - eventScreenChoiceArena, drawScreenChoiceArena, - stopScreenChoiceArena)); -} - -void quitScreenChoiceArena() -{ - destroyWidgetImage(image_backgorund); - - destroyWidgetButton(button_play); - destroyWidgetButton(button_back); - - destroyWidgetButton(button_next); - destroyWidgetButton(button_prev); - - destroyListItem(listAllWidgetButtonimage, destroyWidgetButtonimage); -} diff --git a/src/screen/screen_choiceArena.h b/src/screen/screen_choiceArena.h deleted file mode 100644 index dbe12de..0000000 --- a/src/screen/screen_choiceArena.h +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef SCREEN_CHOICE_ARENA - -# define SCREEN_CHOICE_ARENA - -# include "main.h" -# include "arenaFile.h" - -# define SCREENSHOT_ARENA_WIDTH 160 -# define SCREENSHOT_ARENA_HEIGHT 107 - -extern void drawScreenChoiceArena(); -extern void eventScreenChoiceArena(); -extern arenaFile_t *getChoiceArena(); -extern void setChoiceArena(arenaFile_t * arenaFile); -extern void initScreenChoiceArena(); -extern void quitScreenChoiceArena(); - -#endif diff --git a/src/screen/screen_credits.c b/src/screen/screen_credits.c deleted file mode 100644 index a3ed787..0000000 --- a/src/screen/screen_credits.c +++ /dev/null @@ -1,163 +0,0 @@ - -#include -#include - -#include "main.h" -#include "list.h" -#include "textFile.h" - -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -#endif - -#include "screen_credits.h" - -#include "widget.h" -#include "widget_image.h" -#include "widget_label.h" -#include "widget_button.h" - -static widget_t *image_backgorund; -static widget_t *button_back; -static list_t *listWidgetLabel; -static textFile_t *textFile; -static int offset; -static int creditExists; - -static void hotkey_escape() -{ - setScreen("mainMenu"); -} - -void startScreenCredits() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - offset = 0; - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} - -void drawScreenCredits() -{ - int i; - - drawWidgetImage(image_backgorund); - - drawWidgetButton(button_back); - - for (i = 0; i < listWidgetLabel->count; i++) { - int z; - - widget_t *this; - - this = (widget_t *) listWidgetLabel->list[i]; - - z = this->y; - this->y += offset; - - if (this->y > SCREEN_CREDITS_OFFSET_MIN && this->y < SCREEN_CREDITS_OFFSET_MAX) { - drawWidgetLabel(this); - } - - this->y = z; - } - -} - -void eventScreenCredits() -{ - eventWidgetButton(button_back); - - offset -= SCREEN_CREDITS_OFFSET_SPEED; - - if (offset < SCREEN_CREDITS_OFFSET_RESTART) { - offset = 0; - } - - //printf("offset = %d\n", offset); -} - -void stopScreenCredits() -{ - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_back) { - setScreen("mainMenu"); - } -} - -void initScreenCredits() -{ - image_t *image; - int i; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = newWidgetButton(_("back"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, - WINDOW_SIZE_Y - 80, eventWidget); - - listWidgetLabel = newList(); - - if (tryExistFile(PATH_DOC SCREEN_CREDITS_FILE) == 0) { - creditExists = 1; - textFile = loadTextFile(PATH_DOC SCREEN_CREDITS_FILE); - - for (i = 0; i < textFile->text->count; i++) { - widget_t *label; - char *line; - - line = (char *) textFile->text->list[i]; - - label = newWidgetLabel(line, WINDOW_SIZE_X / 2 - WINDOW_SIZE_X / 4, - (WINDOW_SIZE_Y - 100) + i * 20, - WIDGET_LABEL_LEFT); - - addList(listWidgetLabel, label); - } - } else { - for (i = 0; i < 5; i++) { - creditExists = 0; - widget_t *label; - char line[STR_SIZE]; - - sprintf(line, _("Credit file not found... %s/%s"), PATH_DOC, - SCREEN_CREDITS_FILE); - - label = newWidgetLabel(line, WINDOW_SIZE_X / 2, - (WINDOW_SIZE_Y - 100) + i * 20, - WIDGET_LABEL_CENTER); - - addList(listWidgetLabel, label); - } - } - - registerScreen(newScreen ("credits", startScreenCredits, eventScreenCredits, - drawScreenCredits, stopScreenCredits)); -} - -void quitScreenCredits() -{ - destroyWidgetImage(image_backgorund); - - destroyWidgetButton(button_back); - destroyListItem(listWidgetLabel, destroyWidgetLabel); - - if (creditExists) { - destroyTextFile(textFile); - } -} diff --git a/src/screen/screen_credits.h b/src/screen/screen_credits.h deleted file mode 100644 index 37c25f3..0000000 --- a/src/screen/screen_credits.h +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef SCREEN_CREDITS_H - -# define SCREEN_CREDITS_H - -# define SCREEN_CREDITS_FILE "AUTHORS" - -# define SCREEN_CREDITS_OFFSET_MIN 130 -# define SCREEN_CREDITS_OFFSET_MAX WINDOW_SIZE_Y-120 -# define SCREEN_CREDITS_OFFSET_RESTART -1000 -# define SCREEN_CREDITS_OFFSET_SPEED 2 - -extern void startScreenCredits(); -extern void drawScreenCredits(); -extern void eventScreenCredits(); -extern void stopScreenCredits(); -extern void initScreenCredits(); -extern void quitScreenCredits(); - -#endif diff --git a/src/screen/screen_downArena.c b/src/screen/screen_downArena.c deleted file mode 100644 index d26621b..0000000 --- a/src/screen/screen_downArena.c +++ /dev/null @@ -1,391 +0,0 @@ - -#include -#include -#include -#include - -#include "main.h" -#include "list.h" -#include "buffer.h" -#include "textFile.h" -#include "arenaFile.h" -#include "homeDirector.h" - -#include "interface.h" -#include "screen.h" -#include "image.h" - -#include "net_multiplayer.h" -#include "udp.h" -#include "tcp.h" - -#include "widget.h" -#include "widget_image.h" -#include "widget_label.h" -#include "widget_button.h" - -#include "screen_setting.h" -#include "screen_downArena.h" -#include "screen_gameType.h" - -static sock_udp_t *sock_server_udp; -static sock_tcp_t *sock_server_tcp; - -static widget_t *image_backgorund; -static widget_t *button_back; -static widget_t *label_status; - -static char str_status[STR_PROTO_SIZE]; -static char arenaNetName[STR_SIZE]; - -static int status_tcp_socket; -static buffer_t *recvBuffer; -static buffer_t *sendBuffer; - -static char path[STR_PATH_SIZE]; -static FILE *file; -static int fileSize; -static int fileOffset; - -static my_time_t timeSendMsg; -static int countSendMsg; - -static void setStatusString(char *s) -{ - printf("status -> %s\n", s); - destroyWidgetLabel(label_status); - label_status = newWidgetLabel(s, WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); -} - -static void connectToDownServer() -{ - char status[STR_SIZE]; - char msg[STR_PROTO_SIZE]; - - sock_server_tcp = connectTcpSocket(getSettingIP(), getSettingPort()); - - if( sock_server_tcp == NULL ) - { - sprintf(status, "I do not connect to %s %d TCP down server", getSettingIP(), getSettingPort()); - setStatusString(status); - return; - } - - setTcpSockNonBlock(sock_server_tcp); - - recvBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE); - sendBuffer = newBuffer(DOWN_ARENA_BUFFER_SIZE); - status_tcp_socket = DOWN_SERVER_STATUS_OK; - - file = NULL; - countSendMsg = 0; - timeSendMsg = getMyTime(); - - sprintf(msg, "GETARENA %s\n", arenaNetName); - - addBuffer(sendBuffer, msg, strlen(msg)); - - sprintf(status, "Connect to %s %d TCP down server", getSettingIP(), getSettingPort()); - setStatusString(status); -} - -static void closeConnectFromDownServer() -{ - closeTcpSocket(sock_server_tcp); - destroyBuffer(recvBuffer); - destroyBuffer(sendBuffer); - sock_server_tcp = NULL; - recvBuffer = NULL; - sendBuffer = NULL; -} - -static void sendStatusToGameServer() -{ - char *msg = "status\n"; - - if( countSendMsg > DOWN_ARENA_MAX_SEND_MSG_STATUS ) - { - char status[STR_SIZE]; - sprintf(status, "Game server %s %d is down", getSettingIP(), getSettingPort()); - setStatusString(status); - return; - } - - timeSendMsg = getMyTime(); - countSendMsg++; - printf("countSendMsg = %d\n", countSendMsg++); - - if( writeUdpSocket(sock_server_udp, sock_server_udp, msg, strlen(msg)) < 0 ) - { - char status[STR_SIZE]; - sprintf(status, "I do not send message to %s %d UDP game server", getSettingIP(), getSettingPort()); - setStatusString(status); - } -} - -void startScreenDownArena() -{ - char status[STR_SIZE]; - - strcpy(str_status, "none"); - memset(arenaNetName, 0, STR_SIZE); - - sock_server_udp = connectUdpSocket(getSettingIP(), getSettingPort()); - - if (sock_server_udp == NULL) - { - sprintf(status, "I do not connect to %s %d UDP game server", getSettingIP(), getSettingPort()); - setStatusString(status); - return; - } - - setUdpSockNonBlock(sock_server_udp); - - sprintf(status, "Connect to %s %d UDP game server", getSettingIP(), getSettingPort()); - setStatusString(status); - - sendStatusToGameServer(); -} - -void drawScreenDownArena() -{ - drawWidgetImage(image_backgorund); - drawWidgetLabel(label_status); - drawWidgetButton(button_back); -} - -static void proto_ok(char *line) -{ - //printf("line = %s\n", line); - fileSize = atoi(line + 3); - fileOffset = 0; - - sprintf(path, "%s/%s.zip", getHomeDirector(), arenaNetName); - //printf("path = %s\n", path); - file = fopen(path, "wb"); -} - -static void proto_err(char *line) -{ - //printf("line = %s\n", line); - setStatusString(line + 4); - closeConnectFromDownServer(); -} - -static void eventProto(char *line) -{ - if( strncmp(line, "OK", 2) == 0 ) - { - proto_ok(line); - } - - if( strncmp(line, "ERR", 3) == 0 ) - { - proto_err(line); - } -} - -static int downArenaFile() -{ - char status[STR_SIZE]; - void *data; - int len; - - len = getBufferSize(recvBuffer); - data = getBufferData(recvBuffer); - cutBuffer(recvBuffer, len); - - fwrite(data, len, 1, file); - fileOffset += len; - - sprintf(status, "I down %d / %d", fileOffset, fileSize); - setStatusString(status); - - return len; -} - -static int eventRecvBuffer() -{ - char buffer[STR_PROTO_SIZE]; - char line[STR_PROTO_SIZE]; - int ret; - - memset(buffer, 0, STR_PROTO_SIZE); - - ret = readTcpSocket(sock_server_tcp, buffer, STR_PROTO_SIZE - 1); - //if (ret <= 0) printf("readTcpSocket = %d\n", ret); - - if (ret < 0) { - return -1; - } - - if (addBuffer(recvBuffer, buffer, ret) < 0) { - char status[STR_SIZE]; - sprintf(status, "Error -- recv buffer is full"); - setStatusString(status); - closeConnectFromDownServer(); - return -1; - } - - if (file == NULL && getBufferLine(recvBuffer, line, STR_PROTO_SIZE) >= 0) { - eventProto(line); - return ret; - } - - if (file != NULL) { - return downArenaFile(); - } - - return -1; -} - -static int eventSendBuffer() -{ - void *data; - int len; - int res; - - len = getBufferSize(sendBuffer); - - if (len == 0) { - return -1; - } - - data = getBufferData(sendBuffer); - - res = writeTcpSocket(sock_server_tcp, data, len); - - if (res < 0) { - return -1; - } - - cutBuffer(sendBuffer, res); - return res; -} - -static void readArenaFromStatus() -{ - const char *str_arena = "arena: "; - - char *offset_begin; - char *offset_end; - - offset_begin = strstr(str_status, str_arena); - - if (offset_begin != NULL) { - offset_begin += strlen(str_arena); - offset_end = strstr(offset_begin, "\n"); - - if (offset_end != NULL) { - closeUdpSocket(sock_server_udp); - sock_server_udp = NULL; - strncpy(arenaNetName, offset_begin, offset_end - offset_begin); - - if (getArenaFileFormNetName(arenaNetName) != NULL) { - setScreen("world"); - return; - } - - connectToDownServer(); - - printf("arenaNetName = >>%s<<\n", arenaNetName); - } - } -} - -static void eventStatus() -{ - if( getMyTime() - timeSendMsg > DOWN_ARENA_MAX_TIEMOUT_LIMIT ) - { - sendStatusToGameServer(); - } - - if( readUdpSocket(sock_server_udp, sock_server_udp, str_status, STR_PROTO_SIZE - 1) > 0 ) - { - //printf("str_status = %s\n", str_status); - readArenaFromStatus(); - } -} - -void eventScreenDownArena() -{ - int i; - - if (strcmp(str_status, "none") == 0) { - eventStatus(); - } - - if (recvBuffer != NULL) { - for (i = 0; i < DOWN_ARENA_COUNT_READ_SOCKET; i++) { - if (eventRecvBuffer() <= 0) { - break; - } - } - } - - if (sendBuffer != NULL) { - eventSendBuffer(); - } - - if (file != NULL && fileSize == fileOffset && fileSize > 0) { - fclose(file); - file = NULL; - closeConnectFromDownServer(); - loadArenaFile(path); - setScreen("world"); - } - - eventWidgetButton(button_back); -} - -void stopScreenDownArena() -{ - if (file != NULL) { - unlink(path); - } - - if (sock_server_tcp != NULL) { - closeConnectFromDownServer(); - } - - if (sock_server_udp != NULL) { - closeUdpSocket(sock_server_udp); - } - -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_back) { - setScreen("mainMenu"); - } -} - -void initScreenDownArena() -{ - image_t *image; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = - newWidgetButton(_("back"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, - WINDOW_SIZE_Y - 80, eventWidget); - - label_status = - newWidgetLabel("none", WINDOW_SIZE_X / 2, 250, WIDGET_LABEL_CENTER); - - registerScreen( newScreen("downArena", startScreenDownArena, eventScreenDownArena, - drawScreenDownArena, stopScreenDownArena)); -} - -void quitScreenDownArena() -{ - destroyWidgetImage(image_backgorund); - destroyWidgetButton(button_back); - destroyWidgetLabel(label_status); -} diff --git a/src/screen/screen_downArena.h b/src/screen/screen_downArena.h deleted file mode 100644 index d9f25d7..0000000 --- a/src/screen/screen_downArena.h +++ /dev/null @@ -1,22 +0,0 @@ - -#ifndef SCREEN_DOWN_ARENA_H - -# define SCREEN_DOWN_ARENA_H - -# define DOWN_SERVER_STATUS_OK 0 -# define DOWN_SERVER_STATUS_ZOMBIE 1 - -# define DOWN_ARENA_BUFFER_SIZE 4096 - -# define DOWN_ARENA_MAX_SEND_MSG_STATUS 10 -# define DOWN_ARENA_MAX_TIEMOUT_LIMIT 500 -# define DOWN_ARENA_COUNT_READ_SOCKET 100 - -extern void startScreenDownArena(); -extern void drawScreenDownArena(); -extern void eventScreenDownArena(); -extern void stopScreenDownArena(); -extern void initScreenDownArena(); -extern void quitScreenDownArena(); - -#endif diff --git a/src/screen/screen_gameType.c b/src/screen/screen_gameType.c deleted file mode 100644 index 1ef8461..0000000 --- a/src/screen/screen_gameType.c +++ /dev/null @@ -1,384 +0,0 @@ - -#include -#include -#include - -#include "main.h" -#include "list.h" -#include "director.h" -#include "homeDirector.h" -#include "net_multiplayer.h" -#include "tux.h" - -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -#endif - -#include "screen_gameType.h" -#include "screen_setting.h" - -#include "widget.h" -#include "widget_label.h" -#include "widget_button.h" -#include "widget_image.h" -#include "widget_textfield.h" -#include "widget_choicegroup.h" -#include "widget_check.h" -#include "widget_select.h" - -static widget_t *image_backgorund; - -static widget_t *button_back; -static widget_t *button_play; -static widget_t *button_browser; - -static widget_t *label_none; -static widget_t *label_server; -static widget_t *label_client; -static widget_t *label_load_session; - -static widget_t *label_ip; -static widget_t *label_port; -static widget_t *label_session; - -static list_t *listChoiceGroup; -static widget_t *check_none; -static widget_t *check_server; -static widget_t *check_client; -static widget_t *check_load_session; - -static widget_t *textfield_ip; -static widget_t *textfield_port; - -static widget_t *selectSession; - -static void loadSession(widget_t * p) -{ - director_t *director; - int i; - - director = loadDirector(getHomeDirector()); - - removeAllFromWidgetSelect(p); - - 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, line); - } - } - - destroyDirector(director); -} - -static void hotkey_escape() -{ - setScreen("mainMenu"); -} - -void startScreenGameType() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - setWidgetChoiceStatus(check_none, TRUE); - setWidgetChoiceStatus(check_server, FALSE); - setWidgetChoiceStatus(check_client, FALSE); - setWidgetChoiceStatus(check_load_session, FALSE); - - loadSession(selectSession); - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} - -void drawScreenGameType() -{ - int i; - - drawWidgetImage(image_backgorund); - - for (i = 0; i < listChoiceGroup->count; i++) { - widget_t *this; - - this = (widget_t *) listChoiceGroup->list[i]; - drawWidgetChoicegroup(this); - } - - drawWidgetLabel(label_none); - drawWidgetLabel(label_server); - drawWidgetLabel(label_client); - drawWidgetLabel(label_load_session); - - if (getWidgetChoiceStatus(check_server) == TRUE || getWidgetChoiceStatus(check_client) == TRUE) { - drawWidgetLabel(label_port); - drawWidgetTextfield(textfield_port); - drawWidgetLabel(label_ip); - drawWidgetTextfield(textfield_ip); - } - - if (getWidgetChoiceStatus(check_load_session) == TRUE) { - drawWidgetLabel(label_session); - drawWidgetSelect(selectSession); - } -#if 0 - if (check_server->status == TRUE) { - setSettingIP(getParamElse("--ip", "127.0.0.1")); - setSettingPort(atoi(getParamElse("--port", "2200"))); - } -#endif - - if (getWidgetChoiceStatus(check_client) == TRUE) - drawWidgetButton(button_browser); - - drawWidgetButton(button_back); - drawWidgetButton(button_play); - -} - -void eventScreenGameType() -{ - int i; - - for (i = 0; i < listChoiceGroup->count; i++) { - widget_t *this; - - this = (widget_t *) listChoiceGroup->list[i]; - eventWidgetChoicegroup(this); - } - - if (getWidgetChoiceStatus(check_server) == TRUE || getWidgetChoiceStatus(check_client) == TRUE) { - eventWidgetTextfield(textfield_ip); - eventWidgetTextfield(textfield_port); - } - - if (getWidgetChoiceStatus(check_load_session) == TRUE) { - eventWidgetSelect(selectSession); - } - - eventWidgetButton(button_back); - eventWidgetButton(button_play); - - if (getWidgetChoiceStatus(check_client) == TRUE) - eventWidgetButton(button_browser); -} - -void stopScreenGameType() -{ - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_back) { - setScreen("mainMenu"); - } - - if (button == button_play) { - char *str; - - str = getGemeTypeLoadSession(); - - if (str != NULL) { - setScreen("world"); - return; - } - - if (getSettingGameType() == NET_GAME_TYPE_CLIENT) { - setScreen("downArena"); - //setScreen("world"); - } else { - setScreen("chiceArena"); - } - } - - if (button == button_browser) { - setScreen("browser"); - } -} - -void initScreenGameType() -{ - image_t *image; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = newWidgetButton(_("back"), 100, WINDOW_SIZE_Y - 100, eventWidget); - button_play = newWidgetButton(_("play"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, eventWidget); - button_browser = newWidgetButton(_("browser"), 300, 345, 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")) { - setWidgetChoiceStatus(check_server, TRUE); - } else if (isParamFlag("--client")) { - setWidgetChoiceStatus(check_client, TRUE); - } else { - setWidgetChoiceStatus(check_none, TRUE); - } - - label_none = newWidgetLabel(_("Local game"), 130, 145, WIDGET_LABEL_LEFT); - label_server = newWidgetLabel(_("Set up a server"), 130, 195, WIDGET_LABEL_LEFT); - label_client = newWidgetLabel(_("Network game"), 130, 245, WIDGET_LABEL_LEFT); - label_load_session = newWidgetLabel("load session", 130, 295, WIDGET_LABEL_LEFT); - - label_ip = newWidgetLabel(_("IP"), 300, 145, WIDGET_LABEL_LEFT); - label_port = newWidgetLabel(_("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"), - WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN, - 300, 180); - - textfield_port = newWidgetTextfield(getParamElse("--port", "6800"), - WIDGET_TEXTFIELD_FILTER_NUM, 300, 280); - - selectSession = newWidgetSelect(300, 185, eventWidget); - - registerScreen( newScreen("gameType", startScreenGameType, eventScreenGameType, - drawScreenGameType, stopScreenGameType)); -} - -int setSettingGameType(int status) -{ - if (status == NET_GAME_TYPE_NONE) { - setWidgetChoiceStatus(check_none, TRUE); - return 0; - } - - if (status == NET_GAME_TYPE_SERVER) { - setWidgetChoiceStatus(check_server, TRUE); - return 0; - } - - if (status == NET_GAME_TYPE_CLIENT) { - setWidgetChoiceStatus(check_client, TRUE); - return 0; - } - - return -1; -} - -int getSettingGameType() -{ - if (getWidgetChoiceStatus(check_none) == TRUE || getWidgetChoiceStatus(check_load_session) == TRUE) { - return NET_GAME_TYPE_NONE; - } - - if (getWidgetChoiceStatus(check_server) == TRUE) { - return NET_GAME_TYPE_SERVER; - } - - if (getWidgetChoiceStatus(check_client) == TRUE) { - return NET_GAME_TYPE_CLIENT; - } - - assert(!_("Unknown game type!")); - - return -1; -} - -char *getGemeTypeLoadSession() -{ - if (getWidgetChoiceStatus(check_load_session) == TRUE) { - return getWidgetSelectItem(selectSession); - } - - return NULL; -} - -int setSettingIP(char *address) -{ - char str[STR_SIZE]; - - strcpy(str, address); - setWidgetTextFiledText(textfield_ip, str); - - return 1; -} - -char *getSettingIP() -{ - return getTextFromWidgetTextfield(textfield_ip); -} - -int setSettingPort(int port) -{ - char str[STR_SIZE]; - - sprintf(str, "%d", port); - setWidgetTextFiledText(textfield_port, str); - - return 0; -} - -int getSettingPort() -{ - return atoi(getTextFromWidgetTextfield(textfield_port)); -} - -int getSettingProto() -{ - if (strstr(getTextFromWidgetTextfield(textfield_ip), ".") != NULL) { - return PROTO_UDPv4; - } - - if (strstr(getTextFromWidgetTextfield(textfield_ip), ":") != NULL) { - return PROTO_UDPv6; - } - - DEBUG_MSG(_("Unknown IP protocol!\n")); - - return -1; -} - -void quitScreenGameType() -{ - destroyWidgetImage(image_backgorund); - - 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); - - 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 deleted file mode 100644 index 2c836fc..0000000 --- a/src/screen/screen_gameType.h +++ /dev/null @@ -1,21 +0,0 @@ - -#ifndef SCREEN_GAME_TYPE - -# define SCREEN_GAME_TYPE - -# include "main.h" - -extern void drawScreenGameType(); -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); -extern int getSettingPort(); -extern int getSettingProto(); -extern void quitScreenGameType(); - -#endif diff --git a/src/screen/screen_mainMenu.c b/src/screen/screen_mainMenu.c deleted file mode 100644 index 84d57b8..0000000 --- a/src/screen/screen_mainMenu.c +++ /dev/null @@ -1,133 +0,0 @@ - -#include -#include - -#include "main.h" - -#include "game.h" -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -#endif - -#include "screen_mainMenu.h" -#include "screen_setting.h" - -#include "widget.h" -#include "widget_label.h" -#include "widget_button.h" -#include "widget_textfield.h" -#include "widget_check.h" -#include "widget_image.h" - -static widget_t *image_backgorund; - -static widget_t *button_play; -static widget_t *button_setting; -static widget_t *button_table; -static widget_t *button_credits; -static widget_t *button_end; - -static void hotkey_escape() -{ - quitGame(); -} - -void startScreenMainMenu() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} - -void drawScreenMainMenu() -{ - drawWidgetImage(image_backgorund); - - drawWidgetButton(button_play); - drawWidgetButton(button_setting); - drawWidgetButton(button_table); - drawWidgetButton(button_credits); - drawWidgetButton(button_end); -} - -void eventScreenMainMenu() -{ - eventWidgetButton(button_play); - eventWidgetButton(button_setting); - eventWidgetButton(button_table); - eventWidgetButton(button_credits); - eventWidgetButton(button_end); -} - -void stopScreenMainMenu() -{ - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_play) { - setScreen("gameType"); - } - - if (button == button_setting) { - setScreen("setting"); - } - - if (button == button_table) { - setScreen("table"); - } - - if (button == button_credits) { - setScreen("credits"); - } - - if (button == button_end) { - quitGame(); - } -} - -void initScreenMainMenu() -{ - image_t *image; - - image = - addImageData("screen_main.png", IMAGE_NO_ALPHA, "screen_main", - IMAGE_GROUP_BASE); - image_backgorund = newWidgetImage(0, 0, image); - - button_play = newWidgetButton(_("Start game"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 200, eventWidget); - button_setting = newWidgetButton(_("Settings"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 250, eventWidget); - button_table = newWidgetButton(_("Highscore"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 300, eventWidget); - button_credits = newWidgetButton(_("Credits"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 350, eventWidget); - button_end = newWidgetButton(_("Quit game"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, 400, eventWidget); - -#ifndef NO_SOUND - addMusic("menu.ogg", "menu", MUSIC_GROUP_BASE); -#endif - - registerScreen( newScreen("mainMenu", startScreenMainMenu, eventScreenMainMenu, - drawScreenMainMenu, stopScreenMainMenu)); -} - -void quitScreenMainMenu() -{ - destroyWidgetImage(image_backgorund); - - destroyWidgetButton(button_play); - destroyWidgetButton(button_setting); - destroyWidgetButton(button_table); - destroyWidgetButton(button_credits); - destroyWidgetButton(button_end); -} diff --git a/src/screen/screen_mainMenu.h b/src/screen/screen_mainMenu.h deleted file mode 100644 index ecb369b..0000000 --- a/src/screen/screen_mainMenu.h +++ /dev/null @@ -1,15 +0,0 @@ - -#ifndef SCREEN_MIAN_MENU_H - -# define SCREEN_MIAN_MENU_H - -# include "main.h" - -extern void startScreenMainMenu(); -extern void drawScreenMainMenu(); -extern void eventScreenMainMenu(); -extern void stopScreenMainMenu(); -extern void initScreenMainMenu(); -extern void quitScreenMainMenu(); - -#endif diff --git a/src/screen/screen_setting.c b/src/screen/screen_setting.c deleted file mode 100644 index b52a9db..0000000 --- a/src/screen/screen_setting.c +++ /dev/null @@ -1,538 +0,0 @@ - -#include -#include -#include - -#include "main.h" -#include "list.h" -#include "tux.h" -#include "textFile.h" -#include "director.h" -#include "homeDirector.h" -#include "arenaFile.h" - -#include "configFile.h" -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -# include "sound.h" -#endif - -#include "screen_mainMenu.h" -#include "screen_setting.h" -#include "screen_settingKeys.h" -#include "screen_settingKeys.h" -#include "screen_choiceArena.h" - -#include "widget.h" -#include "widget_label.h" -#include "widget_button.h" -#include "widget_image.h" -#include "widget_textfield.h" -#include "widget_check.h" -#include "widget_select.h" - -static widget_t *image_backgorund; - -static widget_t *button_back; -static widget_t *button_keys; // setting of keycontrols - -static widget_t *label_count_round; -static widget_t *label_name_player1; -static widget_t *label_name_player2; -static widget_t *label_ai; - -#ifndef NO_SOUND -static widget_t *label_music; -static widget_t *label_sound; -#endif - -static widget_t *check[ITEM_COUNT]; -#ifndef NO_SOUND -static widget_t *check_music; -static widget_t *check_sound; -#endif - -static widget_t *image_gun_dual_revolver; -static widget_t *image_gun_scatter; -static widget_t *image_gun_tommy; -static widget_t *image_gun_lasser; -static widget_t *image_gun_mine; -static widget_t *image_gun_bombball; - -static widget_t *image_bonus_speed; -static widget_t *image_bonus_shot; -static widget_t *image_bonus_teleport; -static widget_t *image_bonus_ghost; -static widget_t *image_bonus_4x; -static widget_t *image_bonus_hidden; - -static widget_t *textfield_count_cound; -static widget_t *textfield_name_player1; -static widget_t *textfield_name_player2; - -static widget_t *check_ai; - -static textFile_t *configFile; - -static void hotkey_escape() -{ - setScreen("mainMenu"); -} - -void startScreenSetting() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} - -void drawScreenSetting() -{ - int i; - - drawWidgetImage(image_backgorund); - - drawWidgetLabel(label_count_round); - drawWidgetLabel(label_name_player1); - drawWidgetLabel(label_ai); - -#ifndef NO_SOUND - drawWidgetLabel(label_music); - drawWidgetLabel(label_sound); -#endif - - drawWidgetTextfield(textfield_count_cound); - drawWidgetTextfield(textfield_name_player1); - - if (getWidgetCheckStatus(check_ai) == FALSE) { - drawWidgetLabel(label_name_player2); - drawWidgetTextfield(textfield_name_player2); - } - - drawWidgetImage(image_gun_dual_revolver); - drawWidgetImage(image_gun_scatter); - drawWidgetImage(image_gun_tommy); - drawWidgetImage(image_gun_lasser); - drawWidgetImage(image_gun_mine); - drawWidgetImage(image_gun_bombball); - - drawWidgetImage(image_bonus_speed); - drawWidgetImage(image_bonus_shot); - drawWidgetImage(image_bonus_teleport); - drawWidgetImage(image_bonus_ghost); - drawWidgetImage(image_bonus_4x); - drawWidgetImage(image_bonus_hidden); - -#ifndef NO_SOUND - drawWidgetCheck(check_music); - drawWidgetCheck(check_sound); -#endif - - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - drawWidgetCheck(check[i]); - } - - for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { - drawWidgetCheck(check[i]); - } - - drawWidgetCheck(check_ai); - - drawWidgetButton(button_back); - drawWidgetButton(button_keys); -} - -void eventScreenSetting() -{ - int i; - - eventWidgetTextfield(textfield_count_cound); - eventWidgetTextfield(textfield_name_player1); - - if (getWidgetCheckStatus(check_ai) == FALSE) { - eventWidgetTextfield(textfield_name_player2); - } - -#ifndef NO_SOUND - eventWidgetCheck(check_music); - eventWidgetCheck(check_sound); -#endif - - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - eventWidgetCheck(check[i]); - } - - for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { - eventWidgetCheck(check[i]); - } - - eventWidgetCheck(check_ai); - - eventWidgetButton(button_back); - eventWidgetButton(button_keys); -} - -void stopScreenSetting() -{ - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidget(void *p) -{ - widget_t *button; - widget_t *check; - - button = (widget_t *) (p); - check = (widget_t *) (p); - - if (button == button_back) { - setScreen("mainMenu"); - } - - if (button == button_keys) { - setScreen("settingKeys"); - } - -#ifndef NO_SOUND - if (check == check_music) { - setMusicActive(getWidgetCheckStatus(check_music)); - } - - if (check == check_sound) { - setSoundActive(getWidgetCheckStatus(check_sound)); - } -#endif -} - -static void initSettingFile() -{ - char path[STR_PATH_SIZE]; - char val[STR_SIZE]; - - sprintf(path, "%s/tuxanci.conf", getHomeDirector()); - - configFile = loadTextFile(path); - - if (configFile == NULL) { - fprintf(stderr, _("I am unable to load: \"%s\"!\n"), path); - fprintf(stderr, _("Creating: \"%s\"\n"), path); - - configFile = newTextFile(path); - } - - if (configFile == NULL) { - fprintf(stderr, _("I was unable to create: \"%s\"!\n"), path); - return; - } - - loadValueFromConfigFile(configFile, "COUNT_ROUND", val, STR_SIZE, "15"); - setWidgetTextFiledText(textfield_count_cound, val); - - loadValueFromConfigFile(configFile, "NAME_PLAYER_RIGHT", val, STR_SIZE, - NAME_PLAYER_RIGHT); - setWidgetTextFiledText(textfield_name_player1, val); - - loadValueFromConfigFile(configFile, "NAME_PLAYER_LEFT", val, STR_SIZE, - NAME_PLAYER_LEFT); - setWidgetTextFiledText(textfield_name_player2, val); - - loadValueFromConfigFile(configFile, "GUN_DUAL_SIMPLE", val, STR_SIZE, - "YES"); - setWidgetCheckStatus(check[GUN_DUAL_SIMPLE], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_SCATTER", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_SCATTER], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_TOMMY", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_TOMMY], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_LASSER", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_LASSER], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_MINE", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_MINE], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "GUN_BOMBBALL", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[GUN_BOMBBALL], isYesOrNO(val)); - - loadValueFromConfigFile(configFile, "BONUS_SPEED", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_SPEED], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_SHOT", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_SHOT], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_TELEPORT", val, STR_SIZE, - "YES"); - setWidgetCheckStatus(check[BONUS_TELEPORT], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_GHOST", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_GHOST], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_4X", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_4X], isYesOrNO(val)); - loadValueFromConfigFile(configFile, "BONUS_HIDDEN", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check[BONUS_HIDDEN], isYesOrNO(val)); - - loadValueFromConfigFile(configFile, "AI", val, STR_SIZE, "NO"); - setWidgetCheckStatus(check_ai, isYesOrNO(val)); - -#ifndef NO_SOUND - loadValueFromConfigFile(configFile, "MUSIC", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check_music, isYesOrNO(val)); - - loadValueFromConfigFile(configFile, "SOUND", val, STR_SIZE, "YES"); - setWidgetCheckStatus(check_sound, isYesOrNO(val)); -#endif - - loadValueFromConfigFile(configFile, "ARENA", val, STR_SIZE, "FAGN"); - setChoiceArena(getArenaFileFormNetName(val)); - - saveTextFile(configFile); -} - -static void saveAndDestroyConfigFile() -{ - if (configFile == NULL) { - fprintf(stderr, _("I am unable to save configure file, because config file was not initialised!\n")); - return; - } - - setValueInConfigFile(configFile, "COUNT_ROUND", getTextFromWidgetTextfield(textfield_count_cound)); - setValueInConfigFile(configFile, "NAME_PLAYER_RIGHT", getTextFromWidgetTextfield(textfield_name_player1)); - setValueInConfigFile(configFile, "NAME_PLAYER_LEFT", getTextFromWidgetTextfield(textfield_name_player2)); - setValueInConfigFile(configFile, "GUN_DUAL_SIMPLE", getYesOrNo(getWidgetCheckStatus(check[GUN_DUAL_SIMPLE]))); - setValueInConfigFile(configFile, "GUN_SCATTER", getYesOrNo(getWidgetCheckStatus(check[GUN_SCATTER]))); - setValueInConfigFile(configFile, "GUN_TOMMY", getYesOrNo(getWidgetCheckStatus(check[GUN_TOMMY]))); - setValueInConfigFile(configFile, "GUN_LASSER", getYesOrNo(getWidgetCheckStatus(check[GUN_LASSER]))); - setValueInConfigFile(configFile, "GUN_MINE", getYesOrNo(getWidgetCheckStatus(check[GUN_MINE]))); - setValueInConfigFile(configFile, "GUN_BOMBBALL", getYesOrNo(getWidgetCheckStatus(check[GUN_BOMBBALL]))); - setValueInConfigFile(configFile, "BONUS_SPEED", getYesOrNo(getWidgetCheckStatus(check[BONUS_SPEED]))); - setValueInConfigFile(configFile, "BONUS_SHOT", getYesOrNo(getWidgetCheckStatus(check[BONUS_SHOT]))); - setValueInConfigFile(configFile, "BONUS_TELEPORT", getYesOrNo(getWidgetCheckStatus (check[BONUS_TELEPORT]))); - setValueInConfigFile(configFile, "BONUS_GHOST", getYesOrNo(getWidgetCheckStatus(check[BONUS_GHOST]))); - setValueInConfigFile(configFile, "BONUS_4X", getYesOrNo(getWidgetCheckStatus(check[BONUS_4X]))); - setValueInConfigFile(configFile, "BONUS_HIDDEN", getYesOrNo(getWidgetCheckStatus(check[BONUS_HIDDEN]))); - setValueInConfigFile(configFile, "AI", getYesOrNo(getWidgetCheckStatus(check_ai))); - -#ifndef NO_SOUND - setValueInConfigFile(configFile, "MUSIC", getYesOrNo(getWidgetCheckStatus(check_music))); - setValueInConfigFile(configFile, "SOUND", getYesOrNo(getWidgetCheckStatus(check_sound))); -#endif - - if( getChoiceArena() != NULL ) - { - setValueInConfigFile(configFile, "ARENA", getArenaNetName(getChoiceArena())); - } - //TODO - - saveTextFile(configFile); - destroyTextFile(configFile); -} - -void initScreenSetting() -{ - image_t *image; - int i; - - image = getImage(IMAGE_GROUP_BASE, "screen_main"); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = newWidgetButton(_("back"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, eventWidget); - - button_keys = newWidgetButton(_("controls"), WINDOW_SIZE_X - 200, - button_back->y - WIDGET_BUTTON_HEIGHT - 10, eventWidget); - -#ifndef NO_SOUND - label_music = newWidgetLabel(_("Music:"), 100, WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); - - check_music = newWidgetCheck(label_music->x + label_music->w + 10, - WINDOW_SIZE_Y - 80, isMusicActive(), eventWidget); - label_sound = newWidgetLabel(_("Sound:"), check_music->x + WIDGET_CHECK_WIDTH + 10, - WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); - - check_sound = newWidgetCheck(label_sound->x + label_sound->w + 10, - WINDOW_SIZE_Y - 80, isSoundActive(), eventWidget); - - label_ai = newWidgetLabel(_("AI:"), check_sound->x + WIDGET_CHECK_WIDTH + 10, - WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); -#else - label_ai = newWidgetLabel(_("AI:"), 100, WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); -#endif - - check_ai = newWidgetCheck(label_ai->x + label_ai->w + 10, WINDOW_SIZE_Y - 80, FALSE, eventWidget); - - label_count_round = newWidgetLabel(_("No. of rounds:"), 100, WINDOW_SIZE_Y - 200, WIDGET_LABEL_LEFT); - label_name_player1 = newWidgetLabel(_("Player 1:"), 100, WINDOW_SIZE_Y - 160, WIDGET_LABEL_LEFT); - label_name_player2 = newWidgetLabel(_("Player 2:"), 100, WINDOW_SIZE_Y - 120, WIDGET_LABEL_LEFT); - - textfield_count_cound = newWidgetTextfield(getParamElse("--count", "15"), - WIDGET_TEXTFIELD_FILTER_NUM, - 110 + label_count_round->w, - WINDOW_SIZE_Y - 200); - - textfield_name_player1 = newWidgetTextfield(getParamElse("--name1", NAME_PLAYER_RIGHT), - WIDGET_TEXTFIELD_FILTER_ALPHANUM, - 110 + label_count_round->w, WINDOW_SIZE_Y - 160); - - textfield_name_player2 = newWidgetTextfield(getParamElse("--name2", NAME_PLAYER_LEFT), - WIDGET_TEXTFIELD_FILTER_ALPHANUM, - 110 + label_count_round->w, WINDOW_SIZE_Y - 120); - - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - int x = 0; - int y = 0; - - if (i >= GUN_DUAL_SIMPLE && i <= GUN_TOMMY) { - x = 100; - y = 200 + (i - GUN_DUAL_SIMPLE) * 50; - } - - if (i >= GUN_LASSER && i <= GUN_BOMBBALL) { - x = 250; - y = 200 + (i - GUN_LASSER) * 50; - } - - check[i] = newWidgetCheck(x, y, TRUE, NULL); - } - - for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { - int x = 0; - int y = 0; - - if (i >= BONUS_SPEED && i <= BONUS_TELEPORT) { - x = 430; - y = 200 + (i - BONUS_SPEED) * 50; - } - - if (i >= BONUS_GHOST && i <= BONUS_HIDDEN) { - x = 580; - y = 200 + (i - BONUS_GHOST) * 50; - } - - check[i] = newWidgetCheck(x, y, TRUE, NULL); - } - - image_gun_dual_revolver = newWidgetImage(110 + WIDGET_CHECK_WIDTH, 200, getImage(IMAGE_GROUP_BASE, "panel_dual")); - image_gun_scatter = newWidgetImage(110 + WIDGET_CHECK_WIDTH, 250, getImage(IMAGE_GROUP_BASE, "panel_scatter")); - image_gun_tommy = newWidgetImage(110 + WIDGET_CHECK_WIDTH, 300, getImage(IMAGE_GROUP_BASE, "panel_tommy")); - image_gun_lasser = newWidgetImage(260 + WIDGET_CHECK_WIDTH, 200,getImage(IMAGE_GROUP_BASE, "panel_lasser")); - image_gun_mine = newWidgetImage(260 + WIDGET_CHECK_WIDTH, 250, getImage(IMAGE_GROUP_BASE, "panel_mine")); - image_gun_bombball = newWidgetImage(260 + WIDGET_CHECK_WIDTH, 300, getImage(IMAGE_GROUP_BASE, "panel_bombball")); - image_bonus_speed = newWidgetImage(430 + WIDGET_CHECK_WIDTH, 200, getImage(IMAGE_GROUP_BASE, "panel_speed"));; - image_bonus_shot = newWidgetImage(430 + WIDGET_CHECK_WIDTH, 250, getImage(IMAGE_GROUP_BASE, "panel_shot"));; - image_bonus_teleport = newWidgetImage(430 + WIDGET_CHECK_WIDTH, 300, getImage(IMAGE_GROUP_BASE, "panel_teleport"));; - image_bonus_ghost = newWidgetImage(580 + WIDGET_CHECK_WIDTH, 200, getImage(IMAGE_GROUP_BASE, "panel_ghost"));; - image_bonus_4x = newWidgetImage(580 + WIDGET_CHECK_WIDTH, 250, getImage(IMAGE_GROUP_BASE, "panel_4x"));; - image_bonus_hidden = newWidgetImage(580 + WIDGET_CHECK_WIDTH, 300, getImage(IMAGE_GROUP_BASE, "panel_hidden"));; - - registerScreen( newScreen("setting", startScreenSetting, eventScreenSetting, - drawScreenSetting, stopScreenSetting)); - - initSettingFile(); - -#ifndef NO_SOUND - eventWidget(check_music); - eventWidget(check_sound); -#endif -} - -void getSettingNameRight(char *s) -{ - strcpy(s, getTextFromWidgetTextfield(textfield_name_player1)); -} - -void getSettingNameLeft(char *s) -{ - if (getWidgetCheckStatus(check_ai)) { - strcpy(s, NAME_AI); - } else { - strcpy(s, getTextFromWidgetTextfield(textfield_name_player2)); - } -} - -void getSettingCountRound(int *n) -{ - *n = atoi(getTextFromWidgetTextfield(textfield_count_cound)); -} - -bool_t isSettingAI() -{ - return getWidgetCheckStatus(check_ai); -} - -bool_t isSettingAnyItem() -{ - int i; - - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - if (getWidgetCheckStatus(check[i]) == TRUE) { - return TRUE; - } - } - - for (i = BONUS_SPEED; i < BONUS_HIDDEN; i++) { - if (getWidgetCheckStatus(check[i]) == TRUE) { - return TRUE; - } - } - - return FALSE; -} - -bool_t isSettingItem(int item) -{ - return getWidgetCheckStatus(check[item]); -} - -void quitScreenSetting() -{ - int i; - - saveAndDestroyConfigFile(); - - destroyWidgetImage(image_backgorund); - - destroyWidgetLabel(label_count_round); - destroyWidgetLabel(label_name_player1); - destroyWidgetLabel(label_ai); - -#ifndef NO_SOUND - destroyWidgetLabel(label_music); - destroyWidgetLabel(label_sound); -#endif - destroyWidgetLabel(label_name_player2); - destroyWidgetTextfield(textfield_name_player2); - - destroyWidgetTextfield(textfield_name_player1); - destroyWidgetTextfield(textfield_count_cound); - - destroyWidgetImage(image_gun_dual_revolver); - destroyWidgetImage(image_gun_scatter); - destroyWidgetImage(image_gun_tommy); - destroyWidgetImage(image_gun_lasser); - destroyWidgetImage(image_gun_mine); - destroyWidgetImage(image_gun_bombball); - - destroyWidgetImage(image_bonus_speed); - destroyWidgetImage(image_bonus_shot); - destroyWidgetImage(image_bonus_teleport); - destroyWidgetImage(image_bonus_ghost); - destroyWidgetImage(image_bonus_4x); - destroyWidgetImage(image_bonus_hidden); - -#ifndef NO_SOUND - destroyWidgetCheck(check_music); - destroyWidgetCheck(check_sound); -#endif - - destroyWidgetCheck(check_ai); - - for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { - destroyWidgetCheck(check[i]); - } - - for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { - destroyWidgetCheck(check[i]); - } - - destroyWidgetButton(button_back); - destroyWidgetButton(button_keys); -} diff --git a/src/screen/screen_setting.h b/src/screen/screen_setting.h deleted file mode 100644 index 9521cca..0000000 --- a/src/screen/screen_setting.h +++ /dev/null @@ -1,22 +0,0 @@ - -#ifndef SCREEN_SETTING - -# define SCREEN_SETTING - -# include "main.h" - -# define NAME_AI "TuxBot" -# define NAME_PLAYER_RIGHT "Name1" -# define NAME_PLAYER_LEFT "Name2" - -extern void initScreenSetting(); -extern void drawScreenSetting(); -extern void eventScreenSetting(); -extern void getSettingNameRight(char *s); -extern void getSettingNameLeft(char *s); -extern void getSettingCountRound(int *n); -extern bool_t isSettingAI(); -extern bool_t isSettingAnyItem(); -extern bool_t isSettingItem(int item); -extern void quitScreenSetting(); -#endif diff --git a/src/screen/screen_settingKeys.c b/src/screen/screen_settingKeys.c deleted file mode 100644 index 35215cf..0000000 --- a/src/screen/screen_settingKeys.c +++ /dev/null @@ -1,589 +0,0 @@ - -#include -#include -#include - -#include "main.h" -#include "list.h" -#include "tux.h" -#include "textFile.h" -#include "director.h" -#include "homeDirector.h" - -#include "configFile.h" -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -# include "sound.h" -#endif /* - */ -#include "screen_mainMenu.h" -#include "screen_setting.h" -#include "screen_settingKeys.h" - -#include "widget.h" -#include "widget_button.h" -#include "widget_image.h" -#include "widget_catchkey.h" -#include "widget_label.h" - -static int keytable[KEY_LENGTH]; - -static textFile_t *keycontrolFile; -static widget_t *image_backgorund; -static widget_t *button_back; - -// key names -static widget_t *tux_right; -static widget_t *tux_right_keyup; -static widget_t *tux_right_keydown; -static widget_t *tux_right_keyleft; -static widget_t *tux_right_keyright; -static widget_t *tux_right_keyswitch; -static widget_t *tux_right_keyfire; - -static widget_t *tux_left; -static widget_t *tux_left_keyup; -static widget_t *tux_left_keydown; - -static widget_t *tux_left_keyleft; -static widget_t *tux_left_keyright; -static widget_t *tux_left_keyswitch; -static widget_t *tux_left_keyfire; - -// key values -static widget_t *tux_right_keyup_val; -static widget_t *tux_right_keydown_val; -static widget_t *tux_right_keyleft_val; -static widget_t *tux_right_keyright_val; -static widget_t *tux_right_keyswitch_val; -static widget_t *tux_right_keyfire_val; -static widget_t *tux_left_keyup_val; -static widget_t *tux_left_keydown_val; -static widget_t *tux_left_keyleft_val; -static widget_t *tux_left_keyright_val; -static widget_t *tux_left_keyswitch_val; -static widget_t *tux_left_keyfire_val; - - -//static widget_t *catcher; -// todo add key images -// possible variant will be reusing widget_image for current widget_label so there wont -// be key names but only images - -static void hotkey_escape() -{ - setScreen("setting"); -} - -void startScreenSettingKeys() -{ - -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} -static void setKeytableFromConfigFile(textFile_t * configFile) -{ - -char val[STR_SIZE]; - - -loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_UP", val, STR_SIZE, - "273"); - -keytable[KEY_TUX_RIGHT_MOVE_UP] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", val, - STR_SIZE, "275"); - -keytable[KEY_TUX_RIGHT_MOVE_RIGHT] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", val, STR_SIZE, - "276"); - -keytable[KEY_TUX_RIGHT_MOVE_LEFT] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", val, STR_SIZE, - "274"); - -keytable[KEY_TUX_RIGHT_MOVE_DOWN] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_RIGHT_SHOOT", val, STR_SIZE, - "48"); - -keytable[KEY_TUX_RIGHT_SHOOT] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", val, - STR_SIZE, "49"); - -keytable[KEY_TUX_RIGHT_SWITCH_WEAPON] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_UP", val, STR_SIZE, - "119"); - -keytable[KEY_TUX_LEFT_MOVE_UP] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", val, STR_SIZE, - "100"); - -keytable[KEY_TUX_LEFT_MOVE_RIGHT] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", val, STR_SIZE, - "97"); - -keytable[KEY_TUX_LEFT_MOVE_LEFT] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", val, STR_SIZE, - "115"); - -keytable[KEY_TUX_LEFT_MOVE_DOWN] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_LEFT_SHOOT", val, STR_SIZE, - "113"); - -keytable[KEY_TUX_LEFT_SHOOT] = atoi(val); - -loadValueFromConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", val, - STR_SIZE, "9"); - -keytable[KEY_TUX_LEFT_SWITCH_WEAPON] = atoi(val); - -} -void - - initKeyTable() -{ - -char path[STR_PATH_SIZE]; - -/* - int i; -*/ - sprintf(path, "%s/keycontrol.conf", getHomeDirector()); - -keycontrolFile = loadTextFile(path); - -if (keycontrolFile == NULL) { - -fprintf(stderr, _("I was unable to load file: %s\n"), path); - -fprintf(stderr, _("I try to create file: %s\n"), path); - -keycontrolFile = newTextFile(path); - -} - -if (keycontrolFile == NULL) { - -fprintf(stderr, _("I was unable to create file: %s\n"), path); - -return; - -} - -setKeytableFromConfigFile(keycontrolFile); - -/* - for( i = 0 ; i < KEY_LENGTH ; i++) - { - printf("keytable[%d] = %d\n", i, keytable[i]); - } -*/ -} - -int getKey(int n) -{ - -// printf("keytable[n] = %d\n", keytable[n]); - return keytable[n]; - -} - -void drawScreenSettingKeys() -{ - -drawWidgetImage(image_backgorund); - -drawWidgetButton(button_back); - - // key names - drawWidgetLabel(tux_right); - -drawWidgetLabel(tux_left); - -drawWidgetLabel(tux_right_keyup); - -drawWidgetLabel(tux_right_keydown); - -drawWidgetLabel(tux_right_keyleft); - -drawWidgetLabel(tux_right_keyright); - -drawWidgetLabel(tux_right_keyswitch); - -drawWidgetLabel(tux_right_keyfire); - -drawWidgetLabel(tux_left_keyup); - -drawWidgetLabel(tux_left_keydown); - -drawWidgetLabel(tux_left_keyleft); - -drawWidgetLabel(tux_left_keyright); - -drawWidgetLabel(tux_left_keyswitch); - -drawWidgetLabel(tux_left_keyfire); - - // key values - drawWidgetCatchkey(tux_right_keyup_val); - -drawWidgetCatchkey(tux_right_keydown_val); - -drawWidgetCatchkey(tux_right_keyleft_val); - -drawWidgetCatchkey(tux_right_keyright_val); - -drawWidgetCatchkey(tux_right_keyswitch_val); - -drawWidgetCatchkey(tux_right_keyfire_val); - -drawWidgetCatchkey(tux_left_keyup_val); - -drawWidgetCatchkey(tux_left_keydown_val); - -drawWidgetCatchkey(tux_left_keyleft_val); - -drawWidgetCatchkey(tux_left_keyright_val); - -drawWidgetCatchkey(tux_left_keyswitch_val); - -drawWidgetCatchkey(tux_left_keyfire_val); - -} -static void - - refreshKeytable() -{ - -keytable[6] = getWidgetCatchKey(tux_left_keyup_val); - -keytable[9] = getWidgetCatchKey(tux_left_keydown_val); - -keytable[8] = getWidgetCatchKey(tux_left_keyleft_val); - -keytable[7] = getWidgetCatchKey(tux_left_keyright_val); - -keytable[10] = getWidgetCatchKey(tux_left_keyfire_val); - -keytable[11] = getWidgetCatchKey(tux_left_keyswitch_val); - -keytable[0] = getWidgetCatchKey(tux_right_keyup_val); - -keytable[3] = getWidgetCatchKey(tux_right_keydown_val); - -keytable[2] = getWidgetCatchKey(tux_right_keyleft_val); - -keytable[1] = getWidgetCatchKey(tux_right_keyright_val); - -keytable[4] = getWidgetCatchKey(tux_right_keyfire_val); - -keytable[5] = getWidgetCatchKey(tux_right_keyswitch_val); - -} -static void eventWidget(void *p) -{ - -widget_t * button; - -widget_t * catcher; - - -button = (widget_t *) (p); - -catcher = (widget_t *) (p); - -if (button == button_back) - -setScreen("setting"); - - //events on value - if ((catcher == tux_left_keyup_val) || - (catcher == tux_left_keydown_val) || - (catcher == tux_left_keyleft_val) || - (catcher == tux_left_keyright_val) || - (catcher == tux_left_keyfire_val) || - (catcher == tux_left_keyswitch_val) || - (catcher == tux_right_keyup_val) || - (catcher == tux_right_keydown_val) || - (catcher == tux_right_keyleft_val) || - (catcher == tux_right_keyright_val) || - (catcher == tux_right_keyswitch_val) || - (catcher == tux_right_keyfire_val)) { - - // draw press any key picture - //this will be done by widget catchkey - // check if there is no other key with new value (what to revert if yes?) - refreshKeytable(); - -} - -} - -void eventScreenSettingKeys() -{ - -eventWidgetButton(button_back); - -eventWidgetCatchkey(tux_right_keyup_val); - -eventWidgetCatchkey(tux_right_keydown_val); - -eventWidgetCatchkey(tux_right_keyleft_val); - -eventWidgetCatchkey(tux_right_keyright_val); - -eventWidgetCatchkey(tux_right_keyswitch_val); - -eventWidgetCatchkey(tux_right_keyfire_val); - -eventWidgetCatchkey(tux_left_keyup_val); - -eventWidgetCatchkey(tux_left_keydown_val); - -eventWidgetCatchkey(tux_left_keyleft_val); - -eventWidgetCatchkey(tux_left_keyright_val); - -eventWidgetCatchkey(tux_left_keyswitch_val); - -eventWidgetCatchkey(tux_left_keyfire_val); - -} -void - - stopScreenSettingKeys() -{ - unregisterHotKey(SDLK_ESCAPE); -} -void - - initScreenSettingKeys() -{ - -image_t * image; - - -initKeyTable(); - -image = getImage(IMAGE_GROUP_BASE, "screen_main"); - -image_backgorund = newWidgetImage(0, 0, image); - -button_back = - newWidgetButton(_("Back"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, - eventWidget); - -tux_left = - newWidgetLabel(_("Player 2"), WINDOW_SIZE_X / 4, 150, - WIDGET_LABEL_CENTER); - -tux_left_keyup = - newWidgetLabel(_("Up"), 50, tux_left->y + 50, WIDGET_LABEL_LEFT); - -tux_left_keydown = - newWidgetLabel(_("Down:"), tux_left_keyup->x, tux_left_keyup->y + 20, - WIDGET_LABEL_LEFT); - -tux_left_keyleft = - newWidgetLabel(_("Left:"), tux_left_keyup->x, - tux_left_keydown->y + 20, WIDGET_LABEL_LEFT); - -tux_left_keyright = - newWidgetLabel(_("Right:"), tux_left_keyup->x, - tux_left_keyleft->y + 20, WIDGET_LABEL_LEFT); - -tux_left_keyfire = - newWidgetLabel(_("Fire gun:"), tux_left_keyup->x, - tux_left_keyright->y + 20, WIDGET_LABEL_LEFT); - -tux_left_keyswitch = - newWidgetLabel(_("Switch gun:"), tux_left_keyup->x, - tux_left_keyfire->y + 20, WIDGET_LABEL_LEFT); - -tux_right = - newWidgetLabel(_("Player 1"), WINDOW_SIZE_X / 2 + WINDOW_SIZE_X / 4, - tux_left->y, WIDGET_LABEL_CENTER); - -tux_right_keyup = - newWidgetLabel(_("Up:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_left->y + 50, WIDGET_LABEL_LEFT); - -tux_right_keydown = - newWidgetLabel(_("Down:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_left_keyup->y + 20, WIDGET_LABEL_LEFT); - -tux_right_keyleft = - newWidgetLabel(_("Left:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_right_keydown->y + 20, WIDGET_LABEL_LEFT); - -tux_right_keyright = - newWidgetLabel(_("Right:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_right_keyleft->y + 20, WIDGET_LABEL_LEFT); - -tux_right_keyfire = - newWidgetLabel(_("Fire gun:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_left_keyright->y + 20, WIDGET_LABEL_LEFT); - -tux_right_keyswitch = - newWidgetLabel(_("Switch gun:"), - WINDOW_SIZE_X / 2 + tux_left_keyup->x, - tux_left_keyfire->y + 20, WIDGET_LABEL_LEFT); - -tux_left_keyup_val = - newWidgetCatchkey(keytable[6], tux_left_keyup->x + 200, - tux_left->y + 50, eventWidget); - -tux_left_keydown_val = - newWidgetCatchkey(keytable[9], tux_left_keyup_val->x, - tux_left_keyup->y + 20, eventWidget); - -tux_left_keyleft_val = - newWidgetCatchkey(keytable[8], tux_left_keyup_val->x, - tux_left_keydown->y + 20, eventWidget); - -tux_left_keyright_val = - newWidgetCatchkey(keytable[7], tux_left_keyup_val->x, - tux_left_keyleft->y + 20, eventWidget); - -tux_left_keyfire_val = - newWidgetCatchkey(keytable[10], tux_left_keyup_val->x, - tux_left_keyright->y + 20, eventWidget); - -tux_left_keyswitch_val = - newWidgetCatchkey(keytable[11], tux_left_keyup_val->x, - tux_left_keyfire->y + 20, eventWidget); - -tux_right_keyup_val = - newWidgetCatchkey(keytable[0], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_left->y + 50, eventWidget); - -tux_right_keydown_val = - newWidgetCatchkey(keytable[3], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_left_keyup->y + 20, eventWidget); - -tux_right_keyleft_val = - newWidgetCatchkey(keytable[2], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_right_keydown->y + 20, eventWidget); - -tux_right_keyright_val = - newWidgetCatchkey(keytable[1], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_right_keyleft->y + 20, eventWidget); - -tux_right_keyfire_val = - newWidgetCatchkey(keytable[4], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_left_keyright->y + 20, eventWidget); - -tux_right_keyswitch_val = - newWidgetCatchkey(keytable[5], - WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, - tux_left_keyfire->y + 20, eventWidget); - -registerScreen(newScreen - ("settingKeys", startScreenSettingKeys, - eventScreenSettingKeys, -drawScreenSettingKeys, - stopScreenSettingKeys)); - -} - -void quitKeyTable() -{ - destroyTextFile(keycontrolFile); -} - -void saveKeyTable(textFile_t * configFile) -{ - char str[STR_SIZE]; - - sprintf(str, "%d", getWidgetCatchKey(tux_left_keyup_val)); - setValueInConfigFile(configFile, "TUX_LEFT_MOVE_UP", str); - sprintf(str, "%d", getWidgetCatchKey(tux_left_keydown_val)); - setValueInConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", str); - sprintf(str, "%d", getWidgetCatchKey(tux_left_keyleft_val)); - setValueInConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", str); - sprintf(str, "%d", getWidgetCatchKey(tux_left_keyright_val)); - setValueInConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", str); - sprintf(str, "%d", getWidgetCatchKey(tux_left_keyfire_val)); - setValueInConfigFile(configFile, "TUX_LEFT_SHOOT", str); - sprintf(str, "%d", getWidgetCatchKey(tux_left_keyswitch_val)); - setValueInConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", str); - - sprintf(str, "%d", getWidgetCatchKey(tux_right_keyup_val)); - setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_UP", str); - sprintf(str, "%d", getWidgetCatchKey(tux_right_keydown_val)); - setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", str); - sprintf(str, "%d", getWidgetCatchKey(tux_right_keyleft_val)); - setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", str); - sprintf(str, "%d", getWidgetCatchKey(tux_right_keyright_val)); - setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", str); - sprintf(str, "%d", getWidgetCatchKey(tux_right_keyfire_val)); - setValueInConfigFile(configFile, "TUX_RIGHT_SHOOT", str); - sprintf(str, "%d", getWidgetCatchKey(tux_right_keyswitch_val)); - setValueInConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", str); - - saveTextFile(configFile); -} - -void quitScreenSettingKeys() -{ - saveKeyTable(keycontrolFile); - quitKeyTable(); - - // key names - destroyWidgetImage(image_backgorund); - - destroyWidgetLabel(tux_right); - destroyWidgetLabel(tux_left); - destroyWidgetLabel(tux_right_keyup); - destroyWidgetLabel(tux_right_keydown); - destroyWidgetLabel(tux_right_keyleft); - destroyWidgetLabel(tux_right_keyright); - destroyWidgetLabel(tux_right_keyswitch); - destroyWidgetLabel(tux_right_keyfire); - destroyWidgetLabel(tux_left_keyup); - destroyWidgetLabel(tux_left_keydown); - destroyWidgetLabel(tux_left_keyright); - destroyWidgetLabel(tux_left_keyleft); - destroyWidgetLabel(tux_left_keyswitch); - destroyWidgetLabel(tux_left_keyfire); - - // key values - destroyWidgetCatchkey(tux_right_keyup_val); - - destroyWidgetCatchkey(tux_right_keydown_val); - destroyWidgetCatchkey(tux_right_keyleft_val); - destroyWidgetCatchkey(tux_right_keyright_val); - destroyWidgetCatchkey(tux_right_keyswitch_val); - destroyWidgetCatchkey(tux_right_keyfire_val); - destroyWidgetCatchkey(tux_left_keyup_val); - destroyWidgetCatchkey(tux_left_keydown_val); - destroyWidgetCatchkey(tux_left_keyleft_val); - destroyWidgetCatchkey(tux_left_keyright_val); - destroyWidgetCatchkey(tux_left_keyswitch_val); - destroyWidgetCatchkey(tux_left_keyfire_val); - destroyWidgetButton(button_back); -} - diff --git a/src/screen/screen_settingKeys.h b/src/screen/screen_settingKeys.h deleted file mode 100644 index c90006e..0000000 --- a/src/screen/screen_settingKeys.h +++ /dev/null @@ -1,27 +0,0 @@ - -#ifndef SCREEN_SETTING_KEYS -# define SCREEN_SETTING_KEYS -# define KEY_TUX_RIGHT_MOVE_UP 0 -# define KEY_TUX_RIGHT_MOVE_RIGHT 1 -# define KEY_TUX_RIGHT_MOVE_LEFT 2 -# define KEY_TUX_RIGHT_MOVE_DOWN 3 -# define KEY_TUX_RIGHT_SHOOT 4 -# define KEY_TUX_RIGHT_SWITCH_WEAPON 5 -# define KEY_TUX_LEFT_MOVE_UP 6 -# define KEY_TUX_LEFT_MOVE_RIGHT 7 -# define KEY_TUX_LEFT_MOVE_LEFT 8 -# define KEY_TUX_LEFT_MOVE_DOWN 9 -# define KEY_TUX_LEFT_SHOOT 10 -# define KEY_TUX_LEFT_SWITCH_WEAPON 11 -# define KEY_LENGTH 12 - -# include "main.h" - extern void initScreenSettingKeys(); - extern void drawScreenSettingKeys(); - extern void eventScreenSettingKeys(); - extern void quitScreenSettingKeys(); - extern void initKeyTable(); - extern int getKey(int n); - extern void quitKeyTable(); - -#endif /* */ diff --git a/src/screen/screen_table.c b/src/screen/screen_table.c deleted file mode 100644 index b49de93..0000000 --- a/src/screen/screen_table.c +++ /dev/null @@ -1,229 +0,0 @@ - -#include -#include -#include - -#include "main.h" -#include "list.h" -#include "textFile.h" -#include "homeDirector.h" - -#include "interface.h" -#include "screen.h" -#include "image.h" -#include "hotKey.h" - -#ifndef NO_SOUND -# include "music.h" -#endif - -#include "screen_table.h" - -#include "widget_image.h" -#include "widget_label.h" -#include "widget_button.h" - -static widget_t *image_backgorund; -static widget_t *button_back; - -static list_t *listWidgetLabelNumer; -static list_t *listWidgetLabelName; -static list_t *listWidgetLabelScore; - -static textFile_t *textFile; - -static void hotkey_escape() -{ - setScreen("mainMenu"); -} - -void startScreenTable() -{ -#ifndef NO_SOUND - playMusic("menu", MUSIC_GROUP_BASE); -#endif - - registerHotKey(SDLK_ESCAPE, hotkey_escape); -} - -void drawScreenTable() -{ - int i; - - drawWidgetImage(image_backgorund); - - drawWidgetButton(button_back); - - for (i = 0; i < listWidgetLabelNumer->count; i++) { - widget_t *this; - this = (widget_t *) listWidgetLabelNumer->list[i]; - drawWidgetLabel(this); - } - - for (i = 0; i < listWidgetLabelName->count; i++) { - widget_t *this; - this = (widget_t *) listWidgetLabelName->list[i]; - drawWidgetLabel(this); - } - - for (i = 0; i < listWidgetLabelScore->count; i++) { - widget_t *this; - this = (widget_t *) listWidgetLabelScore->list[i]; - drawWidgetLabel(this); - } -} - -void eventScreenTable() -{ - eventWidgetButton(button_back); -} - -void stopScreenTable() -{ - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidget(void *p) -{ - widget_t *button; - - button = (widget_t *) (p); - - if (button == button_back) { - setScreen("mainMenu"); - } -} - -static void setWidgetLabel() -{ - int i; - - if (textFile == NULL) { - fprintf(stderr, _("Highscore file: \"%s\" was not loaded!"), SCREEN_TABLE_FILE_HIGHSCORE_NAME); - - return; - } - - if (listWidgetLabelNumer != NULL || - listWidgetLabelName != NULL || - listWidgetLabelScore != NULL) { - destroyListItem(listWidgetLabelNumer, destroyWidgetLabel); - destroyListItem(listWidgetLabelName, destroyWidgetLabel); - destroyListItem(listWidgetLabelScore, destroyWidgetLabel); - } - - listWidgetLabelNumer = newList(); - listWidgetLabelName = newList(); - listWidgetLabelScore = newList(); - - for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { - widget_t *label; - char name[STR_NAME_SIZE]; - char score[STR_NUM_SIZE]; - char num[STR_NUM_SIZE]; - char *line; - - line = (char *) textFile->text->list[i]; - - sscanf(line, "%s %s", name, score); - sprintf(num, "%2d)", i + 1); - - label = newWidgetLabel(num, WINDOW_SIZE_X / 2 - 100, 200 + i * 20, WIDGET_LABEL_LEFT); - addList(listWidgetLabelNumer, label); - - label = newWidgetLabel(name, WINDOW_SIZE_X / 2, 200 + i * 20, WIDGET_LABEL_CENTER); - addList(listWidgetLabelName, label); - - label = newWidgetLabel(score, WINDOW_SIZE_X / 2 + 80, 200 + i * 20, WIDGET_LABEL_LEFT); - addList(listWidgetLabelScore, label); - } -} - -static void loadHighscoreFile() -{ - char path[STR_PATH_SIZE]; - int i; - - sprintf(path, "%s/" SCREEN_TABLE_FILE_HIGHSCORE_NAME, getHomeDirector()); - textFile = loadTextFile(path); - - if (textFile == NULL) { - fprintf(stderr, _("I am unable to load: \"%s\"!\n"), path); - fprintf(stderr, _("Creating: \"%s\"\n"), path); - textFile = newTextFile(path); - } else { - return; - } - - if (textFile == NULL) { - fprintf(stderr, _("I was unable to create: \"%s\"!\n"), path); - return; - } - - for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { - addList(textFile->text, strdup("no_name 0")); - } - - saveTextFile(textFile); -} - -int addPlayerInHighScore(char *name, int score) -{ - int i; - - for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { - char *line; - char thisName[STR_NAME_SIZE]; - int thisCore; - - line = (char *) textFile->text->list[i]; - sscanf(line, "%s %d", thisName, &thisCore); - - if (score >= thisCore) { - char new[STR_SIZE]; - - sprintf(new, "%s %d", name, score); - insList(textFile->text, i, strdup(new)); - delListItem(textFile->text, SCREEN_TABLE_MAX_PLAYERS, free); - setWidgetLabel(); - - return 0; - } - } - - return -1; -} - -void initScreenTable() -{ - image_t *image; - - image = addImageData("screen_table.png", IMAGE_NO_ALPHA, "screen_table", IMAGE_GROUP_BASE); - image_backgorund = newWidgetImage(0, 0, image); - - button_back = newWidgetButton(_("back"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, - WINDOW_SIZE_Y - 100, eventWidget); - - loadHighscoreFile(); - listWidgetLabelNumer = NULL; - listWidgetLabelName = NULL; - listWidgetLabelScore = NULL; - setWidgetLabel(); - - registerScreen(newScreen("table", startScreenTable, eventScreenTable, drawScreenTable, stopScreenTable)); -} - -void quitScreenTable() -{ - destroyWidgetImage(image_backgorund); - - destroyWidgetButton(button_back); - destroyListItem(listWidgetLabelNumer, destroyWidgetLabel); - destroyListItem(listWidgetLabelName, destroyWidgetLabel); - destroyListItem(listWidgetLabelScore, destroyWidgetLabel); - - if (textFile != NULL) { - saveTextFile(textFile); - destroyTextFile(textFile); - } -} diff --git a/src/screen/screen_table.h b/src/screen/screen_table.h deleted file mode 100644 index a91b233..0000000 --- a/src/screen/screen_table.h +++ /dev/null @@ -1,17 +0,0 @@ - -#ifndef SCREEN_TABLE_H - -# define SCREEN_TABLE_H - -# define SCREEN_TABLE_MAX_PLAYERS 10 -# define SCREEN_TABLE_FILE_HIGHSCORE_NAME "highscore" - -extern void startScreenTable(); -extern void drawScreenTable(); -extern void eventScreenTable(); -extern void stopScreenTable(); -extern int addPlayerInHighScore(char *name, int score); -extern void initScreenTable(); -extern void quitScreenTable(); - -#endif diff --git a/src/screen/screen_world.c b/src/screen/screen_world.c deleted file mode 100644 index 8f2f6d2..0000000 --- a/src/screen/screen_world.c +++ /dev/null @@ -1,609 +0,0 @@ - -#include -#include - -#include "main.h" -#include "list.h" -#include "tux.h" -#include "item.h" -#include "shot.h" -#include "gun.h" -#include "myTimer.h" -#include "net_multiplayer.h" -#include "arena.h" -#include "arenaFile.h" -#include "proto.h" -#include "modules.h" -#include "idManager.h" -#include "serverSendMsg.h" - -#include "interface.h" -#include "layer.h" -#include "image.h" -#include "font.h" - -#include "hotKey.h" -#include "panel.h" -#include "radar.h" -#include "chat.h" -#include "pauza.h" -#include "term.h" -#include "saveDialog.h" -#include "saveLoad.h" - -#ifndef NO_SOUND -# include "music.h" -# include "sound.h" -#endif - -#include "screen.h" -#include "screen_world.h" -#include "screen_analyze.h" -#include "screen_setting.h" -#include "screen_gameType.h" -#include "screen_settingKeys.h" -#include "screen_choiceArena.h" -#include "screen_table.h" - - -static arena_t *arena; -static bool_t isScreenWorldInit = FALSE; -static bool_t isEndWorld; - -static tux_t *tuxWithControlRightKeyboard; -static tux_t *tuxWithControlLeftKeyboard; - -bool_t isScreenWorldInicialized() -{ - return isScreenWorldInit; -} - -void setGameType() -{ - int ret = 0; - - ret = initNetMuliplayer(getSettingGameType(), getSettingIP(), - getSettingPort(), getSettingProto()); - - if (ret != 0) { - fprintf(stderr, _("Network initialization error!\n")); - setWorldEnd(); - } -} - -void setWorldArena(arenaFile_t * arenaFile) -{ - arena = getArena(arenaFile); - -#ifndef NO_SOUND - playMusic(arena->music, MUSIC_GROUP_USER); -#endif -} - -void setWorldEnd() -{ - isEndWorld = TRUE; -} - -static void timer_endArena() -{ - if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { - setWorldEnd(); - return; - } -} - -void countRoundInc() -{ - if (arena->max_countRound == WORLD_COUNT_ROUND_UNLIMITED || - arena->countRound >= arena->max_countRound) { - return; - } - - arena->countRound++; - //printf("count %d/%d\n", count, max_count); - - if (arena->countRound >= arena->max_countRound) { - //printf("count %d ending\n", count); -#ifndef NO_SOUND - playSound("end", SOUND_GROUP_BASE); -#endif - addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_endArena, NULL, TIMER_END_ARENA); - } -} - -void prepareArena() -{ - tux_t *tux; - char name[STR_NAME_SIZE]; - - //printf("getSettingAI = %s\n", getSettingAI()); - setCurrentArena(NULL); - tuxWithControlRightKeyboard = NULL; - tuxWithControlLeftKeyboard = NULL; - - if (getGemeTypeLoadSession() != NULL) { - loadArena(getGemeTypeLoadSession()); - return; - } - - switch (getNetTypeGame()) { - case NET_GAME_TYPE_NONE: - setWorldArena(getChoiceArena()); - addNewItem(arena->spaceItem, ID_UNKNOWN); - getSettingCountRound(&arena->max_countRound); - - tux = newTux(); - tux->control = TUX_CONTROL_KEYBOARD_RIGHT; - tuxWithControlRightKeyboard = tux; - getSettingNameRight(name); - tuxSetName(tux, name); - addObjectToSpace(arena->spaceTux, tux); - - tux = newTux(); - tux->control = TUX_CONTROL_KEYBOARD_LEFT; - tuxWithControlLeftKeyboard = tux; - getSettingNameLeft(name); - tuxSetName(tux, name); - addObjectToSpace(arena->spaceTux, tux); - - if (isSettingAI()) { - tux->control = TUX_CONTROL_AI; - - if (loadModule("libmodAI") != 0) { - tux->control = TUX_CONTROL_KEYBOARD_LEFT; - } - } - //printf("getGemeTypeLoadSession = %s\n", getGemeTypeLoadSession()); - - break; - - case NET_GAME_TYPE_SERVER: - setWorldArena(getChoiceArena()); - addNewItem(arena->spaceItem, ID_UNKNOWN); - getSettingCountRound(&arena->max_countRound); - - tux = newTux(); - tux->control = TUX_CONTROL_KEYBOARD_RIGHT; - tuxWithControlRightKeyboard = tux; - getSettingNameRight(name); - tuxSetName(tux, name); - addObjectToSpace(arena->spaceTux, tux); - break; - - case NET_GAME_TYPE_CLIENT: - break; - } -} - -void drawWorld() -{ - if (arena != NULL) { - drawArena(arena); - drawPanel(tuxWithControlRightKeyboard, tuxWithControlLeftKeyboard); - - if (arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y) { - drawRadar(arena); - } - } - - drawChat(); - drawPauza(); - drawTerm(); - drawSaveDialog(); -} - -static void netAction(tux_t * tux, int action) -{ - if (getSettingGameType() == NET_GAME_TYPE_SERVER) { - proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, NULL, tux, action); - } - - if (getSettingGameType() == NET_GAME_TYPE_CLIENT) { - proto_send_event_client(action); - } -} - -static void control_keyboard_right(tux_t * tux) -{ - static int lastKey = 0; - int countKey; - Uint8 *mapa; - mapa = SDL_GetKeyState(NULL); - - assert(tux != NULL); - assert(mapa != NULL); - - countKey = 0; - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_SWITCH_WEAPON)] == SDL_PRESSED - && tux->isCanSwitchGun == TRUE) { - netAction(tux, TUX_SWITCH_GUN); - actionTux(tux, TUX_SWITCH_GUN); - return; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_SHOOT)] == SDL_PRESSED - && tux->isCanShot == TRUE) { - netAction(tux, TUX_SHOT); - actionTux(tux, TUX_SHOT); - return; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_UP)) - goto tuUp; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_RIGHT_MOVE_UP); - netAction(tux, TUX_UP); - actionTux(tux, TUX_UP); - return; - - tuUp:; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_RIGHT)) - goto tuRight; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_RIGHT_MOVE_RIGHT); - netAction(tux, TUX_RIGHT); - actionTux(tux, TUX_RIGHT); - return; - - tuRight:; - - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_LEFT)) - goto tuLeft; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_RIGHT_MOVE_LEFT); - netAction(tux, TUX_LEFT); - actionTux(tux, TUX_LEFT); - return; - - tuLeft:; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_DOWN)) - goto tuDown; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_RIGHT_MOVE_DOWN); - netAction(tux, TUX_DOWN); - actionTux(tux, TUX_DOWN); - return; - - tuDown:; - } -} - -static void control_keyboard_left(tux_t * tux) -{ - static int lastKey = 0; - int countKey; - Uint8 *mapa; - mapa = SDL_GetKeyState(NULL); - - assert(tux != NULL); - assert(mapa != NULL); - - countKey = 0; - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED) - countKey++; - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_SWITCH_WEAPON)] == SDL_PRESSED) { - if (tux->isCanSwitchGun == TRUE) { - actionTux(tux, TUX_SWITCH_GUN); - return; - } - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_SHOOT)] == SDL_PRESSED - && tux->isCanShot == TRUE) { - actionTux(tux, TUX_SHOT); - return; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_UP)) - goto tuUp; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_LEFT_MOVE_UP); - actionTux(tux, TUX_UP); - return; - - tuUp:; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_RIGHT)) - goto tuRight; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_LEFT_MOVE_RIGHT); - actionTux(tux, TUX_RIGHT); - return; - - tuRight:; - - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_LEFT)) - goto tuLeft; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_LEFT_MOVE_LEFT); - actionTux(tux, TUX_LEFT); - return; - - tuLeft:; - } - - if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED) { - if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_DOWN)) - goto tuDown; - - if (countKey == 1) - lastKey = getKey(KEY_TUX_LEFT_MOVE_DOWN); - actionTux(tux, TUX_DOWN); - return; - - tuDown:; - } -} - -static void eventEnd() -{ - if (isEndWorld == TRUE) { - setScreen("analyze"); - return; - } -} - -tux_t *getControlTux(int control_type) -{ - switch (control_type) { - case TUX_CONTROL_KEYBOARD_RIGHT: - return tuxWithControlRightKeyboard; - break; - case TUX_CONTROL_KEYBOARD_LEFT: - return tuxWithControlLeftKeyboard; - break; - } - - return NULL; -} - -void setControlTux(tux_t * tux, int control_type) -{ - switch (control_type) { - case TUX_CONTROL_KEYBOARD_RIGHT: - tuxWithControlRightKeyboard = tux; - break; - case TUX_CONTROL_KEYBOARD_LEFT: - tuxWithControlLeftKeyboard = tux; - break; - } -} - -void tuxControl(tux_t * p) -{ - assert(p != NULL); - - if (p->status != TUX_STATUS_ALIVE) { - return; - } - - switch (p->control) { - case TUX_CONTROL_NONE: - assert(!_("Tux has not defined controls!")); - break; - - case TUX_CONTROL_KEYBOARD_LEFT: - if (isChatActive() == FALSE) { - control_keyboard_left(p); - } - break; - - case TUX_CONTROL_KEYBOARD_RIGHT: - if (isChatActive() == FALSE) { - control_keyboard_right(p); - } - break; - } -} - -void eventWorld() -{ - tux_t *thisTux; - - if (arena == NULL) { - eventNetMultiplayer(); - eventEnd(); - return; - } - - eventNetMultiplayer(); - - if (isPauzeActive() == FALSE && isSaveDialogActive() == FALSE) { - eventArena(arena); - //eventModule(); - } - - thisTux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - - addToRadar(thisTux->id, thisTux->x, thisTux->y, RADAR_TYPE_YOU); - - thisTux = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); - - if (thisTux != NULL) { - addToRadar(thisTux->id, thisTux->x, thisTux->y, RADAR_TYPE_TUX); - } - - eventEnd(); - eventChat(); - eventPauza(); - eventTerm(); - eventSaveDialog(); - -} - -static void hotkey_escape() -{ - setWorldEnd(); -} - -void startWorld() -{ - arena = NULL; - isEndWorld = FALSE; - - registerHotKey(SDLK_ESCAPE, hotkey_escape); - initArena(); - initListID(); - initRadar(); - initPauza(); - initTerm(); - initSaveDialog(); - - initModule(); - setGameType(); - initChat(); - prepareArena(); -} - -static void action_analyze(space_t * space, tux_t * tux, void *p) -{ - addAnalyze(tux->name, tux->score); -} - -static void setAnalyze() -{ - restartAnalyze(); - - actionSpace(arena->spaceTux, action_analyze, NULL); - - endAnalyze(); -} - -static void setTable() -{ - tux_t *tuxRight; - tux_t *tuxLeft; - - if (getSettingGameType() != NET_GAME_TYPE_NONE) { - return; - } - - tuxRight = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); - tuxLeft = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); - - if (tuxRight->score > tuxLeft->score) { - addPlayerInHighScore(tuxRight->name, tuxRight->score); - } - - if (tuxLeft->score > tuxRight->score) { - addPlayerInHighScore(tuxLeft->name, tuxLeft->score); - } -} - -void stoptWorld() -{ - if (arena != NULL) { - setTable(); - setAnalyze(); - } - - unregisterHotKey(SDLK_ESCAPE); - quitArena(); - - quitNetMultiplayer(); - - if (arena != NULL) { - destroyArena(arena); - } - - quitRadar(); - quitPauza(); - quitTerm(); - quitSaveDialog(); - - -#ifndef NO_SOUND - stopMusic(); -#endif - delAllImageInGroup(IMAGE_GROUP_USER); - -#ifndef NO_SOUND - delAllMusicInGroup(MUSIC_GROUP_USER); -#endif - quitModule(); - quitChat(); - quitListID(); -} - -void initWorld() -{ - assert(isImageInicialized() == TRUE); - assert(isTuxInicialized() == TRUE); - assert(isShotInicialized() == TRUE); - assert(isPanelInicialized() == TRUE); - assert(isScreenInicialized() == TRUE); - - registerScreen(newScreen - ("world", startWorld, eventWorld, drawWorld, stoptWorld)); - -#ifndef NO_SOUND - addSound("dead.ogg", "dead", SOUND_GROUP_BASE); - addSound("explozion.ogg", "explozion", SOUND_GROUP_BASE); - addSound("gun_lasser.ogg", "gun_lasser", SOUND_GROUP_BASE); - addSound("gun_revolver.ogg", "gun_revolver", SOUND_GROUP_BASE); - addSound("gun_scatter.ogg", "gun_scatter", SOUND_GROUP_BASE); - addSound("gun_tommy.ogg", "gun_tommy", SOUND_GROUP_BASE); - addSound("put_mine.ogg", "put_mine", SOUND_GROUP_BASE); - addSound("teleport.ogg", "teleport", SOUND_GROUP_BASE); - addSound("item_bonus.ogg", "item_bonus", SOUND_GROUP_BASE); - addSound("item_gun.ogg", "item_gun", SOUND_GROUP_BASE); - addSound("switch_gun.ogg", "switch_gun", SOUND_GROUP_BASE); - addSound("end.ogg", "end", SOUND_GROUP_BASE); -#endif - - isScreenWorldInit = TRUE; -} - -void quitWorld() -{ - DEBUG_MSG(_("Quitting screen world\n")); - isScreenWorldInit = FALSE; -} diff --git a/src/screen/screen_world.h b/src/screen/screen_world.h deleted file mode 100644 index 67935f7..0000000 --- a/src/screen/screen_world.h +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef SCREEN_WORLD_H - -# define SCREEN_WORLD_H - -# include "main.h" -# include "myTimer.h" -# include "tux.h" -# include "arenaFile.h" -# include "arena.h" - -# define TIMER_END_ARENA 5000 -# define WORLD_COUNT_ROUND_UNLIMITED -1 -# define LAG_SERVER_UNKNOWN -1 - -extern bool_t isScreenWorldInicialized(); -extern void initWorld(); -extern void setWorldArena(arenaFile_t * arenaFile); -extern void setWorldEnd(); -extern void countRoundInc(); -extern tux_t *getControlTux(int control_type); -extern void setControlTux(tux_t * tux, int control_type); -extern void tuxControl(tux_t * p); -extern void drawWorld(); -extern void eventWorld(); -extern void startArena(); -extern void stopArena(); -extern void quitWorld(); - -#endif diff --git a/src/screen/setting.c b/src/screen/setting.c new file mode 100644 index 0000000..9fab21f --- /dev/null +++ b/src/screen/setting.c @@ -0,0 +1,538 @@ + +#include +#include +#include + +#include "main.h" +#include "list.h" +#include "tux.h" +#include "textFile.h" +#include "director.h" +#include "homeDirector.h" +#include "arenaFile.h" + +#include "configFile.h" +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +# include "sound.h" +#endif + +#include "mainMenu.h" +#include "setting.h" +#include "settingKeys.h" +#include "settingKeys.h" +#include "choiceArena.h" + +#include "widget.h" +#include "widget_label.h" +#include "widget_button.h" +#include "widget_image.h" +#include "widget_textfield.h" +#include "widget_check.h" +#include "widget_select.h" + +static widget_t *image_backgorund; + +static widget_t *button_back; +static widget_t *button_keys; // setting of keycontrols + +static widget_t *label_count_round; +static widget_t *label_name_player1; +static widget_t *label_name_player2; +static widget_t *label_ai; + +#ifndef NO_SOUND +static widget_t *label_music; +static widget_t *label_sound; +#endif + +static widget_t *check[ITEM_COUNT]; +#ifndef NO_SOUND +static widget_t *check_music; +static widget_t *check_sound; +#endif + +static widget_t *image_gun_dual_revolver; +static widget_t *image_gun_scatter; +static widget_t *image_gun_tommy; +static widget_t *image_gun_lasser; +static widget_t *image_gun_mine; +static widget_t *image_gun_bombball; + +static widget_t *image_bonus_speed; +static widget_t *image_bonus_shot; +static widget_t *image_bonus_teleport; +static widget_t *image_bonus_ghost; +static widget_t *image_bonus_4x; +static widget_t *image_bonus_hidden; + +static widget_t *textfield_count_cound; +static widget_t *textfield_name_player1; +static widget_t *textfield_name_player2; + +static widget_t *check_ai; + +static textFile_t *configFile; + +static void hotkey_escape() +{ + setScreen("mainMenu"); +} + +void startScreenSetting() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} + +void drawScreenSetting() +{ + int i; + + drawWidgetImage(image_backgorund); + + drawWidgetLabel(label_count_round); + drawWidgetLabel(label_name_player1); + drawWidgetLabel(label_ai); + +#ifndef NO_SOUND + drawWidgetLabel(label_music); + drawWidgetLabel(label_sound); +#endif + + drawWidgetTextfield(textfield_count_cound); + drawWidgetTextfield(textfield_name_player1); + + if (getWidgetCheckStatus(check_ai) == FALSE) { + drawWidgetLabel(label_name_player2); + drawWidgetTextfield(textfield_name_player2); + } + + drawWidgetImage(image_gun_dual_revolver); + drawWidgetImage(image_gun_scatter); + drawWidgetImage(image_gun_tommy); + drawWidgetImage(image_gun_lasser); + drawWidgetImage(image_gun_mine); + drawWidgetImage(image_gun_bombball); + + drawWidgetImage(image_bonus_speed); + drawWidgetImage(image_bonus_shot); + drawWidgetImage(image_bonus_teleport); + drawWidgetImage(image_bonus_ghost); + drawWidgetImage(image_bonus_4x); + drawWidgetImage(image_bonus_hidden); + +#ifndef NO_SOUND + drawWidgetCheck(check_music); + drawWidgetCheck(check_sound); +#endif + + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + drawWidgetCheck(check[i]); + } + + for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { + drawWidgetCheck(check[i]); + } + + drawWidgetCheck(check_ai); + + drawWidgetButton(button_back); + drawWidgetButton(button_keys); +} + +void eventScreenSetting() +{ + int i; + + eventWidgetTextfield(textfield_count_cound); + eventWidgetTextfield(textfield_name_player1); + + if (getWidgetCheckStatus(check_ai) == FALSE) { + eventWidgetTextfield(textfield_name_player2); + } + +#ifndef NO_SOUND + eventWidgetCheck(check_music); + eventWidgetCheck(check_sound); +#endif + + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + eventWidgetCheck(check[i]); + } + + for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { + eventWidgetCheck(check[i]); + } + + eventWidgetCheck(check_ai); + + eventWidgetButton(button_back); + eventWidgetButton(button_keys); +} + +void stopScreenSetting() +{ + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidget(void *p) +{ + widget_t *button; + widget_t *check; + + button = (widget_t *) (p); + check = (widget_t *) (p); + + if (button == button_back) { + setScreen("mainMenu"); + } + + if (button == button_keys) { + setScreen("settingKeys"); + } + +#ifndef NO_SOUND + if (check == check_music) { + setMusicActive(getWidgetCheckStatus(check_music)); + } + + if (check == check_sound) { + setSoundActive(getWidgetCheckStatus(check_sound)); + } +#endif +} + +static void initSettingFile() +{ + char path[STR_PATH_SIZE]; + char val[STR_SIZE]; + + sprintf(path, "%s/tuxanci.conf", getHomeDirector()); + + configFile = loadTextFile(path); + + if (configFile == NULL) { + fprintf(stderr, _("I am unable to load: \"%s\"!\n"), path); + fprintf(stderr, _("Creating: \"%s\"\n"), path); + + configFile = newTextFile(path); + } + + if (configFile == NULL) { + fprintf(stderr, _("I was unable to create: \"%s\"!\n"), path); + return; + } + + loadValueFromConfigFile(configFile, "COUNT_ROUND", val, STR_SIZE, "15"); + setWidgetTextFiledText(textfield_count_cound, val); + + loadValueFromConfigFile(configFile, "NAME_PLAYER_RIGHT", val, STR_SIZE, + NAME_PLAYER_RIGHT); + setWidgetTextFiledText(textfield_name_player1, val); + + loadValueFromConfigFile(configFile, "NAME_PLAYER_LEFT", val, STR_SIZE, + NAME_PLAYER_LEFT); + setWidgetTextFiledText(textfield_name_player2, val); + + loadValueFromConfigFile(configFile, "GUN_DUAL_SIMPLE", val, STR_SIZE, + "YES"); + setWidgetCheckStatus(check[GUN_DUAL_SIMPLE], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_SCATTER", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_SCATTER], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_TOMMY", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_TOMMY], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_LASSER", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_LASSER], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_MINE", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_MINE], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "GUN_BOMBBALL", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[GUN_BOMBBALL], isYesOrNO(val)); + + loadValueFromConfigFile(configFile, "BONUS_SPEED", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_SPEED], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_SHOT", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_SHOT], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_TELEPORT", val, STR_SIZE, + "YES"); + setWidgetCheckStatus(check[BONUS_TELEPORT], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_GHOST", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_GHOST], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_4X", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_4X], isYesOrNO(val)); + loadValueFromConfigFile(configFile, "BONUS_HIDDEN", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check[BONUS_HIDDEN], isYesOrNO(val)); + + loadValueFromConfigFile(configFile, "AI", val, STR_SIZE, "NO"); + setWidgetCheckStatus(check_ai, isYesOrNO(val)); + +#ifndef NO_SOUND + loadValueFromConfigFile(configFile, "MUSIC", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check_music, isYesOrNO(val)); + + loadValueFromConfigFile(configFile, "SOUND", val, STR_SIZE, "YES"); + setWidgetCheckStatus(check_sound, isYesOrNO(val)); +#endif + + loadValueFromConfigFile(configFile, "ARENA", val, STR_SIZE, "FAGN"); + setChoiceArena(getArenaFileFormNetName(val)); + + saveTextFile(configFile); +} + +static void saveAndDestroyConfigFile() +{ + if (configFile == NULL) { + fprintf(stderr, _("I am unable to save configure file, because config file was not initialised!\n")); + return; + } + + setValueInConfigFile(configFile, "COUNT_ROUND", getTextFromWidgetTextfield(textfield_count_cound)); + setValueInConfigFile(configFile, "NAME_PLAYER_RIGHT", getTextFromWidgetTextfield(textfield_name_player1)); + setValueInConfigFile(configFile, "NAME_PLAYER_LEFT", getTextFromWidgetTextfield(textfield_name_player2)); + setValueInConfigFile(configFile, "GUN_DUAL_SIMPLE", getYesOrNo(getWidgetCheckStatus(check[GUN_DUAL_SIMPLE]))); + setValueInConfigFile(configFile, "GUN_SCATTER", getYesOrNo(getWidgetCheckStatus(check[GUN_SCATTER]))); + setValueInConfigFile(configFile, "GUN_TOMMY", getYesOrNo(getWidgetCheckStatus(check[GUN_TOMMY]))); + setValueInConfigFile(configFile, "GUN_LASSER", getYesOrNo(getWidgetCheckStatus(check[GUN_LASSER]))); + setValueInConfigFile(configFile, "GUN_MINE", getYesOrNo(getWidgetCheckStatus(check[GUN_MINE]))); + setValueInConfigFile(configFile, "GUN_BOMBBALL", getYesOrNo(getWidgetCheckStatus(check[GUN_BOMBBALL]))); + setValueInConfigFile(configFile, "BONUS_SPEED", getYesOrNo(getWidgetCheckStatus(check[BONUS_SPEED]))); + setValueInConfigFile(configFile, "BONUS_SHOT", getYesOrNo(getWidgetCheckStatus(check[BONUS_SHOT]))); + setValueInConfigFile(configFile, "BONUS_TELEPORT", getYesOrNo(getWidgetCheckStatus (check[BONUS_TELEPORT]))); + setValueInConfigFile(configFile, "BONUS_GHOST", getYesOrNo(getWidgetCheckStatus(check[BONUS_GHOST]))); + setValueInConfigFile(configFile, "BONUS_4X", getYesOrNo(getWidgetCheckStatus(check[BONUS_4X]))); + setValueInConfigFile(configFile, "BONUS_HIDDEN", getYesOrNo(getWidgetCheckStatus(check[BONUS_HIDDEN]))); + setValueInConfigFile(configFile, "AI", getYesOrNo(getWidgetCheckStatus(check_ai))); + +#ifndef NO_SOUND + setValueInConfigFile(configFile, "MUSIC", getYesOrNo(getWidgetCheckStatus(check_music))); + setValueInConfigFile(configFile, "SOUND", getYesOrNo(getWidgetCheckStatus(check_sound))); +#endif + + if( getChoiceArena() != NULL ) + { + setValueInConfigFile(configFile, "ARENA", getArenaNetName(getChoiceArena())); + } + //TODO + + saveTextFile(configFile); + destroyTextFile(configFile); +} + +void initScreenSetting() +{ + image_t *image; + int i; + + image = getImage(IMAGE_GROUP_BASE, "screen_main"); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = newWidgetButton(_("back"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, eventWidget); + + button_keys = newWidgetButton(_("controls"), WINDOW_SIZE_X - 200, + button_back->y - WIDGET_BUTTON_HEIGHT - 10, eventWidget); + +#ifndef NO_SOUND + label_music = newWidgetLabel(_("Music:"), 100, WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); + + check_music = newWidgetCheck(label_music->x + label_music->w + 10, + WINDOW_SIZE_Y - 80, isMusicActive(), eventWidget); + label_sound = newWidgetLabel(_("Sound:"), check_music->x + WIDGET_CHECK_WIDTH + 10, + WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); + + check_sound = newWidgetCheck(label_sound->x + label_sound->w + 10, + WINDOW_SIZE_Y - 80, isSoundActive(), eventWidget); + + label_ai = newWidgetLabel(_("AI:"), check_sound->x + WIDGET_CHECK_WIDTH + 10, + WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); +#else + label_ai = newWidgetLabel(_("AI:"), 100, WINDOW_SIZE_Y - 85, WIDGET_LABEL_LEFT); +#endif + + check_ai = newWidgetCheck(label_ai->x + label_ai->w + 10, WINDOW_SIZE_Y - 80, FALSE, eventWidget); + + label_count_round = newWidgetLabel(_("No. of rounds:"), 100, WINDOW_SIZE_Y - 200, WIDGET_LABEL_LEFT); + label_name_player1 = newWidgetLabel(_("Player 1:"), 100, WINDOW_SIZE_Y - 160, WIDGET_LABEL_LEFT); + label_name_player2 = newWidgetLabel(_("Player 2:"), 100, WINDOW_SIZE_Y - 120, WIDGET_LABEL_LEFT); + + textfield_count_cound = newWidgetTextfield(getParamElse("--count", "15"), + WIDGET_TEXTFIELD_FILTER_NUM, + 110 + label_count_round->w, + WINDOW_SIZE_Y - 200); + + textfield_name_player1 = newWidgetTextfield(getParamElse("--name1", NAME_PLAYER_RIGHT), + WIDGET_TEXTFIELD_FILTER_ALPHANUM, + 110 + label_count_round->w, WINDOW_SIZE_Y - 160); + + textfield_name_player2 = newWidgetTextfield(getParamElse("--name2", NAME_PLAYER_LEFT), + WIDGET_TEXTFIELD_FILTER_ALPHANUM, + 110 + label_count_round->w, WINDOW_SIZE_Y - 120); + + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + int x = 0; + int y = 0; + + if (i >= GUN_DUAL_SIMPLE && i <= GUN_TOMMY) { + x = 100; + y = 200 + (i - GUN_DUAL_SIMPLE) * 50; + } + + if (i >= GUN_LASSER && i <= GUN_BOMBBALL) { + x = 250; + y = 200 + (i - GUN_LASSER) * 50; + } + + check[i] = newWidgetCheck(x, y, TRUE, NULL); + } + + for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { + int x = 0; + int y = 0; + + if (i >= BONUS_SPEED && i <= BONUS_TELEPORT) { + x = 430; + y = 200 + (i - BONUS_SPEED) * 50; + } + + if (i >= BONUS_GHOST && i <= BONUS_HIDDEN) { + x = 580; + y = 200 + (i - BONUS_GHOST) * 50; + } + + check[i] = newWidgetCheck(x, y, TRUE, NULL); + } + + image_gun_dual_revolver = newWidgetImage(110 + WIDGET_CHECK_WIDTH, 200, getImage(IMAGE_GROUP_BASE, "panel_dual")); + image_gun_scatter = newWidgetImage(110 + WIDGET_CHECK_WIDTH, 250, getImage(IMAGE_GROUP_BASE, "panel_scatter")); + image_gun_tommy = newWidgetImage(110 + WIDGET_CHECK_WIDTH, 300, getImage(IMAGE_GROUP_BASE, "panel_tommy")); + image_gun_lasser = newWidgetImage(260 + WIDGET_CHECK_WIDTH, 200,getImage(IMAGE_GROUP_BASE, "panel_lasser")); + image_gun_mine = newWidgetImage(260 + WIDGET_CHECK_WIDTH, 250, getImage(IMAGE_GROUP_BASE, "panel_mine")); + image_gun_bombball = newWidgetImage(260 + WIDGET_CHECK_WIDTH, 300, getImage(IMAGE_GROUP_BASE, "panel_bombball")); + image_bonus_speed = newWidgetImage(430 + WIDGET_CHECK_WIDTH, 200, getImage(IMAGE_GROUP_BASE, "panel_speed"));; + image_bonus_shot = newWidgetImage(430 + WIDGET_CHECK_WIDTH, 250, getImage(IMAGE_GROUP_BASE, "panel_shot"));; + image_bonus_teleport = newWidgetImage(430 + WIDGET_CHECK_WIDTH, 300, getImage(IMAGE_GROUP_BASE, "panel_teleport"));; + image_bonus_ghost = newWidgetImage(580 + WIDGET_CHECK_WIDTH, 200, getImage(IMAGE_GROUP_BASE, "panel_ghost"));; + image_bonus_4x = newWidgetImage(580 + WIDGET_CHECK_WIDTH, 250, getImage(IMAGE_GROUP_BASE, "panel_4x"));; + image_bonus_hidden = newWidgetImage(580 + WIDGET_CHECK_WIDTH, 300, getImage(IMAGE_GROUP_BASE, "panel_hidden"));; + + registerScreen( newScreen("setting", startScreenSetting, eventScreenSetting, + drawScreenSetting, stopScreenSetting)); + + initSettingFile(); + +#ifndef NO_SOUND + eventWidget(check_music); + eventWidget(check_sound); +#endif +} + +void getSettingNameRight(char *s) +{ + strcpy(s, getTextFromWidgetTextfield(textfield_name_player1)); +} + +void getSettingNameLeft(char *s) +{ + if (getWidgetCheckStatus(check_ai)) { + strcpy(s, NAME_AI); + } else { + strcpy(s, getTextFromWidgetTextfield(textfield_name_player2)); + } +} + +void getSettingCountRound(int *n) +{ + *n = atoi(getTextFromWidgetTextfield(textfield_count_cound)); +} + +bool_t isSettingAI() +{ + return getWidgetCheckStatus(check_ai); +} + +bool_t isSettingAnyItem() +{ + int i; + + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + if (getWidgetCheckStatus(check[i]) == TRUE) { + return TRUE; + } + } + + for (i = BONUS_SPEED; i < BONUS_HIDDEN; i++) { + if (getWidgetCheckStatus(check[i]) == TRUE) { + return TRUE; + } + } + + return FALSE; +} + +bool_t isSettingItem(int item) +{ + return getWidgetCheckStatus(check[item]); +} + +void quitScreenSetting() +{ + int i; + + saveAndDestroyConfigFile(); + + destroyWidgetImage(image_backgorund); + + destroyWidgetLabel(label_count_round); + destroyWidgetLabel(label_name_player1); + destroyWidgetLabel(label_ai); + +#ifndef NO_SOUND + destroyWidgetLabel(label_music); + destroyWidgetLabel(label_sound); +#endif + destroyWidgetLabel(label_name_player2); + destroyWidgetTextfield(textfield_name_player2); + + destroyWidgetTextfield(textfield_name_player1); + destroyWidgetTextfield(textfield_count_cound); + + destroyWidgetImage(image_gun_dual_revolver); + destroyWidgetImage(image_gun_scatter); + destroyWidgetImage(image_gun_tommy); + destroyWidgetImage(image_gun_lasser); + destroyWidgetImage(image_gun_mine); + destroyWidgetImage(image_gun_bombball); + + destroyWidgetImage(image_bonus_speed); + destroyWidgetImage(image_bonus_shot); + destroyWidgetImage(image_bonus_teleport); + destroyWidgetImage(image_bonus_ghost); + destroyWidgetImage(image_bonus_4x); + destroyWidgetImage(image_bonus_hidden); + +#ifndef NO_SOUND + destroyWidgetCheck(check_music); + destroyWidgetCheck(check_sound); +#endif + + destroyWidgetCheck(check_ai); + + for (i = GUN_DUAL_SIMPLE; i <= GUN_BOMBBALL; i++) { + destroyWidgetCheck(check[i]); + } + + for (i = BONUS_SPEED; i <= BONUS_HIDDEN; i++) { + destroyWidgetCheck(check[i]); + } + + destroyWidgetButton(button_back); + destroyWidgetButton(button_keys); +} diff --git a/src/screen/setting.h b/src/screen/setting.h new file mode 100644 index 0000000..9521cca --- /dev/null +++ b/src/screen/setting.h @@ -0,0 +1,22 @@ + +#ifndef SCREEN_SETTING + +# define SCREEN_SETTING + +# include "main.h" + +# define NAME_AI "TuxBot" +# define NAME_PLAYER_RIGHT "Name1" +# define NAME_PLAYER_LEFT "Name2" + +extern void initScreenSetting(); +extern void drawScreenSetting(); +extern void eventScreenSetting(); +extern void getSettingNameRight(char *s); +extern void getSettingNameLeft(char *s); +extern void getSettingCountRound(int *n); +extern bool_t isSettingAI(); +extern bool_t isSettingAnyItem(); +extern bool_t isSettingItem(int item); +extern void quitScreenSetting(); +#endif diff --git a/src/screen/settingKeys.c b/src/screen/settingKeys.c new file mode 100644 index 0000000..7813a69 --- /dev/null +++ b/src/screen/settingKeys.c @@ -0,0 +1,589 @@ + +#include +#include +#include + +#include "main.h" +#include "list.h" +#include "tux.h" +#include "textFile.h" +#include "director.h" +#include "homeDirector.h" + +#include "configFile.h" +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +# include "sound.h" +#endif /* + */ +#include "mainMenu.h" +#include "setting.h" +#include "settingKeys.h" + +#include "widget.h" +#include "widget_button.h" +#include "widget_image.h" +#include "widget_catchkey.h" +#include "widget_label.h" + +static int keytable[KEY_LENGTH]; + +static textFile_t *keycontrolFile; +static widget_t *image_backgorund; +static widget_t *button_back; + +// key names +static widget_t *tux_right; +static widget_t *tux_right_keyup; +static widget_t *tux_right_keydown; +static widget_t *tux_right_keyleft; +static widget_t *tux_right_keyright; +static widget_t *tux_right_keyswitch; +static widget_t *tux_right_keyfire; + +static widget_t *tux_left; +static widget_t *tux_left_keyup; +static widget_t *tux_left_keydown; + +static widget_t *tux_left_keyleft; +static widget_t *tux_left_keyright; +static widget_t *tux_left_keyswitch; +static widget_t *tux_left_keyfire; + +// key values +static widget_t *tux_right_keyup_val; +static widget_t *tux_right_keydown_val; +static widget_t *tux_right_keyleft_val; +static widget_t *tux_right_keyright_val; +static widget_t *tux_right_keyswitch_val; +static widget_t *tux_right_keyfire_val; +static widget_t *tux_left_keyup_val; +static widget_t *tux_left_keydown_val; +static widget_t *tux_left_keyleft_val; +static widget_t *tux_left_keyright_val; +static widget_t *tux_left_keyswitch_val; +static widget_t *tux_left_keyfire_val; + + +//static widget_t *catcher; +// todo add key images +// possible variant will be reusing widget_image for current widget_label so there wont +// be key names but only images + +static void hotkey_escape() +{ + setScreen("setting"); +} + +void startScreenSettingKeys() +{ + +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} +static void setKeytableFromConfigFile(textFile_t * configFile) +{ + +char val[STR_SIZE]; + + +loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_UP", val, STR_SIZE, + "273"); + +keytable[KEY_TUX_RIGHT_MOVE_UP] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", val, + STR_SIZE, "275"); + +keytable[KEY_TUX_RIGHT_MOVE_RIGHT] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", val, STR_SIZE, + "276"); + +keytable[KEY_TUX_RIGHT_MOVE_LEFT] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", val, STR_SIZE, + "274"); + +keytable[KEY_TUX_RIGHT_MOVE_DOWN] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_RIGHT_SHOOT", val, STR_SIZE, + "48"); + +keytable[KEY_TUX_RIGHT_SHOOT] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", val, + STR_SIZE, "49"); + +keytable[KEY_TUX_RIGHT_SWITCH_WEAPON] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_UP", val, STR_SIZE, + "119"); + +keytable[KEY_TUX_LEFT_MOVE_UP] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", val, STR_SIZE, + "100"); + +keytable[KEY_TUX_LEFT_MOVE_RIGHT] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", val, STR_SIZE, + "97"); + +keytable[KEY_TUX_LEFT_MOVE_LEFT] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", val, STR_SIZE, + "115"); + +keytable[KEY_TUX_LEFT_MOVE_DOWN] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_LEFT_SHOOT", val, STR_SIZE, + "113"); + +keytable[KEY_TUX_LEFT_SHOOT] = atoi(val); + +loadValueFromConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", val, + STR_SIZE, "9"); + +keytable[KEY_TUX_LEFT_SWITCH_WEAPON] = atoi(val); + +} +void + + initKeyTable() +{ + +char path[STR_PATH_SIZE]; + +/* + int i; +*/ + sprintf(path, "%s/keycontrol.conf", getHomeDirector()); + +keycontrolFile = loadTextFile(path); + +if (keycontrolFile == NULL) { + +fprintf(stderr, _("I was unable to load file: %s\n"), path); + +fprintf(stderr, _("I try to create file: %s\n"), path); + +keycontrolFile = newTextFile(path); + +} + +if (keycontrolFile == NULL) { + +fprintf(stderr, _("I was unable to create file: %s\n"), path); + +return; + +} + +setKeytableFromConfigFile(keycontrolFile); + +/* + for( i = 0 ; i < KEY_LENGTH ; i++) + { + printf("keytable[%d] = %d\n", i, keytable[i]); + } +*/ +} + +int getKey(int n) +{ + +// printf("keytable[n] = %d\n", keytable[n]); + return keytable[n]; + +} + +void drawScreenSettingKeys() +{ + +drawWidgetImage(image_backgorund); + +drawWidgetButton(button_back); + + // key names + drawWidgetLabel(tux_right); + +drawWidgetLabel(tux_left); + +drawWidgetLabel(tux_right_keyup); + +drawWidgetLabel(tux_right_keydown); + +drawWidgetLabel(tux_right_keyleft); + +drawWidgetLabel(tux_right_keyright); + +drawWidgetLabel(tux_right_keyswitch); + +drawWidgetLabel(tux_right_keyfire); + +drawWidgetLabel(tux_left_keyup); + +drawWidgetLabel(tux_left_keydown); + +drawWidgetLabel(tux_left_keyleft); + +drawWidgetLabel(tux_left_keyright); + +drawWidgetLabel(tux_left_keyswitch); + +drawWidgetLabel(tux_left_keyfire); + + // key values + drawWidgetCatchkey(tux_right_keyup_val); + +drawWidgetCatchkey(tux_right_keydown_val); + +drawWidgetCatchkey(tux_right_keyleft_val); + +drawWidgetCatchkey(tux_right_keyright_val); + +drawWidgetCatchkey(tux_right_keyswitch_val); + +drawWidgetCatchkey(tux_right_keyfire_val); + +drawWidgetCatchkey(tux_left_keyup_val); + +drawWidgetCatchkey(tux_left_keydown_val); + +drawWidgetCatchkey(tux_left_keyleft_val); + +drawWidgetCatchkey(tux_left_keyright_val); + +drawWidgetCatchkey(tux_left_keyswitch_val); + +drawWidgetCatchkey(tux_left_keyfire_val); + +} +static void + + refreshKeytable() +{ + +keytable[6] = getWidgetCatchKey(tux_left_keyup_val); + +keytable[9] = getWidgetCatchKey(tux_left_keydown_val); + +keytable[8] = getWidgetCatchKey(tux_left_keyleft_val); + +keytable[7] = getWidgetCatchKey(tux_left_keyright_val); + +keytable[10] = getWidgetCatchKey(tux_left_keyfire_val); + +keytable[11] = getWidgetCatchKey(tux_left_keyswitch_val); + +keytable[0] = getWidgetCatchKey(tux_right_keyup_val); + +keytable[3] = getWidgetCatchKey(tux_right_keydown_val); + +keytable[2] = getWidgetCatchKey(tux_right_keyleft_val); + +keytable[1] = getWidgetCatchKey(tux_right_keyright_val); + +keytable[4] = getWidgetCatchKey(tux_right_keyfire_val); + +keytable[5] = getWidgetCatchKey(tux_right_keyswitch_val); + +} +static void eventWidget(void *p) +{ + +widget_t * button; + +widget_t * catcher; + + +button = (widget_t *) (p); + +catcher = (widget_t *) (p); + +if (button == button_back) + +setScreen("setting"); + + //events on value + if ((catcher == tux_left_keyup_val) || + (catcher == tux_left_keydown_val) || + (catcher == tux_left_keyleft_val) || + (catcher == tux_left_keyright_val) || + (catcher == tux_left_keyfire_val) || + (catcher == tux_left_keyswitch_val) || + (catcher == tux_right_keyup_val) || + (catcher == tux_right_keydown_val) || + (catcher == tux_right_keyleft_val) || + (catcher == tux_right_keyright_val) || + (catcher == tux_right_keyswitch_val) || + (catcher == tux_right_keyfire_val)) { + + // draw press any key picture + //this will be done by widget catchkey + // check if there is no other key with new value (what to revert if yes?) + refreshKeytable(); + +} + +} + +void eventScreenSettingKeys() +{ + +eventWidgetButton(button_back); + +eventWidgetCatchkey(tux_right_keyup_val); + +eventWidgetCatchkey(tux_right_keydown_val); + +eventWidgetCatchkey(tux_right_keyleft_val); + +eventWidgetCatchkey(tux_right_keyright_val); + +eventWidgetCatchkey(tux_right_keyswitch_val); + +eventWidgetCatchkey(tux_right_keyfire_val); + +eventWidgetCatchkey(tux_left_keyup_val); + +eventWidgetCatchkey(tux_left_keydown_val); + +eventWidgetCatchkey(tux_left_keyleft_val); + +eventWidgetCatchkey(tux_left_keyright_val); + +eventWidgetCatchkey(tux_left_keyswitch_val); + +eventWidgetCatchkey(tux_left_keyfire_val); + +} +void + + stopScreenSettingKeys() +{ + unregisterHotKey(SDLK_ESCAPE); +} +void + + initScreenSettingKeys() +{ + +image_t * image; + + +initKeyTable(); + +image = getImage(IMAGE_GROUP_BASE, "screen_main"); + +image_backgorund = newWidgetImage(0, 0, image); + +button_back = + newWidgetButton(_("Back"), WINDOW_SIZE_X - 200, WINDOW_SIZE_Y - 100, + eventWidget); + +tux_left = + newWidgetLabel(_("Player 2"), WINDOW_SIZE_X / 4, 150, + WIDGET_LABEL_CENTER); + +tux_left_keyup = + newWidgetLabel(_("Up"), 50, tux_left->y + 50, WIDGET_LABEL_LEFT); + +tux_left_keydown = + newWidgetLabel(_("Down:"), tux_left_keyup->x, tux_left_keyup->y + 20, + WIDGET_LABEL_LEFT); + +tux_left_keyleft = + newWidgetLabel(_("Left:"), tux_left_keyup->x, + tux_left_keydown->y + 20, WIDGET_LABEL_LEFT); + +tux_left_keyright = + newWidgetLabel(_("Right:"), tux_left_keyup->x, + tux_left_keyleft->y + 20, WIDGET_LABEL_LEFT); + +tux_left_keyfire = + newWidgetLabel(_("Fire gun:"), tux_left_keyup->x, + tux_left_keyright->y + 20, WIDGET_LABEL_LEFT); + +tux_left_keyswitch = + newWidgetLabel(_("Switch gun:"), tux_left_keyup->x, + tux_left_keyfire->y + 20, WIDGET_LABEL_LEFT); + +tux_right = + newWidgetLabel(_("Player 1"), WINDOW_SIZE_X / 2 + WINDOW_SIZE_X / 4, + tux_left->y, WIDGET_LABEL_CENTER); + +tux_right_keyup = + newWidgetLabel(_("Up:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_left->y + 50, WIDGET_LABEL_LEFT); + +tux_right_keydown = + newWidgetLabel(_("Down:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_left_keyup->y + 20, WIDGET_LABEL_LEFT); + +tux_right_keyleft = + newWidgetLabel(_("Left:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_right_keydown->y + 20, WIDGET_LABEL_LEFT); + +tux_right_keyright = + newWidgetLabel(_("Right:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_right_keyleft->y + 20, WIDGET_LABEL_LEFT); + +tux_right_keyfire = + newWidgetLabel(_("Fire gun:"), WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_left_keyright->y + 20, WIDGET_LABEL_LEFT); + +tux_right_keyswitch = + newWidgetLabel(_("Switch gun:"), + WINDOW_SIZE_X / 2 + tux_left_keyup->x, + tux_left_keyfire->y + 20, WIDGET_LABEL_LEFT); + +tux_left_keyup_val = + newWidgetCatchkey(keytable[6], tux_left_keyup->x + 200, + tux_left->y + 50, eventWidget); + +tux_left_keydown_val = + newWidgetCatchkey(keytable[9], tux_left_keyup_val->x, + tux_left_keyup->y + 20, eventWidget); + +tux_left_keyleft_val = + newWidgetCatchkey(keytable[8], tux_left_keyup_val->x, + tux_left_keydown->y + 20, eventWidget); + +tux_left_keyright_val = + newWidgetCatchkey(keytable[7], tux_left_keyup_val->x, + tux_left_keyleft->y + 20, eventWidget); + +tux_left_keyfire_val = + newWidgetCatchkey(keytable[10], tux_left_keyup_val->x, + tux_left_keyright->y + 20, eventWidget); + +tux_left_keyswitch_val = + newWidgetCatchkey(keytable[11], tux_left_keyup_val->x, + tux_left_keyfire->y + 20, eventWidget); + +tux_right_keyup_val = + newWidgetCatchkey(keytable[0], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_left->y + 50, eventWidget); + +tux_right_keydown_val = + newWidgetCatchkey(keytable[3], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_left_keyup->y + 20, eventWidget); + +tux_right_keyleft_val = + newWidgetCatchkey(keytable[2], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_right_keydown->y + 20, eventWidget); + +tux_right_keyright_val = + newWidgetCatchkey(keytable[1], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_right_keyleft->y + 20, eventWidget); + +tux_right_keyfire_val = + newWidgetCatchkey(keytable[4], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_left_keyright->y + 20, eventWidget); + +tux_right_keyswitch_val = + newWidgetCatchkey(keytable[5], + WINDOW_SIZE_X / 2 + tux_left_keyup_val->x, + tux_left_keyfire->y + 20, eventWidget); + +registerScreen(newScreen + ("settingKeys", startScreenSettingKeys, + eventScreenSettingKeys, +drawScreenSettingKeys, + stopScreenSettingKeys)); + +} + +void quitKeyTable() +{ + destroyTextFile(keycontrolFile); +} + +void saveKeyTable(textFile_t * configFile) +{ + char str[STR_SIZE]; + + sprintf(str, "%d", getWidgetCatchKey(tux_left_keyup_val)); + setValueInConfigFile(configFile, "TUX_LEFT_MOVE_UP", str); + sprintf(str, "%d", getWidgetCatchKey(tux_left_keydown_val)); + setValueInConfigFile(configFile, "TUX_LEFT_MOVE_DOWN", str); + sprintf(str, "%d", getWidgetCatchKey(tux_left_keyleft_val)); + setValueInConfigFile(configFile, "TUX_LEFT_MOVE_LEFT", str); + sprintf(str, "%d", getWidgetCatchKey(tux_left_keyright_val)); + setValueInConfigFile(configFile, "TUX_LEFT_MOVE_RIGHT", str); + sprintf(str, "%d", getWidgetCatchKey(tux_left_keyfire_val)); + setValueInConfigFile(configFile, "TUX_LEFT_SHOOT", str); + sprintf(str, "%d", getWidgetCatchKey(tux_left_keyswitch_val)); + setValueInConfigFile(configFile, "TUX_LEFT_SWITCH_WEAPON", str); + + sprintf(str, "%d", getWidgetCatchKey(tux_right_keyup_val)); + setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_UP", str); + sprintf(str, "%d", getWidgetCatchKey(tux_right_keydown_val)); + setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_DOWN", str); + sprintf(str, "%d", getWidgetCatchKey(tux_right_keyleft_val)); + setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_LEFT", str); + sprintf(str, "%d", getWidgetCatchKey(tux_right_keyright_val)); + setValueInConfigFile(configFile, "TUX_RIGHT_MOVE_RIGHT", str); + sprintf(str, "%d", getWidgetCatchKey(tux_right_keyfire_val)); + setValueInConfigFile(configFile, "TUX_RIGHT_SHOOT", str); + sprintf(str, "%d", getWidgetCatchKey(tux_right_keyswitch_val)); + setValueInConfigFile(configFile, "TUX_RIGHT_SWITCH_WEAPON", str); + + saveTextFile(configFile); +} + +void quitScreenSettingKeys() +{ + saveKeyTable(keycontrolFile); + quitKeyTable(); + + // key names + destroyWidgetImage(image_backgorund); + + destroyWidgetLabel(tux_right); + destroyWidgetLabel(tux_left); + destroyWidgetLabel(tux_right_keyup); + destroyWidgetLabel(tux_right_keydown); + destroyWidgetLabel(tux_right_keyleft); + destroyWidgetLabel(tux_right_keyright); + destroyWidgetLabel(tux_right_keyswitch); + destroyWidgetLabel(tux_right_keyfire); + destroyWidgetLabel(tux_left_keyup); + destroyWidgetLabel(tux_left_keydown); + destroyWidgetLabel(tux_left_keyright); + destroyWidgetLabel(tux_left_keyleft); + destroyWidgetLabel(tux_left_keyswitch); + destroyWidgetLabel(tux_left_keyfire); + + // key values + destroyWidgetCatchkey(tux_right_keyup_val); + + destroyWidgetCatchkey(tux_right_keydown_val); + destroyWidgetCatchkey(tux_right_keyleft_val); + destroyWidgetCatchkey(tux_right_keyright_val); + destroyWidgetCatchkey(tux_right_keyswitch_val); + destroyWidgetCatchkey(tux_right_keyfire_val); + destroyWidgetCatchkey(tux_left_keyup_val); + destroyWidgetCatchkey(tux_left_keydown_val); + destroyWidgetCatchkey(tux_left_keyleft_val); + destroyWidgetCatchkey(tux_left_keyright_val); + destroyWidgetCatchkey(tux_left_keyswitch_val); + destroyWidgetCatchkey(tux_left_keyfire_val); + destroyWidgetButton(button_back); +} + diff --git a/src/screen/settingKeys.h b/src/screen/settingKeys.h new file mode 100644 index 0000000..c90006e --- /dev/null +++ b/src/screen/settingKeys.h @@ -0,0 +1,27 @@ + +#ifndef SCREEN_SETTING_KEYS +# define SCREEN_SETTING_KEYS +# define KEY_TUX_RIGHT_MOVE_UP 0 +# define KEY_TUX_RIGHT_MOVE_RIGHT 1 +# define KEY_TUX_RIGHT_MOVE_LEFT 2 +# define KEY_TUX_RIGHT_MOVE_DOWN 3 +# define KEY_TUX_RIGHT_SHOOT 4 +# define KEY_TUX_RIGHT_SWITCH_WEAPON 5 +# define KEY_TUX_LEFT_MOVE_UP 6 +# define KEY_TUX_LEFT_MOVE_RIGHT 7 +# define KEY_TUX_LEFT_MOVE_LEFT 8 +# define KEY_TUX_LEFT_MOVE_DOWN 9 +# define KEY_TUX_LEFT_SHOOT 10 +# define KEY_TUX_LEFT_SWITCH_WEAPON 11 +# define KEY_LENGTH 12 + +# include "main.h" + extern void initScreenSettingKeys(); + extern void drawScreenSettingKeys(); + extern void eventScreenSettingKeys(); + extern void quitScreenSettingKeys(); + extern void initKeyTable(); + extern int getKey(int n); + extern void quitKeyTable(); + +#endif /* */ diff --git a/src/screen/table.c b/src/screen/table.c new file mode 100644 index 0000000..5abb3c9 --- /dev/null +++ b/src/screen/table.c @@ -0,0 +1,229 @@ + +#include +#include +#include + +#include "main.h" +#include "list.h" +#include "textFile.h" +#include "homeDirector.h" + +#include "interface.h" +#include "screen.h" +#include "image.h" +#include "hotKey.h" + +#ifndef NO_SOUND +# include "music.h" +#endif + +#include "table.h" + +#include "widget_image.h" +#include "widget_label.h" +#include "widget_button.h" + +static widget_t *image_backgorund; +static widget_t *button_back; + +static list_t *listWidgetLabelNumer; +static list_t *listWidgetLabelName; +static list_t *listWidgetLabelScore; + +static textFile_t *textFile; + +static void hotkey_escape() +{ + setScreen("mainMenu"); +} + +void startScreenTable() +{ +#ifndef NO_SOUND + playMusic("menu", MUSIC_GROUP_BASE); +#endif + + registerHotKey(SDLK_ESCAPE, hotkey_escape); +} + +void drawScreenTable() +{ + int i; + + drawWidgetImage(image_backgorund); + + drawWidgetButton(button_back); + + for (i = 0; i < listWidgetLabelNumer->count; i++) { + widget_t *this; + this = (widget_t *) listWidgetLabelNumer->list[i]; + drawWidgetLabel(this); + } + + for (i = 0; i < listWidgetLabelName->count; i++) { + widget_t *this; + this = (widget_t *) listWidgetLabelName->list[i]; + drawWidgetLabel(this); + } + + for (i = 0; i < listWidgetLabelScore->count; i++) { + widget_t *this; + this = (widget_t *) listWidgetLabelScore->list[i]; + drawWidgetLabel(this); + } +} + +void eventScreenTable() +{ + eventWidgetButton(button_back); +} + +void stopScreenTable() +{ + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidget(void *p) +{ + widget_t *button; + + button = (widget_t *) (p); + + if (button == button_back) { + setScreen("mainMenu"); + } +} + +static void setWidgetLabel() +{ + int i; + + if (textFile == NULL) { + fprintf(stderr, _("Highscore file: \"%s\" was not loaded!"), SCREEN_TABLE_FILE_HIGHSCORE_NAME); + + return; + } + + if (listWidgetLabelNumer != NULL || + listWidgetLabelName != NULL || + listWidgetLabelScore != NULL) { + destroyListItem(listWidgetLabelNumer, destroyWidgetLabel); + destroyListItem(listWidgetLabelName, destroyWidgetLabel); + destroyListItem(listWidgetLabelScore, destroyWidgetLabel); + } + + listWidgetLabelNumer = newList(); + listWidgetLabelName = newList(); + listWidgetLabelScore = newList(); + + for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { + widget_t *label; + char name[STR_NAME_SIZE]; + char score[STR_NUM_SIZE]; + char num[STR_NUM_SIZE]; + char *line; + + line = (char *) textFile->text->list[i]; + + sscanf(line, "%s %s", name, score); + sprintf(num, "%2d)", i + 1); + + label = newWidgetLabel(num, WINDOW_SIZE_X / 2 - 100, 200 + i * 20, WIDGET_LABEL_LEFT); + addList(listWidgetLabelNumer, label); + + label = newWidgetLabel(name, WINDOW_SIZE_X / 2, 200 + i * 20, WIDGET_LABEL_CENTER); + addList(listWidgetLabelName, label); + + label = newWidgetLabel(score, WINDOW_SIZE_X / 2 + 80, 200 + i * 20, WIDGET_LABEL_LEFT); + addList(listWidgetLabelScore, label); + } +} + +static void loadHighscoreFile() +{ + char path[STR_PATH_SIZE]; + int i; + + sprintf(path, "%s/" SCREEN_TABLE_FILE_HIGHSCORE_NAME, getHomeDirector()); + textFile = loadTextFile(path); + + if (textFile == NULL) { + fprintf(stderr, _("I am unable to load: \"%s\"!\n"), path); + fprintf(stderr, _("Creating: \"%s\"\n"), path); + textFile = newTextFile(path); + } else { + return; + } + + if (textFile == NULL) { + fprintf(stderr, _("I was unable to create: \"%s\"!\n"), path); + return; + } + + for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { + addList(textFile->text, strdup("no_name 0")); + } + + saveTextFile(textFile); +} + +int addPlayerInHighScore(char *name, int score) +{ + int i; + + for (i = 0; i < SCREEN_TABLE_MAX_PLAYERS; i++) { + char *line; + char thisName[STR_NAME_SIZE]; + int thisCore; + + line = (char *) textFile->text->list[i]; + sscanf(line, "%s %d", thisName, &thisCore); + + if (score >= thisCore) { + char new[STR_SIZE]; + + sprintf(new, "%s %d", name, score); + insList(textFile->text, i, strdup(new)); + delListItem(textFile->text, SCREEN_TABLE_MAX_PLAYERS, free); + setWidgetLabel(); + + return 0; + } + } + + return -1; +} + +void initScreenTable() +{ + image_t *image; + + image = addImageData("screen_table.png", IMAGE_NO_ALPHA, "screen_table", IMAGE_GROUP_BASE); + image_backgorund = newWidgetImage(0, 0, image); + + button_back = newWidgetButton(_("back"), WINDOW_SIZE_X / 2 - WIDGET_BUTTON_WIDTH / 2, + WINDOW_SIZE_Y - 100, eventWidget); + + loadHighscoreFile(); + listWidgetLabelNumer = NULL; + listWidgetLabelName = NULL; + listWidgetLabelScore = NULL; + setWidgetLabel(); + + registerScreen(newScreen("table", startScreenTable, eventScreenTable, drawScreenTable, stopScreenTable)); +} + +void quitScreenTable() +{ + destroyWidgetImage(image_backgorund); + + destroyWidgetButton(button_back); + destroyListItem(listWidgetLabelNumer, destroyWidgetLabel); + destroyListItem(listWidgetLabelName, destroyWidgetLabel); + destroyListItem(listWidgetLabelScore, destroyWidgetLabel); + + if (textFile != NULL) { + saveTextFile(textFile); + destroyTextFile(textFile); + } +} diff --git a/src/screen/table.h b/src/screen/table.h new file mode 100644 index 0000000..a91b233 --- /dev/null +++ b/src/screen/table.h @@ -0,0 +1,17 @@ + +#ifndef SCREEN_TABLE_H + +# define SCREEN_TABLE_H + +# define SCREEN_TABLE_MAX_PLAYERS 10 +# define SCREEN_TABLE_FILE_HIGHSCORE_NAME "highscore" + +extern void startScreenTable(); +extern void drawScreenTable(); +extern void eventScreenTable(); +extern void stopScreenTable(); +extern int addPlayerInHighScore(char *name, int score); +extern void initScreenTable(); +extern void quitScreenTable(); + +#endif diff --git a/src/screen/world.c b/src/screen/world.c new file mode 100644 index 0000000..5fa3ecd --- /dev/null +++ b/src/screen/world.c @@ -0,0 +1,609 @@ + +#include +#include + +#include "main.h" +#include "list.h" +#include "tux.h" +#include "item.h" +#include "shot.h" +#include "gun.h" +#include "myTimer.h" +#include "net_multiplayer.h" +#include "arena.h" +#include "arenaFile.h" +#include "proto.h" +#include "modules.h" +#include "idManager.h" +#include "serverSendMsg.h" + +#include "interface.h" +#include "layer.h" +#include "image.h" +#include "font.h" + +#include "hotKey.h" +#include "panel.h" +#include "radar.h" +#include "chat.h" +#include "pauza.h" +#include "term.h" +#include "saveDialog.h" +#include "saveLoad.h" + +#ifndef NO_SOUND +# include "music.h" +# include "sound.h" +#endif + +#include "screen.h" +#include "world.h" +#include "analyze.h" +#include "setting.h" +#include "gameType.h" +#include "settingKeys.h" +#include "choiceArena.h" +#include "table.h" + + +static arena_t *arena; +static bool_t isScreenWorldInit = FALSE; +static bool_t isEndWorld; + +static tux_t *tuxWithControlRightKeyboard; +static tux_t *tuxWithControlLeftKeyboard; + +bool_t isScreenWorldInicialized() +{ + return isScreenWorldInit; +} + +void setGameType() +{ + int ret = 0; + + ret = initNetMuliplayer(getSettingGameType(), getSettingIP(), + getSettingPort(), getSettingProto()); + + if (ret != 0) { + fprintf(stderr, _("Network initialization error!\n")); + setWorldEnd(); + } +} + +void setWorldArena(arenaFile_t * arenaFile) +{ + arena = getArena(arenaFile); + +#ifndef NO_SOUND + playMusic(arena->music, MUSIC_GROUP_USER); +#endif +} + +void setWorldEnd() +{ + isEndWorld = TRUE; +} + +static void timer_endArena() +{ + if (getNetTypeGame() != NET_GAME_TYPE_CLIENT) { + setWorldEnd(); + return; + } +} + +void countRoundInc() +{ + if (arena->max_countRound == WORLD_COUNT_ROUND_UNLIMITED || + arena->countRound >= arena->max_countRound) { + return; + } + + arena->countRound++; + //printf("count %d/%d\n", count, max_count); + + if (arena->countRound >= arena->max_countRound) { + //printf("count %d ending\n", count); +#ifndef NO_SOUND + playSound("end", SOUND_GROUP_BASE); +#endif + addTaskToTimer(getCurrentArena()->listTimer, TIMER_ONE, timer_endArena, NULL, TIMER_END_ARENA); + } +} + +void prepareArena() +{ + tux_t *tux; + char name[STR_NAME_SIZE]; + + //printf("getSettingAI = %s\n", getSettingAI()); + setCurrentArena(NULL); + tuxWithControlRightKeyboard = NULL; + tuxWithControlLeftKeyboard = NULL; + + if (getGemeTypeLoadSession() != NULL) { + loadArena(getGemeTypeLoadSession()); + return; + } + + switch (getNetTypeGame()) { + case NET_GAME_TYPE_NONE: + setWorldArena(getChoiceArena()); + addNewItem(arena->spaceItem, ID_UNKNOWN); + getSettingCountRound(&arena->max_countRound); + + tux = newTux(); + tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + tuxWithControlRightKeyboard = tux; + getSettingNameRight(name); + tuxSetName(tux, name); + addObjectToSpace(arena->spaceTux, tux); + + tux = newTux(); + tux->control = TUX_CONTROL_KEYBOARD_LEFT; + tuxWithControlLeftKeyboard = tux; + getSettingNameLeft(name); + tuxSetName(tux, name); + addObjectToSpace(arena->spaceTux, tux); + + if (isSettingAI()) { + tux->control = TUX_CONTROL_AI; + + if (loadModule("libmodAI") != 0) { + tux->control = TUX_CONTROL_KEYBOARD_LEFT; + } + } + //printf("getGemeTypeLoadSession = %s\n", getGemeTypeLoadSession()); + + break; + + case NET_GAME_TYPE_SERVER: + setWorldArena(getChoiceArena()); + addNewItem(arena->spaceItem, ID_UNKNOWN); + getSettingCountRound(&arena->max_countRound); + + tux = newTux(); + tux->control = TUX_CONTROL_KEYBOARD_RIGHT; + tuxWithControlRightKeyboard = tux; + getSettingNameRight(name); + tuxSetName(tux, name); + addObjectToSpace(arena->spaceTux, tux); + break; + + case NET_GAME_TYPE_CLIENT: + break; + } +} + +void drawWorld() +{ + if (arena != NULL) { + drawArena(arena); + drawPanel(tuxWithControlRightKeyboard, tuxWithControlLeftKeyboard); + + if (arena->w > WINDOW_SIZE_X || arena->h > WINDOW_SIZE_Y) { + drawRadar(arena); + } + } + + drawChat(); + drawPauza(); + drawTerm(); + drawSaveDialog(); +} + +static void netAction(tux_t * tux, int action) +{ + if (getSettingGameType() == NET_GAME_TYPE_SERVER) { + proto_send_event_server(PROTO_SEND_ALL_SEES_TUX, NULL, tux, action); + } + + if (getSettingGameType() == NET_GAME_TYPE_CLIENT) { + proto_send_event_client(action); + } +} + +static void control_keyboard_right(tux_t * tux) +{ + static int lastKey = 0; + int countKey; + Uint8 *mapa; + mapa = SDL_GetKeyState(NULL); + + assert(tux != NULL); + assert(mapa != NULL); + + countKey = 0; + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_SWITCH_WEAPON)] == SDL_PRESSED + && tux->isCanSwitchGun == TRUE) { + netAction(tux, TUX_SWITCH_GUN); + actionTux(tux, TUX_SWITCH_GUN); + return; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_SHOOT)] == SDL_PRESSED + && tux->isCanShot == TRUE) { + netAction(tux, TUX_SHOT); + actionTux(tux, TUX_SHOT); + return; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_UP)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_UP)) + goto tuUp; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_RIGHT_MOVE_UP); + netAction(tux, TUX_UP); + actionTux(tux, TUX_UP); + return; + + tuUp:; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_RIGHT)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_RIGHT)) + goto tuRight; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_RIGHT_MOVE_RIGHT); + netAction(tux, TUX_RIGHT); + actionTux(tux, TUX_RIGHT); + return; + + tuRight:; + + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_LEFT)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_LEFT)) + goto tuLeft; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_RIGHT_MOVE_LEFT); + netAction(tux, TUX_LEFT); + actionTux(tux, TUX_LEFT); + return; + + tuLeft:; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_RIGHT_MOVE_DOWN)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_RIGHT_MOVE_DOWN)) + goto tuDown; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_RIGHT_MOVE_DOWN); + netAction(tux, TUX_DOWN); + actionTux(tux, TUX_DOWN); + return; + + tuDown:; + } +} + +static void control_keyboard_left(tux_t * tux) +{ + static int lastKey = 0; + int countKey; + Uint8 *mapa; + mapa = SDL_GetKeyState(NULL); + + assert(tux != NULL); + assert(mapa != NULL); + + countKey = 0; + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED) + countKey++; + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_SWITCH_WEAPON)] == SDL_PRESSED) { + if (tux->isCanSwitchGun == TRUE) { + actionTux(tux, TUX_SWITCH_GUN); + return; + } + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_SHOOT)] == SDL_PRESSED + && tux->isCanShot == TRUE) { + actionTux(tux, TUX_SHOT); + return; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_UP)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_UP)) + goto tuUp; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_LEFT_MOVE_UP); + actionTux(tux, TUX_UP); + return; + + tuUp:; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_RIGHT)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_RIGHT)) + goto tuRight; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_LEFT_MOVE_RIGHT); + actionTux(tux, TUX_RIGHT); + return; + + tuRight:; + + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_LEFT)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_LEFT)) + goto tuLeft; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_LEFT_MOVE_LEFT); + actionTux(tux, TUX_LEFT); + return; + + tuLeft:; + } + + if (mapa[(SDLKey) getKey(KEY_TUX_LEFT_MOVE_DOWN)] == SDL_PRESSED) { + if (countKey > 1 && lastKey == getKey(KEY_TUX_LEFT_MOVE_DOWN)) + goto tuDown; + + if (countKey == 1) + lastKey = getKey(KEY_TUX_LEFT_MOVE_DOWN); + actionTux(tux, TUX_DOWN); + return; + + tuDown:; + } +} + +static void eventEnd() +{ + if (isEndWorld == TRUE) { + setScreen("analyze"); + return; + } +} + +tux_t *getControlTux(int control_type) +{ + switch (control_type) { + case TUX_CONTROL_KEYBOARD_RIGHT: + return tuxWithControlRightKeyboard; + break; + case TUX_CONTROL_KEYBOARD_LEFT: + return tuxWithControlLeftKeyboard; + break; + } + + return NULL; +} + +void setControlTux(tux_t * tux, int control_type) +{ + switch (control_type) { + case TUX_CONTROL_KEYBOARD_RIGHT: + tuxWithControlRightKeyboard = tux; + break; + case TUX_CONTROL_KEYBOARD_LEFT: + tuxWithControlLeftKeyboard = tux; + break; + } +} + +void tuxControl(tux_t * p) +{ + assert(p != NULL); + + if (p->status != TUX_STATUS_ALIVE) { + return; + } + + switch (p->control) { + case TUX_CONTROL_NONE: + assert(!_("Tux has not defined controls!")); + break; + + case TUX_CONTROL_KEYBOARD_LEFT: + if (isChatActive() == FALSE) { + control_keyboard_left(p); + } + break; + + case TUX_CONTROL_KEYBOARD_RIGHT: + if (isChatActive() == FALSE) { + control_keyboard_right(p); + } + break; + } +} + +void eventWorld() +{ + tux_t *thisTux; + + if (arena == NULL) { + eventNetMultiplayer(); + eventEnd(); + return; + } + + eventNetMultiplayer(); + + if (isPauzeActive() == FALSE && isSaveDialogActive() == FALSE) { + eventArena(arena); + //eventModule(); + } + + thisTux = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + + addToRadar(thisTux->id, thisTux->x, thisTux->y, RADAR_TYPE_YOU); + + thisTux = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); + + if (thisTux != NULL) { + addToRadar(thisTux->id, thisTux->x, thisTux->y, RADAR_TYPE_TUX); + } + + eventEnd(); + eventChat(); + eventPauza(); + eventTerm(); + eventSaveDialog(); + +} + +static void hotkey_escape() +{ + setWorldEnd(); +} + +void startWorld() +{ + arena = NULL; + isEndWorld = FALSE; + + registerHotKey(SDLK_ESCAPE, hotkey_escape); + initArena(); + initListID(); + initRadar(); + initPauza(); + initTerm(); + initSaveDialog(); + + initModule(); + setGameType(); + initChat(); + prepareArena(); +} + +static void action_analyze(space_t * space, tux_t * tux, void *p) +{ + addAnalyze(tux->name, tux->score); +} + +static void setAnalyze() +{ + restartAnalyze(); + + actionSpace(arena->spaceTux, action_analyze, NULL); + + endAnalyze(); +} + +static void setTable() +{ + tux_t *tuxRight; + tux_t *tuxLeft; + + if (getSettingGameType() != NET_GAME_TYPE_NONE) { + return; + } + + tuxRight = getControlTux(TUX_CONTROL_KEYBOARD_RIGHT); + tuxLeft = getControlTux(TUX_CONTROL_KEYBOARD_LEFT); + + if (tuxRight->score > tuxLeft->score) { + addPlayerInHighScore(tuxRight->name, tuxRight->score); + } + + if (tuxLeft->score > tuxRight->score) { + addPlayerInHighScore(tuxLeft->name, tuxLeft->score); + } +} + +void stoptWorld() +{ + if (arena != NULL) { + setTable(); + setAnalyze(); + } + + unregisterHotKey(SDLK_ESCAPE); + quitArena(); + + quitNetMultiplayer(); + + if (arena != NULL) { + destroyArena(arena); + } + + quitRadar(); + quitPauza(); + quitTerm(); + quitSaveDialog(); + + +#ifndef NO_SOUND + stopMusic(); +#endif + delAllImageInGroup(IMAGE_GROUP_USER); + +#ifndef NO_SOUND + delAllMusicInGroup(MUSIC_GROUP_USER); +#endif + quitModule(); + quitChat(); + quitListID(); +} + +void initWorld() +{ + assert(isImageInicialized() == TRUE); + assert(isTuxInicialized() == TRUE); + assert(isShotInicialized() == TRUE); + assert(isPanelInicialized() == TRUE); + assert(isScreenInicialized() == TRUE); + + registerScreen(newScreen + ("world", startWorld, eventWorld, drawWorld, stoptWorld)); + +#ifndef NO_SOUND + addSound("dead.ogg", "dead", SOUND_GROUP_BASE); + addSound("explozion.ogg", "explozion", SOUND_GROUP_BASE); + addSound("gun_lasser.ogg", "gun_lasser", SOUND_GROUP_BASE); + addSound("gun_revolver.ogg", "gun_revolver", SOUND_GROUP_BASE); + addSound("gun_scatter.ogg", "gun_scatter", SOUND_GROUP_BASE); + addSound("gun_tommy.ogg", "gun_tommy", SOUND_GROUP_BASE); + addSound("put_mine.ogg", "put_mine", SOUND_GROUP_BASE); + addSound("teleport.ogg", "teleport", SOUND_GROUP_BASE); + addSound("item_bonus.ogg", "item_bonus", SOUND_GROUP_BASE); + addSound("item_gun.ogg", "item_gun", SOUND_GROUP_BASE); + addSound("switch_gun.ogg", "switch_gun", SOUND_GROUP_BASE); + addSound("end.ogg", "end", SOUND_GROUP_BASE); +#endif + + isScreenWorldInit = TRUE; +} + +void quitWorld() +{ + DEBUG_MSG(_("Quitting screen world\n")); + isScreenWorldInit = FALSE; +} diff --git a/src/screen/world.h b/src/screen/world.h new file mode 100644 index 0000000..67935f7 --- /dev/null +++ b/src/screen/world.h @@ -0,0 +1,30 @@ + +#ifndef SCREEN_WORLD_H + +# define SCREEN_WORLD_H + +# include "main.h" +# include "myTimer.h" +# include "tux.h" +# include "arenaFile.h" +# include "arena.h" + +# define TIMER_END_ARENA 5000 +# define WORLD_COUNT_ROUND_UNLIMITED -1 +# define LAG_SERVER_UNKNOWN -1 + +extern bool_t isScreenWorldInicialized(); +extern void initWorld(); +extern void setWorldArena(arenaFile_t * arenaFile); +extern void setWorldEnd(); +extern void countRoundInc(); +extern tux_t *getControlTux(int control_type); +extern void setControlTux(tux_t * tux, int control_type); +extern void tuxControl(tux_t * p); +extern void drawWorld(); +extern void eventWorld(); +extern void startArena(); +extern void stopArena(); +extern void quitWorld(); + +#endif -- cgit v1.2.3