Change menu_headings to accept color and attribute

Instead of just accepting an attribute, it's now possible to
use a color, or both color and attribute, for example:

OPTIONS=menu_headings:inverse
OPTIONS=menu_headings:red
OPTIONS=menu_headings:red&underline

Default is still just inverse.
This lets the player change the menu heading color without
needing to use menu colors for them.

Also makes it so the core uses NO_COLOR instead of 0, for all
the menu lines which don't have any prefedefined color.

Tested for tty, curses, x11, qt, and win32
This commit is contained in:
Pasi Kallinen
2023-11-13 07:33:56 +02:00
parent dd6c249a8c
commit dd5ca5b058
47 changed files with 251 additions and 150 deletions
+2 -2
View File
@@ -471,11 +471,11 @@ void NetHackQtBind::qt_start_menu(winid wid, unsigned long mbehavior UNUSED)
}
void NetHackQtBind::qt_add_menu(winid wid, const glyph_info *glyphinfo,
const ANY_P * identifier, char ch, char gch, int attr, int clr UNUSED,
const ANY_P * identifier, char ch, char gch, int attr, int clr,
const char *str, unsigned itemflags)
{
NetHackQtWindow* window=id_to_window[(int)wid];
window->AddMenu(glyphinfo->glyph, identifier, ch, gch, attr,
window->AddMenu(glyphinfo->glyph, identifier, ch, gch, attr, clr,
QString::fromLatin1(str),
itemflags);
}
+6 -6
View File
@@ -258,7 +258,7 @@ NetHackQtMenuWindow::MenuItem::~MenuItem()
}
void NetHackQtMenuWindow::AddMenu(int glyph, const ANY_P *identifier,
char ch, char gch, int attr,
char ch, char gch, int attr, int clr,
const QString& str, unsigned itemflags)
{
bool presel = (itemflags & MENU_ITEMFLAGS_SELECTED) != 0;
@@ -279,11 +279,11 @@ void NetHackQtMenuWindow::AddMenu(int glyph, const ANY_P *identifier,
itemlist[itemcount].ch = ch;
itemlist[itemcount].gch = gch;
itemlist[itemcount].attr = attr;
itemlist[itemcount].color = clr;
itemlist[itemcount].str = str;
itemlist[itemcount].selected = itemlist[itemcount].preselected = presel;
itemlist[itemcount].itemflags = itemflags;
itemlist[itemcount].count = -1L;
itemlist[itemcount].color = -1;
// Display the boulder symbol correctly
if (str.left(8) == "boulder\t") {
int bracket = str.indexOf('[');
@@ -294,7 +294,7 @@ void NetHackQtMenuWindow::AddMenu(int glyph, const ANY_P *identifier,
}
}
int mcolor, mattr;
if (attr == 0 && ::iflags.use_menu_color
if (::iflags.use_menu_color
&& get_menu_coloring(str.toLatin1().constData(), &mcolor, &mattr)) {
itemlist[itemcount].attr = mattr;
itemlist[itemcount].color = mcolor;
@@ -618,7 +618,7 @@ void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
table->item(row, 4)->setFlags(Qt::ItemIsEnabled);
WidenColumn(4, fm.QFM_WIDTH(text));
if ((int) mi.color != -1) {
if ((int) mi.color != NO_COLOR) {
twi->setForeground(colors[mi.color].q);
}
@@ -1344,13 +1344,13 @@ void NetHackQtMenuOrTextWindow::StartMenu(bool using_WIN_INVEN)
}
void NetHackQtMenuOrTextWindow::AddMenu(
int glyph, const ANY_P* identifier,
char ch, char gch, int attr,
char ch, char gch, int attr, int clr,
const QString& str, unsigned itemflags)
{
if (!actual)
MenuOrText_too_soon_warning("AddMenu");
else
actual->AddMenu(glyph, identifier, ch, gch, attr, str, itemflags);
actual->AddMenu(glyph, identifier, ch, gch, attr, clr, str, itemflags);
}
void NetHackQtMenuOrTextWindow::EndMenu(const QString& prompt)
{
+2 -2
View File
@@ -58,7 +58,7 @@ public:
virtual void StartMenu(bool using_WIN_INVEN = false);
virtual void AddMenu(int glyph, const ANY_P *identifier,
char ch, char gch, int attr,
char ch, char gch, int attr, int clr,
const QString& str, unsigned itemflags);
virtual void EndMenu(const QString& prompt);
virtual int SelectMenu(int how, MENU_ITEM_P **menu_list);
@@ -195,7 +195,7 @@ public:
// Menu
virtual void StartMenu(bool using_WIN_INVENT = false);
virtual void AddMenu(int glyph, const ANY_P *identifier,
char ch, char gch, int attr,
char ch, char gch, int attr, int clr,
const QString& str, unsigned itemflags);
virtual void EndMenu(const QString& prompt);
virtual int SelectMenu(int how, MENU_ITEM_P **menu_list);
+1 -1
View File
@@ -103,7 +103,7 @@ void NetHackQtWindow::PutStr(int attr UNUSED, const QString& text UNUSED) { puts
void NetHackQtWindow::StartMenu(bool using_WIN_INVEN UNUSED)
{ puts("unexpected StartMenu"); }
void NetHackQtWindow::AddMenu(int glyph UNUSED, const ANY_P* identifier UNUSED,
char ch UNUSED, char gch UNUSED, int attr UNUSED,
char ch UNUSED, char gch UNUSED, int attr UNUSED, int clr UNUSED,
const QString& str UNUSED, unsigned itemflags UNUSED)
{ puts("unexpected AddMenu"); }
void NetHackQtWindow::EndMenu(const QString& prompt UNUSED) { puts("unexpected EndMenu"); }
+1 -1
View File
@@ -37,7 +37,7 @@ public:
}
virtual void StartMenu(bool using_WIN_INVEN = false);
virtual void AddMenu(int glyph, const ANY_P* identifier,
char ch, char gch, int attr,
char ch, char gch, int attr, int clr,
const QString& str, unsigned itemflags);
virtual void EndMenu(const QString& prompt);
virtual int SelectMenu(int how, MENU_ITEM_P **menu_list);