1#include "Library/Controller/InputFunction.h"
2
3#include <controller/seadControllerMgr.h>
4
5#include "Library/Controller/PadReplayFunction.h"
6#include "Library/Controller/ReplayController.h"
7
8namespace al {
9
10inline sead::ControllerBase* getController(s32 port) {
11 if (port == -1)
12 port = getMainControllerPort();
13
14 if (isValidReplayController(port))
15 return getReplayController(port);
16
17 return sead::ControllerMgr::instance()->getController(port);
18}
19
20bool isPadTrigger(s32 port, s32 button) {
21 return getController(port)->isTrig(mask: button);
22}
23
24bool isPadTriggerA(s32 port) {
25 return isPadTrigger(port, button: 1);
26}
27
28bool isPadTriggerB(s32 port) {
29 return isPadTrigger(port, button: 1 << 1);
30}
31
32bool isPadTriggerX(s32 port) {
33 return isPadTrigger(port, button: 1 << 3);
34}
35
36bool isPadTriggerY(s32 port) {
37 return isPadTrigger(port, button: 1 << 4);
38}
39
40bool isPadTriggerZL(s32 port) {
41 return isPadTrigger(port, button: 1 << 2);
42}
43
44bool isPadTriggerZR(s32 port) {
45 return isPadTrigger(port, button: 1 << 5);
46}
47
48bool isPadTriggerL(s32 port) {
49 return isPadTrigger(port, button: 1 << 13);
50}
51
52bool isPadTriggerR(s32 port) {
53 return isPadTrigger(port, button: 1 << 14);
54}
55
56bool isPadTrigger1(s32 port) {
57 return isPadTrigger(port, button: 1 << 7);
58}
59
60bool isPadTrigger2(s32 port) {
61 return isPadTrigger(port, button: 1 << 6);
62}
63
64bool isPadTriggerUp(s32 port) {
65 return isPadTrigger(port, button: 1 << 16);
66}
67
68bool isPadTriggerDown(s32 port) {
69 return isPadTrigger(port, button: 1 << 17);
70}
71
72bool isPadTriggerLeft(s32 port) {
73 return isPadTrigger(port, button: 1 << 18);
74}
75
76bool isPadTriggerRight(s32 port) {
77 return isPadTrigger(port, button: 1 << 19);
78}
79
80bool isPadTriggerLeftUp(s32 port) {
81 return isPadHoldLeftUp(port) && (getController(port)->isTrig(mask: 0x50000));
82}
83
84bool isPadTriggerLeftDown(s32 port) {
85 return isPadHoldLeftDown(port) && (getController(port)->isTrig(mask: 0x60000));
86}
87
88bool isPadTriggerRightUp(s32 port) {
89 return isPadHoldRightUp(port) && (getController(port)->isTrig(mask: 0x90000));
90}
91
92bool isPadTriggerRightDown(s32 port) {
93 return isPadHoldRightDown(port) && (getController(port)->isTrig(mask: 0xA0000));
94}
95
96bool isPadTriggerHome(s32 port) {
97 return isPadTrigger(port, button: 1 << 8);
98}
99
100bool isPadTriggerStart(s32 port) {
101 return isPadTrigger(port, button: 1 << 11);
102}
103
104bool isPadTriggerSelect(s32 port) {
105 return isPadTrigger(port, button: 1 << 12);
106}
107
108bool isPadTriggerPlus(s32 port) {
109 return isPadTrigger(port, button: 1 << 10);
110}
111
112bool isPadTriggerMinus(s32 port) {
113 return isPadTrigger(port, button: 1 << 9);
114}
115
116bool isPadTriggerTouch() {
117 return isPadTrigger(port: getTouchPanelPort(), button: 1 << 15);
118}
119
120bool isPadTriggerUpLeftStick(s32 port) {
121 return isPadTrigger(port, button: 1 << 20);
122}
123
124bool isPadTriggerDownLeftStick(s32 port) {
125 return isPadTrigger(port, button: 1 << 21);
126}
127
128bool isPadTriggerLeftLeftStick(s32 port) {
129 return isPadTrigger(port, button: 1 << 22);
130}
131
132bool isPadTriggerRightLeftStick(s32 port) {
133 return isPadTrigger(port, button: 1 << 23);
134}
135
136bool isPadTriggerUpRightStick(s32 port) {
137 return isPadTrigger(port, button: 1 << 24);
138}
139
140bool isPadTriggerDownRightStick(s32 port) {
141 return isPadTrigger(port, button: 1 << 25);
142}
143
144bool isPadTriggerLeftRightStick(s32 port) {
145 return isPadTrigger(port, button: 1 << 26);
146}
147
148bool isPadTriggerRightRightStick(s32 port) {
149 return isPadTrigger(port, button: 1 << 27);
150}
151
152bool isPadTriggerAnyABXY(s32 port) {
153 return isPadTriggerA(port) || isPadTriggerB(port) || isPadTriggerX(port) || isPadTriggerY(port);
154}
155
156bool isPadTriggerAny(s32 port) {
157 return isPadTrigger(port, button: 0xFFF7FFF);
158}
159
160bool isPadTriggerLeftStick(s32 port) {
161 return isPadTrigger(port, button: 0xF00000);
162}
163
164bool isPadTriggerRightStick(s32 port) {
165 return isPadTrigger(port, button: 0xF000000);
166}
167
168bool isPadTriggerPressLeftStick(s32 port) {
169 return isPadTrigger1(port);
170}
171
172bool isPadTriggerPressRightStick(s32 port) {
173 return isPadTrigger2(port);
174}
175
176inline bool isPadRepeat(s32 port, s32 button) {
177 return getController(port)->isTrigWithRepeat(mask: button);
178}
179
180bool isPadRepeatA(s32 port) {
181 return isPadRepeat(port, button: 1);
182}
183
184bool isPadRepeatB(s32 port) {
185 return isPadRepeat(port, button: 1 << 1);
186}
187
188bool isPadRepeatX(s32 port) {
189 return isPadRepeat(port, button: 1 << 3);
190}
191
192bool isPadRepeatY(s32 port) {
193 return isPadRepeat(port, button: 1 << 4);
194}
195
196bool isPadRepeatZL(s32 port) {
197 return isPadRepeat(port, button: 1 << 2);
198}
199
200bool isPadRepeatZR(s32 port) {
201 return isPadRepeat(port, button: 1 << 5);
202}
203
204bool isPadRepeatL(s32 port) {
205 return isPadRepeat(port, button: 1 << 13);
206}
207
208bool isPadRepeatR(s32 port) {
209 return isPadRepeat(port, button: 1 << 14);
210}
211
212bool isPadRepeat1(s32 port) {
213 return isPadRepeat(port, button: 1 << 7);
214}
215
216bool isPadRepeat2(s32 port) {
217 return isPadRepeat(port, button: 1 << 6);
218}
219
220bool isPadRepeatUp(s32 port) {
221 return isPadRepeat(port, button: 1 << 16);
222}
223
224bool isPadRepeatDown(s32 port) {
225 return isPadRepeat(port, button: 1 << 17);
226}
227
228bool isPadRepeatLeft(s32 port) {
229 return isPadRepeat(port, button: 1 << 18);
230}
231
232bool isPadRepeatRight(s32 port) {
233 return isPadRepeat(port, button: 1 << 19);
234}
235
236bool isPadRepeatHome(s32 port) {
237 return isPadRepeat(port, button: 1 << 8);
238}
239
240bool isPadRepeatStart(s32 port) {
241 return isPadRepeat(port, button: 1 << 11);
242}
243
244bool isPadRepeatSelect(s32 port) {
245 return isPadRepeat(port, button: 1 << 12);
246}
247
248bool isPadRepeatPlus(s32 port) {
249 return isPadRepeat(port, button: 1 << 10);
250}
251
252bool isPadRepeatMinus(s32 port) {
253 return isPadRepeat(port, button: 1 << 9);
254}
255
256bool isPadRepeatTouch() {
257 return isPadRepeat(port: getTouchPanelPort(), button: 1 << 15);
258}
259
260bool isPadRepeatUpLeftStick(s32 port) {
261 return isPadRepeat(port, button: 1 << 20);
262}
263
264bool isPadRepeatDownLeftStick(s32 port) {
265 return isPadRepeat(port, button: 1 << 21);
266}
267
268bool isPadRepeatLeftLeftStick(s32 port) {
269 return isPadRepeat(port, button: 1 << 22);
270}
271
272bool isPadRepeatRightLeftStick(s32 port) {
273 return isPadRepeat(port, button: 1 << 23);
274}
275
276bool isPadRepeatUpRightStick(s32 port) {
277 return isPadRepeat(port, button: 1 << 24);
278}
279
280bool isPadRepeatDownRightStick(s32 port) {
281 return isPadRepeat(port, button: 1 << 25);
282}
283
284bool isPadRepeatLeftRightStick(s32 port) {
285 return isPadRepeat(port, button: 1 << 26);
286}
287
288bool isPadRepeatRightRightStick(s32 port) {
289 return isPadRepeat(port, button: 1 << 27);
290}
291
292bool isPadHoldPressLeftStick(s32 port) {
293 return isPadHold1(port);
294}
295
296bool isPadHoldPressRightStick(s32 port) {
297 return isPadHold2(port);
298}
299
300bool isPadHold(s32 port, s32 button) {
301 return getController(port)->isHold(mask: button);
302}
303
304bool isPadHoldA(s32 port) {
305 return isPadHold(port, button: 1);
306}
307
308bool isPadHoldB(s32 port) {
309 return isPadHold(port, button: 1 << 1);
310}
311
312bool isPadHoldX(s32 port) {
313 return isPadHold(port, button: 1 << 3);
314}
315
316bool isPadHoldY(s32 port) {
317 return isPadHold(port, button: 1 << 4);
318}
319
320bool isPadHoldZL(s32 port) {
321 return isPadHold(port, button: 1 << 2);
322}
323
324bool isPadHoldZR(s32 port) {
325 return isPadHold(port, button: 1 << 5);
326}
327
328bool isPadHoldL(s32 port) {
329 return isPadHold(port, button: 1 << 13);
330}
331
332bool isPadHoldR(s32 port) {
333 return isPadHold(port, button: 1 << 14);
334}
335
336bool isPadHold1(s32 port) {
337 return isPadHold(port, button: 1 << 7);
338}
339
340bool isPadHold2(s32 port) {
341 return isPadHold(port, button: 1 << 6);
342}
343
344bool isPadHoldUp(s32 port) {
345 return isPadHold(port, button: 1 << 16);
346}
347
348bool isPadHoldDown(s32 port) {
349 return isPadHold(port, button: 1 << 17);
350}
351
352bool isPadHoldLeft(s32 port) {
353 return isPadHold(port, button: 1 << 18);
354}
355
356bool isPadHoldRight(s32 port) {
357 return isPadHold(port, button: 1 << 19);
358}
359
360bool isPadHoldLeftUp(s32 port) {
361 return getController(port)->isHoldAll(mask: 0x50000);
362}
363
364bool isPadHoldLeftDown(s32 port) {
365 return getController(port)->isHoldAll(mask: 0x60000);
366}
367
368bool isPadHoldRightUp(s32 port) {
369 return getController(port)->isHoldAll(mask: 0x90000);
370}
371
372bool isPadHoldRightDown(s32 port) {
373 return getController(port)->isHoldAll(mask: 0xA0000);
374}
375
376bool isPadHoldHome(s32 port) {
377 return isPadHold(port, button: 1 << 8);
378}
379
380bool isPadHoldStart(s32 port) {
381 return isPadHold(port, button: 1 << 11);
382}
383
384bool isPadHoldSelect(s32 port) {
385 return isPadHold(port, button: 1 << 12);
386}
387
388bool isPadHoldPlus(s32 port) {
389 return isPadHold(port, button: 1 << 10);
390}
391
392bool isPadHoldMinus(s32 port) {
393 return isPadHold(port, button: 1 << 9);
394}
395
396bool isPadHoldAny(s32 port) {
397 return isPadHold(port, button: 0xFFF7FFF);
398}
399
400bool isPadHoldAnyWithoutStick(s32 port) {
401 return isPadHold(port, button: 0xF7FFF);
402}
403
404bool isPadHoldTouch() {
405 return isPadHold(port: getTouchPanelPort(), button: 1 << 15);
406}
407
408bool isPadHoldUpLeftStick(s32 port) {
409 return isPadHold(port, button: 1 << 20);
410}
411
412bool isPadHoldDownLeftStick(s32 port) {
413 return isPadHold(port, button: 1 << 21);
414}
415
416bool isPadHoldLeftLeftStick(s32 port) {
417 return isPadHold(port, button: 1 << 22);
418}
419
420bool isPadHoldRightLeftStick(s32 port) {
421 return isPadHold(port, button: 1 << 23);
422}
423
424bool isPadHoldUpRightStick(s32 port) {
425 return isPadHold(port, button: 1 << 24);
426}
427
428bool isPadHoldDownRightStick(s32 port) {
429 return isPadHold(port, button: 1 << 25);
430}
431
432bool isPadHoldLeftRightStick(s32 port) {
433 return isPadHold(port, button: 1 << 26);
434}
435
436bool isPadHoldRightRightStick(s32 port) {
437 return isPadHold(port, button: 1 << 27);
438}
439
440bool isPadHoldLeftStick(s32 port) {
441 return isPadHold(port, button: 0xF00000);
442}
443
444bool isPadHoldRightStick(s32 port) {
445 return isPadHold(port, button: 0xF000000);
446}
447
448inline bool isPadRelease(s32 port, s32 button) {
449 return getController(port)->isRelease(mask: button);
450}
451
452bool isPadReleaseA(s32 port) {
453 return isPadRelease(port, button: 1);
454}
455
456bool isPadReleaseB(s32 port) {
457 return isPadRelease(port, button: 1 << 1);
458}
459
460bool isPadReleaseX(s32 port) {
461 return isPadRelease(port, button: 1 << 3);
462}
463
464bool isPadReleaseY(s32 port) {
465 return isPadRelease(port, button: 1 << 4);
466}
467
468bool isPadReleaseZL(s32 port) {
469 return isPadRelease(port, button: 1 << 2);
470}
471
472bool isPadReleaseZR(s32 port) {
473 return isPadRelease(port, button: 1 << 5);
474}
475
476bool isPadReleaseL(s32 port) {
477 return isPadRelease(port, button: 1 << 13);
478}
479
480bool isPadReleaseR(s32 port) {
481 return isPadRelease(port, button: 1 << 14);
482}
483
484bool isPadRelease1(s32 port) {
485 return isPadRelease(port, button: 1 << 7);
486}
487
488bool isPadRelease2(s32 port) {
489 return isPadRelease(port, button: 1 << 6);
490}
491
492bool isPadReleaseUp(s32 port) {
493 return isPadRelease(port, button: 1 << 16);
494}
495
496bool isPadReleaseDown(s32 port) {
497 return isPadRelease(port, button: 1 << 17);
498}
499
500bool isPadReleaseLeft(s32 port) {
501 return isPadRelease(port, button: 1 << 18);
502}
503
504bool isPadReleaseRight(s32 port) {
505 return isPadRelease(port, button: 1 << 19);
506}
507
508bool isPadReleaseHome(s32 port) {
509 return isPadRelease(port, button: 1 << 8);
510}
511
512bool isPadReleaseStart(s32 port) {
513 return isPadRelease(port, button: 1 << 11);
514}
515
516bool isPadReleaseSelect(s32 port) {
517 return isPadRelease(port, button: 1 << 12);
518}
519
520bool isPadReleasePlus(s32 port) {
521 return isPadRelease(port, button: 1 << 10);
522}
523
524bool isPadReleaseMinus(s32 port) {
525 return isPadRelease(port, button: 1 << 9);
526}
527
528bool isPadReleaseTouch() {
529 return isPadRelease(port: getTouchPanelPort(), button: 1 << 15);
530}
531
532bool isPadReleaseUpLeftStick(s32 port) {
533 return isPadRelease(port, button: 1 << 20);
534}
535
536bool isPadReleaseDownLeftStick(s32 port) {
537 return isPadRelease(port, button: 1 << 21);
538}
539
540bool isPadReleaseLeftLeftStick(s32 port) {
541 return isPadRelease(port, button: 1 << 22);
542}
543
544bool isPadReleaseRightLeftStick(s32 port) {
545 return isPadRelease(port, button: 1 << 23);
546}
547
548bool isPadReleaseUpRightStick(s32 port) {
549 return isPadRelease(port, button: 1 << 24);
550}
551
552bool isPadReleaseDownRightStick(s32 port) {
553 return isPadRelease(port, button: 1 << 25);
554}
555
556bool isPadReleaseLeftRightStick(s32 port) {
557 return isPadRelease(port, button: 1 << 26);
558}
559
560bool isPadReleaseRightRightStick(s32 port) {
561 return isPadRelease(port, button: 1 << 27);
562}
563
564const sead::Vector2f& getLeftStick(s32 port) {
565 return getController(port)->getLeftStick();
566}
567
568const sead::Vector2f& getRightStick(s32 port) {
569 return getController(port)->getRightStick();
570}
571
572void getPadCrossDir(sead::Vector2f* vec, s32 port) {
573 vec->x = 0;
574 vec->y = 0;
575 if (isPadHoldUp(port))
576 vec->y = 1;
577 if (isPadHoldDown(port))
578 vec->y = -1;
579 if (isPadHoldLeft(port))
580 vec->x = -1;
581 if (isPadHoldRight(port))
582 vec->x = 1;
583}
584
585void getPadCrossDirSideways(sead::Vector2f* vec, s32 port) {
586 vec->x = 0;
587 vec->y = 0;
588 if (isPadHoldUp(port))
589 vec->x = -1;
590 if (isPadHoldDown(port))
591 vec->x = 1;
592 if (isPadHoldLeft(port))
593 vec->y = -1;
594 if (isPadHoldRight(port))
595 vec->y = 1;
596}
597
598void calcTouchScreenPos(sead::Vector2f* vec) {
599 vec->set(getController(port: getTouchPanelPort())->getPointer());
600}
601
602void calcTouchLayoutPos(sead::Vector2f*) {}
603
604bool isTouchPosInRect(const sead::Vector2f& rect_pos, const sead::Vector2f& size) {
605 sead::Vector2f pos;
606 calcTouchScreenPos(vec: &pos);
607 return rect_pos.x <= pos.x && pos.x < rect_pos.x + size.x && rect_pos.y <= pos.y &&
608 pos.y < rect_pos.y + size.y;
609}
610
611void setPadRepeat(s32 a1, s32 a2, s32 a3, s32 port) {
612 getController(port)->setPadRepeat(mask: a1, delay_frame: a2, pulse_frame: a3);
613}
614
615s32 getPlayerControllerPort(s32 playerNo) {
616 auto* manager = sead::ControllerMgr::instance();
617 sead::Controller* controller = manager->getControllerByOrder(
618 id: sead::ControllerDefine::ControllerId::cController_Npad, index: playerNo);
619 return manager->findControllerPort(controller);
620}
621
622s32 getTouchPanelPort() {
623 auto* manager = sead::ControllerMgr::instance();
624 sead::Controller* controller = manager->getControllerByOrder(
625 id: sead::ControllerDefine::ControllerId::cController_PadTouch, index: 0);
626 return manager->findControllerPort(controller);
627}
628
629s32 getMainControllerPort() {
630 return getPlayerControllerPort(playerNo: 0);
631}
632
633s32 getMainJoyPadDoublePort() {
634 return getMainControllerPort();
635}
636
637s32 getMainJoyPadSingleRightPort() {
638 return 1;
639}
640
641s32 getMainJoyPadSingleLeftPort() {
642 return 2;
643}
644
645} // namespace al
646