ddnet/src/game/client/menu.cpp

1648 lines
42 KiB
C++
Raw Normal View History

2007-05-22 15:03:32 +00:00
#include <stdio.h>
#include <math.h>
2007-05-28 13:49:44 +00:00
#include <string.h>
2007-06-10 17:25:08 +00:00
#include <stdlib.h>
#include <game/math.h>
extern "C" {
#include <engine/system.h>
#include <engine/interface.h>
#include <engine/config.h>
#include <engine/client/ui.h>
}
2007-05-22 15:03:32 +00:00
#include "../mapres.h"
2007-08-22 21:13:33 +00:00
#include "../version.h"
2007-05-22 15:03:32 +00:00
#include "mapres_image.h"
#include "mapres_tilemap.h"
2007-05-22 15:03:32 +00:00
2007-07-14 23:08:17 +00:00
#include "data.h"
#include <mastersrv/mastersrv.h>
2007-07-14 23:08:17 +00:00
extern data_container *data;
2007-05-22 15:03:32 +00:00
/********************************************************
MENU
*********************************************************/
2007-05-27 18:14:24 +00:00
enum gui_tileset_enum
{
tileset_regular,
tileset_hot,
tileset_active,
tileset_inactive
};
void draw_area(gui_tileset_enum tileset, int areax, int areay, int areaw, int areah, float x, float y, float w, float h)
2007-05-27 18:14:24 +00:00
{
const float tex_w = 512.0, tex_h = 512.0;
switch (tileset)
{
case tileset_regular:
break;
2007-05-27 18:14:24 +00:00
case tileset_hot:
areax += 192; areay += 192; break;
2007-05-27 18:14:24 +00:00
case tileset_active:
areay += 192; break;
2007-05-27 18:14:24 +00:00
case tileset_inactive:
areax += 192; break;
2007-05-27 18:14:24 +00:00
default:
dbg_msg("menu", "invalid tileset given to draw_part");
}
float ts_x = areax / tex_w;
float ts_y = areay / tex_h;
float te_x = (areax + areaw) / tex_w;
float te_y = (areay + areah) / tex_h;
2007-05-27 18:14:24 +00:00
gfx_blend_normal();
gfx_texture_set(data->images[IMAGE_GUI_WIDGETS].id);
2007-05-27 18:14:24 +00:00
gfx_quads_begin();
gfx_setcolor(1,1,1,1);
2007-05-27 18:14:24 +00:00
gfx_quads_setsubset(
ts_x, // startx
ts_y, // starty
te_x, // endx
te_y); // endy
2007-05-27 18:14:24 +00:00
gfx_quads_drawTL(x,y,w,h);
gfx_quads_end();
2007-05-28 13:49:44 +00:00
}
void draw_part(int part_type, gui_tileset_enum tileset, float x, float y, float w, float h)
2007-05-28 13:49:44 +00:00
{
gui_box part = data->gui.misc[part_type];
draw_area(tileset, part.x, part.y, part.w, part.h, x, y, w, h);
//draw_part(parts[part], tileset, x, y, w, h);
2007-05-27 18:14:24 +00:00
}
void draw_part(int part_type, gui_tileset_enum tileset, float x, float y)
2007-05-27 18:14:24 +00:00
{
gui_box part = data->gui.misc[part_type];
draw_part(part_type, tileset, x, y, part.w, part.h);
2007-05-27 18:14:24 +00:00
}
void draw_box(int box_type, gui_tileset_enum tileset, float x, float y, float w, float h)
{
gui_compositebox box = data->gui.boxes[box_type];
/* A composite box consists of 9 parts. To get the coordinates for all corners, we need A, B, C and D:
* A----+----+----+
* | tl | tm | tr |
* +----B----+----+
* | ml | mm | mr |
* +----+----C----+
* | bl | bm | br |
* +----+----+----D
*/
2007-07-26 18:51:01 +00:00
int ax = box.rect.x;
int ay = box.rect.y;
int bx = box.center.x;
int by = box.center.y;
int cx = box.center.x + box.center.w;
int cy = box.center.y + box.center.h;
int dx = box.rect.x + box.rect.w;
int dy = box.rect.y + box.rect.h;
draw_area(tileset, ax, ay, bx-ax, by-ay, x, y, bx-ax, by-ay);
draw_area(tileset, bx, ay, cx-bx, by-ay, x+bx-ax, y, w-(bx-ax)-(dx-cx), by-ay);
draw_area(tileset, cx, ay, dx-cx, by-ay, x+w-(dx-cx), y, dx-cx, by-ay);
2007-05-28 13:49:44 +00:00
2007-07-28 17:12:01 +00:00
draw_area(tileset, ax, by, bx-ax, min(int(h-(by-ay)-(dy-cy)), cy-by), x, y+(by-ay), bx-ax, h-(by-ay)-(dy-cy));
draw_area(tileset, bx, by, cx-bx, cy-by, x+bx-ax, y+(by-ay), w-(bx-ax)-(dx-cx), h-(by-ay)-(dy-cy));
2007-07-28 17:12:01 +00:00
draw_area(tileset, cx, by, dx-cx, min(int(h-(by-ay)-(dy-cy)), cy-by), x+w-(dx-cx), y+(by-ay), dx-cx, h-(by-ay)-(dy-cy));
2007-05-28 13:49:44 +00:00
draw_area(tileset, ax, cy, bx-ax, dy-cy, x, y+h-(dy-cy), bx-ax, dy-cy);
draw_area(tileset, bx, cy, cx-bx, dy-cy, x+bx-ax, y+h-(dy-cy), w-(bx-ax)-(dx-cx), dy-cy);
draw_area(tileset, cx, cy, dx-cx, dy-cy, x+w-(dx-cx), y+h-(dy-cy), dx-cx, dy-cy);
2007-05-28 13:49:44 +00:00
}
2007-10-09 09:04:57 +00:00
extern "C"
{
2007-05-22 15:03:32 +00:00
struct pretty_font
{
2007-06-10 20:00:58 +00:00
float m_CharStartTable[256];
float m_CharEndTable[256];
2007-05-22 15:03:32 +00:00
int font_texture;
};
extern pretty_font *current_font;
2007-10-09 09:04:57 +00:00
}
extern void render_sun(float x, float y);
extern void select_sprite(int id, int flags=0, int sx=0, int sy=0);
extern void draw_sprite(float x, float y, float size);
2007-07-21 12:57:36 +00:00
void draw_background(float t)
2007-05-22 15:03:32 +00:00
{
2007-07-21 12:57:36 +00:00
// background color
gfx_clear(0.65f,0.78f,0.9f);
gfx_blend_normal();
2007-07-22 13:19:18 +00:00
2007-07-21 12:57:36 +00:00
render_sun(170, 170);
gfx_texture_set(data->images[IMAGE_CLOUDS].id);
2007-07-21 21:08:28 +00:00
gfx_quads_begin();
select_sprite(SPRITE_CLOUD1);
draw_sprite(3500 - fmod(t * 20 + 2000, 4524), 250, 512);
select_sprite(SPRITE_CLOUD2);
draw_sprite(3000 - fmod(t * 50 + 2000, 4024), 150+250, 512);
select_sprite(SPRITE_CLOUD3);
draw_sprite(4000 - fmod(t * 60 + 500, 4512), 300+130, 256);
2007-07-21 21:08:28 +00:00
gfx_quads_end();
gfx_texture_set(data->images[IMAGE_MENU_BACKGROUND].id);
2007-07-22 13:19:18 +00:00
gfx_quads_begin();
2007-08-04 23:26:41 +00:00
gfx_quads_drawTL(0, 430, 1600, 1600/2);
2007-07-22 13:19:18 +00:00
gfx_quads_end();
2007-05-22 15:03:32 +00:00
2007-07-22 13:19:18 +00:00
int frame = int(t * 10) % 3;
2007-05-22 15:03:32 +00:00
2007-07-22 13:19:18 +00:00
//float x_path = -t
float x_nudge = 3*cos(t*10);
float y_nudge = 8*sin(t*3);
x_nudge += 150 * cos(t/3);
y_nudge += 30 * sin(t/3);
float angl = t/3;
angl = fmod(angl, 2*pi);
bool flip = angl > pi;
gfx_texture_set(data->images[IMAGE_MENU_BUTTERFLY].id);
2007-05-22 15:03:32 +00:00
gfx_quads_begin();
gfx_setcolor(1, 1, 1, 1);
2007-05-22 15:03:32 +00:00
gfx_quads_setsubset(
2007-07-22 13:19:18 +00:00
flip ? (frame + 1) * 0.25f : frame * 0.25f, // startx
0.0f, // starty
flip ? frame * 0.25f : (frame + 1) * 0.25f, // endx
0.5f); // endy
gfx_quads_drawTL(1250 + x_nudge, 480 + y_nudge, 64, 64);
2007-05-22 15:03:32 +00:00
gfx_quads_end();
}
void draw_image_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra)
{
ui_do_image(*(int *)id, x, y, w, h);
}
2007-05-27 18:14:24 +00:00
void draw_single_part_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra)
{
gui_tileset_enum tileset;
if (ui_active_item() == id && ui_hot_item() == id)
tileset = tileset_active;
else if (ui_hot_item() == id)
tileset = tileset_hot;
else
tileset = tileset_regular;
2007-07-13 13:40:04 +00:00
draw_part((int)((char*)extra-(char*)0), tileset, x, y, w, h);
2007-05-27 18:14:24 +00:00
}
2007-06-01 02:21:46 +00:00
void draw_menu_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra)
{
int box_type;
2007-07-13 13:40:04 +00:00
if ((int)((char*)extra-(char*)0))
box_type = GUI_BOX_SCREEN_INFO;
2007-06-01 02:21:46 +00:00
else
box_type = GUI_BOX_SCREEN_LIST;
draw_box(box_type, tileset_regular, x, y, w, h);
2007-06-01 02:21:46 +00:00
ui_do_label(x + 10, y, text, 28);
}
2007-05-27 18:14:24 +00:00
void draw_teewars_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra)
{
2007-07-26 18:51:01 +00:00
const float font_size = h-6.0f;//42.0f;
2007-07-21 18:18:06 +00:00
float text_width = gfx_pretty_text_width(font_size, text, -1);
2007-05-27 18:14:24 +00:00
gui_tileset_enum tileset;
2007-07-20 22:19:40 +00:00
if (ui_active_item() == id)
2007-07-21 12:57:36 +00:00
{
int inside = ui_mouse_inside(x, y, w, h);
tileset = inside ? tileset_active : tileset_hot;
}
2007-05-27 18:14:24 +00:00
else if (ui_hot_item() == id)
tileset = tileset_hot;
else
tileset = tileset_regular;
2007-07-13 13:40:04 +00:00
if ((int)((char*)extra-(char*)0) == 1)
2007-05-28 13:49:44 +00:00
tileset = tileset_inactive;
2007-05-27 18:14:24 +00:00
draw_box(GUI_BOX_BUTTON, tileset, x, y, w, h);
2007-05-27 18:14:24 +00:00
2007-07-22 13:43:31 +00:00
ui_do_label(x + w/2 - text_width/2, y + 2, text, font_size);
2007-05-27 18:14:24 +00:00
}
/*
2007-05-22 15:03:32 +00:00
struct server_info
{
int version;
int players;
int max_players;
netaddr4 address;
char name[129];
char map[65];
};*/
2007-05-22 15:03:32 +00:00
struct server_list
{
int active_count, info_count;
int scroll_index;
int selected_index;
};
2007-06-01 02:21:46 +00:00
int ui_do_key_reader(void *id, float x, float y, float w, float h, int key)
{
// process
2007-07-20 22:30:11 +00:00
static bool mouse_released = true;
2007-06-01 02:21:46 +00:00
int inside = ui_mouse_inside(x, y, w, h);
int new_key = key;
2007-07-20 22:30:11 +00:00
if(!ui_mouse_button(0))
mouse_released = true;
2007-06-10 15:19:04 +00:00
2007-07-20 22:19:40 +00:00
if(ui_active_item() == id)
2007-06-01 02:21:46 +00:00
{
int k = inp_last_key();
2007-07-20 22:19:40 +00:00
if (k)
2007-06-10 15:19:04 +00:00
{
2007-07-20 22:19:40 +00:00
new_key = k;
ui_set_active_item(0);
2007-07-20 22:30:11 +00:00
mouse_released = false;
2007-06-10 15:19:04 +00:00
}
2007-06-01 02:21:46 +00:00
}
2007-07-20 22:19:40 +00:00
else if(ui_hot_item() == id)
2007-06-01 02:21:46 +00:00
{
2007-07-20 22:30:11 +00:00
if(ui_mouse_button(0) && mouse_released)
2007-07-20 22:19:40 +00:00
ui_set_active_item(id);
2007-06-01 02:21:46 +00:00
}
2007-07-20 22:19:40 +00:00
if(inside)
ui_set_hot_item(id);
2007-06-01 02:21:46 +00:00
// draw
2007-07-22 13:19:18 +00:00
int box_type;
if (ui_active_item() == id || ui_hot_item() == id)
box_type = GUI_BOX_SCREEN_INFO;
else
box_type = GUI_BOX_SCREEN_TEXTBOX;
draw_box(box_type, tileset_regular, x, y, w, h);
2007-06-01 02:21:46 +00:00
const char *str = inp_key_name(key);
2007-06-01 02:21:46 +00:00
ui_do_label(x + 10, y, str, 36);
if (ui_active_item() == id)
{
float w = gfx_pretty_text_width(36.0f, str, -1);
2007-06-01 02:21:46 +00:00
ui_do_label(x + 10 + w, y, "_", 36);
}
return new_key;
}
int ui_do_combo_box(void *id, float x, float y, float w, const char **lines, int line_count, int selected_index)
2007-06-01 02:21:46 +00:00
{
float line_height = 36.0f;
2007-07-26 18:51:01 +00:00
float height = line_count * line_height;
2007-06-01 02:21:46 +00:00
2007-07-26 18:51:01 +00:00
int inside = (ui_active_item() == id) ? ui_mouse_inside(x, y, w, height) : ui_mouse_inside(x, y, w, line_height);
2007-07-13 13:40:04 +00:00
int hover_index = (int)((ui_mouse_y() - y) / line_height);
2007-06-01 02:21:46 +00:00
2007-07-21 16:33:01 +00:00
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))
2007-07-26 18:51:01 +00:00
{
2007-07-21 16:33:01 +00:00
ui_set_active_item(id);
2007-07-26 18:51:01 +00:00
}
2007-07-21 16:33:01 +00:00
}
if (inside)
{
ui_set_hot_item(id);
}
2007-06-01 02:21:46 +00:00
if (ui_active_item() == id)
{
for (int i = 0; i < line_count; i++)
{
int box_type;
2007-06-01 02:21:46 +00:00
if (inside && hover_index == i)
box_type = GUI_BOX_SCREEN_INFO;
2007-06-01 02:21:46 +00:00
else
box_type = GUI_BOX_SCREEN_LIST;
2007-06-01 02:21:46 +00:00
draw_box(box_type, tileset_regular, x, y + i * line_height, w, line_height);
ui_do_label(x + 10 + 10, y + i * line_height, lines[i], 36);
2007-06-01 02:21:46 +00:00
if (selected_index == i)
ui_do_label(x + 10, y + i * line_height, "-", 36);
}
}
else
{
2007-07-22 13:19:18 +00:00
int box_type;
if (ui_active_item() == id || ui_hot_item() == id)
box_type = GUI_BOX_SCREEN_INFO;
else
box_type = GUI_BOX_SCREEN_TEXTBOX;
draw_box(box_type, tileset_regular, x, y, w, line_height);
ui_do_label(x + 10, y, lines[selected_index], 36);
2007-06-01 02:21:46 +00:00
}
return selected_index;
}
2007-05-22 15:03:32 +00:00
int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int str_size)
{
int inside = ui_mouse_inside(x, y, w, h);
int r = 0;
2007-07-28 17:44:12 +00:00
static int at_index = 0;
2007-05-22 15:03:32 +00:00
2007-07-20 22:30:11 +00:00
if(ui_last_active_item() == id)
2007-05-22 15:03:32 +00:00
{
int c = inp_last_char();
int k = inp_last_key();
2007-05-22 15:03:32 +00:00
int len = strlen(str);
2007-06-11 19:59:29 +00:00
2007-07-28 17:44:12 +00:00
if (inside && ui_mouse_button(0))
{
int mx_rel = (int)(ui_mouse_x() - x);
2007-07-28 17:44:12 +00:00
for (int i = 1; i <= len; i++)
{
if (gfx_pretty_text_width(36.0f, str, i) + 10 > mx_rel)
{
at_index = i - 1;
break;
}
if (i == len)
at_index = len;
}
}
if (at_index > len)
at_index = len;
if (!(c >= 0 && c < 32))
2007-05-22 15:03:32 +00:00
{
2007-07-28 17:44:12 +00:00
if (len < str_size - 1 && at_index < str_size - 1)
2007-05-22 15:03:32 +00:00
{
2007-07-28 17:44:12 +00:00
memmove(str + at_index + 1, str + at_index, len - at_index + 1);
str[at_index] = c;
at_index++;
2007-05-22 15:03:32 +00:00
}
}
if (k == KEY_BACKSPACE && at_index > 0)
2007-05-22 15:03:32 +00:00
{
2007-07-28 17:55:50 +00:00
memmove(str + at_index - 1, str + at_index, len - at_index + 1);
at_index--;
2007-05-22 15:03:32 +00:00
}
else if (k == KEY_DEL && at_index < len)
2007-07-28 17:55:50 +00:00
memmove(str + at_index, str + at_index + 1, len - at_index);
else if (k == KEY_ENTER)
2007-07-21 16:33:01 +00:00
ui_clear_last_active_item();
else if (k == KEY_LEFT && at_index > 0)
2007-07-28 17:44:12 +00:00
at_index--;
else if (k == KEY_RIGHT && at_index < len)
2007-07-28 17:44:12 +00:00
at_index++;
else if (k == KEY_HOME)
at_index = 0;
else if (k == KEY_END)
at_index = len;
2007-07-21 16:33:01 +00:00
2007-05-22 15:03:32 +00:00
r = 1;
}
2007-07-21 18:18:06 +00:00
int box_type;
if (ui_active_item() == id || ui_hot_item() == id || ui_last_active_item() == id)
box_type = GUI_BOX_SCREEN_INFO;
else
box_type = GUI_BOX_SCREEN_TEXTBOX;
2007-07-28 17:44:12 +00:00
bool just_got_active = false;
2007-07-20 22:30:11 +00:00
if(ui_active_item() == id)
{
if(!ui_mouse_button(0))
ui_set_active_item(0);
}
2007-07-20 22:19:40 +00:00
else if(ui_hot_item() == id)
{
if(ui_mouse_button(0))
2007-07-28 17:44:12 +00:00
{
if (ui_last_active_item() != id)
just_got_active = true;
2007-07-20 22:19:40 +00:00
ui_set_active_item(id);
2007-07-28 17:44:12 +00:00
}
2007-07-20 22:19:40 +00:00
}
if(inside)
2007-07-20 22:30:11 +00:00
ui_set_hot_item(id);
2007-05-22 15:03:32 +00:00
2007-07-21 18:18:06 +00:00
draw_box(box_type, tileset_regular, x, y, w, h);
2007-05-28 13:49:44 +00:00
2007-06-01 02:21:46 +00:00
ui_do_label(x + 10, y, str, 36);
2007-07-28 17:44:12 +00:00
if (ui_last_active_item() == id && !just_got_active)
2007-05-22 15:03:32 +00:00
{
2007-07-28 17:44:12 +00:00
float w = gfx_pretty_text_width(36.0f, str, at_index);
2007-06-01 02:21:46 +00:00
ui_do_label(x + 10 + w, y, "_", 36);
2007-05-22 15:03:32 +00:00
}
return r;
}
2007-07-21 16:33:01 +00:00
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;
}
2007-10-07 20:05:55 +00:00
int ui_do_button_rect(void *id, const char *text, int checked, struct rect *r, draw_button_callback draw_func, void *extra)
{
return ui_do_button(id, text, checked, r->x, r->y, r->w, r->h, draw_func, extra);
}
void ui_do_label_rect(struct rect *r, char *str, float size)
{
ui_do_label(r->x + 3, r->y + r->h/2 - size/2, str, size);
}
2007-07-21 17:43:00 +00:00
int do_scroll_bar_horiz(void *id, float x, float y, float width, int steps, int last_index)
{
int r = last_index;
static int up_button;
static int down_button;
if (ui_do_button(&up_button, "", 0, x, y + 8, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_LEFT))
{
if (r > 0)
--r;
}
if (ui_do_button(&down_button, "", 0, x + width - 16, y + 8, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_RIGHT))
{
if (r < steps)
++r;
}
if (steps > 0) // only if there's actually stuff to scroll through
{
int inside = ui_mouse_inside(x + 16, y, width - 32, 32);
if (inside && (!ui_active_item() || ui_active_item() == id))
ui_set_hot_item(id);
if(ui_active_item() == id)
{
if (ui_mouse_button(0))
{
float pos = ui_mouse_x() - x - 16;
float perc = pos / (width - 32);
r = (int)((steps + 1) * perc);
if (r < 0)
r = 0;
else if (r > steps)
r = steps;
}
else
ui_set_active_item(0);
}
else if (ui_hot_item() == id && ui_mouse_button(0))
ui_set_active_item(id);
else if (inside && (!ui_active_item() || ui_active_item() == id))
ui_set_hot_item(id);
}
draw_part(GUI_MISC_SLIDER_BIG_HORIZ_BEGIN, tileset_regular, x + 16, y + 8, 16, 16);
draw_part(GUI_MISC_SLIDER_BIG_HORIZ_MID, tileset_regular, x + 32, y + 8, width - 32 - 32, 16);
draw_part(GUI_MISC_SLIDER_BIG_HORIZ_END, tileset_regular, x + width - 32, y + 8, 16, 16);
2007-07-21 21:11:54 +00:00
draw_part(GUI_MISC_SLIDER_BIG_HANDLE_HORIZ, tileset_regular, x + 16 + r * ((width - 64) / steps), y + 8, 32, 16);
2007-07-21 17:43:00 +00:00
return r;
}
int do_scroll_bar_vert(void *id, float x, float y, float height, int steps, int last_index)
2007-05-22 15:03:32 +00:00
{
int r = last_index;
2007-05-28 13:49:44 +00:00
static int up_button;
static int down_button;
if (ui_do_button(&up_button, "", 0, x + 8, y, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_UP))
2007-05-22 15:03:32 +00:00
{
if (r > 0)
--r;
}
if (ui_do_button(&down_button, "", 0, x + 8, y + height - 16, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_DOWN))
2007-05-22 15:03:32 +00:00
{
if (r < steps)
++r;
}
2007-06-01 02:21:46 +00:00
if (steps > 0) // only if there's actually stuff to scroll through
2007-05-22 15:03:32 +00:00
{
2007-05-28 13:49:44 +00:00
int inside = ui_mouse_inside(x, y + 16, 16, height - 32);
2007-05-22 15:03:32 +00:00
if (inside && (!ui_active_item() || ui_active_item() == id))
ui_set_hot_item(id);
if(ui_active_item() == id)
{
if (ui_mouse_button(0))
{
2007-07-21 17:43:00 +00:00
float pos = ui_mouse_y() - y - 32;
2007-05-28 13:49:44 +00:00
float perc = pos / (height - 32);
2007-05-22 15:03:32 +00:00
r = (int)((steps + 1) * perc);
2007-05-22 15:03:32 +00:00
if (r < 0)
r = 0;
else if (r > steps)
r = steps;
}
else
ui_set_active_item(0);
}
else if (ui_hot_item() == id && ui_mouse_button(0))
ui_set_active_item(id);
else if (inside && (!ui_active_item() || ui_active_item() == id))
ui_set_hot_item(id);
}
draw_part(GUI_MISC_SLIDER_BIG_VERT_BEGIN, tileset_regular, x + 8, y + 16, 16, 16);
draw_part(GUI_MISC_SLIDER_BIG_VERT_MID, tileset_regular, x + 8, y + 32, 16, height - 32 - 32);
draw_part(GUI_MISC_SLIDER_BIG_VERT_END, tileset_regular, x + 8, y + height - 32, 16, 16);
2007-05-27 18:14:24 +00:00
2007-07-21 21:11:54 +00:00
draw_part(GUI_MISC_SLIDER_BIG_HANDLE_VERT, tileset_regular, x + 8, y + 16 + r * ((height - 64) / steps), 16, 32);
2007-05-27 18:14:24 +00:00
2007-05-22 15:03:32 +00:00
return r;
}
static int do_server_list(float x, float y, int *scroll_index, int *selected_index, int visible_items)
2007-05-22 15:03:32 +00:00
{
2007-05-28 13:49:44 +00:00
const float spacing = 3.f;
const float item_height = 28;
const float item_width = 728;
const float real_width = item_width + 20;
2007-05-22 15:03:32 +00:00
const float real_height = item_height * visible_items + spacing * (visible_items - 1);
int num_servers = client_serverbrowse_sorted_num();
2007-05-22 15:03:32 +00:00
int r = -1;
for (int i = 0; i < visible_items; i++)
{
int item_index = i + *scroll_index;
if (item_index >= num_servers)
;
2007-06-01 02:21:46 +00:00
//ui_do_image(empty_item_texture, x, y + i * item_height + i * spacing, item_width, item_height);
2007-05-22 15:03:32 +00:00
else
{
SERVER_INFO *item = client_serverbrowse_sorted_get(item_index);
2007-05-22 15:03:32 +00:00
bool clicked = false;
clicked = ui_do_button(item, item->name, 0, x, y + i * item_height + i * spacing, item_width, item_height,
draw_menu_button, (*selected_index == item_index) ? (void *)1 : 0);
2007-05-22 15:03:32 +00:00
char temp[64]; // plenty of extra room so we don't get sad :o
sprintf(temp, "%i/%i %3d", item->num_players, item->max_players, item->latency);
2007-05-22 15:03:32 +00:00
2007-06-01 02:21:46 +00:00
ui_do_label(x + 600, y + i * item_height + i * spacing, temp, item_height);
ui_do_label(x + 360, y + i * item_height + i * spacing, item->map, item_height);
2007-05-22 15:03:32 +00:00
if (clicked)
{
r = item_index;
*selected_index = item_index;
2007-05-22 15:03:32 +00:00
}
}
}
*scroll_index = do_scroll_bar_vert(scroll_index, x + real_width - 16, y, real_height,
max(num_servers - visible_items, 0), *scroll_index);
2007-05-22 15:03:32 +00:00
return r;
}
2007-07-21 15:48:35 +00:00
enum
{
SCREEN_MAIN,
SCREEN_DISCONNECTED,
SCREEN_CONNECTING,
2007-07-21 15:48:35 +00:00
SCREEN_SETTINGS_GENERAL,
SCREEN_SETTINGS_CONTROLS,
SCREEN_SETTINGS_VIDEO,
2007-07-26 18:51:01 +00:00
SCREEN_SETTINGS_VIDEO_SELECT_MODE,
SCREEN_SETTINGS_VIDEO_CUSTOM,
2007-07-21 15:48:35 +00:00
SCREEN_SETTINGS_SOUND,
SCREEN_KERNING
};
static int screen = SCREEN_MAIN;
static CONFIGURATION config_copy;
2007-05-22 15:03:32 +00:00
2007-07-21 15:48:35 +00:00
const float column1_x = 250;
2007-07-21 17:43:00 +00:00
const float column2_x = column1_x + 170;
2007-07-21 15:48:35 +00:00
const float column3_x = column2_x + 170;
const float row1_y = 180;
const float row2_y = row1_y + 40;
const float row3_y = row2_y + 40;
2007-07-21 17:43:00 +00:00
const float row4_y = row3_y + 40;
const float row5_y = row4_y + 40;
const float row6_y = row5_y + 40;
const float row7_y = row6_y + 40;
2007-07-21 15:48:35 +00:00
static char address[128] = "localhost:8303";
2007-10-07 20:05:55 +00:00
static float colors[7][3] =
{
{ 0, 0, 1 },
{ 0, 1, 0 },
{ 0, 1, 1 },
{ 1, 0, 0 },
{ 1, 0, 1 },
{ 1, 1, 0 },
{ 1, 1, 1 },
};
static void draw_rect(struct rect *r)
{
float *color = colors[rand()%7];
gfx_setcolor(color[0], color[1], color[2], 1);
gfx_lines_draw(r->x, r->y, r->x+r->w, r->y);
gfx_lines_draw(r->x+r->w, r->y, r->x+r->w, r->y+r->h);
gfx_lines_draw(r->x+r->w, r->y+r->h, r->x, r->y+r->h);
gfx_lines_draw(r->x, r->y+r->h, r->x, r->y);
}
static void draw_rects(struct rect *rects, int count)
{
gfx_texture_set(-1);
gfx_lines_begin();
for (int i = 0; i < count; i++)
{
struct rect *r = &rects[i];
float *color = colors[i%7];
gfx_setcolor(color[0], color[1], color[2], 1);
gfx_lines_draw(r->x, r->y, r->x+r->w, r->y);
gfx_lines_draw(r->x+r->w, r->y, r->x+r->w, r->y+r->h);
gfx_lines_draw(r->x+r->w, r->y+r->h, r->x, r->y+r->h);
gfx_lines_draw(r->x, r->y+r->h, r->x, r->y);
}
gfx_lines_end();
}
static void print_rect(struct rect *r)
{
printf("x: %f y: %f w: %f h: %f\n", r->x, r->y, r->w, r->h);
}
static void tab_menu_render(struct rect *r)
{
static struct rect button1;
static struct rect button2;
static struct rect button3;
static struct rect rest1;
static struct rect rest2;
static struct rect rest3;
ui_vsplit_l(r, 160, &button1, &rest1);
ui_vsplit_l(&rest1, 160, &button2, &rest2);
ui_vsplit_l(&rest2, 160, &button3, &rest3);
if (ui_do_button_rect(&button1, "Browser", 0, &button1, draw_teewars_button, 0))
{
screen = SCREEN_MAIN;
}
if (ui_do_button_rect(&button2, "Settings", 0, &button2, draw_teewars_button, 0))
{
screen = SCREEN_SETTINGS_GENERAL;
}
ui_do_label_rect(&rest3, "Name:", 36);
}
static void ui_settings_render(struct rect *r)
{
static struct rect sub_menu_selector;
static struct rect center;
ui_vsplit_l(r, 100, &sub_menu_selector, &center);
switch (screen)
{
/*case SCREEN_SETTINGS_GENERAL: settings_general_render(); break;
case SCREEN_SETTINGS_CONTROLS: settings_controls_render(); break;
case SCREEN_SETTINGS_VIDEO: settings_video_render(); break;
case SCREEN_SETTINGS_VIDEO_SELECT_MODE: settings_video_render_select_mode(); break;
case SCREEN_SETTINGS_VIDEO_CUSTOM: settings_video_render_custom(); break;
case SCREEN_SETTINGS_SOUND: settings_sound_render(); break;*/
}
}
static void middle_render(struct rect *r)
{
bool ingame = false;
switch (screen)
{
case SCREEN_MAIN:
{
if (ingame)
{}
//return ingame_main_render();
else
{
static struct rect browser;
ui_margin(r, 5, &browser);
ui_do_button_rect(&browser, "b", 0, &browser, draw_teewars_button, 0);
}
break;
}
case SCREEN_DISCONNECTED:
{
break;
//return disconnected_render();
}
case SCREEN_CONNECTING:
{
break;
//return connecting_render();
}
case SCREEN_SETTINGS_GENERAL:
case SCREEN_SETTINGS_CONTROLS:
case SCREEN_SETTINGS_VIDEO:
case SCREEN_SETTINGS_VIDEO_SELECT_MODE:
case SCREEN_SETTINGS_VIDEO_CUSTOM:
case SCREEN_SETTINGS_SOUND:
{
ui_settings_render(r);
//return settings_render(ingame);
}
case SCREEN_KERNING:
{
break;
//return kerning_render();
}
default: dbg_msg("menu", "invalid screen selected..."); break;
}
}
static int ui_menu_render(struct rect *r)
{
static struct rect top;
static struct rect temp;
static struct rect middle;
static struct rect bottom;
ui_hsplit_t(r, 48, &top, &temp);
ui_hsplit_b(&temp, 32, &middle, &bottom);
tab_menu_render(&top);
middle_render(&middle);
return -ui_do_button_rect(&bottom, "Quit", 0, &bottom, draw_teewars_button, 0);
}
static int main_render()
2007-06-01 02:21:46 +00:00
{
2007-05-22 15:03:32 +00:00
static bool inited = false;
if (!inited)
{
inited = true;
client_serverbrowse_refresh(0);
2007-05-22 15:03:32 +00:00
}
static int scoll_index = 0, selected_index = -1;
2007-07-22 13:19:18 +00:00
int last_selected_index = selected_index;
do_server_list(20, 160, &scoll_index, &selected_index, 8);
2007-07-22 13:19:18 +00:00
ui_do_edit_box(address, 280, 425, 300, 36, address, sizeof(address));
if (last_selected_index != selected_index && selected_index != -1)
{
SERVER_INFO *server;
server = client_serverbrowse_get(selected_index);
2007-07-22 13:19:18 +00:00
strcpy(address, server->address);
2007-07-22 13:19:18 +00:00
}
2007-05-22 15:03:32 +00:00
2007-05-28 13:49:44 +00:00
static int refresh_button, join_button, quit_button;
2007-07-26 09:40:46 +00:00
static int use_lan = 0;
2007-10-07 20:05:55 +00:00
if (ui_do_button(&refresh_button, "Refresh", 0, 20, 460, 170, 48, draw_teewars_button, 0))
2007-07-26 09:40:46 +00:00
client_serverbrowse_refresh(use_lan);
ui_do_label(60, 420, "Search LAN ", 36);
int last_lan = use_lan;
use_lan = ui_do_check_box(&use_lan, 20, 424, 32, 32, use_lan);
if (use_lan != last_lan)
client_serverbrowse_refresh(use_lan);
2007-05-28 13:49:44 +00:00
if (ui_do_button(&join_button, "Join", 0, 620, 420, 128, 48, draw_teewars_button, 0))
2007-05-22 15:03:32 +00:00
{
2007-07-22 13:19:18 +00:00
client_connect(address);
2007-05-22 15:03:32 +00:00
return 1;
}
if (ui_do_button(&quit_button, "Quit", 0, 620, 490, 128, 48, draw_teewars_button, 0))
2007-05-22 15:03:32 +00:00
return -1;
2007-06-01 02:21:46 +00:00
static int settings_button;
if (ui_do_button(&settings_button, "Settings", 0, 400, 490, 170, 48, draw_teewars_button, 0))
2007-06-01 11:08:33 +00:00
{
config_copy = config;
2007-07-21 15:48:35 +00:00
screen = SCREEN_SETTINGS_GENERAL;
2007-06-01 11:08:33 +00:00
}
// render status text
if(client_serverbrowse_num_requests())
{
char buf[512];
sprintf(buf, "Refreshing %d servers...", client_serverbrowse_num_requests());
ui_do_label(20, 400, buf, 28);
}
else
{
char buf[512];
sprintf(buf, "%d of %d servers", client_serverbrowse_sorted_num(), client_serverbrowse_num());
ui_do_label(20, 400, buf, 28);
}
2007-06-01 02:21:46 +00:00
2007-09-30 11:55:42 +00:00
ui_do_edit_box(&config.b_filter_string, 20+150, 600-80, 200, 36, config.b_filter_string, sizeof(config.b_filter_string));
config.b_filter_empty = ui_do_check_box(&config.b_filter_empty, 20, 600-80, 32, 32, config.b_filter_empty);
config.b_filter_full = ui_do_check_box(&config.b_filter_full, 20+50, 600-80, 32, 32, config.b_filter_full);
config.b_filter_pw = ui_do_check_box(&config.b_filter_pw, 20+100, 600-80, 32, 32, config.b_filter_pw);
2007-10-07 20:05:55 +00:00
2007-06-01 02:21:46 +00:00
return 0;
}
2007-07-21 15:48:35 +00:00
static int settings_general_render()
{
2007-06-01 02:21:46 +00:00
// NAME
2007-07-21 15:48:35 +00:00
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));
2007-06-01 02:21:46 +00:00
2007-08-15 10:18:01 +00:00
// Dynamic camera
ui_do_label(column1_x, row2_y, "Dynamic Camera:", 36);
config_set_dynamic_camera(&config_copy, ui_do_check_box(&config_copy.dynamic_camera, column2_x + 55, row2_y + 4, 32, 32, config_copy.dynamic_camera));
2007-08-15 10:18:01 +00:00
2007-07-21 15:48:35 +00:00
return 0;
}
typedef void (*assign_func_callback)(CONFIGURATION *config, int value);
struct key_thing
{
char name[32];
int *key;
assign_func_callback assign_func;
};
2007-07-21 15:48:35 +00:00
static int settings_controls_render()
{
static int scroll_index = 0;
const key_thing keys[] =
{
{ "Move Left:", &config_copy.key_move_left, config_set_key_move_left },
{ "Move Right:", &config_copy.key_move_right, config_set_key_move_right },
{ "Jump:", &config_copy.key_jump, config_set_key_jump },
{ "Fire:", &config_copy.key_fire, config_set_key_fire },
{ "Hook:", &config_copy.key_hook, config_set_key_hook },
{ "Hammer:", &config_copy.key_weapon1, config_set_key_weapon1 },
{ "Pistol:", &config_copy.key_weapon2, config_set_key_weapon2 },
{ "Shotgun:", &config_copy.key_weapon3, config_set_key_weapon3 },
{ "Grenade:", &config_copy.key_weapon4, config_set_key_weapon4 },
{ "Next Weapon:", &config_copy.key_next_weapon, config_set_key_next_weapon },
{ "Prev. Weapon:", &config_copy.key_prev_weapon, config_set_key_prev_weapon },
2007-08-15 10:18:01 +00:00
{ "Emoticon:", &config_copy.key_emoticon, config_set_key_emoticon },
{ "Screenshot:", &config_copy.key_screenshot, config_set_key_screenshot },
};
const int key_count = sizeof(keys) / sizeof(key_thing);
2007-08-05 23:00:32 +00:00
for (int i = 0; i < 6; i++)
{
key_thing key = keys[i + scroll_index];
ui_do_label(column1_x, row1_y + 40 * i, key.name, 36);
key.assign_func(&config_copy, ui_do_key_reader(key.key, column2_x, row1_y + 40 * i, 150, 36, *key.key));
}
scroll_index = do_scroll_bar_vert(&scroll_index, 600, row1_y, 40 * 6, key_count - 6, scroll_index);
2007-08-05 23:00:32 +00:00
ui_do_label(column1_x, row1_y + 40 * 6, "Scroll wheel weapon switch", 22);
config_set_scroll_weapon(&config_copy, ui_do_check_box(&config_copy.scroll_weapon, column2_x + 50, row1_y + 40 * 6, 22, 22, config_copy.scroll_weapon));
2007-07-21 15:48:35 +00:00
return 0;
}
2007-06-01 02:21:46 +00:00
2007-07-26 18:51:01 +00:00
static const int MAX_RESOLUTIONS = 128;
static int settings_video_render_select_mode()
2007-07-21 15:48:35 +00:00
{
static VIDEO_MODE modes[MAX_RESOLUTIONS];
static int num_modes = -1;
if(num_modes == -1)
num_modes = gfx_get_video_modes(modes, MAX_RESOLUTIONS);
2007-07-26 18:51:01 +00:00
static int scroll_index = 0;
scroll_index = do_scroll_bar_vert(&scroll_index, 500, row1_y, 40 * 7, num_modes - 7, scroll_index);
2007-07-21 12:57:36 +00:00
2007-07-26 18:51:01 +00:00
for (int i = 0; i < 7; i++)
2007-06-01 11:08:33 +00:00
{
2007-07-26 18:51:01 +00:00
int index = i + scroll_index;
if(index >= num_modes)
break;
2007-07-26 18:51:01 +00:00
//key_thing key = keys[i + scroll_index];
int depth = modes[index].red+modes[index].green+modes[index].blue;
if(depth < 16)
depth = 16;
else if(depth > 16)
depth = 24;
char buf[128];
int s = 0;
if(modes[index].width == config_copy.gfx_screen_width &&
modes[index].height == config_copy.gfx_screen_height &&
depth == config_copy.gfx_color_depth)
2007-07-21 12:57:36 +00:00
{
2007-07-26 18:51:01 +00:00
s = 1;
2007-07-21 12:57:36 +00:00
}
2007-07-26 18:51:01 +00:00
sprintf(buf, "%c %dx%d %d bit %c", s?'>':' ', modes[index].width, modes[index].height, depth, s?'<':' ');
if(ui_do_button((void*)&modes[index], buf, 0,
column1_x, row1_y + 40 * i, 250, 32.0f, draw_teewars_button, 0))
2007-06-10 15:42:19 +00:00
{
2007-07-26 18:51:01 +00:00
// select
config_set_gfx_color_depth(&config_copy, depth);
config_set_gfx_screen_width(&config_copy, modes[index].width);
config_set_gfx_screen_height(&config_copy, modes[index].height);
2007-07-26 18:51:01 +00:00
screen = SCREEN_SETTINGS_VIDEO;
2007-06-10 15:42:19 +00:00
}
}
static int back_button = 0;
if(ui_do_button(&back_button, "Back", 0, column3_x, row7_y, 150, 32, draw_teewars_button, 0))
screen = SCREEN_SETTINGS_VIDEO;
return 0;
}
2007-06-10 15:42:19 +00:00
static int settings_video_render_custom()
{
ui_do_label(column1_x, row1_y, "Quality Textures:", 36);
config_set_gfx_texture_quality(&config_copy, ui_do_check_box(&config_copy.gfx_texture_quality, column3_x, row1_y + 5, 32, 32, config_copy.gfx_texture_quality));
ui_do_label(column1_x, row2_y, "Texture Compression:", 36);
config_set_gfx_texture_compression(&config_copy, ui_do_check_box(&config_copy.gfx_texture_compression, column3_x, row2_y + 5, 32, 32, config_copy.gfx_texture_compression));
ui_do_label(column1_x, row3_y, "High Detail:", 36);
config_set_gfx_high_detail(&config_copy, ui_do_check_box(&config_copy.gfx_high_detail, column3_x, row3_y + 5, 32, 32, config_copy.gfx_high_detail));
static int back_button = 0;
if(ui_do_button(&back_button, "Back", 0, column3_x, row7_y, 150, 32, draw_teewars_button, 0))
screen = SCREEN_SETTINGS_VIDEO;
2007-07-26 18:51:01 +00:00
return 0;
}
2007-07-21 15:48:35 +00:00
2007-07-26 18:51:01 +00:00
static int settings_video_render()
{
2007-07-21 15:48:35 +00:00
ui_do_label(column1_x, row1_y, "Mode:", 36);
2007-06-01 11:08:33 +00:00
2007-07-26 18:51:01 +00:00
char buf[128];
sprintf(buf, "%dx%d %d bit", config_copy.gfx_screen_width, config_copy.gfx_screen_height, config_copy.gfx_color_depth);
2007-07-26 18:51:01 +00:00
static int select_button = 0;
if(ui_do_button(&select_button, buf, 0, column2_x, row1_y, 300, 32, draw_teewars_button, 0))
2007-07-26 18:51:01 +00:00
screen = SCREEN_SETTINGS_VIDEO_SELECT_MODE;
// we need to draw these bottom up, to make overlapping work correctly
ui_do_label(column1_x, row2_y, "Fullscreen:", 36);
config_set_gfx_fullscreen(&config_copy, ui_do_check_box(&config_copy.gfx_fullscreen, column2_x, row2_y + 5, 32, 32, config_copy.gfx_fullscreen));
ui_do_label(column1_x, row3_y, "V-sync:", 36);
config_set_gfx_vsync(&config_copy, ui_do_check_box(&config_copy.gfx_vsync, column2_x, row3_y + 5, 32, 32, config_copy.gfx_vsync));
int current_level =
(config_copy.gfx_texture_quality<<8)|
(config_copy.gfx_texture_compression<<4)|
(config_copy.gfx_high_detail);
static const int opt_levels[3] = {0x101,0x001,0x010};
static const char *opts[] = {
"High",
"Medium",
"Low",
"Custom"};
int selected = 0; // custom per default
for(; selected < 3; selected++)
{
if(current_level == opt_levels[selected])
break;
}
ui_do_label(column1_x, row4_y, "Quality:", 36);
int new_level = ui_do_combo_box(&config_copy.gfx_texture_quality, column2_x, row4_y, 150, opts, 4, selected);
if(new_level < 3)
{
config_set_gfx_texture_quality(&config_copy, (opt_levels[new_level]>>8)&1);
config_set_gfx_texture_compression(&config_copy, (opt_levels[new_level]>>4)&1);
config_set_gfx_high_detail(&config_copy, opt_levels[new_level]&1);
}
static int custom_button=0;
if(ui_do_button(&custom_button, "Customize", 0, column3_x, row4_y, 130, 32, draw_teewars_button, 0))
screen = SCREEN_SETTINGS_VIDEO_CUSTOM;
ui_do_label(column1_x, row6_y + 50, "(A restart of the game is required for these settings to take effect.)", 20);
2007-07-21 15:48:35 +00:00
return 0;
}
static int settings_sound_render()
{
2007-07-21 17:43:00 +00:00
ui_do_label(column1_x, row1_y, "Volume:", 36);
config_set_volume(&config_copy, do_scroll_bar_horiz(&config_copy.volume, column2_x, row1_y, 200, 255, config_copy.volume));
2007-07-21 18:18:06 +00:00
snd_set_master_volume(config_copy.volume / 255.0f);
2007-07-21 17:43:00 +00:00
2007-07-21 15:48:35 +00:00
return 0;
}
2007-08-10 12:43:27 +00:00
extern void draw_round_rect(float x, float y, float w, float h, float r);
2007-08-14 22:48:49 +00:00
void send_changename_request(const char *name);
2007-08-10 12:43:27 +00:00
static int settings_render(bool ingame)
2007-07-21 15:48:35 +00:00
{
2007-08-10 12:43:27 +00:00
if (ingame)
{
gfx_blend_normal();
gfx_texture_set(-1);
gfx_quads_begin();
gfx_setcolor(0,0,0,0.5f);
2007-08-10 12:43:27 +00:00
draw_round_rect(10, 120, 780, 460, 30.0f);
gfx_quads_end();
}
2007-07-21 15:48:35 +00:00
static int general_button, controls_button, video_button, sound_button;
if (ui_do_button(&general_button, "General", 0, 30, 200, 170, 48, draw_teewars_button, 0))
2007-07-21 15:48:35 +00:00
screen = SCREEN_SETTINGS_GENERAL;
if (ui_do_button(&controls_button, "Controls", 0, 30, 250, 170, 48, draw_teewars_button, 0))
2007-07-21 15:48:35 +00:00
screen = SCREEN_SETTINGS_CONTROLS;
if (ui_do_button(&video_button, "Video", 0, 30, 300, 170, 48, draw_teewars_button, 0))
2007-07-21 15:48:35 +00:00
screen = SCREEN_SETTINGS_VIDEO;
if (ui_do_button(&sound_button, "Sound", 0, 30, 350, 170, 48, draw_teewars_button, 0))
2007-07-21 15:48:35 +00:00
screen = SCREEN_SETTINGS_SOUND;
switch (screen)
{
case SCREEN_SETTINGS_GENERAL: settings_general_render(); break;
case SCREEN_SETTINGS_CONTROLS: settings_controls_render(); break;
case SCREEN_SETTINGS_VIDEO: settings_video_render(); break;
2007-07-26 18:51:01 +00:00
case SCREEN_SETTINGS_VIDEO_SELECT_MODE: settings_video_render_select_mode(); break;
case SCREEN_SETTINGS_VIDEO_CUSTOM: settings_video_render_custom(); break;
2007-07-21 15:48:35 +00:00
case SCREEN_SETTINGS_SOUND: settings_sound_render(); break;
}
2007-06-01 11:08:33 +00:00
// SAVE BUTTON
static int save_button;
if (ui_do_button(&save_button, "Save", 0, 482, 490, 128, 48, draw_teewars_button, 0))
2007-06-01 11:08:33 +00:00
{
2007-08-14 22:48:49 +00:00
// did we change our name?
if (ingame && strcmp(config.player_name, config_copy.player_name) != 0)
send_changename_request(config_copy.player_name);
2007-06-01 11:08:33 +00:00
config = config_copy;
#ifdef CONF_PLATFORM_MACOSX
config_save("~/.teewars");
#else
config_save("default.cfg");
#endif
2007-07-21 15:48:35 +00:00
screen = SCREEN_MAIN;
2007-06-01 11:08:33 +00:00
}
// CANCEL BUTTON
static int cancel_button;
if (ui_do_button(&cancel_button, "Cancel", 0, 620, 490, 150, 48, draw_teewars_button, 0))
2007-07-21 18:18:06 +00:00
{
snd_set_master_volume(config.volume / 255.0f);
2007-07-21 15:48:35 +00:00
screen = SCREEN_MAIN;
2007-07-21 18:18:06 +00:00
}
2007-06-01 02:21:46 +00:00
2007-05-22 15:03:32 +00:00
return 0;
}
2007-08-10 12:43:27 +00:00
extern int gametype;
static int ingame_main_render()
{
static int menu_resume, menu_quit, menu_settings;
2007-08-10 12:43:27 +00:00
/*if (gametype == GAMETYPE_TDM)
{
char buf[128];
2007-08-10 12:43:27 +00:00
// Switch team
ui_do_label(100,100,"Switch Team",40);
sprintf(buf,"Team: %s",local_player->team ? "A" : "B");
if (ui_do_button(&menu_team, buf, 0, 30, 150, 170, 48, draw_teewars_button))
{
msg_pack_start(MSG_SWITCHTEAM, MSGFLAG_VITAL);
msg_pack_end();
client_send_msg();
menu_active = false;
}
}*/
const int column1_x = 275;
const int row1_y = 200;
const int row2_y = row1_y + 60;
const int row3_y = row2_y + 60;
const int row4_y = row3_y + 60;
gfx_blend_normal();
gfx_texture_set(-1);
gfx_quads_begin();
gfx_setcolor(0,0,0,0.5f);
2007-08-10 12:43:27 +00:00
draw_round_rect(170, 120, 460, 360, 30.0f);
gfx_quads_end();
ui_do_image(data->images[IMAGE_BANNER].id, 214, 150, 384, 96);
if (ui_do_button(&menu_resume, "Resume Game", 0, column1_x, row2_y, 250, 48, draw_teewars_button, 0))
2007-08-10 12:43:27 +00:00
{
return 1;
}
if (ui_do_button(&menu_quit, "Disconnect", 0, column1_x, row4_y, 250, 48, draw_teewars_button, 0))
2007-08-10 12:43:27 +00:00
{
client_disconnect();
return 1;
}
if (ui_do_button(&menu_settings, "Settings", 0, column1_x, row3_y, 250, 48, draw_teewars_button, 0))
2007-08-10 12:43:27 +00:00
{
config_copy = config;
screen = SCREEN_SETTINGS_GENERAL;
}
return 0;
}
2007-10-09 09:04:57 +00:00
extern "C" double extra_kerning[256*256];
2007-06-10 17:25:08 +00:00
2007-07-21 15:48:35 +00:00
static int kerning_render()
2007-06-10 17:25:08 +00:00
{
static bool loaded = false;
2007-06-10 21:35:59 +00:00
static char text[32] = {0};
2007-06-10 17:25:08 +00:00
if (!loaded)
{
// TODO: fix me
/*
2007-06-10 17:25:08 +00:00
file_stream file;
if (file.open_r("kerning.txt"))
{
line_stream lstream(&file);
int i = 0;
char *line;
while ((line = lstream.get_line()))
extra_kerning[i++] = atof(line);
file.close();
}
2007-06-10 20:00:58 +00:00
if (file.open_r("tracking.txt"))
{
line_stream lstream(&file);
char *line;
for (int i = 0; i < 256; i++)
{
line = lstream.get_line();
current_font->m_CharStartTable[i] = atof(line);
line = lstream.get_line();
current_font->m_CharEndTable[i] = atof(line);
}
file.close();
}
*/
2007-06-10 20:00:58 +00:00
2007-06-10 17:25:08 +00:00
loaded = true;
}
2007-06-10 21:35:59 +00:00
ui_do_edit_box(text, 160, 20, 300, 36, text, sizeof(text));
2007-06-10 17:25:08 +00:00
2007-06-10 21:35:59 +00:00
ui_do_label(160, 250, text, 70);
2007-06-10 17:25:08 +00:00
int len = strlen(text);
for (int i = 0; i < len-1; i++)
{
char s[3] = {0};
s[0] = text[i];
s[1] = text[i+1];
ui_do_label(10, 30 * i + 10, s, 45);
int index = s[0] + s[1] * 256;
// less
if (ui_do_button((void *)(100 + i * 2), "", 0, 50, 30 * i + 10 + 20, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_LEFT))
2007-06-10 17:25:08 +00:00
{
extra_kerning[index] -= 0.01;
}
// more
if (ui_do_button((void *)(100 + i * 2 + 1), "", 0, 66, 30 * i + 10 + 20, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_RIGHT))
2007-06-10 17:25:08 +00:00
{
extra_kerning[index] += 0.01;
}
char num[16];
sprintf(num, "(%f)", extra_kerning[index]);
2007-06-10 21:35:59 +00:00
ui_do_label(84, 30 * i + 30, num, 12);
2007-06-10 17:25:08 +00:00
}
2007-06-10 20:00:58 +00:00
for (int i = 0; i < len; i++)
{
char s[2] = {0};
s[0] = text[i];
ui_do_label(700, 35 * i + 10, s, 45);
gfx_blend_normal();
gfx_texture_set(-1);
gfx_quads_begin();
gfx_setcolor(0,0,0,0.5);
2007-06-10 20:00:58 +00:00
gfx_quads_drawTL(700,35*i+20,1,30);
2007-06-11 19:59:29 +00:00
gfx_quads_drawTL(700+45*(current_font->m_CharEndTable[(int)s[0]]-current_font->m_CharStartTable[(int)s[0]]),35*i+20,1,30);
2007-06-10 20:00:58 +00:00
gfx_quads_end();
// less
if (ui_do_button((void *)(200 + i * 2), "", 0, 650, 35 * i + 10 + 15, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_LEFT))
2007-06-10 20:00:58 +00:00
{
2007-07-13 21:22:45 +00:00
current_font->m_CharStartTable[(int)s[0]] -= 0.01f;
2007-06-10 20:00:58 +00:00
}
// more
if (ui_do_button((void *)(200 + i * 2 + 1), "", 0, 666, 35 * i + 10 + 15, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_RIGHT))
2007-06-10 20:00:58 +00:00
{
2007-07-13 21:22:45 +00:00
current_font->m_CharStartTable[(int)s[0]] += 0.01f;
2007-06-10 20:00:58 +00:00
}
2007-06-10 21:35:59 +00:00
char num[16];
2007-06-11 19:59:29 +00:00
sprintf(num, "(%f)", current_font->m_CharStartTable[(int)s[0]]);
2007-06-10 21:35:59 +00:00
ui_do_label(645, 35 * i + 40, num, 12);
2007-06-10 20:00:58 +00:00
// less
if (ui_do_button((void *)(300 + i * 2), "", 0, 750, 35 * i + 10 + 15, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_LEFT))
2007-06-10 20:00:58 +00:00
{
2007-07-13 21:22:45 +00:00
current_font->m_CharEndTable[(int)s[0]] -= 0.01f;
2007-06-10 20:00:58 +00:00
}
// more
if (ui_do_button((void *)(300 + i * 2 + 1), "", 0, 766, 35 * i + 10 + 15, 16, 16, draw_single_part_button, (void *)GUI_MISC_SLIDER_BIG_ARROW_RIGHT))
2007-06-10 20:00:58 +00:00
{
2007-07-13 21:22:45 +00:00
current_font->m_CharEndTable[(int)s[0]] += 0.01f;
2007-06-10 20:00:58 +00:00
}
2007-06-11 19:59:29 +00:00
sprintf(num, "(%f)", current_font->m_CharEndTable[(int)s[0]]);
2007-06-10 21:35:59 +00:00
ui_do_label(745, 35 * i + 40, num, 12);
2007-06-10 20:00:58 +00:00
}
2007-06-10 17:25:08 +00:00
// SAVE BUTTON
static int save_button;
if (ui_do_button(&save_button, "Save", 0, 482, 520, 128, 48, draw_teewars_button, 0))
2007-06-10 17:25:08 +00:00
{
// TODO: fix or remove me
/*
2007-06-10 17:25:08 +00:00
file_stream file;
if (file.open_w("kerning.txt"))
{
char t[16];
for (int i = 0; i < 256*256; i++)
{
sprintf(t, "%f\n", extra_kerning[i]);
file.write(t, strlen(t));
}
file.close();
}
2007-06-10 20:00:58 +00:00
if (file.open_w("tracking.txt"))
{
char t[16];
for (int i = 0; i < 256; i++)
{
sprintf(t, "%f\n", current_font->m_CharStartTable[i]);
file.write(t, strlen(t));
sprintf(t, "%f\n", current_font->m_CharEndTable[i]);
file.write(t, strlen(t));
}
file.close();
}
*/
2007-06-10 20:00:58 +00:00
2007-06-10 17:25:08 +00:00
//screen = 0;
}
// CANCEL BUTTON
static int cancel_button;
if (ui_do_button(&cancel_button, "Cancel", 0, 620, 520, 150, 48, draw_teewars_button, 0))
2007-07-21 15:48:35 +00:00
screen = SCREEN_MAIN;
2007-06-10 17:25:08 +00:00
return 0;
}
int render_popup(const char *caption, const char *text, const char *button_text)
{
float tw;
float w = 700;
float h = 300;
float x = 800/2-w/2;
float y = 600/2-h/2;
gfx_blend_normal();
gfx_texture_set(-1);
gfx_quads_begin();
gfx_setcolor(0,0,0,0.50f);
draw_round_rect(x, y, w, h, 40.0f);
gfx_quads_end();
tw = gfx_pretty_text_width(48.0f, caption, -1);
ui_do_label(x+w/2-tw/2, y+20, caption, 48.0f);
tw = gfx_pretty_text_width(32.0f, text, -1);
2007-08-22 21:13:33 +00:00
gfx_pretty_text(x+w/2-tw/2, y+130, 32.0f, text, -1);
if(button_text)
{
static int back_button = 0;
if(ui_do_button(&back_button, button_text, 0, x+w/2-100, y+220, 200, 48, draw_teewars_button, 0))
return 1;
if(inp_key_down(KEY_ESC) || inp_key_down(KEY_ENTER))
return 1;
}
return 0;
}
static int disconnected_render()
{
if(strlen(client_error_string()) == 0)
screen = SCREEN_MAIN;
else
{
if(render_popup("Disconnected", client_error_string(), "Back"))
screen = SCREEN_MAIN;
}
return 0;
}
static int connecting_render()
{
char buf[256];
sprintf(buf, "Server: %s", address);
if(render_popup("Connecting", buf, "Abort"))
{
client_disconnect();
screen = SCREEN_MAIN;
}
return 0;
}
void menu_do_disconnected()
{
screen = SCREEN_DISCONNECTED;
}
void menu_do_connecting()
{
screen = SCREEN_CONNECTING;
}
2007-08-10 12:43:27 +00:00
void menu_do_connected()
2007-06-01 02:21:46 +00:00
{
2007-08-10 12:43:27 +00:00
screen = SCREEN_MAIN;
}
static int menu_render(bool ingame)
{
if (!ingame)
{
// background color
gfx_clear(0.65f,0.78f,0.9f);
//gfx_clear(89/255.f,122/255.f,0.0);
2007-06-01 02:21:46 +00:00
2007-08-10 12:43:27 +00:00
// GUI coordsys
gfx_mapscreen(0,0,800.0f,600.0f);
2007-06-01 02:21:46 +00:00
2007-08-10 12:43:27 +00:00
static int64 start = time_get();
2007-06-01 02:21:46 +00:00
2007-08-10 12:43:27 +00:00
float t = double(time_get() - start) / double(time_freq());
gfx_mapscreen(0,0,1600.0f,1200.0f);
draw_background(t);
gfx_mapscreen(0,0,800.0f,600.0f);
2007-06-01 02:21:46 +00:00
2007-08-10 12:43:27 +00:00
if (screen != SCREEN_KERNING)
{
ui_do_image(data->images[IMAGE_BANNER].id, 200, 20, 512, 128);
ui_do_label(20.0f, 600.0f-40.0f, "Version: " TEEWARS_VERSION, 36);
2007-08-22 21:13:33 +00:00
if(config.debug)
ui_do_label(20.0f, 600.0f-60.0f, "Nethash: " TEEWARS_NETVERSION_HASH, 24);
2007-08-10 12:43:27 +00:00
}
}
else
2007-06-10 21:35:59 +00:00
{
2007-08-10 12:43:27 +00:00
gfx_mapscreen(0, 0, 800, 600);
2007-06-10 21:35:59 +00:00
}
2007-06-01 02:21:46 +00:00
2007-10-07 20:13:30 +00:00
if(config.dbg_new_gui)
2007-10-07 20:05:55 +00:00
{
2007-10-07 20:13:30 +00:00
struct rect *screen = ui_screen();
2007-10-07 20:05:55 +00:00
2007-10-07 20:13:30 +00:00
static float scale = 1.0f;
2007-10-07 20:05:55 +00:00
2007-10-07 20:13:30 +00:00
if (inp_key_pressed('I'))
scale += 0.01;
if (inp_key_pressed('O'))
scale -= 0.01;
2007-10-07 20:05:55 +00:00
2007-10-07 20:13:30 +00:00
dbg_msg("year", "%f", scale);
2007-10-07 20:05:55 +00:00
2007-10-07 20:13:30 +00:00
ui_scale(scale);
int retn = ui_menu_render(screen);
2007-10-07 20:05:55 +00:00
2007-10-07 20:13:30 +00:00
gfx_texture_set(-1);
gfx_lines_begin();
ui_foreach_rect(draw_rect);
gfx_lines_end();
2007-10-07 20:05:55 +00:00
2007-10-07 20:13:30 +00:00
return retn;
}
else
{
switch (screen)
{
case SCREEN_MAIN: return ingame ? ingame_main_render() : main_render();
case SCREEN_DISCONNECTED: return disconnected_render();
case SCREEN_CONNECTING: return connecting_render();
case SCREEN_SETTINGS_GENERAL:
case SCREEN_SETTINGS_CONTROLS:
case SCREEN_SETTINGS_VIDEO:
case SCREEN_SETTINGS_VIDEO_SELECT_MODE:
case SCREEN_SETTINGS_VIDEO_CUSTOM:
case SCREEN_SETTINGS_SOUND: return settings_render(ingame);
case SCREEN_KERNING: return kerning_render();
default: dbg_msg("menu", "invalid screen selected..."); return 0;
}
2007-10-07 20:05:55 +00:00
}
2007-06-01 02:21:46 +00:00
}
extern "C" void modmenu_init() // TODO: nastyness
2007-05-22 15:03:32 +00:00
{
2007-07-16 19:39:04 +00:00
// TODO: should be removed
current_font->font_texture = gfx_load_texture("data/big_font.png");
2007-05-22 15:03:32 +00:00
}
void modmenu_shutdown()
{
}
extern "C" int modmenu_render(int ingame) // TODO: nastyness
2007-05-22 15:03:32 +00:00
{
static int mouse_x = 0;
static int mouse_y = 0;
// handle mouse movement
2007-07-16 19:39:04 +00:00
float mx, my;
2007-05-22 15:03:32 +00:00
{
int rx, ry;
inp_mouse_relative(&rx, &ry);
mouse_x += rx;
mouse_y += ry;
if(mouse_x < 0) mouse_x = 0;
if(mouse_y < 0) mouse_y = 0;
if(mouse_x > gfx_screenwidth()) mouse_x = gfx_screenwidth();
if(mouse_y > gfx_screenheight()) mouse_y = gfx_screenheight();
// update the ui
2007-05-28 13:49:44 +00:00
mx = (mouse_x/(float)gfx_screenwidth())*800.0f;
my = (mouse_y/(float)gfx_screenheight())*600.0f;
2007-05-22 15:03:32 +00:00
int buttons = 0;
if(inp_key_pressed(KEY_MOUSE_1)) buttons |= 1;
if(inp_key_pressed(KEY_MOUSE_2)) buttons |= 2;
if(inp_key_pressed(KEY_MOUSE_3)) buttons |= 4;
2007-05-22 15:03:32 +00:00
ui_update(mx,my,mx*3.0f,my*3.0f,buttons);
}
2007-06-01 02:21:46 +00:00
//int r = menu_render(server_address, str, max_len);
2007-08-10 12:43:27 +00:00
int r = menu_render(ingame);
2007-05-22 15:03:32 +00:00
gfx_texture_set(data->images[IMAGE_CURSOR].id);
2007-05-22 15:03:32 +00:00
gfx_quads_begin();
gfx_setcolor(1,1,1,1);
2007-07-21 18:18:06 +00:00
gfx_quads_drawTL(mx,my,24,24);
2007-05-22 15:03:32 +00:00
gfx_quads_end();
inp_clear();
2007-05-22 15:03:32 +00:00
return r;
}