Jump to content

Custom HUD Layout


Recommended Posts

Hi all!


Today I just started browsing through the Don't Starve lua scripts and began work on creating my first Don't Starve Mod!  I'm attempting to make a HUD that is better suited for triple monitors by moving the resources on the left and right sides (the CraftTabs, Clock, Health, etc) to the middle monitor.


Using the minimap mod for inspiration, I was able to come up with the following modmain.lua after some time:

local require = GLOBAL.requirelocal GetWorld = GLOBAL.GetWorldlocal function AdjustHUD( inst )	inst:DoTaskInTime( 0, function() 		-- convenient references to HUD objects		local controls = inst.HUD.controls		local inv = inst.HUD.controls.inv		local craft = inst.HUD.controls.crafttabs		local screensize = {TheSim:GetScreenSize()}				-- experimenting with coordinates		inv:SetPosition(200,0,0)		craft:SetPosition(1500,0,0)		craft.tabs:SetPosition(1500-16, 0, 0)		craft.bg_cover:SetPosition(1500-38, 0, 0)				-- keep the screensize up to date for when we use it		local OnUpdate_base = controls.OnUpdate		controls.OnUpdate = function(self, dt)			OnUpdate_base(self, dt)			local curscreensize = {TheSim:GetScreenSize()}			if curscreensize[1] ~= screensize[1] or curscreensize[2] ~= screensize[2] then				screensize = curscreensize			end		end	end)endAddSimPostInit( AdjustHUD )

I am able to move the interfaces around using SetPosition, but I don't really understand the coordinate system.  I think everything is anchored to a certain side of the screen (ANCHOR_LEFT for ex), and the first and second parameters in the SetPosition method seem to be vertical and horziontal coordinates (but I don't think they are in pixel units).


Additionally, the inventory works fine when moved, but it seems the crafting menu breaks after being moved.  Do I need to call another class method to reinitialize the clickable components after I move it?


My final question is in regards to the associated HUD image files - each of the components seem to have "panels" that are rendered offscreen.  Would I need to crop these with an image editor and then override the image that gets used for each item or is there a way to only render the usable parts of the panels?


Thanks in advance for anyone can shed some light on the codebase for me :)

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

  • Create New...