summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-08 15:08:39 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-08-08 15:08:39 +0000
commit54d61c622ba721b4ea57852e0ba6c87acfa66a2b (patch)
tree5240311b5ab0aca967089b60df22034457fe515c /src/client
parent8a49909114b3590d48d808b664db8b804bfe2ff7 (diff)
- schopnost autodetekce jazyka systému → v případě neznámého jazyka se zvolí default (angličtina)
- pamatovat posledně hranou arénu → vybrat ji a dostatečně zvýraznit - pauza klevsa [P] - seznam hráčů pod klávesou TAB – skóre, ping git-svn-id: http://opensvn.csie.org/tuxanci_ng@193 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/client')
-rw-r--r--src/client/game.c23
-rw-r--r--src/client/language.c57
-rw-r--r--src/client/pauza.c76
-rw-r--r--src/client/pauza.h16
-rw-r--r--src/client/term.c148
-rw-r--r--src/client/term.h5
6 files changed, 261 insertions, 64 deletions
diff --git a/src/client/game.c b/src/client/game.c
index 0a8caf0..1525035 100644
--- a/src/client/game.c
+++ b/src/client/game.c
@@ -69,12 +69,13 @@ static void initGame()
initShot();
initPanel();
initWorld();
+
initScreenMainMenu();
initScreenAnalyze();
+ initScreenChoiceArena();
initScreenSetting();
initScreenSettingKeys();
initScreenGameType();
- initScreenChoiceArena();
initScreenCredits();
initScreenTable();
initScreenBrowser();
@@ -83,6 +84,17 @@ static void initGame()
void quitGame()
{
quitSDL();
+
+ quitScreenMainMenu();
+ quitScreenAnalyze();
+ quitScreenSetting();
+ quitScreenSettingKeys();
+ quitScreenGameType();
+ quitScreenChoiceArena();
+ quitScreenCredits();
+ quitScreenTable();
+ quitScreenBrowser();
+
quitLayer();
quitFont();
quitLanguage();
@@ -99,15 +111,6 @@ void quitGame()
quitMusic();
quitAudio();
#endif
- quitScreenMainMenu();
- quitScreenAnalyze();
- quitScreenSetting();
- quitScreenSettingKeys();
- quitScreenGameType();
- quitScreenChoiceArena();
- quitScreenCredits();
- quitScreenTable();
- quitScreenBrowser();
printf("quit..\n");
diff --git a/src/client/language.c b/src/client/language.c
index 6200e92..eb915ed 100644
--- a/src/client/language.c
+++ b/src/client/language.c
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <sys/stat.h>
#include "main.h"
#include "list.h"
@@ -11,12 +12,13 @@
#include "configFile.h"
#include "language.h"
+#include "director.h"
static textFile_t *languageFile;
static char fontFile[STR_FILE_NAME_SIZE];
static int fontSize;
-char* getHead(textFile_t *ts)
+static char* getHead(textFile_t *ts)
{
int i;
@@ -34,7 +36,54 @@ char* getHead(textFile_t *ts)
return NULL;
}
+static char* getSupportLanguage()
+{
+ director_t *director;
+ char *envLang;
+ char lang[STR_SIZE];
+ int i;
+
+ printf("I search language..\n");
+
+ envLang = getenv("LANG");
+
+ if( envLang == NULL )
+ {
+ printf("Environment LANG not defined, I use default value \"en\"\n");
+ return strdup("en");
+ }
+
+ memset(lang, 0, STR_SIZE);
+ strncpy(lang, envLang, 2);
+
+ director = loadDirector(PATH_LANG);
+
+ if( director == NULL )
+ {
+ fprintf(stderr, "Do not open director %s\n", PATH_LANG);
+ return strdup("en");
+ }
+ for( i = 0 ; i < director->list->count ; i++ )
+ {
+ char *line;
+
+ line = (char *)director->list->list[i];
+
+ if( strncmp(lang, line, 2) == 0 )
+ {
+ printf("I choice lang %s in file %s\n", lang, line);
+ return strdup(lang);
+ }
+ }
+
+ destroyDirector(director);
+
+ printf("Lang %s not support, I use default language english\n", lang);
+
+ return strdup("en");
+}
+
int initLanguage()
{
textFile_t *languageTypeFile;
@@ -48,12 +97,16 @@ int initLanguage()
if( languageTypeFile == NULL )
{
+ char *defaultLang;
+
fprintf(stderr, "Don't load %s\n", path);
fprintf(stderr, "I create %s\n", path);
languageTypeFile = newTextFile(path);
- addList(languageTypeFile->text, strdup("en") );
+ defaultLang = getSupportLanguage();
+ addList(languageTypeFile->text, strdup(defaultLang) );
saveTextFile(languageTypeFile);
+ free(defaultLang);
}
if( languageTypeFile == NULL )
diff --git a/src/client/pauza.c b/src/client/pauza.c
new file mode 100644
index 0000000..97bade5
--- /dev/null
+++ b/src/client/pauza.c
@@ -0,0 +1,76 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "main.h"
+#include "list.h"
+#include "myTimer.h"
+
+#include "interface.h"
+#include "image.h"
+#include "pauza.h"
+
+static image_t *g_pauza;
+static bool_t activePauza;
+static my_time_t lastActive;
+
+void initPauza()
+{
+ g_pauza = addImageData("pauza.png", IMAGE_ALPHA, "pauza", IMAGE_GROUP_USER);
+ activePauza = FALSE;
+ lastActive = getMyTime();
+}
+
+static void switchPauzed()
+{
+ if( activePauza == TRUE )
+ {
+ activePauza = FALSE;
+ }
+ else
+ {
+ activePauza = TRUE;
+ }
+}
+
+void drawPauza()
+{
+ if( activePauza )
+ {
+ drawImage(g_pauza,
+ WINDOW_SIZE_X/2 - g_pauza->w/2,
+ WINDOW_SIZE_Y/2 - g_pauza->h/2,
+ 0, 0,
+ g_pauza->w, g_pauza->h);
+ }
+}
+
+void eventPauza()
+{
+ Uint8 *mapa;
+ mapa = SDL_GetKeyState(NULL);
+
+ if( mapa[SDLK_p] == SDL_PRESSED )
+ {
+ my_time_t currentTime;
+
+ currentTime = getMyTime();
+
+ if( currentTime - lastActive > PAUZE_ACTIVE_TIME_INTERVAL )
+ {
+ lastActive = currentTime;
+ switchPauzed();
+ }
+ }
+}
+
+bool_t isPauzeActive()
+{
+ return activePauza;
+}
+
+void quitPauza()
+{
+}
+
diff --git a/src/client/pauza.h b/src/client/pauza.h
new file mode 100644
index 0000000..b5eb58e
--- /dev/null
+++ b/src/client/pauza.h
@@ -0,0 +1,16 @@
+
+#ifndef PAUZA_H
+
+#define PAUZA_H
+
+#define PAUZE_ACTIVE_TIME_INTERVAL 1000
+
+#include "main.h"
+
+extern void initPauza();
+extern void drawPauza();
+extern void eventPauza();
+extern bool_t isPauzeActive();
+extern void quitPauza();
+
+#endif
diff --git a/src/client/term.c b/src/client/term.c
index fc1824d..6cad4d4 100644
--- a/src/client/term.c
+++ b/src/client/term.c
@@ -5,102 +5,152 @@
#include "main.h"
#include "list.h"
#include "myTimer.h"
+#include "tux.h"
+#include "space.h"
+#include "arena.h"
#include "interface.h"
#include "term.h"
#include "font.h"
-typedef struct struct_term_t
-{
- char *text;
- my_time_t delTime;
-} term_t;
-
static list_t *listText;
+static bool_t activeTerm;
+static my_time_t lastActive;
+static my_time_t lastRefresh;
-static term_t* newTermItem(char *s)
+void initTerm()
{
- term_t *new;
- char *line;
- int len;
+ listText = newList();
- assert( s != NULL );
-
- line = strdup(s);
- len = strlen(line);
- line[len-1] = '\0';
+ activeTerm = FALSE;
+ lastActive = getMyTime();
+ lastRefresh = lastActive;
+}
- new = malloc( sizeof(term_t) );
- memset(new, 0, sizeof(term_t));
+static char* getStrGun(int gun)
+{
+ switch( gun )
+ {
+ case GUN_SIMPLE : return "revolver";
+ case GUN_DUAL_SIMPLE : return "dual revolver";
+ case GUN_SCATTER : return "scatter";
+ case GUN_TOMMY : return "tommy";
+ case GUN_LASSER : return "lasser";
+ case GUN_MINE : return "mine";
+ case GUN_BOMBBALL : return "bombball";
+ default : return "none";
+ }
- new->text = line;
- new->delTime = getMyTime() + TERM_DEL_TEXT_TIMEOUT;
+ return "gun_unknow";
+}
- return new;
+static char* getStrBonus(int bonus)
+{
+ switch( bonus )
+ {
+ case BONUS_SPEED : return "speed";
+ case BONUS_SHOT : return "shot";
+ case BONUS_TELEPORT : return "teleport";
+ case BONUS_GHOST : return "ghost";
+ case BONUS_4X : return "4X";
+ case BONUS_HIDDEN : return "hidden";
+ default : return "none";
+ }
+
+ return "bonus_unknow";
}
-static void destroyTermItem(term_t *p)
+static void action_refreshTerm(space_t *space, tux_t *tux, void *p)
{
- assert( p != NULL );
-
- free(p->text);
- free(p);
+ char str[STR_SIZE];
+
+ sprintf(str,
+ "name: %s "
+ "score: %d "
+ "gun: %s "
+ "shot: %d "
+ "bonus: %s",
+
+ tux->name, tux->score,
+ getStrGun(tux->gun),
+ tux->shot[tux->gun],
+ getStrBonus(tux->bonus)
+ );
+
+ addList(listText, strdup(str) );
}
-void initTerm()
+static void refreshTerm()
{
+ arena_t *arena;
+
+ arena = getCurrentArena();
+
+ destroyListItem(listText, free);
listText = newList();
+
+ actionSpace(arena->spaceTux, action_refreshTerm, NULL);
+
+ //printf("refresh term..\n");
}
void drawTerm()
{
int i;
+ if( activeTerm == FALSE )
+ {
+ return;
+ }
+
for( i = 0 ; i < listText->count ; i++ )
{
char *line;
- line = (char *)( (term_t *)listText->list[i] )->text;
+ line = (char *) listText->list[i];
drawFont(line, 10, 10 + i*20, COLOR_WHITE);
}
}
+static void switchTerm()
+{
+ if( activeTerm == TRUE )
+ {
+ activeTerm = FALSE;
+ }
+ else
+ {
+ activeTerm = TRUE;
+ }
+}
+
void eventTerm()
{
my_time_t currentTime;
- int i;
+ Uint8 *mapa;
- currentTime = getMyTime();
+ mapa = SDL_GetKeyState(NULL);
+ currentTime = getMyTime();
- for( i = 0 ; i < listText->count ; i++ )
+ if( currentTime - lastRefresh > TERM_REFRESH_TIME_INTERVAL )
{
- my_time_t thisTime;
-
- thisTime = ( (term_t *)listText->list[i] )->delTime;
-
- if( currentTime > thisTime )
- {
- delListItem(listText, i, destroyTermItem);
- i--;
- }
+ lastRefresh = currentTime;
+ refreshTerm();
}
-}
-
-void appendTextInTerm(char *s)
-{
-
- addList(listText, newTermItem(s) );
-
- if( listText->count > TERM_MAX_LINES )
+ if( mapa[SDLK_TAB] == SDL_PRESSED )
{
- delListItem(listText, 0, destroyTermItem);
+ if( currentTime - lastActive > TERM_ACTIVE_TIME_INTERVAL )
+ {
+ lastActive = currentTime;
+ switchTerm();
+ }
}
}
void quitTerm()
{
assert( listText != NULL );
- destroyListItem(listText, destroyTermItem);
+ destroyListItem(listText, free);
}
diff --git a/src/client/term.h b/src/client/term.h
index b48a2b7..99dbf79 100644
--- a/src/client/term.h
+++ b/src/client/term.h
@@ -5,13 +5,12 @@
#include "main.h"
-#define TERM_MAX_LINES 10
-#define TERM_DEL_TEXT_TIMEOUT 2000
+#define TERM_ACTIVE_TIME_INTERVAL 500
+#define TERM_REFRESH_TIME_INTERVAL 1000
extern void initTerm();
extern void drawTerm();
extern void eventTerm();
-extern void appendTextInTerm(char *s);
extern void quitTerm();
#endif