mirror of
https://codeberg.org/noisytoot/notnotdnethack.git
synced 2025-08-10 22:51:38 +01:00
curses improvements - #extcmd, msgtype.
This commit is contained in:
parent
59925ebdcd
commit
ed706c1dfe
7 changed files with 87 additions and 20 deletions
|
@ -21,6 +21,7 @@ boolean counting; /* Count window is active */
|
|||
#define NONE -1
|
||||
#define KEY_ESC 0x1b
|
||||
#define DIALOG_BORDER_COLOR CLR_MAGENTA
|
||||
#define ALERT_BORDER_COLOR CLR_RED
|
||||
#define SCROLLBAR_COLOR CLR_MAGENTA
|
||||
#define SCROLLBAR_BACK_COLOR CLR_BLACK
|
||||
#define HIGHLIGHT_COLOR CLR_WHITE
|
||||
|
@ -178,6 +179,10 @@ extern void curses_puts(winid wid, int attr, const char *text);
|
|||
|
||||
extern void curses_clear_nhwin(winid wid);
|
||||
|
||||
extern void curses_alert_win_border(winid wid, boolean onoff);
|
||||
|
||||
extern void curses_alert_main_borders(boolean onoff);
|
||||
|
||||
extern void curses_draw_map(int sx, int sy, int ex, int ey);
|
||||
|
||||
extern boolean curses_map_borders(int *sx, int *sy, int *ex, int *ey,
|
||||
|
@ -279,6 +284,8 @@ extern void curses_cleanup(void);
|
|||
|
||||
extern void curses_message_win_puts(const char *message, boolean recursed);
|
||||
|
||||
extern int curses_block(boolean require_tab); /* for MSGTYPE=STOP */
|
||||
|
||||
extern int curses_more(void);
|
||||
|
||||
extern void curses_clear_unhighlight_message_window(void);
|
||||
|
|
|
@ -393,7 +393,7 @@ int curses_ext_cmd()
|
|||
}
|
||||
|
||||
winy += messageh - 1;
|
||||
extwin = newwin(1, 25, winy, winx);
|
||||
extwin = newwin(1, messagew-2, winy, winx);
|
||||
startx = 0;
|
||||
starty = 0;
|
||||
pline("#");
|
||||
|
@ -406,17 +406,20 @@ int curses_ext_cmd()
|
|||
wmove(extwin, starty, startx);
|
||||
waddstr(extwin, "# ");
|
||||
wmove(extwin, starty, startx + 2);
|
||||
curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, ON);
|
||||
waddstr(extwin, cur_choice);
|
||||
curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, OFF);
|
||||
wmove(extwin, starty, strlen(cur_choice) + startx + 2);
|
||||
wprintw(extwin, " ", cur_choice);
|
||||
|
||||
/* if we have an autocomplete command, AND it matches uniquely */
|
||||
if (matches == 1)
|
||||
{
|
||||
curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, ON);
|
||||
wmove(extwin, starty, strlen(cur_choice) + startx + 2);
|
||||
wprintw(extwin, "%s ", extcmdlist[ret].ef_txt
|
||||
wprintw(extwin, "%s", extcmdlist[ret].ef_txt
|
||||
+ strlen(cur_choice));
|
||||
curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, OFF);
|
||||
mvwprintw(extwin, starty,
|
||||
strlen(extcmdlist[ret].ef_txt) + 2, " ");
|
||||
}
|
||||
|
||||
wrefresh(extwin);
|
||||
|
@ -424,7 +427,7 @@ int curses_ext_cmd()
|
|||
prompt_width = strlen(cur_choice);
|
||||
matches = 0;
|
||||
|
||||
if (letter == DOESCAPE)
|
||||
if (letter == DOESCAPE || letter == ERR)
|
||||
{
|
||||
ret = -1;
|
||||
break;
|
||||
|
@ -432,6 +435,14 @@ int curses_ext_cmd()
|
|||
|
||||
if ((letter == '\r') || (letter == '\n'))
|
||||
{
|
||||
if (ret == -1) {
|
||||
for (count = 0; extcmdlist[count].ef_txt; count++) {
|
||||
if (!strcasecmp(cur_choice, extcmdlist[count].ef_txt)) {
|
||||
ret = count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -450,9 +461,14 @@ int curses_ext_cmd()
|
|||
}
|
||||
}
|
||||
|
||||
if (letter != '*' && prompt_width < BUFSZ -1) {
|
||||
cur_choice[prompt_width] = letter;
|
||||
cur_choice[prompt_width + 1] = '\0';
|
||||
ret = -1;
|
||||
}
|
||||
for (count = 0; extcmdlist[count].ef_txt; count++)
|
||||
{
|
||||
if (!extcmdlist[count].autocomplete) continue;
|
||||
if (!extcmdlist[count].autocomplete) continue;
|
||||
if (strlen(extcmdlist[count].ef_txt) > prompt_width)
|
||||
{
|
||||
if (strncasecmp(cur_choice, extcmdlist[count].ef_txt,
|
||||
|
@ -461,20 +477,18 @@ int curses_ext_cmd()
|
|||
if ((extcmdlist[count].ef_txt[prompt_width] ==
|
||||
lowc(letter)) || letter == '*')
|
||||
{
|
||||
if ((matches == 0) && (letter != '*'))
|
||||
if (matches == 0)
|
||||
{
|
||||
ret = count;
|
||||
cur_choice[prompt_width] = letter;
|
||||
cur_choice[prompt_width + 1] = '\0';
|
||||
}
|
||||
|
||||
matches++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
curses_destroy_win(extwin);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1197,6 +1211,11 @@ static int menu_get_selections(WINDOW *win, nhmenu *menu, int how)
|
|||
while (!dismiss)
|
||||
{
|
||||
curletter = getch();
|
||||
|
||||
if (curletter == ERR) {
|
||||
num_selected = -1;
|
||||
dismiss = TRUE;
|
||||
}
|
||||
|
||||
if (curletter == DOESCAPE)
|
||||
{
|
||||
|
|
|
@ -277,14 +277,20 @@ void curses_display_nhwindow(winid wid, BOOLEAN_P block)
|
|||
{
|
||||
(void) curses_more();
|
||||
}
|
||||
|
||||
|
||||
if ((wid == MESSAGE_WIN) && block)
|
||||
{
|
||||
if (u.uhp != -1) (void) curses_block(TRUE);
|
||||
/* don't bug player with TAB prompt on "Saving..." */
|
||||
else (void) curses_more();
|
||||
}
|
||||
|
||||
if (curses_is_menu(wid) || curses_is_text(wid))
|
||||
{
|
||||
curses_end_menu(wid, "");
|
||||
curses_select_menu(wid, PICK_NONE, &selected);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -153,31 +153,42 @@ void curses_message_win_puts(const char *message, boolean recursed)
|
|||
}
|
||||
|
||||
|
||||
int curses_more()
|
||||
int curses_block(boolean require_tab)
|
||||
{
|
||||
int height, width, ret;
|
||||
WINDOW *win = curses_get_nhwin(MESSAGE_WIN);
|
||||
|
||||
curses_get_window_size(MESSAGE_WIN, &height, &width);
|
||||
curses_toggle_color_attr(win, MORECOLOR, NONE, ON);
|
||||
mvwprintw(win, my, mx, ">>");
|
||||
mvwprintw(win, my, mx, require_tab ? "<TAB!>" : ">>");
|
||||
curses_toggle_color_attr(win, MORECOLOR, NONE, OFF);
|
||||
if (require_tab) curses_alert_main_borders(TRUE);
|
||||
wrefresh(win);
|
||||
ret = wgetch(win);
|
||||
while ((ret = wgetch(win) != '\t') && require_tab);
|
||||
if (require_tab) curses_alert_main_borders(FALSE);
|
||||
if (height == 1)
|
||||
{
|
||||
curses_clear_unhighlight_message_window();
|
||||
}
|
||||
else
|
||||
{
|
||||
mvwprintw(win, my, mx, " ");
|
||||
scroll_window(MESSAGE_WIN);
|
||||
turn_lines = 1;
|
||||
mvwprintw(win, my, mx, " ");
|
||||
wrefresh(win);
|
||||
if (!require_tab)
|
||||
{
|
||||
scroll_window(MESSAGE_WIN);
|
||||
turn_lines = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int curses_more()
|
||||
{
|
||||
return curses_block(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/* Clear the message window if one line; otherwise unhighlight old messages */
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
void curses_message_win_puts(const char *message, boolean recursed);
|
||||
|
||||
int curses_block(boolean require_tab);
|
||||
|
||||
int curses_more(void);
|
||||
|
||||
void curses_clear_unhighlight_message_window(void);
|
||||
|
|
|
@ -561,6 +561,24 @@ void curses_clear_nhwin(winid wid)
|
|||
}
|
||||
}
|
||||
|
||||
/* Change colour of window border to alert player to something */
|
||||
void curses_alert_win_border(winid wid, boolean onoff)
|
||||
{
|
||||
WINDOW *win = curses_get_nhwin(wid);
|
||||
if (!curses_window_has_border(wid)) return;
|
||||
if (onoff) curses_toggle_color_attr(win, ALERT_BORDER_COLOR, NONE, ON);
|
||||
box(win, 0, 0);
|
||||
if (onoff) curses_toggle_color_attr(win, ALERT_BORDER_COLOR, NONE, OFF);
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
|
||||
void curses_alert_main_borders(boolean onoff)
|
||||
{
|
||||
curses_alert_win_border(MAP_WIN, onoff);
|
||||
curses_alert_win_border(MESSAGE_WIN, onoff);
|
||||
curses_alert_win_border(STATUS_WIN, onoff);
|
||||
}
|
||||
|
||||
/* Return true if given wid is a main NetHack window */
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@ void curses_puts(winid wid, int attr, const char *text);
|
|||
|
||||
void curses_clear_nhwin(winid wid);
|
||||
|
||||
void curses_alert_win_border(winid wid, boolean onoff);
|
||||
|
||||
void curses_alert_main_borders(boolean onoff);
|
||||
|
||||
void curses_draw_map(int sx, int sy, int ex, int ey);
|
||||
|
||||
boolean curses_map_borders(int *sx, int *sy, int *ex, int *ey, int ux,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue