Page 1 of 1

help me to modify that widget

Posted: 27 Nov 2009, 17:11
by manolo_
so thats the lua i ripped from ca some time ago, so i want to change it a lil but, so it will show the E and M costs for morph/build in a next line, so how?

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:GetInfo()
  return {
    name      = "InlineTip-BM",
    desc      = "v0.3 Prints unit name next to cursor when hovering over buildpic.",
    author    = "CarRepairer",
    date      = "2008-08-20",
    license   = "GNU GPL, v2 or later",
    layer     = 1, 
    enabled   = false  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local Spring          = Spring
local gl, GL          = gl, GL
local widgetHandler   = widgetHandler
local panelFont       = LUAUI_DIRNAME.."Fonts/KOMTXT___16"



--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local fhDraw          = fontHandler.Draw
local glColor         = gl.Color
local GetCurrentTooltip = Spring.GetCurrentTooltip
local GetMouseState = Spring.GetMouseState 

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

fontHandler.UseFont(panelFont)
local panelFontSize  = fontHandler.GetFontSize()
fontHandler.DisableCache()

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function getShortTooltip()
	local tooltip = GetCurrentTooltip()

	if tooltip:find('Build') == 1 then
		return tooltip:gsub('([^-]*)\-.*', '%1')
	elseif tooltip:find('Morph') == 5 then
		return tooltip:gsub('([^(time)]*)\(time).*', '%1')
	end
	return false
	
end


function widget:DrawScreen()

	local curTooltip = getShortTooltip()

	if (curTooltip) then
		fontHandler.DisableCache()

		fontHandler.UseFont(panelFont)
		glColor(1,1,1,1)
	
		local mx, my = GetMouseState()
		fhDraw(curTooltip, mx + 15, my - 15)
	end

end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:Initialize()
end

function widget:Shutdown()
	fontHandler.FreeFonts()
	fontHandler.FreeCache()
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Re: help me to modify that widget

Posted: 29 Nov 2009, 07:17
by Tribulex
Is this for xta? Just keep in mind that I am actually making an inline tooltip for xta. I dont mean to burst your bubble, but if you tell me what you want in it Ill put it in.

Re: help me to modify that widget

Posted: 29 Nov 2009, 13:34
by manolo_
i didnt knew that, but i just want to have the name and the E/M-costs while i hover over the build/morph-pic. the widget shows the name, so i need someone how adds the line for the costs