custom UI controls?

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.

custom UI controls?

Postby lea » June 4th, 2017, 11:44 am

I endeavored to customize BfW's UI theme to my liking (as per ThemeWML wiki page) and it provides enough tools to rearrange existing controls and adapt it to different resolutions.

But what about customizing controls themselves?
Is it possible to (for example) show unit's abilities one per row instead of all in the same row?
or show a value of certain WML variable in GUI?
or show stats of highlighted unit in on one UI panel while simultaneously showing stats of currently selected unit in another?
or add a scrollbar to a panel so that its parts that are beyond its size (or screen boundaries) can be seen by user?
author of: Altered Era/Ruleset (on BfW 1.12 and BfW 1.10 add-ons servers)
lea
 
Posts: 124
Joined: October 1st, 2016, 7:25 pm

Re: custom UI controls?

Postby Celtic_Minstrel » June 8th, 2017, 1:01 am

I believe most of those are indeed possible. (I know of no way to add a scrollbar, though.) The first two (abilities in one line and value of a variable) would probably require Lua. There is also a semi-working theme already that shows the stats of two units simultaneously — I think it's called the "widescreen theme", and you can switch to it in the preferences.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 754
Joined: August 3rd, 2012, 11:26 pm

Re: custom UI controls?

Postby lea » June 8th, 2017, 9:27 am

Celtic_Minstrel wrote:The first two (abilities in one line and value of a variable) would probably require Lua.
any pointers as to where to look for examples?

Celtic_Minstrel wrote: There is also a semi-working theme already that shows the stats of two units simultaneously — I think it's called the "widescreen theme", and you can switch to it in the preferences.
cannot see in in Wesnoth v1.12.6, was it added in 1.13?
author of: Altered Era/Ruleset (on BfW 1.12 and BfW 1.10 add-ons servers)
lea
 
Posts: 124
Joined: October 1st, 2016, 7:25 pm

Re: custom UI controls?

Postby shadowm » June 9th, 2017, 12:58 am

It was removed before 1.11.16 (from the 1.12 branch only) because it was considered broken in some way. This would be the last version of the theme for 1.11.x/1.12.x prior to removal.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
I also made Wesnoth RCX, a team-color preview tool for artists and content creators.
Elsewhere: shadowmBlogFollow me on Twitter
User avatar
shadowm
Wesnoth.org Administrator
 
Posts: 6177
Joined: November 14th, 2006, 5:54 pm
Location: Chile

Re: custom UI controls?

Postby Celtic_Minstrel » June 9th, 2017, 1:43 am

This page has an example of using Lua to add a custom status effect, but that API can in fact customize all the data in the theme. Since you've already looked into ThemeWML I imagine you'll already have some idea of what each part does; unfortunately they're not really described in much detail there, but the names (unit_status etc) are the same as the tags in ThemeWML.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 754
Joined: August 3rd, 2012, 11:26 pm

Re: custom UI controls?

Postby lea » June 9th, 2017, 4:59 am

shadowm, thanks for the pointer!

Celtic_Minstrel, your link to Lua wiki page seems to be invalid...
EDIT: I think I found correct version of your link: https://wiki.wesnoth.org/LuaWML/Display ... heme_items
Last edited by lea on June 9th, 2017, 5:02 am, edited 1 time in total.
author of: Altered Era/Ruleset (on BfW 1.12 and BfW 1.10 add-ons servers)
lea
 
Posts: 124
Joined: October 1st, 2016, 7:25 pm

Re: custom UI controls?

Postby Celtic_Minstrel » June 9th, 2017, 5:02 am

Whoops, fixed.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 754
Joined: August 3rd, 2012, 11:26 pm

Re: custom UI controls?

Postby lea » June 9th, 2017, 6:02 am

Seems understandable except one thing: where this piece of Lua code should go to be correctly included in my custom UI theme? could anybody please point to an example?

any example of using something/anything from wesnoth.theme_items in actual UI theme should do

the most common usage of Lua seems to be inclusion of lua code into event handlers - is there an event for UI refreshing or it should be included in some other place?
author of: Altered Era/Ruleset (on BfW 1.12 and BfW 1.10 add-ons servers)
lea
 
Posts: 124
Joined: October 1st, 2016, 7:25 pm

Re: custom UI controls?

Postby Celtic_Minstrel » June 10th, 2017, 2:13 am

My campaign does something basically the same as the example. Lua code here, referenced here. In other words, just a [lua] tag anywhere should work; however, if it's not for a campaign, you should instead put the [lua] tag within [era] or [modification] so it's only loaded when it needs to be,
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 754
Joined: August 3rd, 2012, 11:26 pm

Re: custom UI controls?

Postby lea » June 10th, 2017, 8:20 am

Thanks for examples!
So UI elements call Lua functions with certain names when they render/refresh themselves?
Is it possible to include my Lua code into UI theme, so that it does not affect other UI themes?
author of: Altered Era/Ruleset (on BfW 1.12 and BfW 1.10 add-ons servers)
lea
 
Posts: 124
Joined: October 1st, 2016, 7:25 pm

Re: custom UI controls?

Postby gfgtdf » June 10th, 2017, 1:22 pm

Celtic_Minstrel wrote:My campaign does something basically the same as the example. Lua code here, referenced here. In other words, just a [lua] tag anywhere should work; however, if it's not for a campaign, you should instead put the [lua] tag within [era] or [modification] so it's only loaded when it needs to be,

Note however that before wesnoth 1.13 [lua] might not be reccognized directly in [era] or [modification], so you have to put it in a preload event.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
gfgtdf
Developer
 
Posts: 899
Joined: February 10th, 2013, 2:25 pm

Re: custom UI controls?

Postby lea » June 10th, 2017, 6:23 pm

gfgtdf wrote:Note however that before wesnoth 1.13 [lua] might not be reccognized directly in [era] or [modification], so you have to put it in a preload event.
this does not seem to be a problem as long as I can detect which UI theme is used so that my changes do not mangle UI themes other than those it is meant to affect. how can that be achieved?
author of: Altered Era/Ruleset (on BfW 1.12 and BfW 1.10 add-ons servers)
lea
 
Posts: 124
Joined: October 1st, 2016, 7:25 pm

Re: custom UI controls?

Postby Celtic_Minstrel » June 11th, 2017, 4:02 am

As far as I know, there's no way to detect the currently-active theme in 1.12. In 1.13 you can read a Lua variable, which if I recall correctly is wesnoth.game_config.theme. If you need something that will work on 1.12 though, the best I can think of is somehow having a WML variable that's set only if your theme is active... and that would only be possible if the theme is linked to an era, modification, scenario, or campaign.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
 
Posts: 754
Joined: August 3rd, 2012, 11:26 pm

Re: custom UI controls?

Postby lea » June 11th, 2017, 5:39 am

Thanks, Celtic_Minstrel
looks like the best thing I can do usability-wise is to provide an option to turn it off...
author of: Altered Era/Ruleset (on BfW 1.12 and BfW 1.10 add-ons servers)
lea
 
Posts: 124
Joined: October 1st, 2016, 7:25 pm

Re: custom UI controls?

Postby lea » August 23rd, 2017, 6:42 am

Celtic_Minstrel wrote:My campaign does something basically the same as the example. Lua code here, referenced here. In other words, just a [lua] tag anywhere should work; however, if it's not for a campaign, you should instead put the [lua] tag within [era] or [modification] so it's only loaded when it needs to be,
it works for custom unit statuses and I tried to modify it to change text of [income] UI element? like this:
Code: Select all
    [event]
        name=start #also tried preload and other one-time events
        first_time_only=yes
        [lua]
            code = <<
                local old_income = wesnoth.theme_items.income
                function wesnoth.theme_items.income()
                    local new_income = old_income()
                    table.insert(new_income, { "element", {
                    text = "123"
                    } })
                end
                return new_income
            >>
        [/lua]
    [/event]
and got error message from wesnoth:
Code: Select all
[string "..."]:6: bad argument #1 to 'insert' (table expected, got nil)

and income indicator went blank (except income icon is still there since it is a separate UI element)
tried to remove table.insert command - error message vanished but income indicator is still blank. tried to put constant values after "return" command instead of new_income variable (like "text" and 123) - income indicator is blank regardless.

I guess "income" is not a table unlike "status" - if so then how to edit it?
anybody tried to do similar things with any of text/number UI elements in wesnoth UI theme?
author of: Altered Era/Ruleset (on BfW 1.12 and BfW 1.10 add-ons servers)
lea
 
Posts: 124
Joined: October 1st, 2016, 7:25 pm

Next

Return to WML Workshop

Who is online

Users browsing this forum: GreatLord and 3 guests