@@ -20,8 +20,20 @@ procedure delete_button;
20
20
21
21
#include "crafting.h"
22
22
23
- variable crafting_hotkey, schema_pids;
24
- variable warning_msg, show_crafting_scheduled, crafting_button_shown, crafting_button_top;
23
+ variable begin
24
+ crafting_hotkey;
25
+ schema_pids;
26
+ warning_msg;
27
+ show_crafting_scheduled;
28
+ crafting_button_shown;
29
+ crafting_button_top;
30
+
31
+ button_x;
32
+ button_y;
33
+ button_global_x;
34
+ button_global_y;
35
+ //iface_window_id;
36
+ end
25
37
26
38
#define WIN_CRAFT_BTN "helwin"
27
39
#define SFX_BUTTON_DOWN "butin4"
@@ -34,6 +46,7 @@ variable warning_msg, show_crafting_scheduled, crafting_button_shown, crafting_b
34
46
#define BUTTON_BOTTOM_OFFSET 62
35
47
#define BUTTON_RIGHT_OFFSET 399
36
48
49
+ #define can_enter_crafting (not(get_game_mode) and craft_ui_mode <= MODE_EXIT)
37
50
38
51
procedure warning_combat begin
39
52
if (warning_msg == false) then begin
@@ -58,7 +71,7 @@ procedure keypress_handler begin
58
71
if (hotkey_pressed_now(crafting_hotkey, key)) then begin
59
72
if combat_is_initialized then
60
73
call warning_combat;
61
- else if (not(get_game_mode) and craft_ui_mode <= MODE_EXIT ) then begin
74
+ else if (can_enter_crafting ) then begin
62
75
call schedule_show_crafting;
63
76
end
64
77
end else if (craft_ui_mode > MODE_EXIT) then begin
@@ -130,15 +143,16 @@ procedure do_up begin
130
143
end
131
144
end
132
145
133
- // Create the button
146
+ // DEPRECATED Create the button
147
+ /*
134
148
procedure create_button begin
135
149
// Mash's HRP has a bug when clicking on main interface - it goes on top (sfall doesn't have this).
136
150
// Workaround: delete and recreate button when going to/from these UI's with moveontop flag only when button is actually clickable.
137
- variable onTop := not(get_game_mode bwand (BARTER bwor INVENTORY bwor DIALOG));
151
+ variable onTop := true;// not(get_game_mode bwand (BARTER bwor INVENTORY bwor DIALOG));
138
152
if crafting_button_shown then begin
139
- if (crafting_button_top != onTop) then
140
- DeleteWin(WIN_CRAFT_BTN);
141
- else
153
+ // if (crafting_button_top != onTop) then
154
+ // DeleteWin(WIN_CRAFT_BTN);
155
+ // else
142
156
return;
143
157
end
144
158
variable
@@ -150,8 +164,41 @@ procedure create_button begin
150
164
AddButtonGFX("but", PCX_BUTTON_DOWN, PCX_BUTTON_UP, PCX_BUTTON_UP);
151
165
AddButtonProc("but", do_on, do_off, do_down, do_up);
152
166
ShowWin;
153
- crafting_button_top := onTop;
167
+ // crafting_button_top := onTop;
154
168
crafting_button_shown := true;
169
+ end*/
170
+
171
+ procedure draw_button(variable pressed) begin
172
+ interface_art_draw(WINTYPE_IFACEBAR, PCX_BUTTON_DOWN if pressed else PCX_BUTTON_UP, button_x, button_y);
173
+ end
174
+
175
+ // Create the button
176
+ procedure init_button begin
177
+ button_x := get_interface_width(WINTYPE_IFACEBAR) - BUTTON_RIGHT_OFFSET;
178
+ button_y := get_interface_height(WINTYPE_IFACEBAR) - BUTTON_BOTTOM_OFFSET;
179
+ button_global_x := get_interface_x(WINTYPE_IFACEBAR) + button_x;
180
+ button_global_y := get_interface_y(WINTYPE_IFACEBAR) + button_y;
181
+ // TODO: after sfall update
182
+ // iface_window_id := get_interface_id(WINTYPE_IFACEBAR);
183
+ call draw_button(false);
184
+ end
185
+
186
+ procedure mouse_over_button begin
187
+ // TODO: after sfall update
188
+ // if (get_window_under_mouse != iface_window_id) then return false;
189
+ variable x := get_mouse_x, y := get_mouse_y;
190
+ return x >= button_global_x
191
+ and x < button_global_x + BUTTON_WIDTH
192
+ and y >= button_global_y
193
+ and y < button_global_y + BUTTON_HEIGHT;
194
+ end
195
+
196
+ procedure check_mouse_off_button begin
197
+ if (mouse_over_button) then return;
198
+
199
+ call draw_button(false);
200
+ call do_off;
201
+ set_global_script_repeat(0);
155
202
end
156
203
157
204
procedure delete_button begin
@@ -161,15 +208,40 @@ procedure delete_button begin
161
208
DeleteWin(WIN_CRAFT_BTN);
162
209
end
163
210
211
+ procedure mouseclick_handler begin
212
+ variable
213
+ pressed := get_sfall_arg,
214
+ btn := get_sfall_arg;
215
+ //window := get_window_under_mouse;
216
+
217
+ display_msg(string_format("mouseclick (%d, %d) mode %x", get_mouse_x, get_mouse_y, get_game_mode));
218
+ if (btn == 0 and mouse_over_button and can_enter_crafting) then begin
219
+ if (pressed) then begin
220
+ call draw_button(true);
221
+ call do_down;
222
+ set_global_script_repeat(1);
223
+ end
224
+ else begin
225
+ call draw_button(false);
226
+ call do_up;
227
+ end
228
+ end
229
+ end
230
+
231
+ // OLD button code
232
+ /*
233
+ #define OVERLAPPING_MODES (LOADGAME bwor LOCALMAP bwor WORLDMAP bwor OPTIONS bwor CHARSCREEN bwor PIPBOY bwor AUTOMAP bwor BARTER bwor DIALOG bwor SPECIAL bwor INVENTORY bwor INTFACEUSE bwor INTFACELOOT)
234
+
164
235
procedure gamemodechange_handler begin
165
236
variable gameExit := get_sfall_arg;
166
- if (not (get_game_mode bwand (LOADGAME bwor LOCALMAP bwor WORLDMAP)) and not gameExit) then begin
237
+ //display_msg(sprintf("gamemode= %x", get_game_mode));
238
+ if (not (get_game_mode bwand OVERLAPPING_MODES) and not gameExit) then begin
167
239
call create_button;
168
240
end
169
241
else begin
170
242
call delete_button;
171
243
end
172
- end
244
+ end*/
173
245
174
246
procedure useobj_handler begin
175
247
variable
@@ -203,19 +275,22 @@ procedure start begin
203
275
crafting_hotkey := parse_hotkey(craft_raw_cfg.Main.hotkey);
204
276
schema_pids := array_fixed(string_split_ints(craft_raw_cfg.Main.schematic_pids, ","));
205
277
register_hook_proc(HOOK_KEYPRESS, keypress_handler);
206
- register_hook_proc(HOOK_GAMEMODECHANGE, gamemodechange_handler);
278
+ register_hook_proc(HOOK_MOUSECLICK, mouseclick_handler);
279
+ //register_hook_proc(HOOK_GAMEMODECHANGE, gamemodechange_handler);
207
280
register_hook_proc(HOOK_DESCRIPTIONOBJ, descriptionobj_handler);
208
281
register_hook_proc(HOOK_USEOBJ, useobj_handler);
209
282
210
- call create_button ;
283
+ call init_button ;
211
284
212
285
set_global_script_type(1);
213
286
end else begin
214
287
//debug_msg("gl_fixit repeats");
215
288
if (show_crafting_scheduled) then begin
216
289
show_crafting_scheduled := false;
217
290
call show_crafting_window;
291
+ set_global_script_repeat(0);
218
292
end
219
- set_global_script_repeat(0);
293
+ if (button_pressed) then
294
+ call check_mouse_off_button;
220
295
end
221
296
end
0 commit comments