Page 1 of 1

Some changes and a fully scriptable GUI

Posted: Thu Jul 15, 2010 6:20 pm
by paradoxnj
I had to change the scripting language to Lua. Squirrel is no longer in active development and will not be supported by the original author. It's not much of a change from Squirrel as Squirrel is actually a derivative of Lua.

Now...on to the good stuff. I've been working on a fully scriptable GUI for a little while now and have finally achieved it. The Lua switch made that a lot easier.

Here is a sample script that makes a window. When you close that window, it quits RF2.

Code: Select all

-- Get the singletons so that we type less
local guiSys = CEGUI.System:getSingleton()
local winMgr = CEGUI.WindowManager:getSingleton()

-- Create the root window
local sheet = winMgr:createWindow("DefaultGUISheet", "root")

-- Create a frame window
local frameWin = winMgr:createWindow("TaharezLook/FrameWindow", "mainWnd")

-- Add the frame window to the root window
sheet:addChildWindow(frameWin)

-- Set the size and position of the frame window
local sz = CEGUI.UVector2(CEGUI.UDim(0.5, 0), CEGUI.UDim(0.5,0))
local pos = CEGUI.UVector2(CEGUI.UDim(0.2,0), CEGUI.UDim(0.1, 0))

frameWin:setSize(sz)
frameWin:setPosition(pos)

-- Disable user resizing
frameWin:setProperty("SizingEnabled", "False")

-- Subscribe to the CloseClicked event
frameWin:subscribeEvent("CloseClicked", "frameWin_onCloseClicked")

-- Tell the GUI system to use our root window as the current GUI
guiSys:setGUISheet(sheet)

-- Event function
function frameWin_onCloseClicked(eventArgs)
	local we = CEGUI.toWindowEventArgs(eventArgs)
	CEGUI.WindowManager:getSingleton():destroyWindow(we.window)

	ScriptEngine:quit()
end
The above code produces the following:

Image

You can also use the CEGUI Layout Editor to create the GUI visually and just attach your own script functions to the window events. Here is a sample of that using the CEGUI Demo8 Layout.

Code: Select all

-----------------------------------------
-- Start of handler functions
-----------------------------------------
-----------------------------------------
-- Alpha slider handler (not used!)
-----------------------------------------
function sliderHandler(args)
    CEGUI.System:getSingleton():getGUISheet():setAlpha(CEGUI.toSlider(CEGUI.toWindowEventArgs(args).window):getCurrentValue())
end

-----------------------------------------
-- Handler to slide pane
--
-- Here we move the 'Demo8' sheet window
-- and re-position the scrollbar
-----------------------------------------
function panelSlideHandler(args)
    local scroller = CEGUI.toScrollbar(CEGUI.toWindowEventArgs(args).window)
    local demoWnd = CEGUI.WindowManager:getSingleton():getWindow("Demo8")

    local relHeight = demoWnd:getHeight():asRelative(demoWnd:getParentPixelHeight())

    scroller:setPosition(CEGUI.UVector2(CEGUI.UDim(0,0), CEGUI.UDim(scroller:getScrollPosition() / relHeight,0)))
    demoWnd:setPosition(CEGUI.UVector2(CEGUI.UDim(0,0), CEGUI.UDim(-scroller:getScrollPosition(),0)))
end

-----------------------------------------
-- Handler to set preview colour when
-- colour selector scrollers change
-----------------------------------------
function colourChangeHandler(args)
    local winMgr = CEGUI.WindowManager:getSingleton()

    local r = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Red")):getScrollPosition()
    local g = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Green")):getScrollPosition()
    local b = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Blue")):getScrollPosition()
    local col = CEGUI.colour:new_local(r, g, b, 1)
    local crect = CEGUI.ColourRect(col)

    winMgr:getWindow("Demo8/Window1/Controls/ColourSample"):setProperty("ImageColours", CEGUI.PropertyHelper:colourRectToString(crect))
end


-----------------------------------------
-- Handler to add an item to the box
-----------------------------------------
function addItemHandler(args)
    local winMgr = CEGUI.WindowManager:getSingleton()

    local text = winMgr:getWindow("Demo8/Window1/Controls/Editbox"):getText()
    local cols = CEGUI.PropertyHelper:stringToColourRect(winMgr:getWindow("Demo8/Window1/Controls/ColourSample"):getProperty("ImageColours"))

    local newItem = CEGUI.createListboxTextItem(text, 0, nil, false, true)
    newItem:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
    newItem:setSelectionColours(cols)

    CEGUI.toListbox(winMgr:getWindow("Demo8/Window1/Listbox")):addItem(newItem)
end

local guiSys = CEGUI.System:getSingleton()
local winMgr = CEGUI.WindowManager:getSingleton()

local rootWin = winMgr:loadWindowLayout("./media/gui/demo8.layout")
guiSys:setGUISheet(rootWin)

-- subscribe required events
winMgr:getWindow("Demo8/ViewScroll"):subscribeEvent("ScrollPosChanged", "panelSlideHandler")
winMgr:getWindow("Demo8/Window1/Controls/Blue"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
winMgr:getWindow("Demo8/Window1/Controls/Red"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
winMgr:getWindow("Demo8/Window1/Controls/Green"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
winMgr:getWindow("Demo8/Window1/Controls/Add"):subscribeEvent("Clicked", "addItemHandler")
The above code produces the following:

Image

Boy I can't wait to see the complicated inventory systems and HUDs that can be achieved with this. :)

Re: Some changes and a fully scriptable GUI

Posted: Fri Jul 16, 2010 5:34 am
by Veleran
I hope the window does n t need scripting to open and that it ll be automated like in rf1.(otherwise all will go to udk and unity3d -no offence,just a foreseeing).

Re: Some changes and a fully scriptable GUI

Posted: Fri Jul 16, 2010 1:59 pm
by paradoxnj
What do you mean? If you mean initializing RF2 itself, then you won't need scripting for that. If you mean the GUI window (aka HUD or menu), then the examples I posted is what I mean. I'll post a screen shot to be more clear.

RF1's menu system is very limiting. RF2 provides you with a fully functional GUI in the game. That GUI is programmable with your actions and not limited to "Exit_Button", "New_Game", etc... You also have a full set of widgets to use such as frame windows, sliders, check boxes, combo boxes, list boxes, color pickers, tree view, tooltips, menus, etc... It also fully supports drag and drop for you RPG HUD fans.

[EDIT] Screen shots added to original post [/EDIT]

Re: Some changes and a fully scriptable GUI

Posted: Sat Jul 17, 2010 9:37 am
by Veleran
I mean a basic starting menu script template (with default bitmaps).
What i hope is that you dont have to script any small action like loading a static actor that is nt like a pawn,should nt need to be defined in any script and this way you may add quicker many static stuff like these in the level.

Re: Some changes and a fully scriptable GUI

Posted: Sat Jul 17, 2010 3:56 pm
by paradoxnj
Starting a basic menu template could be done using the CEGUI Layout Editor. You will have to tell the buttons what to do though. There will be a set of predefined actions that you can choose from (e.g startGame, openSubMenu, etc). Starting a game from scratch will require the following steps:

1. Open the editor (not available in the first alpha version)
2. Create a package
3. Define the first game state (e.g Menu, custom logo, cut scene)
4. Create terrain (optional)
5. Place objects, lights and planes
6. Define logic
7. Optimize level (no compiling necessary)(Optional)
8. Publish your game.

Static actors will not need logic script. You will place them in the editor just like you do now. There will be 2 ways to define static objects:

1. Entity definition script
2. Editor gui (creates entity definition script visually)

Everything will be placed via drag and drop.

Static meshes can also contain logic. For example, you might want to push them around or when someone touches it, trigger a cut scene or unlock/open a door. I define static as non-animated (e.g no walk, run, idle).

I am allowing more advanced users to create their own entities with or without logic.

The editor will also automagically generate script for you also depending on a set of predefined actions (visual scripting). That is in the final product though. The idea is to allow flexibility by editing stuff by hand for more advanced people, and have everything done visually for the beginners. Intermediate users can do either. The more you do manually, the more control you have.

CEGUI has a Layout Editor that is fully supported by RF2. So there will be plenty of tools to help you along. You might not even need to open a script. ;)