10 #define DLGITEM(x) { #x, CTU_DLGITEM_ ## x }
12 static struct dlg_item dlg_action
[] = {
21 static struct dlg_item dlg_health
[] = {
27 static struct dlg_item dlg_meter
[] = {
36 static struct dlg_item dlg_magic
[] = {
43 static struct dlg_item dlg_info
[] = {
51 struct ctu_dlg dlg
[] = {
52 { "Action:", &dlg_action
[0], 1, },
53 { "Health:", &dlg_health
[0], 1, },
54 { "Meter:", &dlg_meter
[0], 0, },
55 { "Magic:", &dlg_magic
[0], 0, },
56 { "Info:", &dlg_info
[0], 1, },
58 int n_dlg
= sizeof(dlg
) / sizeof(dlg
[0]);
60 static int dlg_cur
= 0;
64 static int fm2k_win_set
;
68 find_fm2k_win(HWND hwnd
, LPARAM lParam
)
73 code
= GetClassName(hwnd
, buf
, sizeof(buf
));
75 ctud("GetClassName failed with %d\n", (int)GetLastError());
79 if (!strcasecmp(buf
, "KGT2KGAME")) {
81 ctud("Found multiple FM2K windows? old: 0x%lx new: 0x%lx\n",
82 (unsigned long)fm2k_win
, (unsigned long)hwnd
);
96 if (!EnumThreadWindows(proc_thread_id
, &find_fm2k_win
, 0)) {
97 ctud("EnumThreadWindows failed with %d\n", (int)GetLastError());
111 if (get_fm2k_win()) {
112 if (!SetWindowText(fm2k_win
, "FightingIsMagic (Collective Training Unit)")) {
113 ctud("SetWindowText failed with %d\n", (int)GetLastError());
119 get_menu_coords(RECT
*rc_win
, RECT
*rc_client
)
123 if (!get_fm2k_win()) {
127 ZeroMemory(&winfo
, sizeof(winfo
));
128 winfo
.cbSize
= sizeof(winfo
);
130 if (!GetWindowInfo(fm2k_win
, &winfo
)) {
131 ctud("GetWindowInfo failed with %d\n", (int)GetLastError());
136 *rc_win
= winfo
.rcWindow
;
139 *rc_client
= winfo
.rcClient
;
146 setctrl(HWND dlgHwnd
, int id
, const char *str
)
153 for (cur
= buf
; *cur
; cur
++) {
159 hwnd
= GetDlgItem(dlgHwnd
, id
);
161 ctud("Error %d from GetDlgItem\n", (int)GetLastError());
165 if (!SetWindowText(hwnd
, buf
)) {
166 ctud("Error %d from SetWindowText\n", (int)GetLastError());
171 setlabel(HWND dlgHwnd
, int index
, const char *str
)
173 setctrl(dlgHwnd
, CTU_CTRL_LBL
+ index
, str
);
177 setval(HWND dlgHwnd
, int index
, const char *str
)
179 setctrl(dlgHwnd
, CTU_CTRL_CENT
+ index
, str
);
183 setactive(HWND dlgHwnd
, int index
)
185 if (index
!= dlg_cur
) {
186 setctrl(dlgHwnd
, CTU_CTRL_LEFT
+ dlg_cur
, "");
187 setctrl(dlgHwnd
, CTU_CTRL_RIGHT
+ dlg_cur
, "");
189 setctrl(dlgHwnd
, CTU_CTRL_LEFT
+ index
, "<");
190 setctrl(dlgHwnd
, CTU_CTRL_RIGHT
+ index
, ">");
194 menu_dlg_proc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
197 case WM_INITDIALOG
: {
201 for (i
= 0; i
< n_dlg
; i
++) {
202 struct ctu_dlg
*cur
= &dlg
[i
];
204 setlabel(hwnd
, i
, cur
->label
);
205 setval(hwnd
, i
, cur
->val_arr
[cur
->cur
].name
);
212 if (get_menu_coords(NULL
, &rc
)) {
215 center
= (rc
.left
+ rc
.right
) / 2;
218 rc
.left
= center
- width
/2;
219 /* actually the width */
221 /* actually the height */
223 rc
.top
= rc
.top
+ 100;
225 ctud("Setting window pos\n");
226 if (!SetWindowPos(hwnd
,
231 SWP_SHOWWINDOW
| SWP_NOACTIVATE
)) {
232 ctud("SetWindowPos error %d\n", (int)GetLastError());
243 handle_pauseinput(int val
)
245 int delta_h
= 0, delta_v
= 0;
247 /*ctud("pause menu got input 0x%x\n", (unsigned)val);*/
249 if ((val
& CTRL_BACK
)) {
252 if ((val
& CTRL_FWD
)) {
255 if ((val
& CTRL_DOWN
)) {
258 if ((val
& CTRL_UP
)) {
263 int newcur
= dlg_cur
;
268 if (newcur
>= n_dlg
) {
269 newcur
= newcur
% n_dlg
;
271 setactive(hwndMenu
, newcur
);
276 struct ctu_dlg
*curdlg
= &dlg
[dlg_cur
];
277 int cur
= curdlg
->cur
;
282 for (cur
= 0; curdlg
->val_arr
[cur
].name
; cur
++)
287 if (!curdlg
->val_arr
[cur
].name
) {
291 setval(hwndMenu
, dlg_cur
, curdlg
->val_arr
[cur
].name
);
299 static HANDLE hwndInfo
;
303 while ((code
= GetMessage(&msg
, NULL
, 0, 0)) != 0) {
305 ctud("GetMessage got error: %d\n", (int)GetLastError());
308 switch (msg
.message
) {
310 if (IsWindow(hwndMenu
)) {
311 DestroyWindow(hwndMenu
);
314 ctud("menu not on?\n");
318 ctud("got MENUON message\n");
319 if (IsWindow(hwndMenu
)) {
320 ctud("menu already on?\n");
322 hwndMenu
= CreateDialog(hinst
,
323 MAKEINTRESOURCE(CTU_MENUDLG
),
327 ShowWindow(hwndMenu
, SW_SHOWNOACTIVATE
);
332 handle_pauseinput((int)msg
.wParam
);
340 if (IsWindow(hwndInfo
)) {
341 DestroyWindow(hwndInfo
);
344 ctud("info dlg not on?\n");
349 if (IsWindow(hwndInfo
)) {
350 ctud("info dlg already on?\n");
352 hwndInfo
= CreateDialog(hinst
, MAKEINTRESOURCE(CTU_INFODLG
), NULL
,
354 ShowWindow(hwndInfo
, SW_SHOWNOACTIVATE
);
359 info_update(hwndInfo
);
363 if (IsWindow(hwndInfo
)) {
364 info_input(hwndInfo
, (int)msg
.lParam
);
368 case CTU_THREADUPDATE
:
369 if (!AttachThreadInput(mainthread
, proc_thread_id
, TRUE
)) {
370 ctud("AttachThreadInput error %d\n", (int)GetLastError());
378 if (IsWindow(hwndMenu
) && IsDialogMessage(hwndMenu
, &msg
)) {
379 /* noop; IsDialogMessage dispatches the message for us */
381 TranslateMessage(&msg
);
382 DispatchMessage(&msg
);