JKos wrote:[*]gw.addElement(gwElement,[hookname]) -- hook name can be gui,inventory,skills or stats
I was thinking about fifth type of hooks - events, i.e. dialog boxes that will appear only in specific locations in the dungeon. On the other hand, they should probably be implemented as a special case of gui hook.
JKos wrote:
- gw.removeElement(gwElementId)
- gw.createElement(elementName,elementId,[x],[y],[width],[height]) -- element factory
- gw.setKeyHook(key,toggle,callback) -- generic key hook
- gw.draw(g) -- draws all elements
We can possibly implement createElement() with one extra optional parameter "parent". It would simplify creating events (no need to call addElement, no need to store leaf buttons)
This code
Code: Select all
-- create 200x200 rectangle to postion 20,20
local dialog = gw.createElement('rect','my_dialog',20,20,200,200)
-- create button
local button = gw.createElement('button','my_button',20,150,20,100)
dialog.addElement(button) -- is positioned relatively to dialog element. x=20+20,y=20+150
would be simplified to:
Code: Select all
-- create 200x200 rectangle to postion 20,20
local dialog = gw.createElement('rect','my_dialog',20,20,200,200)
-- create button as a child of dialog. All coordinates become relative to parent
gw.createElement('button','my_button',20,150,20,100, dialog)
Your proposal for gwElement api seems more or less complete. I assume that by functions you meant functions that will be called if element is clicked, right? (and possibly some other functions)
JKos wrote:
I like to design by making imaginary examples, so for example I would like to be able to do things like this.
That's very convenient approach. It helps to visualize if the concept is reasonably usable or not.
JKos wrote:
High level api should be something more like this
Code: Select all
local dialog = gw.createDialog('my_dialog',{'top','left'})
dialog.addText('Hello!') -- adds a new text line to the dialog (default posiotion is top left)
dialog.addText('This is my shop.') -- add another line
local button = dialog:addButton('my_button','Bye',{'bottom','left'})
button.setAction('close')
local button_2 = dialog:addButton('my_other_button','Buy items',{'after','my_button'})
button_2.setAction('my_shop_script','drawShopGui') -- similar to addConnector
We need more than a dialog. Let me give an example. In EOB1, you meet a wounded dwarf. First dialog is to heal, talk or leave. This step can be implemented using your proposal. But once you choose one option, e.g. heal, you get completely different dialog. How do you propose to model that? Call dialog.removeElement() for all old options and dialog.addElement() for new options?
JKos wrote:
For this we need to implement some kind of oop like functionality so the widgets could inherit functions and properties from other elements.
Something like this:
gwElement
rect extends gwElement
dialog extends rect
button extends rect
closeButton extends button
..etc..
Unfortunately we don't have access to lua meta methods, but we should be able to do this with the factory pattern.
That makes sense, given that Lua doesn't support inheritance. I was a bit puzzled when I first read that. BTW we also need to support: image extends rect.
JKos wrote:
Example: dialog extends the basic rect element
Code: Select all
createDialog(id,x,y,w,h)
local dialog = gw.createElement('rect',id,x,y,w,h)
-- Extend the rect element by defining a new function addButton
dialog.class = 'dialog'
dialog.addButton = function(id,x,y,w,h)
...
local button = gw.createElement('button',id,x,y,w,h)
...
return self.addElement(button)
end
...
end
Why do we need to set dialog.class to any specific value? In what context that would be useful? That's an honest question.
I'm total noob regarding Lua. I wrote a small gui for my OpenWRT package, but that was ages ago and I forgot everything.
JKos wrote:
Everybody (not just me, Xanathar or thomson) should express they opinions soon as possible because it's much harder to change the api and general design principles after we have actually started coding it.
The design sounds reasonable.
Is there a way to calculate width of a text? Calculating absolute positions if the user specifies 'center' or 'right' will be tricky.