forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 1
/
button.lua
623 lines (544 loc) · 23.1 KB
/
button.lua
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
-- #################################################################
-- courseplay.button class
courseplay.button = {};
cpButton_mt = Class(courseplay.button);
function courseplay.button:new(vehicle, hudPage, img, functionToCall, parameter, x, y, width, height, hudRow, modifiedParameter, hoverText, isMouseWheelArea, isToggleButton, toolTip)
local self = setmetatable({}, cpButton_mt);
if img then
if type(img) == 'table' then
if img[1] == 'iconSprite.png' then
self.overlay = Overlay:new(img, courseplay.hud.iconSpritePath, x, y, width, height);
self.spriteSection = img[2];
end;
else
self.overlay = Overlay:new(img, Utils.getFilename('img/' .. img, courseplay.path), x, y, width, height);
end;
end;
if hoverText == nil then
hoverText = false;
end;
if isMouseWheelArea == nil then
isMouseWheelArea = false;
end;
if isToggleButton == nil then
isToggleButton = false;
end;
if not vehicle.isCourseplayManager then
self.vehicle = vehicle;
end;
self.page = hudPage;
self.functionToCall = functionToCall;
self:setParameter(parameter);
self.width = width;
self.height = height;
self.x_init = x;
self.x = x;
self.x2 = (x + width);
self.y_init = y;
self.y = y;
self.y2 = (y + height);
self.row = hudRow;
self.hoverText = hoverText;
self:setColor('white')
self:setToolTip(toolTip);
self.isMouseWheelArea = isMouseWheelArea and functionToCall ~= nil;
self.isToggleButton = isToggleButton;
self:setCanBeClicked(not isMouseWheelArea and functionToCall ~= nil);
self:setShow(true);
self:setClicked(false);
self:setActive(false);
self:setDisabled(false);
self:setHovered(false);
if modifiedParameter then
self.modifiedParameter = modifiedParameter;
end
if isMouseWheelArea then
self.canScrollUp = true;
self.canScrollDown = true;
end;
if self.spriteSection then
self:setSpriteSectionUVs(self.spriteSection);
else
self:setSpecialButtonUVs();
end;
if vehicle.isCourseplayManager then
table.insert(vehicle[hudPage].buttons, self);
else
table.insert(vehicle.cp.buttons[hudPage], self);
end;
return self;
end;
function courseplay.button:setSpriteSectionUVs(spriteSection)
if not spriteSection or courseplay.hud.buttonUVsPx[spriteSection] == nil then return; end;
self.spriteSection = spriteSection;
courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.buttonUVsPx[spriteSection], courseplay.hud.iconSpriteSize.x, courseplay.hud.iconSpriteSize.y);
end;
function courseplay.button:setSpecialButtonUVs()
if not self.overlay then return; end;
local fn = self.functionToCall;
local prm = self.parameter;
local txtSizeX, txtSizeY = courseplay.hud.iconSpriteSize.x, courseplay.hud.iconSpriteSize.y;
if fn == 'setCpMode' then
courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.modeButtonsUVsPx[prm], txtSizeX, txtSizeY);
elseif fn == 'setHudPage' then
courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.pageButtonsUVsPx[prm], txtSizeX, txtSizeY);
elseif fn == 'generateCourse' then
courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.pageButtonsUVsPx[courseplay.hud.PAGE_COURSE_GENERATION], txtSizeX, txtSizeY);
elseif fn == 'toggleDebugChannel' then
self:setSpriteSectionUVs('recordingStop');
-- CpManager buttons
elseif fn == 'goToVehicle' then
courseplay.utils:setOverlayUVsPx(self.overlay, courseplay.hud.pageButtonsUVsPx[courseplay.hud.PAGE_DRIVING_SETTINGS], txtSizeX, txtSizeY);
end;
end;
function courseplay.button:render()
-- self = courseplay.button
local vehicle, pg, fn, prm = self.vehicle, self.page, self.functionToCall, self.parameter;
local hoveredButton = false;
--mouseWheelAreas conditionals
if self.isMouseWheelArea then
local canScrollUp, canScrollDown;
if pg == courseplay.hud.PAGE_CP_CONTROL then
if fn == "setCustomFieldEdgePathNumber" then
canScrollUp = vehicle.cp.fieldEdge.customField.isCreated and vehicle.cp.fieldEdge.customField.fieldNum < courseplay.fields.customFieldMaxNum;
canScrollDown = vehicle.cp.fieldEdge.customField.isCreated and vehicle.cp.fieldEdge.customField.fieldNum > 0;
end;
elseif pg == courseplay.hud.PAGE_MANAGE_COURSES then
if fn == "shiftHudCourses" then
canScrollUp = vehicle.cp.hud.courseListPrev == true;
canScrollDown = vehicle.cp.hud.courseListNext == true;
end;
elseif pg == courseplay.hud.PAGE_COMBI_MODE then
if fn == 'changeCombineOffset' or fn == 'changeTipperOffset' then
canScrollUp = vehicle.cp.mode == courseplay.MODE_COMBI or vehicle.cp.mode == courseplay.MODE_OVERLOADER;
canScrollDown = canScrollUp;
elseif fn == "changeTurnDiameter" then
canScrollUp = true;
canScrollDown = vehicle.cp.turnDiameter > 0;
elseif fn == "changeFollowAtFillLevel" then
canScrollUp = vehicle.cp.followAtFillLevel < 100;
canScrollDown = vehicle.cp.followAtFillLevel > 0;
elseif fn == "changeDriveOnAtFillLevel" then
canScrollUp = vehicle.cp.driveOnAtFillLevel < 100;
canScrollDown = vehicle.cp.driveOnAtFillLevel > 0;
elseif fn == 'changeRefillUntilPct' then
canScrollUp = (vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_LIQUIDMANURE_TRANSPORT) and vehicle.cp.refillUntilPct < 100;
canScrollDown = (vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_LIQUIDMANURE_TRANSPORT) and vehicle.cp.refillUntilPct > 1;
end;
elseif pg == courseplay.hud.PAGE_MANAGE_COMBINES then
if fn == 'setSearchCombineOnField' then
canScrollUp = courseplay.fields.numAvailableFields > 0 and vehicle.cp.searchCombineAutomatically and vehicle.cp.searchCombineOnField > 0;
canScrollDown = courseplay.fields.numAvailableFields > 0 and vehicle.cp.searchCombineAutomatically and vehicle.cp.searchCombineOnField < courseplay.fields.numAvailableFields;
end;
elseif pg == courseplay.hud.PAGE_SPEEDS then
if fn == 'changeTurnSpeed' then
canScrollUp = vehicle.cp.speeds.turn < vehicle.cp.speeds.max;
canScrollDown = vehicle.cp.speeds.turn > vehicle.cp.speeds.minTurn;
elseif fn == 'changeFieldSpeed' then
canScrollUp = vehicle.cp.speeds.field < vehicle.cp.speeds.max;
canScrollDown = vehicle.cp.speeds.field > vehicle.cp.speeds.minField;
elseif fn == 'changeMaxSpeed' then
canScrollUp = vehicle.cp.speeds.useRecordingSpeed == false and vehicle.cp.speeds.street < vehicle.cp.speeds.max;
canScrollDown = vehicle.cp.speeds.useRecordingSpeed == false and vehicle.cp.speeds.street > vehicle.cp.speeds.minStreet;
elseif fn == 'changeUnloadSpeed' then
canScrollUp = vehicle.cp.speeds.unload < vehicle.cp.speeds.max;
canScrollDown = vehicle.cp.speeds.unload > vehicle.cp.speeds.minUnload;
end;
elseif pg == courseplay.hud.PAGE_GENERAL_SETTINGS then
if fn == "changeWaitTime" then
canScrollUp = courseplay:getCanHaveWaitTime(vehicle);
canScrollDown = canScrollUp and vehicle.cp.waitTime > 0;
elseif fn == 'changeDebugChannelSection' then
canScrollUp = courseplay.debugChannelSection > 1;
canScrollDown = courseplay.debugChannelSection < courseplay.numDebugChannelSections;
end;
elseif pg == courseplay.hud.PAGE_DRIVING_SETTINGS then
if fn == "changeLaneOffset" then
canScrollUp = vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_FIELDWORK;
canScrollDown = canScrollUp;
elseif fn == "changeToolOffsetX" or fn == "changeToolOffsetZ" then
canScrollUp = vehicle.cp.mode == courseplay.MODE_OVERLOADER or vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_FIELDWORK or vehicle.cp.mode == courseplay.MODE_COMBINE_SELF_UNLOADING or vehicle.cp.mode == courseplay.MODE_LIQUIDMANURE_TRANSPORT;
canScrollDown = canScrollUp;
end;
elseif pg == courseplay.hud.PAGE_COURSE_GENERATION then
if fn == "setFieldEdgePath" then
canScrollUp = courseplay.fields.numAvailableFields > 0 and vehicle.cp.fieldEdge.selectedField.fieldNum < courseplay.fields.numAvailableFields;
canScrollDown = courseplay.fields.numAvailableFields > 0 and vehicle.cp.fieldEdge.selectedField.fieldNum > 0;
elseif fn == "changeWorkWidth" then
canScrollUp = true;
canScrollDown = vehicle.cp.workWidth > 0.1;
end;
end;
if canScrollUp ~= nil then
self:setCanScrollUp(canScrollUp);
end;
if canScrollDown ~= nil then
self:setCanScrollDown(canScrollDown);
end;
elseif self.overlay ~= nil then
if pg ~= -courseplay.hud.PAGE_MANAGE_COURSES then -- NOTE: course buttons' (page -2) visibility are handled in buttonsActiveEnabled(), section 'page2'
local show = true;
-- CONDITIONAL DISPLAY
-- Global
if pg == "global" then
if fn == "showSaveCourseForm" and prm == "course" then
show = vehicle.cp.canDrive and not vehicle.cp.isRecording and not vehicle.cp.recordingIsPaused and vehicle.Waypoints ~= nil and #(vehicle.Waypoints) ~= 0;
end;
-- Page 1
elseif pg == courseplay.hud.PAGE_CP_CONTROL then
if fn == "setCpMode" then
show = vehicle.cp.canSwitchMode and not vehicle.cp.distanceCheck;
elseif fn == "clearCustomFieldEdge" or fn == "toggleCustomFieldEdgePathShow" then
show = not vehicle.cp.canDrive and vehicle.cp.fieldEdge.customField.isCreated;
elseif fn == "setCustomFieldEdgePathNumber" then
if prm < 0 then
show = not vehicle.cp.canDrive and vehicle.cp.fieldEdge.customField.isCreated and vehicle.cp.fieldEdge.customField.fieldNum > 0;
elseif prm > 0 then
show = not vehicle.cp.canDrive and vehicle.cp.fieldEdge.customField.isCreated and vehicle.cp.fieldEdge.customField.fieldNum < courseplay.fields.customFieldMaxNum;
end;
elseif fn == 'toggleFindFirstWaypoint' then
show = vehicle.cp.canDrive and not vehicle:getIsCourseplayDriving() and not vehicle.cp.isRecording and not vehicle.cp.recordingIsPaused;
elseif fn == 'stop_record' or fn == 'setRecordingPause' or fn == 'delete_waypoint' or fn == 'set_waitpoint' or fn == 'set_crossing' or fn == 'setRecordingTurnManeuver' or fn == 'change_DriveDirection' then
show = vehicle.cp.isRecording or vehicle.cp.recordingIsPaused;
elseif fn == 'clearCurrentLoadedCourse' then
show = vehicle.cp.canDrive and not vehicle.cp.isDriving;
end;
-- Page 2
elseif pg == courseplay.hud.PAGE_MANAGE_COURSES then
if fn == "reloadCoursesFromXML" then
show = g_server ~= nil;
elseif fn == "showSaveCourseForm" and prm == "filter" then
show = not vehicle.cp.hud.choose_parent;
elseif fn == 'clearCurrentLoadedCourse' then
show = vehicle.cp.canDrive and not vehicle.cp.isDriving;
elseif fn == "shiftHudCourses" then
if prm < 0 then
show = vehicle.cp.hud.courseListPrev;
elseif prm > 0 then
show = vehicle.cp.hud.courseListNext;
end;
end;
-- Page 3
elseif pg == courseplay.hud.PAGE_COMBI_MODE then
if fn == 'changeCombineOffset' or fn == 'changeTipperOffset' then
show = vehicle.cp.mode == courseplay.MODE_COMBI or vehicle.cp.mode == courseplay.MODE_OVERLOADER;
elseif fn == "changeTurnDiameter" and prm < 0 then
show = vehicle.cp.turnDiameter > 0;
elseif fn == "changeFollowAtFillLevel" then
if prm < 0 then
show = vehicle.cp.followAtFillLevel > 0;
elseif prm > 0 then
show = vehicle.cp.followAtFillLevel < 100;
end;
elseif fn == "changeDriveOnAtFillLevel" then
if prm < 0 then
show = vehicle.cp.driveOnAtFillLevel > 0;
elseif prm > 0 then
show = vehicle.cp.driveOnAtFillLevel < 100;
end;
elseif fn == 'changeRefillUntilPct' then
if prm < 0 then
show = (vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_LIQUIDMANURE_TRANSPORT) and vehicle.cp.refillUntilPct > 1;
elseif prm > 0 then
show = (vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_LIQUIDMANURE_TRANSPORT) and vehicle.cp.refillUntilPct < 100;
end;
end;
-- Page 4
elseif pg == courseplay.hud.PAGE_MANAGE_COMBINES then
if fn == 'selectAssignedCombine' then
show = not vehicle.cp.searchCombineAutomatically;
if show and prm < 0 then
show = vehicle.cp.selectedCombineNumber > 0;
end;
elseif fn == 'setSearchCombineOnField' then
show = courseplay.fields.numAvailableFields > 0 and vehicle.cp.searchCombineAutomatically;
if show then
if prm < 0 then
show = vehicle.cp.searchCombineOnField > 0;
else
show = vehicle.cp.searchCombineOnField < courseplay.fields.numAvailableFields;
end;
end;
elseif fn == 'removeActiveCombineFromTractor' then
show = vehicle.cp.activeCombine ~= nil;
end;
-- Page 5
elseif pg == courseplay.hud.PAGE_SPEEDS then
if fn == 'changeTurnSpeed' then
if prm < 0 then
show = vehicle.cp.speeds.turn > vehicle.cp.speeds.minTurn;
elseif prm > 0 then
show = vehicle.cp.speeds.turn < vehicle.cp.speeds.max;
end;
elseif fn == 'changeFieldSpeed' then
if prm < 0 then
show = vehicle.cp.speeds.field > vehicle.cp.speeds.minField;
elseif prm > 0 then
show = vehicle.cp.speeds.field < vehicle.cp.speeds.max;
end;
elseif fn == 'changeMaxSpeed' then
if prm < 0 then
show = not vehicle.cp.speeds.useRecordingSpeed and vehicle.cp.speeds.street > vehicle.cp.speeds.minStreet;
elseif prm > 0 then
show = not vehicle.cp.speeds.useRecordingSpeed and vehicle.cp.speeds.street < vehicle.cp.speeds.max;
end;
elseif fn == 'changeUnloadSpeed' then
if prm < 0 then
show = vehicle.cp.speeds.unload > vehicle.cp.speeds.minUnload;
elseif prm > 0 then
show = vehicle.cp.speeds.unload < vehicle.cp.speeds.max;
end;
end;
-- Page 6
elseif pg == courseplay.hud.PAGE_GENERAL_SETTINGS then
if fn == 'toggleRealisticDriving' then
show = vehicle.cp.mode == courseplay.MODE_COMBI or vehicle.cp.mode == courseplay.MODE_OVERLOADER;
elseif fn == 'changeWarningLightsMode' then
if prm < 0 then
show = vehicle.cp.warningLightsMode > courseplay.WARNING_LIGHTS_NEVER;
else
show = vehicle.cp.warningLightsMode < courseplay.WARNING_LIGHTS_BEACON_ALWAYS;
end;
elseif fn == "changeWaitTime" then
show = courseplay:getCanHaveWaitTime(vehicle);
if show and prm < 0 then
show = vehicle.cp.waitTime > 0;
end;
elseif fn == "toggleDebugChannel" then
show = prm >= courseplay.debugChannelSectionStart and prm <= courseplay.debugChannelSectionEnd;
elseif fn == "changeDebugChannelSection" then
if prm < 0 then
show = courseplay.debugChannelSection > 1;
elseif prm > 0 then
show = courseplay.debugChannelSection < courseplay.numDebugChannelSections;
end;
end;
-- Page 7
elseif pg == courseplay.hud.PAGE_DRIVING_SETTINGS then
if fn == "changeLaneOffset" then
show = vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_FIELDWORK;
elseif fn == "toggleSymmetricLaneChange" then
show = (vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_FIELDWORK) and vehicle.cp.laneOffset ~= 0;
elseif fn == "changeToolOffsetX" or fn == "changeToolOffsetZ" then
show = vehicle.cp.mode == courseplay.MODE_OVERLOADER or vehicle.cp.mode == courseplay.MODE_SEED_FERTILIZE or vehicle.cp.mode == courseplay.MODE_FIELDWORK or vehicle.cp.mode == courseplay.MODE_COMBINE_SELF_UNLOADING;
elseif fn == "switchDriverCopy" and prm < 0 then
show = vehicle.cp.selectedDriverNumber > 0;
elseif fn == "copyCourse" then
show = vehicle.cp.hasFoundCopyDriver;
end;
-- Page 8
elseif pg == courseplay.hud.PAGE_COURSE_GENERATION then
if fn == 'clearCurrentLoadedCourse' then
show = vehicle.cp.canDrive and not vehicle.cp.isDriving;
elseif fn == 'toggleSucHud' then
show = courseplay.fields.numAvailableFields > 0 and vehicle.cp.fieldEdge.selectedField.fieldNum > 0;
elseif fn == "toggleSelectedFieldEdgePathShow" then
show = courseplay.fields.numAvailableFields > 0 and vehicle.cp.fieldEdge.selectedField.fieldNum > 0;
elseif fn == "setFieldEdgePath" then
show = courseplay.fields.numAvailableFields > 0;
if show then
if prm < 0 then
show = vehicle.cp.fieldEdge.selectedField.fieldNum > 0;
elseif prm > 0 then
show = vehicle.cp.fieldEdge.selectedField.fieldNum < courseplay.fields.numAvailableFields;
end;
end;
elseif fn == "changeWorkWidth" and prm < 0 then
show = vehicle.cp.workWidth > 0.1;
elseif fn == "changeStartingDirection" then
show = vehicle.cp.hasStartingCorner;
elseif fn == 'toggleHeadlandDirection' or fn == 'toggleHeadlandOrder' then
show = vehicle.cp.headland.numLanes > 0;
elseif fn == 'changeHeadlandNumLanes' then
if prm < 0 then
show = vehicle.cp.headland.numLanes > 0;
elseif prm > 0 then
show = vehicle.cp.headland.numLanes < vehicle.cp.headland.maxNumLanes;
end;
-- NOTE: generateCourse button is handled in buttonsActiveEnabled(), section 'generateCourse'
end;
end;
self:setShow(show);
end;
if self.show then
-- set color
local currentColor = self.curColor;
local targetColor = currentColor;
local hoverColor = 'hover';
if fn == 'openCloseHud' then
hoverColor = 'closeRed';
end;
if fn == 'moveShovelToPosition' and not self.isDisabled and vehicle.cp.manualShovelPositionOrder and vehicle.cp.manualShovelPositionOrder == prm then -- forced color
targetColor = 'warningRed';
elseif not self.isDisabled and not self.isActive and not self.isHovered and self.canBeClicked and not self.isClicked then
targetColor = 'white';
elseif self.isDisabled then
targetColor = 'whiteDisabled';
elseif not self.isDisabled and self.canBeClicked and self.isClicked and fn ~= 'openCloseHud' then
targetColor = 'activeRed';
elseif self.isHovered and ((not self.isDisabled and self.isToggleButton and self.isActive and self.canBeClicked and not self.isClicked) or (not self.isDisabled and not self.isActive and self.canBeClicked and not self.isClicked)) then
targetColor = hoverColor;
hoveredButton = true;
if self.isToggleButton then
--print(string.format('self %q (loop %d): isHovered=%s, isActive=%s, isDisabled=%s, canBeClicked=%s -> hoverColor', fn, g_updateLoopIndex, tostring(self.isHovered), tostring(self.isActive), tostring(self.isDisabled), tostring(self.canBeClicked)));
end;
elseif self.isActive and (not self.isToggleButton or (self.isToggleButton and not self.isHovered)) then
targetColor = 'activeGreen';
if self.isToggleButton then
--print(string.format('button %q (loop %d): isHovered=%s, isActive=%s, isDisabled=%s, canBeClicked=%s -> activeGreen', fn, g_updateLoopIndex, tostring(self.isHovered), tostring(self.isActive), tostring(self.isDisabled), tostring(self.canBeClicked)));
end;
end;
if currentColor ~= targetColor then
self:setColor(targetColor);
end;
-- render
self.overlay:render();
end;
end; --elseif button.overlay ~= nil
return hoveredButton;
end;
function courseplay.button:setColor(colorName)
if self.overlay and colorName and (self.curColor == nil or self.curColor ~= colorName) and courseplay.hud.colors[colorName] then
self.overlay:setColor(unpack(courseplay.hud.colors[colorName]));
self.curColor = colorName;
end;
end;
function courseplay.button:setPosition(posX, posY)
self.x = posX;
self.x_init = posX;
self.x2 = posX + self.width;
self.y = posY;
self.y_init = posY;
self.y2 = posY + self.height;
if not self.overlay then return; end;
self.overlay:setPosition(self.x, self.y);
end;
function courseplay.button:setOffset(offsetX, offsetY)
offsetX = offsetX or 0
offsetY = offsetY or 0
self.x = self.x_init + offsetX;
self.y = self.y_init + offsetY;
self.x2 = self.x + self.width;
self.y2 = self.y + self.height;
if not self.overlay then return; end;
self.overlay:setPosition(self.x, self.y);
end
function courseplay.button:setParameter(parameter)
if self.parameter ~= parameter then
self.parameter = parameter;
end;
end;
function courseplay.button:setToolTip(text)
if self.toolTip ~= text then
self.toolTip = text;
end;
end;
function courseplay.button:setActive(active)
if self.isActive ~= active then
self.isActive = active;
end;
end;
function courseplay.button:setCanBeClicked(canBeClicked)
if self.canBeClicked ~= canBeClicked then
self.canBeClicked = canBeClicked;
end;
end;
function courseplay.button:setClicked(clicked)
if self.isClicked ~= clicked then
self.isClicked = clicked;
end;
end;
function courseplay.button:setDisabled(disabled)
if self.isDisabled ~= disabled then
self.isDisabled = disabled;
end;
end;
function courseplay.button:setHovered(hovered)
if self.isHovered ~= hovered then
self.isHovered = hovered;
end;
end;
function courseplay.button:setCanScrollUp(canScrollUp)
if self.canScrollUp ~= canScrollUp then
self.canScrollUp = canScrollUp;
end;
end;
function courseplay.button:setCanScrollDown(canScrollDown)
if self.canScrollDown ~= canScrollDown then
self.canScrollDown = canScrollDown;
end;
end;
function courseplay.button:setShow(show)
if self.show ~= show then
self.show = show;
end;
end;
function courseplay.button:setAttribute(attribute, value)
if self[attribute] ~= value then
self[attribute] = value;
end;
end;
function courseplay.button:deleteOverlay()
if self.overlay ~= nil and self.overlay.overlayId ~= nil and self.overlay.delete ~= nil then
self.overlay:delete();
end;
end;
function courseplay.button:getHasMouse(mouseX, mouseY)
-- return mouseX > self.x and mouseX < self.x2 and mouseY > self.y and mouseY < self.y2;
return courseplay:mouseIsInArea(mouseX, mouseY, self.x, self.x2, self.y, self.y2);
end;
-- #################################################################
-- courseplay.buttons
function courseplay.buttons:renderButtons(vehicle, page)
-- self = courseplay.buttons
local hoveredButton;
for _,button in pairs(vehicle.cp.buttons.global) do
if button:render() then
hoveredButton = button;
end;
end;
for _,button in pairs(vehicle.cp.buttons[page]) do
if button:render() then
hoveredButton = button;
end;
end;
if page == courseplay.hud.PAGE_MANAGE_COURSES then
for _,button in pairs(vehicle.cp.buttons[-courseplay.hud.PAGE_MANAGE_COURSES]) do
if button:render() then
hoveredButton = button;
end;
end;
end;
if vehicle.cp.suc.active then
if vehicle.cp.suc.fruitNegButton:render() then
hoveredButton = vehicle.cp.suc.fruitNegButton;
end;
if vehicle.cp.suc.fruitPosButton:render() then
hoveredButton = vehicle.cp.suc.fruitPosButton;
end;
end;
-- set currently hovered button in vehicle
self:setHoveredButton(vehicle, hoveredButton);
end;
function courseplay.buttons:setHoveredButton(vehicle, button)
if vehicle.cp.buttonHovered == button then
return;
end;
vehicle.cp.buttonHovered = button;
self:onHoveredButtonChanged(vehicle);
end;
function courseplay.buttons:onHoveredButtonChanged(vehicle)
-- set toolTip in vehicle
if vehicle.cp.buttonHovered ~= nil and vehicle.cp.buttonHovered.toolTip ~= nil then
courseplay:setToolTip(vehicle, vehicle.cp.buttonHovered.toolTip);
elseif vehicle.cp.buttonHovered == nil then
courseplay:setToolTip(vehicle, nil);
end;
end;
function courseplay.buttons:deleteButtonOverlays(vehicle)
for k,buttonSection in pairs(vehicle.cp.buttons) do
for i,button in pairs(buttonSection) do
button:deleteOverlay();
end;
end;
end;