Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c31cc6a552 |
@@ -0,0 +1,112 @@
|
|||||||
|
local Logger = require("classes.util.Logger")
|
||||||
|
local logger = Logger.new("ImageDisplay")
|
||||||
|
|
||||||
|
---@class ImageDisplay
|
||||||
|
local ImageDisplay = {}
|
||||||
|
|
||||||
|
---@param unit Unit
|
||||||
|
---@param settings ImageDisplaySettings
|
||||||
|
function ImageDisplay.outImageToUnit(unit, settings)
|
||||||
|
if unit == nil then return end
|
||||||
|
settings:ValidateOrSetDefaults() --Overwrites wrong settings
|
||||||
|
if settings.picPath == nil then
|
||||||
|
logger:warn("No picture path provided for unit display.")
|
||||||
|
return -- Nothing to display
|
||||||
|
end
|
||||||
|
ImageDisplay.outImage("a_out_picture_u",
|
||||||
|
unit,
|
||||||
|
settings.picPath,
|
||||||
|
settings.duration,
|
||||||
|
settings.clearview,
|
||||||
|
settings.delay,
|
||||||
|
settings.horizontalAlignment,
|
||||||
|
settings.verticalAlignment,
|
||||||
|
settings.size,
|
||||||
|
settings.sizeUnits
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param group Group
|
||||||
|
---@param settings ImageDisplaySettings
|
||||||
|
function ImageDisplay.outImageToGroup(group, settings)
|
||||||
|
if group == nil then return end
|
||||||
|
settings:ValidateOrSetDefaults() --Overwrites wrong settings
|
||||||
|
if settings.picPath == nil then
|
||||||
|
logger:warn("No picture path provided for group display.")
|
||||||
|
return -- Nothing to display
|
||||||
|
end
|
||||||
|
ImageDisplay.outImage("a_out_picture_g",
|
||||||
|
group,
|
||||||
|
settings.picPath,
|
||||||
|
settings.duration,
|
||||||
|
settings.clearview,
|
||||||
|
settings.delay,
|
||||||
|
settings.horizontalAlignment,
|
||||||
|
settings.verticalAlignment,
|
||||||
|
settings.size,
|
||||||
|
settings.sizeUnits
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@alias OutPictureTriggerName
|
||||||
|
---| "a_out_picture_u"
|
||||||
|
---| "a_out_picture_g"
|
||||||
|
|
||||||
|
---@private
|
||||||
|
---@param object Unit|Group
|
||||||
|
---@param triggerName OutPictureTriggerName
|
||||||
|
---@param picPath string
|
||||||
|
---@param duration number
|
||||||
|
---@param clearview boolean
|
||||||
|
---@param delay number
|
||||||
|
---@param horizontalAlignment ImageDisplaySettings.HorizontalAlignment
|
||||||
|
---@param verticalAlignment ImageDisplaySettings.VerticalAlignment
|
||||||
|
---@param size number
|
||||||
|
---@param sizeUnits ImageDisplaySettings.SizeUnits
|
||||||
|
function ImageDisplay.outImage(triggerName, object, picPath, duration, clearview, delay, horizontalAlignment, verticalAlignment, size, sizeUnits)
|
||||||
|
|
||||||
|
---@type number
|
||||||
|
local id
|
||||||
|
if triggerName == "a_out_picture_u" then
|
||||||
|
object = object --[[@as Unit]]
|
||||||
|
id = object:getID()
|
||||||
|
elseif triggerName == "a_out_picture_g" then
|
||||||
|
object = object --[[@as Group]]
|
||||||
|
id = object:getID()
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
a_out_picture_u(
|
||||||
|
unitID:number,
|
||||||
|
filePath:string,
|
||||||
|
showTime:number,
|
||||||
|
clearview:boolean,
|
||||||
|
startDelayTime:number,
|
||||||
|
horzAlignment:string,
|
||||||
|
vertAlignment:string,
|
||||||
|
size:number,
|
||||||
|
size_units:string
|
||||||
|
) -- args may not correct.
|
||||||
|
]]
|
||||||
|
|
||||||
|
local cmdString = string.format(triggerName .. '(%d, "%s", %d, %s, %d, "%d", "%d", %d, "%d")',
|
||||||
|
id,
|
||||||
|
picPath,
|
||||||
|
duration,
|
||||||
|
clearview,
|
||||||
|
delay,
|
||||||
|
horizontalAlignment,
|
||||||
|
verticalAlignment,
|
||||||
|
size,
|
||||||
|
sizeUnits)
|
||||||
|
|
||||||
|
local f, err = loadstring(cmdString)
|
||||||
|
if f then
|
||||||
|
f()
|
||||||
|
else
|
||||||
|
logger:error("Something failed when drawing complex drawing" .. err)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return ImageDisplay
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
|
||||||
|
---@class ImageDisplaySettings
|
||||||
|
---@field picPath string?
|
||||||
|
---@field duration number
|
||||||
|
---@field clearview boolean
|
||||||
|
---@field delay number
|
||||||
|
---@field horizontalAlignment ImageDisplaySettings.HorizontalAlignment
|
||||||
|
---@field verticalAlignment ImageDisplaySettings.VerticalAlignment
|
||||||
|
---@field size number
|
||||||
|
---@field sizeUnits ImageDisplaySettings.SizeUnits
|
||||||
|
local ImageDisplaySettings = {}
|
||||||
|
ImageDisplaySettings.__index = ImageDisplaySettings
|
||||||
|
|
||||||
|
---@enum ImageDisplaySettings.VerticalAlignment
|
||||||
|
ImageDisplaySettings.VerticalAlignment = {
|
||||||
|
Top = "0",
|
||||||
|
Center = "1",
|
||||||
|
Bottom = "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
---@enum ImageDisplaySettings.HorizontalAlignment
|
||||||
|
ImageDisplaySettings.HorizontalAlignment = {
|
||||||
|
Left = "0",
|
||||||
|
Center = "1",
|
||||||
|
Right = "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
---@enum ImageDisplaySettings.SizeUnits
|
||||||
|
ImageDisplaySettings.SizeUnits = {
|
||||||
|
OriginalSize = "0",
|
||||||
|
WindowSize = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImageDisplaySettings.new()
|
||||||
|
local self = setmetatable({}, ImageDisplaySettings)
|
||||||
|
self.picPath = nil
|
||||||
|
self.duration = 30
|
||||||
|
self.clearview = false
|
||||||
|
self.delay = 0
|
||||||
|
self.horizontalAlignment = ImageDisplaySettings.HorizontalAlignment.Center
|
||||||
|
self.verticalAlignment = ImageDisplaySettings.VerticalAlignment.Center
|
||||||
|
self.size = 100
|
||||||
|
self.sizeUnits = ImageDisplaySettings.SizeUnits.OriginalSize
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function ImageDisplaySettings:ValidateOrSetDefaults()
|
||||||
|
if self.picPath == "" then self.picPath = nil end
|
||||||
|
if self.duration == nil or self.duration <= 0 then self.duration = 30 end
|
||||||
|
if self.clearview == nil then self.clearview = false end
|
||||||
|
if self.delay == nil then self.delay = 0 end
|
||||||
|
if self.horizontalAlignment == nil then self.horizontalAlignment = ImageDisplaySettings.HorizontalAlignment.Center end
|
||||||
|
if self.verticalAlignment == nil then self.verticalAlignment = ImageDisplaySettings.VerticalAlignment.Center end
|
||||||
|
if self.size == nil or self.size <= 0 then self.size = 100 end
|
||||||
|
if self.sizeUnits == nil then self.sizeUnits = ImageDisplaySettings.SizeUnits.OriginalSize end
|
||||||
|
end
|
||||||
|
|
||||||
|
return ImageDisplaySettings
|
||||||
Reference in New Issue
Block a user