Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ColorPickButtonElement
- ConstructionScreen
- ContextActionDisplay
- ControlBarDisplay
- DialogElement
- DynamicFadedBitmapElement
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GameInfoDisplayMobile
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiTopDownCursor
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDSliderElement
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InfoDisplay
- InfoHUDBox
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputGlyphElementUI
- InputHelpDisplay
- KeyValueInfoHUDBox
- ListElement
- ListItemElement
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PictureElement
- PlatformIconElement
- PlayerControlPadDisplay
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- ScrollingLayoutElement
- SettingsModel
- SideNotification
- SideNotificationMobile
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- SpeedSliderDisplay
- StatusBar
- SteeringSliderDisplay
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TerrainLayerElement
- TextBackdropElement
- TextElement
- TextInputElement
- ThreePartBitmapElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VariableWorkWidthHUDExten...
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- WardrobeScreen
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
IngameMap
DescriptionIn-game map display element. This class is used to display the game map both in the HUD as well as in the in-game menu.Parent
HUDElementFunctions
- addMapHotspot
- createBackground
- createComponents
- createToggleMapSizeGlyph
- delete
- determinePlayerPosition
- determineVehiclePosition
- drawHotspot
- drawLatencyToServer
- drawPlayersCoordinates
- getBackgroundPosition
- loadMap
- new
- removeMapHotspot
- resetSettings
- setAllowToggle
- setFullscreen
- setHotspotFilter
- setScale
- setSelectedHotspot
- setWorldSize
- storeScaledValues
- toggleSize
- updateHotspotFilters
addMapHotspot
DescriptionDefinitionaddMapHotspot()Code
325 | function IngameMap:addMapHotspot(mapHotspot) |
326 | table.insert(self.hotspots, mapHotspot) |
327 | |
328 | -- On mobile we sort spatially |
329 | if GS_IS_MOBILE_VERSION then |
330 | local mapSize = 1024 |
331 | table.sort(self.hotspots, function(v1, v2) |
332 | -- Split into 6 horizontal bands (must be an even number because map changes position based on the 0.5 split) |
333 | -- Sort horizontall within bands and vertically per band |
334 | |
335 | local band1 = math.ceil((v1.worldZ + mapSize * 0.5) / (mapSize * 0.16666)) |
336 | local band2 = math.ceil((v2.worldZ + mapSize * 0.5) / (mapSize * 0.16666)) |
337 | |
338 | if band1 == band2 then |
339 | return v1.worldX < v2.worldX or (v1.worldX == v2.worldX and v1.worldZ < v2.worldZ) |
340 | else |
341 | return (band1 - band2) < 0 |
342 | end |
343 | end) |
344 | else |
345 | table.sort(self.hotspots, function(v1, v2) return v1:getCategory() > v2:getCategory() end) |
346 | end |
347 | self.hotspotsSorted = nil |
348 | |
349 | return mapHotspot |
350 | end |
createBackground
DescriptionCreate the empty background overlay.Definition
createBackground()Code
750 | function IngameMap:createBackground(hudAtlasPath) |
751 | local width, height = getNormalizedScreenValues(unpack(IngameMap.SIZE.SELF)) |
752 | local posX, posY = self:getBackgroundPosition() |
753 | |
754 | local overlay = Overlay.new(hudAtlasPath, posX, posY, width, height) |
755 | overlay:setUVs(GuiUtils.getUVs(IngameMap.UV.BACKGROUND_ROUND)) |
756 | overlay:setColor(0,0,0,0.75) |
757 | |
758 | return overlay |
759 | end |
createComponents
DescriptionCreate required display components.Definition
createComponents(string hudAtlasPath)Arguments
string | hudAtlasPath | Path to the HUD texture atlas |
764 | function IngameMap:createComponents(hudAtlasPath) |
765 | local baseX, baseY = self:getPosition() |
766 | local width, height = self:getWidth(), self:getHeight() |
767 | |
768 | self:createToggleMapSizeGlyph(hudAtlasPath, baseX, baseY, width, height) |
769 | end |
createToggleMapSizeGlyph
DescriptionCreate the input glyph for map size toggling.Definition
createToggleMapSizeGlyph()Code
773 | function IngameMap:createToggleMapSizeGlyph(hudAtlasPath, baseX, baseY, baseWidth, baseHeight) |
774 | local width, height = getNormalizedScreenValues(unpack(IngameMap.SIZE.INPUT_ICON)) |
775 | local offX, offY = getNormalizedScreenValues(unpack(IngameMap.POSITION.INPUT_ICON)) |
776 | |
777 | local element = InputGlyphElement.new(self.inputDisplayManager, width, height) |
778 | local posX, posY = baseX + offX, baseY + offY |
779 | |
780 | element:setPosition(posX, posY) |
781 | element:setKeyboardGlyphColor(IngameMap.COLOR.INPUT_ICON) |
782 | element:setAction(InputAction.TOGGLE_MAP_SIZE) |
783 | |
784 | self.toggleMapSizeGlyph = element |
785 | self:addChild(element) |
786 | end |
delete
DescriptionDelete this element and all of its components.Definition
delete()Code
106 | function IngameMap:delete() |
107 | IngameMap:superClass().delete(self) |
108 | |
109 | g_inputBinding:removeActionEventsByTarget(self) |
110 | |
111 | self.mapElement:delete() |
112 | self:setSelectedHotspot(nil) |
113 | |
114 | for _, layout in ipairs(self.layouts) do |
115 | layout:delete() |
116 | end |
117 | |
118 | if self.mapOverlayGenerator ~= nil then |
119 | self.mapOverlayGenerator:delete() |
120 | end |
121 | end |
determinePlayerPosition
DescriptionDefinitiondeterminePlayerPosition()Code
296 | function IngameMap:determinePlayerPosition(player) |
297 | return player:getPositionData() |
298 | end |
determineVehiclePosition
DescriptionDefinitiondetermineVehiclePosition()Code
302 | function IngameMap:determineVehiclePosition(enterable) |
303 | local posX, posY, posZ = getTranslation(enterable.rootNode) |
304 | |
305 | -- set arrow rotation |
306 | local dx, _, dz = localDirectionToWorld(enterable.rootNode, 0, 0, 1) |
307 | local yRot |
308 | if enterable.spec_drivable ~= nil and enterable.spec_drivable.reverserDirection == -1 then |
309 | yRot = MathUtil.getYRotationFromDirection(dx, dz) |
310 | else |
311 | yRot = MathUtil.getYRotationFromDirection(dx, dz) + math.pi |
312 | end |
313 | |
314 | local vel = enterable:getLastSpeed() |
315 | |
316 | return posX, posY, posZ, yRot, vel |
317 | end |
drawHotspot
DescriptionDraw a single hotspot on the map.Definition
drawHotspot()Code
694 | function IngameMap:drawHotspot(hotspot, smallVersion) |
695 | if hotspot == nil then |
696 | return |
697 | end |
698 | |
699 | local worldX, worldZ = hotspot:getWorldPosition() |
700 | local rotation = hotspot:getWorldRotation() |
701 | |
702 | local objectX = (worldX + self.worldCenterOffsetX) / self.worldSizeX * self.mapExtensionScaleFactor + self.mapExtensionOffsetX |
703 | local objectZ = (worldZ + self.worldCenterOffsetZ) / self.worldSizeZ * self.mapExtensionScaleFactor + self.mapExtensionOffsetZ |
704 | |
705 | local zoom = self.layout:getIconZoom() |
706 | hotspot:setScale(self.uiScale * zoom) |
707 | |
708 | local x, y, yRot, visible = self.layout:getMapObjectPosition(objectX, objectZ, hotspot:getWidth(), hotspot:getHeight(), rotation, hotspot:getIsPersistent()) |
709 | if visible then |
710 | hotspot:setLastRenderInfo(x, y, yRot, self.layout) |
711 | -- drawFilledRect(x, y, hotspot:getWidth(), hotspot:getHeight(), 1, 0, 0, 0.2) |
712 | hotspot:render(x, y, yRot, smallVersion) |
713 | end |
714 | end |
drawLatencyToServer
DescriptionDraw current latency to server as text.Definition
drawLatencyToServer()Code
639 | function IngameMap:drawLatencyToServer() |
640 | if g_client ~= nil and g_client.currentLatency ~= nil and g_currentMission.missionDynamicInfo.isMultiplayer and g_currentMission.missionDynamicInfo.isClient then |
641 | local color |
642 | if g_client.currentLatency <= 50 then |
643 | color = IngameMap.COLOR.LATENCY_GOOD |
644 | elseif g_client.currentLatency < 100 then |
645 | color = IngameMap.COLOR.LATENCY_MEDIUM |
646 | else |
647 | color = IngameMap.COLOR.LATENCY_BAD |
648 | end |
649 | |
650 | self.layout:drawLatency(string.format("%dms", math.max(g_client.currentLatency, 10)), color) |
651 | end |
652 | end |
drawPlayersCoordinates
DescriptionDraw the player's current coordinates as text.Definition
drawPlayersCoordinates()Code
631 | function IngameMap:drawPlayersCoordinates() |
632 | local renderString = string.format("%.1f°, %d, %d", math.deg(-self.playerRotation % (2*math.pi)), self.normalizedPlayerPosX * self.worldSizeX, self.normalizedPlayerPosZ * self.worldSizeZ) |
633 | |
634 | self.layout:drawCoordinates(renderString) |
635 | end |
getBackgroundPosition
DescriptionGet the base position of the entire element.Definition
getBackgroundPosition()Code
744 | function IngameMap:getBackgroundPosition() |
745 | return g_safeFrameOffsetX, g_safeFrameOffsetY |
746 | end |
loadMap
DescriptionDefinitionloadMap()Code
246 | function IngameMap:loadMap(filename, worldSizeX, worldSizeZ, fieldColor, grassFieldColor) |
247 | self.mapElement:delete() -- will also delete the wrapped Overlay |
248 | |
249 | self:setWorldSize(worldSizeX, worldSizeZ) |
250 | |
251 | self.mapOverlay = Overlay.new(filename, 0, 0, 1, 1) |
252 | |
253 | self.mapElement = HUDElement.new(self.mapOverlay) |
254 | self:addChild(self.mapElement) |
255 | |
256 | self:setScale(self.uiScale) |
257 | |
258 | self.mapOverlayGenerator = MapOverlayGenerator.new(g_i18n, g_fruitTypeManager, g_fillTypeManager, g_farmlandManager, g_farmManager, g_currentMission.weedSystem) |
259 | self.mapOverlayGenerator:setColorBlindMode(false) |
260 | self.mapOverlayGenerator:setFieldColor(fieldColor, grassFieldColor) |
261 | self.fieldRefreshTimer = IngameMap.FIELD_REFRESH_INTERVAL |
262 | end |
new
DescriptionCreate a new instance of IngameMap.Definition
new(string hudAtlasPath, table inputDisplayManager)Arguments
string | hudAtlasPath | Path to the HUD atlas texture |
table | inputDisplayManager | InputDisplayManager reference |
40 | function IngameMap.new(hud, hudAtlasPath, inputDisplayManager, customMt) |
41 | local self = IngameMap:superClass().new(nil, nil, customMt or IngameMap_mt) |
42 | self.overlay = self:createBackground(hudAtlasPath) |
43 | |
44 | self.hud = hud |
45 | self.hudAtlasPath = hudAtlasPath |
46 | self.inputDisplayManager = inputDisplayManager |
47 | |
48 | self.uiScale = 1.0 |
49 | |
50 | self.isVisible = true |
51 | |
52 | self.layouts = { |
53 | IngameMapLayoutNone.new(), |
54 | IngameMapLayoutCircle.new(), |
55 | IngameMapLayoutSquare.new(), |
56 | IngameMapLayoutSquareLarge.new(), |
57 | IngameMapLayoutFullscreen.new(), |
58 | } |
59 | self.fullScreenLayout = self.layouts[#self.layouts] |
60 | self.state = 1 |
61 | self.layout = self.layouts[self.state] |
62 | |
63 | self.mapOverlay = Overlay.new(nil, 0, 0, 1, 1) -- null-object, obsoletes defensive checks |
64 | self.mapElement = HUDElement.new(self.mapOverlay) -- null-object |
65 | |
66 | self:createComponents(hudAtlasPath) |
67 | for _, layout in ipairs(self.layouts) do |
68 | layout:createComponents(self, hudAtlasPath) |
69 | end |
70 | |
71 | self.filter = {} |
72 | self.filter[MapHotspot.CATEGORY_FIELD] = true |
73 | self.filter[MapHotspot.CATEGORY_ANIMAL] = true |
74 | self.filter[MapHotspot.CATEGORY_MISSION] = true |
75 | self.filter[MapHotspot.CATEGORY_TOUR] = true |
76 | self.filter[MapHotspot.CATEGORY_STEERABLE] = true |
77 | self.filter[MapHotspot.CATEGORY_COMBINE] = true |
78 | self.filter[MapHotspot.CATEGORY_TRAILER] = true |
79 | self.filter[MapHotspot.CATEGORY_TOOL] = true |
80 | self.filter[MapHotspot.CATEGORY_UNLOADING] = true |
81 | self.filter[MapHotspot.CATEGORY_LOADING] = true |
82 | self.filter[MapHotspot.CATEGORY_PRODUCTION] = true |
83 | self.filter[MapHotspot.CATEGORY_SHOP] = true |
84 | self.filter[MapHotspot.CATEGORY_OTHER] = true |
85 | self.filter[MapHotspot.CATEGORY_AI] = true |
86 | self.filter[MapHotspot.CATEGORY_PLAYER] = true |
87 | |
88 | self:setWorldSize(2048, 2048) |
89 | |
90 | self.hotspots = {} |
91 | self.selectedHotspot = nil |
92 | |
93 | self.mapExtensionOffsetX = 0.25 |
94 | self.mapExtensionOffsetZ = 0.25 |
95 | self.mapExtensionScaleFactor = 0.5 |
96 | |
97 | self.allowToggle = true |
98 | |
99 | self.topDownCamera = nil -- set by screen views which use a top down view, used for map position update |
100 | |
101 | return self |
102 | end |
removeMapHotspot
DescriptionDefinitionremoveMapHotspot()Code
354 | function IngameMap:removeMapHotspot(mapHotspot) |
355 | if mapHotspot ~= nil then |
356 | for i=1, #self.hotspots do |
357 | if self.hotspots[i] == mapHotspot then |
358 | table.remove(self.hotspots, i) |
359 | break |
360 | end |
361 | end |
362 | |
363 | if self.selectedHotspot == mapHotspot then |
364 | self:setSelectedHotspot(nil) |
365 | end |
366 | |
367 | if g_currentMission ~= nil then |
368 | if g_currentMission.currentMapTargetHotspot == mapHotspot then |
369 | g_currentMission:setMapTargetHotspot(nil) |
370 | end |
371 | end |
372 | |
373 | self.hotspotsSorted = nil |
374 | end |
375 | end |
resetSettings
DescriptionDefinitionresetSettings()Code
193 | function IngameMap:resetSettings() |
194 | if self.overlay == nil then |
195 | return -- instance has been deleted, ignore reset |
196 | end |
197 | |
198 | -- self:setScale(self.uiScale) -- resets scaled values |
199 | |
200 | -- local baseX, baseY = self:getBackgroundPosition() |
201 | -- self:setPosition(baseX + self.mapOffsetX, baseY + self.mapOffsetY) |
202 | -- self:setSize(self.mapWidth, self.mapHeight) |
203 | |
204 | self:setSelectedHotspot(nil) |
205 | end |
setAllowToggle
DescriptionDefinitionsetAllowToggle()Code
225 | function IngameMap:setAllowToggle(isAllowed) |
226 | self.allowToggle = isAllowed |
227 | end |
setFullscreen
DescriptionSet full-screen mode (for map overview) without affecting the mini-map state.Definition
setFullscreen()Code
129 | function IngameMap:setFullscreen(isFullscreen) |
130 | if self.isFullscreen == isFullscreen then |
131 | return |
132 | end |
133 | |
134 | self.layout:deactivate() |
135 | |
136 | self.isFullscreen = isFullscreen |
137 | if isFullscreen then |
138 | self.layout = self.fullScreenLayout |
139 | else |
140 | self.layout = self.layouts[self.state] |
141 | end |
142 | |
143 | self.layout:activate() |
144 | |
145 | g_inputBinding:setActionEventTextVisibility(self.toggleMapSizeEventId, self.layout:getShowsToggleActionText()) |
146 | end |
setHotspotFilter
DescriptionDefinitionsetHotspotFilter()Code
470 | function IngameMap:setHotspotFilter(category, isActive) |
471 | if category ~= nil then |
472 | if isActive then |
473 | g_gameSettings:setValue("ingameMapFilter", Utils.clearBit(g_gameSettings:getValue("ingameMapFilter"), category)) |
474 | else |
475 | g_gameSettings:setValue("ingameMapFilter", Utils.setBit(g_gameSettings:getValue("ingameMapFilter"), category)) |
476 | end |
477 | self.filter[category] = isActive |
478 | self.hotspotsSorted = nil |
479 | end |
480 | end |
setScale
DescriptionSet this element's scale.Definition
setScale(float uiScale)Arguments
float | uiScale | Current UI scale applied to both width and height of elements |
723 | function IngameMap:setScale(uiScale) |
724 | IngameMap:superClass().setScale(self, uiScale, uiScale) |
725 | self.uiScale = uiScale |
726 | |
727 | self:storeScaledValues(uiScale) |
728 | end |
setSelectedHotspot
DescriptionDefinitionsetSelectedHotspot()Code
379 | function IngameMap:setSelectedHotspot(hotspot) |
380 | if self.selectedHotspot ~= nil then |
381 | self.selectedHotspot:setSelected(false) |
382 | end |
383 | self.selectedHotspot = hotspot |
384 | if self.selectedHotspot ~= nil then |
385 | self.selectedHotspot:setSelected(true) |
386 | end |
387 | end |
setWorldSize
DescriptionDefinitionsetWorldSize()Code
275 | function IngameMap:setWorldSize(worldSizeX, worldSizeZ) |
276 | self.worldSizeX = worldSizeX |
277 | self.worldSizeZ = worldSizeZ |
278 | self.worldCenterOffsetX = self.worldSizeX * 0.5 |
279 | self.worldCenterOffsetZ = self.worldSizeZ * 0.5 |
280 | |
281 | for _, layout in ipairs(self.layouts) do |
282 | layout:setWorldSize(worldSizeX, worldSizeZ) |
283 | end |
284 | end |
storeScaledValues
DescriptionStore scaled positioning, size and offset values.Definition
storeScaledValues()Code
732 | function IngameMap:storeScaledValues(uiScale) |
733 | for _, layout in ipairs(self.layouts) do |
734 | layout:storeScaledValues(self, uiScale) |
735 | end |
736 | end |
toggleSize
DescriptionDefinitiontoggleSize()Code
150 | function IngameMap:toggleSize(state, force) |
151 | --#profile g_remoteProfiler.ZoneBeginN("IngameMap_toggleSize") |
152 | self.layout:deactivate() |
153 | |
154 | if state ~= nil then |
155 | self.state = math.max(math.min(state, #self.layouts - 1), 1) |
156 | else |
157 | self.state = (self.state % (#self.layouts - 1)) + 1 |
158 | end |
159 | |
160 | self.layout = self.layouts[self.state] |
161 | self.layout:activate() |
162 | |
163 | g_inputBinding:setActionEventTextVisibility(self.toggleMapSizeEventId, self.layout:getShowsToggleActionText()) |
164 | g_gameSettings:setValue("ingameMapState", self.state) |
165 | --#profile g_remoteProfiler.ZoneEnd() |
166 | end |
updateHotspotFilters
DescriptionDefinitionupdateHotspotFilters()Code
457 | function IngameMap:updateHotspotFilters() |
458 | for category, _ in pairs(self.filter) do |
459 | if category == MapHotspot.CATEGORY_SHOP then |
460 | -- Make shop and 'other' equal to each other |
461 | self:setHotspotFilter(category, not Utils.isBitSet(g_gameSettings:getValue("ingameMapFilter"), MapHotspot.CATEGORY_OTHER)) |
462 | else |
463 | self:setHotspotFilter(category, not Utils.isBitSet(g_gameSettings:getValue("ingameMapFilter"), category)) |
464 | end |
465 | end |
466 | end |