This commit is contained in:
Jakob Fries 2007-07-21 16:33:01 +00:00
parent a622421cf3
commit d40868e913
8 changed files with 89 additions and 38 deletions

View file

@ -1225,7 +1225,7 @@ int editor_main(int argc, char **argv)
return -1;
}
if(!gfx_init(false))
if(!gfx_init())
return -1;
modmenu_init();

View file

@ -173,8 +173,6 @@ public:
// data to hold three snapshots
// previous,
bool fullscreen;
enum
{
STATE_OFFLINE,
@ -193,8 +191,6 @@ public:
state = s;
}
void set_fullscreen(bool flag) { fullscreen = flag; }
void send_info()
{
recived_snapshots = 0;
@ -342,7 +338,7 @@ public:
snapshot_part = 0;
// init graphics and sound
if(!gfx_init(fullscreen))
if(!gfx_init())
return;
snd_init(); // sound is allowed to fail
@ -643,7 +639,6 @@ int main(int argc, char **argv)
netaddr4 server_address(127, 0, 0, 1, 8303);
//const char *name = "nameless jerk";
bool connect_at_once = false;
bool fullscreen = true;
bool editor = false;
// init network, need to be done first so we can do lookups
@ -684,7 +679,7 @@ int main(int argc, char **argv)
else if(argv[i][0] == '-' && argv[i][1] == 'w' && argv[i][2] == 0)
{
// -w
fullscreen = false;
config.fullscreen = 0;
}
else if(argv[i][0] == '-' && argv[i][1] == 'e' && argv[i][2] == 0)
{
@ -698,7 +693,6 @@ int main(int argc, char **argv)
{
// start the client
client c;
c.set_fullscreen(fullscreen);
c.run(connect_at_once ? &server_address : 0x0);
}
return 0;

View file

@ -33,8 +33,6 @@ static vec2 g_QuadTexture[4];
static opengl::vertex_buffer vertex_buffer;
//static int screen_width = 800;
//static int screen_height = 600;
static int screen_width = 1024;
static int screen_height = 768;
static float rotation = 0;
static int quads_drawing = 0;
@ -103,9 +101,9 @@ static void draw_quad(bool _bflush = false)
}
}
bool gfx_init(bool fullscreen)
bool gfx_init()
{
if(!context.create(config.screen_width, config.screen_height, 24, 8, 16, 0, fullscreen?opengl::context::FLAG_FULLSCREEN:0))
if(!context.create(config.screen_width, config.screen_height, 24, 8, 16, 0, config.fullscreen?opengl::context::FLAG_FULLSCREEN:0))
{
dbg_msg("game", "failed to create gl context");
return false;
@ -124,7 +122,7 @@ bool gfx_init(bool fullscreen)
context.version_minor(),
context.version_rev());*/
gfx_mapscreen(0,0,screen_width, screen_height);
gfx_mapscreen(0,0,config.screen_width, config.screen_height);
// TODO: make wrappers for this
glEnable(GL_BLEND);
@ -347,12 +345,12 @@ void gfx_swap()
int gfx_screenwidth()
{
return screen_width;
return config.screen_width;
}
int gfx_screenheight()
{
return screen_height;
return config.screen_height;
}
void gfx_texture_set(int slot)

View file

@ -32,7 +32,8 @@ float ui_mouse_world_y() { return mouse_wy; }
int ui_mouse_button(int index) { return (mouse_buttons>>index)&1; }
void ui_set_hot_item(void *id) { becomming_hot_item = id; }
void ui_set_active_item(void *id) { active_item = id; last_active_item = id; }
void ui_set_active_item(void *id) { active_item = id; if (id) last_active_item = id; }
void ui_clear_last_active_item() { last_active_item = 0; }
void *ui_hot_item() { return hot_item; }
void *ui_active_item() { return active_item; }
void *ui_last_active_item() { return last_active_item; }

View file

@ -18,6 +18,7 @@ int ui_mouse_button(int index);
void ui_set_hot_item(void *id);
void ui_set_active_item(void *id);
void ui_clear_last_active_item();
void *ui_hot_item();
void *ui_active_item();
void *ui_last_active_item();

View file

@ -2,6 +2,8 @@
MACRO_CONFIG_INT(screen_width, 800, 0, 0)
MACRO_CONFIG_INT(screen_height, 600, 0, 0)
MACRO_CONFIG_INT(fullscreen, 1, 0, 1)
MACRO_CONFIG_INT(color_depth, 24, 16, 24)
MACRO_CONFIG_STR(player_name, 32, "nameless tee")
MACRO_CONFIG_STR(clan_name, 32, "")
MACRO_CONFIG_STR(password, 32, "")

View file

@ -57,7 +57,7 @@ int gfx_load_png(image_info *img, const char *filename);
*/
// graphics
bool gfx_init(bool fullscreen); // NOT EXPOSED
bool gfx_init(); // NOT EXPOSED
void gfx_shutdown(); // NOT EXPOSED
void gfx_swap(); // NOT EXPOSED

View file

@ -303,6 +303,27 @@ int ui_do_combo_box(void *id, float x, float y, float w, char *lines, int line_c
int inside = (ui_active_item() == id) ? ui_mouse_inside(x, y, w, line_count * line_height) : ui_mouse_inside(x, y, w, line_height);
int hover_index = (int)((ui_mouse_y() - y) / line_height);
if (ui_active_item() == id)
{
if (!ui_mouse_button(0))
{
ui_set_active_item(0);
if (inside)
selected_index = hover_index;
}
}
else if(ui_hot_item() == id)
{
if (ui_mouse_button(0))
ui_set_active_item(id);
}
if (inside)
{
ui_set_hot_item(id);
}
if (ui_active_item() == id)
{
for (int i = 0; i < line_count; i++)
@ -318,22 +339,12 @@ int ui_do_combo_box(void *id, float x, float y, float w, char *lines, int line_c
if (selected_index == i)
ui_do_label(x + 10, y + i * line_height, "-", 36);
}
if (!ui_mouse_button(0))
{
ui_set_active_item(0);
if (inside)
selected_index = hover_index;
}
}
else
{
draw_box(GUI_BOX_SCREEN_LIST, tileset_regular, x, y, w, line_height);
ui_do_label(x + 10, y, lines + 128 * selected_index, 36);
if (inside && ui_mouse_button(0))
ui_set_active_item(id);
}
return selected_index;
@ -364,6 +375,9 @@ int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int
if (len > 0)
str[len-1] = 0;
}
else if (k == input::enter)
ui_clear_last_active_item();
r = 1;
}
@ -394,6 +408,45 @@ int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int
return r;
}
int ui_do_check_box(void *id, float x, float y, float w, float h, int value)
{
int inside = ui_mouse_inside(x, y, w, h);
int r = value;
if(ui_active_item() == id)
{
if(!ui_mouse_button(0))
{
ui_set_active_item(0);
r = r ? 0 : 1;
}
}
else if(ui_hot_item() == id)
{
if(ui_mouse_button(0))
ui_set_active_item(id);
}
if(inside)
ui_set_hot_item(id);
// render
gui_tileset_enum tileset;
int part_type;
if (ui_active_item() == id)
tileset = tileset_active;
else if (ui_hot_item() == id)
tileset = tileset_hot;
else
tileset = tileset_regular;
part_type = r ? GUI_MISC_RADIO_CHECKED : GUI_MISC_RADIO_UNCHECKED;
draw_part(part_type, tileset, x, y, w, h);
return r;
}
int do_scroll_bar(void *id, float x, float y, float height, int steps, int last_index)
{
int r = last_index;
@ -688,8 +741,6 @@ static int main_render(netaddr4 *server_address)
static int settings_general_render()
{
//ui_do_label(100, 150, "General", 36);
// NAME
ui_do_label(column1_x, row1_y, "Name:", 36);
ui_do_edit_box(config_copy.player_name, column2_x, row1_y, 300, 36, config_copy.player_name, sizeof(config_copy.player_name));
@ -757,13 +808,13 @@ static int settings_video_render()
inited = true;
}
static int depth_index = 0;
int depth_index = (config_copy.color_depth == 16) ? 0 : 1;
static int selected_index = -1;
if (selected_index == -1)
{
for (int i = 0; i < resolution_count[depth_index]; i++)
{
if (config.screen_width == resolutions[depth_index][i][0])
if (config_copy.screen_width == resolutions[depth_index][i][0])
{
selected_index = i;
break;
@ -777,19 +828,23 @@ static int settings_video_render()
static char bit_labels[][128] =
{
"16",
"32"
"24"
};
// we need to draw these bottom up, to make overlapping work correctly
ui_do_label(column1_x, row3_y + 50, "(A restart of the game is required for these settings to take effect.)", 20);
ui_do_label(column1_x, row3_y, "Fullscreen:", 36);
config_set_fullscreen(&config_copy, ui_do_check_box(&config_copy.fullscreen, column2_x, row3_y + 5, 32, 32, config_copy.fullscreen));
ui_do_label(column1_x, row2_y, "Resolution:", 36);
selected_index = ui_do_combo_box(&selected_index, column2_x, row2_y, 180, (char *)resolution_names[depth_index], resolution_count[depth_index], selected_index);
selected_index = ui_do_combo_box(&selected_index, column2_x, row2_y, 170, (char *)resolution_names[depth_index], resolution_count[depth_index], selected_index);
ui_do_label(column1_x, row1_y, "Bits:", 36);
depth_index = ui_do_combo_box(&depth_index, column2_x, row1_y, 110, (char *)bit_labels, 2, depth_index);
ui_do_label(column1_x, row3_y, "Fullscreen:", 36);
ui_do_label(column1_x, row3_y + 200, "(A restart of the game is required for these settings to take effect.)", 16);
depth_index = ui_do_combo_box(&depth_index, column2_x, row1_y, 64, (char *)bit_labels, 2, depth_index);
config_set_color_depth(&config_copy, (depth_index == 0) ? 16 : 24);
config_set_screen_width(&config_copy, resolutions[depth_index][selected_index][0]);
config_set_screen_height(&config_copy, resolutions[depth_index][selected_index][1]);