-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.cpp
More file actions
257 lines (243 loc) · 9.33 KB
/
Copy pathhandlers.cpp
File metadata and controls
257 lines (243 loc) · 9.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// Handlers module — hit detection and button click handlers
#include "handlers.h"
// =====================================================================
// Hit detection
// =====================================================================
bool in_rect(int mx, int my, int x1, int y1, int x2, int y2) {
return mx >= x1 && mx <= x2 && my >= y1 && my <= y2;
}
bool is_actionable_region(int mx, int my) {
// Control panel buttons
if (in_rect(mx,my, 595,426, 610,442)) return true; // Fire+
if (in_rect(mx,my, 455,426, 470,442)) return true; // Fire-
if (in_rect(mx,my, 595,362, 610,379)) return true; // Air+
if (in_rect(mx,my, 455,362, 470,379)) return true; // Air-
if (in_rect(mx,my, 448,256, 455,275)) return true; // Valve water in
if (in_rect(mx,my, 558,256, 568,276)) return true; // Valve water out
if (in_rect(mx,my, 513,310, 525,319)) return true; // Stove open
if (in_rect(mx,my, 536,310, 547,319)) return true; // Stove close
if (in_rect(mx,my, 377,216, 424,232)) return true; // ESC
if (in_rect(mx,my, 518,216, 566,232)) return true; // HELP
if (in_rect(mx,my, 432,216, 508,232)) return true; // CTRL
if (in_rect(mx,my, 605,195, 618,207)) return true; // ?
if (in_rect(mx,my, 575,216, 597,232)) return true; // Language toggle
// Diagram elements — direct-click on valves, stove door, open/close buttons
if (in_rect(mx,my, 40,178, 70,195)) return true; // Valve 1 (on pipe-in)
if (in_rect(mx,my, 225,255, 255,272)) return true; // Valve 2 (on pipe-out)
if (in_rect(mx,my, 120,365, 170,405)) return true; // Stove door
if (in_rect(mx,my, 60,360, 92,378)) return true; // Open stove button (on diagram)
if (in_rect(mx,my, 210,360, 250,378)) return true; // Close stove button (on diagram)
return false;
}
// =====================================================================
// Button click handlers
// =====================================================================
void handle_fire_plus() {
if (stove_open == 1) {
Sound(1000);
int slider_x = 475 + 3 + ii*5 - jj*5;
if (slider_x >= 475+3 && slider_x < 475+109) {
setfillstyle(1,1);
bar(slider_x, 439+3-11, slider_x+3, 439+12-11);
}
if (475+3+ii*5-jj*5 < 475+109) {
ii++;
percent_of_fire_V = (int)(((float)ii*5-(float)jj*5)/106.0f * 22);
}
} else {
Sound(800);
SDL_Delay(50);
}
Nosound();
}
void handle_fire_minus() {
if (stove_open == 1) {
Sound(900);
setfillstyle(1,15);
bar(475+109, 439+3-11, 475+112, 439+12-11);
int slider_x = 475 + 3 + ii*5 - jj*5;
if (slider_x > 475+3 && slider_x < 475+109) {
bar(slider_x, 439+3-11, slider_x+3, 439+12-11);
}
if (475+3+ii*5-jj*5 > 475+3) {
jj++;
percent_of_fire_V = (int)(((float)ii*5-(float)jj*5)/106.0f * 22);
}
slider_x = 475 + 3 + ii*5 - jj*5;
setfillstyle(1,15);
bar(slider_x, 439+3-11, slider_x+3, 439+12-11);
} else {
Sound(800);
SDL_Delay(50);
}
Nosound();
}
void handle_air_plus() {
Sound(1000);
draw_air_valve_open(338,81,0);
valve_air_open = 1;
int slider_x = 370+105+3+kk*5-ff*5;
if (slider_x >= 370+105+3 && slider_x < 370+105+109) {
setfillstyle(1,1);
bar(slider_x, 190+185+3-12, slider_x+3, 190+185+12-12);
}
if (370+105+3+kk*5-ff*5 < 370+105+109) {
kk++;
percent_of_air_V = (int)(((float)kk*5-(float)ff*5)/106.0f * 22);
}
if (Pressure > 0) draw_air_valve_open(338,81,percent_of_air_V);
if (percent_of_air_V == 0) draw_air_valve_close(338,81,0);
Nosound();
}
void handle_air_minus() {
Sound(900);
setfillstyle(1,15);
bar(370+105+109, 190+184+3-11, 370+105+112, 190+184+12-11);
int slider_x = 370+105+3+kk*5-ff*5;
if (slider_x > 370+105+3 && slider_x < 370+105+109) {
bar(slider_x, 190+184+3-11, slider_x+3, 190+184+12-11);
}
if (370+105+3+kk*5-ff*5 > 370+105+3) {
ff++;
percent_of_air_V = (int)(((float)kk*5-(float)ff*5)/106.0f * 22);
}
slider_x = 370+105+3+kk*5-ff*5;
setfillstyle(1,15);
bar(slider_x, 190+184+3-11, slider_x+3, 190+184+12-11);
if (percent_of_air_V == 0) {
valve_air_open = 0;
draw_air_valve_close(338,81,0);
}
if (Pressure >= 0) draw_air_valve_close(338,81,percent_of_air_V);
Nosound();
}
void handle_valve_water_in_press() {
setfillstyle(1,0); fillellipse(370+60+21,190+80,3,3);
setfillstyle(1,15); fillellipse(370+81+21,190+80,3,3);
valve_1_open = 1;
draw_valve_open(110,175);
// Descending frequency sweep matching original Project_Mouse.cpp:358-360
Sound(1450);Sound(1400);Sound(1350);Sound(1300);
Sound(1250);Sound(1200);Sound(1150);Sound(1100);
Sound(1050);Sound(1000);Sound(950); Sound(900);
// Fill inlet pipe indication window with water color (ellipses + bar between)
setfillstyle(1,9);
fillellipse(80,186,4,4); fillellipse(100,186,4,4);
bar(80,183,100,189);
if (Water_in_boiler <= 179) Water_in_boiler++;
else Water_in_boiler = 180;
water_level_up(110,175,Water_in_boiler);
putout_level(110-12,195,Water_in_boiler);
}
void handle_valve_water_in_release() {
Nosound();
setfillstyle(1,15); fillellipse(370+60+21,190+80,3,3);
setfillstyle(1,0); fillellipse(370+81+21,190+80,3,3);
draw_valve_close(110,175);
if (Water_in_boiler < 130) {
// Clear inlet pipe indication window back to empty color
setfillstyle(1,5);
fillellipse(80,186,4,4); fillellipse(100,186,4,4);
bar(80,183,100,189);
}
}
void handle_valve_water_out_press() {
setfillstyle(1,15); fillellipse(370+191+21,190+80,3,3);
setfillstyle(1,0); fillellipse(370+191,190+80,3,3);
draw_valve_open(110+185,175+77);
// Ascending frequency sweep matching original Project_Mouse.cpp:414-415
Sound(900); Sound(950); Sound(1000);
Sound(1050); Sound(1100); Sound(1150);
if (Water_in_boiler >= 48) {
// Fill both outlet pipe indication windows with water color (ellipses + bar)
setfillstyle(1,9);
fillellipse(195,263,4,4); fillellipse(215,263,4,4);
bar(195,260,215,266);
fillellipse(260,263,3,3); fillellipse(280,263,3,3);
bar(260,260,280,266);
if (Water_in_boiler >= 1) Water_in_boiler--;
else Water_in_boiler = 0;
if (water_alarm == 1 && Water_in_boiler < 125) {
draw_alarm_of_water(141,118,10);
water_alarm = 0;
}
water_level_down(110,175,Water_in_boiler);
putout_level(110-12,195,Water_in_boiler);
if (Water_in_boiler < 50) {
// Clear both outlet pipe indication windows back to empty color (ellipses + bar)
setfillstyle(1,5);
fillellipse(195,263,4,4); fillellipse(215,263,4,4);
bar(195,260,215,266);
fillellipse(260,263,3,3); fillellipse(280,263,3,3);
bar(260,260,280,266);
}
}
}
void handle_valve_water_out_release() {
Nosound();
setfillstyle(1,15); fillellipse(370+191,190+80,3,3);
setfillstyle(1,0); fillellipse(370+191+21,190+80,3,3);
draw_valve_close(110+185,175+77);
// Clear both outlet pipe indication windows back to empty color (ellipses + bar)
setfillstyle(1,5);
fillellipse(195,263,4,4); fillellipse(215,263,4,4);
bar(195,260,215,266);
fillellipse(260,263,3,3); fillellipse(280,263,3,3);
bar(260,260,280,266);
if (Water_in_boiler < 130) {
// Clear inlet pipe indication window back to empty color
setfillstyle(1,5);
fillellipse(80,186,4,4); fillellipse(100,186,4,4);
bar(80,183,100,189);
}
}
void handle_stove_open_btn() {
setfillstyle(1,15); fillellipse(370+81+21+70,190+125,3,3);
setfillstyle(1,0); fillellipse(370+81+70,190+125,3,3);
if (stove_open == 0) {
stove_open = 1;
draw_open_stove_button_pressed(60,360);
draw_close_stove_button(210,360);
draw_stove_open(95,320);
settextstyle(0,0,0);
} else {
Sound(800);
SDL_Delay(50);
Nosound();
}
}
void handle_lang_toggle() {
// Flip language
g_language = (g_language == LANG_CN) ? LANG_EN : LANG_CN;
// Redraw entire UI in new language
mian_interface_initialize();
// Restore dynamic visual state that mian_interface_initialize draws as default
if (valve_1_open == 1) draw_valve_open(110,175);
if (stove_open == 1) {
draw_open_stove_button_pressed(60,360);
draw_close_stove_button(210,360);
draw_stove_open(95,320);
}
// Water level and gauge displays are restored by the main loop's per-frame updates
putout_level(110-12,195,Water_in_boiler);
water_level_up(110,175,Water_in_boiler);
}
void handle_stove_close_btn() {
if (stove_open == 1 && percent_of_air_V == 0 && percent_of_fire_V == 0) {
stove_open = 0;
draw_close_stove_button_pressed(210,360);
draw_open_stove_button(60,360);
draw_stove_close(95,320);
setfillstyle(1,3);
bar(85+3,460+3-12,85+112,460+12-12);
ii = 1; jj = 1;
settextstyle(0,0,0);
setcolor(15);
setfillstyle(1,0); fillellipse(370+81+21+70,190+125,3,3);
setfillstyle(1,15); fillellipse(370+81+70,190+125,3,3);
} else {
Sound(800);
SDL_Delay(50);
Nosound();
}
}