From 509890f14896d2064916555c04a3bfeec537cb1d Mon Sep 17 00:00:00 2001 From: Tomas Chvatal Date: Sat, 10 Jan 2009 17:00:10 +0100 Subject: Revert "First pass renaming sreen and widgets." This reverts commit 5855f591b6d509633e3730346e18122768ec6e04. --- src/CMakeLists.txt | 22 +- 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/tcp_server.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/saveDialog.c | 8 +- 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 | 191 ----------- 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 | 191 +++++++++++ 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 -- src/widget/button.c | 103 ------ src/widget/button.h | 26 -- src/widget/buttonimage.c | 86 ----- src/widget/buttonimage.h | 27 -- src/widget/catchkey.c | 140 -------- src/widget/catchkey.h | 27 -- src/widget/check.c | 118 ------- src/widget/check.h | 28 -- src/widget/choicegroup.c | 147 -------- src/widget/choicegroup.h | 33 -- src/widget/image.c | 52 --- src/widget/image.h | 19 -- src/widget/label.c | 64 ---- src/widget/label.h | 24 -- src/widget/select.c | 150 --------- src/widget/select.h | 26 -- src/widget/textfield.c | 444 ------------------------ src/widget/textfield.h | 41 --- src/widget/widget.c | 2 +- src/widget/widget_button.c | 103 ++++++ src/widget/widget_button.h | 26 ++ src/widget/widget_buttonimage.c | 86 +++++ src/widget/widget_buttonimage.h | 27 ++ src/widget/widget_catchkey.c | 140 ++++++++ src/widget/widget_catchkey.h | 27 ++ src/widget/widget_check.c | 118 +++++++ src/widget/widget_check.h | 28 ++ src/widget/widget_choicegroup.c | 147 ++++++++ src/widget/widget_choicegroup.h | 33 ++ src/widget/widget_image.c | 52 +++ src/widget/widget_image.h | 19 ++ src/widget/widget_label.c | 64 ++++ src/widget/widget_label.h | 24 ++ src/widget/widget_select.c | 150 +++++++++ src/widget/widget_select.h | 26 ++ src/widget/widget_textfield.c | 444 ++++++++++++++++++++++++ src/widget/widget_textfield.h | 41 +++ 100 files changed, 6001 insertions(+), 6001 deletions(-) delete mode 100644 src/screen/analyze.c delete mode 100644 src/screen/analyze.h delete mode 100644 src/screen/browser.c delete mode 100644 src/screen/browser.h delete mode 100644 src/screen/choiceArena.c delete mode 100644 src/screen/choiceArena.h delete mode 100644 src/screen/credits.c delete mode 100644 src/screen/credits.h delete mode 100644 src/screen/downArena.c delete mode 100644 src/screen/downArena.h delete mode 100644 src/screen/gameType.c delete mode 100644 src/screen/gameType.h delete mode 100644 src/screen/mainMenu.c delete mode 100644 src/screen/mainMenu.h create mode 100644 src/screen/screen_analyze.c create mode 100644 src/screen/screen_analyze.h create mode 100644 src/screen/screen_browser.c create mode 100644 src/screen/screen_browser.h create mode 100644 src/screen/screen_choiceArena.c create mode 100644 src/screen/screen_choiceArena.h create mode 100644 src/screen/screen_credits.c create mode 100644 src/screen/screen_credits.h create mode 100644 src/screen/screen_downArena.c create mode 100644 src/screen/screen_downArena.h create mode 100644 src/screen/screen_gameType.c create mode 100644 src/screen/screen_gameType.h create mode 100644 src/screen/screen_mainMenu.c create mode 100644 src/screen/screen_mainMenu.h create mode 100644 src/screen/screen_setting.c create mode 100644 src/screen/screen_setting.h create mode 100644 src/screen/screen_settingKeys.c create mode 100644 src/screen/screen_settingKeys.h create mode 100644 src/screen/screen_table.c create mode 100644 src/screen/screen_table.h create mode 100644 src/screen/screen_world.c create mode 100644 src/screen/screen_world.h delete mode 100644 src/screen/setting.c delete mode 100644 src/screen/setting.h delete mode 100644 src/screen/settingKeys.c delete mode 100644 src/screen/settingKeys.h delete mode 100644 src/screen/table.c delete mode 100644 src/screen/table.h delete mode 100644 src/screen/world.c delete mode 100644 src/screen/world.h delete mode 100644 src/widget/button.c delete mode 100644 src/widget/button.h delete mode 100644 src/widget/buttonimage.c delete mode 100644 src/widget/buttonimage.h delete mode 100644 src/widget/catchkey.c delete mode 100644 src/widget/catchkey.h delete mode 100644 src/widget/check.c delete mode 100644 src/widget/check.h delete mode 100644 src/widget/choicegroup.c delete mode 100644 src/widget/choicegroup.h delete mode 100644 src/widget/image.c delete mode 100644 src/widget/image.h delete mode 100644 src/widget/label.c delete mode 100644 src/widget/label.h delete mode 100644 src/widget/select.c delete mode 100644 src/widget/select.h delete mode 100644 src/widget/textfield.c delete mode 100644 src/widget/textfield.h create mode 100644 src/widget/widget_button.c create mode 100644 src/widget/widget_button.h create mode 100644 src/widget/widget_buttonimage.c create mode 100644 src/widget/widget_buttonimage.h create mode 100644 src/widget/widget_catchkey.c create mode 100644 src/widget/widget_catchkey.h create mode 100644 src/widget/widget_check.c create mode 100644 src/widget/widget_check.h create mode 100644 src/widget/widget_choicegroup.c create mode 100644 src/widget/widget_choicegroup.h create mode 100644 src/widget/widget_image.c create mode 100644 src/widget/widget_image.h create mode 100644 src/widget/widget_label.c create mode 100644 src/widget/widget_label.h create mode 100644 src/widget/widget_select.c create mode 100644 src/widget/widget_select.h create mode 100644 src/widget/widget_textfield.c create mode 100644 src/widget/widget_textfield.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9f642e..0b9de02 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,18 +56,18 @@ SET ( SRC_client ${WORKDIR}/client/pauza ${WORKDIR}/client/saveDialog ${WORKDIR}/client/hotKey - ${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}/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}/widget/check ${WORKDIR}/widget/button - ${WORKDIR}/widget/textfield ${WORKDIR}/widget/label - ${WORKDIR}/widget/buttonimage ${WORKDIR}/widget/image - ${WORKDIR}/widget/select ${WORKDIR}/widget/catchkey - ${WORKDIR}/widget/choicegroup ${WORKDIR}/widget/widget + ${WORKDIR}/widget/widget_check ${WORKDIR}/widget/widget_button + ${WORKDIR}/widget/widget_textfield ${WORKDIR}/widget/widget_label + ${WORKDIR}/widget/widget_buttonimage ${WORKDIR}/widget/widget_image + ${WORKDIR}/widget/widget_select ${WORKDIR}/widget/widget_catchkey + ${WORKDIR}/widget/widget_choicegroup ${WORKDIR}/widget/widget ) SET ( SRC_audio diff --git a/src/base/arena.c b/src/base/arena.c index effbff4..4658e08 100644 --- a/src/base/arena.c +++ b/src/base/arena.c @@ -14,8 +14,8 @@ #ifndef PUBLIC_SERVER # include "hotKey.h" -# include "world.h" -# include "setting.h" +# include "screen_world.h" +# include "screen_setting.h" # include "layer.h" #endif diff --git a/src/base/gun.c b/src/base/gun.c index d357349..27f88bd 100644 --- a/src/base/gun.c +++ b/src/base/gun.c @@ -19,7 +19,7 @@ #endif #ifndef PUBLIC_SERVER # include "interface.h" -# include "world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER # include "publicServer.h" diff --git a/src/base/item.c b/src/base/item.c index 75074bc..822d6b4 100644 --- a/src/base/item.c +++ b/src/base/item.c @@ -19,8 +19,8 @@ # include "radar.h" # include "layer.h" -# include "world.h" -# include "setting.h" +# include "screen_world.h" +# include "screen_setting.h" # ifndef NO_SOUND # include "sound.h" diff --git a/src/base/net_multiplayer.c b/src/base/net_multiplayer.c index cb9ca59..f59b3b2 100644 --- a/src/base/net_multiplayer.c +++ b/src/base/net_multiplayer.c @@ -15,8 +15,8 @@ #include "udp.h" #ifndef PUBLIC_SERVER -# include "setting.h" -# include "choiceArena.h" +# include "screen_setting.h" +# include "screen_choiceArena.h" # include "screen.h" # include "client.h" diff --git a/src/base/proto.c b/src/base/proto.c index f927dfa..606dd33 100644 --- a/src/base/proto.c +++ b/src/base/proto.c @@ -21,11 +21,11 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -# include "world.h" -# include "setting.h" -# include "choiceArena.h" -# include "analyze.h" -# include "downArena.h" +# include "screen_world.h" +# include "screen_setting.h" +# include "screen_choiceArena.h" +# include "screen_analyze.h" +# include "screen_downArena.h" # include "client.h" # include "term.h" # include "radar.h" diff --git a/src/base/proto.h b/src/base/proto.h index 8cd7568..590317b 100644 --- a/src/base/proto.h +++ b/src/base/proto.h @@ -18,9 +18,9 @@ # include "net_multiplayer.h" # ifndef PUBLIC_SERVER -# include "world.h" -# include "setting.h" -# include "choiceArena.h" +# include "screen_world.h" +# include "screen_setting.h" +# include "screen_choiceArena.h" # include "client.h" # endif diff --git a/src/base/server.c b/src/base/server.c index 5f16ef7..2112927 100644 --- a/src/base/server.c +++ b/src/base/server.c @@ -33,7 +33,7 @@ #include "downServer.h" #ifndef PUBLIC_SERVER -# include "world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/base/serverSendMsg.c b/src/base/serverSendMsg.c index e38975f..e7d1c09 100644 --- a/src/base/serverSendMsg.c +++ b/src/base/serverSendMsg.c @@ -11,7 +11,7 @@ #include "serverSendMsg.h" #ifndef PUBLIC_SERVER -# include "world.h" +# include "screen_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 306527b..977ccb4 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 "world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/base/tcp_server.c b/src/base/tcp_server.c index de5ac39..b781fb5 100644 --- a/src/base/tcp_server.c +++ b/src/base/tcp_server.c @@ -30,7 +30,7 @@ #include "index.h" #ifndef PUBLIC_SERVER -# include "world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/base/tux.c b/src/base/tux.c index 5bb2305..746679d 100644 --- a/src/base/tux.c +++ b/src/base/tux.c @@ -28,7 +28,7 @@ # include "sound.h" # endif -# include "world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/base/udp_server.c b/src/base/udp_server.c index fc65d19..a469a3a 100644 --- a/src/base/udp_server.c +++ b/src/base/udp_server.c @@ -30,7 +30,7 @@ #include "index.h" #ifndef PUBLIC_SERVER -# include "world.h" +# include "screen_world.h" #endif #ifdef PUBLIC_SERVER diff --git a/src/client/chat.c b/src/client/chat.c index b446b08..6ca9ec9 100644 --- a/src/client/chat.c +++ b/src/client/chat.c @@ -11,7 +11,7 @@ #include "serverSendMsg.h" #include "net_multiplayer.h" -#include "world.h" +#include "screen_world.h" #include "proto.h" #include "interface.h" #include "chat.h" diff --git a/src/client/client.c b/src/client/client.c index 1902be6..e92a238 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -23,8 +23,8 @@ #include "client.h" -#include "analyze.h" -#include "world.h" +#include "screen_analyze.h" +#include "screen_world.h" #include "buffer.h" #include "udp.h" diff --git a/src/client/game.c b/src/client/game.c index 87676d5..e96805b 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 "settingKeys.h" +#include "screen_settingKeys.h" #include "panel.h" #include "radar.h" @@ -30,17 +30,17 @@ # include "music.h" #endif -#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" +#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" static void initGame() { diff --git a/src/client/layer.c b/src/client/layer.c index c50be65..983a9c8 100644 --- a/src/client/layer.c +++ b/src/client/layer.c @@ -10,7 +10,7 @@ #include "layer.h" #include "image.h" -#include "world.h" +#include "screen_world.h" static list_t *listLayer; diff --git a/src/client/saveDialog.c b/src/client/saveDialog.c index d8cfa29..1c832e7 100644 --- a/src/client/saveDialog.c +++ b/src/client/saveDialog.c @@ -17,9 +17,9 @@ #include "hotKey.h" #include "widget.h" -#include "label.h" -#include "button.h" -#include "textfield.h" +#include "widget_label.h" +#include "widget_button.h" +#include "widget_textfield.h" static image_t *g_background; static bool_t activeSaveDialog; @@ -64,7 +64,7 @@ void initSaveDialog() { activeSaveDialog = FALSE; - g_background = getImage(IMAGE_GROUP_BASE, "main"); + g_background = getImage(IMAGE_GROUP_BASE, "screen_main"); widgetLabelMsg = newWidgetLabel("name", SAVE_DIALOG_LOCATIN_X + 20, SAVE_DIALOG_LOCATIN_Y + 20, diff --git a/src/client/saveLoad.c b/src/client/saveLoad.c index 0448a4f..b5dbdf2 100644 --- a/src/client/saveLoad.c +++ b/src/client/saveLoad.c @@ -16,8 +16,8 @@ #include "saveLoad.h" -#include "choiceArena.h" -#include "world.h" +#include "screen_choiceArena.h" +#include "screen_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 deleted file mode 100644 index 516f7b9..0000000 --- a/src/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 "mainMenu.h" -#include "analyze.h" - -#include "widget.h" -#include "label.h" -#include "button.h" -#include "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, "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 deleted file mode 100644 index 8f975b4..0000000 --- a/src/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/browser.c b/src/screen/browser.c deleted file mode 100644 index f6aa702..0000000 --- a/src/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 "gameType.h" -#include "browser.h" - -#include "widget.h" -#include "image.h" -#include "label.h" -#include "button.h" -#include "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, "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 deleted file mode 100644 index e810e58..0000000 --- a/src/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/choiceArena.c b/src/screen/choiceArena.c deleted file mode 100644 index e73eea6..0000000 --- a/src/screen/choiceArena.c +++ /dev/null @@ -1,191 +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 "mainMenu.h" -#include "choiceArena.h" - -#include "widget.h" -#include "label.h" -#include "button.h" -#include "image.h" -#include "buttonimage.h" - -static widget_t *image_backgorund; - -static widget_t *button_play; -static widget_t *button_back; - -static list_t *listWidgetButtonimage; -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); - - for (i = 0; i < listWidgetButtonimage->count; i++) { - widget_t *this; - - this = (widget_t *) listWidgetButtonimage->list[i]; - drawWidgetButtonimage(this); - } -} - -void eventScreenChoiceArena() -{ - int i; - - eventWidgetButton(button_play); - eventWidgetButton(button_back); - - for (i = 0; i < listWidgetButtonimage->count; i++) { - widget_t *this; - - this = (widget_t *) listWidgetButtonimage->list[i]; - eventWidgetButtonimage(this); - } -} - -void stopScreenChoiceArena() -{ - unregisterHotKey(SDLK_ESCAPE); -} - -static void eventWidgetButtonImage(void *p) -{ - widget_t *buttonimage; - int i; - - buttonimage = (widget_t *) (p); - - for (i = 0; i < listWidgetButtonimage->count; i++) { - widget_t *this; - - this = (widget_t *) (listWidgetButtonimage->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 *) listWidgetButtonimage->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"); - } -} - -void initScreenChoiceArena() -{ - image_t *image; - int i; - - image = getImage(IMAGE_GROUP_BASE, "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); - - listWidgetButtonimage = 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); - - x = 100 + 200 * (i - 3 * (i / 3)); - y = 150 + 200 * (i / 3); - - widget_buttonimage = newWidgetButtonimage(image, x, y, eventWidgetButtonImage); -/* - if( i == choiceArenaId ) - { - widget_buttonimage->active = 1; - } -*/ - addList(listWidgetButtonimage, widget_buttonimage); - } - - registerScreen( newScreen("chiceArena", startScreenChoiceArena, - eventScreenChoiceArena, drawScreenChoiceArena, - stopScreenChoiceArena)); -} - -void quitScreenChoiceArena() -{ - destroyWidgetImage(image_backgorund); - - destroyWidgetButton(button_play); - destroyWidgetButton(button_back); - - destroyListItem(listWidgetButtonimage, destroyWidgetButtonimage); -} diff --git a/src/screen/choiceArena.h b/src/screen/choiceArena.h deleted file mode 100644 index dbe12de..0000000 --- a/src/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/credits.c b/src/screen/credits.c deleted file mode 100644 index b78aec0..0000000 --- a/src/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 "credits.h" - -#include "widget.h" -#include "image.h" -#include "label.h" -#include "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, "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 deleted file mode 100644 index 37c25f3..0000000 --- a/src/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/downArena.c b/src/screen/downArena.c deleted file mode 100644 index 899d59f..0000000 --- a/src/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 "image.h" -#include "label.h" -#include "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(), PROTO_TCPv4); - - 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(), PROTO_UDPv4); - - 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, "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 deleted file mode 100644 index d9f25d7..0000000 --- a/src/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/gameType.c b/src/screen/gameType.c deleted file mode 100644 index c71e7ef..0000000 --- a/src/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 "gameType.h" -#include "setting.h" - -#include "widget.h" -#include "label.h" -#include "button.h" -#include "image.h" -#include "textfield.h" -#include "choicegroup.h" -#include "check.h" -#include "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, "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 deleted file mode 100644 index 2c836fc..0000000 --- a/src/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/mainMenu.c b/src/screen/mainMenu.c deleted file mode 100644 index 2209d8e..0000000 --- a/src/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 "mainMenu.h" -#include "setting.h" - -#include "widget.h" -#include "label.h" -#include "button.h" -#include "textfield.h" -#include "check.h" -#include "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("main.png", IMAGE_NO_ALPHA, "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 deleted file mode 100644 index ecb369b..0000000 --- a/src/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_analyze.c b/src/screen/screen_analyze.c new file mode 100644 index 0000000..b249f81 --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..8f975b4 --- /dev/null +++ b/src/screen/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/screen_browser.c b/src/screen/screen_browser.c new file mode 100644 index 0000000..f09ca18 --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..e810e58 --- /dev/null +++ b/src/screen/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/screen_choiceArena.c b/src/screen/screen_choiceArena.c new file mode 100644 index 0000000..7bc6ce4 --- /dev/null +++ b/src/screen/screen_choiceArena.c @@ -0,0 +1,191 @@ + +#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 list_t *listWidgetButtonimage; +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); + + for (i = 0; i < listWidgetButtonimage->count; i++) { + widget_t *this; + + this = (widget_t *) listWidgetButtonimage->list[i]; + drawWidgetButtonimage(this); + } +} + +void eventScreenChoiceArena() +{ + int i; + + eventWidgetButton(button_play); + eventWidgetButton(button_back); + + for (i = 0; i < listWidgetButtonimage->count; i++) { + widget_t *this; + + this = (widget_t *) listWidgetButtonimage->list[i]; + eventWidgetButtonimage(this); + } +} + +void stopScreenChoiceArena() +{ + unregisterHotKey(SDLK_ESCAPE); +} + +static void eventWidgetButtonImage(void *p) +{ + widget_t *buttonimage; + int i; + + buttonimage = (widget_t *) (p); + + for (i = 0; i < listWidgetButtonimage->count; i++) { + widget_t *this; + + this = (widget_t *) (listWidgetButtonimage->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 *) listWidgetButtonimage->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"); + } +} + +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); + + listWidgetButtonimage = 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); + + x = 100 + 200 * (i - 3 * (i / 3)); + y = 150 + 200 * (i / 3); + + widget_buttonimage = newWidgetButtonimage(image, x, y, eventWidgetButtonImage); +/* + if( i == choiceArenaId ) + { + widget_buttonimage->active = 1; + } +*/ + addList(listWidgetButtonimage, widget_buttonimage); + } + + registerScreen( newScreen("chiceArena", startScreenChoiceArena, + eventScreenChoiceArena, drawScreenChoiceArena, + stopScreenChoiceArena)); +} + +void quitScreenChoiceArena() +{ + destroyWidgetImage(image_backgorund); + + destroyWidgetButton(button_play); + destroyWidgetButton(button_back); + + destroyListItem(listWidgetButtonimage, destroyWidgetButtonimage); +} diff --git a/src/screen/screen_choiceArena.h b/src/screen/screen_choiceArena.h new file mode 100644 index 0000000..dbe12de --- /dev/null +++ b/src/screen/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/screen_credits.c b/src/screen/screen_credits.c new file mode 100644 index 0000000..a3ed787 --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..37c25f3 --- /dev/null +++ b/src/screen/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/screen_downArena.c b/src/screen/screen_downArena.c new file mode 100644 index 0000000..94b2387 --- /dev/null +++ b/src/screen/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 "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(), PROTO_TCPv4); + + 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(), PROTO_UDPv4); + + 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 new file mode 100644 index 0000000..d9f25d7 --- /dev/null +++ b/src/screen/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/screen_gameType.c b/src/screen/screen_gameType.c new file mode 100644 index 0000000..1ef8461 --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..2c836fc --- /dev/null +++ b/src/screen/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/screen_mainMenu.c b/src/screen/screen_mainMenu.c new file mode 100644 index 0000000..84d57b8 --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..ecb369b --- /dev/null +++ b/src/screen/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_setting.c b/src/screen/screen_setting.c new file mode 100644 index 0000000..b52a9db --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..9521cca --- /dev/null +++ b/src/screen/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/screen_settingKeys.c b/src/screen/screen_settingKeys.c new file mode 100644 index 0000000..35215cf --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..c90006e --- /dev/null +++ b/src/screen/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/screen_table.c b/src/screen/screen_table.c new file mode 100644 index 0000000..b49de93 --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..a91b233 --- /dev/null +++ b/src/screen/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/screen_world.c b/src/screen/screen_world.c new file mode 100644 index 0000000..8f2f6d2 --- /dev/null +++ b/src/screen/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 "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 new file mode 100644 index 0000000..67935f7 --- /dev/null +++ b/src/screen/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 diff --git a/src/screen/setting.c b/src/screen/setting.c deleted file mode 100644 index 67e8ac9..0000000 --- a/src/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 "mainMenu.h" -#include "setting.h" -#include "settingKeys.h" -#include "settingKeys.h" -#include "choiceArena.h" - -#include "widget.h" -#include "label.h" -#include "button.h" -#include "image.h" -#include "textfield.h" -#include "check.h" -#include "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, "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 deleted file mode 100644 index 9521cca..0000000 --- a/src/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/settingKeys.c b/src/screen/settingKeys.c deleted file mode 100644 index ccd89f4..0000000 --- a/src/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 "mainMenu.h" -#include "setting.h" -#include "settingKeys.h" - -#include "widget.h" -#include "button.h" -#include "image.h" -#include "catchkey.h" -#include "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, "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 deleted file mode 100644 index c90006e..0000000 --- a/src/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/table.c b/src/screen/table.c deleted file mode 100644 index c9c005f..0000000 --- a/src/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 "table.h" - -#include "image.h" -#include "label.h" -#include "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("table.png", IMAGE_NO_ALPHA, "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 deleted file mode 100644 index a91b233..0000000 --- a/src/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/world.c b/src/screen/world.c deleted file mode 100644 index 5fa3ecd..0000000 --- a/src/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 "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 deleted file mode 100644 index 67935f7..0000000 --- a/src/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/widget/button.c b/src/widget/button.c deleted file mode 100644 index e2db211..0000000 --- a/src/widget/button.c +++ /dev/null @@ -1,103 +0,0 @@ - -#include -#include - -#include "main.h" - -#include "interface.h" -#include "image.h" -#include "font.h" - -#include "widget.h" -#include "button.h" - -widget_t *newWidgetButton(char *text, int x, int y, void (*fce_event) (void *)) -{ - widget_button_t *new; - - new = malloc(sizeof(widget_button_t)); - new->text = strdup(text); - new->fce_event = fce_event; - getTextSize(text, &(new->w), &(new->h)); - - return newWidget(WIDGET_TYPE_BUTTON, x, y, - WIDGET_BUTTON_WIDTH, WIDGET_BUTTON_HEIGHT, new); -} - -void drawWidgetButton(widget_t * widget) -{ - widget_button_t *p; - static image_t *g_button0 = NULL; - static image_t *g_button1 = NULL; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); - - p = (widget_button_t *) widget->private_data; - getMousePosition(&x, &y); - - if (g_button0 == NULL) { - g_button0 = addImageData("button0.png", IMAGE_ALPHA, "button0", IMAGE_GROUP_BASE); - } - - if (g_button1 == NULL) { - g_button1 = - addImageData("button1.png", IMAGE_ALPHA, "button1", IMAGE_GROUP_BASE); - } - - if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT) { - drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h); - } else { - drawImage(g_button0, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h); - } - - //drawFont(p->text, p->x+WIDGET_BUTTON_WIDTH/2-p->w/2, p->y+p->h/2, COLOR_WHITE); - drawFont(p->text, widget->x + WIDGET_BUTTON_WIDTH / 2 - p->w / 2, - widget->y + WIDGET_BUTTON_HEIGHT / 2 - p->h / 2, COLOR_WHITE); -} - -void eventWidgetButton(widget_t * widget) -{ - widget_button_t *p; - static int time = 0; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); - - p = (widget_button_t *) widget->private_data; - - if (time > 0) { - time--; - return; - } - - getMousePosition(&x, &y); - - if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT && - isMouseClicked()) { - time = WIDGET_BUTTON_TIME; - - DEBUG_MSG(_("Event caught\n")); - - p->fce_event(widget); - } -} - -void destroyWidgetButton(widget_t * widget) -{ - widget_button_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTON); - - p = (widget_button_t *) widget->private_data; - - free(p->text); - free(p); - - destroyWidget(widget); -} diff --git a/src/widget/button.h b/src/widget/button.h deleted file mode 100644 index ac238be..0000000 --- a/src/widget/button.h +++ /dev/null @@ -1,26 +0,0 @@ - -#ifndef WIDGET_BUTTON_H - -# define WIDGET_BUTTON_H - -# include "main.h" -# include "widget.h" - -# define WIDGET_BUTTON_TIME 10 - -# define WIDGET_BUTTON_WIDTH 125 -# define WIDGET_BUTTON_HEIGHT 36 - -typedef struct widget_button { - char *text; - int w, h; - void (*fce_event) (void *); -} widget_button_t; - -extern widget_t *newWidgetButton(char *text, int x, int y, - void (*fce_event) (void *)); -extern void drawWidgetButton(widget_t * widget); -extern void eventWidgetButton(widget_t * widget); -extern void destroyWidgetButton(widget_t * widget); - -#endif diff --git a/src/widget/buttonimage.c b/src/widget/buttonimage.c deleted file mode 100644 index 1859ef0..0000000 --- a/src/widget/buttonimage.c +++ /dev/null @@ -1,86 +0,0 @@ - -#include -#include - -#include "main.h" -#include "interface.h" -#include "font.h" -#include "image.h" - -#include "widget.h" -#include "buttonimage.h" - -widget_t *newWidgetButtonimage(image_t * image, int x, int y, void (*fce_event) (void *)) -{ - widget_buttonimage_t *new; - - new = malloc(sizeof(widget_buttonimage_t)); - new->image = image; - new->w = image->w / 2; - new->h = image->h; - new->active = 0; - new->fce_event = fce_event; - - return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new); -} - -void setWidgetButtonimageActive(widget_t * widget, bool_t active) -{ - widget_buttonimage_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - - p = (widget_buttonimage_t *) widget->private_data; - p->active = active; -} - -void drawWidgetButtonimage(widget_t * widget) -{ - widget_buttonimage_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - - p = (widget_buttonimage_t *) widget->private_data; - drawImage(p->image, widget->x, widget->y, p->active * p->w, 0, p->w, p->h); -} - -void eventWidgetButtonimage(widget_t * widget) -{ - widget_buttonimage_t *p; - static int time = 0; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - - p = (widget_buttonimage_t *) widget->private_data; - - if (time > 0) { - time--; - return; - } - - getMousePosition(&x, &y); - - if (x >= widget->x && x <= widget->x + p->w && - y >= widget->y && y <= widget->y + p->h && isMouseClicked()) { - time = WIDGET_BUTTONIMAGE_TIME; - p->active = 1; - p->fce_event(widget); - } -} - -void destroyWidgetButtonimage(widget_t * widget) -{ - widget_buttonimage_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); - - p = (widget_buttonimage_t *) widget->private_data; - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/buttonimage.h b/src/widget/buttonimage.h deleted file mode 100644 index 5a0ab7c..0000000 --- a/src/widget/buttonimage.h +++ /dev/null @@ -1,27 +0,0 @@ - -#ifndef WIDGET_BUTTONIMAGE_H - -# include "main.h" - -# define WIDGET_BUTTONIMAGE_H - -# define WIDGET_BUTTONIMAGE_TIME 10 - -# include "widget.h" - -typedef struct widget_buttonimageimage { - int w, h; - int active; - image_t *image; - void (*fce_event) (void *); -} widget_buttonimage_t; - -extern widget_t *newWidgetButtonimage(image_t * image, int x, int y, - void (*fce_event) (void *)); - -extern void setWidgetButtonimageActive(widget_t * widget, bool_t active); -extern void drawWidgetButtonimage(widget_t * widget); -extern void eventWidgetButtonimage(widget_t * widget); -extern void destroyWidgetButtonimage(widget_t * widget); - -#endif diff --git a/src/widget/catchkey.c b/src/widget/catchkey.c deleted file mode 100644 index ecfb993..0000000 --- a/src/widget/catchkey.c +++ /dev/null @@ -1,140 +0,0 @@ - -#include -#include - -#include "main.h" -#include "interface.h" -#include "font.h" - -#include "widget.h" -#include "catchkey.h" - -widget_t *newWidgetCatchkey(int key, int x, int y, void *event) -{ - widget_catchkey_t *new; - - new = malloc(sizeof(widget_catchkey_t)); - new->key = key; - new->fce_event = event; - new->active = FALSE; - - return newWidget(WIDGET_TYPE_CATCHKEY, x, y, WIDGET_CATCHKEY_WIDTH, WIDGET_CATCHKEY_HEIGHT, new); -} - -int getWidgetCatchKey(widget_t * widget) -{ - widget_catchkey_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); - - p = (widget_catchkey_t *) widget->private_data; - - return p->key; -} - -void setWidgetCatchKey(widget_t * widget, int key) -{ - widget_catchkey_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); - - p = (widget_catchkey_t *) widget->private_data; - - p->key = key; -} - -void drawWidgetCatchkey(widget_t * widget) -{ - widget_catchkey_t *p; - char *name; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); - - p = (widget_catchkey_t *) widget->private_data; - name = NULL; - - if (p->key != WIDGET_CATCHKEY_NOKEY) { - name = (char *) SDL_GetKeyName(p->key); - } - - if (name == NULL) { - name = "no key"; - } - - if (p->active) { - drawFont(name, widget->x, widget->y, COLOR_RED); - } else { - drawFont(name, widget->x, widget->y, COLOR_WHITE); - } -} - -static int getPessAnyKey() -{ - Uint8 *mapa; - int i; - - mapa = SDL_GetKeyState(NULL); - - for (i = SDLK_FIRST; i <= SDLK_COMPOSE; i++) { - if (i == SDLK_NUMLOCK || // black key - i == SDLK_CAPSLOCK || - i == SDLK_SCROLLOCK) { - continue; - } - - if (mapa[i] == SDL_PRESSED) { - return i; - } - } - - return WIDGET_CATCHKEY_NOKEY; -} - -void eventWidgetCatchkey(widget_t * widget) -{ - widget_catchkey_t *p; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); - - p = (widget_catchkey_t *) widget->private_data; - - getMousePosition(&x, &y); - - if (isMouseClicked()) { - if (x >= widget->x && x <= widget->x + WIDGET_CATCHKEY_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CATCHKEY_HEIGHT) { - p->active = TRUE; - } else { - p->active = FALSE; - } - } - - if (p->active == TRUE) { - int key; - - key = getPessAnyKey(); - - if (key != WIDGET_CATCHKEY_NOKEY) { - p->key = key; - p->fce_event(widget); - } - } -} - -void destroyWidgetCatchkey(widget_t * widget) -{ - widget_catchkey_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CATCHKEY); - - p = (widget_catchkey_t *) widget->private_data; - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/catchkey.h b/src/widget/catchkey.h deleted file mode 100644 index 106bc92..0000000 --- a/src/widget/catchkey.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WIDGET_CATCHKEY_H - -# define WIDGET_CATCHKEY_H - -# include "main.h" -# include "widget.h" - -# define WIDGET_CATCHKEY_WIDTH 110 -# define WIDGET_CATCHKEY_HEIGHT 12 - -# define WIDGET_CATCHKEY_NOKEY -1 - -typedef struct widget_catchkey_struct { - int w, h; - int key; - bool_t active; - void (*fce_event) (void *p); -} widget_catchkey_t; - -extern widget_t *newWidgetCatchkey(int key, int x, int y, void *event); -extern int getWidgetCatchKey(widget_t * p); -extern void setWidgetCatchKey(widget_t * p, int key); -extern void drawWidgetCatchkey(widget_t * p); -extern void eventWidgetCatchkey(widget_t * p); -extern void destroyWidgetCatchkey(widget_t * p); - -#endif diff --git a/src/widget/check.c b/src/widget/check.c deleted file mode 100644 index 7ef4b8b..0000000 --- a/src/widget/check.c +++ /dev/null @@ -1,118 +0,0 @@ - -#include -#include - -#include "main.h" -#include "interface.h" -#include "image.h" - -#include "widget.h" -#include "check.h" - -widget_t *newWidgetCheck(int x, int y, bool_t status, void (*fce_event) (void *)) -{ - widget_check_t *new; - - new = malloc(sizeof(widget_check_t)); - new->time = 0; - new->status = status; - new->fce_event = fce_event; - - return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT, new); -} - -void drawWidgetCheck(widget_t * widget) -{ - widget_check_t *p; - static image_t *g_check = NULL; - int x, y; - int offset; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); - - p = (widget_check_t *) widget->private_data; - - getMousePosition(&x, &y); - - if (g_check == NULL) { - g_check = addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); - } - - if (p->status == TRUE) { - offset = 0; - } else { - offset = WIDGET_CHECK_WIDTH; - } - - drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT); -} - -void eventWidgetCheck(widget_t * widget) -{ - widget_check_t *p; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); - - p = (widget_check_t *) widget->private_data; - - if (p->time > 0) { - p->time--; - return; - } - - getMousePosition(&x, &y); - - if (x >= widget->x && x <= widget->x + WIDGET_CHECK_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CHECK_HEIGHT && - isMouseClicked()) { - if (p->status == TRUE) { - p->status = FALSE; - p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; - } else { - p->status = TRUE; - p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; - } - - if (p->fce_event != NULL) { - p->fce_event(widget); - } - } -} - -bool_t getWidgetCheckStatus(widget_t * widget) -{ - widget_check_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); - - p = (widget_check_t *) widget->private_data; - - return p->status; -} - -void setWidgetCheckStatus(widget_t * widget, bool_t status) -{ - widget_check_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); - - p = (widget_check_t *) widget->private_data; - p->status = status; -} - -void destroyWidgetCheck(widget_t * widget) -{ - widget_check_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHECK); - - p = (widget_check_t *) widget->private_data; - free(p); - destroyWidget(widget); -} diff --git a/src/widget/check.h b/src/widget/check.h deleted file mode 100644 index 007e82c..0000000 --- a/src/widget/check.h +++ /dev/null @@ -1,28 +0,0 @@ - -#ifndef WIDGET_CHECK_H - -# define WIDGET_CHECK_H - -# include "main.h" -# include "widget.h" - -# define WIDGET_CHECK_TIME_SWITCH_STATUS 5 - -# define WIDGET_CHECK_WIDTH 25 -# define WIDGET_CHECK_HEIGHT 25 - -typedef struct widget_check { - bool_t status; - int time; - void (*fce_event) (void *); -} widget_check_t; - -extern widget_t *newWidgetCheck(int x, int y, bool_t status, - void (*fce_event) (void *)); -extern void drawWidgetCheck(widget_t * widget); -extern void eventWidgetCheck(widget_t * widget); -extern bool_t getWidgetCheckStatus(widget_t * widget); -extern void setWidgetCheckStatus(widget_t * widget, bool_t status); -extern void destroyWidgetCheck(widget_t * widget); - -#endif diff --git a/src/widget/choicegroup.c b/src/widget/choicegroup.c deleted file mode 100644 index 0eb562a..0000000 --- a/src/widget/choicegroup.c +++ /dev/null @@ -1,147 +0,0 @@ - -#include -#include - -#include "main.h" -#include "interface.h" -#include "image.h" - -#include "widget.h" -#include "choicegroup.h" - -widget_t *newWidgetChoicegroup(int x, int y, bool_t status, list_t * list, void (*fce_event) (void *)) -{ - widget_choicegroup_t *new; - widget_t *widget; - - new = malloc(sizeof(widget_choicegroup_t)); - new->time = 0; - new->status = status; - new->fce_event = fce_event; - new->list = list; - - widget = newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT, new); - - addList(new->list, widget); - - return widget; -} - -void drawWidgetChoicegroup(widget_t * widget) -{ - widget_choicegroup_t *p; - static image_t *g_choicegroup = NULL; - int x, y; - int offset; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); - - p = (widget_choicegroup_t *) widget->private_data; - - getMousePosition(&x, &y); - - if (g_choicegroup == NULL) { - g_choicegroup = addImageData("choice.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE); - } - - if (p->status == TRUE) { - offset = 0; - } else { - offset = WIDGET_CHOICEGROUP_WIDTH; - } - - drawImage(g_choicegroup, widget->x, widget->y, offset, 0, - WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); -} - -void setWidgetChoiceActive(widget_t * widget) -{ - widget_choicegroup_t *p; - int i; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); - - p = (widget_choicegroup_t *) widget->private_data; - - for (i = 0; i < p->list->count; i++) { - widget_t *this; - widget_choicegroup_t *thisChoice; - - this = (widget_t *) p->list->list[i]; - thisChoice = (widget_choicegroup_t *) this->private_data; - - if (widget == this) { - thisChoice->status = TRUE; - thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; - thisChoice->fce_event(p); - } else { - thisChoice->status = FALSE; - } - } -} - -bool_t getWidgetChoiceStatus(widget_t * widget) -{ - widget_choicegroup_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); - - p = (widget_choicegroup_t *) widget->private_data; - - return p->status; -} - -void setWidgetChoiceStatus(widget_t * widget, bool_t status) -{ - widget_choicegroup_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); - - p = (widget_choicegroup_t *) widget->private_data; - p->status = status; -} - -void eventWidgetChoicegroup(widget_t * widget) -{ - widget_choicegroup_t *p; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); - - p = (widget_choicegroup_t *) widget->private_data; - - if (p->time > 0) { - p->time--; - return; - } - - getMousePosition(&x, &y); - - if (x >= widget->x && x <= widget->x + WIDGET_CHOICEGROUP_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_CHOICEGROUP_HEIGHT && - isMouseClicked()) { - setWidgetChoiceActive(widget); - } -} - -void destroyWidgetChoicegroup(widget_t * widget) -{ - widget_choicegroup_t *p; - int index; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_CHOICE); - - p = (widget_choicegroup_t *) widget->private_data; - index = searchListItem(p->list, widget); - assert(index != -1); - delList(p->list, index); - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/choicegroup.h b/src/widget/choicegroup.h deleted file mode 100644 index a892d74..0000000 --- a/src/widget/choicegroup.h +++ /dev/null @@ -1,33 +0,0 @@ - -#ifndef WIDGET_CHOICEGROUP_H - -# define WIDGET_CHOICEGROUP_H - -# include "main.h" -# include "list.h" -# include "widget.h" - -# define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 - -# define WIDGET_CHOICEGROUP_WIDTH 25 -# define WIDGET_CHOICEGROUP_HEIGHT 25 - -typedef struct widget_choicegroup { - bool_t status; - int time; - void (*fce_event) (void *); - list_t *list; -} widget_choicegroup_t; - -extern widget_t *newWidgetChoicegroup(int x, int y, bool_t status, - list_t * list, - void (*fce_event) (void *)); - -extern void drawWidgetChoicegroup(widget_t * p); -extern void setWidgetChoiceActive(widget_t * widget); -extern bool_t getWidgetChoiceStatus(widget_t * widget); -extern void setWidgetChoiceStatus(widget_t * widget, bool_t status); -extern void eventWidgetChoicegroup(widget_t * p); -extern void destroyWidgetChoicegroup(widget_t * p); - -#endif diff --git a/src/widget/image.c b/src/widget/image.c deleted file mode 100644 index 2c9702f..0000000 --- a/src/widget/image.c +++ /dev/null @@ -1,52 +0,0 @@ - -#include -#include - -#include -#include "main.h" -#include "image.h" -#include "interface.h" -#include "font.h" - -#include "widget.h" -#include "image.h" - -widget_t *newWidgetImage(int x, int y, image_t * image) -{ - widget_image_t *new; - - new = malloc(sizeof(widget_image_t)); - new->image = image; - - return newWidget(WIDGET_TYPE_IMAGE, x, y, image->w, image->h, new); -} - -void drawWidgetImage(widget_t * widget) -{ - widget_image_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); - - p = (widget_image_t *) widget->private_data; - drawImage(p->image, widget->x, widget->y, 0, 0, p->image->w, p->image->h); -} - -void eventWidgetImage(widget_t * widget) -{ - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); -} - -void destroyWidgetImage(widget_t * widget) -{ - widget_image_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_IMAGE); - - p = (widget_image_t *) widget->private_data; - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/image.h b/src/widget/image.h deleted file mode 100644 index 61bf89a..0000000 --- a/src/widget/image.h +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef WIDGET_IMAGE_H - -# define WIDGET_IMAGE_H - -# include "main.h" -# include "interface.h" -# include "widget.h" - -typedef struct widget_image { - image_t *widget_image; -} widget_image_t; - -extern widget_t *newWidgetImage(int x, int y, image_t * image); -extern void drawWidgetImage(widget_t * p); -extern void eventWidgetImage(widget_t * p); -extern void destroyWidgetImage(widget_t * p); - -#endif diff --git a/src/widget/label.c b/src/widget/label.c deleted file mode 100644 index a2d0a48..0000000 --- a/src/widget/label.c +++ /dev/null @@ -1,64 +0,0 @@ - -#include -#include - -#include "main.h" -#include "interface.h" -#include "font.h" -#include "label.h" -#include "widget.h" - -widget_t *newWidgetLabel(char *text, int x, int y, int bind) -{ - widget_label_t *new; - - new = malloc(sizeof(widget_label_t)); - new->text = strdup(text); - new->bind = bind; - getTextSize(text, &(new->w), &(new->h)); - - return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new); -} - -void drawWidgetLabel(widget_t * widget) -{ - widget_label_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); - - p = (widget_label_t *) widget->private_data; - - switch (p->bind) { - case WIDGET_LABEL_RIGHT: - drawFont(p->text, widget->x + p->w, widget->y + p->h / 2, COLOR_WHITE); - break; - case WIDGET_LABEL_LEFT: - drawFont(p->text, widget->x, widget->y + widget->h / 2, COLOR_WHITE); - break; - case WIDGET_LABEL_CENTER: - drawFont(p->text, widget->x - p->w / 2, widget->y + p->h / 2, COLOR_WHITE); - break; - } -} - -void eventWidgetLabel(widget_t * widget) -{ - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); -} - -void destroyWidgetLabel(widget_t * widget) -{ - widget_label_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_LABEL); - - p = (widget_label_t *) widget->private_data; - - free(p->text); - free(p); - - destroyWidget(widget); -} diff --git a/src/widget/label.h b/src/widget/label.h deleted file mode 100644 index 743db7e..0000000 --- a/src/widget/label.h +++ /dev/null @@ -1,24 +0,0 @@ - -#ifndef WIDGET_LABEL_H - -# define WIDGET_LABEL_H - -# include "main.h" -# include "widget.h" - -typedef struct widget_label { - int w, h; - char *text; - int bind; -} widget_label_t; - -# define WIDGET_LABEL_RIGHT 1 -# define WIDGET_LABEL_LEFT 2 -# define WIDGET_LABEL_CENTER 3 - -extern widget_t *newWidgetLabel(char *text, int x, int y, int bind); -extern void drawWidgetLabel(widget_t * widget); -extern void eventWidgetLabel(widget_t * widget); -extern void destroyWidgetLabel(widget_t * widget); - -#endif diff --git a/src/widget/select.c b/src/widget/select.c deleted file mode 100644 index 5e290e2..0000000 --- a/src/widget/select.c +++ /dev/null @@ -1,150 +0,0 @@ - -#include -#include - -#include "main.h" -#include "interface.h" -#include "font.h" - -#include "widget.h" -#include "select.h" - -widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)) -{ - widget_select_t *new; - - new = malloc(sizeof(widget_select_t)); - new->select = -1; - new->fce_event = fce_event; - new->list = newList(); - - return newWidget(WIDGET_TYPE_SELECT, x, y, 0, 0, new); -} - -char *getWidgetSelectItem(widget_t * widget) -{ - widget_select_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - p = (widget_select_t *) widget->private_data; - - if (p->select == -1) { - return NULL; - } - - return (char *) p->list->list[p->select]; -} - -int getWidgetSelectIndex(widget_t * widget) -{ - widget_select_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - p = (widget_select_t *) widget->private_data; - - return p->select; -} - -void addToWidgetSelect(widget_t * widget, char *s) -{ - widget_select_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - p = (widget_select_t *) widget->private_data; - - addList(p->list, strdup(s)); -} - -void removeAllFromWidgetSelect(widget_t * widget) -{ - widget_select_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - p = (widget_select_t *) widget->private_data; - - while (p->list->count > 0) { - delListItem(p->list, 0, free); - } -} - -void drawWidgetSelect(widget_t * widget) -{ - widget_select_t *p; - int x, y, w, h; - int i; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - getMousePosition(&x, &y); - p = (widget_select_t *) widget->private_data; - - for (i = 0; i < p->list->count; i++) { - char *line; - - line = (char *) p->list->list[i]; - - getTextSize(line, &w, &h); - - if (x > widget->x && y > widget->y + i * 20 && - x < widget->x + w && y < widget->y + i * 20 + h) { - drawFont(line, widget->x, widget->y + i * 20, COLOR_YELLOW); - } else { - if (p->select == i) { - drawFont(line, widget->x, widget->y + i * 20, COLOR_RED); - } else { - drawFont(line, widget->x, widget->y + i * 20, COLOR_WHITE); - } - } - } -} - -void eventWidgetSelect(widget_t * widget) -{ - widget_select_t *p; - int x, y, w, h; - int i; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - p = (widget_select_t *) widget->private_data; - getMousePosition(&x, &y); - - for (i = 0; i < p->list->count; i++) { - char *line; - - line = (char *) p->list->list[i]; - - getTextSize(line, &w, &h); - - if (x > widget->x && y > widget->y + i * 20 && - x < widget->x + w && y < widget->y + i * 20 + h && - isMouseClicked()) { - p->select = i; - p->fce_event(p); - } - } -} - -void destroyWidgetSelect(widget_t * widget) -{ - widget_select_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_SELECT); - - p = (widget_select_t *) widget->private_data; - - destroyListItem(p->list, free); - free(p); - destroyWidget(widget); -} diff --git a/src/widget/select.h b/src/widget/select.h deleted file mode 100644 index 9d772cc..0000000 --- a/src/widget/select.h +++ /dev/null @@ -1,26 +0,0 @@ - -#ifndef WIDGET_SELECT_H - -# define WIDGET_SELECT_H - -# include "main.h" -# include "list.h" -# include "widget.h" - -typedef struct widget_select { - int w, h; - list_t *list; - int select; - void (*fce_event) (void *); -} widget_select_t; - -extern widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)); -extern char *getWidgetSelectItem(widget_t * widget); -extern int getWidgetSelectIndex(widget_t * widget); -extern void addToWidgetSelect(widget_t * widget, char *s); -extern void removeAllFromWidgetSelect(widget_t * widget); -extern void drawWidgetSelect(widget_t * widget); -extern void eventWidgetSelect(widget_t * widget); -extern void destroyWidgetSelect(widget_t * widget); - -#endif diff --git a/src/widget/textfield.c b/src/widget/textfield.c deleted file mode 100644 index edc74a8..0000000 --- a/src/widget/textfield.c +++ /dev/null @@ -1,444 +0,0 @@ - -#include -#include - -#include "main.h" -#include "interface.h" -#include "font.h" -#include "image.h" - -#include "widget.h" -#include "textfield.h" - -//#define ZZEEXX86_READKEY - -widget_t *newWidgetTextfield(char *text, int filter, int x, int y) -{ - widget_textfield_t *new; - - new = malloc(sizeof(widget_textfield_t)); - memset(new, 0, sizeof(widget_textfield_t)); - - strcpy(new->text, text); - new->time = 0; - new->timeBlick = 0; - new->atime = 0; - new->active = FALSE; - new->filter = filter; - getTextSize(text, &new->w, &new->h); - - return newWidget(WIDGET_TYPE_TEXTFILED, x, y, - WIDGET_TEXTFIELD_WIDTH, WIDGET_TEXTFIELD_HEIGHT, new); -} - -static void drawBackground(widget_t * widget) -{ - static image_t *g_textfield0 = NULL; - static image_t *g_textfield1 = NULL; - widget_textfield_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - - if (g_textfield0 == NULL) { - g_textfield0 = addImageData("textfield0.png", IMAGE_ALPHA, "textfiled0", IMAGE_GROUP_BASE); - } - - if (g_textfield1 == NULL) { - g_textfield1 = addImageData("textfield1.png", IMAGE_ALPHA, "textfiled1", IMAGE_GROUP_BASE); - } - - if (p->active) { - drawImage(g_textfield1, widget->x, widget->y, 0, 0, g_textfield1->w, g_textfield1->h); - } else { - drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, g_textfield0->h); - } -} - -static void drawText(widget_t * widget) -{ - char str[STR_SIZE]; - widget_textfield_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - - strcpy(str, p->text); - - if (p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR / 2 && p->active == TRUE) - { - //strcat(str, ">"); - strcat(str, "\f"); - } - - p->timeBlick++; - - if (p->timeBlick == WIDGET_TEXTFIELD_TIME_BLICK_CURSOR) { - p->timeBlick = 0; - } - - //drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+p->h/2, COLOR_WHITE); - //printf("p->y: %d\nheight: %d\n p->h: %d\n", p->y, WIDGET_TEXTFIELD_HEIGHT, p->h); - - drawFont(str, widget->x + WIDGET_TEXTFIELD_TEXT_OFFSET_X, - widget->y + WIDGET_TEXTFIELD_HEIGHT / 2 - p->h / 2, COLOR_WHITE); -} - -void drawWidgetTextfield(widget_t * widget) -{ - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - drawBackground(widget); - drawText(widget); -} - -void setWidgetTextFiledText(widget_t * widget, char *text) -{ - widget_textfield_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - - memset(p->text, 0, STR_SIZE); - strcpy(p->text, text); - getTextSize(text, &p->w, &p->h); -} - -char *getTextFromWidgetTextfield(widget_t * widget) -{ - widget_textfield_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - return p->text; -} - -static void checkText(widget_textfield_t * p) -{ - int len; - int i; - - //printf("check\n"); - - len = strlen(p->text); - - for (i = 0; i < len; i++) { - char c; - bool_t isDel; - - c = p->text[i]; - isDel = TRUE; - - switch (p->filter) { - case WIDGET_TEXTFIELD_FILTER_ALL: - isDel = FALSE; - break; - - case WIDGET_TEXTFIELD_FILTER_NUM: - if (c >= '0' && c <= '9') { - isDel = FALSE; - } - break; - - case WIDGET_TEXTFIELD_FILTER_ALPHANUM: - if ((c >= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c == '_' || c == '-')) { - isDel = FALSE; - } - break; - - case WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN: - if ((c >= '0' && c <= '9') || - (c == '.' || c == ':' || c == '-')) { - isDel = FALSE; - } - break; - - default: - assert(!_("Bad filter!")); - break; - } - - if (isDel) { - memmove(p->text + i, p->text + i + 1, len - i); - len = strlen(p->text); - i--; - } - } - - getTextSize(p->text, &p->w, &p->h); -} - -#ifdef ZZEEXX86_READKEY -static void readKey(widget_textfield_t * p) -{ - Uint8 *mapa; - int len; - int i; - - //printf("readKey w=%d\n", p->w); - - if (p->active == FALSE) { - return; - } - - if (p->atime < 100) - p->atime++; - - mapa = SDL_GetKeyState(NULL); - len = strlen(p->text); - - // mazanie posledneho klavesu - if (mapa[SDLK_BACKSPACE] == SDL_PRESSED) { - if (len > 0) { - p->time = 0; - p->text[len - 1] = '\0'; - getTextSize(p->text, &p->w, &p->h); - } - - return; - } - - if (p->w > WIDGET_TEXTFIELD_WIDTH - 40) { - return; - } - // klavesy abecedy - for (i = SDLK_SPACE /*SDLK_a */ ; i <= SDLK_z; i++) { - //if(widthtext, " "); - checkText(p); - return; - } - - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - if (p->text[len - 1] == *c) { - p->time++; - - if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { - if (p->atime < 3) - return; - } - } else - p->time = 0; - } - - p->atime = 0; - - strcat(p->text, c); - checkText(p); - - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || - mapa[SDLK_RSHIFT] == SDL_PRESSED) { - p->text[strlen(p->text) - 1] -= 32; - checkText(p); - return; - } - } - } - - // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice - for (i = SDLK_0; i <= SDLK_9; i++) { - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - const char *c = (const char *) SDL_GetKeyName(i); - - if (len) { - if (p->text[len - 1] == *c) { - p->time++; - - if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { - if (p->atime < 3) - return; - } - } else - p->time = 0; - } - - p->atime = 0; - - strcat(p->text, c); - checkText(p); - return; - } - } - - // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici - for (i = SDLK_KP0; i <= SDLK_KP9; i++) { - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - const char *c = (const char *) SDL_GetKeyName(i) + 1; - - if (len) { - if (p->text[len - 1] == *c) { - p->time++; - - if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { - if (p->atime < 3) - return; - } - } else - p->time = 0; - } - - p->atime = 0; - - strncat(p->text, c, 1); // napr. "[4]" - checkText(p); - return; - } - } -} -#endif - -#ifndef ZZEEXX86_READKEY -static void readKey(widget_textfield_t * p) -{ - Uint8 *mapa; - int len; - int i; - - const int len_shift_map = 20; - - char shift_map[] = { - '-', '_', - '=', '+', - '[', '{', - ']', '}', - ';', ':', - '/', '\"', - '\\', '|', - ',', '<', - '.', '>', - '/', '?' - }; - - if (p->active == FALSE) { - return; - } - - if (p->atime < 100) - p->atime++; - - mapa = SDL_GetKeyState(NULL); - len = strlen(p->text); - - for (i = SDLK_FIRST; i <= SDLK_F15; i++) { - if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { - char *name = (char *) SDL_GetKeyName(i); - char c = '\0'; - - if (name == NULL) - continue; - //printf("name %s\n", name); - - if (strlen(name) == 1) - c = name[0]; - - if (strlen(name) == 3) - c = name[1]; - - if (strcmp(name, "space") == 0) - c = ' '; - - - if (strcmp(name, "backspace") == 0 && len > 0) { - p->time = 0; - p->text[len - 1] = '\0'; - checkText(p); - return; - } - - if (c == '\0' || p->w > WIDGET_TEXTFIELD_WIDTH - 40) { - continue; - } - - if (len > 0) { - if (p->text[len - 1] == c) { - p->time++; - - if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { - if (p->atime < 3) - return; - } - } else { - p->time = 0; - } - } - - p->atime = 0; - - p->text[len] = c; - - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { - int i; - - for (i = 0; i < len_shift_map; i += 2) { - if (c == shift_map[i]) { - p->text[len] = shift_map[i + 1]; - } - } - - checkText(p); - return; - } - - if (mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { - p->text[len] -= 32; - } - - checkText(p); - return; - } - } -} -#endif - -void eventWidgetTextfield(widget_t * widget) -{ - widget_textfield_t *p; - int x, y; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - - getMousePosition(&x, &y); - - if (isMouseClicked()) { - if (x >= widget->x && x <= widget->x + WIDGET_TEXTFIELD_WIDTH && - y >= widget->y && y <= widget->y + WIDGET_TEXTFIELD_HEIGHT) { - p->active = TRUE; - } else { - p->active = FALSE; - } - } - - readKey(p); -} - -void destroyWidgetTextfield(widget_t * widget) -{ - widget_textfield_t *p; - - assert(widget != NULL); - assert(widget->type == WIDGET_TYPE_TEXTFILED); - - p = (widget_textfield_t *) widget->private_data; - - free(p); - destroyWidget(widget); -} diff --git a/src/widget/textfield.h b/src/widget/textfield.h deleted file mode 100644 index 7991deb..0000000 --- a/src/widget/textfield.h +++ /dev/null @@ -1,41 +0,0 @@ - -#ifndef WIDGET_TEXTFIELD_H - -# define WIDGET_TEXTFIELD_H - -# include "main.h" -# include "widget.h" - -# define WIDGET_TEXTFIELD_WIDTH 175 -# define WIDGET_TEXTFIELD_HEIGHT 36 - -# define WIDGET_TEXTFIELD_TEXT_OFFSET_X 10 - -# define WIDGET_TEXTFIELD_TIME_MULTIPLE 10 -# define WIDGET_TEXTFIELD_TIME_READ_KEY 2 -# define WIDGET_TEXTFIELD_TIME_BLICK_CURSOR 20 - -# define WIDGET_TEXTFIELD_FILTER_ALL 0 -# define WIDGET_TEXTFIELD_FILTER_NUM 2 -# define WIDGET_TEXTFIELD_FILTER_ALPHANUM 3 -# define WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN 4 - -typedef struct widget_textfield { - int w, h; - int canWrite; - int timeBlick; - int time; - int atime; - int filter; - char text[STR_SIZE]; - bool_t active; -} widget_textfield_t; - -extern widget_t *newWidgetTextfield(char *text, int filter, int x, int y); -extern void setWidgetTextFiledText(widget_t * widget, char *text); -extern char *getTextFromWidgetTextfield(widget_t * widget); -extern void drawWidgetTextfield(widget_t * widget); -extern void eventWidgetTextfield(widget_t * widget); -extern void destroyWidgetTextfield(widget_t * widget); - -#endif diff --git a/src/widget/widget.c b/src/widget/widget.c index f33e643..b72a463 100644 --- a/src/widget/widget.c +++ b/src/widget/widget.c @@ -5,7 +5,7 @@ #include "main.h" #include "widget.h" -#include "label.h" +#include "widget_label.h" widget_t *newWidget(int type, int x, int y, int w, int h, void *private_data) { diff --git a/src/widget/widget_button.c b/src/widget/widget_button.c new file mode 100644 index 0000000..c2afcad --- /dev/null +++ b/src/widget/widget_button.c @@ -0,0 +1,103 @@ + +#include +#include + +#include "main.h" + +#include "interface.h" +#include "image.h" +#include "font.h" + +#include "widget.h" +#include "widget_button.h" + +widget_t *newWidgetButton(char *text, int x, int y, void (*fce_event) (void *)) +{ + widget_button_t *new; + + new = malloc(sizeof(widget_button_t)); + new->text = strdup(text); + new->fce_event = fce_event; + getTextSize(text, &(new->w), &(new->h)); + + return newWidget(WIDGET_TYPE_BUTTON, x, y, + WIDGET_BUTTON_WIDTH, WIDGET_BUTTON_HEIGHT, new); +} + +void drawWidgetButton(widget_t * widget) +{ + widget_button_t *p; + static image_t *g_button0 = NULL; + static image_t *g_button1 = NULL; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTON); + + p = (widget_button_t *) widget->private_data; + getMousePosition(&x, &y); + + if (g_button0 == NULL) { + g_button0 = addImageData("button0.png", IMAGE_ALPHA, "button0", IMAGE_GROUP_BASE); + } + + if (g_button1 == NULL) { + g_button1 = + addImageData("button1.png", IMAGE_ALPHA, "button1", IMAGE_GROUP_BASE); + } + + if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT) { + drawImage(g_button1, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h); + } else { + drawImage(g_button0, widget->x, widget->y, 0, 0, g_button0->w, g_button0->h); + } + + //drawFont(p->text, p->x+WIDGET_BUTTON_WIDTH/2-p->w/2, p->y+p->h/2, COLOR_WHITE); + drawFont(p->text, widget->x + WIDGET_BUTTON_WIDTH / 2 - p->w / 2, + widget->y + WIDGET_BUTTON_HEIGHT / 2 - p->h / 2, COLOR_WHITE); +} + +void eventWidgetButton(widget_t * widget) +{ + widget_button_t *p; + static int time = 0; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTON); + + p = (widget_button_t *) widget->private_data; + + if (time > 0) { + time--; + return; + } + + getMousePosition(&x, &y); + + if (x >= widget->x && x <= widget->x + WIDGET_BUTTON_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_BUTTON_HEIGHT && + isMouseClicked()) { + time = WIDGET_BUTTON_TIME; + + DEBUG_MSG(_("Event caught\n")); + + p->fce_event(widget); + } +} + +void destroyWidgetButton(widget_t * widget) +{ + widget_button_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTON); + + p = (widget_button_t *) widget->private_data; + + free(p->text); + free(p); + + destroyWidget(widget); +} diff --git a/src/widget/widget_button.h b/src/widget/widget_button.h new file mode 100644 index 0000000..ac238be --- /dev/null +++ b/src/widget/widget_button.h @@ -0,0 +1,26 @@ + +#ifndef WIDGET_BUTTON_H + +# define WIDGET_BUTTON_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_BUTTON_TIME 10 + +# define WIDGET_BUTTON_WIDTH 125 +# define WIDGET_BUTTON_HEIGHT 36 + +typedef struct widget_button { + char *text; + int w, h; + void (*fce_event) (void *); +} widget_button_t; + +extern widget_t *newWidgetButton(char *text, int x, int y, + void (*fce_event) (void *)); +extern void drawWidgetButton(widget_t * widget); +extern void eventWidgetButton(widget_t * widget); +extern void destroyWidgetButton(widget_t * widget); + +#endif diff --git a/src/widget/widget_buttonimage.c b/src/widget/widget_buttonimage.c new file mode 100644 index 0000000..dd20e62 --- /dev/null +++ b/src/widget/widget_buttonimage.c @@ -0,0 +1,86 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" +#include "image.h" + +#include "widget.h" +#include "widget_buttonimage.h" + +widget_t *newWidgetButtonimage(image_t * image, int x, int y, void (*fce_event) (void *)) +{ + widget_buttonimage_t *new; + + new = malloc(sizeof(widget_buttonimage_t)); + new->image = image; + new->w = image->w / 2; + new->h = image->h; + new->active = 0; + new->fce_event = fce_event; + + return newWidget(WIDGET_TYPE_BUTTONIMAGE, x, y, new->w, new->h, new); +} + +void setWidgetButtonimageActive(widget_t * widget, bool_t active) +{ + widget_buttonimage_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + + p = (widget_buttonimage_t *) widget->private_data; + p->active = active; +} + +void drawWidgetButtonimage(widget_t * widget) +{ + widget_buttonimage_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + + p = (widget_buttonimage_t *) widget->private_data; + drawImage(p->image, widget->x, widget->y, p->active * p->w, 0, p->w, p->h); +} + +void eventWidgetButtonimage(widget_t * widget) +{ + widget_buttonimage_t *p; + static int time = 0; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + + p = (widget_buttonimage_t *) widget->private_data; + + if (time > 0) { + time--; + return; + } + + getMousePosition(&x, &y); + + if (x >= widget->x && x <= widget->x + p->w && + y >= widget->y && y <= widget->y + p->h && isMouseClicked()) { + time = WIDGET_BUTTONIMAGE_TIME; + p->active = 1; + p->fce_event(widget); + } +} + +void destroyWidgetButtonimage(widget_t * widget) +{ + widget_buttonimage_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_BUTTONIMAGE); + + p = (widget_buttonimage_t *) widget->private_data; + + free(p); + destroyWidget(widget); +} diff --git a/src/widget/widget_buttonimage.h b/src/widget/widget_buttonimage.h new file mode 100644 index 0000000..5a0ab7c --- /dev/null +++ b/src/widget/widget_buttonimage.h @@ -0,0 +1,27 @@ + +#ifndef WIDGET_BUTTONIMAGE_H + +# include "main.h" + +# define WIDGET_BUTTONIMAGE_H + +# define WIDGET_BUTTONIMAGE_TIME 10 + +# include "widget.h" + +typedef struct widget_buttonimageimage { + int w, h; + int active; + image_t *image; + void (*fce_event) (void *); +} widget_buttonimage_t; + +extern widget_t *newWidgetButtonimage(image_t * image, int x, int y, + void (*fce_event) (void *)); + +extern void setWidgetButtonimageActive(widget_t * widget, bool_t active); +extern void drawWidgetButtonimage(widget_t * widget); +extern void eventWidgetButtonimage(widget_t * widget); +extern void destroyWidgetButtonimage(widget_t * widget); + +#endif diff --git a/src/widget/widget_catchkey.c b/src/widget/widget_catchkey.c new file mode 100644 index 0000000..b213890 --- /dev/null +++ b/src/widget/widget_catchkey.c @@ -0,0 +1,140 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" + +#include "widget.h" +#include "widget_catchkey.h" + +widget_t *newWidgetCatchkey(int key, int x, int y, void *event) +{ + widget_catchkey_t *new; + + new = malloc(sizeof(widget_catchkey_t)); + new->key = key; + new->fce_event = event; + new->active = FALSE; + + return newWidget(WIDGET_TYPE_CATCHKEY, x, y, WIDGET_CATCHKEY_WIDTH, WIDGET_CATCHKEY_HEIGHT, new); +} + +int getWidgetCatchKey(widget_t * widget) +{ + widget_catchkey_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); + + p = (widget_catchkey_t *) widget->private_data; + + return p->key; +} + +void setWidgetCatchKey(widget_t * widget, int key) +{ + widget_catchkey_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); + + p = (widget_catchkey_t *) widget->private_data; + + p->key = key; +} + +void drawWidgetCatchkey(widget_t * widget) +{ + widget_catchkey_t *p; + char *name; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); + + p = (widget_catchkey_t *) widget->private_data; + name = NULL; + + if (p->key != WIDGET_CATCHKEY_NOKEY) { + name = (char *) SDL_GetKeyName(p->key); + } + + if (name == NULL) { + name = "no key"; + } + + if (p->active) { + drawFont(name, widget->x, widget->y, COLOR_RED); + } else { + drawFont(name, widget->x, widget->y, COLOR_WHITE); + } +} + +static int getPessAnyKey() +{ + Uint8 *mapa; + int i; + + mapa = SDL_GetKeyState(NULL); + + for (i = SDLK_FIRST; i <= SDLK_COMPOSE; i++) { + if (i == SDLK_NUMLOCK || // black key + i == SDLK_CAPSLOCK || + i == SDLK_SCROLLOCK) { + continue; + } + + if (mapa[i] == SDL_PRESSED) { + return i; + } + } + + return WIDGET_CATCHKEY_NOKEY; +} + +void eventWidgetCatchkey(widget_t * widget) +{ + widget_catchkey_t *p; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); + + p = (widget_catchkey_t *) widget->private_data; + + getMousePosition(&x, &y); + + if (isMouseClicked()) { + if (x >= widget->x && x <= widget->x + WIDGET_CATCHKEY_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_CATCHKEY_HEIGHT) { + p->active = TRUE; + } else { + p->active = FALSE; + } + } + + if (p->active == TRUE) { + int key; + + key = getPessAnyKey(); + + if (key != WIDGET_CATCHKEY_NOKEY) { + p->key = key; + p->fce_event(widget); + } + } +} + +void destroyWidgetCatchkey(widget_t * widget) +{ + widget_catchkey_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CATCHKEY); + + p = (widget_catchkey_t *) widget->private_data; + + free(p); + destroyWidget(widget); +} diff --git a/src/widget/widget_catchkey.h b/src/widget/widget_catchkey.h new file mode 100644 index 0000000..106bc92 --- /dev/null +++ b/src/widget/widget_catchkey.h @@ -0,0 +1,27 @@ +#ifndef WIDGET_CATCHKEY_H + +# define WIDGET_CATCHKEY_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_CATCHKEY_WIDTH 110 +# define WIDGET_CATCHKEY_HEIGHT 12 + +# define WIDGET_CATCHKEY_NOKEY -1 + +typedef struct widget_catchkey_struct { + int w, h; + int key; + bool_t active; + void (*fce_event) (void *p); +} widget_catchkey_t; + +extern widget_t *newWidgetCatchkey(int key, int x, int y, void *event); +extern int getWidgetCatchKey(widget_t * p); +extern void setWidgetCatchKey(widget_t * p, int key); +extern void drawWidgetCatchkey(widget_t * p); +extern void eventWidgetCatchkey(widget_t * p); +extern void destroyWidgetCatchkey(widget_t * p); + +#endif diff --git a/src/widget/widget_check.c b/src/widget/widget_check.c new file mode 100644 index 0000000..e574211 --- /dev/null +++ b/src/widget/widget_check.c @@ -0,0 +1,118 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "image.h" + +#include "widget.h" +#include "widget_check.h" + +widget_t *newWidgetCheck(int x, int y, bool_t status, void (*fce_event) (void *)) +{ + widget_check_t *new; + + new = malloc(sizeof(widget_check_t)); + new->time = 0; + new->status = status; + new->fce_event = fce_event; + + return newWidget(WIDGET_TYPE_CHECK, x, y, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT, new); +} + +void drawWidgetCheck(widget_t * widget) +{ + widget_check_t *p; + static image_t *g_check = NULL; + int x, y; + int offset; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); + + p = (widget_check_t *) widget->private_data; + + getMousePosition(&x, &y); + + if (g_check == NULL) { + g_check = addImageData("check.png", IMAGE_ALPHA, "check", IMAGE_GROUP_BASE); + } + + if (p->status == TRUE) { + offset = 0; + } else { + offset = WIDGET_CHECK_WIDTH; + } + + drawImage(g_check, widget->x, widget->y, offset, 0, WIDGET_CHECK_WIDTH, WIDGET_CHECK_HEIGHT); +} + +void eventWidgetCheck(widget_t * widget) +{ + widget_check_t *p; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); + + p = (widget_check_t *) widget->private_data; + + if (p->time > 0) { + p->time--; + return; + } + + getMousePosition(&x, &y); + + if (x >= widget->x && x <= widget->x + WIDGET_CHECK_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_CHECK_HEIGHT && + isMouseClicked()) { + if (p->status == TRUE) { + p->status = FALSE; + p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; + } else { + p->status = TRUE; + p->time = WIDGET_CHECK_TIME_SWITCH_STATUS; + } + + if (p->fce_event != NULL) { + p->fce_event(widget); + } + } +} + +bool_t getWidgetCheckStatus(widget_t * widget) +{ + widget_check_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); + + p = (widget_check_t *) widget->private_data; + + return p->status; +} + +void setWidgetCheckStatus(widget_t * widget, bool_t status) +{ + widget_check_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); + + p = (widget_check_t *) widget->private_data; + p->status = status; +} + +void destroyWidgetCheck(widget_t * widget) +{ + widget_check_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHECK); + + p = (widget_check_t *) widget->private_data; + free(p); + destroyWidget(widget); +} diff --git a/src/widget/widget_check.h b/src/widget/widget_check.h new file mode 100644 index 0000000..007e82c --- /dev/null +++ b/src/widget/widget_check.h @@ -0,0 +1,28 @@ + +#ifndef WIDGET_CHECK_H + +# define WIDGET_CHECK_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_CHECK_TIME_SWITCH_STATUS 5 + +# define WIDGET_CHECK_WIDTH 25 +# define WIDGET_CHECK_HEIGHT 25 + +typedef struct widget_check { + bool_t status; + int time; + void (*fce_event) (void *); +} widget_check_t; + +extern widget_t *newWidgetCheck(int x, int y, bool_t status, + void (*fce_event) (void *)); +extern void drawWidgetCheck(widget_t * widget); +extern void eventWidgetCheck(widget_t * widget); +extern bool_t getWidgetCheckStatus(widget_t * widget); +extern void setWidgetCheckStatus(widget_t * widget, bool_t status); +extern void destroyWidgetCheck(widget_t * widget); + +#endif diff --git a/src/widget/widget_choicegroup.c b/src/widget/widget_choicegroup.c new file mode 100644 index 0000000..1045f81 --- /dev/null +++ b/src/widget/widget_choicegroup.c @@ -0,0 +1,147 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "image.h" + +#include "widget.h" +#include "widget_choicegroup.h" + +widget_t *newWidgetChoicegroup(int x, int y, bool_t status, list_t * list, void (*fce_event) (void *)) +{ + widget_choicegroup_t *new; + widget_t *widget; + + new = malloc(sizeof(widget_choicegroup_t)); + new->time = 0; + new->status = status; + new->fce_event = fce_event; + new->list = list; + + widget = newWidget(WIDGET_TYPE_CHOICE, x, y, WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT, new); + + addList(new->list, widget); + + return widget; +} + +void drawWidgetChoicegroup(widget_t * widget) +{ + widget_choicegroup_t *p; + static image_t *g_choicegroup = NULL; + int x, y; + int offset; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); + + p = (widget_choicegroup_t *) widget->private_data; + + getMousePosition(&x, &y); + + if (g_choicegroup == NULL) { + g_choicegroup = addImageData("choice.png", IMAGE_ALPHA, "choicegroup", IMAGE_GROUP_BASE); + } + + if (p->status == TRUE) { + offset = 0; + } else { + offset = WIDGET_CHOICEGROUP_WIDTH; + } + + drawImage(g_choicegroup, widget->x, widget->y, offset, 0, + WIDGET_CHOICEGROUP_WIDTH, WIDGET_CHOICEGROUP_HEIGHT); +} + +void setWidgetChoiceActive(widget_t * widget) +{ + widget_choicegroup_t *p; + int i; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); + + p = (widget_choicegroup_t *) widget->private_data; + + for (i = 0; i < p->list->count; i++) { + widget_t *this; + widget_choicegroup_t *thisChoice; + + this = (widget_t *) p->list->list[i]; + thisChoice = (widget_choicegroup_t *) this->private_data; + + if (widget == this) { + thisChoice->status = TRUE; + thisChoice->time = WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS; + thisChoice->fce_event(p); + } else { + thisChoice->status = FALSE; + } + } +} + +bool_t getWidgetChoiceStatus(widget_t * widget) +{ + widget_choicegroup_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); + + p = (widget_choicegroup_t *) widget->private_data; + + return p->status; +} + +void setWidgetChoiceStatus(widget_t * widget, bool_t status) +{ + widget_choicegroup_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); + + p = (widget_choicegroup_t *) widget->private_data; + p->status = status; +} + +void eventWidgetChoicegroup(widget_t * widget) +{ + widget_choicegroup_t *p; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); + + p = (widget_choicegroup_t *) widget->private_data; + + if (p->time > 0) { + p->time--; + return; + } + + getMousePosition(&x, &y); + + if (x >= widget->x && x <= widget->x + WIDGET_CHOICEGROUP_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_CHOICEGROUP_HEIGHT && + isMouseClicked()) { + setWidgetChoiceActive(widget); + } +} + +void destroyWidgetChoicegroup(widget_t * widget) +{ + widget_choicegroup_t *p; + int index; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_CHOICE); + + p = (widget_choicegroup_t *) widget->private_data; + index = searchListItem(p->list, widget); + assert(index != -1); + delList(p->list, index); + + free(p); + destroyWidget(widget); +} diff --git a/src/widget/widget_choicegroup.h b/src/widget/widget_choicegroup.h new file mode 100644 index 0000000..a892d74 --- /dev/null +++ b/src/widget/widget_choicegroup.h @@ -0,0 +1,33 @@ + +#ifndef WIDGET_CHOICEGROUP_H + +# define WIDGET_CHOICEGROUP_H + +# include "main.h" +# include "list.h" +# include "widget.h" + +# define WIDGET_CHOICEGROUP_TIME_SWITCH_STATUS 5 + +# define WIDGET_CHOICEGROUP_WIDTH 25 +# define WIDGET_CHOICEGROUP_HEIGHT 25 + +typedef struct widget_choicegroup { + bool_t status; + int time; + void (*fce_event) (void *); + list_t *list; +} widget_choicegroup_t; + +extern widget_t *newWidgetChoicegroup(int x, int y, bool_t status, + list_t * list, + void (*fce_event) (void *)); + +extern void drawWidgetChoicegroup(widget_t * p); +extern void setWidgetChoiceActive(widget_t * widget); +extern bool_t getWidgetChoiceStatus(widget_t * widget); +extern void setWidgetChoiceStatus(widget_t * widget, bool_t status); +extern void eventWidgetChoicegroup(widget_t * p); +extern void destroyWidgetChoicegroup(widget_t * p); + +#endif diff --git a/src/widget/widget_image.c b/src/widget/widget_image.c new file mode 100644 index 0000000..ad49f9e --- /dev/null +++ b/src/widget/widget_image.c @@ -0,0 +1,52 @@ + +#include +#include + +#include +#include "main.h" +#include "image.h" +#include "interface.h" +#include "font.h" + +#include "widget.h" +#include "widget_image.h" + +widget_t *newWidgetImage(int x, int y, image_t * image) +{ + widget_image_t *new; + + new = malloc(sizeof(widget_image_t)); + new->image = image; + + return newWidget(WIDGET_TYPE_IMAGE, x, y, image->w, image->h, new); +} + +void drawWidgetImage(widget_t * widget) +{ + widget_image_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_IMAGE); + + p = (widget_image_t *) widget->private_data; + drawImage(p->image, widget->x, widget->y, 0, 0, p->image->w, p->image->h); +} + +void eventWidgetImage(widget_t * widget) +{ + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_IMAGE); +} + +void destroyWidgetImage(widget_t * widget) +{ + widget_image_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_IMAGE); + + p = (widget_image_t *) widget->private_data; + + free(p); + destroyWidget(widget); +} diff --git a/src/widget/widget_image.h b/src/widget/widget_image.h new file mode 100644 index 0000000..081fbda --- /dev/null +++ b/src/widget/widget_image.h @@ -0,0 +1,19 @@ + +#ifndef WIDGET_IMAGE_H + +# define WIDGET_IMAGE_H + +# include "main.h" +# include "interface.h" +# include "widget.h" + +typedef struct widget_image { + image_t *image; +} widget_image_t; + +extern widget_t *newWidgetImage(int x, int y, image_t * image); +extern void drawWidgetImage(widget_t * p); +extern void eventWidgetImage(widget_t * p); +extern void destroyWidgetImage(widget_t * p); + +#endif diff --git a/src/widget/widget_label.c b/src/widget/widget_label.c new file mode 100644 index 0000000..e3c907c --- /dev/null +++ b/src/widget/widget_label.c @@ -0,0 +1,64 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" +#include "widget_label.h" +#include "widget.h" + +widget_t *newWidgetLabel(char *text, int x, int y, int bind) +{ + widget_label_t *new; + + new = malloc(sizeof(widget_label_t)); + new->text = strdup(text); + new->bind = bind; + getTextSize(text, &(new->w), &(new->h)); + + return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new); +} + +void drawWidgetLabel(widget_t * widget) +{ + widget_label_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_LABEL); + + p = (widget_label_t *) widget->private_data; + + switch (p->bind) { + case WIDGET_LABEL_RIGHT: + drawFont(p->text, widget->x + p->w, widget->y + p->h / 2, COLOR_WHITE); + break; + case WIDGET_LABEL_LEFT: + drawFont(p->text, widget->x, widget->y + widget->h / 2, COLOR_WHITE); + break; + case WIDGET_LABEL_CENTER: + drawFont(p->text, widget->x - p->w / 2, widget->y + p->h / 2, COLOR_WHITE); + break; + } +} + +void eventWidgetLabel(widget_t * widget) +{ + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_LABEL); +} + +void destroyWidgetLabel(widget_t * widget) +{ + widget_label_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_LABEL); + + p = (widget_label_t *) widget->private_data; + + free(p->text); + free(p); + + destroyWidget(widget); +} diff --git a/src/widget/widget_label.h b/src/widget/widget_label.h new file mode 100644 index 0000000..743db7e --- /dev/null +++ b/src/widget/widget_label.h @@ -0,0 +1,24 @@ + +#ifndef WIDGET_LABEL_H + +# define WIDGET_LABEL_H + +# include "main.h" +# include "widget.h" + +typedef struct widget_label { + int w, h; + char *text; + int bind; +} widget_label_t; + +# define WIDGET_LABEL_RIGHT 1 +# define WIDGET_LABEL_LEFT 2 +# define WIDGET_LABEL_CENTER 3 + +extern widget_t *newWidgetLabel(char *text, int x, int y, int bind); +extern void drawWidgetLabel(widget_t * widget); +extern void eventWidgetLabel(widget_t * widget); +extern void destroyWidgetLabel(widget_t * widget); + +#endif diff --git a/src/widget/widget_select.c b/src/widget/widget_select.c new file mode 100644 index 0000000..f53e583 --- /dev/null +++ b/src/widget/widget_select.c @@ -0,0 +1,150 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" + +#include "widget.h" +#include "widget_select.h" + +widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)) +{ + widget_select_t *new; + + new = malloc(sizeof(widget_select_t)); + new->select = -1; + new->fce_event = fce_event; + new->list = newList(); + + return newWidget(WIDGET_TYPE_SELECT, x, y, 0, 0, new); +} + +char *getWidgetSelectItem(widget_t * widget) +{ + widget_select_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); + + p = (widget_select_t *) widget->private_data; + + if (p->select == -1) { + return NULL; + } + + return (char *) p->list->list[p->select]; +} + +int getWidgetSelectIndex(widget_t * widget) +{ + widget_select_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); + + p = (widget_select_t *) widget->private_data; + + return p->select; +} + +void addToWidgetSelect(widget_t * widget, char *s) +{ + widget_select_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); + + p = (widget_select_t *) widget->private_data; + + addList(p->list, strdup(s)); +} + +void removeAllFromWidgetSelect(widget_t * widget) +{ + widget_select_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); + + p = (widget_select_t *) widget->private_data; + + while (p->list->count > 0) { + delListItem(p->list, 0, free); + } +} + +void drawWidgetSelect(widget_t * widget) +{ + widget_select_t *p; + int x, y, w, h; + int i; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); + + getMousePosition(&x, &y); + p = (widget_select_t *) widget->private_data; + + for (i = 0; i < p->list->count; i++) { + char *line; + + line = (char *) p->list->list[i]; + + getTextSize(line, &w, &h); + + if (x > widget->x && y > widget->y + i * 20 && + x < widget->x + w && y < widget->y + i * 20 + h) { + drawFont(line, widget->x, widget->y + i * 20, COLOR_YELLOW); + } else { + if (p->select == i) { + drawFont(line, widget->x, widget->y + i * 20, COLOR_RED); + } else { + drawFont(line, widget->x, widget->y + i * 20, COLOR_WHITE); + } + } + } +} + +void eventWidgetSelect(widget_t * widget) +{ + widget_select_t *p; + int x, y, w, h; + int i; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); + + p = (widget_select_t *) widget->private_data; + getMousePosition(&x, &y); + + for (i = 0; i < p->list->count; i++) { + char *line; + + line = (char *) p->list->list[i]; + + getTextSize(line, &w, &h); + + if (x > widget->x && y > widget->y + i * 20 && + x < widget->x + w && y < widget->y + i * 20 + h && + isMouseClicked()) { + p->select = i; + p->fce_event(p); + } + } +} + +void destroyWidgetSelect(widget_t * widget) +{ + widget_select_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_SELECT); + + p = (widget_select_t *) widget->private_data; + + destroyListItem(p->list, free); + free(p); + destroyWidget(widget); +} diff --git a/src/widget/widget_select.h b/src/widget/widget_select.h new file mode 100644 index 0000000..9d772cc --- /dev/null +++ b/src/widget/widget_select.h @@ -0,0 +1,26 @@ + +#ifndef WIDGET_SELECT_H + +# define WIDGET_SELECT_H + +# include "main.h" +# include "list.h" +# include "widget.h" + +typedef struct widget_select { + int w, h; + list_t *list; + int select; + void (*fce_event) (void *); +} widget_select_t; + +extern widget_t *newWidgetSelect(int x, int y, void (*fce_event) (void *)); +extern char *getWidgetSelectItem(widget_t * widget); +extern int getWidgetSelectIndex(widget_t * widget); +extern void addToWidgetSelect(widget_t * widget, char *s); +extern void removeAllFromWidgetSelect(widget_t * widget); +extern void drawWidgetSelect(widget_t * widget); +extern void eventWidgetSelect(widget_t * widget); +extern void destroyWidgetSelect(widget_t * widget); + +#endif diff --git a/src/widget/widget_textfield.c b/src/widget/widget_textfield.c new file mode 100644 index 0000000..6a8824a --- /dev/null +++ b/src/widget/widget_textfield.c @@ -0,0 +1,444 @@ + +#include +#include + +#include "main.h" +#include "interface.h" +#include "font.h" +#include "image.h" + +#include "widget.h" +#include "widget_textfield.h" + +//#define ZZEEXX86_READKEY + +widget_t *newWidgetTextfield(char *text, int filter, int x, int y) +{ + widget_textfield_t *new; + + new = malloc(sizeof(widget_textfield_t)); + memset(new, 0, sizeof(widget_textfield_t)); + + strcpy(new->text, text); + new->time = 0; + new->timeBlick = 0; + new->atime = 0; + new->active = FALSE; + new->filter = filter; + getTextSize(text, &new->w, &new->h); + + return newWidget(WIDGET_TYPE_TEXTFILED, x, y, + WIDGET_TEXTFIELD_WIDTH, WIDGET_TEXTFIELD_HEIGHT, new); +} + +static void drawBackground(widget_t * widget) +{ + static image_t *g_textfield0 = NULL; + static image_t *g_textfield1 = NULL; + widget_textfield_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); + + p = (widget_textfield_t *) widget->private_data; + + if (g_textfield0 == NULL) { + g_textfield0 = addImageData("textfield0.png", IMAGE_ALPHA, "textfiled0", IMAGE_GROUP_BASE); + } + + if (g_textfield1 == NULL) { + g_textfield1 = addImageData("textfield1.png", IMAGE_ALPHA, "textfiled1", IMAGE_GROUP_BASE); + } + + if (p->active) { + drawImage(g_textfield1, widget->x, widget->y, 0, 0, g_textfield1->w, g_textfield1->h); + } else { + drawImage(g_textfield0, widget->x, widget->y, 0, 0, g_textfield0->w, g_textfield0->h); + } +} + +static void drawText(widget_t * widget) +{ + char str[STR_SIZE]; + widget_textfield_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); + + p = (widget_textfield_t *) widget->private_data; + + strcpy(str, p->text); + + if (p->timeBlick > WIDGET_TEXTFIELD_TIME_BLICK_CURSOR / 2 && p->active == TRUE) + { + //strcat(str, ">"); + strcat(str, "\f"); + } + + p->timeBlick++; + + if (p->timeBlick == WIDGET_TEXTFIELD_TIME_BLICK_CURSOR) { + p->timeBlick = 0; + } + + //drawFont(str, p->x+WIDGET_TEXTFIELD_TEXT_OFFSET_X, p->y+p->h/2, COLOR_WHITE); + //printf("p->y: %d\nheight: %d\n p->h: %d\n", p->y, WIDGET_TEXTFIELD_HEIGHT, p->h); + + drawFont(str, widget->x + WIDGET_TEXTFIELD_TEXT_OFFSET_X, + widget->y + WIDGET_TEXTFIELD_HEIGHT / 2 - p->h / 2, COLOR_WHITE); +} + +void drawWidgetTextfield(widget_t * widget) +{ + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); + + drawBackground(widget); + drawText(widget); +} + +void setWidgetTextFiledText(widget_t * widget, char *text) +{ + widget_textfield_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); + + p = (widget_textfield_t *) widget->private_data; + + memset(p->text, 0, STR_SIZE); + strcpy(p->text, text); + getTextSize(text, &p->w, &p->h); +} + +char *getTextFromWidgetTextfield(widget_t * widget) +{ + widget_textfield_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); + + p = (widget_textfield_t *) widget->private_data; + return p->text; +} + +static void checkText(widget_textfield_t * p) +{ + int len; + int i; + + //printf("check\n"); + + len = strlen(p->text); + + for (i = 0; i < len; i++) { + char c; + bool_t isDel; + + c = p->text[i]; + isDel = TRUE; + + switch (p->filter) { + case WIDGET_TEXTFIELD_FILTER_ALL: + isDel = FALSE; + break; + + case WIDGET_TEXTFIELD_FILTER_NUM: + if (c >= '0' && c <= '9') { + isDel = FALSE; + } + break; + + case WIDGET_TEXTFIELD_FILTER_ALPHANUM: + if ((c >= '0' && c <= '9') || + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (c == '_' || c == '-')) { + isDel = FALSE; + } + break; + + case WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN: + if ((c >= '0' && c <= '9') || + (c == '.' || c == ':' || c == '-')) { + isDel = FALSE; + } + break; + + default: + assert(!_("Bad filter!")); + break; + } + + if (isDel) { + memmove(p->text + i, p->text + i + 1, len - i); + len = strlen(p->text); + i--; + } + } + + getTextSize(p->text, &p->w, &p->h); +} + +#ifdef ZZEEXX86_READKEY +static void readKey(widget_textfield_t * p) +{ + Uint8 *mapa; + int len; + int i; + + //printf("readKey w=%d\n", p->w); + + if (p->active == FALSE) { + return; + } + + if (p->atime < 100) + p->atime++; + + mapa = SDL_GetKeyState(NULL); + len = strlen(p->text); + + // mazanie posledneho klavesu + if (mapa[SDLK_BACKSPACE] == SDL_PRESSED) { + if (len > 0) { + p->time = 0; + p->text[len - 1] = '\0'; + getTextSize(p->text, &p->w, &p->h); + } + + return; + } + + if (p->w > WIDGET_TEXTFIELD_WIDTH - 40) { + return; + } + // klavesy abecedy + for (i = SDLK_SPACE /*SDLK_a */ ; i <= SDLK_z; i++) { + //if(widthtext, " "); + checkText(p); + return; + } + + const char *c = (const char *) SDL_GetKeyName(i); + + if (len) { + if (p->text[len - 1] == *c) { + p->time++; + + if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { + if (p->atime < 3) + return; + } + } else + p->time = 0; + } + + p->atime = 0; + + strcat(p->text, c); + checkText(p); + + if (mapa[SDLK_LSHIFT] == SDL_PRESSED || + mapa[SDLK_RSHIFT] == SDL_PRESSED) { + p->text[strlen(p->text) - 1] -= 32; + checkText(p); + return; + } + } + } + + // aby ve jmene bulanka fungovaly take cislice alfanumericke klavesnice + for (i = SDLK_0; i <= SDLK_9; i++) { + if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { + const char *c = (const char *) SDL_GetKeyName(i); + + if (len) { + if (p->text[len - 1] == *c) { + p->time++; + + if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { + if (p->atime < 3) + return; + } + } else + p->time = 0; + } + + p->atime = 0; + + strcat(p->text, c); + checkText(p); + return; + } + } + + // aby ve jmene bulanka fungovaly take cislice napsane na numericke klavesnici + for (i = SDLK_KP0; i <= SDLK_KP9; i++) { + if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { + const char *c = (const char *) SDL_GetKeyName(i) + 1; + + if (len) { + if (p->text[len - 1] == *c) { + p->time++; + + if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { + if (p->atime < 3) + return; + } + } else + p->time = 0; + } + + p->atime = 0; + + strncat(p->text, c, 1); // napr. "[4]" + checkText(p); + return; + } + } +} +#endif + +#ifndef ZZEEXX86_READKEY +static void readKey(widget_textfield_t * p) +{ + Uint8 *mapa; + int len; + int i; + + const int len_shift_map = 20; + + char shift_map[] = { + '-', '_', + '=', '+', + '[', '{', + ']', '}', + ';', ':', + '/', '\"', + '\\', '|', + ',', '<', + '.', '>', + '/', '?' + }; + + if (p->active == FALSE) { + return; + } + + if (p->atime < 100) + p->atime++; + + mapa = SDL_GetKeyState(NULL); + len = strlen(p->text); + + for (i = SDLK_FIRST; i <= SDLK_F15; i++) { + if (mapa[i] == SDL_PRESSED && len < STR_SIZE) { + char *name = (char *) SDL_GetKeyName(i); + char c = '\0'; + + if (name == NULL) + continue; + //printf("name %s\n", name); + + if (strlen(name) == 1) + c = name[0]; + + if (strlen(name) == 3) + c = name[1]; + + if (strcmp(name, "space") == 0) + c = ' '; + + + if (strcmp(name, "backspace") == 0 && len > 0) { + p->time = 0; + p->text[len - 1] = '\0'; + checkText(p); + return; + } + + if (c == '\0' || p->w > WIDGET_TEXTFIELD_WIDTH - 40) { + continue; + } + + if (len > 0) { + if (p->text[len - 1] == c) { + p->time++; + + if (p->time < WIDGET_TEXTFIELD_TIME_MULTIPLE) { + if (p->atime < 3) + return; + } + } else { + p->time = 0; + } + } + + p->atime = 0; + + p->text[len] = c; + + if (mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { + int i; + + for (i = 0; i < len_shift_map; i += 2) { + if (c == shift_map[i]) { + p->text[len] = shift_map[i + 1]; + } + } + + checkText(p); + return; + } + + if (mapa[SDLK_LSHIFT] == SDL_PRESSED || mapa[SDLK_RSHIFT] == SDL_PRESSED) { + p->text[len] -= 32; + } + + checkText(p); + return; + } + } +} +#endif + +void eventWidgetTextfield(widget_t * widget) +{ + widget_textfield_t *p; + int x, y; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); + + p = (widget_textfield_t *) widget->private_data; + + getMousePosition(&x, &y); + + if (isMouseClicked()) { + if (x >= widget->x && x <= widget->x + WIDGET_TEXTFIELD_WIDTH && + y >= widget->y && y <= widget->y + WIDGET_TEXTFIELD_HEIGHT) { + p->active = TRUE; + } else { + p->active = FALSE; + } + } + + readKey(p); +} + +void destroyWidgetTextfield(widget_t * widget) +{ + widget_textfield_t *p; + + assert(widget != NULL); + assert(widget->type == WIDGET_TYPE_TEXTFILED); + + p = (widget_textfield_t *) widget->private_data; + + free(p); + destroyWidget(widget); +} diff --git a/src/widget/widget_textfield.h b/src/widget/widget_textfield.h new file mode 100644 index 0000000..7991deb --- /dev/null +++ b/src/widget/widget_textfield.h @@ -0,0 +1,41 @@ + +#ifndef WIDGET_TEXTFIELD_H + +# define WIDGET_TEXTFIELD_H + +# include "main.h" +# include "widget.h" + +# define WIDGET_TEXTFIELD_WIDTH 175 +# define WIDGET_TEXTFIELD_HEIGHT 36 + +# define WIDGET_TEXTFIELD_TEXT_OFFSET_X 10 + +# define WIDGET_TEXTFIELD_TIME_MULTIPLE 10 +# define WIDGET_TEXTFIELD_TIME_READ_KEY 2 +# define WIDGET_TEXTFIELD_TIME_BLICK_CURSOR 20 + +# define WIDGET_TEXTFIELD_FILTER_ALL 0 +# define WIDGET_TEXTFIELD_FILTER_NUM 2 +# define WIDGET_TEXTFIELD_FILTER_ALPHANUM 3 +# define WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN 4 + +typedef struct widget_textfield { + int w, h; + int canWrite; + int timeBlick; + int time; + int atime; + int filter; + char text[STR_SIZE]; + bool_t active; +} widget_textfield_t; + +extern widget_t *newWidgetTextfield(char *text, int filter, int x, int y); +extern void setWidgetTextFiledText(widget_t * widget, char *text); +extern char *getTextFromWidgetTextfield(widget_t * widget); +extern void drawWidgetTextfield(widget_t * widget); +extern void eventWidgetTextfield(widget_t * widget); +extern void destroyWidgetTextfield(widget_t * widget); + +#endif -- cgit v1.2.3