assaultfish/client/ui.c

125 lines
3.5 KiB
C
Raw Normal View History

2025-12-19 08:52:48 +09:00
#include <af_common.h>
2025-12-19 15:18:15 +09:00
MwWidget ui_notice(int width, int height) {
if(width == 0 && height == 0) {
width = 400;
2025-12-19 08:52:48 +09:00
height = 300;
}
return MwVaCreateWidget(MwFrameClass, "notice", window, (MwGetInteger(window, MwNwidth) - width) / 2, (MwGetInteger(window, MwNheight) - height) / 2, width, height,
2025-12-19 15:18:15 +09:00
MwNhasBorder, 1,
MwNinverted, 0,
NULL);
2025-12-19 08:52:48 +09:00
}
2025-12-19 15:18:15 +09:00
void ui_notice_destroy(MwWidget widget) {
2025-12-19 08:52:48 +09:00
MwDestroyWidget(widget);
}
2025-12-19 15:18:15 +09:00
static void ui_login_join(MwWidget handle, void* user, void* client) {
2025-12-20 00:29:38 +09:00
char* username = MwStringDuplicate(MwGetText(MwGetVoid(user, "VusernameEntry"), MwNtext));
char* hostname = MwStringDuplicate(MwGetText(MwGetVoid(user, "VhostnameEntry"), MwNtext));
int port = atoi(MwGetText(MwGetVoid(user, "VportEntry"), MwNtext));
2025-12-19 15:18:15 +09:00
MwLLDestroyPixmap(MwGetVoid(user, MwNpixmap));
ui_notice_destroy(user);
2025-12-20 00:29:38 +09:00
net_connect(username, hostname, port);
free(username);
free(hostname);
2025-12-19 15:18:15 +09:00
}
static void ui_login(void) {
MwWidget wnd = ui_notice(0, 0);
int bw = MwDefaultBorderWidth(wnd);
MwWidget join = MwVaCreateWidget(MwButtonClass, "join", wnd, MwGetInteger(wnd, MwNwidth) - bw - 10 - 96, MwGetInteger(wnd, MwNheight) - bw - 10 - 24, 96, 24,
MwNtext, "Join",
NULL);
MwWidget box = MwVaCreateWidget(MwBoxClass, "box", wnd, bw, bw, MwGetInteger(wnd, MwNwidth) - bw * 2, MwGetInteger(wnd, MwNheight) - bw * 2 - 10 - 24,
MwNorientation, MwVERTICAL,
MwNmargin, 10,
MwNpadding, 10,
NULL);
MwWidget icon = MwVaCreateWidget(MwImageClass, "icon", box, 0, 0, 0, 0,
MwNfillArea, 0,
MwNfixedSize, 100,
NULL);
MwWidget entrybox[3];
2025-12-20 00:29:38 +09:00
MwWidget entryinput[3];
2025-12-19 15:18:15 +09:00
MwLLPixmap px = MwLoadImage(wnd, DATAROOTDIR "/assaultfish/logo.png");
2025-12-19 08:52:48 +09:00
const char* labels[3] = {
2025-12-19 15:18:15 +09:00
"Username",
"Hostname",
"Port"};
2025-12-19 08:52:48 +09:00
const char* entries[3] = {
2025-12-19 15:18:15 +09:00
"JohnDoe",
"127.0.0.1",
"",
2025-12-19 08:52:48 +09:00
};
2025-12-19 15:18:15 +09:00
int i;
2025-12-19 08:52:48 +09:00
char buf[16];
sprintf(buf, "%d", AF_DEFAULT_PORT);
entries[2] = buf;
2025-12-19 15:18:15 +09:00
for(i = 0; i < 3; i++) {
2025-12-19 08:52:48 +09:00
entrybox[i] = MwVaCreateWidget(MwBoxClass, "entrybox", box, 0, 0, 0, 0,
2025-12-19 15:18:15 +09:00
MwNfixedSize, 24,
MwNmargin, 10,
NULL);
MwVaCreateWidget(MwLabelClass, "label", entrybox[i], 0, 0, 0, 0,
MwNfixedSize, 100,
MwNtext, labels[i],
MwNalignment, MwALIGNMENT_END,
NULL);
2025-12-20 00:29:38 +09:00
entryinput[i] = MwVaCreateWidget(MwEntryClass, "entry", entrybox[i], 0, 0, 0, 0,
MwNtext, entries[i],
NULL);
2025-12-19 08:52:48 +09:00
}
MwVaApply(icon,
2025-12-19 15:18:15 +09:00
MwNpixmap, px,
NULL);
MwVaApply(wnd,
MwNpixmap, px,
2025-12-20 00:29:38 +09:00
"VusernameEntry", entryinput[0],
"VhostnameEntry", entryinput[1],
"VportEntry", entryinput[2],
2025-12-19 15:18:15 +09:00
NULL);
2025-12-19 08:52:48 +09:00
2025-12-19 15:18:15 +09:00
MwAddUserHandler(join, MwNactivateHandler, ui_login_join, wnd);
2025-12-19 08:52:48 +09:00
}
2025-12-20 00:29:38 +09:00
static void ui_message_ok(MwWidget handle, void* user, void* client) {
MwDispatchUserHandler(user, MwNactivateHandler, NULL);
ui_notice_destroy(user);
}
MwWidget ui_message(const char* message) {
MwWidget wnd = ui_notice(0, 0);
int bw = MwDefaultBorderWidth(wnd);
MwWidget label = MwVaCreateWidget(MwLabelClass, "label", wnd, bw, (MwGetInteger(wnd, MwNheight) - 24) / 2, MwGetInteger(wnd, MwNwidth) - bw * 2, 24,
MwNtext, message,
NULL);
MwWidget ok = MwVaCreateWidget(MwButtonClass, "ok", wnd, MwGetInteger(wnd, MwNwidth) - bw - 10 - 96, MwGetInteger(wnd, MwNheight) - bw - 10 - 24, 96, 24,
MwNtext, "OK",
NULL);
MwAddUserHandler(ok, MwNactivateHandler, ui_message_ok, wnd);
return wnd;
}
2025-12-20 00:32:49 +09:00
void ui_scene_change(void) {
2025-12-19 15:18:15 +09:00
if(gl_scene == AF_SCENE_MAIN) {
ui_login();
}
}
2025-12-19 08:52:48 +09:00
2025-12-19 15:18:15 +09:00
void ui_init(void) {
MwToggleDarkTheme(root, 1);
2025-12-19 08:52:48 +09:00
}