562 | function InputHelpDisplay:animateShow() |
563 | HUDDisplayElement:superClass().setVisible(self, true) |
564 | |
565 | local transX, transY = self:getHidingTranslation() |
566 | |
567 | local sequence = TweenSequence.new(self) |
568 | local moveIn = MultiValueTween:new(self.setAnimationOffset, {transX, transY}, {0, 0}, HUDDisplayElement.MOVE_ANIMATION_DURATION) |
569 | local unfoldEntries = Tween:new(self.setAnimationAvailableHeight, 0, self:getAvailableHeight(), HUDDisplayElement.MOVE_ANIMATION_DURATION) |
570 | |
571 | sequence:addTween(moveIn) |
572 | sequence:addTween(unfoldEntries) |
573 | sequence:addCallback(self.onAnimateVisibilityFinished, true) |
574 | |
575 | sequence:start() |
576 | self.animation = sequence |
577 | end |
294 | function InputHelpDisplay:collectVehicleTypesAndSpecializations(vehicleTypes, specs, depth, vehicle, rootVehicle) |
295 | if vehicle.getAttachedImplements == nil then |
296 | return |
297 | end |
298 | |
299 | vehicleTypes[vehicle] = vehicle.typeName |
300 | |
301 | local vehicleSpecs = specs[vehicle] |
302 | if not vehicleSpecs then |
303 | vehicleSpecs = {} |
304 | specs[vehicle] = vehicleSpecs |
305 | end |
306 | |
307 | for _, v in pairs(vehicle.specializations) do |
308 | table.insert(vehicleSpecs, v) |
309 | end |
310 | |
311 | local attachedImplements = vehicle:getAttachedImplements() |
312 | |
313 | for _, implement in pairs(attachedImplements) do |
314 | local attached = implement.object |
315 | if attached ~= nil and attached.specializations ~= nil and depth <= 3 then |
316 | self:collectVehicleTypesAndSpecializations(vehicleTypes, specs, depth + 1, attached, rootVehicle) |
317 | end |
318 | end |
319 | end |
917 | function InputHelpDisplay:createComboHeader(hudAtlasPath, frameX, frameY, combos, boxSize, separatorPositions) |
918 | local width, height = self:scalePixelToScreenVector(InputHelpDisplay.SIZE.HEADER) |
919 | local posY = frameY - height |
920 | local bgOverlay = Overlay:new(nil, frameX, posY, width, height) |
921 | local headerElement = HUDElement:new(bgOverlay) |
922 | |
923 | local glyphWidth, glyphHeight = self:scalePixelToScreenVector(InputHelpDisplay.SIZE.COMBO_GLYPH) |
924 | local boxWidth, boxHeight = self:scalePixelToScreenVector(boxSize) |
925 | local count = 0 |
926 | for i, combo in ipairs(combos) do |
927 | local actionName = combo.controls |
928 | local glyphElement = self:createComboInputGlyph(0, 0, glyphWidth, glyphHeight, actionName) |
929 | local glyphWidth = glyphElement:getGlyphWidth() -- get modified width based on action |
930 | |
931 | local glyphPosX = frameX + boxWidth * count + (boxWidth - glyphWidth) * 0.5 |
932 | local glyphPosY = posY + (boxHeight - glyphHeight) * 0.5 |
933 | |
934 | -- align left and right outer combo icons with help entry icons |
935 | if i == 1 then -- leftmost |
936 | local offX = self:scalePixelToScreenWidth(InputHelpDisplay.POSITION.INPUT_GLYPH[1]) |
937 | glyphPosX = frameX + offX |
938 | elseif i == #combos then -- rightmost |
939 | local offX = self:scalePixelToScreenWidth(InputHelpDisplay.POSITION.AXIS_ICON[1]) - glyphWidth |
940 | glyphPosX = frameX + boxWidth * i + offX |
941 | end |
942 | |
943 | glyphElement:setPosition(glyphPosX, glyphPosY) |
944 | headerElement:addChild(glyphElement) |
945 | |
946 | self.comboInputGlyphs[actionName] = glyphElement -- store by action name for visibility changes |
947 | |
948 | if count > 0 and count <= #separatorPositions then |
949 | local sepX, sepY = self:scalePixelToScreenVector(separatorPositions[count]) |
950 | sepY = sepY + boxHeight * 0.5 |
951 | |
952 | local separator = self:createVerticalSeparator(hudAtlasPath, frameX + sepX, posY + sepY) |
953 | headerElement:addChild(separator) |
954 | end |
955 | |
956 | count = count + 1 |
957 | end |
958 | |
959 | local separator = self:createHorizontalSeparator(hudAtlasPath, frameX, posY) |
960 | headerElement:addChild(separator) |
961 | |
962 | return headerElement |
963 | end |
841 | function InputHelpDisplay:createComponents(hudAtlasPath) |
842 | local baseWidth, baseHeight = getNormalizedScreenValues(unpack(InputHelpDisplay.SIZE.HELP_ENTRY)) |
843 | |
844 | local baseX, baseY = self:getPosition() |
845 | local frame = self:createFrame(hudAtlasPath, baseX, baseY, baseWidth, baseHeight) |
846 | |
847 | local maxEntries = self:getMaxEntryCount() |
848 | local frameX, frameY = frame:getPosition() |
849 | self:createEntries(hudAtlasPath, frameX, frameY, maxEntries) |
850 | |
851 | self:createMouseComboHeader(hudAtlasPath, frameX, frameY) |
852 | self:createControllerComboHeader(hudAtlasPath, frameX, frameY) |
853 | end |
1011 | function InputHelpDisplay:createEntries(hudAtlasPath, frameX, frameY, count) |
1012 | local posX, posY = frameX, frameY |
1013 | local entryWidth, entryHeight = self:scalePixelToScreenVector(InputHelpDisplay.SIZE.HELP_ENTRY) |
1014 | |
1015 | local overlay = Overlay:new(nil, posX, posY, entryWidth, entryHeight * count) |
1016 | local entriesFrame = HUDElement:new(overlay) |
1017 | self.entriesFrame = entriesFrame |
1018 | self:addChild(entriesFrame) |
1019 | |
1020 | local totalHeight = count * entryHeight |
1021 | for i = 1, count do |
1022 | posY = frameY + totalHeight - entryHeight * i |
1023 | local entry = self:createEntry(hudAtlasPath, posX, posY, entryWidth, entryHeight) |
1024 | table.insert(self.entries, entry) |
1025 | table.insert(self.entryGlyphWidths, 0) |
1026 | entriesFrame:addChild(entry) |
1027 | |
1028 | -- add horizontal separator for all entries |
1029 | local sep = self:createHorizontalSeparator(hudAtlasPath, posX, posY) |
1030 | table.insert(self.horizontalSeparators, sep) |
1031 | entriesFrame:addChild(sep) |
1032 | end |
1033 | end |
987 | function InputHelpDisplay:createEntry(hudAtlasPath, posX, posY, width, height) |
988 | local overlay = Overlay:new(nil, posX, posY, width, height) |
989 | local entryElement = HUDElement:new(overlay) |
990 | |
991 | local glyphWidth, glyphHeight = self:scalePixelToScreenVector(InputHelpDisplay.SIZE.INPUT_GLYPH) |
992 | local offX, offY = self:scalePixelToScreenWidth(InputHelpDisplay.POSITION.INPUT_GLYPH[1]), (height - glyphHeight) * 0.5 |
993 | local glyphElement = InputGlyphElement:new(self.inputDisplayManager, glyphWidth, glyphHeight) |
994 | glyphElement:setPosition(posX + offX, posY + offY) |
995 | glyphElement:setKeyboardGlyphColor(InputHelpDisplay.COLOR.INPUT_GLYPH) |
996 | |
997 | entryElement:addChild(glyphElement) |
998 | table.insert(self.inputGlyphs, glyphElement) |
999 | |
1000 | return entryElement |
1001 | end |
658 | function InputHelpDisplay:drawHelpInfos() |
659 | local framePosX, framePosY = self.entriesFrame:getPosition() |
660 | local entriesHeight = self.entriesFrame:getHeight() |
661 | for i, helpElement in ipairs(self.visibleHelpElements) do |
662 | local entryPosY = framePosY + entriesHeight - i * self.entryHeight |
663 | if helpElement.iconOverlay ~= nil then |
664 | local posX = framePosX + self.entryWidth - self.axisIconWidth + self.axisIconOffsetX |
665 | local posY = entryPosY + self.entryHeight * 0.5 |
666 | |
667 | helpElement.iconOverlay:setPosition(posX, posY) |
668 | helpElement.iconOverlay:setDimension(self.axisIconWidth, self.axisIconHeight) |
669 | helpElement.iconOverlay:render() |
670 | else |
671 | setTextBold(false) |
672 | setTextColor(unpack(InputHelpDisplay.COLOR.HELP_TEXT)) |
673 | |
674 | local text = "" |
675 | local textWidth = 0 |
676 | local posX, posY = framePosX, entryPosY |
677 | local textLeftX = 1 |
678 | if helpElement.textRight ~= "" then |
679 | setTextAlignment(RenderText.ALIGN_RIGHT) |
680 | text = helpElement.textRight |
681 | textWidth = getTextWidth(self.helpTextSize, text) |
682 | posX = posX + self.entryWidth + self.helpTextOffsetX |
683 | posY = posY + (self.entryHeight - self.helpTextSize) * 0.5 + self.helpTextOffsetY |
684 | textLeftX = posX - textWidth |
685 | elseif helpElement.textLeft ~= "" then |
686 | setTextAlignment(RenderText.ALIGN_LEFT) |
687 | text = helpElement.textLeft |
688 | posX = posX + self.extraTextOffsetX |
689 | posY = posY + (self.entryHeight - self.helpTextSize) * 0.5 + self.extraTextOffsetY |
690 | textLeftX = posX |
691 | end |
692 | |
693 | -- check glyph width and re-align text if necessary |
694 | local glyphWidth = self.entryGlyphWidths[i] or 0 -- 0 -> no glyph to display for this entry |
695 | local glyphLeftX, _ = glyphWidth ~= 0 and self.inputGlyphs[i]:getPosition() or 0 |
696 | local glyphRightX = glyphLeftX + glyphWidth |
697 | |
698 | if glyphRightX < textLeftX then |
699 | renderText(posX, posY, self.helpTextSize, text) |
700 | else |
701 | -- distribute text over two lines |
702 | local availableTextWidth = posX - glyphRightX - math.abs(self.helpTextOffsetX) |
703 | setTextWrapWidth(availableTextWidth) |
704 | setTextLineBounds(0, 2) -- start at first line (engine zero-indexed), for two lines |
705 | |
706 | -- center posY again when using two lines |
707 | posY = entryPosY + self.entryHeight * 0.5 + self.helpTextOffsetY |
708 | renderText(posX, posY, self.helpTextSize, text) |
709 | |
710 | -- reset uncommon text rendering state: |
711 | setTextWrapWidth(0) |
712 | setTextLineBounds(0, 0) |
713 | end |
714 | end |
715 | end |
716 | end |
720 | function InputHelpDisplay:drawVehicleHUDExtensions() |
721 | if self.extensionsHeight > 0 then |
722 | local leftPosX = self:getPosition() |
723 | local width = self:getWidth() |
724 | local posY = self.extensionsStartY |
725 | local usedHeight = 0 |
726 | for _, extension in pairs(self.vehicleHudExtensions) do |
727 | local extHeight = extension:getDisplayHeight() |
728 | if extension:canDraw() and usedHeight + extHeight <= self.extensionsHeight then |
729 | posY = extension:draw(leftPosX + self.extraTextOffsetX, leftPosX + width + self.helpTextOffsetX, posY) |
730 | usedHeight = usedHeight + extHeight |
731 | end |
732 | end |
733 | end |
734 | end |
473 | function InputHelpDisplay:getInputHelpElements(availableHeight, pressedComboMaskGamepad, pressedComboMaskMouse, useGamepadButtons) |
474 | local currentPressedMask = useGamepadButtons and pressedComboMaskGamepad or pressedComboMaskMouse |
475 | local isCombo = currentPressedMask ~= 0 |
476 | local isFillUp = false |
477 | local usedPressedMask = currentPressedMask |
478 | |
479 | local eventHelpElements = self.inputDisplayManager:getEventHelpElements(currentPressedMask, useGamepadButtons) |
480 | if #eventHelpElements == 0 and not self.hasComboCommands and isCombo then |
481 | -- just load the base input list without modifier (pressed mask == 0) |
482 | eventHelpElements = self.inputDisplayManager:getEventHelpElements(0, useGamepadButtons) |
483 | isFillUp = true |
484 | usedPressedMask = 0 |
485 | end |
486 | |
487 | self.currentHelpElementCount = #eventHelpElements |
488 | local helpElements = {} |
489 | |
490 | local usedHeight = 0 |
491 | local i = 1 |
492 | while usedHeight + self.entryHeight <= availableHeight and i <= #eventHelpElements do |
493 | if not self:getIsHelpElementAllowed(helpElements, eventHelpElements[i]) then |
494 | break |
495 | end |
496 | |
497 | table.insert(helpElements, eventHelpElements[i]) |
498 | usedHeight = usedHeight + self.entryHeight |
499 | i = i + 1 |
500 | end |
501 | |
502 | local contextCustomElements = self.customHelpElements[self.inputManager:getContextName()] |
503 | if contextCustomElements ~= nil then |
504 | self.currentHelpElementCount = self.currentHelpElementCount + #contextCustomElements |
505 | |
506 | i = 1 |
507 | while usedHeight + self.entryHeight <= availableHeight and i <= #contextCustomElements do |
508 | local customHelpElement = contextCustomElements[i] |
509 | -- display custom element if bindings and controller symbols could be resolved, otherwise a null-element is |
510 | -- returned which we test against: |
511 | if customHelpElement ~= InputDisplayManager.NO_HELP_ELEMENT then |
512 | local action = self.inputManager:getActionByName(customHelpElement.actionName) |
513 | if action ~= nil then |
514 | local fitsComboMask = action.comboMaskGamepad == pressedComboMaskGamepad and action.comboMaskMouse == pressedComboMaskMouse |
515 | local noComboFillUp = action.comboMaskGamepad == 0 and action.comboMaskMouse == 0 and isFillUp |
516 | |
517 | if fitsComboMask or noComboFillUp then |
518 | table.insert(helpElements, customHelpElement) |
519 | usedHeight = usedHeight + self.entryHeight |
520 | end |
521 | end |
522 | end |
523 | |
524 | i = i + 1 |
525 | end |
526 | end |
527 | |
528 | return helpElements, usedHeight, usedPressedMask |
529 | end |
28 | function InputHelpDisplay.new(hudAtlasPath, messageCenter, inputManager, inputDisplayManager, ingameMap, communicationDisplay, ingameMessage, isConsoleVersion) |
29 | local backgroundOverlay = InputHelpDisplay.createBackground() |
30 | local self = InputHelpDisplay:superClass().new(InputHelpDisplay_mt, backgroundOverlay, nil) |
31 | |
32 | self.messageCenter = messageCenter |
33 | self.inputManager = inputManager |
34 | self.inputDisplayManager = inputDisplayManager |
35 | self.ingameMap = ingameMap |
36 | self.communicationDisplay = communicationDisplay |
37 | self.ingameMessage = ingameMessage |
38 | self.isConsoleVersion = isConsoleVersion |
39 | |
40 | self.isOverlayMenuVisible = false |
41 | |
42 | self.controlsLabelText = utf8ToUpper(g_i18n:getText(InputHelpDisplay.L10N_CONTROLS_LABEL)) |
43 | |
44 | self.vehicle = nil -- currently controlled vehicle |
45 | self.vehicleTypesBuffer = {} -- vehicle -> vehicleTypeName |
46 | self.vehicleSpecializationsBuffer = {} -- vehicle -> specializations |
47 | self.vehicleHudExtensions = {} -- known and active vehicle HUD extensions, specialization -> extension |
48 | |
49 | self.extraHelpTexts = {} |
50 | self.currentAvailableHeight = 0 |
51 | |
52 | self.comboInputGlyphs = {} -- actionName -> InputGlyphElement |
53 | self.entries = {} -- array of HUDElement |
54 | self.entryGlyphWidths = {} -- array of float -> synchronous with self.entries, stores the currently required glyph width |
55 | self.inputGlyphs = {} -- array of InputGlyphElement, synchronous with self.entries |
56 | self.horizontalSeparators = {} -- array of HUDElement |
57 | self.frame = nil -- HUDFrameElement for the background frame |
58 | self.entriesFrame = nil -- HUDElement which holds all help entries for repositioning |
59 | self.mouseComboHeader = nil |
60 | self.gamepadComboHeader = nil |
61 | self.customHelpElements = {} -- array of InputHelpElement |
62 | |
63 | self.headerHeight = 0 |
64 | self.entryWidth, self.entryHeight = 0, 0 |
65 | self.controlsLabelTextSize = 0 |
66 | self.controlsLabelOffsetX, self.controlsLabelOffsetY = 0, 0 |
67 | self.helpTextSize = 0 |
68 | self.helpTextOffsetX, self.helpTextOffsetY = 0, 0 |
69 | self.extraTextOffsetX, self.extraTextOffsetY = 0, 0 |
70 | self.axisIconOffsetX = 0 |
71 | self.axisIconWidth, self.axisIconHeight = 0, 0 |
72 | self.frameOffsetX, self.frameOffsetY = 0, 0 |
73 | self.frameBarOffsetY = 0 |
74 | |
75 | self.hasComboCommands = false |
76 | self.visibleHelpElements = {} -- current frame help elements |
77 | self.currentHelpElementCount = 0 -- maximum number of help elements which are currently active |
78 | self.requireHudExtensionsRefresh = false |
79 | self.numUsedEntries = 0 -- number of used entries in the current frame |
80 | self.extensionsHeight = 0 -- screen height of active HUDExensions in the current frame |
81 | self.extensionsStartY = 0 -- start Y position of vehicle extensions |
82 | self.comboIterator = {} |
83 | |
84 | self.animationEntryCount = 0 |
85 | self.animationAvailableHeight = math.huge |
86 | self.animationOffsetX = 0 |
87 | self.animationOffsetY = 0 |
88 | |
89 | self:createComponents(hudAtlasPath) |
90 | self:subscribeMessages() |
91 | |
92 | return self |
93 | end |
588 | function InputHelpDisplay:onInputDevicesChanged() |
589 | for _, combos in pairs{InputBinding.ORDERED_MOUSE_COMBOS, InputBinding.ORDERED_GAMEPAD_COMBOS} do |
590 | for i, combo in ipairs(combos) do |
591 | local actionName = combo.controls |
592 | local glyphElement = self.comboInputGlyphs[actionName] |
593 | local prevWidth = glyphElement:getGlyphWidth() |
594 | glyphElement:setAction(actionName, nil, nil, false, true) -- no action text, use combo buttons, make copies of overlays |
595 | local glyphWidth = glyphElement:getGlyphWidth() -- get modified width based on action |
596 | |
597 | -- reposition glyphs |
598 | if prevWidth ~= glyphWidth then |
599 | if i > 1 then -- first (left) glyph is always correctly aligned, no correction needed |
600 | local posX, posY = glyphElement:getPosition() |
601 | if i == #combos then |
602 | posX = posX + prevWidth - glyphWidth |
603 | else |
604 | posX = posX + (prevWidth - glyphWidth) * 0.5 |
605 | end |
606 | |
607 | glyphElement:setPosition(posX, posY) |
608 | end |
609 | end |
610 | end |
611 | end |
612 | end |
241 | function InputHelpDisplay:refreshHUDExtensions() |
242 | for k, hudExtension in pairs(self.vehicleHudExtensions) do |
243 | hudExtension:delete() |
244 | self.vehicleHudExtensions[k] = nil |
245 | end |
246 | |
247 | local uiScale = self:getScale() |
248 | for vehicle, specs in pairs(self.vehicleSpecializationsBuffer) do |
249 | for _, spec in pairs(specs) do |
250 | local hudExtension = self.vehicleHudExtensions[spec] |
251 | if hudExtension == nil and VehicleHUDExtension.hasHUDExtensionForSpecialization(spec) then |
252 | hudExtension = VehicleHUDExtension.createHUDExtensionForSpecialization(spec, vehicle, uiScale, |
253 | InputHelpDisplay.COLOR.HELP_TEXT, self.helpTextSize) |
254 | self.vehicleHudExtensions[spec] = hudExtension |
255 | end |
256 | end |
257 | end |
258 | end |
750 | function InputHelpDisplay:storeScaledValues() |
751 | self.headerHeight = self:scalePixelToScreenHeight(InputHelpDisplay.SIZE.HEADER[2]) |
752 | self.entryWidth, self.entryHeight = self:scalePixelToScreenVector(InputHelpDisplay.SIZE.HELP_ENTRY) |
753 | self.controlsLabelTextSize = self:scalePixelToScreenHeight(HUDElement.TEXT_SIZE.DEFAULT_TITLE) |
754 | self.controlsLabelOffsetX, self.controlsLabelOffsetY = self:scalePixelToScreenVector(InputHelpDisplay.POSITION.CONTROLS_LABEL) |
755 | self.helpTextSize = self:scalePixelToScreenHeight(HUDElement.TEXT_SIZE.DEFAULT_TEXT) |
756 | self.helpTextOffsetX, self.helpTextOffsetY = self:scalePixelToScreenVector(InputHelpDisplay.POSITION.HELP_TEXT) |
757 | self.extraTextOffsetX, self.extraTextOffsetY = self:scalePixelToScreenVector(InputHelpDisplay.POSITION.EXTRA_TEXT) |
758 | self.axisIconOffsetX = self:scalePixelToScreenWidth(InputHelpDisplay.POSITION.AXIS_ICON[1]) |
759 | self.axisIconWidth, self.axisIconHeight = self:scalePixelToScreenVector(InputHelpDisplay.SIZE.AXIS_ICON) |
760 | self.frameOffsetX, self.frameOffsetY = self:scalePixelToScreenVector(InputHelpDisplay.POSITION.FRAME) |
761 | self.frameBarOffsetY = self:scalePixelToScreenHeight(HUDFrameElement.THICKNESS.BAR) |
762 | self.minimumMapSpacingY = self:scalePixelToScreenHeight(InputHelpDisplay.MIN_MAP_SPACING) |
763 | end |
441 | function InputHelpDisplay:updateComboInputGlyphs(comboActionStatus, pressedComboMaskMouse, pressedComboMaskGamepad) |
442 | self.comboIterator[InputBinding.MOUSE_COMBOS] = pressedComboMaskMouse |
443 | self.comboIterator[InputBinding.GAMEPAD_COMBOS] = pressedComboMaskGamepad |
444 | |
445 | -- apply visibility settings to combo buttons |
446 | for actionCombos, pressedComboMask in pairs(self.comboIterator) do |
447 | for actionName, comboData in pairs(actionCombos) do |
448 | local comboGlyph = self.comboInputGlyphs[actionName] |
449 | if comboActionStatus[actionName] then |
450 | comboGlyph:setVisible(true) |
451 | |
452 | local isPressed = bitAND(pressedComboMask, comboData.mask) ~= 0 |
453 | if isPressed then |
454 | comboGlyph:setButtonGlyphColor(InputHelpDisplay.COLOR.COMBO_GLYPH_PRESSED) |
455 | else |
456 | comboGlyph:setButtonGlyphColor(InputHelpDisplay.COLOR.COMBO_GLYPH) |
457 | end |
458 | else |
459 | comboGlyph:setVisible(false) |
460 | end |
461 | end |
462 | end |
463 | end |
378 | function InputHelpDisplay:updateEntries(helpElements, pressedComboMaskGamepad) |
379 | local usedCount = 0 |
380 | |
381 | local entryCount = #self.entries |
382 | local separatorCount = math.min(#helpElements - 1, entryCount - 1) |
383 | if self.extensionsHeight > 0 and not self.ingameMap:getIsFullSize() then |
384 | separatorCount = separatorCount + 1 |
385 | end |
386 | |
387 | for i = 1, entryCount do |
388 | local entry = self.entries[i] |
389 | if i <= #helpElements then |
390 | usedCount = usedCount + 1 |
391 | entry:setVisible(#helpElements[i].buttons > 0 or #helpElements[i].keys > 0) |
392 | |
393 | local helpElement = helpElements[i] |
394 | if helpElement.actionName ~= "" then |
395 | if helpElement.actionName2 ~= "" then |
396 | self.inputGlyphs[i]:setActions({helpElement.actionName, helpElement.actionName2}, nil, nil, helpElement.inlineModifierButtons, nil, pressedComboMaskGamepad) |
397 | else |
398 | self.inputGlyphs[i]:setAction(helpElement.actionName, nil, nil, helpElement.inlineModifierButtons, nil, pressedComboMaskGamepad) -- no action text, do not show combo buttons |
399 | end |
400 | |
401 | self.entryGlyphWidths[i] = self.inputGlyphs[i]:getGlyphWidth() |
402 | else |
403 | self.entryGlyphWidths[i] = 0 |
404 | end |
405 | else |
406 | entry:setVisible(false) |
407 | end |
408 | end |
409 | |
410 | for i = 1, #self.horizontalSeparators do |
411 | local separator = self.horizontalSeparators[i] |
412 | separator:setVisible(i <= separatorCount) |
413 | end |
414 | |
415 | self.numUsedEntries = usedCount |
416 | end |
262 | function InputHelpDisplay:updateHUDExtensions() |
263 | if self.vehicle ~= nil then -- update HUD extensions, can change when implements are attached / detached |
264 | local prevHash = getVehicleTypeHash(self.vehicleTypesBuffer) |
265 | |
266 | clearTable(self.vehicleTypesBuffer) |
267 | clearTable(self.vehicleSpecializationsBuffer) |
268 | self:collectVehicleTypesAndSpecializations(self.vehicleTypesBuffer, self.vehicleSpecializationsBuffer, 1, self.vehicle, self.vehicle) |
269 | |
270 | local currentHash = getVehicleTypeHash(self.vehicleTypesBuffer) |
271 | if prevHash ~= currentHash then |
272 | self.requireHudExtensionsRefresh = true |
273 | end |
274 | end |
275 | |
276 | if self.requireHudExtensionsRefresh then |
277 | self:refreshHUDExtensions() |
278 | self.requireHudExtensionsRefresh = false |
279 | end |
280 | |
281 | local extensionsHeight = 0 |
282 | for _, hudExtension in pairs(self.vehicleHudExtensions) do |
283 | local height = hudExtension:getDisplayHeight() |
284 | if hudExtension:canDraw() and extensionsHeight + height <= self.currentAvailableHeight then |
285 | extensionsHeight = extensionsHeight + height |
286 | end |
287 | end |
288 | |
289 | self.extensionsHeight = extensionsHeight |
290 | end |
338 | function InputHelpDisplay:updateInputContext() |
339 | local availableHeight = self:getAvailableHeight() |
340 | if not self.animation:getFinished() then |
341 | availableHeight = math.min(availableHeight, self.animationAvailableHeight) |
342 | end |
343 | |
344 | local pressedComboMaskGamepad, pressedComboMaskMouse, pressedComboMaskFarmWheel = self.inputManager:getComboCommandPressedMask() |
345 | local useGamepadButtons = self.isConsoleVersion or (self.inputManager:getInputHelpMode() == GS_INPUT_HELP_MODE_GAMEPAD) |
346 | |
347 | if GS_PLATFORM_TYPE == GS_PLATFORM_TYPE_PS4 then |
348 | pressedComboMaskGamepad = math.max(pressedComboMaskGamepad, pressedComboMaskFarmWheel) |
349 | end |
350 | |
351 | self:updateComboHeaders(useGamepadButtons, pressedComboMaskMouse, pressedComboMaskGamepad) |
352 | if self.hasComboCommands then |
353 | availableHeight = availableHeight - self.headerHeight |
354 | end |
355 | |
356 | local helpElements, usedHeight, usedPressedMask = self:getInputHelpElements(availableHeight, pressedComboMaskGamepad, pressedComboMaskMouse, useGamepadButtons) |
357 | self.visibleHelpElements = helpElements |
358 | availableHeight = availableHeight - usedHeight |
359 | |
360 | for _, text in pairs(self.extraHelpTexts) do |
361 | if availableHeight - self.entryHeight >= 0 then |
362 | local extraTextHelpElement = InputHelpElement.new(nil, nil, nil, nil, nil, text) |
363 | table.insert(helpElements, extraTextHelpElement) |
364 | availableHeight = availableHeight - self.entryHeight |
365 | else |
366 | break |
367 | end |
368 | end |
369 | |
370 | self:updateEntries(helpElements, usedPressedMask) |
371 | self.currentAvailableHeight = availableHeight -- store remainder for dynamic components (e.g. HUD extensions) |
372 | end |
205 | function InputHelpDisplay:updateSizeAndPositions() |
206 | local totalSize = - self.frameOffsetY |
207 | |
208 | local baseX, baseTopY = self:getTopLeftPosition() |
209 | local frameX, frameTopY = baseX + self.frameOffsetX, baseTopY + self.frameOffsetY |
210 | local entriesHeight = self.entriesFrame:getHeight() |
211 | local entriesPosY = frameTopY - entriesHeight |
212 | |
213 | if self.hasComboCommands then |
214 | totalSize = totalSize + self.headerHeight |
215 | entriesPosY = entriesPosY - self.headerHeight |
216 | end |
217 | |
218 | totalSize = totalSize + self.numUsedEntries * self.entryHeight |
219 | self.extensionsStartY = frameTopY - totalSize -- store the extensions starting Y position for drawing |
220 | |
221 | totalSize = totalSize + self.extensionsHeight |
222 | |
223 | self:setDimension(self:getWidth(), totalSize) |
224 | self:setPosition(baseX, baseTopY - totalSize) |
225 | |
226 | if self:getVisible() and not self.animation:getFinished() then |
227 | self:storeOriginalPosition() |
228 | end |
229 | |
230 | -- need to adjust header positions to keep them anchored to top left |
231 | self.mouseComboHeader:setPosition(frameX, frameTopY - self.headerHeight) |
232 | self.gamepadComboHeader:setPosition(frameX, frameTopY - self.headerHeight) |
233 | |
234 | self.entriesFrame:setPosition(frameX, entriesPosY) -- moves up or down depending on header visibility |
235 | local frameHeight = self:getHeight() + self.frameOffsetY + self.frameBarOffsetY |
236 | self.frame:setPosition(frameX, frameTopY - frameHeight) |
237 | end |