Skip to content

Commit

Permalink
Ticks: Add texture chaning conditions (both use and texture path)
Browse files Browse the repository at this point in the history
Fixes: #4687
  • Loading branch information
InfusOnWoW committed Feb 10, 2024
1 parent 193618e commit e95f2fc
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 36 deletions.
4 changes: 2 additions & 2 deletions WeakAuras/Conditions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ local function formatValueForAssignment(vType, value, pathToCustomFunction, path
return tostring(value)
end
return "nil"
elseif (vType == "string") then
elseif (vType == "string" or vType == "texture") then
if type(value) == "string" then
return string.format("%s", Private.QuotedString(value))
end
Expand Down Expand Up @@ -164,7 +164,7 @@ local function formatValueForAssignment(vType, value, pathToCustomFunction, path
end

local function formatValueForCall(type, property)
if type == "bool" or type == "number" or type == "list" or type == "icon" or type == "string"
if type == "bool" or type == "number" or type == "list" or type == "icon" or type == "string" or type == "texture"
or type == "progressSource"
then
return "propertyChanges['" .. property .. "']";
Expand Down
36 changes: 36 additions & 0 deletions WeakAuras/SubRegionTypes/Tick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ local properties = {
type = "bool",
default = true,
},
tick_use_texture = {
display = L["Use Texture"],
setter = "SetUseTexture",
type = "bool",
default = true,
},
tick_texture = {
display = L["Texture"],
setter = "SetTexture",
type = "texture"
}
}

local function GetProperties(parentData, data)
Expand Down Expand Up @@ -404,6 +415,31 @@ local funcs = {
end
end
end,
UpdateTexture = function(self)
if self.use_texture then
for _, tick in ipairs(self.ticks) do
Private.SetTextureOrAtlas(tick, self.tick_texture, "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE")
end
else
for _, tick in ipairs(self.ticks) do
tick:SetColorTexture(self.tick_color[1], self.tick_color[2], self.tick_color[3], self.tick_color[4])
end
end
end,
SetTexture = function(self, texture)
if self.tick_texture == texture then
return
end
self.tick_texture = texture
self:UpdateTexture()
end,
SetUseTexture = function(self, use)
if self.use_texture == use then
return
end
self.use_texture = use
self:UpdateTexture()
end
}

local function modify(parent, region, parentData, data, first)
Expand Down
31 changes: 30 additions & 1 deletion WeakAurasOptions/ConditionOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ local function addControlsForChange(args, order, data, conditionVariable, totalA
args["condition" .. i .. "value" .. j].validate = WeakAuras.ValidateNumeric;
end
end
elseif (propertyType == "string") then
elseif (propertyType == "string" or propertyType == "texture") then
args["condition" .. i .. "value" .. j] = {
type = "input",
width = WeakAuras.normalWidth,
Expand All @@ -528,6 +528,35 @@ local function addControlsForChange(args, order, data, conditionVariable, totalA
set = setValue
}
order = order + 1;
if propertyType == "texture" then
args["condition" .. i .. "value" .. j].width = WeakAuras.normalWidth - 0.15
args["condition" .. i .. "value_browse" .. j] = {
type = "execute",
name = L["Choose"],
width = 0.15,
order = order,
func = function()
if data.controlledChildren then
local paths = {}
for id, reference in pairs(conditions[i].changes[j].references) do
paths[id] = {"conditions", conditions[i].check.references[id].conditionIndex, "changes", reference.changeIndex}
end
OptionsPrivate.OpenTexturePicker(data, paths,
{texture = "value"},
OptionsPrivate.Private.texture_types)
else
OptionsPrivate.OpenTexturePicker(data, {[data.id] = { "conditions", i, "changes", j } },
{texture = "value"},
OptionsPrivate.Private.texture_types)
end
end,
imageWidth = 24,
imageHeight = 24,
control = "WeakAurasIcon",
image = "Interface\\AddOns\\WeakAuras\\Media\\Textures\\browse",
}
order = order + 1;
end
elseif (propertyType == "icon") then
args["condition" .. i .. "value" .. j] = {
type = "input",
Expand Down
36 changes: 19 additions & 17 deletions WeakAurasOptions/OptionsFrames/TexturePicker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ local function CompareValues(a, b)
end
end

local function GetAll(baseObject, path, property, default)
local function GetAll(baseObject, paths, property, default)
local valueFromPath = OptionsPrivate.Private.ValueFromPath
if not property then
return default
Expand All @@ -46,7 +46,7 @@ local function GetAll(baseObject, path, property, default)
local result = default
local first = true
for child in OptionsPrivate.Private.TraverseLeafsOrAura(baseObject) do
local childObject = valueFromPath(child, path)
local childObject = valueFromPath(child, paths[child.id])
if childObject and childObject[property] then
if first then
result = childObject[property]
Expand All @@ -61,10 +61,10 @@ local function GetAll(baseObject, path, property, default)
return result
end

local function SetAll(baseObject, path, property, value, width, height, adjustSize)
local function SetAll(baseObject, paths, property, value, width, height, adjustSize)
local valueFromPath = OptionsPrivate.Private.ValueFromPath
for child in OptionsPrivate.Private.TraverseLeafsOrAura(baseObject) do
local object = valueFromPath(child, path)
local object = valueFromPath(child, paths[child.id])
if object then
object[property] = value
if adjustSize and width and height then
Expand Down Expand Up @@ -255,17 +255,17 @@ local function ConstructTexturePicker(frame)
wipe(group.selectedTextures)
group.selectedTextures[texturePath] = true

SetAll(self.baseObject, self.path, self.properties.texture, texturePath, width, height, self.adjustSize)
SetAll(self.baseObject, self.paths, self.properties.texture, texturePath, width, height, self.adjustSize)

group:UpdateList();
local status = dropdown.status or dropdown.localstatus
dropdown.dropdown:SetText(dropdown.list[status.selected]);
end

function group.Open(self, baseObject, path, properties, textures, SetTextureFunc, adjustSize)
function group.Open(self, baseObject, paths, properties, textures, SetTextureFunc, adjustSize)
local valueFromPath = OptionsPrivate.Private.ValueFromPath
self.baseObject = baseObject
self.path = path
self.paths = paths
self.properties = properties
self.textures = textures;
self.SetTextureFunc = SetTextureFunc
Expand All @@ -274,29 +274,31 @@ local function ConstructTexturePicker(frame)
self.adjustSize = adjustSize

for child in OptionsPrivate.Private.TraverseLeafsOrAura(baseObject) do
local object = valueFromPath(child, path)
local object = valueFromPath(child, paths[child.id])
if object and object[properties.texture] then
self.givenPath[child.id] = object[properties.texture]
self.selectedTextures[object[properties.texture]] = true
local texture = object[properties.texture]
self.givenPath[child.id] = texture
self.selectedTextures[texture] = true
else
self.givenPath[child.id] = ""
end
end

local colorAll = GetAll(baseObject, path, properties.color, {1, 1, 1, 1});
local colorAll = GetAll(baseObject, paths, properties.color, {1, 1, 1, 1});
self.textureData = {
r = colorAll[1] or 1,
g = colorAll[2] or 1,
b = colorAll[3] or 1,
a = colorAll[4] or 1,
auraRotation = GetAll(baseObject, path, properties.auraRotation, 0),
texRotation = GetAll(baseObject, path, properties.rotation, 0),
mirror = GetAll(baseObject, path, properties.mirror, false),
blendMode = GetAll(baseObject, path, properties.blendMode, "ADD")
auraRotation = GetAll(baseObject, paths, properties.auraRotation, 0),
texRotation = GetAll(baseObject, paths, properties.rotation, 0),
mirror = GetAll(baseObject, paths, properties.mirror, false),
blendMode = GetAll(baseObject, paths, properties.blendMode, "ADD")
}

frame.window = "texture";
frame:UpdateFrameVisible()
group:UpdateList()
local _, givenPath = next(self.givenPath)
local picked = false;
for categoryName, category in pairs(self.textures) do
if not(picked) then
Expand Down Expand Up @@ -327,7 +329,7 @@ local function ConstructTexturePicker(frame)
function group.CancelClose()
local valueFromPath = OptionsPrivate.Private.ValueFromPath
for child in OptionsPrivate.Private.TraverseLeafsOrAura(group.baseObject) do
local childObject = valueFromPath(child, group.path)
local childObject = valueFromPath(child, group.paths[child.id])
if childObject then
childObject[group.properties.texture] = group.givenPath[child.id]
WeakAuras.Add(child);
Expand Down
7 changes: 6 additions & 1 deletion WeakAurasOptions/RegionOptions/AuraBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ local function createOptions(id, data)
width = 0.15,
order = 44.1,
func = function()
OptionsPrivate.OpenTexturePicker(data, {}, {
local path = {}
local paths = {}
for child in OptionsPrivate.Private.TraverseLeafsOrAura(data) do
paths[child.id] = path
end
OptionsPrivate.OpenTexturePicker(data, paths, {
texture = "sparkTexture",
color = "sparkColor",
rotation = "sparkRotation",
Expand Down
14 changes: 12 additions & 2 deletions WeakAurasOptions/RegionOptions/ProgressTexture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ local function createOptions(id, data)
width = 0.15,
order = 2,
func = function()
OptionsPrivate.OpenTexturePicker(data, {}, {
local path = {}
local paths = {}
for child in OptionsPrivate.Private.TraverseLeafsOrAura(data) do
paths[child.id] = path
end
OptionsPrivate.OpenTexturePicker(data, paths, {
texture = "foregroundTexture",
color = "foregroundColor",
texRotation = "rotation",
Expand Down Expand Up @@ -48,7 +53,12 @@ local function createOptions(id, data)
width = 0.15,
order = 6,
func = function()
OptionsPrivate.OpenTexturePicker(data, {}, {
local path = {}
local paths = {}
for child in OptionsPrivate.Private.TraverseLeafsOrAura(data) do
paths[child.id] = path
end
OptionsPrivate.OpenTexturePicker(data, paths, {
texture = "backgroundTexture",
color = "backgroundColor",
texRotation = "rotation",
Expand Down
24 changes: 17 additions & 7 deletions WeakAurasOptions/RegionOptions/StopMotion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ local function createOptions(id, data)
name = L["Choose"],
order = 2,
func = function()
OptionsPrivate.OpenTexturePicker(data, {}, {
local path = {}
local paths = {}
for child in OptionsPrivate.Private.TraverseLeafsOrAura(data) do
paths[child.id] = path
end
OptionsPrivate.OpenTexturePicker(data, paths, {
texture = "foregroundTexture",
color = "foregroundColor",
mirror = "mirror",
Expand Down Expand Up @@ -378,12 +383,17 @@ local function createOptions(id, data)
name = L["Choose"],
order = 20,
func = function()
OptionsPrivate.OpenTexturePicker(data, {}, {
texture = "backgroundTexture",
color = "backgroundColor",
mirror = "mirror",
blendMode = "blendMode"
}, texture_types, setTextureFunc, true);
local path = {}
local paths = {}
for child in OptionsPrivate.Private.TraverseLeafsOrAura(data) do
paths[child.id] = path
end
OptionsPrivate.OpenTexturePicker(data, paths, {
texture = "backgroundTexture",
color = "backgroundColor",
mirror = "mirror",
blendMode = "blendMode"
}, texture_types, setTextureFunc, true);
end,
disabled = function() return data.sameTexture or data.hideBackground; end,
hidden = function() return data.hideBackground end,
Expand Down
7 changes: 6 additions & 1 deletion WeakAurasOptions/RegionOptions/Texture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ local function createOptions(id, data)
width = 0.15,
order = 1.1,
func = function()
OptionsPrivate.OpenTexturePicker(data, {}, {
local path = {}
local paths = {}
for child in OptionsPrivate.Private.TraverseLeafsOrAura(data) do
paths[child.id] = path
end
OptionsPrivate.OpenTexturePicker(data, paths, {
texture = "texture",
color = "color",
mirror = "mirror",
Expand Down
9 changes: 6 additions & 3 deletions WeakAurasOptions/SubRegionOptions/Tick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ local function createOptions(parentData, data, index, subIndex)
width = 0.15,
order = 12.5,
func = function()
OptionsPrivate.OpenTexturePicker(parentData, {
"subRegions", index
}, {
local path = { "subRegions", index }
local paths = {}
for child in OptionsPrivate.Private.TraverseLeafsOrAura(parentData) do
paths[child.id] = path
end
OptionsPrivate.OpenTexturePicker(parentData, paths, {
texture = "tick_texture",
color = "tick_color",
blendMode = "tick_blend_mode"
Expand Down
4 changes: 2 additions & 2 deletions WeakAurasOptions/WeakAurasOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1679,8 +1679,8 @@ function WeakAuras.UpdateThumbnail(data)
button:UpdateThumbnail()
end

function OptionsPrivate.OpenTexturePicker(baseObject, path, properties, textures, SetTextureFunc, adjustSize)
frame.texturePicker:Open(baseObject, path, properties, textures, SetTextureFunc, adjustSize)
function OptionsPrivate.OpenTexturePicker(baseObject, paths, properties, textures, SetTextureFunc, adjustSize)
frame.texturePicker:Open(baseObject, paths, properties, textures, SetTextureFunc, adjustSize)
end

function OptionsPrivate.OpenIconPicker(baseObject, paths, groupIcon)
Expand Down

0 comments on commit e95f2fc

Please sign in to comment.