summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-14 14:47:44 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-14 14:47:44 +0000
commit50ba3d5e1e9f9eeda049a348efa4645af07610bc (patch)
tree3a41428f4ce755e596a4d5c2c69668515935e5b0 /src/client
parent5b67651831ad9b160b41990288c938c7a05c1db1 (diff)
- novy widget widget_choicegroup
- moznost ukladat a nacitavat rozohranu hru ( uklada sa pomocou F2) ( neda sa ulozit sietovy multiplayer, a este nie je dokonce ulozenie hranie s AI ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@195 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/client')
-rw-r--r--src/client/saveDialog.c160
-rw-r--r--src/client/saveDialog.h21
-rw-r--r--src/client/saveLoad.c258
-rw-r--r--src/client/saveLoad.h12
4 files changed, 451 insertions, 0 deletions
diff --git a/src/client/saveDialog.c b/src/client/saveDialog.c
new file mode 100644
index 0000000..0595d1e
--- /dev/null
+++ b/src/client/saveDialog.c
@@ -0,0 +1,160 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "myTimer.h"
+#include "tux.h"
+#include "space.h"
+#include "arena.h"
+#include "net_multiplayer.h"
+
+#include "interface.h"
+#include "saveDialog.h"
+#include "image.h"
+#include "font.h"
+#include "saveLoad.h"
+
+#include "widget_label.h"
+#include "widget_button.h"
+#include "widget_textfield.h"
+
+static image_t *g_background;
+static bool_t activeSaveDialog;
+static my_time_t lastActive;
+
+static widget_label_t *widgetLabelMsg;
+static widget_textfield_t *widgetTextFieldName;
+
+static widget_button_t *widgetButtonSave;
+static widget_button_t *widgetButtonBack;
+
+static void switchTerm()
+{
+ if( activeSaveDialog == TRUE )
+ {
+ activeSaveDialog = FALSE;
+ }
+ else
+ {
+ activeSaveDialog = TRUE;
+ }
+}
+
+static void eventWidget(void *p)
+{
+ widget_button_t *button;
+
+ button = (widget_button_t *)p;
+
+ if( button == widgetButtonSave )
+ {
+ saveArena(widgetTextFieldName->text, getCurrentArena());
+ switchTerm();
+ }
+
+ if( button == widgetButtonBack )
+ {
+ switchTerm();
+ }
+}
+
+void initSaveDialog()
+{
+ activeSaveDialog = FALSE;
+ lastActive = getMyTime();
+
+ g_background = getImage(IMAGE_GROUP_BASE, "screen_main");
+
+ widgetLabelMsg = newWidgetLabel(
+ "name",
+ SAVE_DIALOG_LOCATIN_X+20,
+ SAVE_DIALOG_LOCATIN_Y+20,
+ WIDGET_LABEL_LEFT);
+
+ widgetTextFieldName = newWidgetTextfield(
+ "noname",
+ WIDGET_TEXTFIELD_FILTER_ALPHANUM,
+ widgetLabelMsg->x+widgetLabelMsg->w+10,
+ widgetLabelMsg->y);
+
+ widgetButtonSave = newWidgetButton(
+ "Save",
+ SAVE_DIALOG_LOCATIN_X+20,
+ SAVE_DIALOG_LOCATIN_Y+60,
+ eventWidget);
+
+ widgetButtonBack = newWidgetButton(
+ "Back",
+ SAVE_DIALOG_LOCATIN_X+20+WIDGET_BUTTON_WIDTH+20,
+ SAVE_DIALOG_LOCATIN_Y+60,
+ eventWidget);
+}
+
+bool_t isSaveDialogActive()
+{
+ return activeSaveDialog;
+}
+
+void drawSaveDialog()
+{
+ if( activeSaveDialog == FALSE )
+ {
+ return;
+ }
+
+ drawImage(g_background,
+ SAVE_DIALOG_LOCATIN_X,
+ SAVE_DIALOG_LOCATIN_Y,
+ SAVE_DIALOG_LOCATIN_X,
+ SAVE_DIALOG_LOCATIN_Y,
+ SAVE_DIALOG_SIZE_X, SAVE_DIALOG_SIZE_Y);
+
+ drawWidgetLabel(widgetLabelMsg);
+ drawWidgetTextfield(widgetTextFieldName);
+ drawWidgetButton(widgetButtonSave);
+ drawWidgetButton(widgetButtonBack);
+}
+
+void eventSaveDialog()
+{
+ my_time_t currentTime;
+ Uint8 *mapa;
+
+ if( getNetTypeGame() != NET_GAME_TYPE_NONE )
+ {
+ return;
+ }
+
+ mapa = SDL_GetKeyState(NULL);
+
+ currentTime = getMyTime();
+
+ if( mapa[SDLK_F2] == SDL_PRESSED )
+ {
+ if( currentTime - lastActive > SAVEDIALOG_ACTIVE_TIME_INTERVAL )
+ {
+ lastActive = currentTime;
+ switchTerm();
+ }
+ }
+
+ if( activeSaveDialog == FALSE )
+ {
+ return;
+ }
+
+ eventWidgetTextfield(widgetTextFieldName);
+ eventWidgetButton(widgetButtonSave);
+ eventWidgetButton(widgetButtonBack);
+
+}
+
+void quitSaveDialog()
+{
+ destroyWidgetLabel(widgetLabelMsg);
+ destroyWidgetTextfield(widgetTextFieldName);
+ destroyWidgetButton(widgetButtonSave);
+ destroyWidgetButton(widgetButtonBack);
+}
diff --git a/src/client/saveDialog.h b/src/client/saveDialog.h
new file mode 100644
index 0000000..0849bdb
--- /dev/null
+++ b/src/client/saveDialog.h
@@ -0,0 +1,21 @@
+
+#ifndef SAVE_DIALOG_H
+
+#define SAVE_DIALOG_H
+
+#define SAVEDIALOG_ACTIVE_TIME_INTERVAL 500
+
+#define SAVE_DIALOG_SIZE_X 320
+#define SAVE_DIALOG_SIZE_Y 120
+
+#define SAVE_DIALOG_LOCATIN_X (WINDOW_SIZE_X/2 - SAVE_DIALOG_SIZE_X/2)
+#define SAVE_DIALOG_LOCATIN_Y (WINDOW_SIZE_Y/2 - SAVE_DIALOG_SIZE_Y/2)
+
+
+extern void initSaveDialog();
+extern bool_t isSaveDialogActive();
+extern void drawSaveDialog();
+extern void eventSaveDialog();
+extern void quitSaveDialog();
+
+#endif
diff --git a/src/client/saveLoad.c b/src/client/saveLoad.c
new file mode 100644
index 0000000..a31bc64
--- /dev/null
+++ b/src/client/saveLoad.c
@@ -0,0 +1,258 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "textFile.h"
+#include "homeDirector.h"
+
+#include "arena.h"
+#include "arenaFile.h"
+#include "tux.h"
+#include "shot.h"
+#include "item.h"
+
+#include "saveLoad.h"
+
+#include "screen_choiceArena.h"
+#include "screen_world.h"
+
+static void action_saveTux(space_t *space, tux_t *tux, textFile_t *textFile)
+{
+ char str[STR_PROTO_SIZE];
+
+ snprintf(str, STR_PROTO_SIZE,
+ "TUX %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
+ tux->id, tux->x, tux->y, tux->status, tux->position ,tux->control, tux->frame, tux->score, tux->name,
+ tux->gun, tux->bonus, tux->shot[GUN_SIMPLE], tux->shot[GUN_DUAL_SIMPLE],
+ tux->shot[GUN_SCATTER], tux->shot[GUN_TOMMY], tux->shot[GUN_LASSER],
+ tux->shot[GUN_MINE], tux->shot[GUN_BOMBBALL],
+ tux->bonus_time, tux->pickup_time);
+
+ addList(textFile->text, strdup(str));
+}
+
+static void action_saveShot(space_t *space, shot_t *shot, textFile_t *textFile)
+{
+ char str[STR_PROTO_SIZE];
+
+ snprintf(str, STR_PROTO_SIZE, "SHOT %d %d %d %d %d %d %d %d %d",
+ shot->id, shot->x, shot->y, shot->px, shot->py,
+ shot->position, shot->gun, shot->author_id, shot->isCanKillAuthor);
+
+ addList(textFile->text, strdup(str));
+}
+
+static void action_saveItem(space_t *space, item_t *item, textFile_t *textFile)
+{
+ char str[STR_PROTO_SIZE];
+
+ snprintf(str, STR_PROTO_SIZE, "ITEM %d %d %d %d %d %d %d",
+ item->id, item->type, item->x, item->y,
+ item->count, item->frame, item->author_id);
+
+ addList(textFile->text, strdup(str));
+}
+
+static void saveContextArenaToTextFile(textFile_t *textFile, arena_t *arena)
+{
+ char str[STR_PROTO_SIZE];
+
+ sprintf(str, "ARENA %s %d %d",
+ getArenaNetName(getChoiceArenaId()),
+ arena->countRound,
+ arena->max_countRound);
+
+ addList(textFile->text, strdup(str));
+
+ actionSpace(arena->spaceTux, action_saveTux, textFile);
+ actionSpace(arena->spaceShot, action_saveShot, textFile);
+ actionSpace(arena->spaceItem, action_saveItem, textFile);
+}
+
+void saveArena(char *filename, arena_t *arena)
+{
+ textFile_t *textFile;
+ char path[STR_PATH_SIZE];
+
+ sprintf(path, "%s/%s.sav", getHomeDirector(), filename);
+ printf("path = %s\n", path);
+
+ textFile = newTextFile(path);
+
+ if( textFile != NULL )
+ {
+ saveContextArenaToTextFile(textFile, arena);
+ saveTextFile(textFile);
+ destroyTextFile(textFile);
+ }
+ else
+ {
+ fprintf(stderr, "Do not save %s\n", path);
+ }
+}
+
+static arena_t* loadArenaFromLine(char *line)
+{
+ char cmd[STR_SIZE];
+ char name[STR_SIZE];
+ int countRound;
+ int max_countRound;
+ arena_t *arena;
+
+ sscanf(line, "%s %s %d %d", cmd, name, &countRound, &max_countRound);
+
+ setWorldArena( getArenaIdFormNetName(name) );
+ setMaxCountRound(max_countRound);
+ arena = getCurrentArena();
+ arena->countRound = countRound;
+
+ return arena;
+}
+
+static void loadTuxFromLine(char *line, arena_t *arena)
+{
+ char cmd[STR_PROTO_SIZE];
+ char name[STR_NAME_SIZE];
+ int id, x, y, status, position, frame, score, control;
+ int myGun, myBonus;
+ int gun1, gun2, gun3, gun4, gun5, gun6, gun7;
+ int time1, time2;
+ tux_t *tux;
+
+ sscanf(line, "%s %d %d %d %d %d %d %d %d %s %d %d %d %d %d %d %d %d %d %d %d",
+ cmd, &id, &x, &y, &status, &position, &control, &frame, &score, name,
+ &myGun, &myBonus, &gun1, &gun2, &gun3, &gun4, &gun5, &gun6, &gun7, &time1, &time2);
+
+ tux = newTux();
+ replaceTuxID(tux, id);
+ addObjectToSpace(arena->spaceTux, tux);
+
+ tux->control = control;
+
+ if( tux->control == TUX_CONTROL_KEYBOARD_RIGHT )
+ {
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_RIGHT);
+ }
+
+ if( tux->control == TUX_CONTROL_KEYBOARD_LEFT )
+ {
+ setControlTux(tux, TUX_CONTROL_KEYBOARD_LEFT);
+ }
+
+ moveObjectInSpace(arena->spaceTux, tux, x, y);
+ tux->status = status;
+ tux->position = position;
+ tux->frame = frame;
+ tux->score = score;
+ strcpy(tux->name, name);
+ tux->gun = myGun;
+ tux->bonus = myBonus;
+ tux->shot[GUN_SIMPLE] = gun1;
+ tux->shot[GUN_DUAL_SIMPLE] = gun2;
+ tux->shot[GUN_SCATTER] = gun3;
+ tux->shot[GUN_TOMMY] = gun4;
+ tux->shot[GUN_LASSER] = gun5;
+ tux->shot[GUN_MINE] = gun6;
+ tux->shot[GUN_BOMBBALL] = gun7;
+ tux->bonus_time = time1;
+ tux->pickup_time = time2;
+}
+
+static void loadShotFromLine(char *line, arena_t *arena)
+{
+ char cmd[STR_PROTO_SIZE];
+ int x, y, px, py, position, gun, shot_id, author_id, isCanKillAuthor;
+ shot_t *shot;
+
+ sscanf(line, "%s %d %d %d %d %d %d %d %d %d",
+ cmd, &shot_id, &x, &y, &px, &py, &position, &gun, &author_id, &isCanKillAuthor);
+
+ shot = newShot(x, y, px, py, gun, author_id);
+
+ replaceShotID(shot, shot_id);
+ shot->isCanKillAuthor = isCanKillAuthor;
+ shot->position = position;
+
+ if( shot->gun == GUN_LASSER )
+ {
+ transformOnlyLasser(shot);
+ }
+
+ addObjectToSpace(arena->spaceShot, shot);
+}
+
+static void loadItemFromLine(char *line, arena_t *arena)
+{
+ char cmd[STR_PROTO_SIZE];
+ int id, type, x, y, count, frame, author_id, check_id;
+ item_t *item;
+
+ sscanf(line, "%s %d %d %d %d %d %d %d %d",
+ cmd, &id, &type, &x, &y, &count, &frame, &author_id, &check_id);
+
+ item = newItem(x, y, type, author_id);
+
+ replaceItemID(item, id);
+ item->count = count;
+ item->frame = frame;
+
+ addObjectToSpace(arena->spaceItem, item);
+}
+
+static arena_t* loadContextArenaFromTextFile(textFile_t *textFile)
+{
+ arena_t *arena;
+ int i;
+
+ for( i = 0 ; i < textFile->text->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)textFile->text->list[i];
+
+ if( strncmp(line, "ARENA", 5) == 0 )
+ {
+ arena = loadArenaFromLine(line);
+ }
+
+ if( strncmp(line, "TUX", 3) == 0 )
+ {
+ loadTuxFromLine(line, arena);
+ }
+
+ if( strncmp(line, "SHOT", 4) == 0 )
+ {
+ loadShotFromLine(line, arena);
+ }
+
+ if( strncmp(line, "ITEM", 4) == 0 )
+ {
+ loadItemFromLine(line, arena);
+ }
+ }
+
+ return arena;
+}
+
+void loadArena(char *filename)
+{
+ textFile_t *textFile;
+ char path[STR_PATH_SIZE];
+
+ sprintf(path, "%s/%s", getHomeDirector(), filename);
+ printf("path = %s\n", path);
+
+ textFile = loadTextFile(path);
+
+ if( textFile != NULL )
+ {
+ loadContextArenaFromTextFile(textFile);
+ destroyTextFile(textFile);
+ }
+ else
+ {
+ fprintf(stderr, "Do not load %s\n", path);
+ }
+}
diff --git a/src/client/saveLoad.h b/src/client/saveLoad.h
new file mode 100644
index 0000000..875e1f8
--- /dev/null
+++ b/src/client/saveLoad.h
@@ -0,0 +1,12 @@
+
+#ifndef SAVELOAD_H
+
+#define SAVELOAD_H
+
+#include "textFile.h"
+#include "arena.h"
+
+extern void saveArena(char *filename, arena_t *arena);
+extern void loadArena(char *filename);
+
+#endif