Elvish_Hunter's Lua thread

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Elvish_Hunter's Lua thread

Post by melinath »

I think that Crendgrim is right that the current layout is confusing. I can't say for sure whether (his?) is better without seeing it in action. Part of the reason that I want to try porting this to ModularLua is that it has some utilities for making dialog creation easier, which would make testing things easier. (Potentially.) I'll let you know how if I make any progress on that.
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Elvish_Hunter's Lua thread

Post by Max »

Crendgrim wrote:This looks a bit cluttered up and you'll search long for the desired information.
My suggestion would be to keep the labels in the top column and use the bottom column for the values:

Code: Select all

 X   Y   Type           Name         ID                Can recruit  Valid  Petrified
 14  10  Elvish Archer  Urandeladir  Elvish Archer-17  no           map    no
why not try to mimic how this information is shown in the unit panel? people or already used to that (apart from x/y coordinates)...
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Elvish_Hunter's Lua thread

Post by Anonymissimus »

melinath wrote:
Anonymissimus wrote: What else could one want than the unit being killed when setting hitpoints to 0 ?
I frequently want to set the hitpoints to 0 to ensure a kill when one unit attacks another.
Actually this use case is valid (and abuses a corner case in the engine). There are some conditions which let the defender always die and the hit animation be played if the defender was at 0hps and the defender dies no matter what the chance to be hit was. Amazing to see thunderers hit with 100% precision. :mrgreen: So it's useful if one needs a second_unit for the events
melinath wrote:Would it be all right with you if I port this into ModularLua?
IMHO a bad idea since it introduces redundant code.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Elvish_Hunter's Lua thread

Post by Elvish_Hunter »

melinath wrote:I think that Crendgrim is right that the current layout is confusing. I can't say for sure whether (his?) is better without seeing it in action.
Done in the latest SVN commit.
Quick_debug_Crend_layout.jpg
I also added [get_movement_type], that I found on the forums, and that was made by silene some time ago :cry: , but that's another story.
Max wrote:why not try to mimic how this information is shown in the unit panel? people or already used to that (apart from x/y coordinates)...
If you're referring to the panel shown on the right side of the screen while playing, that panel doesn't show ID, Can recruit and Valid fields. :wink: Also, I have some formatting limitations, because Label widget doesn't yet support Pango markup - unless it was recently introduced; in this case, I'll do an svn update.
Anonymissimus wrote:Actually this use case is valid (and abuses a corner case in the engine). There are some conditions which let the defender always die and the hit animation be played if the defender was at 0hps and the defender dies no matter what the chance to be hit was. Amazing to see thunderers hit with 100% precision. :mrgreen: So it's useful if one needs a second_unit for the events
So, should I add back the Fire events checkbutton, perhaps making it true by default? And it's even better to see Dragonguards hitting an Elvish Ranger on forest with 100% chance to kill... :twisted:
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Elvish_Hunter's Lua thread

Post by Exasperation »

The label widget does support Pango, but not in a way that's currently accessible from Lua (and since Pango support defaults to off, that means it's currently stuck off). I have a patch pending for it.

Not sure what's going on with the warning. Does it still show up if the unit is at full health to begin with?

Is there a reason that petrified shows up both in the top area as a label and below as a checkbox?

Finally, you can use image path functions (http://wiki.wesnoth.org/ImagePathFunctionWML) in image widgets. So you can do something like

Code: Select all

wesnoth.set_dialog_value ( string.format("%s~TC(%d,magenta)", lua_dialog_unit.__cfg.image, lua_dialog_unit.side), "unit_image" )
and have the unit's image show up properly team-colored. If you felt like it you could even put a couple of conditionals in and use ~GS() to turn the image black&white if the unit is petrified or ~CS() to make it green if poisoned.
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Elvish_Hunter's Lua thread

Post by melinath »

In terms of the look of things: Right now, it mostly looks strange to me to have such a long line of things across the top and then have a narrow two-column layout down the center of the window. Perhaps explore a four-column layout? Try putting the unit picture and stats that are currently across the top down the left side instead.
Anonymissimus wrote:IMHO a bad idea since it introduces redundant code.
Don't worry. I'm not planning on copying it, but rather porting it. This will probably involve a refactor of the code at the time of porting. Especially since this is being implemented as a menu item, whereas I'd prefer to use it as a function. (i.e. debug.unit(x, y))
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Elvish_Hunter's Lua thread

Post by Elvish_Hunter »

Exasperation wrote:Not sure what's going on with the warning. Does it still show up if the unit is at full health to begin with?
It shows every time that a special slider label is shown. In this tag, that means every time that the unit has (or the slider is set to) full HP, 0 HP or full XP. If you have any other question, please ask. :)
Exasperation wrote:Is there a reason that petrified shows up both in the top area as a label and below as a checkbox?
From http://wiki.wesnoth.org/LuaWML:Units :
# petrified, canrecruit: booleans (read only)
# role, facing: strings (read/write)
# status: proxy associative table (read only, read/write fields) (Version 1.9 and later only)
It will be removed, but why we have two petrified (one as direct field, and one inside the status table) in the unit proxy table?
Exasperation wrote:Finally, you can use image path functions (http://wiki.wesnoth.org/ImagePathFunctionWML) in image widgets.
The funny thing is that I already used them in past; I simply didn't yet thought of implementing it. It will be done. :wink:
melinath wrote:In terms of the look of things: Right now, it mostly looks strange to me to have such a long line of things across the top and then have a narrow two-column layout down the center of the window. Perhaps explore a four-column layout? Try putting the unit picture and stats that are currently across the top down the left side instead.
Partially done (I need to make a nested grid for the unit image; when it's finished, I'll commit it):
melinath_layout.jpg
Looks better, now?
Another question: in Python/Tkinter/ttk, when I want to disable a widget inside a dialog, I can set its state as disabled, either while creating it, or using its configure method. Examples:

Code: Select all

disabled_button=Button(self.parent,text="This button is disabled",width=25,state=DISABLED)
disabled_button.configure(text="This button is disabled",state=DISABLED)
and (after using pack, grid or place) the button is grayed out. There is any way to do it in Lua, using wesnoth.set_dialog_callback? I wasn't able to find anything.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: Elvish_Hunter's Lua thread

Post by melinath »

Yeah, I think that looks better.

In terms of widget state: I would love to know this, as well. I tried to figure it out a while back, but though states clearly exist, I couldn't find any way to change between them with Lua.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Elvish_Hunter's Lua thread

Post by Anonymissimus »

Elvish_Hunter wrote:why we have two petrified (one as direct field, and one inside the status table) in the unit proxy table?
The redundancy is also in the engine (unit::incapacitated() to unit::get_state(STATE_PETRIFIED)), apparently silene got confused by that. Well, removing it would break backwards compatibility now...
melinath wrote:but though states clearly exist, I couldn't find any way to change between them with Lua.
Can you describe an ingame situation where a gui2 item gets greyed out ? :P (That'd be the starting point for a lua function setting this.)
IIRC shadowmaster was looking for this too upon writing the *allow_end_turn tags.

EDIT
The preferences don't count afaik since it's not converted to gui2.
Last edited by Anonymissimus on July 3rd, 2011, 3:34 pm, edited 1 time in total.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Elvish_Hunter's Lua thread

Post by Exasperation »

Selectively quoting myself from IRC:
< Exasperation> I've been thinking more about widgets+Lua
< Exasperation> anyway, I've been thinking about what other important capabilities might be missing from the Lua interface to GUI2
< Exasperation> The big thing I noticed that was missing is the ability to assign callbacks to buttons. You (apparently) can make buttons that close the window and return a value, or that don't do anything, but there doesn't yet appear to be a way to attach a function to the button from Lua. I think I see how you would do it, though.
< Exasperation> the minor thing I noticed is that you don't seem to have access to the enable/disable widget commands from Lua
I already submitted a patch for the button callback issue, I could probably put together a patch for enable/disable in the next couple of days (I got distracted by other stuff - such as being able to enable markup in labels - before getting to that part).

I was going to say something about petrified, but Anonymissimus got to it while I was writing this.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Elvish_Hunter's Lua thread

Post by Anonymissimus »

Elvish_Hunter: Can you please remove those log messages. There should only be something in case of an error.
You could use the [wml_message] tag for this in such way that messages important for debugging are omitted if wesnoth was started with --log-debug=wml. But this should only be used for things that are really important and might cause a bug, you get spammed in the long run otherwise.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Elvish_Hunter's Lua thread

Post by Elvish_Hunter »

melinath wrote:Yeah, I think that looks better.
Finished, and committed.
Anonymissimus wrote:gui2 item gets greyed out ?
How can I understand if a dialog is GUI or GUI2? :?:
Anonymissimus wrote:Can you please remove those log messages.
Done.
I also noticed that you made this commit:
UMC-Dev commit 9944 wrote:WLP: fixed out-of-bounds if current values exceed maximums (can be if e.g. set by the debug mode console)
This made me think: "And if the unit has negative experience?" So, I made another commit:
UMC-Dev commit 10012 wrote:Used math.min to avoid out-of-bounds error if unit has negative HP or XP (it may happen by use of debug console, or when fighting against units with negative levels)
Apparently, this will be useful only for HP and HP, since setting moves and attacks left to negative values using the debug console, and then inspecting the unit, results in such values being set to 0 (I tested).
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Elvish_Hunter's Lua thread

Post by Anonymissimus »

Elvish_Hunter wrote:How can I understand if a dialog is GUI or GUI2? :?:
1. You ask mordante.
2. You inspect the code path/call stack of a dialog of interest to see whether it calls stuff from the namespace gui::... or gui2::...
3. You launch the MSVC debugger and follow the code path/call stack to see the same. ^_^
EDIT
4. You search in data/gui/ whether the dialog in question is defined there since afaik gui1 dialogs are hardcoded. But since you don't know what and where to look for you prefer 2).

For the lua dialogs for example it's easy to know where to start (lua.cpp) and to find it (intf_show_dialog etc) and to see that they're all gui2.
Last edited by Anonymissimus on July 5th, 2011, 3:49 pm, edited 1 time in total.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Elvish_Hunter's Lua thread

Post by 8680 »

Elvish_Hunter wrote:This made me think: "And if the unit has negative experience?" So, I made another commit:
UMC-Dev commit 10012 wrote:Used math.min to avoid out-of-bounds error if unit has negative HP or XP (it may happen by use of debug console, or when fighting against units with negative levels)
Shouldn't you have used math.max()?
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Elvish_Hunter's Lua thread

Post by Elvish_Hunter »

Because I needed to set the minimum value of such sliders.

Code: Select all

> return math.max(-5,0)
0
> return math.min(-5,0)
-5
Using math.max won't solve the issue at all, while math.min does. :mrgreen:
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Post Reply