1 /* Copyright (C) 2001 by Alex Kompel <shurikk@pacbell.net> */
2 /* NetHack may be freely redistributed. See license for details. */
10 #define MAXWINDOWTEXT 255
12 #define NHSTAT_LINES_2 2
13 #define NHSTAT_LINES_4 4
14 typedef struct mswin_nethack_status_window {
16 char window_text[MAXWINDOWTEXT];
17 } NHStatusWindow, *PNHStatusWindow;
19 static TCHAR szStatusWindowClass[] = TEXT("MSNHStatusWndClass");
20 LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
21 static void register_status_window_class(void);
22 static void FormatStatusString(char* text, int format);
24 HWND mswin_init_status_window () {
25 static int run_once = 0;
30 register_status_window_class( );
37 WS_CHILD | WS_DISABLED | WS_CLIPSIBLINGS,
40 0, /* x-size - we will set it later */
41 0, /* y-size - we will set it later */
46 if( !ret ) panic("Cannot create status window");
48 EnableWindow(ret, FALSE);
50 data = (PNHStatusWindow)malloc(sizeof(NHStatusWindow));
51 if( !data ) panic("out of memory");
53 ZeroMemory(data, sizeof(NHStatusWindow));
54 data->nhstat_format = NHSTAT_LINES_4;
55 SetWindowLong(ret, GWL_USERDATA, (LONG)data);
59 void register_status_window_class()
63 ZeroMemory( &wcex, sizeof(wcex));
64 wcex.style = CS_NOCLOSE;
65 wcex.lpfnWndProc = (WNDPROC)StatusWndProc;
68 wcex.hInstance = GetNHApp()->hApp;
70 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
71 wcex.hbrBackground = mswin_get_brush(NHW_STATUS, MSWIN_COLOR_BG);
72 wcex.lpszMenuName = NULL;
73 wcex.lpszClassName = szStatusWindowClass;
79 LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
86 data = (PNHStatusWindow)GetWindowLong(hWnd, GWL_USERDATA);
89 case WM_MSNH_COMMAND: {
93 case MSNH_MSG_CLEAR_WINDOW:
94 ZeroMemory(data->window_text, sizeof(data->window_text));
95 FormatStatusString(data->window_text, data->nhstat_format);
98 case MSNH_MSG_CURSOR: {
99 PMSNHMsgCursor msg_data = (PMSNHMsgCursor)lParam;
100 if( msg_data->y==0 ) {
101 InvalidateRect(hWnd, NULL, TRUE);
109 TCHAR wbuf[MAXWINDOWTEXT];
110 COLORREF OldBg, OldFg;
112 hdc = BeginPaint(hWnd, &ps);
113 GetClientRect(hWnd, &rt);
115 oldFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
116 OldBg = SetBkColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_BG));
117 OldFg = SetTextColor(hdc, mswin_get_color(NHW_STATUS, MSWIN_COLOR_FG));
120 NH_A2W(data->window_text, wbuf, MAXWINDOWTEXT),
121 strlen(data->window_text),
123 DT_LEFT | DT_NOPREFIX);
125 SetTextColor (hdc, OldFg);
126 SetBkColor (hdc, OldBg);
127 SelectObject(hdc, oldFont);
133 SetWindowLong(hWnd, GWL_USERDATA, (LONG)0);
137 SetFocus(GetNHApp()->hMainWnd);
141 return DefWindowProc(hWnd, message, wParam, lParam);
146 void mswin_status_window_size (HWND hWnd, LPSIZE sz)
151 PNHStatusWindow data;
153 GetWindowRect(hWnd, &rt);
154 sz->cx = rt.right - rt.left;
155 sz->cy = rt.bottom - rt.top;
157 data = (PNHStatusWindow)GetWindowLong(hWnd, GWL_USERDATA);
160 saveFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
161 GetTextMetrics(hdc, &tm);
163 /* see if the status window can fit 80 characters per line */
164 if( (80*tm.tmMaxCharWidth)>=sz->cx ) data->nhstat_format = NHSTAT_LINES_4;
165 else data->nhstat_format = NHSTAT_LINES_2;
167 /* set height of the status box */
168 sz->cy = tm.tmHeight * data->nhstat_format;
170 SelectObject(hdc, saveFont);
171 ReleaseDC(hWnd, hdc);
174 extern const char *hu_stat[]; /* defined in eat.c */
175 extern const char *enc_stat[]; /* define in botl.c */
176 void FormatStatusString(char* text, int format)
180 int cap = near_capacity();
182 Strcpy(text, plname);
183 if('a' <= text[0] && text[0] <= 'z') text[0] += 'A'-'a';
185 Sprintf(nb = eos(text)," the ");
191 Strcpy(mbot, mons[u.umonnum].mname);
192 while(mbot[k] != 0) {
193 if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) &&
194 'a' <= mbot[k] && mbot[k] <= 'z')
195 mbot[k] += 'A' - 'a';
198 Sprintf(nb = eos(nb), mbot);
200 Sprintf(nb = eos(nb), rank_of(u.ulevel, Role_switch, flags.female));
202 if( format==NHSTAT_LINES_4 ) Sprintf(nb = eos(nb),"\r\n");
204 if (ACURR(A_STR) > 18) {
205 if (ACURR(A_STR) > STR18(100))
206 Sprintf(nb = eos(nb),"St:%2d ",ACURR(A_STR)-100);
207 else if (ACURR(A_STR) < STR18(100))
208 Sprintf(nb = eos(nb), "St:18/%02d ",ACURR(A_STR)-18);
210 Sprintf(nb = eos(nb),"St:18/** ");
212 Sprintf(nb = eos(nb), "St:%-1d ",ACURR(A_STR));
213 Sprintf(nb = eos(nb),
214 "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
215 ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), ACURR(A_CHA));
216 Sprintf(nb = eos(nb), (u.ualign.type == A_CHAOTIC) ? " Chaotic" :
217 (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful");
220 Sprintf(nb = eos(nb), " S:%ld", botl_score());
222 if( format==NHSTAT_LINES_4 ||
223 format==NHSTAT_LINES_2 ) strcat(text, "\r\n");
226 hp = Upolyd ? u.mh : u.uhp;
227 hpmax = Upolyd ? u.mhmax : u.uhpmax;
230 (void) describe_level(nb=eos(nb));
231 Sprintf(nb = eos(nb),
232 "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", oc_syms[COIN_CLASS],
238 hp, hpmax, u.uen, u.uenmax, u.uac);
241 Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
243 else if(flags.showexp)
244 Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel,u.uexp);
247 Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
248 if( format==NHSTAT_LINES_4 ) strcat(text, "\r\n");
249 else strcat(text, " ");
253 Sprintf(nb = eos(nb), "T:%ld ", moves);
255 if(strcmp(hu_stat[u.uhs], " ")) {
256 Strcat(text, hu_stat[u.uhs]);
257 Sprintf(nb = eos(nb), " ");
259 if(Confusion) Sprintf(nb = eos(nb), "Conf");
261 if (u.usick_type & SICK_VOMITABLE)
262 Sprintf(nb = eos(nb), " FoodPois");
263 if (u.usick_type & SICK_NONVOMITABLE)
264 Sprintf(nb = eos(nb), " Ill");
266 if(Blind) Sprintf(nb = eos(nb), " Blind");
267 if(Stunned) Sprintf(nb = eos(nb), " Stun");
268 if(Hallucination) Sprintf(nb = eos(nb), " Hallu");
269 if(Slimed) Sprintf(nb = eos(nb), " Slime");
270 if(cap > UNENCUMBERED)
271 Sprintf(nb = eos(nb), " %s", enc_stat[cap]);