Upload
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#include <ui/Components.h>
|
||||
|
||||
bool button_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
Button* button = (Button*)component;
|
||||
SDL_Rect src = { button->x, button->y, button->w, button->h };
|
||||
SDL_Rect dst = { button->d_x * INTERFACE_SCALE, button->d_y * INTERFACE_SCALE, button->d_w * INTERFACE_SCALE, button->d_h * INTERFACE_SCALE };
|
||||
|
||||
int mouse_x, mouse_y;
|
||||
float scale_x, scale_y;
|
||||
Uint32 flags = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
|
||||
mouse_x /= scale_x;
|
||||
mouse_y /= scale_y;
|
||||
|
||||
if(mouse_x >= dst.x && mouse_y >= dst.y && mouse_x < dst.x + dst.w && mouse_y < dst.y + dst.h)
|
||||
{
|
||||
src.x += src.w;
|
||||
|
||||
if(flags & SDL_BUTTON(1))
|
||||
{
|
||||
if(!button->clicked && button->cb)
|
||||
{
|
||||
button->clicked = true;
|
||||
|
||||
if (!button->cb(component))
|
||||
return false;
|
||||
}
|
||||
dst.y += 2;
|
||||
}
|
||||
else
|
||||
button->clicked = false;
|
||||
}
|
||||
else
|
||||
button->clicked = false;
|
||||
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <ui/Components.h>
|
||||
|
||||
bool image_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
Image* image = (Image*)component;
|
||||
|
||||
SDL_Rect src = { image->x, image->y, image->w, image->h };
|
||||
SDL_Rect dst = { image->d_x * INTERFACE_SCALE, image->d_y * INTERFACE_SCALE, image->d_w * INTERFACE_SCALE, image->d_h * INTERFACE_SCALE };
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
#include <ui/Components.h>
|
||||
#include <UTF8.h>
|
||||
|
||||
bool label_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
Label* label = (Label*)component;
|
||||
int x = label->x;
|
||||
int y = label->y;
|
||||
SDL_Color clr = COLOR_WHITE;
|
||||
|
||||
for (int i = 0; i < utf8_strlen(label->text); i++)
|
||||
{
|
||||
utf8_char c = utf8_tolower(utf8_get(label->text, i));
|
||||
|
||||
int ind;
|
||||
switch (c)
|
||||
{
|
||||
case '\n':
|
||||
x = label->x;
|
||||
y += 8;
|
||||
continue;
|
||||
|
||||
case ' ':
|
||||
x += 5;
|
||||
continue;
|
||||
|
||||
case ' ':
|
||||
x += 10;
|
||||
continue;
|
||||
|
||||
case '-':
|
||||
case '_':
|
||||
ind = 26;
|
||||
break;
|
||||
|
||||
case ',':
|
||||
ind = 27;
|
||||
break;
|
||||
|
||||
case '1':
|
||||
ind = 28;
|
||||
break;
|
||||
|
||||
case '2':
|
||||
ind = 29;
|
||||
break;
|
||||
|
||||
case '3':
|
||||
ind = 30;
|
||||
break;
|
||||
|
||||
case '4':
|
||||
ind = 31;
|
||||
break;
|
||||
|
||||
case '5':
|
||||
ind = 32;
|
||||
break;
|
||||
|
||||
case '6':
|
||||
ind = 33;
|
||||
break;
|
||||
|
||||
case '7':
|
||||
ind = 34;
|
||||
break;
|
||||
|
||||
case '8':
|
||||
ind = 35;
|
||||
break;
|
||||
|
||||
case '9':
|
||||
ind = 36;
|
||||
break;
|
||||
|
||||
case '0':
|
||||
ind = 37;
|
||||
break;
|
||||
|
||||
case '!':
|
||||
case '.':
|
||||
ind = 38;
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
ind = 39;
|
||||
break;
|
||||
|
||||
case ':':
|
||||
ind = 40;
|
||||
break;
|
||||
|
||||
case '(':
|
||||
case '[':
|
||||
case '<':
|
||||
ind = 41;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
case ']':
|
||||
case '>':
|
||||
ind = 42;
|
||||
break;
|
||||
|
||||
case '%':
|
||||
ind = 43;
|
||||
break;
|
||||
|
||||
case '+':
|
||||
ind = 77;
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
clr = COLOR_RED;
|
||||
continue;
|
||||
|
||||
case '@':
|
||||
clr = COLOR_GRN;
|
||||
continue;
|
||||
|
||||
case '&':
|
||||
clr = COLOR_PUR;
|
||||
continue;
|
||||
|
||||
case '/':
|
||||
clr = COLOR_BLU;
|
||||
continue;
|
||||
|
||||
case '|':
|
||||
clr = COLOR_GRA;
|
||||
continue;
|
||||
|
||||
case '`':
|
||||
clr = COLOR_YLW;
|
||||
continue;
|
||||
|
||||
case '~':
|
||||
clr = COLOR_WHITE;
|
||||
continue;
|
||||
|
||||
case 0x2116:
|
||||
clr = COLOR_ORG;
|
||||
continue;
|
||||
|
||||
default:
|
||||
if(c >= 'a' && c <= 'z')
|
||||
ind = c - 97;
|
||||
else if(c >= 0x0430 && c <= 0x044F)
|
||||
ind = c - 0x0430 + 45;
|
||||
else
|
||||
ind = 44;
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_SetTextureColorMod(g_textureSheet, clr.r, clr.g, clr.b);
|
||||
SDL_Rect src = (SDL_Rect){ 480 + ind * 8, 432, 8, 6 };
|
||||
SDL_Rect dst = (SDL_Rect){ x * label->scale, y * label->scale, 8 * label->scale, 6 * label->scale };
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
x += 6;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 'w':
|
||||
case 'm':
|
||||
case 'x':
|
||||
case 'n':
|
||||
case 0x043C:
|
||||
case 0x0434:
|
||||
case 0x0438:
|
||||
case 0x0439:
|
||||
case 0x044E:
|
||||
case 0x044C:
|
||||
case 0x043B:
|
||||
case 0x0448:
|
||||
case 0x0449:
|
||||
case 0x0446:
|
||||
case 0x0436:
|
||||
x += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetTextureColorMod(g_textureSheet, 255, 255, 255);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,594 @@
|
||||
#include "Config.h"
|
||||
#include <string.h>
|
||||
#include <ui/Main.h>
|
||||
#include <ui/Components.h>
|
||||
#include <ui/Presets.h>
|
||||
#include <io/Threads.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <Lib.h>
|
||||
#include <Maps.h>
|
||||
#include <Server.h>
|
||||
#include <States.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int lobby = 0;
|
||||
enum
|
||||
{
|
||||
UST_MAIN,
|
||||
UST_OPTIONS,
|
||||
UST_PLAYERS,
|
||||
UST_INFO
|
||||
} state;
|
||||
char text_buffer[40][256];
|
||||
char info_text[1024];
|
||||
int text_index = 0;
|
||||
int text_length = 0;
|
||||
int g_mouseWheel = 0;
|
||||
int g_pmouseWheel = 0;
|
||||
|
||||
void init_info();
|
||||
bool main_menu(Component* component);
|
||||
bool options_menu(Component* component);
|
||||
bool players_menu(Component* component);
|
||||
bool info_menu(Component* component);
|
||||
|
||||
bool back_to_lobby(Component* component);
|
||||
bool practice_mode(Component* component);
|
||||
bool force_exe_win(Component* component);
|
||||
bool force_surv_win(Component* component);
|
||||
|
||||
bool map_list_changed(Component* component);
|
||||
bool map_list_reset(Component* component);
|
||||
|
||||
Component* main_components[] =
|
||||
{
|
||||
(Component*)&(ImageCreate(0, 0, 480, 270, 0, 272, 480, 270)),
|
||||
(Component*)&(ImageCreate(16, 48, 276, 176, 128, 0, 272, 176)),
|
||||
(Component*)&(ImageCreate(199, 10, 64, 16, 1829, 0, 64, 16)),
|
||||
|
||||
(Component*)&(ButtonCreate(59, 249, 32, 8, main_menu, 480, 400, 32, 8)),
|
||||
(Component*)&(ButtonCreate(150, 249, 54, 8, options_menu, 480, 408, 54, 8)),
|
||||
(Component*)&(ButtonCreate(268, 249, 53, 8, players_menu, 480, 416, 53, 8)),
|
||||
(Component*)&(ButtonCreate(386, 249, 29, 8, info_menu, 480, 424, 29, 8)),
|
||||
|
||||
(Component*)&(ButtonCreate(320, 106, 128, 20, back_to_lobby, 400, 0, 128, 20)),
|
||||
(Component*)&(ButtonCreate(320, 136, 128, 20, practice_mode, 400 + 256, 0, 128, 20)),
|
||||
(Component*)&(ButtonCreate(320, 166, 128, 20, force_exe_win, 400 + 512, 0, 128, 20)),
|
||||
(Component*)&(ButtonCreate(320, 196, 128, 20, force_surv_win, 400 + 512 + 256, 0, 128, 20)),
|
||||
};
|
||||
|
||||
Component* options_components[] =
|
||||
{
|
||||
(Component*)&(MapListCreate(0, 38, 288, 195, map_list_changed)),
|
||||
(Component*)&(ImageCreate(0, 0, 480, 270, 2256, 0, 480, 270)),
|
||||
(Component*)&(ImageCreate(184, 10, 103, 16, 1925, 0, 103, 16)),
|
||||
|
||||
(Component*)&(ButtonCreate(59, 249, 32, 8, main_menu, 480, 400, 32, 8)),
|
||||
(Component*)&(ButtonCreate(150, 249, 54, 8, options_menu, 480, 408, 54, 8)),
|
||||
(Component*)&(ButtonCreate(268, 249, 53, 8, players_menu, 480, 416, 53, 8)),
|
||||
(Component*)&(ButtonCreate(386, 249, 29, 8, info_menu, 480, 424, 29, 8)),
|
||||
|
||||
(Component*)&(MapListPresetCreate(320, 48, 128, 40)),
|
||||
(Component*)&(ButtonCreate(320, 96, 128, 20, map_list_reset, 3540, 0, 128, 20)),
|
||||
(Component*)&(PingLimitCreate(320, 125, 128, 40)),
|
||||
(Component*)&(TButtonCreate(320, 172, 128, 20, (ButtonCallback)config_save, &g_config.anticheat, true, 3120, 0, 128, 20)),
|
||||
(Component*)&(TButtonCreate(320, 200, 128, 20, (ButtonCallback)config_save, &g_config.pride, false, 2736, 0, 128, 20)),
|
||||
};
|
||||
|
||||
Component* players_components[] =
|
||||
{
|
||||
(Component*)&(ImageCreate(0, 0, 480, 270, 0, 272, 480, 270)),
|
||||
(Component*)&(ImageCreate(179, 10, 112, 16, 2032, 0, 112, 16)),
|
||||
|
||||
(Component*)&(PlayerListCreate(16, 48)),
|
||||
(Component*)&(PlayerListConfigCreate(168, 48, playerlist_op_update)),
|
||||
(Component*)&(PlayerListConfigCreate(320, 48, playerlist_bans_update)),
|
||||
|
||||
(Component*)&(ButtonCreate(59, 249, 32, 8, main_menu, 480, 400, 32, 8)),
|
||||
(Component*)&(ButtonCreate(150, 249, 54, 8, options_menu, 480, 408, 54, 8)),
|
||||
(Component*)&(ButtonCreate(268, 249, 53, 8, players_menu, 480, 416, 53, 8)),
|
||||
(Component*)&(ButtonCreate(386, 249, 29, 8, info_menu, 480, 424, 29, 8)),
|
||||
};
|
||||
|
||||
Component* info_components[] =
|
||||
{
|
||||
(Component*)&(ImageCreate(0, 0, 480, 270, 0, 272, 480, 270)),
|
||||
(Component*)&(ImageCreate(208, 10, 55, 16, 2172, 0, 55, 16)),
|
||||
(Component*)&(LabelCreate(4, 38 + 4, info_text, 2)),
|
||||
|
||||
(Component*)&(ButtonCreate(59, 249, 32, 8, main_menu, 480, 400, 32, 8)),
|
||||
(Component*)&(ButtonCreate(150, 249, 54, 8, options_menu, 480, 408, 54, 8)),
|
||||
(Component*)&(ButtonCreate(268, 249, 53, 8, players_menu, 480, 416, 53, 8)),
|
||||
(Component*)&(ButtonCreate(386, 249, 29, 8, info_menu, 480, 424, 29, 8)),
|
||||
};
|
||||
|
||||
void log_msg(const char* type, const char* message)
|
||||
{
|
||||
char msg[512];
|
||||
|
||||
if (strcmp(type, DEBUG_TYPE) == 0)
|
||||
snprintf(msg, 512, "|%s~", message);
|
||||
else if (strcmp(type, WARN_TYPE) == 0)
|
||||
snprintf(msg, 512, "`%s~", message);
|
||||
else if (strcmp(type, ERROR_TYPE) == 0)
|
||||
snprintf(msg, 512, "\\%s~", message);
|
||||
else
|
||||
snprintf(msg, 512, "~%s", message);
|
||||
|
||||
if (text_length > 39)
|
||||
{
|
||||
for (int i = 1; i < 40; i++)
|
||||
strncpy(text_buffer[i - 1], text_buffer[i], 255);
|
||||
}
|
||||
|
||||
strncpy(text_buffer[text_index], msg, 255);
|
||||
|
||||
if (text_index < 39)
|
||||
text_index++;
|
||||
|
||||
if (text_length < 40)
|
||||
text_length++;
|
||||
}
|
||||
|
||||
int server_loop(void)
|
||||
{
|
||||
if (!disaster_init())
|
||||
return 1;
|
||||
|
||||
return disaster_run();
|
||||
}
|
||||
|
||||
int console_loop(void)
|
||||
{
|
||||
SDL_Quit();
|
||||
|
||||
#ifdef WIN32
|
||||
AllocConsole();
|
||||
(void)freopen("CONOUT$", "w", stdout);
|
||||
#endif
|
||||
|
||||
return server_loop();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (strcmp(argv[i], "--nogui") == 0)
|
||||
return console_loop();
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
{
|
||||
char msg[1024];
|
||||
snprintf(msg, 1024, "%s\n\nPress OK to fallback to console mode.", SDL_GetError());
|
||||
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", msg, NULL);
|
||||
return console_loop();
|
||||
}
|
||||
|
||||
SDL_Window* window;
|
||||
SDL_Renderer* renderer;
|
||||
if (!(window = SDL_CreateWindow("DisasterServer v" STRINGIFY(BUILD_VERSION) " (Modified)", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 480 * INTERFACE_SCALE, 270 * INTERFACE_SCALE, SDL_WINDOW_SHOWN)))
|
||||
{
|
||||
char msg[1024];
|
||||
snprintf(msg, 1024, "%s\n\nPress OK to fallback to console mode.", SDL_GetError());
|
||||
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", msg, NULL);
|
||||
return console_loop();
|
||||
}
|
||||
|
||||
if (!(renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED)))
|
||||
{
|
||||
char msg[1024];
|
||||
snprintf(msg, 1024, "%s\n\nPress OK to fallback to console mode.", SDL_GetError());
|
||||
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", msg, NULL);
|
||||
return console_loop();
|
||||
}
|
||||
|
||||
if (!resources_load(renderer))
|
||||
return console_loop();
|
||||
|
||||
init_info();
|
||||
log_hook(log_msg);
|
||||
SDL_RenderSetLogicalSize(renderer, 480 * INTERFACE_SCALE, 270 * INTERFACE_SCALE);
|
||||
SDL_RenderSetVSync(renderer, true);
|
||||
|
||||
Label label;
|
||||
Thread thr;
|
||||
ThreadSpawn(thr, server_loop, NULL);
|
||||
|
||||
bool running = true;
|
||||
float bg = 0;
|
||||
|
||||
while (running)
|
||||
{
|
||||
SDL_Event ev;
|
||||
while (SDL_PollEvent(&ev))
|
||||
{
|
||||
switch (ev.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
running = false;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEWHEEL:
|
||||
g_mouseWheel = ev.wheel.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
{
|
||||
SDL_Rect src = (SDL_Rect){ 480 + ((int)bg / 3 % 28) * 96, 446, 96, 96 };
|
||||
for(int i = 0; i < 6 * INTERFACE_SCALE; i++)
|
||||
{
|
||||
for(int j = 0; j < 3 * INTERFACE_SCALE; j++)
|
||||
{
|
||||
SDL_Rect dst = (SDL_Rect){ -((int)bg / 2 % 96) + i * 96, j * 96, 96, 96 };
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
}
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case UST_MAIN:
|
||||
{
|
||||
for (int i = 0; i < sizeof(main_components) / sizeof(Component*); i++)
|
||||
main_components[i]->update(renderer, main_components[i]);
|
||||
|
||||
for (int i = 0; i < text_length; i++)
|
||||
{
|
||||
label = LabelCreate(23 * 2, 55 * 2 + i * 8, text_buffer[i], 1);
|
||||
label.update(renderer, (Component*)&label);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case UST_OPTIONS:
|
||||
{
|
||||
for (int i = 0; i < sizeof(options_components) / sizeof(Component*); i++)
|
||||
options_components[i]->update(renderer, options_components[i]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case UST_PLAYERS:
|
||||
{
|
||||
for (int i = 0; i < sizeof(players_components) / sizeof(Component*); i++)
|
||||
players_components[i]->update(renderer, players_components[i]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case UST_INFO:
|
||||
{
|
||||
for (int i = 0; i < sizeof(info_components) / sizeof(Component*); i++)
|
||||
info_components[i]->update(renderer, info_components[i]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_mouseWheel = 0;
|
||||
bg += 0.64;
|
||||
}
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Delay(32);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_info()
|
||||
{
|
||||
char compiler[128];
|
||||
|
||||
#ifdef __clang__
|
||||
snprintf(compiler, 128, "clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||
#elif defined(__GNUC__)
|
||||
snprintf(compiler, 128, "gcc %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
#elif defined(_MSC_VER)
|
||||
snprintf(compiler, 128, "msvc %d", _MSC_VER);
|
||||
#else
|
||||
snprintf(compiler, 128, "unknown");
|
||||
#endif
|
||||
|
||||
SDL_version sdl_ver;
|
||||
SDL_GetVersion(&sdl_ver);
|
||||
const SDL_version* img_ver = IMG_Linked_Version();
|
||||
|
||||
snprintf(info_text, 1024, INFO_TEXT, compiler, sdl_ver.major, sdl_ver.minor, sdl_ver.patch, img_ver->major, img_ver->minor, img_ver->patch);
|
||||
}
|
||||
|
||||
bool main_menu(Component* component)
|
||||
{
|
||||
state = UST_MAIN;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool options_menu(Component* component)
|
||||
{
|
||||
state = UST_OPTIONS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool players_menu(Component* component)
|
||||
{
|
||||
state = UST_PLAYERS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool info_menu(Component* component)
|
||||
{
|
||||
state = UST_INFO;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool back_to_lobby(Component* component)
|
||||
{
|
||||
Server* server = disaster_get(lobby);
|
||||
|
||||
if(!server)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Server is not running (Check logs in Info tab)!", NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
MutexLock(server->state_lock);
|
||||
{
|
||||
if(server->state != ST_LOBBY && !lobby_init(server))
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Failed to return to lobby: lobby_init() returned FALSE", NULL);
|
||||
}
|
||||
MutexUnlock(server->state_lock);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool practice_mode(Component* component)
|
||||
{
|
||||
Server* server = disaster_get(lobby);
|
||||
|
||||
if(!server)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Server is not running (Check logs in Info tab)!", NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
MutexLock(server->state_lock);
|
||||
{
|
||||
if(server->state == ST_LOBBY && server_ingame(server) > 1)
|
||||
{
|
||||
if(!charselect_init(20, server))
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Failed to set practice mode: charselect_init() returned FALSE", NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
MutexUnlock(server->state_lock);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool force_exe_win(Component* component)
|
||||
{
|
||||
Server* server = disaster_get(lobby);
|
||||
|
||||
if(!server)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Server is not running (Check logs in Info tab)!", NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
MutexLock(server->state_lock);
|
||||
{
|
||||
if(server->state == ST_GAME)
|
||||
{
|
||||
if(!game_end(server, ED_EXEWIN, false))
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Failed to set exe win: game_end() returned FALSE", NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
MutexUnlock(server->state_lock);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool force_surv_win(Component* component)
|
||||
{
|
||||
Server* server = disaster_get(lobby);
|
||||
|
||||
if(!server)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Server is not running (Check logs in Info tab)!", NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
MutexLock(server->state_lock);
|
||||
{
|
||||
if(server->state == ST_GAME)
|
||||
{
|
||||
if(!game_end(server, ED_SURVWIN, false))
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Failed to set surv win: game_end() returned FALSE", NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
MutexUnlock(server->state_lock);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool map_list_changed(Component* component)
|
||||
{
|
||||
MapListPreset* preset_list = (MapListPreset*)options_components[7];
|
||||
preset_list->preset = PRESET_CUSTOM;
|
||||
|
||||
for (int i = 0; i < PRESET_COUNT; i++)
|
||||
{
|
||||
if (memcmp(g_config.map_list, g_defaultPresets[i].values, sizeof(g_config.map_list)) == 0)
|
||||
{
|
||||
preset_list->preset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool map_list_reset(Component* component)
|
||||
{
|
||||
MapListPreset* preset_list = (MapListPreset*)options_components[7];
|
||||
preset_list->preset = PRESET_CUSTOM;
|
||||
|
||||
MutexLock(g_config.map_list_lock);
|
||||
memset(g_config.map_list, 0, sizeof(g_config.map_list));
|
||||
MutexUnlock(g_config.map_list_lock);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ui_update_playerlist(Server* server)
|
||||
{
|
||||
if(!server)
|
||||
return;
|
||||
|
||||
if(server->id != 0)
|
||||
return;
|
||||
|
||||
PlayerList* list = (PlayerList*)players_components[2];
|
||||
for(size_t i = 0; i < server->peers.capacity; i++)
|
||||
{
|
||||
PeerData* player = (PeerData*)server->peers.ptr[i];
|
||||
if(!player)
|
||||
{
|
||||
memset(&list->peers[i], 0, sizeof(list->peers[i]));
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(&list->peers[i], server->peers.ptr[i], sizeof(list->peers[i]));
|
||||
}
|
||||
}
|
||||
|
||||
bool ui_update_delete(Component* component)
|
||||
{
|
||||
DeleteButton* delete = (DeleteButton*)component;
|
||||
if (cJSON_HasObjectItem(delete->root, delete->key))
|
||||
{
|
||||
cJSON_DeleteItemFromObject(delete->root, delete->key);
|
||||
|
||||
if (!collection_save(delete->collection, delete->root))
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Failed to save collection!", NULL);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ui_button_op(struct _Component* component)
|
||||
{
|
||||
PlayerButton* button = (PlayerButton*)component;
|
||||
Server* server = disaster_get(lobby);
|
||||
|
||||
bool res = true;
|
||||
MutexLock(server->state_lock);
|
||||
{
|
||||
for(size_t i = 0; i < server->peers.capacity; i++)
|
||||
{
|
||||
PeerData* peer = (PeerData*)server->peers.ptr[i];
|
||||
if(!peer)
|
||||
continue;
|
||||
|
||||
if(peer->id != button->peer.id)
|
||||
continue;
|
||||
|
||||
if(strcmp(peer->nickname.value, button->peer.nickname.value) != 0)
|
||||
continue;
|
||||
|
||||
if(strcmp(peer->udid.value, button->peer.udid.value) != 0)
|
||||
continue;
|
||||
|
||||
if (peer->op)
|
||||
break;
|
||||
|
||||
peer->op = true;
|
||||
|
||||
server_send_msg(server, peer->peer, CLRCODE_GRN "you're an operator now");
|
||||
res = op_add(peer->nickname.value, peer->ip.value);
|
||||
}
|
||||
}
|
||||
MutexUnlock(server->state_lock);
|
||||
|
||||
RAssert(res);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ui_button_kick(struct _Component* component)
|
||||
{
|
||||
PlayerButton* button = (PlayerButton*)component;
|
||||
Server* server = disaster_get(lobby);
|
||||
|
||||
bool res = true;
|
||||
MutexLock(server->state_lock);
|
||||
{
|
||||
for(size_t i = 0; i < server->peers.capacity; i++)
|
||||
{
|
||||
PeerData* peer = (PeerData*)server->peers.ptr[i];
|
||||
if(!peer)
|
||||
continue;
|
||||
|
||||
if(peer->id != button->peer.id)
|
||||
continue;
|
||||
|
||||
if(strcmp(peer->nickname.value, button->peer.nickname.value) != 0)
|
||||
continue;
|
||||
|
||||
if(strcmp(peer->udid.value, button->peer.udid.value) != 0)
|
||||
continue;
|
||||
|
||||
server_disconnect(server, peer->peer, DR_KICKEDBYHOST, NULL);
|
||||
res = timeout_set(peer->nickname.value, peer->udid.value, peer->ip.value, time(NULL) + 5);
|
||||
}
|
||||
}
|
||||
MutexUnlock(server->state_lock);
|
||||
|
||||
RAssert(res);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ui_button_ban(struct _Component* component)
|
||||
{
|
||||
PlayerButton* button = (PlayerButton*)component;
|
||||
Server* server = disaster_get(lobby);
|
||||
|
||||
bool res = true;
|
||||
MutexLock(server->state_lock);
|
||||
{
|
||||
for(size_t i = 0; i < server->peers.capacity; i++)
|
||||
{
|
||||
PeerData* peer = (PeerData*)server->peers.ptr[i];
|
||||
if(!peer)
|
||||
continue;
|
||||
|
||||
if(peer->id != button->peer.id)
|
||||
continue;
|
||||
|
||||
if(strcmp(peer->nickname.value, button->peer.nickname.value) != 0)
|
||||
continue;
|
||||
|
||||
if(strcmp(peer->udid.value, button->peer.udid.value) != 0)
|
||||
continue;
|
||||
|
||||
server_disconnect(server, peer->peer, DR_BANNEDBYHOST, NULL);
|
||||
res = ban_add(peer->nickname.value, peer->udid.value, peer->ip.value);
|
||||
}
|
||||
}
|
||||
MutexUnlock(server->state_lock);
|
||||
|
||||
RAssert(res);
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#include <Log.h>
|
||||
#include <Maps.h>
|
||||
#include <ui/Resources.h>
|
||||
#include <ui/Components.h>
|
||||
#include <CMath.h>
|
||||
|
||||
const int low_bound = -(MAP_COUNT/4 * 124 - 124/2 - 194);
|
||||
|
||||
bool maplist_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
MapList* list = (MapList*)component;
|
||||
SDL_Rect bounds = { list->x * INTERFACE_SCALE, list->y * INTERFACE_SCALE, list->w * INTERFACE_SCALE, list->h * INTERFACE_SCALE };
|
||||
|
||||
int mouse_x, mouse_y;
|
||||
float scale_x, scale_y;
|
||||
Uint32 flags = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
|
||||
mouse_x /= scale_x;
|
||||
mouse_y /= scale_y;
|
||||
|
||||
bool mouse_down = false;
|
||||
if(flags & SDL_BUTTON(1))
|
||||
{
|
||||
if(!list->clicked)
|
||||
{
|
||||
mouse_down = true;
|
||||
list->clicked = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
list->clicked = false;
|
||||
|
||||
bool in_bounds = mouse_x >= bounds.x && mouse_y >= bounds.y && mouse_x < bounds.x + bounds.w && mouse_y < bounds.y + bounds.h;
|
||||
if(in_bounds)
|
||||
{
|
||||
list->target_scroll += g_mouseWheel * 45;
|
||||
if(list->target_scroll >= 0)
|
||||
list->target_scroll = 0;
|
||||
|
||||
if(list->target_scroll < low_bound)
|
||||
list->target_scroll = low_bound;
|
||||
}
|
||||
|
||||
list->scroll = lerp(list->scroll, list->target_scroll, 0.30);
|
||||
|
||||
MutexLock(g_config.map_list_lock);
|
||||
for(int i = 0; i < MAP_COUNT; i++)
|
||||
{
|
||||
SDL_Rect src = { 0, 272, 123, 104 };
|
||||
SDL_Rect dst = { 8 + i % 4 * 143, 90 + i / 4 * 124 + list->scroll, 123, 104 };
|
||||
|
||||
src.x = 480 + i * src.w;
|
||||
|
||||
if(in_bounds && mouse_x >= dst.x && mouse_y >= dst.y && mouse_x < dst.x + dst.w && mouse_y < dst.y + dst.h)
|
||||
{
|
||||
dst.y -= 2;
|
||||
|
||||
if (mouse_down)
|
||||
{
|
||||
g_config.map_list[i] = !g_config.map_list[i];
|
||||
list->cb(component);
|
||||
}
|
||||
|
||||
if(flags & SDL_BUTTON(1))
|
||||
dst.y += 2;
|
||||
}
|
||||
|
||||
const Uint8 color = g_config.map_list[i] ? 255 : 96;
|
||||
SDL_SetTextureColorMod(g_textureSheet, color, color, color);
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
}
|
||||
MutexUnlock(g_config.map_list_lock);
|
||||
|
||||
SDL_SetTextureColorMod(g_textureSheet, 255, 255, 255);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#include <ui/Components.h>
|
||||
#include <ui/Presets.h>
|
||||
|
||||
bool mappreset_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
MapListPreset* list = (MapListPreset*)component;
|
||||
SDL_Rect src = { 4016, 0, 128, 40 };
|
||||
SDL_Rect dst = { list->x * INTERFACE_SCALE, list->y * INTERFACE_SCALE, list->w * INTERFACE_SCALE, list->h * INTERFACE_SCALE };
|
||||
|
||||
int mouse_x, mouse_y;
|
||||
float scale_x, scale_y;
|
||||
Uint32 flags = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
|
||||
bool mouse_down = false;
|
||||
if (flags & SDL_BUTTON(1))
|
||||
{
|
||||
if (!list->clicked)
|
||||
{
|
||||
mouse_down = true;
|
||||
list->clicked = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
list->clicked = false;
|
||||
|
||||
mouse_x /= scale_x;
|
||||
mouse_y /= scale_y;
|
||||
|
||||
if (mouse_x >= dst.x && mouse_y >= dst.y && mouse_x < dst.x + dst.w && mouse_y < dst.y + dst.h)
|
||||
{
|
||||
src.x += src.w;
|
||||
|
||||
SDL_Rect arrow_src = { 1680, 0, 116, 32 };
|
||||
SDL_Rect arrow_dst = { dst.x, dst.y, 116 * INTERFACE_SCALE, 32 * INTERFACE_SCALE };
|
||||
|
||||
if (mouse_down)
|
||||
{
|
||||
arrow_dst.y += 2;
|
||||
|
||||
MutexLock(g_config.map_list_lock);
|
||||
{
|
||||
if (mouse_x < dst.x + dst.w / 2)
|
||||
{
|
||||
if (--list->preset < 0)
|
||||
list->preset = PRESET_COUNT - 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (++list->preset >= PRESET_COUNT - 1)
|
||||
list->preset = 0;
|
||||
}
|
||||
|
||||
memcpy(g_config.map_list, g_defaultPresets[list->preset].values, sizeof(g_config.map_list));
|
||||
}
|
||||
MutexUnlock(g_config.map_list_lock);
|
||||
}
|
||||
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &arrow_src, &arrow_dst);
|
||||
}
|
||||
else
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
|
||||
list->label.scale = INTERFACE_SCALE;
|
||||
list->label.x = dst.x / INTERFACE_SCALE + 8;
|
||||
list->label.y = dst.y / INTERFACE_SCALE + 25;
|
||||
list->label.text = g_defaultPresets[list->preset].name;
|
||||
label_update(renderer, (Component*)&list->label);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#include "Colors.h"
|
||||
#include <ui/Components.h>
|
||||
#include <ui/Presets.h>
|
||||
|
||||
bool ping_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
PingLimit* list = (PingLimit*)component;
|
||||
SDL_Rect src = { 4272, 0, 128, 40 };
|
||||
SDL_Rect dst = { list->x * INTERFACE_SCALE, list->y * INTERFACE_SCALE, list->w * INTERFACE_SCALE, list->h * INTERFACE_SCALE };
|
||||
|
||||
int mouse_x, mouse_y;
|
||||
float scale_x, scale_y;
|
||||
Uint32 flags = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
|
||||
bool mouse_down = false;
|
||||
if (flags & SDL_BUTTON(1))
|
||||
{
|
||||
if (!list->clicked)
|
||||
{
|
||||
mouse_down = true;
|
||||
list->clicked = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
list->clicked = false;
|
||||
|
||||
mouse_x /= scale_x;
|
||||
mouse_y /= scale_y;
|
||||
|
||||
if (mouse_x >= dst.x && mouse_y >= dst.y && mouse_x < dst.x + dst.w && mouse_y < dst.y + dst.h)
|
||||
{
|
||||
src.x += src.w;
|
||||
|
||||
SDL_Rect arrow_src = { 1680, 0, 116, 32 };
|
||||
SDL_Rect arrow_dst = { dst.x, dst.y, 116 * INTERFACE_SCALE, 32 * INTERFACE_SCALE };
|
||||
|
||||
const char* text;
|
||||
|
||||
if (mouse_down)
|
||||
{
|
||||
arrow_dst.y += 2;
|
||||
|
||||
if (mouse_x < dst.x + dst.w / 2)
|
||||
{
|
||||
if (--list->preset < 0)
|
||||
list->preset = PING_PRESET_COUNT - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (++list->preset >= PING_PRESET_COUNT)
|
||||
list->preset = 0;
|
||||
}
|
||||
|
||||
g_config.ping_limit = g_defaultPingPresets[list->preset];
|
||||
config_save();
|
||||
}
|
||||
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &arrow_src, &arrow_dst);
|
||||
}
|
||||
else
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
|
||||
char* name;
|
||||
switch (g_config.ping_limit)
|
||||
{
|
||||
case 80:
|
||||
name = CLRCODE_RED "very strict";
|
||||
list->preset = 0;
|
||||
break;
|
||||
|
||||
case 120:
|
||||
name = CLRCODE_YLW "strict";
|
||||
list->preset = 1;
|
||||
break;
|
||||
|
||||
case 180:
|
||||
name = "forgiving";
|
||||
list->preset = 2;
|
||||
break;
|
||||
|
||||
case 250:
|
||||
name = CLRCODE_GRN "defualt";
|
||||
list->preset = 3;
|
||||
break;
|
||||
|
||||
case UINT16_MAX:
|
||||
name = CLRCODE_PUR "unlimited";
|
||||
list->preset = 4;
|
||||
break;
|
||||
|
||||
default:
|
||||
name = "custom";
|
||||
list->preset = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
list->label.scale = INTERFACE_SCALE;
|
||||
list->label.x = dst.x / INTERFACE_SCALE + 8;
|
||||
list->label.y = dst.y / INTERFACE_SCALE + 25;
|
||||
|
||||
char value[128];
|
||||
|
||||
if(list->preset == 4)
|
||||
snprintf(value, 128, "%s", name);
|
||||
else
|
||||
snprintf(value, 128, "%s - " CLRCODE_RST "%d", name, g_config.ping_limit);
|
||||
|
||||
list->label.text = value;
|
||||
label_update(renderer, (Component*)&list->label);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
#include "Config.h"
|
||||
#include "cJSON.h"
|
||||
#include "io/Threads.h"
|
||||
#include <ui/Main.h>
|
||||
#include <ui/Components.h>
|
||||
#include <ui/Presets.h>
|
||||
#include <Colors.h>
|
||||
#include <stdio.h>
|
||||
|
||||
bool playerlist_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
PlayerList* list = (PlayerList*)component;
|
||||
SDL_Rect src = { 4528, 0, 144, 176 };
|
||||
SDL_Rect dst = { list->x * INTERFACE_SCALE, list->y * INTERFACE_SCALE, list->w * INTERFACE_SCALE, list->h * INTERFACE_SCALE };
|
||||
|
||||
SDL_Point mouse;
|
||||
float scale_x, scale_y;
|
||||
Uint32 flags = SDL_GetMouseState(&mouse.x, &mouse.y);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
|
||||
mouse.x /= scale_x;
|
||||
mouse.y /= scale_y;
|
||||
|
||||
if (!(flags & SDL_BUTTON(1)))
|
||||
list->clicked = false;
|
||||
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
|
||||
SDL_Rect title_src = (SDL_Rect){ 4672, 0, 80, 8 };
|
||||
SDL_Rect title_dst = (SDL_Rect){ (list->x + 32) * INTERFACE_SCALE, (list->y + 6) * INTERFACE_SCALE, 80 * INTERFACE_SCALE, 8 * INTERFACE_SCALE };
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &title_src, &title_dst);
|
||||
|
||||
Label label = LabelCreate(list->x + 8, list->y + 8, "", INTERFACE_SCALE);
|
||||
PlayerButton op = (PlayerButton){ 4672, 16, 15, 8, button_update, list->x + 20 * 2, list->y - 2 + 8, 15, 8, ui_button_op, 0, { 0 } };
|
||||
PlayerButton kick = (PlayerButton){ 4672, 24, 29, 8, button_update, list->x + 31 * 2, list->y - 2 + 8, 29, 8, ui_button_kick, 0, { 0 } };
|
||||
PlayerButton ban = (PlayerButton){ 4672, 32, 24, 8, button_update, list->x + 49 * 2, list->y - 2 + 8, 24, 8, ui_button_ban, 0, { 0 } };
|
||||
|
||||
for(int i = 0; i < 7; i++)
|
||||
{
|
||||
if(list->peers[i].nickname.len == 0)
|
||||
continue;
|
||||
|
||||
label.y += 8 * INTERFACE_SCALE;
|
||||
op.d_y += 8 * INTERFACE_SCALE;
|
||||
kick.d_y += 8 * INTERFACE_SCALE;
|
||||
ban.d_y += 8 * INTERFACE_SCALE;
|
||||
|
||||
SDL_Rect check = (SDL_Rect){ (label.x - 2) * INTERFACE_SCALE, (label.y - 4) * INTERFACE_SCALE, 132 * INTERFACE_SCALE, 12 * INTERFACE_SCALE };
|
||||
char text[128];
|
||||
|
||||
if(!list->clicked && SDL_PointInRect(&mouse, &check))
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 73, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, &check);
|
||||
|
||||
snprintf(text, 128, "%s", "...");
|
||||
op.peer = list->peers[i];
|
||||
kick.peer = list->peers[i];
|
||||
ban.peer = list->peers[i];
|
||||
|
||||
if (!op.update(renderer, (Component*)&op) || !kick.update(renderer, (Component*)&kick) || !ban.update(renderer, (Component*)&ban))
|
||||
{
|
||||
list->clicked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
snprintf(text, 128, "%s", list->peers[i].nickname.value);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
label.text = text;
|
||||
label.update(renderer, (Component*)&label);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool playerlist_bans_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
PlayerListConfig* list = (PlayerListConfig*)component;
|
||||
SDL_Rect src = { 4528, 0, 144, 176 };
|
||||
SDL_Rect dst = { list->x * INTERFACE_SCALE, list->y * INTERFACE_SCALE, list->w * INTERFACE_SCALE, list->h * INTERFACE_SCALE };
|
||||
|
||||
SDL_Point mouse;
|
||||
float scale_x, scale_y;
|
||||
Uint32 flags = SDL_GetMouseState(&mouse.x, &mouse.y);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
|
||||
mouse.x /= scale_x;
|
||||
mouse.y /= scale_y;
|
||||
|
||||
if (!(flags & SDL_BUTTON(1)))
|
||||
list->clicked = false;
|
||||
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
|
||||
SDL_Rect title_src = (SDL_Rect){ 4763, 0, 58, 8 };
|
||||
SDL_Rect title_dst = (SDL_Rect){ (list->x + 42) * INTERFACE_SCALE, (list->y + 6) * INTERFACE_SCALE, 58 * INTERFACE_SCALE, 8 * INTERFACE_SCALE };
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &title_src, &title_dst);
|
||||
|
||||
Label label = LabelCreate(list->x + 8, list->y + 8, "", INTERFACE_SCALE);
|
||||
DeleteButton delete = (DeleteButton){ 4672, 40, 43, 8, button_update, list->x + 20 * 2, list->y - 2 + 8, 43, 8, ui_update_delete, false, BANS_FILE, g_bans, NULL };
|
||||
|
||||
MutexLock(g_banMut);
|
||||
{
|
||||
if (SDL_PointInRect(&mouse, &dst))
|
||||
{
|
||||
list->page -= g_mouseWheel;
|
||||
list->page = SDL_clamp(list->page, 0, SDL_max((int)ceil(cJSON_GetArraySize(g_bans) / 9.0) - 1, 0));
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
for(cJSON* ban = g_bans->child; ban; ban = ban->next)
|
||||
{
|
||||
if (!ban)
|
||||
continue;
|
||||
|
||||
if (i < list->page * 9)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
else if (i >= list->page * 9 + 9)
|
||||
break;
|
||||
|
||||
label.y += 8 * INTERFACE_SCALE;
|
||||
delete.d_y += 8 * INTERFACE_SCALE;
|
||||
|
||||
SDL_Rect check = (SDL_Rect){ (label.x - 2) * INTERFACE_SCALE, (label.y - 4) * INTERFACE_SCALE, 132 * INTERFACE_SCALE, 12 * INTERFACE_SCALE };
|
||||
|
||||
if(!list->clicked && SDL_PointInRect(&mouse, &check))
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 73, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, &check);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
|
||||
label.text = "...";
|
||||
label.update(renderer, (Component*)&label);
|
||||
|
||||
delete.key = ban->string;
|
||||
if (!delete.update(renderer, (Component*)&delete))
|
||||
{
|
||||
list->clicked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char text[128];
|
||||
snprintf(text, 128, "%s" CLRCODE_RST " (%s)", cJSON_GetStringValue(ban), strstr(ban->string, "-") != NULL ? "udid" : "ip");
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
|
||||
label.text = text;
|
||||
label.update(renderer, (Component*)&label);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
MutexUnlock(g_banMut);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool playerlist_op_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
PlayerListConfig* list = (PlayerListConfig*)component;
|
||||
SDL_Rect src = { 4528, 0, 144, 176 };
|
||||
SDL_Rect dst = { list->x * INTERFACE_SCALE, list->y * INTERFACE_SCALE, list->w * INTERFACE_SCALE, list->h * INTERFACE_SCALE };
|
||||
|
||||
SDL_Point mouse;
|
||||
float scale_x, scale_y;
|
||||
Uint32 flags = SDL_GetMouseState(&mouse.x, &mouse.y);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
|
||||
mouse.x /= scale_x;
|
||||
mouse.y /= scale_y;
|
||||
|
||||
if (!(flags & SDL_BUTTON(1)))
|
||||
list->clicked = false;
|
||||
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
|
||||
SDL_Rect title_src = (SDL_Rect){ 4672, 8, 96, 8 };
|
||||
SDL_Rect title_dst = (SDL_Rect){ (list->x + 24) * INTERFACE_SCALE, (list->y + 6) * INTERFACE_SCALE, 96 * INTERFACE_SCALE, 8 * INTERFACE_SCALE };
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &title_src, &title_dst);
|
||||
|
||||
Label label = LabelCreate(list->x + 8, list->y + 8, "", INTERFACE_SCALE);
|
||||
DeleteButton delete = (DeleteButton){ 4672, 40, 43, 8, button_update, list->x + 20 * 2, list->y - 2 + 8, 43, 8, ui_update_delete, false, OPERATORS_FILE, g_ops, NULL };
|
||||
|
||||
MutexLock(g_opMut);
|
||||
{
|
||||
if (SDL_PointInRect(&mouse, &dst))
|
||||
{
|
||||
list->page -= g_mouseWheel;
|
||||
list->page = SDL_clamp(list->page, 0, SDL_max((int)ceil(cJSON_GetArraySize(g_ops) / 9.0) - 1, 0));
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
for (cJSON* op = g_ops->child; op; op = op->next)
|
||||
{
|
||||
if (!op)
|
||||
continue;
|
||||
|
||||
if (i < list->page * 9)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
else if (i >= list->page * 9 + 9)
|
||||
break;
|
||||
|
||||
label.y += 8 * INTERFACE_SCALE;
|
||||
delete.d_y += 8 * INTERFACE_SCALE;
|
||||
|
||||
SDL_Rect check = (SDL_Rect){ (label.x - 2) * INTERFACE_SCALE, (label.y - 4) * INTERFACE_SCALE, 132 * INTERFACE_SCALE, 12 * INTERFACE_SCALE };
|
||||
char text[128];
|
||||
|
||||
if(!list->clicked && SDL_PointInRect(&mouse, &check))
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 73, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, &check);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
|
||||
label.text = "...";
|
||||
label.update(renderer, (Component*)&label);
|
||||
|
||||
delete.key = op->string;
|
||||
if (!delete.update(renderer, (Component*)&delete))
|
||||
{
|
||||
list->clicked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
label.text = cJSON_GetStringValue(op);
|
||||
label.update(renderer, (Component*)&label);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
MutexUnlock(g_opMut);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <ui/Presets.h>
|
||||
|
||||
Preset g_defaultPresets[] =
|
||||
{
|
||||
{ "default", { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true } },
|
||||
{ "classic", { false, false, true, false, true, false, true, true, true, false, false, false, true, false, true, false, false, false, false, false } },
|
||||
{ "easy", { true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, true } },
|
||||
{ "medium", { false, true, false, true, true, false, false, true, false, false, false, true, true, false, true, false, false, false, false, false } },
|
||||
{ "hard", { false, false, false, false, false, true, true, false, false, true, false, false, false, false, false, true, false, false, true, false } },
|
||||
{ "madness", { false, false, false, false, false, false, false, false, true, false, true, false, false, true, false, false, false, false, false, false } },
|
||||
{ "nightmare universe", { false, true, false, true, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false } },
|
||||
{ "spirits of hell", { true, false, false, false, false, true, false, false, false, false, false, true, false, true, false, false, false, false, false, false } },
|
||||
{ "custom", { 0 } },
|
||||
};
|
||||
|
||||
int g_defaultPingPresets[] = { 80, 120, 180, 250, UINT16_MAX };
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <ui/Resources.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
#include <ui/Spritesheet.h>
|
||||
|
||||
SDL_Texture* g_textureSheet = NULL;
|
||||
SDL_Texture* texture_load(SDL_Renderer* renderer, const void* data, unsigned int length)
|
||||
{
|
||||
SDL_RWops* rw = SDL_RWFromConstMem(data, (int)length);
|
||||
SDL_Surface* img = IMG_Load_RW(rw, 0);
|
||||
if (!img)
|
||||
return NULL;
|
||||
|
||||
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, img);
|
||||
SDL_FreeSurface(img);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
bool resources_load(SDL_Renderer* renderer)
|
||||
{
|
||||
if (!(g_textureSheet = texture_load(renderer, Spritesheet_png, Spritesheet_png_len)))
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "SDL ERROR", SDL_GetError(), NULL);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error (Report to dev)", "Failed to load " "g_textureSheet" "!\nPress OK to fallback to console mode.", NULL);
|
||||
return 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <ui/Components.h>
|
||||
|
||||
bool tbutton_update(SDL_Renderer* renderer, struct _Component* component)
|
||||
{
|
||||
ToggleButton* button = (ToggleButton*)component;
|
||||
SDL_Rect src = { button->x, button->y, button->w, button->h };
|
||||
SDL_Rect dst = { button->d_x * INTERFACE_SCALE, button->d_y * INTERFACE_SCALE, button->d_w * INTERFACE_SCALE, button->d_h * INTERFACE_SCALE };
|
||||
|
||||
int mouse_x, mouse_y;
|
||||
float scale_x, scale_y;
|
||||
Uint32 flags = SDL_GetMouseState(&mouse_x, &mouse_y);
|
||||
SDL_RenderGetScale(renderer, &scale_x, &scale_y);
|
||||
|
||||
mouse_x /= scale_x;
|
||||
mouse_y /= scale_y;
|
||||
|
||||
if (mouse_x >= dst.x && mouse_y >= dst.y && mouse_x < dst.x + dst.w && mouse_y < dst.y + dst.h)
|
||||
{
|
||||
src.x += src.w;
|
||||
|
||||
if (flags & SDL_BUTTON(1))
|
||||
{
|
||||
if (!button->clicked && button->cb)
|
||||
{
|
||||
*button->value = !(*button->value);
|
||||
button->cb(component);
|
||||
button->clicked = true;
|
||||
}
|
||||
dst.y += 2;
|
||||
}
|
||||
else
|
||||
button->clicked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*button->value)
|
||||
{
|
||||
if(!button->reverse)
|
||||
src.x += src.w * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (button->reverse)
|
||||
src.x += src.w * 2;
|
||||
}
|
||||
|
||||
button->clicked = false;
|
||||
}
|
||||
|
||||
SDL_RenderCopy(renderer, g_textureSheet, &src, &dst);
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user