From b429d4a284ee9094bc3f072fe6e7b00cfe2e189d Mon Sep 17 00:00:00 2001 From: dutchie031 Date: Mon, 17 Aug 2026 21:37:34 +0200 Subject: [PATCH] wip --- .../stageClasses/Stages/BaseStage/Stage.lua | 60 ++++++++++++----- .../stageClasses/Stages/ExtraStage.lua | 4 +- .../drawings/helper/DrawingHelper.lua | 12 +++- .../stageClasses/missions/ZoneMission.lua | 2 +- src/classes/util/DcsUtil.lua | 65 ------------------- 5 files changed, 59 insertions(+), 84 deletions(-) diff --git a/src/classes/stageClasses/Stages/BaseStage/Stage.lua b/src/classes/stageClasses/Stages/BaseStage/Stage.lua index 8444329..4bbc674 100644 --- a/src/classes/stageClasses/Stages/BaseStage/Stage.lua +++ b/src/classes/stageClasses/Stages/BaseStage/Stage.lua @@ -11,6 +11,8 @@ local StageBase = require("classes.stageClasses.SpecialZones.StageBase") local BlueSam = require("classes.stageClasses.SpecialZones.BlueSam") local Events = require("classes.spearhead_events") local GlobalCapManager = require("classes.capClasses.GlobalCapManager") +local CustomDrawing = require("classes.stageClasses.drawings.CustomDrawing") +local DrawingHelper = require("classes.stageClasses.drawings.helper.DrawingHelper") ---@alias StageColor ---| "RED" @@ -53,7 +55,8 @@ local GlobalCapManager = require("classes.capClasses.GlobalCapManager") --- @field protected _preActivated boolean --- @field protected _activeStage integer --- @field protected _stageConfig StageConfig ---- @field protected _stageDrawingId integer +--- @field protected _stageDrawing DrawingObject +--- @field protected _currentDrawingId integer --- @field protected _spawnedGroups Array --- @field protected _stageCompleteListeners Array --- @field protected CheckContinuousAsync fun(self:Stage, time:number) : number? @@ -65,11 +68,11 @@ Stage.__index = Stage Stage.StageColors = { - INVISIBLE = { r=0, g=0, b=0, a=0 }, - RED_ACTIVE = { r=1, g=0, b=0, a=0.15 }, - RED_PREACTIVE = { r=1, g=0, b=0, a=0.10}, - BLUE = { r=0, g=0, b=1, a=0.10}, - GRAY = { r=80/255, g=80/255, b=80/255, a=0.10 } + INVISIBLE = { 0, 0, 0, 0 }, + RED_ACTIVE = { 1, 0, 0, 0.15 }, + RED_PREACTIVE = { 1, 0, 0, 0.10}, + BLUE = { 0, 0, 1, 0.10}, + GRAY = { 80/255, 80/255, 80/255, 0.10 } } ---comment @@ -116,7 +119,34 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority local zone = DcsUtil.getZoneByName(self.zoneName) if zone then - self._stageDrawingId = DcsUtil.DrawZone(zone, Stage.StageColors.INVISIBLE, Stage.StageColors.INVISIBLE, 4) + if zone.zone_type == "Cilinder" then + ---@type Circle + local drawing = { + colorString = DrawingHelper.ColorTableToColorString( Stage.StageColors.INVISIBLE), + mapX = zone.location.x, + mapY = zone.location.y, + radius = zone.radius, + name = "DRAWING_" .. zone.name, + polygonMode = "circle", + primitiveType = "Polygon", + thickness = 1, + fillColorString = DrawingHelper.ColorTableToColorString( Stage.StageColors.INVISIBLE), + visible = true, + style = "solid" + } + + self._stageDrawing = drawing + else + local verts = {} + + ---@type Free + local drawing = { + mapX = zone.location.x, + mapY = zone.location.y, + + } + + end end self._spawnedGroups = {} @@ -253,6 +283,7 @@ function Stage:superNew(database, stageConfig, logger, initData, missionPriority end end + Events.AddStageNumberChangedListener(self) return self @@ -367,8 +398,7 @@ function Stage:AddStageCompleteListener(listener) end ---Activates all SAMS, Airbase units etc all at once. ----@param draw boolean -function Stage:PreActivate(draw) +function Stage:PreActivate() if self._preActivated == false then self._preActivated = true for key, mission in pairs(self._db.sams) do @@ -382,9 +412,7 @@ function Stage:PreActivate(draw) end end - if draw == true then - self:MarkStage(Stage.StageColors.RED_PREACTIVE) - end + self:MarkStage(Stage.StageColors.RED_PREACTIVE) end @@ -405,6 +433,8 @@ function Stage:MarkStage(stageColor) DcsUtil.SetLineColor(self._stageDrawingId, lineColor) DcsUtil.SetFillColor(self._stageDrawingId, fillColor) end + + end function Stage:ActivateStage() @@ -414,7 +444,7 @@ function Stage:ActivateStage() self:MarkStage(Stage.StageColors.RED_ACTIVE) end) - self:PreActivate(false) + self:PreActivate() self._logger:debug("Activating Misc groups for zone. Count: " .. Util.tableLength(self._db.miscGroups)) for _, miscGroup in pairs(self._db.miscGroups) do @@ -462,9 +492,9 @@ function Stage:OnStageNumberChanged(number) if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number) - self:PreActivate(true) + self:PreActivate() elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then - self:PreActivate(false) + self:PreActivate() end if number == self.stageNumber then diff --git a/src/classes/stageClasses/Stages/ExtraStage.lua b/src/classes/stageClasses/Stages/ExtraStage.lua index 2b62446..9f3b66a 100644 --- a/src/classes/stageClasses/Stages/ExtraStage.lua +++ b/src/classes/stageClasses/Stages/ExtraStage.lua @@ -47,9 +47,9 @@ function ExtraStage:OnStageNumberChanged(number) if self.stageNumber - self._activeStage == self._stageConfig.AmountPreactivateStage then self._logger:debug("Pre-activating stage: " .. self.zoneName .. " with number: " .. number) - self:PreActivate(true) + self:PreActivate() elseif GlobalCapManager.IsCapActiveWhenZoneIsActive(self.zoneName, number) == true then - self:PreActivate(false) + self:PreActivate() end if number == self.stageNumber then diff --git a/src/classes/stageClasses/drawings/helper/DrawingHelper.lua b/src/classes/stageClasses/drawings/helper/DrawingHelper.lua index fa2b179..2fc675b 100644 --- a/src/classes/stageClasses/drawings/helper/DrawingHelper.lua +++ b/src/classes/stageClasses/drawings/helper/DrawingHelper.lua @@ -149,7 +149,6 @@ function DrawingHelper.DrawPolygon(object, id, logger) local firstPoint = points[1] if firstPoint == nil or newPoint.x ~= firstPoint.x or newPoint.z ~= firstPoint.z then - logger:debug("Drawing free polygon point " .. tostring(k) .. ": " .. tostring(free.points[k].x) .. ", " .. tostring(free.points[k].y)) table.insert(points, newPoint) end end @@ -250,6 +249,17 @@ function DrawingHelper.ColorToColorTable(hexStr) return { r, g , b , a } end +---@param rgba table +---@return string +function DrawingHelper.ColorTableToColorString(rgba) + local r = string.format("%02X", math.floor(rgba[1] * 255)) + local g = string.format("%02X", math.floor(rgba[2] * 255)) + local b = string.format("%02X", math.floor(rgba[3] * 255)) + local a = string.format("%02X", math.floor(rgba[4] * 255)) + + return "0x" .. r .. g .. b .. a +end + ---@param lineStyle string function DrawingHelper.ToLineStyleInteger(lineStyle) lineStyle = lineStyle:lower() diff --git a/src/classes/stageClasses/missions/ZoneMission.lua b/src/classes/stageClasses/missions/ZoneMission.lua index 34c9c12..8be5f72 100644 --- a/src/classes/stageClasses/missions/ZoneMission.lua +++ b/src/classes/stageClasses/missions/ZoneMission.lua @@ -350,7 +350,7 @@ function ZoneMission:SpawnPersistedState() end end ----spawns the mission, but doesn't add +---spawns the mission, but doesn't add it to the mission commands. function ZoneMission:SpawnInactive() self._logger:info("PreActivating " .. self.name) diff --git a/src/classes/util/DcsUtil.lua b/src/classes/util/DcsUtil.lua index ce05cdd..172349e 100644 --- a/src/classes/util/DcsUtil.lua +++ b/src/classes/util/DcsUtil.lua @@ -636,71 +636,6 @@ do -- INIT DCS_UTIL ---@field b number ---@field a number - local drawID = 400 - ---@param zone SpearheadTriggerZone - ---@param lineColor DrawColor - ---@param fillColor DrawColor - ---@param lineStyle LineType - ---@return number drawID - function DCS_UTIL.DrawZone(zone, lineColor, fillColor, lineStyle) - if lineStyle == nil then lineStyle = 4 end - drawID = drawID + 1 - if zone.zone_type == "Cilinder" then - trigger.action.circleToAll(-1, drawID, { x = zone.location.x, y = 0, z = zone.location.y }, zone.radius, - { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, lineStyle, true) - else - local functionString = "trigger.action.markupToAll(7, -1, " .. drawID .. "," - for _, vecpoint in pairs(zone.verts) do - functionString = functionString .. " { x=" .. vecpoint.x .. ", y=0,z=" .. vecpoint.y .. "}," - end - functionString = functionString .. "{0,1,0,1}, {0,1,0,1}, " .. lineStyle .. ")" - - ---@diagnostic disable-next-line: deprecated - local f, err = loadstring(functionString) - if f then - f() - else - env.error("Something failed when drawing complex drawing" .. err) - end - end - local fillColorMapped = { - fillColor.r or 0, - fillColor.g or 0, - fillColor.b or 0, - fillColor.a or 0.5 - } - - local lineColorMapped = { - lineColor.r or 0, - lineColor.g or 0, - lineColor.b or 0, - lineColor.a or 1 - } - - trigger.action.setMarkupColorFill(drawID, fillColorMapped) - trigger.action.setMarkupColor(drawID, lineColorMapped) - - return drawID - end - - ---@param start Vec3 - ---@param finish Vec3 - ---@param lineColor DrawColor - ---@param lineStyle LineType - function DCS_UTIL.DrawLine(start, finish, lineColor, lineStyle) - if lineStyle == nil then lineStyle = 4 end - drawID = drawID + 1 - - local lineColorMapped = { - lineColor.r or 0, - lineColor.g or 0, - lineColor.b or 0, - lineColor.a or 1 - } - - trigger.action.lineToAll(-1, drawID, start, finish, lineColorMapped, lineStyle) - return drawID - end ---@param groupID number ---@param text string