Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on May 23, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathinput.lua
More file actions
Latest commit
262 lines (229 loc) · 11.4 KB
/
Copy pathinput.lua
File metadata and controls
262 lines (229 loc) · 11.4 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
258
259
260
261
262
functioncourseplay:onMouseEvent(posX, posY, isDown, isUp, mouseButton)
--RIGHT CLICK
-- Input binding debug
localvehicle=g_currentMission.controlledVehicle
ifnotcourseplay.isEnabled(vehicle) then
return
end
courseEditor:updateMouseState(vehicle, posX, posY, isDown, isUp, mouseButton)
--print(string.format('courseplay:mouseEvent(posX(%s), posY(%s), isDown(%s), isUp(%s), mouseButton(%s))', tostring(posX), tostring(posY), tostring(isDown), tostring(isUp), tostring(mouseButton) ))
--print(string.format("if isUp(%s) and mouseButton(%s) == courseplay.inputBindings.mouse.secondaryButtonId(%s) and Enterable.getIsEntered(self)(%s) then"
--,tostring(isUp),tostring(mouseButton),tostring(courseplay.inputBindings.mouse.secondaryButtonId),tostring(Enterable.getIsEntered(self))))
ifisUpandmouseButton==courseplay.inputBindings.mouse.secondaryButtonIdandvehicle:getIsEntered() then
ifvehicle.cp.hud.showthen
courseplay:setMouseCursor(vehicle, notvehicle.cp.mouseCursorActive);
elseifnotvehicle.cp.hud.showandcourseplay.globalSettings.enableOpenHudWithMouseGlobal:is(true) andvehicle.cp.settings.enableOpenHudWithMouseVehicle:is(true) then
courseplay:openCloseHud(vehicle, true)
end;
end;
localhudGfx=courseplay.hud.visibleArea;
localmouseIsInHudArea=vehicle.cp.mouseCursorActiveandcourseplay:mouseIsInArea(posX, posY, hudGfx.x1, hudGfx.x2, hudGfx.y1, hudGfx.y2);
-- if not mouseIsInHudArea then return; end;
-- should we switch vehicles? Option must be active, must be in a vehicle, must not be in CP HUD Area (for AD, not sure how to add) and must have any mouse course active.
ifcourseplay.globalSettings.clickToSwitch:is(true) andvehicle:getIsEntered() andnotmouseIsInHudAreaand
mouseButton==courseplay.inputBindings.mouse.primaryButtonIdand (g_inputBinding:getShowMouseCursor() ==true) then
clickToSwitch:updateMouseState(vehicle, posX, posY, isDown, isUp, mouseButton)
end
--LEFT CLICK
if (isDownorisUp) andmouseButton==courseplay.inputBindings.mouse.primaryButtonIdandvehicle.cp.mouseCursorActiveandvehicle.cp.hud.showandvehicle:getIsEntered() andmouseIsInHudAreathen
localbuttonToHandle;
ifbuttonToHandle==nilthen
for_,buttoninpairs(vehicle.cp.buttons.global) do
ifbutton.showandbutton:getHasMouse(posX, posY) andnotbutton.isMouseWheelAreathen
buttonToHandle=button;
break;
end;
end;
end;
ifbuttonToHandle==nilthen
for_,buttoninpairs(vehicle.cp.buttons[vehicle.cp.hud.currentPage]) do
ifbutton.canBeClickedandbutton.showandnotbutton.isDisabledandbutton:getHasMouse(posX, posY) andnotbutton.isMouseWheelAreathen
buttonToHandle=button;
break;
end;
end;
end;
ifbuttonToHandle==nilthen
ifvehicle.cp.hud.currentPage==2then
for_,buttoninpairs(vehicle.cp.buttons[-2]) do
ifbutton.showandbutton:getHasMouse(posX, posY) andnotbutton.isMouseWheelAreathen
buttonToHandle=button;
break;
end;
end;
end;
end;
ifbuttonToHandlethen
buttonToHandle:setClicked(isDown);
--[[if not buttonToHandle.isDisabled and buttonToHandle.hoverText and buttonToHandle.functionToCall ~= nil then
vehicle.cp.hud.content.pages[buttonToHandle.page][buttonToHandle.row][1].isClicked = isDown;
end;]]
ifisUpthen
buttonToHandle:handleMouseClick();
end;
return;
end;
--HOVER
elseifvehicle.cp.mouseCursorActiveandnotisDownandvehicle.cp.hud.showandvehicle:getIsEntered() then
-- local currentHoveredButton;
vehicle.cp.hud.mouseWheel.render=false;
for_,buttoninpairs(vehicle.cp.buttons.global) do
button:setClicked(false);
ifbutton.showandnotbutton.isHiddenthen
button:setClicked(false);
button:setHovered(button:getHasMouse(posX, posY));
ifbutton.isHoveredthen
button:handleHoverAction(vehicle, posX, posY)
end;
end;
end;
for_,buttoninpairs(vehicle.cp.buttons[vehicle.cp.hud.currentPage]) do
button:setClicked(false);
ifbutton.showandnotbutton.isHiddenthen
button:setHovered(button:getHasMouse(posX, posY));
ifbutton.isHoveredthen
button:handleHoverAction(vehicle, posX, posY)
end;
ifbutton.hoverTextandnotbutton.isDisabledthen
vehicle.cp.hud.content.pages[button.page][button.row][1].isHovered=button.isHovered;
end;
end;
end;
ifvehicle.cp.hud.currentPage==2then
for_,buttoninpairs(vehicle.cp.buttons[-2]) do
button:setClicked(false);
ifbutton.showandnotbutton.isHiddenthen
button:setHovered(button:getHasMouse(posX, posY));
ifbutton.hoverTextthen
vehicle.cp.hud.content.pages[2][button.row][1].isHovered=button.isHovered;
end;
end;
end;
end;
--- Prevent mouse from zooming when mouse cursor is inside the CP Hud Mouse Wheel area
self:lockContext(vehicle.cp.hud.mouseWheel.render);
end;
-- ##################################################
-- 2D COURSE WINDOW: DRAG + DROP MOVE
ifvehicle.cp.course2dDrawDataandvehicle.cp.settings.courseDrawMode:isCourseMapVisible() then
localplot=CpManager.course2dPlotField;
ifisDownandmouseButton==courseplay.inputBindings.mouse.primaryButtonIdandvehicle.cp.mouseCursorActiveandvehicle:getIsEntered() andcourseplay:mouseIsInArea(posX, posY, plot.x, plot.x+plot.width, plot.y, plot.y+plot.height) then
CpManager.course2dDragDropMouseDown= { posX, posY };
ifvehicle.cp.course2dPdaMapOverlaythen
vehicle.cp.course2dPdaMapOverlay.origPos= { vehicle.cp.course2dPdaMapOverlay.x, vehicle.cp.course2dPdaMapOverlay.y };
else
vehicle.cp.course2dBackground.origPos= { vehicle.cp.course2dBackground.x, vehicle.cp.course2dBackground.y };
end;
elseifisUpandCpManager.course2dDragDropMouseDown~=nilthen
courseplay.utils:move2dCoursePlotField(vehicle, posX, posY);
elseifnotisUpandnotisDownandCpManager.course2dDragDropMouseDown~=nilthen
courseplay.utils:update2dCourseBackgroundPos(vehicle, posX, posY);
end;
end;
end; --END mouseEvent()
functioncourseplay:mouseIsInArea(mouseX, mouseY, areaX1, areaX2, areaY1, areaY2)
returnmouseX>=areaX1andmouseX<=areaX2andmouseY>=areaY1andmouseY<=areaY2;
end;
functioncourseplay:setCourseplayFunc(func, value, noEventSend, page)
courseplay:debug("setCourseplayFunc: function: " ..func.." value: " ..tostring(value) .." noEventSend: " ..tostring(noEventSend) .." page: " ..tostring(page), courseplay.DBG_MULTIPLAYER)
ifnoEventSend~=truethen
CourseplayEvent.sendEvent(self, func, value,noEventSend,page); -- Die Funktion ruft sendEvent auf und übergibt 3 Werte (self "also mein ID", action, "Ist eine Zahl an der ich festmache welches Fenster ich aufmachen will", state "Ist der eigentliche Wert also true oder false"
end;
ifvalue=="nil" then
value=nil
end
courseplay:executeFunction(self, func, value, page);
ifpageandself.cp.hud.reloadPage[page] ~=nilthen
courseplay.hud:setReloadPageOrder(self, page, true);
end;
end
functioncourseplay:executeFunction(self, func, value, page)
courseplay:debug("executeFunction: function: " ..func.." value: " ..tostring(value) .." page: " ..tostring(page), courseplay.DBG_MULTIPLAYER)
--legancy code
ifStringUtil.startsWith(func,"self") orStringUtil.startsWith(func,"courseplay") then
courseplay:debug(" setting value",courseplay.DBG_MULTIPLAYER)
courseplay:setVarValueFromString(self, func, value)
--courseplay:debug(" "..tostring(func)..": "..tostring(value),courseplay.DBG_MULTIPLAYER)
return
end
ifself:getIsEntered() then
--The old sound playSample(courseplay.hud.clickSound, 1, 1, 0, 0, 0);
-- The new gui click sound
g_currentMission.hud.guiSoundPlayer:playSample(GuiSoundPlayer.SOUND_SAMPLES.CLICK)
end
courseplay:debug(('%s: calling function "%s(%s)"'):format(nameNum(self), tostring(func), tostring(value)), courseplay.DBG_HUD);
iffunc~="rowButton" then
--@source: http://stackoverflow.com/questions/1791234/lua-call-function-from-a-string-with-function-name
assert(loadstring('courseplay:' ..func..'(...)'))(self, value);
courseplay.hud:setReloadPageOrder(self, self.cp.hud.currentPage, true);
else
courseplay:debug(('%s: calling rowButton function !!!'):format(nameNum(self)), courseplay.DBG_MULTIPLAYER);
end; --END isRowFunction
end;
--- Lock/Unlock mouse and keyboard form any interaction outside the courseplay hud
functioncourseplay:lockContext(lockIt)
locallockIt=lockIt~=false;
iflockItandg_inputBinding:getContextName() ~=courseplay.INPUT_CONTEXT_NAMEthen
g_inputBinding:setContext(courseplay.INPUT_CONTEXT_NAME, true, false);
elseifnotlockItandg_inputBinding:getContextName() ==courseplay.INPUT_CONTEXT_NAMEthen
g_inputBinding:revertContext(true);
end
end;
courseplay.inputBindings= {};
courseplay.inputBindings.mouse= {};
courseplay.inputBindings.mouse.mouseButtonOverlays= {
MOUSE_BUTTON_NONE='mouseNMB.png',
MOUSE_BUTTON_LEFT='mouseLMB.png',
MOUSE_BUTTON_RIGHT='mouseRMB.png',
MOUSE_BUTTON_MIDDLE='mouseMMB.png',
MOUSE_BUTTON_LEFTRIGHT='mouseBMB.png'
};
courseplay.inputBindings.keyboard= {};
functioncourseplay:onKeyEvent(unicode, sym, modifier, isDown)
--print(string.format("%s: unicode(%s), sym(%s), modifier(%s), isDown(%s)",tostring(Input.keyIdToIdName[sym]),tostring(unicode),tostring(sym),tostring(modifier),tostring(isDown)))
--[[for name,action in pairs (courseplay.inputActions) do
if sym == action.bindingSym then
--print("set "..tostring(name)..' to '..tostring(isDown))
action.isPressed = isDown
action.hasEvent = isDown
end
end]]
end;
--- appendedFunction onActionBindingsChanged for InputDisplayManager.onActionBindingsChanged
-- Used to update hud if keybindings have been changed when ingame.
functioncourseplay:onActionBindingsChanged(...)
ifg_currentMissionandg_currentMission.enterablesthen
--print("onActionBindingsChanged");
courseplay.inputBindings.updateInputButtonData();
end
end
InputDisplayManager.onActionBindingsChanged=Utils.appendedFunction(InputDisplayManager.onActionBindingsChanged, courseplay.onActionBindingsChanged);
functioncourseplay.inputBindings.updateInputButtonData()
-- print('updateInputButtonData()')
-- MOUSE
for_,inputNameTypeinipairs( { 'primary', 'secondary' } ) do
localinputName='COURSEPLAY_MOUSEACTION_' ..inputNameType:upper();
localaction=g_inputBinding:getActionByName(inputName);
localmouseButtonName="MOUSE_BUTTON_NONE";
localmouseInputDisplayText;
forindex, bindinginipairs(action.bindings) do
ifbinding.isMouseandmouseButtonName=="MOUSE_BUTTON_NONE" then
mouseButtonName=binding.axisNames[1];
mouseInputDisplayText=MouseHelper.getInputDisplayText(binding.axisNames);
end
end
-- print(('\t%s: inputName=%q'):format(inputNameType, inputName));
localtxt;
iftonumber(mouseInputDisplayText) then
txt=g_i18n:getText('COURSEPLAY_MOUSE_BUTTON_NR'):format(tonumber(mouseInputDisplayText));
elseiftype(mouseInputDisplayText) =="string" andg_i18n.texts[("COURSEPLAY_MOUSE_BUTTON_%s"):format(mouseInputDisplayText:upper())] then
txt=g_i18n:getText(("COURSEPLAY_MOUSE_BUTTON_%s"):format(mouseInputDisplayText:upper()));
else
--- Should never happen but could happen if no mouse button was set.
txt=g_i18n:getText('UNKNOWN');
end
courseplay.inputBindings.mouse[inputNameType..'TextI18n'] =txt;
courseplay.inputBindings.mouse[inputNameType..'ButtonId'] =Input[mouseButtonName];
-- print(('\t\t%sTextI18n=%q, mouseButtonId=%d'):format(inputNameType, txt, mouseButtonId));
end;
end;