From 9da845061a2fc7f3401c3b7487062f7922ce759f Mon Sep 17 00:00:00 2001 From: Jakob Fries Date: Fri, 1 Jun 2007 11:08:33 +0000 Subject: [PATCH] gui things --- src/engine/client/client.cpp | 2 +- src/engine/config/config.cpp | 32 ++++++++++++++++++++++++ src/engine/config/config.h | 24 ++++++++++++++++++ src/engine/config/config_define.h | 8 ++++++ src/game/client/menu.cpp | 41 ++++++++++++++++++++++++------- 5 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 src/engine/config/config.cpp create mode 100644 src/engine/config/config.h create mode 100644 src/engine/config/config_define.h diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 20ab0b395..3f7656457 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -695,7 +695,7 @@ int main(int argc, char **argv) { // -n NAME i++; - set_player_name(argv[i]); + set_player_name(&config, argv[i]); } else if(argv[i][0] == '-' && argv[i][1] == 'w' && argv[i][2] == 0) { diff --git a/src/engine/config/config.cpp b/src/engine/config/config.cpp new file mode 100644 index 000000000..844158c15 --- /dev/null +++ b/src/engine/config/config.cpp @@ -0,0 +1,32 @@ +#include + +#include +#include + +#include "config.h" + +configuration config; + +void config_reset() +{ + #define MACRO_CONFIG_INT(name,def,min,max) config.name = def; + #define MACRO_CONFIG_STR(name,len,def) strncpy(config.name, def, len); + + #include "config_define.h" + + #undef MACRO_CONFIG_INT + #undef MACRO_CONFIG_STR + + puts("woaaa"); +} + +void config_load(const char *filename) +{ + dbg_msg("config/load", "loading %s", filename); +} + +#define MACRO_CONFIG_INT(name,def,min,max) void set_ ## name (configuration *c, int val) { if (val < min) val = min; if (max != 0 && val > max) val = max; c->name = val; } +#define MACRO_CONFIG_STR(name,len,def) void set_ ## name (configuration *c, char *str) { strncpy(c->name, def, len-1); c->name[sizeof(c->name)-1] = 0; } +#include "config_define.h" +#undef MACRO_CONFIG_INT +#undef MACRO_CONFIG_STR diff --git a/src/engine/config/config.h b/src/engine/config/config.h new file mode 100644 index 000000000..c1a356a53 --- /dev/null +++ b/src/engine/config/config.h @@ -0,0 +1,24 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +struct configuration +{ + #define MACRO_CONFIG_INT(name,def,min,max) int name; + #define MACRO_CONFIG_STR(name,len,def) char name[len]; + #include "config_define.h" + #undef MACRO_CONFIG_INT + #undef MACRO_CONFIG_STR +}; + +extern configuration config; + +void config_reset(); +void config_load(const char *filename); + +#define MACRO_CONFIG_INT(name,def,min,max) void set_ ## name (configuration *c, int val); +#define MACRO_CONFIG_STR(name,len,def) void set_ ## name (configuration *c, char *str); +#include "config_define.h" +#undef MACRO_CONFIG_INT +#undef MACRO_CONFIG_STR + +#endif diff --git a/src/engine/config/config_define.h b/src/engine/config/config_define.h new file mode 100644 index 000000000..0b1fed7e7 --- /dev/null +++ b/src/engine/config/config_define.h @@ -0,0 +1,8 @@ +MACRO_CONFIG_INT(screen_width, 800, 0, 0) +MACRO_CONFIG_INT(screen_height, 600, 0, 0) +MACRO_CONFIG_STR(player_name, 32, "nameless tee") +MACRO_CONFIG_INT(key_move_left, 65, 32, 127) +MACRO_CONFIG_INT(key_move_right, 68, 32, 127) +MACRO_CONFIG_INT(key_jump, 32, 32, 127) +MACRO_CONFIG_INT(key_fire, 33, 32, 127) +MACRO_CONFIG_INT(key_hook, 34, 32, 127) diff --git a/src/game/client/menu.cpp b/src/game/client/menu.cpp index 7ab315dd4..3c3c98e7d 100644 --- a/src/game/client/menu.cpp +++ b/src/game/client/menu.cpp @@ -782,6 +782,7 @@ static void refresh_list(server_list *list) } static int screen = 0; +static configuration config_copy; static int main_screen_render(netaddr4 *server_address) { @@ -827,7 +828,10 @@ static int main_screen_render(netaddr4 *server_address) static int settings_button; if (ui_do_button(&settings_button, "Settings", 0, 20, 420, 170, 48, draw_teewars_button)) + { + config_copy = config; screen = 1; + } return 0; } @@ -843,20 +847,20 @@ static int settings_screen_render() // NAME ui_do_label(column1_x, name_y, "Name:", 36); - ui_do_edit_box(config.player_name, column2_x, name_y, 300, 36, config.player_name, sizeof(config.player_name)); + ui_do_edit_box(config_copy.player_name, column2_x, name_y, 300, 36, config_copy.player_name, sizeof(config_copy.player_name)); // KEYS ui_do_label(column1_x, keys_y, "Keys:", 36); ui_do_label(column2_x, keys_y + 0, "Move Left:", 36); - set_key_move_left(ui_do_key_reader(&config.key_move_left, column3_x, keys_y + 0, 70, 40, config.key_move_left)); + set_key_move_left(&config_copy, ui_do_key_reader(&config_copy.key_move_left, column3_x, keys_y + 0, 70, 40, config_copy.key_move_left)); ui_do_label(column2_x, keys_y + 40, "Move Right:", 36); - set_key_move_right(ui_do_key_reader(&config.key_move_right, column3_x, keys_y + 40, 70, 40, config.key_move_right)); + set_key_move_right(&config_copy, ui_do_key_reader(&config_copy.key_move_right, column3_x, keys_y + 40, 70, 40, config_copy.key_move_right)); ui_do_label(column2_x, keys_y + 80, "Jump:", 36); - set_key_jump(ui_do_key_reader(&config.key_jump, column3_x, keys_y + 80, 70, 40, config.key_jump)); + set_key_jump(&config_copy, ui_do_key_reader(&config_copy.key_jump, column3_x, keys_y + 80, 70, 40, config_copy.key_jump)); ui_do_label(column2_x, keys_y + 120, "Fire:", 36); - set_key_fire(ui_do_key_reader(&config.key_fire, column3_x, keys_y + 120, 70, 40, config.key_fire)); + set_key_fire(&config_copy, ui_do_key_reader(&config_copy.key_fire, column3_x, keys_y + 120, 70, 40, config_copy.key_fire)); ui_do_label(column2_x, keys_y + 160, "Hook:", 36); - set_key_hook(ui_do_key_reader(&config.key_hook, column3_x, keys_y + 160, 70, 40, config.key_hook)); + set_key_hook(&config_copy, ui_do_key_reader(&config_copy.key_hook, column3_x, keys_y + 160, 70, 40, config_copy.key_hook)); // RESOLUTION static char resolutions[][128] = @@ -867,13 +871,32 @@ static int settings_screen_render() "1024x764", "1280x1024", }; + static int res[][2] = + { + { 400, 300 }, + { 640, 480 }, + { 800, 600 }, + { 1024, 768 }, + { 1280, 1024 }, + }; static int selected_index = 0; ui_do_label(column1_x, resolution_y, "Resolution:", 36); selected_index = ui_do_combo_box(&selected_index, column2_x, resolution_y, 170, (char **)resolutions, 5, selected_index); - // BACK BUTTON - static int back_button; - if (ui_do_button(&back_button, "Back", 0, 620, 490, 128, 48, draw_teewars_button)) + set_screen_width(&config_copy, res[selected_index][0]); + set_screen_height(&config_copy, res[selected_index][1]); + + // SAVE BUTTON + static int save_button; + if (ui_do_button(&save_button, "Save", 0, 482, 490, 128, 48, draw_teewars_button)) + { + config = config_copy; + screen = 0; + } + + // CANCEL BUTTON + static int cancel_button; + if (ui_do_button(&cancel_button, "Cancel", 0, 620, 490, 150, 48, draw_teewars_button)) screen = 0; return 0;