Thread Tools Display Modes
04-26-12, 10:49 AM   #1
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
KGPanels script help again :)

Weird question, I guess....is there a way to script a panel to show or hide, depending on time of day? A.M. or P.M., I mean?
__________________
  Reply With Quote
04-26-12, 06:23 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You wouldn't actually be able to hide the panel, since hidden frames don't run OnUpdate scripts and you'd then have no way to detect when it changed back to the other half of the day, but you could set its opacity to 0:

Panel OnUpdate handler:
Code:
	local hour = tonumber(date("%H"))
	if hour > 12 then
		-- PM
		self:SetAlpha(0)
	else
		-- AM
		self:SetAlpha(1)
	end
If your frame is mouse-enabled, you would also want to disable the mouse:
Code:
	local hour = tonumber(date("%H"))
	if hour > 12 then -- PM
		-- Hide this panel:
		self:SetAlpha(0)
		self:EnableMouse(false)
	else -- AM
		-- Show this panel:
		self:SetAlpha(1)
		self:EnableMouse(true)
	end
  Reply With Quote
04-27-12, 02:19 AM   #3
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Could use a controller frame (a separate, opacity = 0 frame) to fully hide other frames (that can be referenced using the FetchFrame function).
  Reply With Quote
04-27-12, 07:04 AM   #4
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
I won't be able to get to my comp til this evening, but this looks to be exactly what I was aiming for, my thanks, Phanx, Nibelheim~
__________________
  Reply With Quote
04-27-12, 09:37 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Nibelheim View Post
Could use a controller frame (a separate, opacity = 0 frame) to fully hide other frames (that can be referenced using the FetchFrame function).
Yes, but that's more complicated, and just changing the opacity and disabling the mouse works for most cases. The simplest solution is usually the best one, especially when you're designing it for someone with less experience than you.
  Reply With Quote
04-28-12, 12:18 AM   #6
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Yep, worked perfectly for what I needed, thanks again~
__________________
  Reply With Quote
05-07-12, 02:57 PM   #7
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Off topic..sorta.

I'm trying find a way to make an "OnClick" Command in Kgpanels run a macrolike script, i.r /reloadUI.
Such as
OnClick
if pressed then
ReloadUI()
Is this possible?
__________________
  Reply With Quote
05-07-12, 04:55 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The OnClick script in kgPanels actually uses the panel frame's OnMouseDown and/or OnMouseUp events, since frames do not have actual OnClick events (only buttons do), and these events do not count as "hardware events" for the purpose of performing protected actions.

Since reloading the UI requires a hardware event, you cannot do it by clicking on a kgPanels panel. If you need to call protected functions by clicking on something, you will need to either use a different addon that actually creates buttons, or write your own button.

You can, however, call as many unprotected functions as you like, eg. "UIErrorsFrame:AddMessage('Clicked!')"
  Reply With Quote
05-07-12, 05:20 PM   #9
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Well, there goes that Idea, lol. My thanks, as always~


Code:
local Reload = CreateFrame("Button", "Reload", UIParent)

--
-- Config
--
-- frame
local movable = true --false/true
local frame_anchor = "TOP" -- LEFT, TOPLEFT, TOP, TOPRIGHT, RIGHT, CENTER, BOTTOMRIGHT, BOTTOM, BOTTOMLEFT
local texture = "Interface\\Buttons\\WHITE8x8.tga"
local pos_x = -250
local pos_y = -6
if movable == false then
        Reload:ClearAllPoints()
        Reload:SetPoint('BOTTOM', UIParent, "CENTER", 0, 0)
end
Reload:EnableMouse(true)
Reload:RegisterForClicks('AnyUp')

if movable == true then
        Reload:ClearAllPoints()
	Reload:SetPoint('BOTTOM', UIParent, "CENTER", 0, 0)
        Reload:SetSize(20, 20)
	Reload:SetClampedToScreen(false)
	Reload:SetMovable(true)
	Reload:SetUserPlaced(true)
        Reload:SetScript("OnClick", ReloadUI)
	Reload:SetScript('OnMouseDown', function()
        		if(IsAltKeyDown()) then
			Reload:ClearAllPoints()
			Reload:StartMoving()
		end
	end)
	Reload:SetScript('OnMouseUp', function()
		Reload:StopMovingOrSizing()
	end)
end
Would that work?

Edit: Nope. No errors, just no button anywhere, lol.
__________________

Last edited by Kendian : 05-07-12 at 05:52 PM.
  Reply With Quote
05-09-12, 04:57 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That code is actually producing a button... but you can't see it because you didn't give it any visible regions (such as a backdrop, textures, or font strings). You need to either inherit from a template that includes visible regions when you create the button:

Code:
local button = CreateFrame("Button", "MyReloadButton", UIParent, "UIPanelButtonTemplate")
button:SetPoint("CENTER")
button:SetSize(100, 30)
button:SetText("Reload UI")

button:SetMovable(true)
button:SetClampedToScreen(true)
button:RegisterForDrag("RightButton")
button:SetScript("OnDragStart", function(self)
	if IsAltKeyDown() then
		self:StartMoving()
	end
end)
button:SetScript("OnDragStop", button.StopMovingOrSizing)
button:SetScript("OnHide", button.StopMovingOrSizing)

button:SetScript("OnClick", ReloadUI)
... or give the frame visible regions yourself:

Code:
local button = CreateFrame("Button", "MyReloadButton", UIParent)
button:SetPoint("CENTER")
button:SetSize(100, 30)

local texture = button:CreateTexture(nil, "BACKGROUND")
texture:SetAllPoints(true)
texture:SetTexture("Interface\\BUTTONS\\WHITE8X8")
texture:SetVertexColor(0.5, 0, 0)
button:SetNormalTexture(texture)

local text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
text:SetAllPoints(true)
text:SetJustifyH("CENTER")
text:SetJustifyV("CENTER")
text:SetTexColor(1, 0.8, 0)
button:SetNormalFontObject(text)
button:SetText("Reload UI")

button:SetMovable(true)
button:SetClampedToScreen(true)
button:RegisterForDrag("RightButton")
button:SetScript("OnDragStart", function(self)
	if IsAltKeyDown() then
		self:StartMoving()
	end
end)
button:SetScript("OnDragStop", button.StopMovingOrSizing)
button:SetScript("OnHide", button.StopMovingOrSizing)

button:SetScript("OnClick", ReloadUI)
I'm also not really sure what you were aiming for with all of the random variables and if/then conditions in your code... the only reason to include anything like that is if you are writing an in-game options UI and need to be able to apply changes on the fly.

Also:

- You don't need to call SetUserPlaced(true) explicitly. It's implied when you StartMoving. The only reason to ever call it directly would be if you want to turn it off, and you'd need to call it after StopMovingOrSizing.

- You don't need to ClearAllPoints before you StartMoving.

- You should generally enable SetClampedToScreen, not disable it. Otherwise, you can drag the button off the screen, and have no way to get it back outside of editing saved config files or running slash commands.

Last edited by Phanx : 05-09-12 at 05:00 AM.
  Reply With Quote
05-09-12, 10:55 AM   #11
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
....I'm an idiot. Considering that I started this question by asking how to make a panel have this function, it's painful I didn't think it all the way through. My thanks, as always, Phanx, for showing me a light through the trees~
__________________
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » KGPanels script help again :)


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off