-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProTrainer.js
More file actions
152 lines (132 loc) · 4.67 KB
/
ProTrainer.js
File metadata and controls
152 lines (132 loc) · 4.67 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
/// <reference path=".config/sa.d.ts" />
import { drawMenu } from './ProTrainer/core/ui.js';
import { PlayerMenu } from './ProTrainer/modules/player_module.js';
import { WeaponsMenu } from './ProTrainer/modules/weapons_module.js';
import { TeleportMenu } from './ProTrainer/modules/teleport_module.js';
import { VehicleMenu } from './ProTrainer/modules/vehicles_module.js';
import { VehicleModsMenu } from './ProTrainer/modules/vehicle_mods_module.js';
import { WeatherMenu } from './ProTrainer/modules/weather_module.js';
const playerModule = new PlayerMenu();
const weaponsModule = new WeaponsMenu();
const vehicleModule = new VehicleMenu();
const teleportModule = new TeleportMenu();
const vehicleModsModule = new VehicleModsMenu();
const weatherModule = new WeatherMenu();
// --- ARBRE PRINCIPAL DU MENU ---
const mainMenuDef = {
title: "PRO TRAINER",
items: [
playerModule.getMenu(),
vehicleModule.getMenu(),
vehicleModsModule.getMenu(),
teleportModule.getMenu(),
weaponsModule.getMenu(),
weatherModule.getMenu()
]
};
// --- ÉTAT DU GESTIONNAIRE DE MENU ---
let menuOpen = false;
let lastInput = 0;
let menuHistory = [];
let cursorHistory = [];
let currentMenu = mainMenuDef;
let cursor = 0;
// --- BOUCLE PRINCIPALE ---
(async function () {
while (true) {
await asyncWait(0);
// 1. On vérifie si on doit ouvrir ou fermer le menu (Touche F4)
handleMenuToggle();
// 2. Si le menu est ouvert, on gère son fonctionnement
if (menuOpen) {
drawCurrentMenu(); // Gère l'affichage à l'écran
handleMenuInputs(); // Gère les touches de navigation
}
}
})().catch((e) => log("ProTrainer Error: " + (e ? e.message : "")));
// ==========================================
// --- LES FONCTIONS DU MENU ---
// ==========================================
// Gère l'ouverture/fermeture avec F4 (Touche 115)
function handleMenuToggle() {
const now = Date.now();
if (Pad.IsKeyPressed(115) && now - lastInput > 200) {
menuOpen = !menuOpen;
lastInput = now;
if (menuOpen) {
// Remise à zéro quand on ouvre le menu
currentMenu = mainMenuDef;
cursor = 0;
menuHistory = [];
cursorHistory = [];
}
}
}
// Prépare les textes et dessine le menu
function drawCurrentMenu() {
let visibleOptions = currentMenu.items.map(item => {
let mappedItem = {
name: (typeof item.name === 'function') ? item.name() : item.name
};
if (item.rightText) {
mappedItem.rightText = (typeof item.rightText === 'function') ? item.rightText() : item.rightText;
}
if (item.rightColor) {
mappedItem.rightColor = (typeof item.rightColor === 'function') ? item.rightColor() : item.rightColor;
}
return mappedItem;
});
drawMenu(visibleOptions, cursor, currentMenu.title);
}
// Gère la navigation : clavier / manette
function handleMenuInputs() {
const now = Date.now();
let currentItem = currentMenu.items[cursor];
// Vérifie qu'on ne spamme pas les touches
if (now - lastInput <= 150) return;
// Flèche HAUT (38)
if (Pad.IsKeyPressed(38)) {
cursor = (cursor - 1 + currentMenu.items.length) % currentMenu.items.length;
lastInput = now;
}
// Flèche BAS (40)
else if (Pad.IsKeyPressed(40)) {
cursor = (cursor + 1) % currentMenu.items.length;
lastInput = now;
}
// Flèche GAUCHE (37)
else if (Pad.IsKeyPressed(37) && currentItem.onLeft) {
currentItem.onLeft();
lastInput = now;
}
// Flèche DROITE (39)
else if (Pad.IsKeyPressed(39) && currentItem.onRight) {
currentItem.onRight();
lastInput = now;
}
// RETOUR / ESPACE (8) - Quitter le sous-menu
else if (Pad.IsKeyPressed(8) && now - lastInput > 200) {
if (menuHistory.length > 0) {
currentMenu = menuHistory.pop();
cursor = cursorHistory.pop();
} else {
menuOpen = false; // Ferme le menu principal
}
lastInput = now;
}
// ENTRÉE (13) - Valider un choix
else if (Pad.IsKeyPressed(13) && now - lastInput > 250) {
if (currentItem.subMenu) {
menuHistory.push(currentMenu);
cursorHistory.push(cursor);
currentMenu = currentItem.subMenu;
cursor = 0;
} else if (currentItem.action) {
(async () => {
try { await currentItem.action(); }
catch(e) { log("Action Error: " + (e ? e.message : "")); }
})();
}
lastInput = now;
}
}