Page 1 of 14
New GUI scripting concepts and foundation
Posted: Wed Dec 05, 2012 3:33 pm
by antti
Here's something I cooked together quickly to test the upcoming GUI features:

It's totally functional but a little bare-bones.

Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 3:42 pm
by JohnWordsworth
That's awesome. It's all very exciting, especially with the ability to do that only on certain screens and for certain characters. It's going to be super powerful. You could use socketed items and pop stones in them (and then replace the item with a 'sword with green gem') item, add in-game puzzles / close-ups.
What I'm strongly contemplating is a Deck of Many Things... :p
Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 3:56 pm
by Xanathar
I started thinking about building a kind of widget/forms library to help create UIs.
Just the random thoughts I had, dumped here:
- Ability to show widgets (more than one displayed at a time, non-modal) or forms (one at a time)
- Monsters and party should be frozen for the duration of the modal forms (through jkos fw hooks ?)
- Have some kind of declarative syntax like:
Code: Select all
myform =
{
fadein = 0.1, fadeout = 0.1, -- (to understand if feasible modulating pen alpha)
{ type = "image", x = 10, y = 20, image = "..." },
{ type = "label", id = "xxx", x = 50, y = 50 },
{ type = "button", id = "yyy", x = 10, y = 10, w = 20, h = 10 },
{ type = "portrait" ... },
}
function yyy_click()
... auto called do something
end
gui.showDialog(myform, self)
-- or
gui.addWidget(myform, self)
- Allow for ownerdraw things, still offering helper methods (to allow pong implementations)
Of course, apart making a broad idea and maybe defining some API, now it's premature.
If anyone wants to jump on this boat and help when the time comes, he/she is welcome!
Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 5:46 pm
by Diarmuid
Xanathar, that's exactly what I had in mind above when I spoke of a "graphic library". I'm nowhere near your level of coding skills, but if you lay out the global model, I'll be happy helping to write/test specific functions or widgets.
Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 6:31 pm
by Xanathar
Thanks Diarmuid!
Your help is welcome, plus your coding skills are great too!
Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 6:33 pm
by pferguso
Holy Schmolie! I'm out of it for two days and I miss this?? How totally cool! Do these new features work now, or is there an update to Grimrock coming soon that will have the GUI stuff?
Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 6:36 pm
by Xanathar
is there an update to Grimrock coming soon that will have the GUI stuff?
They are coming (about the same time) when the OS/X version will be released.
It's the first time in my life I'm waiting an OS/X software to be released

Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 8:50 pm
by germanny
What´s about a Linux version of grimrock? Is it possible or too heavy coding?
Since steam goes to Linux, too!
And they have better framerates by (already ported Left4dead2) as under Windows

*bg*
Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 9:34 pm
by JKos
@Xanathar
That kind of library would be great, but I think we also definitely need some simple standard method of how we develop the gui elements.
I sketched a basic functionality for modular gui 'framework' (yeah, I just love frameworks and standards

). It's a framework, not a library, because it defines the way of how some things must be implemented and how they are handled.
Code: Select all
cloneObject{
name='party'
...
onDrawGui = function(g)
gui.draw(g)
end
}
script entity: gui
Code: Select all
elements = {}
addElement(element)
elements[element.id] = element
end
removeElement(id)
element[id] = nil
end
draw(g)
for i=1,#elements do
elements[i]:draw(g)
end
end
It's really simple as it should be so everybody can understand it and it doesn't add any unnecessary restrictions. But this way we could dynamically add elements to gui or remove them from it and different kind of elements could be rendered in different ways.
The only requirement is that the element object passed to addElement function must have a method named draw and a property named id. If everyone would use this simple script then all created gui elements would be easily used between dungeons.
If we wanted to create a general use dialog element we could do it like this
Code: Select all
createDialog(id,text)
local e = {}
e.id = id
e.draw = function(self,g)
g.color(30,30,30,150)
g.drawRect(30, 50, 345, 300
g.drawText(text, 200, 80)
-- draw button with text
g.color(128, 128, 128)
g.drawRect(200, 120, 115, 20)
g.color(255, 255, 255)
g.drawText("Ok", 210, 135)
-- close dialog when the button is pressed
if g.button("button1", 200, 120, 115, 20) then
gui.removeElement(self.id)
end
end
return e
end
local dialog = createDialog('hello_dialog_1','Hello grimrockers!')
gui.addElement(dialog)
That dialog object could of course use the graphics library for drawing things. But I think this subject needs it's own thread.
Edit: name -> id
Re: Petri consumes glögg and codes with you
Posted: Wed Dec 05, 2012 11:10 pm
by petri
Immediate mode gui to the rescue
E.g. a simple dialog with three buttons:
Code: Select all
function shopMenu()
local x = 100
local y = 100
-- draws a dialog frame
gui.dialog(x, y, 150, 50)
x = x + 10
y = y + 10
-- draws a button and returns true if the button was pressed
if gui.button("shop_buy", "Buy", x, y, 100, 20) then
-- TODO: enter buy dialog
end
y = y + 25
if gui.button("shop_sell", "Sell", x, y, 100, 20) then
-- TODO: enter sell dialog
end
y = y + 25
if gui.button("shop_exit", "Bye!", x, y, 100, 20) then
-- TODO: exit shop
end
y = y + 25
end