Hilite Status: Improved
Allow defining multiple stops per field. Add hitpointbar.
This commit is contained in:
+76
-35
@@ -18,10 +18,10 @@ typedef struct mswin_nethack_status_window {
|
||||
int n_fields;
|
||||
const char **vals;
|
||||
boolean *activefields;
|
||||
int *percents;
|
||||
int *colors;
|
||||
} NHStatusWindow, *PNHStatusWindow;
|
||||
|
||||
#ifdef STATUS_VIA_WINDOWPORT
|
||||
static int fieldorder1[] = { BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN,
|
||||
BL_WI, BL_CH, BL_ALIGN, BL_SCORE, -1 };
|
||||
static int fieldorder2[] = { BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX,
|
||||
@@ -29,7 +29,6 @@ static int fieldorder2[] = { BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX,
|
||||
BL_EXP, BL_HD, BL_TIME, BL_HUNGER,
|
||||
BL_CAP, BL_CONDITION, -1 };
|
||||
static int *fieldorders[] = { fieldorder1, fieldorder2, NULL };
|
||||
#endif /* STATUS_VIA_WINDOWPORT */
|
||||
|
||||
static TCHAR szStatusWindowClass[] = TEXT("MSNHStatusWndClass");
|
||||
LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
@@ -133,9 +132,10 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
case MSNH_MSG_GETTEXT: {
|
||||
PMSNHMsgGetText msg_data = (PMSNHMsgGetText) lParam;
|
||||
#ifdef STATUS_VIA_WINDOWPORT
|
||||
#ifdef STATUS_HILITES
|
||||
int **fop;
|
||||
int *f;
|
||||
|
||||
msg_data->buffer[0] = '\0';
|
||||
if (data->n_fields > 0) {
|
||||
for (fop = fieldorders; *fop; fop++) {
|
||||
@@ -143,20 +143,20 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if (data->activefields[*f])
|
||||
strncat(msg_data->buffer, data->vals[*f],
|
||||
msg_data->max_size
|
||||
- strlen(msg_data->buffer));
|
||||
- strlen(msg_data->buffer));
|
||||
}
|
||||
strncat(msg_data->buffer, "\r\n",
|
||||
msg_data->max_size - strlen(msg_data->buffer));
|
||||
}
|
||||
}
|
||||
#else /* STATUS_VIA_WINDOWPORT */
|
||||
#else
|
||||
strncpy(msg_data->buffer, data->window_text[0],
|
||||
msg_data->max_size);
|
||||
strncat(msg_data->buffer, "\r\n",
|
||||
msg_data->max_size - strlen(msg_data->buffer));
|
||||
strncat(msg_data->buffer, data->window_text[1],
|
||||
msg_data->max_size - strlen(msg_data->buffer));
|
||||
#endif /* STATUS_VIA_WINDOWPORT */
|
||||
#endif
|
||||
} break;
|
||||
|
||||
case MSNH_MSG_UPDATE_STATUS: {
|
||||
@@ -164,6 +164,7 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
data->n_fields = msg_data->n_fields;
|
||||
data->vals = msg_data->vals;
|
||||
data->activefields = msg_data->activefields;
|
||||
data->percents = msg_data->percents;
|
||||
data->colors = msg_data->colors;
|
||||
InvalidateRect(hWnd, NULL, TRUE);
|
||||
} break;
|
||||
@@ -206,10 +207,12 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef STATUS_VIA_WINDOWPORT
|
||||
#ifdef STATUS_HILITES
|
||||
static LRESULT
|
||||
onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
int hpbar_percent = 100;
|
||||
int hpbar_color = NO_COLOR;
|
||||
int *f;
|
||||
int **fop;
|
||||
SIZE sz;
|
||||
@@ -238,45 +241,83 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||
: (COLORREF) GetSysColor(DEFAULT_COLOR_FG_STATUS);
|
||||
OldFg = SetTextColor(hdc, Fg);
|
||||
|
||||
if (iflags.wc2_hitpointbar && BL_HP < data->n_fields
|
||||
&& data->activefields[BL_HP]) {
|
||||
hpbar_percent = data->percents[BL_HP];
|
||||
hpbar_color = data->colors[BL_HP] & 0x00ff;
|
||||
}
|
||||
|
||||
for (fop = fieldorders; *fop; fop++) {
|
||||
LONG left = rt.left;
|
||||
LONG cy = 0;
|
||||
int vlen;
|
||||
for (f = *fop; *f != -1; f++) {
|
||||
int clr, atr;
|
||||
int fntatr = ATR_NONE;
|
||||
HGDIOBJ fnt;
|
||||
COLORREF nFg, nBg;
|
||||
|
||||
if (((*f) >= data->n_fields) || (!data->activefields[*f]))
|
||||
continue;
|
||||
clr = data->colors[*f] & 0x00ff;
|
||||
atr = (data->colors[*f] & 0xff00) >> 8;
|
||||
vlen = strlen(data->vals[*f]);
|
||||
NH_A2W(data->vals[*f], wbuf, SIZE(wbuf));
|
||||
|
||||
if (!iflags.use_status_hilites) {
|
||||
SelectObject(hdc, normalFont);
|
||||
SetBkColor(hdc, Bg);
|
||||
SetTextColor(hdc, Fg);
|
||||
} else if (data->colors[*f] == CLR_MAX
|
||||
|| data->colors[*f] == BL_HILITE_NONE) {
|
||||
SelectObject(hdc, normalFont);
|
||||
SetBkColor(hdc, Bg);
|
||||
SetTextColor(hdc, Fg);
|
||||
} else if (data->colors[*f] > 0) {
|
||||
SelectObject(hdc, normalFont);
|
||||
SetBkColor(hdc, Bg);
|
||||
SetTextColor(hdc, nhcolor_to_RGB(data->colors[*f]));
|
||||
} else if (data->colors[*f] == BL_HILITE_INVERSE) {
|
||||
SelectObject(hdc, normalFont);
|
||||
SetBkColor(hdc, Fg);
|
||||
SetTextColor(hdc, Bg);
|
||||
} else if (data->colors[*f] == BL_HILITE_BOLD) {
|
||||
SelectObject(hdc, boldFont);
|
||||
SetBkColor(hdc, Bg);
|
||||
SetTextColor(hdc, Fg);
|
||||
} else {
|
||||
SelectObject(hdc, normalFont);
|
||||
SetBkColor(hdc, Bg);
|
||||
SetTextColor(hdc, Fg);
|
||||
}
|
||||
if (atr & HL_BOLD)
|
||||
fntatr = ATR_BOLD;
|
||||
else if (atr & HL_INVERSE)
|
||||
fntatr = ATR_INVERSE;
|
||||
else if (atr & HL_ULINE)
|
||||
fntatr = ATR_ULINE;
|
||||
else if (atr & HL_BLINK)
|
||||
fntatr = ATR_BLINK;
|
||||
else if (atr & HL_DIM)
|
||||
fntatr = ATR_DIM;
|
||||
fnt = mswin_get_font(NHW_STATUS, fntatr, hdc, FALSE);
|
||||
nFg = (clr >= 0 && clr < CLR_MAX) ? nhcolor_to_RGB(clr) : Fg;
|
||||
nBg = Bg;
|
||||
|
||||
GetTextExtentPoint32(hdc, wbuf, vlen, &sz);
|
||||
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
|
||||
if (*f == BL_TITLE && iflags.wc2_hitpointbar) {
|
||||
HBRUSH back_brush = CreateSolidBrush(nhcolor_to_RGB(hpbar_color));
|
||||
RECT barrect;
|
||||
|
||||
/* first draw title normally */
|
||||
SelectObject(hdc, fnt);
|
||||
SetBkMode(hdc, OPAQUE);
|
||||
SetBkColor(hdc, Bg);
|
||||
SetTextColor(hdc, nhcolor_to_RGB(hpbar_color));
|
||||
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
|
||||
|
||||
/* calc bar length */
|
||||
barrect.left = rt.left;
|
||||
barrect.top = rt.top;
|
||||
barrect.bottom = sz.cy;
|
||||
if (hpbar_percent > 0)
|
||||
barrect.right = (int)((hpbar_percent * sz.cx) / 100);
|
||||
else
|
||||
barrect.right = sz.cx;
|
||||
|
||||
/* then draw hpbar on top of title */
|
||||
FillRect(hdc, &barrect, back_brush);
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
SetTextColor(hdc, nBg);
|
||||
DrawText(hdc, wbuf, vlen, &barrect, DT_LEFT);
|
||||
|
||||
DeleteObject(back_brush);
|
||||
} else {
|
||||
if (atr & HL_INVERSE) {
|
||||
COLORREF tmp = nFg;
|
||||
nFg = nBg;
|
||||
nBg = tmp;
|
||||
}
|
||||
SelectObject(hdc, fnt);
|
||||
SetBkMode(hdc, OPAQUE);
|
||||
SetBkColor(hdc, nBg);
|
||||
SetTextColor(hdc, nFg);
|
||||
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
|
||||
}
|
||||
|
||||
rt.left += sz.cx;
|
||||
cy = max(cy, sz.cy);
|
||||
@@ -336,7 +377,7 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /*STATUS_VIA_WINDOWPORT*/
|
||||
#endif /* !STATUS_HILITES */
|
||||
|
||||
void
|
||||
mswin_status_window_size(HWND hWnd, LPSIZE sz)
|
||||
|
||||
Reference in New Issue
Block a user