project-navigation
Personal tools

Author Topic: lua design thoughts  (Read 70396 times)

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #75 on: November 18, 2014, 09:20:17 pm »
Can you post the full translation?

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #77 on: November 19, 2014, 07:32:37 pm »
Yet another thing - how to apply string value to cvar?

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #78 on: November 19, 2014, 08:20:09 pm »
Fixed a bug in the confunc execution. It should work properly now. Added some improvements to the confunc code also.
As for the call the 'removeAllChild', it wasn't implemented yet. I've added it, however it is renamed to "remove_childs".
Please pull the latest fixes from the repository at rxadmin/ufoai.

I also checked youre translation at:
https://github.com/drone-pl/ufoai/blob/df015731694cb77c069f19724c3046e75f2d67b6/base/ufos/ui/mailclient.ufo

There are some places where you query for a child at the wrong level. E.g. in add_mail, you were referencing "mail:child("header"):child("icon").." however "icon" is positioned as a direct child node of "mail", not "header".
Also index can be directly accessed as it is a parameter given to the call.

I've added the corrected version to the rxadmin/ufoai repository as well.

xray.



Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #79 on: November 19, 2014, 08:27:39 pm »
Yet another thing - how to apply string value to cvar?

It is not yet implemented. I've postponed this since I wanted to first find a way to create and reuse variables inside node using lua only. This involves creating lua based table properties that are linked to values stored inside a node. A bit like a callback mechanism only for variables. If I can find a way I can bring lua dynamic variables into the UI.

Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #80 on: November 22, 2014, 09:31:51 am »
Hmm, seems like nodes created in confuncs are treated as statically created and cannot be removed via remove_childs (which removes only dynamically nodes).

Another feature request: implement starlayout and preventtypingescape for uiWindow.

P.S. btw, just as a matter of fact, 'childs' may be not a proper word, because plural word for 'child' is 'children' :)
« Last Edit: November 22, 2014, 12:41:25 pm by Internecivus »

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #81 on: November 22, 2014, 04:51:59 pm »
Hmm, seems like nodes created in confuncs are treated as statically created and cannot be removed via remove_childs (which removes only dynamically nodes).

True. I copied the creation code directly from ui_parse.cpp, the module parsing the ufo scripts. So any node created using lua is basically a static node. However, I think it should be easy to extend the current mechanism with a flag indicating that a dynamic node should be created. I'll look into this.

Quote
Another feature request: implement starlayout and preventtypingescape for uiWindow.

I'll put it on the 'todo' list.

Quote
P.S. btw, just as a matter of fact, 'childs' may be not a proper word, because plural word for 'child' is 'children' :)

I'll rename it. We don't want to have any typos here.

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #82 on: November 23, 2014, 11:16:51 am »
Hmm, seems like nodes created in confuncs are treated as statically created and cannot be removed via remove_childs (which removes only dynamically nodes).

I've added an extra parameter to the node creation functions allowing the creation of dynamic nodes. Usage:
Code: [Select]
local mail = ufo.create_control(mails, "mailheader", "mail" .. index, nil, ufo.DYNAMIC_CONTROL)

This solves the problem, however, I'm not happy with this solution. The solution forces the lua side to have knowledge about static/dynamic nodes and when to use them.

If I look at the code, I have the strong feeling that static nodes are only created during the initial script loading stage and are never created by events and confuncs. If that is the case, the switch between static/dynamic can be made after the parsing stage and it should not become an extra parameter on the lua side. I would like someone to confirm this so I can refactor the implementation.


Offline Internecivus

  • Rookie
  • ***
  • Posts: 64
  • Sometimes I Code
    • View Profile
Re: lua design thoughts
« Reply #83 on: November 23, 2014, 12:13:06 pm »
If I look at the code, I have the strong feeling that static nodes are only created during the initial script loading stage and are never created by events and confuncs.

AFAIK you are right.

P.S. Can you check if on_viewchange is working properly?
In 'mail' window, for example, it has to update scrollbar fullsize and viewsize property and if fullsize is greater than viewsize, scrollbar should appear (autoshowscroll(true)). I don't see scrollbar regardless of the size of the mail text.
« Last Edit: November 23, 2014, 12:48:35 pm by Internecivus »

Offline geever

  • Project Coder
  • PHALANX Commander
  • ***
  • Posts: 2561
    • View Profile
Re: lua design thoughts
« Reply #84 on: November 23, 2014, 01:14:08 pm »
xray, I think Bayo's intention was converting every node to dynamic ones, but he did not have time to finish it. So having them all dynamic is good.

-geever

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #85 on: November 23, 2014, 03:47:37 pm »
OK. I'm going to make all lua created nodes dynamic. This will remove the previous implemented "flags" paramater in the node creation functions.

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #86 on: November 23, 2014, 04:40:02 pm »
P.S. Can you check if on_viewchange is working properly?
In 'mail' window, for example, it has to update scrollbar fullsize and viewsize property and if fullsize is greater than viewsize, scrollbar should appear (autoshowscroll(true)). I don't see scrollbar regardless of the size of the mail text.

You were right. There was a rather annoying bug here. It also prevented the trigger on various other event handlers. I've fixed it and on_viewchange is now properly called. However, this did not solved the viewsize issue. I'll have to look into this a bit further.

I've also changed the creation of nodes. They now are allways dynamic nodes. This triggered an assertion in the execution of func/confunc nodes. It didn't liked dynamic nodes. Possibly to prevent the execution of nodes being deleted. I've removed this assertion but we do need a safeguard against this situation.

Offline Sandro

  • Squad Leader
  • ****
  • Posts: 240
  • Maintenance guy for UFO:AI 3D engine
    • View Profile
Re: lua design thoughts
« Reply #87 on: November 23, 2014, 05:14:26 pm »
Just keep the list of deleted nodes? It could not be so big if you code it seperately, in a map for example. If memory serves, LUA provides the hashmap class?

Offline geever

  • Project Coder
  • PHALANX Commander
  • ***
  • Posts: 2561
    • View Profile
Re: lua design thoughts
« Reply #88 on: November 23, 2014, 07:14:21 pm »
newer UI scripts use "delete all & create nodes" approach quite heavily..

Offline xray

  • Rookie
  • ***
  • Posts: 72
    • View Profile
Re: lua design thoughts
« Reply #89 on: November 26, 2014, 09:36:07 pm »
Another thing.

Window 'mail' is inherited from ipopup.
It has
Code: [Select]
mail:set_closebutton(true)But I don't see any close button somehow.
And another thing is that this window takes up all place.

I've fixed the issues with the close button and the sizing. All these issues were actually related to a fundamental difference in node creating using ufo script and using lua. In ufo script, the node is created, then the properties are read and set and only after that the node is inserted and onLoaded is called. In lua, the node is created, inserted and onLoaded is called. Then the remainder of the lua code sets various properties. This resulted in the isFullscreen flag being incorrect, resulting in the wrong sizing and the closebutton/dragbutton not being created.