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 <baselib/system.h>
|
|
|
|
#include <baselib/stream/file.h>
|
|
|
|
#include <baselib/stream/line.h>
|
|
|
|
|
2007-05-28 13:49:44 +00:00
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
#include <baselib/system.h>
|
2007-06-10 15:19:04 +00:00
|
|
|
#include <baselib/input.h>
|
2007-05-22 15:03:32 +00:00
|
|
|
#include <baselib/network.h>
|
|
|
|
|
2007-05-24 20:54:08 +00:00
|
|
|
#include <engine/interface.h>
|
|
|
|
#include <engine/versions.h>
|
|
|
|
#include "../mapres.h"
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-05-24 20:54:08 +00:00
|
|
|
#include <engine/client/ui.h>
|
|
|
|
#include "mapres_image.h"
|
|
|
|
#include "mapres_tilemap.h"
|
2007-06-01 11:17:10 +00:00
|
|
|
#include <engine/config.h>
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-07-14 23:08:17 +00:00
|
|
|
#include "data.h"
|
|
|
|
|
2007-07-16 16:48:16 +00:00
|
|
|
static data_container *data;
|
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
using namespace baselib;
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
MENU
|
|
|
|
*********************************************************/
|
|
|
|
|
2007-05-27 18:14:24 +00:00
|
|
|
enum gui_tileset_enum
|
|
|
|
{
|
|
|
|
tileset_regular,
|
|
|
|
tileset_hot,
|
|
|
|
tileset_active,
|
|
|
|
tileset_inactive
|
|
|
|
};
|
|
|
|
|
|
|
|
int gui_tileset_texture;
|
|
|
|
|
2007-07-16 16:48:16 +00:00
|
|
|
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:
|
2007-07-16 16:48:16 +00:00
|
|
|
break;
|
2007-05-27 18:14:24 +00:00
|
|
|
case tileset_hot:
|
2007-07-16 16:48:16 +00:00
|
|
|
areax += 192; areay += 192; break;
|
2007-05-27 18:14:24 +00:00
|
|
|
case tileset_active:
|
2007-07-16 16:48:16 +00:00
|
|
|
areay += 192; break;
|
2007-05-27 18:14:24 +00:00
|
|
|
case tileset_inactive:
|
2007-07-16 16:48:16 +00:00
|
|
|
areax += 192; break;
|
2007-05-27 18:14:24 +00:00
|
|
|
default:
|
|
|
|
dbg_msg("menu", "invalid tileset given to draw_part");
|
|
|
|
}
|
2007-07-16 16:48:16 +00:00
|
|
|
|
|
|
|
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(gui_tileset_texture);
|
|
|
|
gfx_quads_begin();
|
|
|
|
gfx_quads_setcolor(1,1,1,1);
|
|
|
|
gfx_quads_setsubset(
|
2007-07-16 16:48:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-07-16 16:48:16 +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
|
|
|
{
|
2007-07-16 16:48:16 +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
|
|
|
}
|
|
|
|
|
2007-07-16 16:48:16 +00:00
|
|
|
void draw_part(int part_type, gui_tileset_enum tileset, float x, float y)
|
2007-05-27 18:14:24 +00:00
|
|
|
{
|
2007-07-16 16:48:16 +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
|
|
|
}
|
|
|
|
|
2007-07-16 16:48:16 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
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-16 16:48:16 +00:00
|
|
|
draw_area(tileset, ax, by, bx-ax, 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));
|
|
|
|
draw_area(tileset, cx, by, dx-cx, cy-by, x+w-(dx-cx), y+(by-ay), dx-cx, h-(by-ay)-(dy-cy));
|
2007-05-28 13:49:44 +00:00
|
|
|
|
2007-07-16 16:48:16 +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-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;
|
|
|
|
float gfx_pretty_text_width(float size, const char *text);
|
|
|
|
|
|
|
|
void draw_scrolling_background(int id, float w, float h, float t)
|
|
|
|
{
|
2007-06-01 02:21:46 +00:00
|
|
|
float tx = w/512.0f;
|
|
|
|
float ty = h/512.0f;
|
2007-05-22 15:03:32 +00:00
|
|
|
|
|
|
|
float start_x = fmod(t, 1.0f);
|
|
|
|
float start_y = 1.0f - fmod(t*0.8f, 1.0f);
|
|
|
|
|
|
|
|
gfx_blend_normal();
|
|
|
|
gfx_texture_set(id);
|
|
|
|
gfx_quads_begin();
|
|
|
|
gfx_quads_setcolor(1,1,1,1);
|
|
|
|
gfx_quads_setsubset(
|
|
|
|
start_x, // startx
|
|
|
|
start_y, // starty
|
|
|
|
start_x+tx, // endx
|
|
|
|
start_y+ty); // endy
|
|
|
|
gfx_quads_drawTL(0.0f,0.0f,w,h);
|
|
|
|
gfx_quads_end();
|
|
|
|
}
|
|
|
|
|
2007-06-10 21:35:59 +00:00
|
|
|
static int background_texture;
|
|
|
|
static int teewars_banner_texture;
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-06-10 21:35:59 +00:00
|
|
|
static int music_menu;
|
|
|
|
static int music_menu_id = -1;
|
2007-05-22 15:03:32 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2007-07-16 16:48:16 +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)
|
|
|
|
{
|
2007-07-16 16:48:16 +00:00
|
|
|
int box_type;
|
2007-07-13 13:40:04 +00:00
|
|
|
if ((int)((char*)extra-(char*)0))
|
2007-07-16 16:48:16 +00:00
|
|
|
box_type = GUI_BOX_SCREEN_INFO;
|
2007-06-01 02:21:46 +00:00
|
|
|
else
|
2007-07-16 16:48:16 +00:00
|
|
|
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-05-28 13:49:44 +00:00
|
|
|
float text_width = gfx_pretty_text_width(46.f, text);
|
2007-05-27 18:14:24 +00:00
|
|
|
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
|
|
|
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
|
|
|
|
2007-07-16 16:48:16 +00:00
|
|
|
draw_box(GUI_BOX_BUTTON, tileset, x, y, w, h);
|
2007-05-27 18:14:24 +00:00
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
ui_do_label(x + w/2 - text_width/2, y, text, 46);
|
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];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct server_list
|
|
|
|
{
|
|
|
|
server_info infos[10];
|
|
|
|
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-06-10 15:19:04 +00:00
|
|
|
static bool can_be_selected = true;
|
2007-06-01 02:21:46 +00:00
|
|
|
int inside = ui_mouse_inside(x, y, w, h);
|
|
|
|
int new_key = key;
|
|
|
|
|
2007-06-10 15:19:04 +00:00
|
|
|
if (!ui_mouse_button(0) && !can_be_selected)
|
|
|
|
can_be_selected = true;
|
|
|
|
|
|
|
|
if (can_be_selected)
|
2007-06-01 02:21:46 +00:00
|
|
|
{
|
2007-06-10 15:19:04 +00:00
|
|
|
if (inside)
|
|
|
|
{
|
|
|
|
ui_set_hot_item(id);
|
2007-06-01 02:21:46 +00:00
|
|
|
|
2007-06-10 15:19:04 +00:00
|
|
|
if (ui_mouse_button(0) && ui_active_item() != id)
|
|
|
|
{
|
|
|
|
ui_set_active_item(id);
|
|
|
|
can_be_selected = false;
|
|
|
|
}
|
|
|
|
}
|
2007-06-01 02:21:46 +00:00
|
|
|
}
|
|
|
|
|
2007-06-10 15:19:04 +00:00
|
|
|
if (can_be_selected)
|
2007-06-01 02:21:46 +00:00
|
|
|
{
|
2007-06-10 15:19:04 +00:00
|
|
|
if (ui_active_item() == id)
|
2007-06-01 02:21:46 +00:00
|
|
|
{
|
2007-06-10 15:19:04 +00:00
|
|
|
int k = input::last_key();
|
|
|
|
if (k)
|
|
|
|
{
|
|
|
|
new_key = k;
|
|
|
|
ui_set_active_item(0);
|
|
|
|
can_be_selected = false;
|
|
|
|
}
|
2007-06-01 02:21:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw
|
2007-07-16 16:48:16 +00:00
|
|
|
draw_box(GUI_BOX_SCREEN_INFO, tileset_regular, x, y, w, h);
|
2007-06-01 02:21:46 +00:00
|
|
|
|
2007-06-10 15:19:04 +00:00
|
|
|
const char *str = input::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);
|
|
|
|
ui_do_label(x + 10 + w, y, "_", 36);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_key;
|
|
|
|
}
|
|
|
|
|
2007-06-10 15:42:19 +00:00
|
|
|
int ui_do_combo_box(void *id, float x, float y, float w, char *lines, int line_count, int selected_index)
|
2007-06-01 02:21:46 +00:00
|
|
|
{
|
|
|
|
float line_height = 36.0f;
|
|
|
|
|
|
|
|
int inside = (ui_active_item() == id) ? ui_mouse_inside(x, y, w, line_count * line_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
|
|
|
|
|
|
|
if (ui_active_item() == id)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < line_count; i++)
|
|
|
|
{
|
2007-07-16 16:48:16 +00:00
|
|
|
int box_type;
|
2007-06-01 02:21:46 +00:00
|
|
|
if (inside && hover_index == i)
|
2007-07-16 16:48:16 +00:00
|
|
|
box_type = GUI_BOX_SCREEN_INFO;
|
2007-06-01 02:21:46 +00:00
|
|
|
else
|
2007-07-16 16:48:16 +00:00
|
|
|
box_type = GUI_BOX_SCREEN_LIST;
|
2007-06-01 02:21:46 +00:00
|
|
|
|
2007-07-16 16:48:16 +00:00
|
|
|
draw_box(box_type, tileset_regular, x, y + i * line_height, w, line_height);
|
2007-06-10 15:42:19 +00:00
|
|
|
ui_do_label(x + 10 + 10, y + i * line_height, lines + 128 * i, 36);
|
2007-06-01 02:21:46 +00:00
|
|
|
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
|
|
|
|
{
|
2007-07-16 16:48:16 +00:00
|
|
|
draw_box(GUI_BOX_SCREEN_LIST, tileset_regular, x, y, w, line_height);
|
2007-06-10 15:42:19 +00:00
|
|
|
ui_do_label(x + 10, y, lines + 128 * selected_index, 36);
|
2007-06-01 02:21:46 +00:00
|
|
|
|
|
|
|
if (inside && ui_mouse_button(0))
|
|
|
|
ui_set_active_item(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(inside)
|
|
|
|
{
|
|
|
|
ui_set_hot_item(id);
|
|
|
|
|
|
|
|
if(ui_mouse_button(0))
|
|
|
|
ui_set_active_item(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui_active_item() == id)
|
|
|
|
{
|
2007-06-10 15:19:04 +00:00
|
|
|
int c = input::last_char();
|
|
|
|
int k = input::last_key();
|
2007-05-22 15:03:32 +00:00
|
|
|
int len = strlen(str);
|
2007-06-11 19:59:29 +00:00
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
if (c >= 32 && c < 128)
|
|
|
|
{
|
|
|
|
if (len < str_size - 1)
|
|
|
|
{
|
|
|
|
str[len] = c;
|
|
|
|
str[len+1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-10 15:19:04 +00:00
|
|
|
if (k == input::backspace)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
if (len > 0)
|
|
|
|
str[len-1] = 0;
|
|
|
|
}
|
|
|
|
r = 1;
|
|
|
|
}
|
|
|
|
|
2007-07-16 16:48:16 +00:00
|
|
|
draw_box(GUI_BOX_SCREEN_TEXTBOX, 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-05-22 15:03:32 +00:00
|
|
|
if (ui_active_item() == id)
|
|
|
|
{
|
2007-05-28 13:49:44 +00:00
|
|
|
float w = gfx_pretty_text_width(36.0f, str);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_scroll_bar(void *id, float x, float y, float height, int steps, int last_index)
|
|
|
|
{
|
|
|
|
int r = last_index;
|
|
|
|
|
2007-05-28 13:49:44 +00:00
|
|
|
static int up_button;
|
|
|
|
static int down_button;
|
|
|
|
|
2007-07-16 16:48:16 +00:00
|
|
|
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;
|
|
|
|
}
|
2007-07-16 16:48:16 +00:00
|
|
|
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-05-28 13:49:44 +00:00
|
|
|
float pos = ui_mouse_y() - y - 16;
|
|
|
|
float perc = pos / (height - 32);
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-05-27 00:47:07 +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);
|
|
|
|
}
|
|
|
|
|
2007-07-16 16:48:16 +00:00
|
|
|
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-16 16:48:16 +00:00
|
|
|
draw_part(GUI_MISC_SLIDER_BIG_HANDLE_HORIZ, tileset_regular, x, y + 16 + r * ((height - 64) / steps), 32, 16);
|
2007-05-27 18:14:24 +00:00
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
static int do_server_list(server_list *list, float x, float y, 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 r = -1;
|
|
|
|
|
|
|
|
for (int i = 0; i < visible_items; i++)
|
|
|
|
{
|
|
|
|
int item_index = i + list->scroll_index;
|
2007-06-01 02:21:46 +00:00
|
|
|
if (item_index >= list->active_count);
|
|
|
|
//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 = &list->infos[item_index];
|
|
|
|
|
|
|
|
bool clicked = false;
|
2007-06-01 02:21:46 +00:00
|
|
|
clicked = ui_do_button(item, item->name, 0, x, y + i * item_height + i * spacing, item_width, item_height, draw_menu_button, (list->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", item->players, item->max_players);
|
|
|
|
|
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;
|
|
|
|
list->selected_index = item_index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-28 13:49:44 +00:00
|
|
|
list->scroll_index = do_scroll_bar(&list->scroll_index, x + real_width - 16, y, real_height, list->active_count - visible_items, list->scroll_index);
|
2007-05-22 15:03:32 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
static char *read_int(char *buffer, int *value)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
*value = buffer[0] << 24;
|
|
|
|
*value |= buffer[1] << 16;
|
|
|
|
*value |= buffer[2] << 8;
|
|
|
|
*value |= buffer[3];
|
|
|
|
|
|
|
|
return buffer + 4;
|
|
|
|
}
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
static char *read_netaddr(char *buffer, netaddr4 *addr)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
addr->ip[0] = *buffer++;
|
|
|
|
addr->ip[1] = *buffer++;
|
|
|
|
addr->ip[2] = *buffer++;
|
|
|
|
addr->ip[3] = *buffer++;
|
|
|
|
|
|
|
|
int port;
|
|
|
|
buffer = read_int(buffer, &port);
|
|
|
|
|
|
|
|
addr->port = port;
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
static void refresh_list(server_list *list)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
netaddr4 addr;
|
|
|
|
netaddr4 me(0, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
list->selected_index = -1;
|
|
|
|
|
|
|
|
if (net_host_lookup(MASTER_SERVER_ADDRESS, MASTER_SERVER_PORT, &addr) == 0)
|
|
|
|
{
|
|
|
|
socket_tcp4 sock;
|
|
|
|
sock.open(&me);
|
|
|
|
|
|
|
|
//sock.set_non_blocking();
|
|
|
|
|
|
|
|
// try and connect with a timeout of 1 second
|
|
|
|
if (sock.connect_non_blocking(&addr))
|
|
|
|
{
|
|
|
|
char data[256];
|
|
|
|
int total_received = 0;
|
|
|
|
int received;
|
|
|
|
|
|
|
|
int master_server_version = -1;
|
|
|
|
int server_count = -1;
|
|
|
|
|
|
|
|
// read header
|
|
|
|
while (total_received < 12 && (received = sock.recv(data + total_received, 12 - total_received)) > 0)
|
|
|
|
total_received += received;
|
|
|
|
|
|
|
|
// see if we have the header
|
|
|
|
if (total_received == 12)
|
|
|
|
{
|
|
|
|
int signature;
|
|
|
|
read_int(data, &signature);
|
|
|
|
|
|
|
|
// check signature
|
2007-05-27 10:54:33 +00:00
|
|
|
if(signature == 'TWSL')
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
read_int(data + 4, &master_server_version);
|
|
|
|
read_int(data + 8, &server_count);
|
|
|
|
|
|
|
|
// TODO: handle master server version O.o
|
|
|
|
|
|
|
|
const int server_info_size = 212;
|
|
|
|
|
|
|
|
list->active_count = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < server_count; i++)
|
|
|
|
{
|
|
|
|
total_received = 0;
|
|
|
|
|
|
|
|
// read data for a server
|
|
|
|
while (sock.is_connected() && total_received < server_info_size && (received = sock.recv(data + total_received, server_info_size - total_received)) > 0)
|
|
|
|
total_received += received;
|
|
|
|
|
|
|
|
// check if we got enough data
|
|
|
|
if (total_received == server_info_size)
|
|
|
|
{
|
|
|
|
char *d = data;
|
|
|
|
|
|
|
|
server_info *info = &list->infos[i];
|
|
|
|
|
|
|
|
d = read_int(d, &info->version);
|
|
|
|
d = read_netaddr(d, &info->address);
|
|
|
|
|
|
|
|
//dbg_msg("menu/got_serverinfo", "IP: %i.%i.%i.%i:%i", (int)info->address.ip[0], (int)info->address.ip[1], (int)info->address.ip[2], (int)info->address.ip[3], info->address.port);
|
|
|
|
|
|
|
|
d = read_int(d, &info->players);
|
|
|
|
d = read_int(d, &info->max_players);
|
|
|
|
memcpy(info->name, d, 128);
|
|
|
|
d += 128;
|
|
|
|
memcpy(info->map, d, 64);
|
|
|
|
|
|
|
|
// let's be safe.
|
|
|
|
info->name[128] = 0;
|
|
|
|
info->map[64] = 0;
|
|
|
|
|
|
|
|
++list->active_count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list->scroll_index >= list->active_count)
|
|
|
|
list->scroll_index = list->active_count - 1;
|
|
|
|
|
|
|
|
if (list->scroll_index < 0)
|
|
|
|
list->scroll_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sock.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
static int screen = 0;
|
2007-06-01 11:08:33 +00:00
|
|
|
static configuration config_copy;
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
static int main_screen_render(netaddr4 *server_address)
|
|
|
|
{
|
2007-05-22 15:03:32 +00:00
|
|
|
static server_list list;
|
|
|
|
static bool inited = false;
|
|
|
|
|
|
|
|
if (!inited)
|
|
|
|
{
|
|
|
|
list.info_count = 256;
|
|
|
|
|
|
|
|
list.scroll_index = 0;
|
|
|
|
list.selected_index = -1;
|
|
|
|
|
|
|
|
inited = true;
|
|
|
|
|
|
|
|
refresh_list(&list);
|
|
|
|
}
|
|
|
|
|
2007-05-28 13:49:44 +00:00
|
|
|
do_server_list(&list, 20, 160, 8);
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-05-28 13:49:44 +00:00
|
|
|
static int refresh_button, join_button, quit_button;
|
|
|
|
|
|
|
|
if (ui_do_button(&refresh_button, "Refresh", 0, 440, 420, 170, 48, draw_teewars_button))
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
refresh_list(&list);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list.selected_index == -1)
|
|
|
|
{
|
2007-05-28 13:49:44 +00:00
|
|
|
ui_do_button(&join_button, "Join", 0, 620, 420, 128, 48, draw_teewars_button, (void *)1);
|
2007-05-22 15:03:32 +00:00
|
|
|
}
|
2007-05-28 13:49:44 +00:00
|
|
|
else if (ui_do_button(&join_button, "Join", 0, 620, 420, 128, 48, draw_teewars_button))
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
*server_address = list.infos[list.selected_index].address;
|
|
|
|
|
|
|
|
dbg_msg("menu/join_button", "IP: %i.%i.%i.%i:%i", (int)server_address->ip[0], (int)server_address->ip[1], (int)server_address->ip[2], (int)server_address->ip[3], server_address->port);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-05-28 13:49:44 +00:00
|
|
|
if (ui_do_button(&quit_button, "Quit", 0, 620, 490, 128, 48, draw_teewars_button))
|
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, 20, 420, 170, 48, draw_teewars_button))
|
2007-06-01 11:08:33 +00:00
|
|
|
{
|
|
|
|
config_copy = config;
|
2007-06-01 02:21:46 +00:00
|
|
|
screen = 1;
|
2007-06-01 11:08:33 +00:00
|
|
|
}
|
2007-06-01 02:21:46 +00:00
|
|
|
|
2007-06-10 17:25:08 +00:00
|
|
|
static int editor_button;
|
|
|
|
if (ui_do_button(&editor_button, "Kerning Editor", 0, 20, 470, 170, 48, draw_teewars_button))
|
|
|
|
screen = 2;
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int settings_screen_render()
|
|
|
|
{
|
2007-06-10 15:42:19 +00:00
|
|
|
const float column1_x = 150;
|
2007-06-01 02:21:46 +00:00
|
|
|
const float column2_x = column1_x + 150;
|
|
|
|
const float column3_x = column2_x + 170;
|
|
|
|
const float name_y = 160;
|
|
|
|
const float resolution_y = 200;
|
|
|
|
const float keys_y = 240;
|
|
|
|
|
|
|
|
// NAME
|
|
|
|
ui_do_label(column1_x, name_y, "Name:", 36);
|
2007-06-01 11:08:33 +00:00
|
|
|
ui_do_edit_box(config_copy.player_name, column2_x, name_y, 300, 36, config_copy.player_name, sizeof(config_copy.player_name));
|
2007-06-01 02:21:46 +00:00
|
|
|
|
|
|
|
// KEYS
|
|
|
|
ui_do_label(column1_x, keys_y, "Keys:", 36);
|
|
|
|
ui_do_label(column2_x, keys_y + 0, "Move Left:", 36);
|
2007-06-09 16:21:28 +00:00
|
|
|
config_set_key_move_left(&config_copy, ui_do_key_reader(&config_copy.key_move_left, column3_x, keys_y + 0, 150, 40, config_copy.key_move_left));
|
2007-06-01 02:21:46 +00:00
|
|
|
ui_do_label(column2_x, keys_y + 40, "Move Right:", 36);
|
2007-06-09 16:21:28 +00:00
|
|
|
config_set_key_move_right(&config_copy, ui_do_key_reader(&config_copy.key_move_right, column3_x, keys_y + 40, 150, 40, config_copy.key_move_right));
|
2007-06-01 02:21:46 +00:00
|
|
|
ui_do_label(column2_x, keys_y + 80, "Jump:", 36);
|
2007-06-09 16:21:28 +00:00
|
|
|
config_set_key_jump(&config_copy, ui_do_key_reader(&config_copy.key_jump, column3_x, keys_y + 80, 150, 40, config_copy.key_jump));
|
2007-06-01 02:21:46 +00:00
|
|
|
ui_do_label(column2_x, keys_y + 120, "Fire:", 36);
|
2007-06-09 16:21:28 +00:00
|
|
|
config_set_key_fire(&config_copy, ui_do_key_reader(&config_copy.key_fire, column3_x, keys_y + 120, 150, 40, config_copy.key_fire));
|
2007-06-01 02:21:46 +00:00
|
|
|
ui_do_label(column2_x, keys_y + 160, "Hook:", 36);
|
2007-06-09 16:21:28 +00:00
|
|
|
config_set_key_hook(&config_copy, ui_do_key_reader(&config_copy.key_hook, column3_x, keys_y + 160, 150, 40, config_copy.key_hook));
|
2007-06-01 02:21:46 +00:00
|
|
|
|
|
|
|
// RESOLUTION
|
|
|
|
static char resolutions[][128] =
|
|
|
|
{
|
|
|
|
"800x600",
|
|
|
|
"1024x764",
|
2007-06-10 15:42:19 +00:00
|
|
|
"1280x960",
|
|
|
|
"1600x1200",
|
2007-06-01 02:21:46 +00:00
|
|
|
};
|
2007-06-01 11:08:33 +00:00
|
|
|
static int res[][2] =
|
|
|
|
{
|
|
|
|
{ 800, 600 },
|
|
|
|
{ 1024, 768 },
|
2007-06-10 15:42:19 +00:00
|
|
|
{ 1280, 960 },
|
|
|
|
{ 1600, 1200 },
|
2007-06-01 11:08:33 +00:00
|
|
|
};
|
2007-06-10 15:42:19 +00:00
|
|
|
|
|
|
|
static int selected_index = -1;
|
|
|
|
if (selected_index == -1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (config.screen_width == res[i][0])
|
|
|
|
{
|
|
|
|
selected_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected_index == -1)
|
|
|
|
selected_index = 1;
|
|
|
|
}
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
ui_do_label(column1_x, resolution_y, "Resolution:", 36);
|
2007-06-10 15:42:19 +00:00
|
|
|
selected_index = ui_do_combo_box(&selected_index, column2_x, resolution_y, 180, (char *)resolutions, 4, selected_index);
|
2007-06-01 02:21:46 +00:00
|
|
|
|
2007-06-01 11:17:10 +00:00
|
|
|
config_set_screen_width(&config_copy, res[selected_index][0]);
|
|
|
|
config_set_screen_height(&config_copy, res[selected_index][1]);
|
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))
|
|
|
|
{
|
|
|
|
config = config_copy;
|
2007-06-01 12:02:27 +00:00
|
|
|
config_save("teewars.cfg");
|
2007-06-01 11:08:33 +00:00
|
|
|
screen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CANCEL BUTTON
|
|
|
|
static int cancel_button;
|
|
|
|
if (ui_do_button(&cancel_button, "Cancel", 0, 620, 490, 150, 48, draw_teewars_button))
|
2007-06-01 02:21:46 +00:00
|
|
|
screen = 0;
|
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-10 17:25:08 +00:00
|
|
|
extern double extra_kerning[256*256];
|
|
|
|
|
|
|
|
static int editor_screen_render()
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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 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
|
2007-07-16 16:48:16 +00:00
|
|
|
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
|
2007-07-16 16:48:16 +00:00
|
|
|
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_quads_setcolor(0,0,0,0.5);
|
|
|
|
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
|
2007-07-16 16:48:16 +00:00
|
|
|
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
|
2007-07-16 16:48:16 +00:00
|
|
|
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
|
2007-07-16 16:48:16 +00:00
|
|
|
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
|
2007-07-16 16:48:16 +00:00
|
|
|
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;
|
2007-06-10 21:35:59 +00:00
|
|
|
if (ui_do_button(&save_button, "Save", 0, 482, 520, 128, 48, draw_teewars_button))
|
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 17:25:08 +00:00
|
|
|
//screen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CANCEL BUTTON
|
|
|
|
static int cancel_button;
|
2007-06-10 21:35:59 +00:00
|
|
|
if (ui_do_button(&cancel_button, "Cancel", 0, 620, 520, 150, 48, draw_teewars_button))
|
2007-06-10 17:25:08 +00:00
|
|
|
screen = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
static int menu_render(netaddr4 *server_address)
|
|
|
|
{
|
|
|
|
// background color
|
|
|
|
gfx_clear(89/255.f,122/255.f,0.0);
|
|
|
|
|
|
|
|
// GUI coordsys
|
|
|
|
gfx_mapscreen(0,0,800.0f,600.0f);
|
|
|
|
|
|
|
|
static int64 start = time_get();
|
|
|
|
|
|
|
|
float t = double(time_get() - start) / double(time_freq());
|
|
|
|
draw_scrolling_background(background_texture, 800, 600, t * 0.01);
|
|
|
|
|
2007-06-10 21:35:59 +00:00
|
|
|
if (screen != 2)
|
|
|
|
{
|
|
|
|
ui_do_image(teewars_banner_texture, 140, 20, 512, 128);
|
|
|
|
ui_do_label(20.0f, 600.0f-40.0f, "Version: " TEEWARS_VERSION, 36);
|
|
|
|
}
|
2007-06-01 02:21:46 +00:00
|
|
|
|
2007-06-11 19:59:29 +00:00
|
|
|
switch (screen)
|
|
|
|
{
|
|
|
|
case 1:
|
2007-06-01 02:21:46 +00:00
|
|
|
return settings_screen_render();
|
2007-06-11 19:59:29 +00:00
|
|
|
case 2:
|
2007-06-10 17:25:08 +00:00
|
|
|
return editor_screen_render();
|
2007-06-11 19:59:29 +00:00
|
|
|
default:
|
|
|
|
return main_screen_render(server_address);
|
|
|
|
}
|
2007-06-01 02:21:46 +00:00
|
|
|
}
|
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
void modmenu_init()
|
|
|
|
{
|
2007-06-10 15:19:04 +00:00
|
|
|
input::enable_char_cache();
|
|
|
|
input::enable_key_cache();
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-07-15 23:52:36 +00:00
|
|
|
current_font->font_texture = gfx_load_texture("data/big_font.png");
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
background_texture = gfx_load_texture("data/gui_bg.png");
|
2007-05-27 18:14:24 +00:00
|
|
|
gui_tileset_texture = gfx_load_texture("data/gui/gui_widgets.png");
|
2007-05-27 00:47:07 +00:00
|
|
|
teewars_banner_texture = gfx_load_texture("data/gui_logo.png");
|
2007-05-22 15:03:32 +00:00
|
|
|
|
|
|
|
music_menu = snd_load_wav("data/audio/Music_Menu.wav");
|
2007-07-16 16:48:16 +00:00
|
|
|
|
|
|
|
data = load_data_container("data/client.dat");
|
2007-05-22 15:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void modmenu_shutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-06-01 02:21:46 +00:00
|
|
|
int modmenu_render(void *ptr)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
|
|
|
static int mouse_x = 0;
|
|
|
|
static int mouse_y = 0;
|
|
|
|
|
|
|
|
if (music_menu_id == -1)
|
|
|
|
{
|
|
|
|
dbg_msg("menu", "no music is playing, so let's play some tunes!");
|
|
|
|
music_menu_id = snd_play(music_menu, SND_LOOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
netaddr4 *server_address = (netaddr4 *)ptr;
|
|
|
|
|
|
|
|
// handle mouse movement
|
|
|
|
float mx, my, mwx, mwy;
|
|
|
|
{
|
|
|
|
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
|
|
|
mwx = mx*3.0f; // adjust to zoom and offset
|
|
|
|
mwy = mx*3.0f; // adjust to zoom and offset
|
|
|
|
|
|
|
|
int buttons = 0;
|
2007-06-10 15:19:04 +00:00
|
|
|
if(inp_key_pressed(input::mouse_1)) buttons |= 1;
|
|
|
|
if(inp_key_pressed(input::mouse_2)) buttons |= 2;
|
|
|
|
if(inp_key_pressed(input::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);
|
|
|
|
int r = menu_render(server_address);
|
2007-05-22 15:03:32 +00:00
|
|
|
|
|
|
|
// render butt ugly mouse cursor
|
|
|
|
gfx_texture_set(-1);
|
|
|
|
gfx_quads_begin();
|
|
|
|
gfx_quads_setcolor(0,0,0,1);
|
|
|
|
gfx_quads_draw_freeform(mx,my,mx,my,
|
2007-05-28 13:49:44 +00:00
|
|
|
mx+14,my,
|
|
|
|
mx,my+14);
|
2007-05-22 15:03:32 +00:00
|
|
|
gfx_quads_setcolor(1,1,1,1);
|
|
|
|
gfx_quads_draw_freeform(mx+1,my+1,mx+1,my+1,
|
2007-05-28 13:49:44 +00:00
|
|
|
mx+10,my+1,
|
|
|
|
mx+1,my+10);
|
2007-05-22 15:03:32 +00:00
|
|
|
gfx_quads_end();
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
snd_stop(music_menu_id);
|
|
|
|
music_menu_id = -1;
|
|
|
|
}
|
|
|
|
|
2007-06-10 15:19:04 +00:00
|
|
|
input::clear_char();
|
|
|
|
input::clear_key();
|
2007-05-22 15:03:32 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|