File size: 7,081 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
if FirstLoad then
s_CameraFadeThread = false
end
function DeleteCameraFadeThread()
if s_CameraFadeThread then
DeleteThread(s_CameraFadeThread)
s_CameraFadeThread = false
end
end
function CameraShowClose(last_camera)
DeleteCameraFadeThread()
if last_camera then
last_camera:RevertProperties()
end
UnlockCamera("CameraPreset")
end
function SwitchToCamera(camera, old_camera, in_between_callback, dont_lock, ged)
if not CanYield() then
DeleteCameraFadeThread()
s_CameraFadeThread = CreateRealTimeThread(function()
SwitchToCamera(camera, old_camera, in_between_callback, dont_lock, ged)
end)
return
end
if IsEditorActive() then
editor.ClearSel()
editor.AddToSel({camera})
end
if old_camera then
old_camera:RevertProperties(not(camera.flip_to_adjacent and old_camera.flip_to_adjacent))
end
if in_between_callback then
in_between_callback()
end
camera:ApplyProperties(dont_lock, not(camera.flip_to_adjacent and old_camera.flip_to_adjacent), ged)
end
function ShowPredefinedCamera(id)
local cam = PredefinedCameras[id]
if not cam then
print("No such camera preset: ", id)
return
end
CreateRealTimeThread(cam.ApplyProperties, cam, "dont_lock")
end
function GedOpCreateCameraDest(ged, selected_camera)
if not selected_camera or not IsKindOf(selected_camera, "Camera") then return end
selected_camera:SetDest(selected_camera)
GedObjectModified(selected_camera)
end
function GedOpUpdateCamera(ged, selected_camera)
if not selected_camera or not IsKindOf(selected_camera, "Camera") then return end
selected_camera:QueryProperties()
GedObjectModified(selected_camera)
end
function GedOpViewMovement(ged, selected_camera)
if not selected_camera or not IsKindOf(selected_camera, "Camera") then return end
SwitchToCamera(selected_camera, nil, nil, "don't lock")
end
function GedOpIsViewMovementToggled()
return not not GetDialog("Showcase")
end
local function TakeCameraScreenshot(ged, path, sector, camera)
if GetMapName() ~= camera.map then
ChangeMap(camera.map)
end
camera:ApplyProperties()
local oldInterfaceInScreenshot = hr.InterfaceInScreenshot
hr.InterfaceInScreenshot = camera.interface and 1 or 0
local image = string.format("%s/%s.png", path, sector)
AsyncFileDelete(image)
WaitNextFrame(3)
local store = {}
Msg("BeforeUpsampledScreenshot", store)
WaitNextFrame()
MovieWriteScreenshot(image, 0, 64, false, 3840, 2160)
WaitNextFrame()
Msg("AfterUpsampledScreenshot", store)
hr.InterfaceInScreenshot = oldInterfaceInScreenshot
camera:RevertProperties()
return image
end
function GedOpTakeScreenshots(ged, camera)
if not camera then return end
local campaign = Game and Game.Campaign or rawget(_G, "DefaultCampaign") or "HotDiamonds"
local campaign_presets = rawget(_G, "CampaignPresets") or empty_table
local sectors = campaign_presets[campaign] and campaign_presets[campaign].Sectors or empty_table
local map_to_sector = {[false] = ""}
for _, sector in ipairs(sectors) do
if sector.Map then
map_to_sector[sector.Map] = sector.Id
end
end
local path = string.format("svnAssets/Source/UI/LoadingScreens/%s", campaign)
local err = AsyncCreatePath(path)
if err then
local os_path = ConvertToOSPath(path)
ged:ShowMessage("Error", string.format("Can't create '%s' folder!", os_path))
return
end
local ok, result = SVNAddFile(path)
if not ok then
ged:ShowMessage("SVN Error", result)
end
StopAllHiding("CameraEditorScreenshots", 0, 0)
local size = UIL.GetScreenSize()
ChangeVideoMode(3840, 2160, 0, false, true)
WaitChangeVideoMode()
LockCamera("Screenshot")
local images = {}
if IsKindOf(camera, "Camera") then
images[1] = TakeCameraScreenshot(ged, path, map_to_sector[camera.map], camera)
else
local cameras = IsKindOf(camera, "GedMultiSelectAdapter") and camera.__objects or camera
table.sort(cameras, function(a, b) return a.map < b.map end)
for _, cam in ipairs(cameras) do
table.insert(images, TakeCameraScreenshot(ged, path, map_to_sector[cam.map], cam))
end
end
UnlockCamera("Screenshot")
ChangeVideoMode(size:x(), size:y(), 0, false, true)
WaitChangeVideoMode()
ResumeAllHiding("CameraEditorScreenshots")
local ok, result = SVNAddFile(images)
if not ok then
ged:ShowMessage("SVN Error", result)
end
print("Taking screenshots and adding to SubVersion done.")
end
function OnMsg.GedOnEditorSelect(obj, selected, ged_editor)
if obj and IsKindOf(obj, "Camera") and selected then
SwitchToCamera(obj, IsKindOf(ged_editor.selected_object, "Camera") and ged_editor.selected_object, nil, "don't lock", ged_editor)
end
end
function GedOpUnlockCamera()
camera.Unlock()
end
function GedOpMaxCamera()
cameraMax.Activate(1)
end
function GedOpTacCamera()
cameraTac.Activate(1)
end
function GedOpRTSCamera()
cameraRTS.Activate(1)
end
function GedOpSaveCameras()
local class = _G["Camera"]
class:SaveAll("save all", "user request")
end
function GedOpCreateReferenceImages()
CreateReferenceImages()
end
-- run to save a screenshot with every camera at correct video mode!
function CreateReferenceImages()
if not IsRealTimeThread() then
CreateRealTimeThread(CreateReferenceImages)
return
end
local folder = "svnAssets/Tests/ReferenceImages"
local cameras = Presets.Camera["reference"]
SetMouseDeltaMode(true)
SetLightmodel(0, LightmodelPresets.ArtPreview, 0)
local size = UIL.GetScreenSize()
ChangeVideoMode(512, 512, 0, false, true)
WaitChangeVideoMode()
local created = 0
for _, cam in ipairs(cameras) do
if GetMapName() ~= cam.map then
ChangeMap(cam.map)
end
cam:ApplyProperties()
Sleep(3000)
AsyncCreatePath(folder)
local image = string.format("%s/%s.png", folder, cam.id)
AsyncFileDelete(image)
if not WriteScreenshot(image, 512, 512) then
print(string.format("Failed to create screenshot '%s'", image))
else
created = created + 1
end
Sleep(300)
cam:RevertProperties()
end
SetMouseDeltaMode(false)
ChangeVideoMode(size:x(), size:y(), 0, false, true)
WaitChangeVideoMode()
print(string.format("Creating %d reference images in '%s' finished.", created, folder))
end
function GetShowcaseCameras(context)
local cameras = Presets.Camera[context and context.group or "reference"] or {}
table.sort(cameras, function(a, b)
if a.map==b.map then
return a.order < b.order
else
return a.map<b.map
end
end)
return cameras
end
function OpenShowcase(root, obj, context)
if GetDialog("Showcase") then
CloseDialog("Showcase")
return
end
if obj and IsKindOf(obj, "Camera") then
local group = obj.group
context = context or {}
context.group = group
elseif obj and type(obj)== "table" and next(obj) then
local group = obj[1].group
context = context or {}
context.group = group
end
OpenDialog("Showcase", nil, context)
end
function OnMsg.GameEnterEditor()
CloseDialog("Showcase")
end
function IsCameraEditorOpened()
local ged = FindGedApp("PresetEditor")
if not ged then return end
local sel = type(ged.selected_object) == "table" and ged.selected_object[1] or ged.selected_object
return IsKindOf(sel, "Camera")
end
|