big money no woomy

This commit is contained in:
mallocnull 2017-11-08 17:00:08 -06:00
parent e73cba81a5
commit f1dd4943ae
4 changed files with 136 additions and 41 deletions

BIN
core

Binary file not shown.

View file

@ -155,7 +155,8 @@ void how_to_play() {
void create_account() { void create_account() {
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"); char input[9];
scr_prompt_string(20, "this prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test", input, 8);
/*int a = 0; /*int a = 0;
while(a != KEY_LF) while(a != KEY_LF)

View file

@ -72,21 +72,43 @@ WINDOW* scr_win_box(int top, int left, int width, int height) {
return win; return win;
} }
static int calculate_height(int width, int length) { static int calculate_height(int width, char *text) {
return (int)ceil((float)length / (float)width); int len = strlen(text), lines = 0, line_width, line_len, char_width, i;
char *ptr, *cpy = (char*)malloc(len * sizeof(char));
strcpy(cpy, text);
ptr = strtok(cpy, "\n");
while(ptr != NULL) {
line_width = 0;
line_len = strlen(ptr);
for(i = 0; i < line_len; ++i) {
if(ptr[i] & 0x80 == 0 && isprint(ptr[i])) {
char_width = 0;
++line_width;
} else if(ptr[i] & 0xE0 == 0xC0) {
char_width = 1;
++line_width;
} else if(ptr[i] & 0xF0 == 0xE0) {
char_width = 2;
++line_width;
} else if(ptr[i] & 0xF8 == 0xF0) {
char_width = 3;
++line_width;
} else if(ptr[i] & 0xC0 == 0x80) {
if(char_width > 0)
--char_width;
else
++line_width;
}
} }
/*static void init_prompt_pairs() {
#ifdef WORK
init_pair(1, COLOR_WHITE, COLOR_BLACK); ptr = strtok(NULL, "\n");
init_pair(2, COLOR_BLACK, COLOR_CYAN); }
init_pair(3, COLOR_WHITE, COLOR_BLACK);
#else return lines;
init_pair(1, COLOR_WHITE, COLOR_BLUE); }
init_pair(2, COLOR_BLACK, COLOR_CYAN);
init_pair(3, COLOR_WHITE, COLOR_BLACK);
#endif
}*/
void scr_alert(int width, char *text) { void scr_alert(int width, char *text) {
erase(); erase();
@ -197,16 +219,16 @@ BOOL scr_prompt(int width, char *text) {
} }
delwin(win); delwin(win);
return retval;
} }
BOOL scr_prompt_string(int width, char *text, char *out, int outlen) { void scr_prompt_string(int width, char *text, char *out, int outlen) {
erase(); erase();
noecho(); noecho();
cbreak(); cbreak();
int ch, curlen = 0; int ch, curlen = 0, i, origin;
short pair; short pair;
BOOL retval = TRUE, loop = TRUE;
WINDOW *win; WINDOW *win;
int text_height = calculate_height(width, strlen(text)); int text_height = calculate_height(width, strlen(text));
@ -230,37 +252,107 @@ BOOL scr_prompt_string(int width, char *text, char *out, int outlen) {
wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
out[0] = '\0'; out[0] = '\0';
for(;;) {
origin = (width - (outlen + 3)) / 2;
wmove(win, text_height + 1, origin);
pair = SCR_PAIR(SCR_BLACK, SCR_CYAN);
wattron(win, pair);
wprintw(win, "-> ");
wattron(win, A_UNDERLINE);
wprintw(win, out);
for(i = curlen; i < outlen; ++i)
waddch(win, ' ');
wattroff(win, A_UNDERLINE);
wattroff(win, pair);
//if(curlen < outlen)
wmove(win, text_height + 1, origin + 3 + curlen);
//else
//scr_hide_cursor();
wrefresh(win);
ch = getch();
if(curlen < outlen && isprint(ch)) {
out[curlen] = ch;
out[curlen + 1] = '\0';
++curlen;
} else if(curlen != 0 && (ch == KEY_BS || ch == KEY_BACKSPACE)) {
--curlen;
out[curlen] = '\0';
} else if(ch == KEY_LF || ch == KEY_ENTER)
break;
}
delwin(win);
}
int scr_prompt_options(int width, char *text, char **options, int optcount) {
erase();
noecho();
cbreak();
int ch, selected = 0, i, origin, maxlen = 0;
short pair;
BOOL loop = TRUE;
WINDOW *win;
int text_height = calculate_height(width, strlen(text));
#ifdef WORK
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
#else
pair = SCR_PAIR(SCR_WHITE, SCR_BLUE);
#endif
attron(pair);
scr_fill();
attron(pair);
attron(SCR_PAIR(SCR_WHITE, SCR_BLACK));
win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 3 + optcount);
attroff(SCR_PAIR(SCR_WHITE, SCR_BLACK));
wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
wprintw(win, text);
wrefresh(win);
wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
for(i = 0; i < optcount; ++i)
maxlen = MAX(maxlen, strlen(options[i]) + 3);
origin = (width - maxlen) / 2;
while(loop) { while(loop) {
wmove(win, text_height + 1, (width - (outlen + 3)) / 2); origin = (width - (outlen + 3)) / 2;
wmove(win, text_height + 1, origin);
pair = retval == TRUE for(i = 0; i < optcount; ++i) {
? SCR_PAIR(SCR_BLACK, SCR_CYAN) pair = i == selected ? SCR_PAIR(SCR_BLACK, SCR_CYAN)
: SCR_PAIR(SCR_WHITE, SCR_BLACK); : SCR_PAIR(SCR_WHITE, SCR_BLACK);
wattron(win, pair);
wprintw(win, check);
wattroff(win, pair);
wprintw(win, " "); }
pair = retval == FALSE
? SCR_PAIR(SCR_BLACK, SCR_CYAN)
: SCR_PAIR(SCR_WHITE, SCR_BLACK);
wattron(win, pair); wattron(win, pair);
wprintw(win, cross); wprintw(win, "-> ");
wattroff(win, pair);
wattron(win, A_UNDERLINE);
wprintw(win, out);
for(i = curlen; i < outlen; ++i)
waddch(win, ' ');
wattroff(win, A_UNDERLINE);
wattroff(win, pair);
wrefresh(win); wrefresh(win);
scr_hide_cursor(); scr_hide_cursor();
ch = getch(); ch = getch();
switch(ch) { switch(ch) {
case KEY_LEFT: case KEY_UP:
retval = TRUE; selected = selected == 0 ? optcount - 1 : selected - 1;
break; break;
case KEY_RIGHT: case KEY_DOWN:
retval = FALSE; selected = selected == optcount - 1 ? 0 : selected + 1;
break; break;
case KEY_LF: case KEY_LF:
case KEY_ENTER: case KEY_ENTER:
@ -270,4 +362,5 @@ BOOL scr_prompt_string(int width, char *text, char *out, int outlen) {
} }
delwin(win); delwin(win);
return selected;
} }

View file

@ -1,10 +1,12 @@
#ifndef CLIENT_SCREEN_H #ifndef CLIENT_SCREEN_H
#define CLIENT_SCREEN_H #define CLIENT_SCREEN_H
#include <ncurses.h> #include <ncurses.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <ctype.h>
#include "common.h" #include "common.h"
#define SCR_BLACK 0 #define SCR_BLACK 0
@ -32,8 +34,7 @@ WINDOW* scr_win_box(int, int, int, int);
void scr_alert(int, char*); void scr_alert(int, char*);
BOOL scr_prompt(int, char*); BOOL scr_prompt(int, char*);
BOOL scr_prompt_string(int, char*, char*, int); void scr_prompt_string(int, char*, char*, int);
BOOL scr_prompt_int(int, char*, int*); int scr_prompt_options(int, char*, char**, int);
BOOL scr_prompt_options(int, char*, char**, int, int*);
#endif #endif