Help with minimap and Chili

Help with minimap and Chili

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Help with minimap and Chili

Post by Funkencool »

Alright so I'm having a little trouble with Chili and getting a minimap in a window.
Image
Basically I have no idea how to get the minimap to draw above the window that 'contains' it, since both must be drawn separately. I tried creating a child control with a custom drawcontrol to draw the minimap but gl.DrawMinimap() can only be call in widget:DrawScreen() as far as I can tell, so that didn't work. Any ideas?

Here's the code which is basically just a stripped down version of carrepairers Chili Minimap.

Code: Select all

function widget:GetInfo()
  return {
    name      = "BAR's Minimap",
    desc      = "Chili Minimap",
    author    = "Licho, CarRepairer, Funkencool",
    date      = "@2010",
    license   = "GNU GPL, v2 or later",
    layer     = -99,
    enabled   = true,
  }
end


local minimap
local Chili
local glDrawMiniMap = gl.DrawMiniMap
local glResetState = gl.ResetState
local glResetMatrices = gl.ResetMatrices


local tabbedMode = false

local function MakeMinimapWindow()
	
	if (minimap) then
		minimap:Dispose()
	end

	local aspect = Game.mapX/Game.mapY
	local h = Chili.Screen0.height * 0.3
	local w = h * aspect
	
	if (aspect > 1) then
		w = h * aspect^0.5
		h = w / aspect
	end
	
	minimap = Chili.Window:New{
		name    = "Minimap", 
		parent  = Chili.Screen0,
		resizable = false,
		width   = w, 
		height  = h,
		x       = 0,
		bottom  = 0,
		padding = {5,5,5,5},
		margin  = {0,0,0,0},
	}
	
end

function widget:KeyRelease(key, mods, label, unicode)
	if key == 0x009 then --// "0x009" is equal to "tab". Reference: uikeys.txt
		local mode = Spring.GetCameraState()["mode"]
		if mode == 7 and not tabbedMode then
			minimap:Hide()
			tabbedMode = true
		end
		if mode ~= 7 and tabbedMode then
			minimap:Show()
			tabbedMode = false
		end
	end
end

function widget:ViewResize(vsx, vsy)
	MakeMinimapWindow()
end

function widget:Initialize()
	
	if (Spring.GetMiniMapDualScreen()) then
		Spring.Echo("ChiliMinimap: auto disabled (DualScreen is enabled).")
		widgetHandler:RemoveWidget()
		return
	end

	if (not WG.Chili) then
		widgetHandler:RemoveWidget()
		return
	end
	
	Chili = WG.Chili
	
	MakeMinimapWindow()
	
	gl.SlaveMiniMap(true)
end

function widget:Shutdown()
	--// reset engine default minimap rendering
	gl.SlaveMiniMap(false)
	Spring.SendCommands("minimap geo " .. Spring.GetConfigString("MiniMapGeometry"))

	--// free the chili window
	if (minimap) then
		minimap:Dispose()
	end
end 


local lx, ly, lw, lh

function widget:DrawScreen() 
	
	if (minimap.hidden) then 
		gl.ConfigMiniMap(0,0,0,0) --// a phantom map still clickable if this is not present.
		return 
	else
		local vsx,vsy = gl.GetViewSizes()
		local cx,cy,cw,ch = Chili.unpack4(minimap.clientArea)
		cx,cy = minimap:LocalToScreen(cx,cy)
		gl.ConfigMiniMap(cx,vsy-ch-cy,cw,ch)		
	end


	gl.PushAttrib(GL.ALL_ATTRIB_BITS)
	gl.MatrixMode(GL.PROJECTION)
	gl.PushMatrix()
	gl.MatrixMode(GL.MODELVIEW)
	gl.PushMatrix()

	glDrawMiniMap()

	gl.MatrixMode(GL.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(GL.MODELVIEW)
	gl.PopMatrix()
	gl.PopAttrib()
end 
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Help with minimap and Chili

Post by Funkencool »

I updated title.

It seems this is actually just chili and I didn't notice (having not updated chili until I upgraded the engine).

So Chili used to draw below gl.DrawMiniMap(). Now it draws above. I either need a way to draw the minimap above chili somewhere in here

Code: Select all

	gl.PushAttrib(GL.ALL_ATTRIB_BITS)
	gl.MatrixMode(GL.PROJECTION)
	gl.PushMatrix()
	gl.MatrixMode(GL.MODELVIEW)
	gl.PushMatrix()
	
	glDrawMiniMap()
	
	gl.MatrixMode(GL.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(GL.MODELVIEW)
	gl.PopMatrix()
	gl.PopAttrib()
Or get chili to once again draw below that.
Any help would be greatly appreciated :-)

Edit: I can confirm pre-FTL Chili from http://springrts.com/phpbb/viewtopic.ph ... 42#p545241 has the behavior I'm looking for
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Help with minimap and Chili

Post by Beherith »

I tried to check wether ZK has the same issue, but they seem to use the same code to draw minimap, yet are not affected by this bug. Could it be they are not yet on chili FTL?
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Help with minimap and Chili

Post by Funkencool »

I'm pretty sure that's the case since they are still using 94.1, which isn't compatible with FTL. Even then their Chili differs slightly from stock chili, or at least used to.

On a side note:
I feel like this could be solved with a little openGL knowledge to change the z-index of the minimap but I just can't seem to get anywhere. I'll probably just end up getting rid of the chili window so the minimap is borderless.

I could also just get rid of the background so only the border is on top. That would actually look good, but require a change to every skin.
User avatar
KingRaptor
Zero-K Developer
Posts: 838
Joined: 14 Mar 2007, 03:44

Re: Help with minimap and Chili

Post by KingRaptor »

Random guess: Change Chili API layer (I think it used to be 1000 and now is -1000)
User avatar
Funkencool
Posts: 542
Joined: 02 Dec 2011, 22:31

Re: Help with minimap and Chili

Post by Funkencool »

Wow thanks raptor :-) , can't believe something so simple flew so far over my head :?

Edit: I suppose I should mention that it did the trick
Post Reply

Return to “Lua Scripts”