295 | function ContextActionDisplay:createActionIcons(hudAtlasPath, baseX, baseY) |
296 | local posX, posY = getNormalizedScreenValues(unpack(ContextActionDisplay.POSITION.CONTEXT_ICON)) |
297 | local width, height = getNormalizedScreenValues(unpack(ContextActionDisplay.SIZE.CONTEXT_ICON)) |
298 | |
299 | local centerY = baseY + (self:getHeight() - height) * 0.5 |
300 | |
301 | for _, iconName in pairs(ContextActionDisplay.CONTEXT_ICON) do |
302 | local iconOverlay = Overlay:new(hudAtlasPath, baseX + posX, centerY, width, height) |
303 | local uvs = ContextActionDisplay.UV[iconName] |
304 | iconOverlay:setUVs(getNormalizedUVs(uvs)) |
305 | iconOverlay:setColor(unpack(ContextActionDisplay.COLOR.CONTEXT_ICON)) |
306 | |
307 | local iconElement = HUDElement:new(iconOverlay) |
308 | iconElement:setVisible(false) |
309 | |
310 | self.contextIconElements[iconName] = iconElement |
311 | self:addChild(iconElement) |
312 | end |
313 | end |
271 | function ContextActionDisplay:createInputGlyph(hudAtlasPath, baseX, baseY, inputDisplayManager) |
272 | local width, height = getNormalizedScreenValues(unpack(ContextActionDisplay.SIZE.INPUT_ICON)) |
273 | local offX, offY = getNormalizedScreenValues(unpack(ContextActionDisplay.POSITION.INPUT_ICON)) |
274 | local element = InputGlyphElement:new(inputDisplayManager, width, height) |
275 | local posX, posY = baseX + offX, baseY + offY + (self:getHeight() - height) * 0.5 |
276 | |
277 | element:setPosition(posX, posY) |
278 | element:setKeyboardGlyphColor(ContextActionDisplay.COLOR.INPUT_ICON) |
279 | |
280 | self.inputGlyphElement = element |
281 | self:addChild(element) |
282 | end |
150 | function ContextActionDisplay:draw() |
151 | if self.contextAction ~= "" and self.contextEventHelpElement ~= nil then |
152 | self.inputGlyphElement:setAction(self.contextAction) -- updates input mode and glyphs if necessary |
153 | |
154 | local contextIconPosX, _ = self.inputGlyphElement:getPosition() |
155 | contextIconPosX = contextIconPosX + self.inputGlyphElement:getWidth() + self.contextIconOffsetX |
156 | for name, element in pairs(self.contextIconElements) do |
157 | element:setPosition(contextIconPosX, nil) -- no change to Y position |
158 | end |
159 | |
160 | ContextActionDisplay:superClass().draw(self) |
161 | local baseX, baseY = self:getPosition() |
162 | |
163 | setTextColor(unpack(ContextActionDisplay.COLOR.ACTION_TEXT)) |
164 | setTextBold(false) |
165 | setTextAlignment(RenderText.ALIGN_LEFT) |
166 | |
167 | local height = self:getHeight() |
168 | |
169 | local posX, posY = baseX + self.actionTextOffsetX, baseY + height + self.actionTextOffsetY |
170 | renderText(posX, posY, self.actionTextSize, self.actionText) |
171 | |
172 | posX = contextIconPosX + self.contextIconSizeX + self.targetTextOffsetX |
173 | posY = baseY + height*0.55 |
174 | setTextBold(true) |
175 | |
176 | local width = self:getWidth() |
177 | local textWrapWidth = width - self.targetTextOffsetX - self.contextIconSizeX - self.inputGlyphElement:getWidth() * 2 - self.contextIconOffsetX |
178 | |
179 | setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_MIDDLE) |
180 | setTextWrapWidth(textWrapWidth) |
181 | renderText(posX, posY, self.targetTextSize, self.targetText) |
182 | setTextWrapWidth(0) |
183 | |
184 | setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_BASELINE) |
185 | |
186 | if g_uiDebugEnabled then |
187 | local yPixel = 1 / g_screenHeight |
188 | setOverlayColor(GuiElement.debugOverlay, 0, 1, 1, 1) |
189 | renderOverlay(GuiElement.debugOverlay, posX, posY, textWrapWidth, yPixel) |
190 | end |
191 | end |
192 | end |
31 | function ContextActionDisplay.new(hudAtlasPath, inputDisplayManager) |
32 | local backgroundOverlay = ContextActionDisplay.createBackground() |
33 | local self = ContextActionDisplay:superClass().new(ContextActionDisplay_mt, backgroundOverlay, nil) |
34 | |
35 | self.uiScale = 1.0 |
36 | self.inputDisplayManager = inputDisplayManager |
37 | |
38 | self.inputGlyphElement = nil |
39 | |
40 | self.contextIconElements = {} |
41 | self.contextAction = "" |
42 | self.contextIconName = "" |
43 | self.targetText = "" |
44 | self.actionText = "" |
45 | self.contextPriority = -math.huge |
46 | |
47 | self.contextIconElementRightX = 0 |
48 | self.contextIconOffsetX, self.contextIconOffsetY = 0, 0 |
49 | self.contextIconSizeX = 0 |
50 | self.actionTextOffsetX, self.actionTextOffsetY = 0, 0 |
51 | self.actionTextSize = 0 |
52 | self.targetTextOffsetX, self.targetTextOffsetY = 0, 0 |
53 | self.targetTextSize = 0 |
54 | self.borderOffsetX = 0 |
55 | |
56 | self.displayTime = 0 |
57 | |
58 | self:createComponents(hudAtlasPath, inputDisplayManager) |
59 | |
60 | return self |
61 | end |
72 | function ContextActionDisplay:setContext(contextAction, contextIconName, targetText, priority, actionText) |
73 | if priority == nil then |
74 | priority = 0 |
75 | end |
76 | |
77 | if priority >= self.contextPriority and self.contextIconElements[contextIconName] ~= nil then |
78 | self.contextAction = contextAction |
79 | self.contextIconName = contextIconName |
80 | self.targetText = targetText |
81 | self.contextPriority = priority |
82 | |
83 | local eventHelpElement = self.inputDisplayManager:getEventHelpElementForAction(self.contextAction) |
84 | self.contextEventHelpElement = eventHelpElement |
85 | |
86 | if eventHelpElement ~= nil then |
87 | self.inputGlyphElement:setAction(contextAction) |
88 | self.actionText = actionText or eventHelpElement.textRight or eventHelpElement.textLeft |
89 | |
90 | local posX, _ = self.inputGlyphElement:getPosition() |
91 | posX = posX + self.inputGlyphElement:getWidth() + self.contextIconOffsetX |
92 | |
93 | for name, element in pairs(self.contextIconElements) do |
94 | element:setPosition(posX, nil) -- no change to Y position |
95 | end |
96 | end |
97 | |
98 | if not self:getVisible() then |
99 | self:setVisible(true, true) |
100 | end |
101 | |
102 | self.displayTime = ContextActionDisplay.MIN_DISPLAY_DURATION |
103 | end |
104 | |
105 | for name, element in pairs(self.contextIconElements) do |
106 | element:setVisible(name == self.contextIconName) |
107 | end |
108 | end |
200 | function ContextActionDisplay:setScale(uiScale) |
201 | ContextActionDisplay:superClass().setScale(self, uiScale, uiScale) |
202 | |
203 | local currentVisibility = self:getVisible() |
204 | self:setVisible(true, false) |
205 | |
206 | self.uiScale = uiScale |
207 | local posX, posY = ContextActionDisplay.getBackgroundPosition(uiScale, self:getWidth()) |
208 | self:setPosition(posX, posY) |
209 | |
210 | self:storeOriginalPosition() |
211 | self:setVisible(currentVisibility, false) |
212 | |
213 | self:storeScaledValues() |
214 | end |
218 | function ContextActionDisplay:storeScaledValues() |
219 | self.contextIconOffsetX, self.contextIconOffsetY = self:scalePixelToScreenVector(ContextActionDisplay.POSITION.CONTEXT_ICON) |
220 | self.contextIconSizeX = self:scalePixelToScreenWidth(ContextActionDisplay.SIZE.CONTEXT_ICON[1]) |
221 | self.borderOffsetX = self:scalePixelToScreenWidth(ContextActionDisplay.OFFSET.X) |
222 | |
223 | self.actionTextOffsetX, self.actionTextOffsetY = self:scalePixelToScreenVector(ContextActionDisplay.POSITION.ACTION_TEXT) |
224 | self.actionTextSize = self:scalePixelToScreenHeight(ContextActionDisplay.TEXT_SIZE.ACTION_TEXT) |
225 | |
226 | self.targetTextOffsetX, self.targetTextOffsetY = self:scalePixelToScreenVector(ContextActionDisplay.POSITION.TARGET_TEXT) |
227 | self.targetTextSize = self:scalePixelToScreenHeight(ContextActionDisplay.TEXT_SIZE.TARGET_TEXT) |
228 | end |
116 | function ContextActionDisplay:update(dt) |
117 | ContextActionDisplay:superClass().update(self, dt) |
118 | |
119 | self.displayTime = self.displayTime - dt |
120 | local isVisible = self:getVisible() |
121 | |
122 | if self.displayTime <= 0 and isVisible and self.animation:getFinished() then |
123 | self:setVisible(false, true) |
124 | end |
125 | |
126 | if not self.animation:getFinished() then |
127 | self:storeScaledValues() |
128 | elseif self.contextAction ~= "" and not isVisible then |
129 | self:resetContext() -- reset context data when move-out animation has finished |
130 | end |
131 | end |