InfoBox Lua Module

Posted by WillFa on Wed 03 Sep 2008 06:28 AM — 4 posts, 11,880 views.

USA #0
I think I'm finally happy with my miniwindow project. Instead of writing a plugin which I find is highly spcific to the author's desires and mud he plays on. I chose to write a Lua module. This module is 800+ lines of code that handles the majority of MiniWindow tasks you'd need to recreate the InfoBar or Status lines. I've reinvented the wheel! But I made it rounder.
There's some pictures of it
http://tinyurl.com/5z9yn6
and
http://tinyurl.com/5z9yn6

It has an object oriented approach to making these windows. The scripting outside of the module is minimal and should be accessible to novice scripters as well as plugin authors.


Someone with just a trigger on their hpbar/prompt could be on their way in just:

Window = InfoBox:new("MyHP")
Window:AddBar("HP", 75)
Window:Update()


3 lines of script to get a gauge working isn't bad. Right?




For a more practical example, the scripting required to make and update the 2 windows pictured is only:


require "InfoBox"

function Init ()
	TextRectangle(5,5,-5,-5, 5,0x222222,3, 0x111111,0)

	HPBox = InfoBox:new("HP")
		HPBox.Bar.textStyle = HPBox.textStyles.sunken
	HPBar 	  = HPBox:AddBar("HP", 0, "green", "firebrick", false)
		HPBar.barStyle = HPBar.barStyles.gradientFixed + HPBar.barStyles.glass
		HPBar.threshold = 52
		HPBar:WatchValue ("vars.pHP")
	HPStatus = HPBox:AddBar("",0,0,0,false,0)
	HPStatus.textStyle = 1
	KarmaBar  =	HPBox:AddBar("Karma", 0,"dodgerblue", "firebrick", false, 8+64)
		KarmaBar.threshold = 40
		KarmaBar:WatchValue("vars.pKarma")
	KStatus = HPBox:AddBar("",0,0,0,false,0)
	KStatus:TextColour ("peachpuff")
	KStatus.textStyle = 4
	KStatus.captionPlacement = 4
	SPBar 	  =	HPBox:AddBar("SP", 0, "deepskyblue", "dimgray", false, 8+128)
		SPBar:WatchValue("vars.pSP")
	VoiceBar  =	HPBox:AddBar("Voice", 0, "mediumpurple", "indigo", false, 8+32)
		VoiceBar:WatchValue("vars.cVoice")
	EnemyBar = HPBox:AddBar("", 0, 0x222222, 0x000070, true, 8+64)
		EnemyBar.threshold = 45
		EnemyBar.textStyle = 1
		EnemyBar:CaptionPlacement(1)
	HPBox:WindowPosition ( InfoBox.windowPositions.S )
	HPBox:Rows  (2)
	
	GXPBox = InfoBox:new("GXP")
		GXPBox.windowPosition = InfoBox.windowPositions.E

	GXPSt = GXPBox:AddBar("GXP to Next Level:",0,0,0,false,0)
		GXPSt.textStyle = InfoBox.textStyles.sunken

	GXPgr = GXPBox:AddBar(0, 0, "silver", "silver")
		GXPgr:CaptionPlacement(2)
		GXPgr:Caption(vars.GXPtoNextLevel)
	TSt = GXPBox:AddBar(NextPoint .. " " .. tostring(Skills[NextPoint].current +1))
	TSt:BarStyle(0)
	Tgr = GXPBox:AddBar(Skills[NextPoint].cost, 0, "slateblue","mediumblue",true, HPBox.barStyles.sunken + HPBox.barStyles.solid)
	Tgr:Threshold(97)
end



function HeartBeat (...)
	local fmt = "  HP: %i/%i  (%+4i)  "
	if vars.cHP then
		vars.hpdelta = vars.cHP - (hplastround or 0)
		HPStatus.caption = fmt:format(vars.cHP, vars.mHP, vars.hpdelta)
		HPStatus:ColourText(vars.hpdelta, 0, 0x006600,0x000066,"black")
		SPBar:Threshold(math.floor((152/vars.mSP) * 100))
		EnemyBar.value = tonumber(vars.BadGuyHealth) or 0
		if vars.SongPerformed then
			KStatus.caption = "Singing: " .. titlecase(vars.SongPerformed)
		else
			KStatus.caption = ""
		end
		if vars.inCombat == "" then
			var.Enemy = ""
		end
		if var.Enemy ~= "" then
			EnemyBar:Caption(var.Enemy)
		else
			EnemyBar:Caption("")
		end
		if HPBox:Update() then
			hplastround = vars.cHP
		end
		TSt:Caption(NextPoint .. " " .. tostring(Skills[NextPoint].current +1))
		Tgr:Caption(Skills[NextPoint].cost - vars.GXPtoSpend)
		GXPgr:Value(vars.GXPtoNextPercent)
		Tgr:Value(math.floor((vars.GXPtoSpend/Skills[NextPoint].cost)*100))
		GXPBox:Update()
	end
end

That makes both windows, all 11 "bars", and keeps them up to date.


If anyone's interested, I'll put the module up on Skydrive. (Or if Nick wouldn't mind hosting it with the other plugins?) and continue working on documenting all the functions in it.
Amended on Wed 03 Sep 2008 06:31 AM by WillFa
Australia Forum Administrator #1
You are welcome to send it to me - I tried to reply privately but the system thinks your email address is wrong - perhaps update your forum profile.
USA #2
Thanks Nick. After thinking about it, I think I'll wait for 4.37 so I can finish cleaning up after myself with WindowDelete.

(The email address was valid; I had "allow e-mail" turned off. I would have guessed Admins could have overridden that. It's updated now, however)
Australia Forum Administrator #3
Admins can see it, sure, but the fact that it had the "bounced" flag on it meant I thought that the address I could see, would be wrong.

Anyway, if you do this, you will see my email address:


print (utils.base64decode ("bmlja0BnYW1tb24uY29tLmF1"))


Hopefully that is cryptic enough to slow the spammers down. ;)