91 | function ConstructionScreen:onOpen() |
92 | ConstructionScreen:superClass().onOpen(self) |
93 | |
94 | -- Used for a basic undo feature |
95 | g_currentMission.lastConstructionScreenOpenTime = g_time |
96 | |
97 | self.inputManager:setContext(ConstructionScreen.INPUT_CONTEXT) |
98 | |
99 | self.camera:setTerrainRootNode(g_currentMission.terrainRootNode) |
100 | self.camera:setControlledPlayer(g_currentMission.player) |
101 | self.camera:setControlledVehicle(g_currentMission.controlledVehicle) |
102 | |
103 | self.camera:activate() |
104 | self.cursor:activate() |
105 | |
106 | g_currentMission.hud.ingameMap:setTopDownCamera(self.camera) |
107 | |
108 | -- Initial brush is always the selector |
109 | if self.selectorBrush == nil then |
110 | local class = g_constructionBrushTypeManager:getClassObjectByTypeName("select") |
111 | self.selectorBrush = class.new(nil, self.cursor) |
112 | end |
113 | self:setBrush(self.selectorBrush, true) |
114 | |
115 | if self.destructBrush == nil then |
116 | local class = g_constructionBrushTypeManager:getClassObjectByTypeName("destruct") |
117 | self.destructBrush = class.new(nil, self.cursor) |
118 | end |
119 | self.destructMode = false |
120 | |
121 | -- We need to know when mouse/gamepad changes |
122 | self.isMouseMode = self.inputManager.lastInputMode == GS_INPUT_HELP_MODE_KEYBOARD |
123 | self.messageCenter:subscribe(MessageType.INPUT_MODE_CHANGED, self.onInputModeChanged, self) |
124 | |
125 | -- Initial blur |
126 | g_depthOfFieldManager:pushArea(self.menuBox.absPosition[1], self.menuBox.absPosition[2], self.menuBox.absSize[1], self.menuBox.absSize[2]) |
127 | |
128 | -- TODO: only load once every mission |
129 | self:rebuildData() |
130 | |
131 | self:resetMenuState() |
132 | self:updateMenuState() |
133 | |
134 | self.messageCenter:subscribe(MessageType.SLOT_USAGE_CHANGED, self.onSlotUsageChanged, self) |
135 | end |
411 | function ConstructionScreen:registerBrushActionEvents() |
412 | local _, eventId |
413 | |
414 | local brush = self.brush |
415 | if brush == nil then |
416 | return |
417 | end |
418 | |
419 | self.brushEvents = {} |
420 | |
421 | -- We need primary button also to select objects without brush |
422 | if brush.supportsPrimaryButton then |
423 | if brush.supportsPrimaryDragging then |
424 | _, eventId = self.inputManager:registerActionEvent(InputAction.CONSTRUCTION_ACTION_PRIMARY, self, self.onButtonPrimaryDrag, true, true, true, true) |
425 | table.insert(self.brushEvents, eventId) |
426 | |
427 | self.primaryBrushEvent = eventId |
428 | else |
429 | _, eventId = self.inputManager:registerActionEvent(InputAction.CONSTRUCTION_ACTION_PRIMARY, self, self.onButtonPrimary, false, true, false, true) |
430 | table.insert(self.brushEvents, eventId) |
431 | |
432 | self.primaryBrushEvent = eventId |
433 | end |
434 | |
435 | self.inputManager:setActionEventTextPriority(eventId, GS_PRIO_VERY_HIGH) |
436 | end |
437 | |
438 | if brush.supportsSecondaryButton then |
439 | if brush.supportsSecondaryDragging then |
440 | _, eventId = self.inputManager:registerActionEvent(InputAction.CONSTRUCTION_ACTION_SECONDARY, self, self.onButtonSecondaryDrag, true, true, true, true) |
441 | table.insert(self.brushEvents, eventId) |
442 | |
443 | self.secondaryBrushEvent = eventId |
444 | else |
445 | _, eventId = self.inputManager:registerActionEvent(InputAction.CONSTRUCTION_ACTION_SECONDARY, self, self.onButtonSecondary, false, true, false, true) |
446 | table.insert(self.brushEvents, eventId) |
447 | |
448 | self.secondaryBrushEvent = eventId |
449 | end |
450 | |
451 | self.inputManager:setActionEventTextPriority(eventId, GS_PRIO_VERY_HIGH) |
452 | end |
453 | |
454 | if brush.supportsTertiaryButton then |
455 | _, self.tertiaryBrushEvent = self.inputManager:registerActionEvent(InputAction.CONSTRUCTION_ACTION_TERTIARY, self, self.onButtonTertiary, false, true, false, true) |
456 | self.inputManager:setActionEventTextPriority(self.tertiaryBrushEvent, GS_PRIO_HIGH) |
457 | table.insert(self.brushEvents, self.tertiaryBrushEvent) |
458 | end |
459 | |
460 | if brush.supportsFourthButton then |
461 | _, self.fourthBrushEvent = self.inputManager:registerActionEvent(InputAction.CONSTRUCTION_ACTION_FOURTH, self, self.onButtonFourth, false, true, false, true) |
462 | self.inputManager:setActionEventTextPriority(self.fourthBrushEvent, GS_PRIO_HIGH) |
463 | table.insert(self.brushEvents, self.fourthBrushEvent) |
464 | end |
465 | |
466 | -- Action axis: trigger on down. They are step-based axis or continuous, defined by the brush. |
467 | |
468 | if brush.supportsPrimaryAxis then |
469 | _, self.primaryBrushAxisEvent = self.inputManager:registerActionEvent(InputAction.AXIS_CONSTRUCTION_ACTION_PRIMARY, self, self.onAxisPrimary, false, not brush.primaryAxisIsContinuous, brush.primaryAxisIsContinuous, true) |
470 | self.inputManager:setActionEventTextPriority(self.primaryBrushAxisEvent, GS_PRIO_HIGH) |
471 | table.insert(self.brushEvents, self.primaryBrushAxisEvent) |
472 | end |
473 | |
474 | if brush.supportsSecondaryAxis then |
475 | _, self.secondaryBrushAxisEvent = self.inputManager:registerActionEvent(InputAction.AXIS_CONSTRUCTION_ACTION_SECONDARY, self, self.onAxisSecondary, false, not brush.secondaryAxisIsContinuous, brush.secondaryAxisIsContinuous, true) |
476 | self.inputManager:setActionEventTextPriority(self.secondaryBrushAxisEvent, GS_PRIO_HIGH) |
477 | table.insert(self.brushEvents, self.secondaryBrushAxisEvent) |
478 | end |
479 | end |