diff --git a/core b/core new file mode 100644 index 0000000..bf92d1e Binary files /dev/null and b/core differ diff --git a/debug b/debug index 27cd1d0..4670304 100755 --- a/debug +++ b/debug @@ -1,2 +1,2 @@ -gcc src/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -lpthread -lncurses -o bin/mahou +gcc src/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -lpthread -lncursesw -o bin/mahou chmod +x bin/mahou diff --git a/src/client/client.c b/src/client/client.c index 0120882..1b0527c 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -2,7 +2,7 @@ #define BANNER_WIDTH 57 #define BANNER_HEIGHT 6 -#define AFTER_BANNER BANNER_HEIGHT + 6 +#define AFTER_BANNER BANNER_HEIGHT + 3 char BANNER[BANNER_HEIGHT][BANNER_WIDTH + 1] = { ". : :::. :: .: ... ... :::", ";;,. ;;; ;;`;; ,;; ;;, .;;;;;;;. ;; ;;;", @@ -31,6 +31,7 @@ struct { static int main_menu(); static void how_to_play(); +static void login_prompt(char*, uint16_t*); static void create_account(); static void client_loop(); @@ -47,6 +48,7 @@ void client() { return; } + setlocale(LC_ALL, ""); initscr(); start_color(); @@ -72,22 +74,15 @@ void client() { } endwin(); - - /*char in[10]; - sock_recv(sock, in, 10); - printf("got %s\r\n", in); - - sock_send(sock, "hello", 6); - printf("sent message"); - - sock_stop(sock); - sock_free(sock);*/ + + sock_stop(ctx.sock); + sock_free(ctx.sock); } static void draw_banner() { int i; for(i = 0; i < BANNER_HEIGHT; ++i) - mvprintw(3 + i, (COLS - BANNER_WIDTH) / 2, BANNER[i]); + scr_center_write(BANNER[i], BANNER_WIDTH, 3 + i); } static int main_menu() { @@ -96,10 +91,13 @@ static int main_menu() { clear(); noecho(); - //raw(); cbreak(); +#ifdef WORK + init_pair(1, COLOR_WHITE, COLOR_BLACK); +#else init_pair(1, COLOR_WHITE, COLOR_BLUE); +#endif init_pair(2, COLOR_BLACK, COLOR_CYAN); attron(COLOR_PAIR(1) | A_BOLD); @@ -114,7 +112,7 @@ static int main_menu() { color = selected == i ? 2 : 1; attron(COLOR_PAIR(color)); - mvprintw(AFTER_BANNER + i*2, (COLS - (MM_MAX_OPT_LEN + 2)) / 2, + mvprintw(AFTER_BANNER + 3 + i*2, (COLS - (MM_MAX_OPT_LEN + 2)) / 2, "* %s", MM_OPTIONS[i]); attroff(COLOR_PAIR(color)); } @@ -152,21 +150,8 @@ void how_to_play() { } void create_account() { - clear(); - noecho(); - cbreak(); - init_pair(1, COLOR_WHITE, COLOR_BLUE); - init_pair(2, COLOR_BLACK, COLOR_CYAN); - - attron(COLOR_PAIR(1) | A_BOLD); - - scr_fill(); - draw_banner(); - - move(0, 0); - - printw("%i %i %i ", KEY_BACKSPACE, KEY_BTAB, KEY_CTAB); + scr_alert(20, "this prompt box is a test of prompt box is a test of prompt box is a test of prompt box is a test of prompt box is a test of"); int a = 0; while(a != KEY_LF) diff --git a/src/client/client.h b/src/client/client.h index d00253c..8fc692e 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -2,6 +2,7 @@ #define CLIENT_H #include +#include #include #include "sock.h" #include "screen.h" diff --git a/src/client/screen.c b/src/client/screen.c index 933e94f..2c81d26 100644 --- a/src/client/screen.c +++ b/src/client/screen.c @@ -7,6 +7,13 @@ void scr_char_fill(char c) { addch(c); } +void scr_str_fill(char *s) { + int i, j; + for(i = 0; i < LINES; ++i) + for(j = 0; j < COLS; ++j) + addstr(s); +} + void scr_fill() { scr_char_fill(' '); } @@ -14,3 +21,55 @@ void scr_fill() { void scr_hide_cursor() { move(LINES - 1, COLS - 1); } + +void scr_center_write(char *string, int length, int row) { + if(length == 0) + length = strlen(string); + + mvprintw(row, (COLS - length) / 2, string); +} + +void scr_box(int top, int left, int width, int height) { + int i, j; + + mvaddstr(top, left, "\u2554"); + for(i = 0; i < width - 2; ++i) + addstr("\u2550"); + addstr("\u2557"); + + for(i = 0; i < height - 2; ++i) { + mvaddstr(top + i + 1, left, "\u2551"); + for(j = 0; j < width - 2; ++j) + addch(' '); + addstr("\u2551"); + } + + mvaddstr(top, left, "\u255A"); + for(i = 0; i < width - 2; ++i) + addstr("\u2550"); + addstr("\u255D"); +} + +static int calculate_height(int width, int length) { + return (int)ciel((float)length / (float)width); +} + +void scr_alert(int width, char *text) { + clear(); + noecho(); + cbreak(); + + int text_height = calculate_height(width, strlen(text)); + + init_pair(1, COLOR_WHITE, COLOR_BLUE); + init_pair(2, COLOR_BLACK, COLOR_CYAN); + init_pair(3, COLOR_WHITE, COLOR_BLACK); + + attron(COLOR_PAIR(3)); + scr_fill(); + attroff(COLOR_PAIR(3)); + + attron(COLOR_PAIR(1)); + scr_box(1, 1, 10, 10); + attroff(COLOR_PAIR(1)); +} \ No newline at end of file diff --git a/src/client/screen.h b/src/client/screen.h index c79a2fc..86705a2 100644 --- a/src/client/screen.h +++ b/src/client/screen.h @@ -3,9 +3,22 @@ #include #include +#include +#include +#include "common.h" void scr_fill(); void scr_char_fill(char); +void scr_wchar_fill(wchar_t); void scr_hide_cursor(); +void scr_center_write(char*, int, int); + +void scr_box(int, int, int, int); + +void scr_alert(int, char*); +BOOL scr_prompt_string(int, char*, char*, int); +BOOL scr_prompt_int(int, char*, int*); +BOOL scr_prompt_options(int, char*, char**, int, int*); + #endif diff --git a/src/common.h b/src/common.h index 9ababeb..4e2a259 100644 --- a/src/common.h +++ b/src/common.h @@ -5,6 +5,8 @@ #include #include +#define WORK + #define FALSE 0 #define TRUE 1 #define BOOL char @@ -12,6 +14,8 @@ #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) +#define KEY_BS 8 +#define KEY_TAB 9 #define KEY_LF 10 #define MAX_CONNS 100 @@ -25,4 +29,4 @@ uint64_t ntohll(uint64_t); void register_spawn_type(uint8_t); uint8_t get_spawn_type(); -#endif +#endif \ No newline at end of file