File size: 3,941 Bytes
b6a38d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
if FirstLoad then
GedSatelliteSectorEditor = false
g_SelectedSatelliteSectors = false
end
TableProperties.directions_set = true
function GetSatelliteSectorsGridBox(campaign)
local grid_sz_x, grid_sz_y = campaign.sector_columns*campaign.sector_size:x(), (campaign.sector_rows - campaign.sector_rowsstart + 1)*campaign.sector_size:y()
local x, y = CabinetSectorsCenter:xy()
return box(x - grid_sz_x/2, y - grid_sz_y/2, x + grid_sz_x/2, y + grid_sz_y/2)
end
function GetSatelliteSectorOnPos(pos, bMapSector)
local campaign = GetCurrentCampaignPreset()
if not campaign then return end
local grid_bx = GetSatelliteSectorsGridBox(campaign)
local sz_x, sz_y = campaign.sector_size:xy()
pos = pos:SetInvalidZ()
if pos:InBox(grid_bx) then
local pt = pos - grid_bx:min()
local id = sector_pack(pt:y() / sz_y + 1, pt:x() / sz_x + 1)
if bMapSector then
return table.find_value(GetSatelliteSectors(), "Id", id)
else
return gv_Sectors[id]
end
end
end
function SectorEditorLabel(sector)
if sector.GroundSector then return end
if not sector.Map then return end
local text = Text:new()
text:SetTextStyle("Console")
local h, s, v = UIL.RGBtoHSV(255, 32, 32)
h = (170 - 64 + xxhash(sector.WeatherZone) % 128)
text:SetColor(RGB(UIL.HSVtoRGB(h, s, v)))
text:SetShadowOffset(1)
text:SetText(sector.Id .. (sector.WeatherZone and ("\n" .. sector.WeatherZone) or ""))
if sector.MapPosition then
text:SetPos(sector.MapPosition)
end
return text
end
function SelectEditorSatelliteSector(sel)
g_SelectedSatelliteSectors = sel or false
if g_SatelliteUI then
g_SatelliteUI:UpdateAllSectorVisuals()
SatelliteSetCameraDest(sel and sel[1].Id, 0)
DbgClearSectorTexts()
for i, s in ipairs(sel) do
DbgAddSectorText(s.Id, _InternalTranslate(T{817728326241, "<SectorName()>", s}))
end
end
end
function OnMsg.OnSectorClick(sector)
local shift = terminal.IsKeyPressed(const.vkShift)
if shift then
table.insert_unique(g_SelectedSatelliteSectors, sector)
end
SelectEditorSatelliteSector(shift and g_SelectedSatelliteSectors or {sector})
UpdateGedSatelliteSectorEditorSel()
end
function IsSatelliteViewEditorActive()
return not not GetDialog("PDADialogSatelliteEditor")
end
function OpenGedSatelliteSectorEditor(campaign)
CreateRealTimeThread(function()
EditorDeactivate()
OpenDialog("PDADialogSatelliteEditor", GetInGameInterface(), { satellite_editor = true })
if GedSatelliteSectorEditor then
GedSatelliteSectorEditor:Send("rfnApp", "Exit")
GedSatelliteSectorEditor = false
end
PopulateParentTableCache(Presets.CampaignPreset)
GedSatelliteSectorEditor = OpenGedApp("GedSatelliteSectorEditor", GetSatelliteSectors(true), { WarningsUpdateRoot = "root" } ) or false
end)
end
function GedSatelliteSectorEditorOnClose()
CloseDialog("PDADialogSatelliteEditor")
GedSatelliteSectorEditor = false
SelectEditorSatelliteSector()
end
function CloseGedSatelliteSectorEditor()
if GedSatelliteSectorEditor then
GedSatelliteSectorEditor:Send("rfnApp", "Exit")
end
end
function UpdateGedSatelliteSectorEditorSel()
if GedSatelliteSectorEditor then
local list = GedSatelliteSectorEditor:ResolveObj("root")
CreateRealTimeThread(function()
local sel = {}
for _, obj in ipairs(g_SelectedSatelliteSectors) do
sel[#sel + 1] = table.find(list, "Id", obj.Id) or nil
end
GedSatelliteSectorEditor:SetSelection("root", sel)
end)
end
end
function OnMsg.GedClosing(ged_id)
if GedSatelliteSectorEditor and GedSatelliteSectorEditor.ged_id == ged_id then
GedSatelliteSectorEditorOnClose()
end
end
function OnMsg.GedOnEditorSelect(obj, selected, editor)
if editor == GedSatelliteSectorEditor and selected then
SelectEditorSatelliteSector{obj}
end
end
function OnMsg.GedOnEditorMultiSelect(data, selected, editor)
if editor == GedSatelliteSectorEditor and selected then
SelectEditorSatelliteSector(data.__objects)
end
end
OnMsg.ChangeMap = CloseGedSatelliteSectorEditor |