• 0

    posted a message on AceGui:Fire issue

     Problem and fix verified. After introducing a control id and re-registering to the color picker on config window reload, now everything is working perfectly.

     

    Thread can be closed. Really helped to write things down.

    Posted in: Lua Code Discussion
  • 0

    posted a message on AceGui:Fire issue

    I think I have found the problem.

     

    When the callback is fired it does sometinh like this:

     

    local function HealthBarInVehicleColorChanged(self, event, r, g, b, a)
    	--Healcsi:Print("HealthBarInVehicleColorChanged")
    	Core:SetHealthInVehicleColor(r, g, b, a)
    	Healcsi:BroadcastEvent("HealthBarInVehicleColorChanged")
    	Healcsi:BroadcastEvent("CoreConfigChanged")
    end

    And the Broadcastevent "CoreConfigChanged" reloads the config window. What I think happens is that the controller gets destroyed (released) and another gets created, or some sort of resource re-allocation happens and the controls will get different frames and this confuses it.

    Thanks

    Posted in: Lua Code Discussion
  • 0

    posted a message on AceGui:Fire issue

    If i change my 

    control:Fire("OnValueChanged", r, g, b, a)

    to

    local control = Healcsi.ColorPicker.frame.obj
    Healcsi:Print("Before Fire: " .. control.text:GetText())
    --control:Fire("OnValueChanged", r, g, b, a)
    
    if control.events["OnValueChanged"] then
    	local success, ret = pcall(control.events["OnValueChanged"], control, "OnValueChanged", r, g, b, a)
    end
    
    Healcsi:Print("After Fire: " .. control.text:GetText())

     

    I get the same result: https://puu.sh/vAezJ/be9a3c07c8.jpg
    I don't understand why. So it's a pcall issue. The callback gets called and then it changes the "self" :/

    Posted in: Lua Code Discussion
  • 0

    posted a message on AceGui:Fire issue

    Hello.

    I'm writing a heal addon. It's still a work in progress. I've been facing an isue for a couple of days and I can't find the solution.

    The prblem is with one of my custom AceGui element. I call it HealcsiColorPicker. And yes it's a color picker (see: https://puu.sh/vAaIl/fd929dd256.png)

     

    I have a configuration window where I put multiple color controls: 

     

    local healtBarModeValueGroup = Gui:Create("InlineGroup")
    healtBarModeValueGroup:SetFullWidth(true)
    healtBarModeValueGroup:SetLayout("Flow")
    healtBarModeValueGroup:SetTitle("HealthBar Modes")
    
    local healthBarOfflineColorPicker = Gui:Create("HealcsiColorPicker")
    healthBarOfflineColorPicker:SetHasAlpha(true)
    healthBarOfflineColorPicker:SetFullWidth(true)
    healthBarOfflineColorPicker:SetCallback("OnValueChanged", HealthBarOfflineColorChanged)
    healthBarOfflineColorPicker:SetLabel("Offline background color and opacity")
    color = Core:GetHealthBarOfflineColor()
    healthBarOfflineColorPicker:SetRGBAColor(color.r, color.g, color.b, color.a)
    
    local healthBarInVehicleColorPicker = Gui:Create("HealcsiColorPicker")
    healthBarInVehicleColorPicker:SetHasAlpha(true)
    healthBarInVehicleColorPicker:SetFullWidth(true)
    healthBarInVehicleColorPicker:SetCallback("OnValueChanged", HealthBarInVehicleColorChanged)
    healthBarInVehicleColorPicker:SetLabel("In vehicle background color and opacity")
    color = Core:GetHealthInVehicleColor()
    healthBarInVehicleColorPicker:SetRGBAColor(color.r, color.g, color.b, color.a)
    
    local healthBarPetColorPicker = Gui:Create("HealcsiColorPicker")
    healthBarPetColorPicker:SetHasAlpha(true)
    healthBarPetColorPicker:SetFullWidth(true)
    healthBarPetColorPicker:SetCallback("OnValueChanged", HealthBarPetColorChanged)
    healthBarPetColorPicker:SetLabel("Pet background color and opacity")
    color = Core:GetHealthBarPetColor()
    healthBarPetColorPicker:SetRGBAColor(color.r, color.g, color.b, color.a)
    
    healtBarModeValueGroup:AddChildren(healthBarOfflineColorPicker, healthBarInVehicleColorPicker, healthBarPetColorPicker)

     

    Inside the Color Picker I create a frame and I set a "OnClick" script for it:

     

    local function Constructor()
      local num = AceGUI:GetNextWidgetNum(Type)
    
      local frame = CreateFrame("Button", "HealcsiColorPicker" .. num, UIParent)
      frame:Hide()
    
      frame:SetSize(20,20)
      frame:EnableMouse(true)
      frame:SetScript("OnClick", OnClick)

     

    The OnClick method then gets the frame.obj and sets it as the color pickers control object: (The color picker is static. Only one Healcsi.ColorPicker is available, but many aceGui objects can be created, and on click they will change the color picker to use the currently selected/cliscked control)

     

    local function OnClick(frame)
    	if not(Healcsi.ColorPicker) then return end
    
    	--self = frame.obj
    	--if not self.disabled then
    
    		Healcsi.ColorPicker.control = frame.obj
    		local control = Healcsi.ColorPicker.control
    
    		Healcsi:Print("Registering: " .. control.text:GetText())
    
    		Healcsi.ColorPicker.init = {}
    		Healcsi.ColorPicker.init.r = control.r
    		Healcsi.ColorPicker.init.g = control.g
    		Healcsi.ColorPicker.init.b = control.b
    		Healcsi.ColorPicker.init.a = control.a
    
    		Healcsi.ColorPicker.r = control.r
    		Healcsi.ColorPicker.g = control.g
    		Healcsi.ColorPicker.b = control.b
    		Healcsi.ColorPicker.a = control.a
    
    		Healcsi.ColorPicker:Show()
    
    		if control.HasAlpha then
    			Healcsi.ColorPicker.content.aSlider:SetDisabled(false)
    		else
    			Healcsi.ColorPicker.content.aSlider:SetValue(255)
    			Healcsi.ColorPicker.content.aSlider:SetDisabled(true)
    		end
    
    		UpdateRGBColor()
    	--end
    end

     

    At the end there is an UpdateRGBColor() that fires the event:

     

    local control = Healcsi.ColorPicker.control
    
    Healcsi:Print("Before Fire: " .. control.text:GetText())
    
    control:Fire("OnValueChanged", r, g, b, a)
    
    Healcsi:Print("After Fire: " .. control.text:GetText())

     

    My problem is the following: The control changes after the Fire event: https://puu.sh/vAbik/732be8bc75.png

    As if I would have jumped to another control and I'm changeing the color of somethng else. If I remove the Fire event, then the control doesn't change.

     

    If you need more information you can find the addon's current version here: https://www.dropbox.com/s/4qx4j6rlx5v64gl/Healcsi.zip?dl=0

    (The custom widget is at: Healcsi\Editor\AceGUIWidget-HealcsiColorPicker.lua)

    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.