Thread Tools Display Modes
Prev Previous Post   Next Post Next
01-21-12, 08:35 AM   #1
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Help creating scroll frame

Hello,

After spending lots of hours, I'm still stuck with creating a scrolling message frame. I've solved several issues, but I still got two majors ones:

1. When the scrolling frame is loaded and some messages are added to it, I get "0" for GetNumLinesDisplayed(). I need a correct value in order to set correctly the slider SetMinMaxValues(). If I print the GetNumLinesDisplayed() on some events, I then get correct value. What should I do in order to get the correct value when constructing the scrolling message frame? Note that GetNumMessages() does return the correct value.

2. I can't make the frame hide when hitting "escape". I've tried to use tinsert(UISpecialFrames, "historyFrame"), but it juse hide my frame and I can't get to show it.

I will appreciate any help, I'm really stuck here.
This is my code (can be copied and run as standalone code):

Code:
local historyFrame 	= CreateFrame("Frame", "historyFrame", UIParent)
	historyFrame.width 	= 500
	historyFrame.height	= 250
	historyFrame:SetFrameStrata("FULLSCREEN_DIALOG")	
	
	historyFrame:SetSize(historyFrame.width, historyFrame.height)	
	historyFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
	historyFrame:SetBackdrop({
		bgFile 		= "Interface\\DialogFrame\\UI-DialogBox-Background",
		edgeFile	= "Interface\\DialogFrame\\UI-DialogBox-Border",
		tile 		= true,
		tileSize 	= 32,
		edgeSize 	= 32,
		insets 		= { left = 8, right = 8, top = 8, bottom = 8 }
	}) 
				  
	historyFrame:SetBackdropColor(0, 0, 0, 1)
	historyFrame:EnableMouse(true)
	historyFrame:EnableMouseWheel(true)	
	
	-- Make movable/resizable	
	historyFrame:SetMovable(true)
	historyFrame:SetResizable(enable)
	frame:SetMinResize(100, 100)
	historyFrame:RegisterForDrag("LeftButton")
	historyFrame:SetScript("OnDragStart", frame.StartMoving)
	historyFrame:SetScript("OnDragStop", frame.StopMovingOrSizing)
	historyFrame:SetScript("OnLoad", function(self) print(self:GetName()) end)
	--tinsert(UISpecialFrames, historyFrame)
	
	-- Close button
	local closebutton = CreateFrame("Button", nil, historyFrame, "UIPanelButtonTemplate")
	closebutton:SetScript("OnClick", function(self) HideParentPanel(self) end)
	closebutton:SetPoint("BOTTOM", 0, 10)
	closebutton:SetHeight(25)
	closebutton:SetWidth(70)
	closebutton:SetText(CLOSE)
	
	-- ScrollingMessageFrame
	local historyScrollingMessage = CreateFrame("ScrollingMessageFrame", historyScrollingMessage, historyFrame)
	historyScrollingMessage:SetPoint("CENTER", 15, 20)	
	historyScrollingMessage:SetSize(historyFrame.width, historyFrame.height - 50)
	historyScrollingMessage:SetFontObject(GameFontNormal)
	historyScrollingMessage:SetTextColor(1, 1, 1, 1) -- default color	
	historyScrollingMessage:SetJustifyH("LEFT")
	historyScrollingMessage:SetHyperlinksEnabled(true)
	historyScrollingMessage:SetFading(false)
	historyScrollingMessage:SetMaxLines(300)
			
	historyScrollingMessage:Clear()
	historyScrollingMessage:AddMessage("1 Here is a message!")	
	historyScrollingMessage:AddMessage("2 Here is a message!")
	historyScrollingMessage:AddMessage("3 Here is a message!")
	historyScrollingMessage:AddMessage("4 Here is a message!")
	historyScrollingMessage:AddMessage("5 Here is a message!")
	historyScrollingMessage:AddMessage("6 Here is a message!")
	historyScrollingMessage:AddMessage("7 Here is a message!")
	historyScrollingMessage:AddMessage("8 Here is a message!")
	historyScrollingMessage:AddMessage("9 Here is a message!")
	historyScrollingMessage:AddMessage("10 Here is a message!")
	historyScrollingMessage:AddMessage("11 Here is a message!")
	historyScrollingMessage:AddMessage("12 Here is a message!")
	historyScrollingMessage:AddMessage("13 Here is a message!")
	historyScrollingMessage:AddMessage("14 Here is a message!")	
	historyScrollingMessage:AddMessage("15 Here is a message!")
	historyScrollingMessage:AddMessage("16 Here is a message!")
	historyScrollingMessage:AddMessage("17 Here is a message!")
	historyScrollingMessage:AddMessage("18 Here is a message!")
	historyScrollingMessage:AddMessage("19 Here is a message!")
	historyScrollingMessage:AddMessage("20 Here is a message!")	
	historyScrollingMessage:AddMessage("21 Here is a message!")
	historyScrollingMessage:AddMessage("22 Here is a message!")
	historyScrollingMessage:AddMessage("23 Here is a message!")
	historyScrollingMessage:AddMessage("24 Here is a message!")
	historyScrollingMessage:AddMessage("25 Here is a message!")	
	--historyScrollingMessage:ScrollToBottom()
	--historyScrollingMessage:ScrollDown()	
	print (historyScrollingMessage:GetNumMessages(), historyScrollingMessage:GetNumLinesDisplayed())
	-------------------------------------------------------------------------------
	-- Scroll bar
	-------------------------------------------------------------------------------
	local ScrollBar = CreateFrame("Slider", "ScrollBar", historyFrame, "UIPanelScrollBarTemplate")
	
	ScrollBar:ClearAllPoints()	
	ScrollBar:SetPoint("RIGHT", historyFrame, "RIGHT", -10, 10)	
	ScrollBar:SetSize(30, historyFrame.height - 90)	
	ScrollBar:SetMinMaxValues(0, 9)
	ScrollBar:SetValueStep(1)	
	ScrollBar.scrollStep = 1 
	ScrollBar:SetScript("OnValueChanged", function(self, value)		
		historyScrollingMessage:SetScrollOffset(select(2, ScrollBar:GetMinMaxValues()) - value)
	 end)
		
	ScrollBar:SetValue(select(2, ScrollBar:GetMinMaxValues()))
	
	historyFrame:SetScript("OnMouseWheel", function(self, delta)
		
		print (historyScrollingMessage:GetNumMessages(), historyScrollingMessage:GetNumLinesDisplayed())
		
		local cur_val = ScrollBar:GetValue()
		local min_val, max_val = ScrollBar:GetMinMaxValues()

		if delta < 0 and cur_val < max_val then
			cur_val = math.min(max_val, cur_val + 1)
			ScrollBar:SetValue(cur_val)			
		elseif delta > 0 and cur_val > min_val then
			cur_val = math.max(min_val, cur_val - 1)
			ScrollBar:SetValue(cur_val)		
		end	
	 end)
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Help creating scroll frame


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