Jump to content
  • entries
    941
  • comments
    5,894
  • views
    867,642

Beta update available


Josh

1,201 views

 Share

An update is available on the beta branch. This adds the Window::Center style back into the new refactored Window class, and adds a missing header file in the Professional Edition.

 

If you'd like to try out a basic implementation of the new GUI, download and extract the attached scripts:

Scripts.zip

 

This code will create a GUI on the rendering context. It simply consists of a solid background filling the screen and a textless button.

--Initialize Steamworks (optional)
Steamworks:Initialize()

--Set the application title
title="test"

--Create a window
local windowstyle = window.Titlebar + window.Resizable
if System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+window.FullScreen end
window=Window:Create(title,0,0,System:GetProperty("screenwidth","1024"),System:GetProperty("screenheight","768"),windowstyle)
--window:HideMouse()

--Create the graphics context
context=Context:Create(window,0)
if context==nil then return end

--Create a world
world=World:Create()
world:SetLightQuality((System:GetProperty("lightquality","1")))

--Load a map
local mapfile = System:GetProperty("map","Maps/start.map")
if Map:Load(mapfile)==false then return end

--Create a GUI
local gui = GUI:Create(context)
gui:GetBase():SetScript("Scripts/GUI/Panel.lua")
local widget = Widget:Create(20,20,75,30,gui:GetBase())
widget:SetScript("Scripts/GUI/Button.lua")

while window:KeyDown(Key.Escape)==false do

--If window has been closed, end the program
if window:Closed() then break end

--Handle map change
if changemapname~=nil then

	--Clear all entities
	world:Clear()

	--Load the next map
	Time:Pause()
	if Map:Load("Maps/"..changemapname..".map")==false then return end
	Time:Resume()

	changemapname = nil
end	

--Update the app timing
Time:Update()

--Update the world
world:Update()

--Render the world
world:Render()

--Render statistics
context:SetBlendMode(Blend.Alpha)
if DEBUG then
	context:SetColor(1,0,0,1)
	context:DrawText("Debug Mode",2,2)
	context:SetColor(1,1,1,1)
	context:DrawStats(2,22)
	context:SetBlendMode(Blend.Solid)
else
	--Toggle statistics on and off
	if (window:KeyHit(Key.F11)) then showstats = not showstats end
	if showstats then
		context:SetColor(1,1,1,1)
		context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2)
	end
end

--Refresh the screen
context:Sync(true)

end

 

This code will create the same GUI directly on the window, with no rendering context initialized, using the native OS drawing commands:

--Initialize Steamworks (optional)
Steamworks:Initialize()

--Set the application title
title="test"

--Create a window
local windowstyle = window.Titlebar + window.Resizable
if System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+window.FullScreen end
window=Window:Create(title,0,0,System:GetProperty("screenwidth","1024"),System:GetProperty("screenheight","768"),windowstyle)
--window:HideMouse()

--Create a GUI
local gui = GUI:Create(window)
gui:GetBase():SetScript("Scripts/GUI/Panel.lua")
local widget = Widget:Create(20,20,75,30,gui:GetBase())
widget:SetScript("Scripts/GUI/Button.lua")

while window:KeyDown(Key.Escape)==false do

--If window has been closed, end the program
if window:Closed() then break end

end

 

The second example isn't really useful for games, but it will allow me to build a cross-platform UI for our own tools, and create an official GUI for in-game use, all in one step.

  • Upvote 3
 Share

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...