Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ContextActionDisplay
- DialogElement
- FieldInfoDisplay
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputHelpDisplay
- ListElement
- ListItemElement
- MapHotspot
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- SettingsModel
- SideNotification
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- StableListElement
- StatusBar
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TextElement
- TextInputElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
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
- colorForFarm
- createBackground
- createComponents
- createFrame
- createOtherMapArrowOverlay
- createPlayerMapArrow
- createToggleMapSizeGlyph
- delete
- determinePlayerPosition
- determineVehiclePosition
- drawEnterableArrows
- drawHotspot
- drawLatencyToServer
- drawOtherPlayerArrows
- drawPlayersCoordinates
- getBackgroundPosition
- getIsFullSize
- loadMap
- new
- removeMapHotspot
- renderHotspots
- resetSettings
- setAllowToggle
- setFilter
- setFullscreen
- setMapObjectOverlayRotation
- setScale
- setSelectedHotspot
- setWorldSize
- setZoomScale
- storeScaledValues
- toggleSize
- updateFilters
- zoom
addMapHotspot
DescriptionDefinitionaddMapHotspot()Code
460 | function IngameMap:addMapHotspot(mapHotspot) |
461 | table.insert(self.hotspots, mapHotspot) |
462 | |
463 | table.sort(self.hotspots, function(v1, v2) return v1.category > v2.category end) |
464 | self.hotspots_sorted = nil |
465 | |
466 | return mapHotspot |
467 | end |
colorForFarm
DescriptionDefinitioncolorForFarm()Code
882 | function IngameMap:colorForFarm(farmId) |
883 | local farm = g_farmManager:getFarmById(farmId) |
884 | if farm ~= nil then |
885 | local color = Farm.COLORS[farm.color] |
886 | if color ~= nil then |
887 | return color[1], color[2], color[3], color[4] |
888 | end |
889 | end |
890 | |
891 | return 1, 1, 1, 1 |
892 | end |
createBackground
DescriptionCreate the empty background overlay.Definition
createBackground()Code
1091 | function IngameMap.createBackground() |
1092 | local width, height = getNormalizedScreenValues(unpack(IngameMap.SIZE.SELF)) |
1093 | local posX, posY = IngameMap.getBackgroundPosition() |
1094 | return Overlay:new(nil, posX, posY, width, height) |
1095 | end |
createComponents
DescriptionCreate required display components.Definition
createComponents(string hudAtlasPath)Arguments
string | hudAtlasPath | Path to the HUD texture atlas |
1100 | function IngameMap:createComponents(hudAtlasPath) |
1101 | local baseX, baseY = self:getPosition() |
1102 | local width, height = self:getWidth(), self:getHeight() |
1103 | |
1104 | self:createFrame(hudAtlasPath, baseX, baseY, width, height) |
1105 | self:createToggleMapSizeGlyph(hudAtlasPath, baseX, baseY, width, height) |
1106 | |
1107 | self:createPlayerMapArrow() |
1108 | self:createOtherMapArrowOverlay() |
1109 | end |
createFrame
DescriptionCreate the map frame.Definition
createFrame()Code
1113 | function IngameMap:createFrame(hudAtlasPath, baseX, baseY, width, height) |
1114 | local frame = HUDFrameElement:new(hudAtlasPath, baseX, baseY, width, height) |
1115 | self.mapFrameElement = frame |
1116 | self:addChild(frame) |
1117 | end |
createOtherMapArrowOverlay
DescriptionCreate an arrow overlay used for other player's and their vehicles in multiplayer.Definition
createOtherMapArrowOverlay()Code
1152 | function IngameMap:createOtherMapArrowOverlay() |
1153 | local width, height = getNormalizedScreenValues(unpack(IngameMap.SIZE.OTHER_ARROW)) |
1154 | local mapArrowRedOverlay = Overlay:new(IngameMap.MAP_HOTSPOT_ATLAS_PATH, 0, 0, width, height) |
1155 | mapArrowRedOverlay:setUVs(getNormalizedUVs(MapHotspot.UV.NAVIGATION_POINTER)) |
1156 | mapArrowRedOverlay:setColor(unpack(IngameMap.COLOR.OTHER_ARROW)) |
1157 | |
1158 | self.mapArrowRedOverlay = mapArrowRedOverlay |
1159 | end |
createPlayerMapArrow
DescriptionCreate the map arrow for the player's position.Definition
createPlayerMapArrow()Code
1138 | function IngameMap:createPlayerMapArrow() |
1139 | local width, height = getNormalizedScreenValues(unpack(IngameMap.SIZE.PLAYER_ARROW)) |
1140 | local playerMapArrowOverlay = Overlay:new(IngameMap.MAP_HOTSPOT_ATLAS_PATH, 0, 0, width, height) |
1141 | playerMapArrowOverlay:setUVs(getNormalizedUVs(MapHotspot.UV.NAVIGATION_POINTER)) |
1142 | playerMapArrowOverlay:setColor(unpack(IngameMap.COLOR.PLAYER_ARROW)) |
1143 | playerMapArrowOverlay:setAlignment(Overlay.ALIGN_VERTICAL_BOTTOM, Overlay.ALIGN_HORIZONTAL_LEFT) |
1144 | self.playerMapArrowOverlay = playerMapArrowOverlay |
1145 | |
1146 | local element = HUDElement:new(playerMapArrowOverlay) |
1147 | self.playerMapArrowElement = element |
1148 | end |
createToggleMapSizeGlyph
DescriptionCreate the input glyph for map size toggling.Definition
createToggleMapSizeGlyph()Code
1121 | function IngameMap:createToggleMapSizeGlyph(hudAtlasPath, baseX, baseY, baseWidth, baseHeight) |
1122 | local width, height = getNormalizedScreenValues(unpack(IngameMap.SIZE.INPUT_ICON)) |
1123 | local offX, offY = getNormalizedScreenValues(unpack(IngameMap.POSITION.INPUT_ICON)) |
1124 | |
1125 | local element = InputGlyphElement:new(self.inputDisplayManager, width, height) |
1126 | local posX, posY = baseX + baseWidth - width - offX, baseY + baseHeight + offY |
1127 | |
1128 | element:setPosition(posX, posY) |
1129 | element:setKeyboardGlyphColor(IngameMap.COLOR.INPUT_ICON) |
1130 | element:setAction(InputAction.TOGGLE_MAP_SIZE) |
1131 | |
1132 | self.toggleMapSizeGlyph = element |
1133 | self:addChild(element) |
1134 | end |
delete
DescriptionDelete this element and all of its components.Definition
delete()Code
128 | function IngameMap:delete() |
129 | IngameMap:superClass().delete(self) |
130 | |
131 | g_inputBinding:removeActionEventsByTarget(self) |
132 | |
133 | self.mapElement:delete() |
134 | self.playerMapArrowElement:delete() |
135 | self.mapArrowRedOverlay:delete() |
136 | |
137 | self:setSelectedHotspot(nil) |
138 | |
139 | -- delete all hotspots |
140 | for _, hotspot in pairs(self.hotspots) do |
141 | hotspot:delete() |
142 | end |
143 | end |
determinePlayerPosition
DescriptionDefinitiondeterminePlayerPosition()Code
416 | function IngameMap:determinePlayerPosition(player) |
417 | return player:getPositionData() |
418 | end |
determineVehiclePosition
DescriptionDefinitiondetermineVehiclePosition()Code
422 | function IngameMap:determineVehiclePosition(steerable) |
423 | local posX, posY, posZ = getTranslation(steerable.rootNode) |
424 | |
425 | -- set arrow rotation |
426 | local dx, _, dz = localDirectionToWorld(steerable.rootNode, 0, 0, 1) |
427 | local yRot |
428 | if steerable.spec_drivable ~= nil and steerable.spec_drivable.reverserDirection == -1 then |
429 | yRot = MathUtil.getYRotationFromDirection(dx, dz) |
430 | else |
431 | yRot = MathUtil.getYRotationFromDirection(dx, dz) + math.pi |
432 | end |
433 | return posX, posY, posZ, yRot |
434 | end |
drawEnterableArrows
DescriptionDraw arrows for enterable vehicles controlled by players.Definition
drawEnterableArrows()Code
928 | function IngameMap:drawEnterableArrows(showNames, leftBorderReached, rightBorderReached, topBorderReached, bottomBorderReached) |
929 | for _, enterable in pairs(g_currentMission.enterables) do |
930 | -- isControlled -> being steered, isEntered -> locally controlled and entered (don't show) |
931 | if enterable.spec_enterable ~= nil and enterable.spec_enterable.isControlled and not enterable.spec_enterable.isEntered then |
932 | local posX, _, posZ, rotY = self:determineVehiclePosition(enterable) |
933 | posX = (math.floor(posX) + self.worldCenterOffsetX) / self.worldSizeX |
934 | posZ = (math.floor(posZ) + self.worldCenterOffsetZ) / self.worldSizeZ |
935 | |
936 | local positionVisible = self:setMapObjectOverlayPosition(self.mapArrowRedOverlay, posX, posZ, |
937 | self.mapArrowRedOverlay.width, self.mapArrowRedOverlay.height, true, showNames, |
938 | leftBorderReached, rightBorderReached, topBorderReached, bottomBorderReached) |
939 | |
940 | if positionVisible then |
941 | self:setMapObjectOverlayRotation(self.mapArrowRedOverlay, rotY) |
942 | local r,g,b,a = self:colorForFarm(enterable:getActiveFarm()) |
943 | self.mapArrowRedOverlay:setColor(r, g, b, a) |
944 | self.mapArrowRedOverlay:render() |
945 | if showNames then |
946 | setTextAlignment(RenderText.ALIGN_LEFT) |
947 | setTextBold(false) |
948 | setTextColor(1, 1, 1, 1) |
949 | local textWidth = getTextWidth(self.playerFontSize, enterable:getControllerName()) |
950 | local posX = MathUtil.clamp(self.mapArrowRedOverlay.x + self.mapArrowRedOverlay.width * 0.5 + self.playerNameOffsetX - textWidth * 0.5, self.mapPosX, self.mapPosX + self.mapWidth - textWidth) |
951 | renderText(posX, self.mapArrowRedOverlay.y + self.playerNameOffsetY, self.playerFontSize, enterable:getControllerName()) |
952 | end |
953 | end |
954 | end |
955 | end |
956 | end |
drawHotspot
DescriptionDraw a single hotspot on the map.Definition
drawHotspot()Code
978 | function IngameMap:drawHotspot(hotspot, leftBorderReached, rightBorderReached, topBorderReached, bottomBorderReached, showNames, noScaling) |
979 | if hotspot ~= nil then |
980 | -- update hotspot's position if it's dynamic |
981 | if hotspot.objectId ~= nil and hotspot.objectId ~= 0 then |
982 | local objectX, _, objectZ = getWorldTranslation(hotspot.objectId) |
983 | hotspot.xMapPos = objectX |
984 | hotspot.zMapPos = objectZ |
985 | end |
986 | |
987 | local objectX = (hotspot.xMapPos+self.worldCenterOffsetX) / self.worldSizeX |
988 | local objectZ = (hotspot.zMapPos+self.worldCenterOffsetZ) / self.worldSizeZ |
989 | |
990 | hotspot.zoom = self.iconZoom |
991 | hotspot.visible = self:setMapObjectOverlayPosition(hotspot, objectX, objectZ, hotspot.width * hotspot.zoom, hotspot.height * hotspot.zoom, hotspot.enabled, hotspot.persistent, leftBorderReached, rightBorderReached, topBorderReached, bottomBorderReached) |
992 | local scale = self.uiScale |
993 | if noScaling then |
994 | scale = 1 |
995 | end |
996 | |
997 | hotspot:render(self.mapPosX, self.mapPosX + self.mapWidth, self.mapPosY, self.mapPosY + self.mapHeight, scale, showNames) |
998 | end |
999 | end |
drawLatencyToServer
DescriptionDraw current latency to server as text.Definition
drawLatencyToServer()Code
1015 | function IngameMap:drawLatencyToServer() |
1016 | if g_client ~= nil and g_client.currentLatency ~= nil and g_currentMission.missionDynamicInfo.isMultiplayer and g_currentMission.missionDynamicInfo.isClient then |
1017 | if g_client.currentLatency <= 50 then |
1018 | setTextColor(unpack(IngameMap.COLOR.LATENCY_GOOD)) |
1019 | elseif g_client.currentLatency < 100 then |
1020 | setTextColor(unpack(IngameMap.COLOR.LATENCY_MEDIUM)) |
1021 | else |
1022 | setTextColor(unpack(IngameMap.COLOR.LATENCY_BAD)) |
1023 | end |
1024 | |
1025 | setTextBold(false) |
1026 | setTextAlignment(RenderText.ALIGN_RIGHT) |
1027 | renderText(self.mapPosX + self.mapWidth - self.coordOffsetX, self.mapPosY + self.mapHeight - self.coordOffsetY - self.fontSize, self.fontSize, string.format("%dms", math.max(g_client.currentLatency, 10))) |
1028 | end |
1029 | end |
drawOtherPlayerArrows
DescriptionDraw arrows for other players' positions.Definition
drawOtherPlayerArrows()Code
896 | function IngameMap:drawOtherPlayerArrows(showNames, leftBorderReached, rightBorderReached, topBorderReached, bottomBorderReached) |
897 | for _, player in pairs(g_currentMission.players) do |
898 | if player.isControlled and not player.isEntered and player ~= g_currentMission.player then |
899 | local posX, _, posZ, rotY = self:determinePlayerPosition(player) |
900 | rotY = rotY - math.pi -- offset returned display rotation value |
901 | posX = (math.floor(posX) + self.worldCenterOffsetX) / self.worldSizeX |
902 | posZ = (math.floor(posZ) + self.worldCenterOffsetZ) / self.worldSizeZ |
903 | |
904 | local positionVisible = self:setMapObjectOverlayPosition(self.mapArrowRedOverlay, posX, posZ, |
905 | self.mapArrowRedOverlay.width, self.mapArrowRedOverlay.height, true, showNames, |
906 | leftBorderReached, rightBorderReached, topBorderReached, bottomBorderReached) |
907 | |
908 | if positionVisible then |
909 | self:setMapObjectOverlayRotation(self.mapArrowRedOverlay, rotY) |
910 | local r, g, b, a = self:colorForFarm(player.farmId) |
911 | self.mapArrowRedOverlay:setColor(r, g, b, a) |
912 | self.mapArrowRedOverlay:render() |
913 | if showNames then |
914 | setTextAlignment(RenderText.ALIGN_LEFT) |
915 | setTextBold(false) |
916 | setTextColor(1, 1, 1, 1) |
917 | local textWidth = getTextWidth(self.playerFontSize, player.visualInformation.playerName) |
918 | local posX = MathUtil.clamp(self.mapArrowRedOverlay.x + self.mapArrowRedOverlay.width * 0.5 + self.playerNameOffsetX - textWidth * 0.5, self.mapPosX, self.mapPosX + self.mapWidth - textWidth) |
919 | renderText(posX, self.mapArrowRedOverlay.y + self.playerNameOffsetY, self.playerFontSize, player.visualInformation.playerName) |
920 | end |
921 | end |
922 | end |
923 | end |
924 | end |
drawPlayersCoordinates
DescriptionDraw the player's current coordinates as text.Definition
drawPlayersCoordinates()Code
1003 | function IngameMap:drawPlayersCoordinates() |
1004 | local renderString = string.format("[%.1f°, %d, %d]", math.deg(-self.playerRotation % (2*math.pi)), self.normalizedPlayerPosX * self.worldSizeX, self.normalizedPlayerPosZ * self.worldSizeZ) |
1005 | |
1006 | -- show the player's current coordinates |
1007 | setTextAlignment(RenderText.ALIGN_RIGHT) |
1008 | setTextBold(false) |
1009 | setTextColor(unpack(IngameMap.COLOR.COORDINATES_TEXT)) |
1010 | renderText(self.mapPosX + self.mapWidth - self.coordOffsetX, self.mapPosY + self.coordOffsetY, self.fontSize, renderString) |
1011 | end |
getBackgroundPosition
DescriptionGet the base position of the entire element.Definition
getBackgroundPosition()Code
1085 | function IngameMap.getBackgroundPosition() |
1086 | return g_safeFrameOffsetX, g_safeFrameOffsetY |
1087 | end |
getIsFullSize
DescriptionDefinitiongetIsFullSize()Code
283 | function IngameMap:getIsFullSize() |
284 | return self.state == IngameMap.STATE_MAP or (self.isFullscreen and self.mapVisWidthMin <= 1) |
285 | end |
loadMap
DescriptionDefinitionloadMap()Code
374 | function IngameMap:loadMap(filename, worldSizeX, worldSizeZ) |
375 | self.mapElement:delete() -- will also delete the wrapped Overlay |
376 | |
377 | self:setWorldSize(worldSizeX, worldSizeZ) |
378 | |
379 | local baseX, baseY = self:getPosition() |
380 | local mapOverlay = Overlay:new(filename, baseX + self.mapOffsetX, baseY + self.mapOffsetY, self.mapSizeX, self.mapSizeY) |
381 | |
382 | self.mapOverlay = mapOverlay |
383 | self.mapAlpha = 1 |
384 | |
385 | local mapElement = HUDElement:new(mapOverlay) |
386 | self.mapElement = mapElement |
387 | self:setScale(self.uiScale) -- re-scale map overlay and borders |
388 | 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 |
34 | function IngameMap:new(hudAtlasPath, inputDisplayManager) |
35 | local backgroundOverlay = IngameMap.createBackground() |
36 | local self = IngameMap:superClass().new(IngameMap_mt, backgroundOverlay, nil) |
37 | |
38 | self.uiScale = 1.0 |
39 | |
40 | self.inputDisplayManager = inputDisplayManager |
41 | |
42 | self.mapOverlay = Overlay:new(nil, 0, 0, 1, 1) -- null-object, obsoletes defensive checks |
43 | self.mapElement = HUDElement:new(self.mapOverlay) -- null-object |
44 | self.mapFrameElement = nil |
45 | self.toggleMapSizeGlyph = nil -- toggle map size input glyph |
46 | self.playerMapArrowElement = nil -- arrow indicator for player position on map |
47 | |
48 | self.mapLabelText = utf8ToUpper(g_i18n:getText(IngameMap.L10N_SYMBOL_MAP_LABEL)) |
49 | self.selectHotspotText = g_i18n:getText(IngameMap.L10N_SYMBOL_SELECT_MAP) |
50 | |
51 | self.mapLabelOffsetX, self.mapLabelOffsetY = 0, 0 |
52 | self.mapLabelTextSize = 0 |
53 | self.mapOffsetX, self.mapOffsetY = 0, 0 |
54 | self.mapSizeX, self.mapSizeY = 0, 0 |
55 | self.mapToFrameDiffX, self.mapToFrameDiffY = 0, 0 |
56 | self.toggleSizeGlyphOffsetX, self.toggleSizeGlyphOffsetY = 0, 0 |
57 | |
58 | self:createComponents(hudAtlasPath) |
59 | |
60 | self.filter = {} |
61 | self.filter[MapHotspot.CATEGORY_DEFAULT] = true |
62 | self.filter[MapHotspot.CATEGORY_FIELD_DEFINITION] = true |
63 | self.filter[MapHotspot.CATEGORY_TRIGGER] = true |
64 | self.filter[MapHotspot.CATEGORY_COLLECTABLE] = true |
65 | self.filter[MapHotspot.CATEGORY_AI] = true |
66 | self.filter[MapHotspot.CATEGORY_TOUR] = true |
67 | self.filter[MapHotspot.CATEGORY_MISSION] = true |
68 | self.filter[MapHotspot.CATEGORY_VEHICLE_STEERABLE] = true |
69 | self.filter[MapHotspot.CATEGORY_VEHICLE_COMBINE] = true |
70 | self.filter[MapHotspot.CATEGORY_VEHICLE_TRAILER] = true |
71 | self.filter[MapHotspot.CATEGORY_VEHICLE_TOOL] = true |
72 | |
73 | self:setWorldSize(2048, 2048) |
74 | |
75 | local uiScale = g_gameSettings:getValue("uiScale") |
76 | |
77 | self.mapPosX = g_safeFrameOffsetX |
78 | self.mapPosY = g_safeFrameOffsetY |
79 | self.minMapWidth, self.minMapHeight = getNormalizedScreenValues(unpack(IngameMap.SIZE.MAP)) |
80 | |
81 | -- map arrow representing the player |
82 | self.mapArrowWidth, self.mapArrowHeight = getNormalizedScreenValues(unpack(IngameMap.SIZE.PLAYER_ARROW)) |
83 | |
84 | self:setSize(self.minMapWidth, self.minMapHeight) |
85 | |
86 | self.maxMapHeight = 0.7 - 2 * self.mapPosY |
87 | self.maxMapWidth = (self.maxMapHeight * g_screenHeight) / g_screenWidth |
88 | |
89 | self.resizeTime = 0.1 * 1000 |
90 | self.resizeDir = 0 |
91 | self.state = IngameMap.STATE_MINIMAP |
92 | |
93 | self.minMapVisWidth = 0.3 |
94 | self.maxMapVisWidth = 1 |
95 | |
96 | self.iconZoom = 1.4 |
97 | self.maxIconZoom = IngameMap.maxIconZoom |
98 | |
99 | self.mapVisWidthMin = self.minMapVisWidth -- this is the largest zoom factor (width) for the map |
100 | self.mapVisWidth = 0.1 -- this is the current zoom factor (width) changes in relation to vehicle speed |
101 | self.mapVisHeight = self.mapVisWidth / self.mapAspectRatio -- zoom factor for height (with aspect ratio from map) |
102 | |
103 | self.mapUVs = {0, 0, 0, 0, 0, 0, 0, 0} |
104 | |
105 | -- the player's position on the map |
106 | self.normalizedPlayerPosX = 0 |
107 | self.normalizedPlayerPosZ = 0 |
108 | self.playerRotation = 0 |
109 | |
110 | -- the map's current center position (same as player position, unless map borders reached) |
111 | self.centerXPos = 0 |
112 | self.centerZPos = 0 |
113 | |
114 | self.hotspots = {} |
115 | |
116 | self.selectedHotspot = nil |
117 | |
118 | self.isVisible = true |
119 | self.allowToggle = true |
120 | |
121 | self.topDownCamera = nil -- set by screen views which use a top down view, used for map position update |
122 | |
123 | return self |
124 | end |
removeMapHotspot
DescriptionDefinitionremoveMapHotspot()Code
471 | function IngameMap:removeMapHotspot(mapHotspot) |
472 | if mapHotspot ~= nil then |
473 | for i = 1, table.getn(self.hotspots) do |
474 | if self.hotspots[i] == mapHotspot then |
475 | table.remove(self.hotspots, i) |
476 | break |
477 | end |
478 | end |
479 | |
480 | if self.selectedHotspot == mapHotspot then |
481 | self:setSelectedHotspot(nil) |
482 | end |
483 | |
484 | if g_currentMission ~= nil then |
485 | if g_currentMission.currentMapTargetHotspot == mapHotspot then |
486 | g_currentMission:setMapTargetHotspot(nil) |
487 | end |
488 | end |
489 | |
490 | mapHotspot.enabled = false |
491 | |
492 | self.hotspots_sorted = nil |
493 | end |
494 | end |
renderHotspots
DescriptionDraw all known hotspots on the map.Definition
renderHotspots()Code
960 | function IngameMap:renderHotspots(leftBorderReached, rightBorderReached, topBorderReached, bottomBorderReached, renderLast, showNames, minimalHotspotSize, noScaling) |
961 | -- reposition all hotspots |
962 | if renderLast then |
963 | new2DLayer() |
964 | end |
965 | |
966 | if self.hotspots_sorted ~= nil then -- this data structure is built in update() when necessary and reset to nil on changes |
967 | for _, hotspot in pairs(self.hotspots_sorted[renderLast]) do |
968 | hotspot.visible = false |
969 | if hotspot ~= self.selectedHotspot and (minimalHotspotSize == nil or hotspot.category == MapHotspot.CATEGORY_FIELD_DEFINITION or minimalHotspotSize <= hotspot.width) then |
970 | self:drawHotspot(hotspot, leftBorderReached, rightBorderReached, topBorderReached, bottomBorderReached, showNames, noScaling) |
971 | end |
972 | end |
973 | end |
974 | end |
resetSettings
DescriptionDefinitionresetSettings()Code
254 | function IngameMap:resetSettings() |
255 | if self.overlay == nil then |
256 | return -- instance has been deleted, ignore reset |
257 | end |
258 | |
259 | if self.state == IngameMap.STATE_MAP then |
260 | self.mapWidth = self.maxMapWidth |
261 | self.mapHeight = self.maxMapHeight |
262 | self.mapVisWidthMin = self.maxMapVisWidth |
263 | self.iconZoom = self.maxIconZoom |
264 | self.mapAlpha = 0.7 |
265 | else |
266 | self.mapWidth = self.minMapWidth |
267 | self.mapHeight = self.minMapHeight |
268 | self.mapVisWidthMin = self.minMapVisWidth |
269 | self.iconZoom = self.maxIconZoom |
270 | self.mapAlpha = 1 |
271 | end |
272 | |
273 | self:setScale(self.uiScale) -- resets scaled values |
274 | |
275 | local baseX, baseY = IngameMap.getBackgroundPosition() |
276 | self:setPosition(baseX + self.mapOffsetX, baseY + self.mapOffsetY) |
277 | self:setSize(self.mapWidth, self.mapHeight) |
278 | self:setSelectedHotspot(nil) |
279 | end |
setAllowToggle
DescriptionDefinitionsetAllowToggle()Code
334 | function IngameMap:setAllowToggle(isAllowed) |
335 | self.allowToggle = isAllowed |
336 | self.toggleMapSizeGlyph:setVisible(isAllowed) |
337 | end |
setFilter
DescriptionDefinitionsetFilter()Code
446 | function IngameMap:setFilter(category, isActive) |
447 | if category ~= nil then |
448 | if isActive then |
449 | g_gameSettings:setValue("ingameMapFilter", Utils.clearBit(g_gameSettings:getValue("ingameMapFilter"), category)) |
450 | else |
451 | g_gameSettings:setValue("ingameMapFilter", Utils.setBit(g_gameSettings:getValue("ingameMapFilter"), category)) |
452 | end |
453 | self.filter[category] = isActive |
454 | self.hotspots_sorted = nil |
455 | end |
456 | end |
setFullscreen
DescriptionSet full-screen mode (for map overview) without affecting the mini-map state.Definition
setFullscreen()Code
147 | function IngameMap:setFullscreen(isFullscreen) |
148 | self.isFullscreen = isFullscreen |
149 | |
150 | if isFullscreen then |
151 | self.mapVisWidthMin = 1 |
152 | self.centerXPos = 0 |
153 | self.centerZPos = 0 |
154 | end |
155 | end |
setMapObjectOverlayRotation
DescriptionDefinitionsetMapObjectOverlayRotation()Code
410 | function IngameMap:setMapObjectOverlayRotation(overlay, rotation) |
411 | overlay:setRotation(rotation, overlay.width*0.5, overlay.height*0.5) |
412 | 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 |
1038 | function IngameMap:setScale(uiScale) |
1039 | IngameMap:superClass().setScale(self, uiScale, uiScale) |
1040 | self.uiScale = uiScale |
1041 | self:storeScaledValues(uiScale) |
1042 | |
1043 | self.mapElement:setScale(uiScale, uiScale) |
1044 | local uniZoomScale = uiScale * self.iconZoom |
1045 | self.playerMapArrowElement:setScale(uniZoomScale, uniZoomScale) |
1046 | self.mapArrowRedOverlay:setScale(uniZoomScale, uniZoomScale) |
1047 | |
1048 | -- update some positioning info by resetting position and size |
1049 | local x, y = self:getPosition() |
1050 | self:setPosition(x + self.mapOffsetX, y + self.mapOffsetY) |
1051 | self:setSize(self.mapWidth, self.mapHeight) |
1052 | end |
setSelectedHotspot
DescriptionDefinitionsetSelectedHotspot()Code
195 | function IngameMap:setSelectedHotspot(hotspot) |
196 | if self.selectedHotspot ~= nil then |
197 | self.selectedHotspot:setSelected(false) |
198 | end |
199 | self.selectedHotspot = hotspot |
200 | if self.selectedHotspot ~= nil then |
201 | self.selectedHotspot:setSelected(true) |
202 | end |
203 | end |
setWorldSize
DescriptionDefinitionsetWorldSize()Code
401 | function IngameMap:setWorldSize(worldSizeX, worldSizeZ) |
402 | self.worldSizeX = worldSizeX |
403 | self.worldSizeZ = worldSizeZ |
404 | self.worldCenterOffsetX = self.worldSizeX * 0.5 |
405 | self.worldCenterOffsetZ = self.worldSizeZ * 0.5 |
406 | end |
setZoomScale
DescriptionDefinitionsetZoomScale()Code
353 | function IngameMap:setZoomScale(uniZoomScale) |
354 | self.playerMapArrowElement:setScale(uniZoomScale, uniZoomScale) |
355 | self.mapArrowRedOverlay:setScale(uniZoomScale, uniZoomScale) |
356 | end |
storeScaledValues
DescriptionStore scaled positioning, size and offset values.Definition
storeScaledValues()Code
1056 | function IngameMap:storeScaledValues(uiScale) |
1057 | self.minMapWidth, self.minMapHeight = self:scalePixelToScreenVector(IngameMap.SIZE.MAP) |
1058 | |
1059 | self.mapLabelOffsetX, self.mapLabelOffsetY = self:scalePixelToScreenVector(IngameMap.POSITION.MAP_LABEL) |
1060 | self.mapLabelTextSize = self:scalePixelToScreenHeight(HUDElement.TEXT_SIZE.DEFAULT_TITLE) |
1061 | |
1062 | self.mapOffsetX, self.mapOffsetY = self:scalePixelToScreenVector(IngameMap.POSITION.MAP) |
1063 | self.mapSizeX, self.mapSizeY = self:scalePixelToScreenVector(IngameMap.SIZE.MAP) |
1064 | |
1065 | self.toggleSizeGlyphOffsetX, self.toggleSizeGlyphOffsetY = self:scalePixelToScreenVector(IngameMap.POSITION.INPUT_ICON) |
1066 | self.selectHotspotTextSize = self:scalePixelToScreenHeight(IngameMap.TEXT_SIZE.GLYPH_TEXT) |
1067 | |
1068 | self.fontSize = self:scalePixelToScreenHeight(HUDElement.TEXT_SIZE.DEFAULT_TEXT) |
1069 | self.coordOffsetX, self.coordOffsetY = self:scalePixelToScreenVector(IngameMap.POSITION.INFO_TEXT) |
1070 | |
1071 | self.playerFontSize = self:scalePixelToScreenHeight(IngameMap.TEXT_SIZE.PLAYER_NAME) |
1072 | self.playerNameOffsetX, self.playerNameOffsetY = self:scalePixelToScreenVector(IngameMap.POSITION.PLAYER_NAME) |
1073 | |
1074 | self.mapToFrameDiffX, self.mapToFrameDiffY = |
1075 | self:scalePixelToScreenWidth(IngameMap.SIZE.SELF[1] - IngameMap.SIZE.MAP[1]), |
1076 | self:scalePixelToScreenHeight(IngameMap.SIZE.SELF[2] - IngameMap.SIZE.MAP[2]) |
1077 | end |
toggleSize
DescriptionDefinitiontoggleSize()Code
159 | function IngameMap:toggleSize(state, force) |
160 | local newState = self.state + 1 |
161 | if newState > IngameMap.STATE_OFF then |
162 | newState = IngameMap.STATE_MINIMAP |
163 | end |
164 | |
165 | if state ~= nil then |
166 | if force or self.state ~= IngameMap.STATE_OFF then |
167 | newState = state |
168 | if state == IngameMap.STATE_MINIMAP and self.state == IngameMap.STATE_MAP then |
169 | self.resizeDir = -1 |
170 | end |
171 | end |
172 | end |
173 | |
174 | self.state = newState |
175 | if newState == IngameMap.STATE_MAP then |
176 | self.resizeDir = 1 |
177 | else |
178 | self:resetSettings() |
179 | end |
180 | |
181 | -- only show toggle map input binding display in global input hints if the map is currently invisible: |
182 | g_inputBinding:setActionEventTextVisibility(self.toggleMapSizeEventId, self.state == IngameMap.STATE_OFF) |
183 | |
184 | g_gameSettings:setValue("ingameMapState", newState) |
185 | end |
updateFilters
DescriptionDefinitionupdateFilters()Code
438 | function IngameMap:updateFilters() |
439 | for category, _ in pairs(self.filter) do |
440 | self:setFilter(category, not Utils.isBitSet(g_gameSettings:getValue("ingameMapFilter"), category)) |
441 | end |
442 | end |
zoom
DescriptionDefinitionzoom()Code
341 | function IngameMap:zoom(zoomDiff) |
342 | self.mapVisWidthMin = MathUtil.clamp(self.mapVisWidthMin + zoomDiff, self.minMapVisWidth, self.maxMapVisWidth) |
343 | |
344 | self:setSize(self.mapWidth, self.mapHeight) |
345 | |
346 | self.iconZoom = 1.2 + (1 - (self.mapVisWidthMin - self.minMapVisWidth) / (self.maxMapVisWidth - self.minMapVisWidth)) |
347 | |
348 | self:setZoomScale(self.uiScale * self.iconZoom) |
349 | end |