Dialog box containing text only - close with mouse click?

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

Moderators: Forum Moderators, Developers

Post Reply
mattsc
Posts: 1119
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Dialog box containing text only - close with mouse click?

Post by mattsc » August 13th, 2011, 4:26 am

Hello Lua experts,

I've been trying to display a "framed" dialog message that simply shows text in the format of some of the standard Wesnoth messages, such as "It is now XXX's turn", the objectives, defeat messages etc. I'm in way over my head here, but with the help of the posts on this forum and copious stealing from them, I've been able to get a replica of the defeat message working (see code below).

Well, it's almost working the same way. I can only close this dialog box with the enter or escape key, while the standard messages can also be closed with a mouse click (or the space bar). Does anybody know if there is a way to include closing by mouse click? Or maybe this is a stupid question and there's a much simpler way to do this?

Also, I haven't understood yet if I need to use wesnoth.synchronize_choice for something as simple as this.

Thanks very much in advance for any help!

Code: Select all

        [lua]
            code=<<
local helper = wesnoth.require "lua/helper.lua"
local T = helper.set_wml_tag_metatable {}
local _ = wesnoth.textdomain "wesnoth"

local dialog = {
  T.tooltip { id = "tooltip_large" },
  T.helptip { id = "tooltip_large" },
  T.grid { 
      T.row { T.column { horizontal_alignment = "left",
          grow_factor = 1, -- this one makes the title bigger and golden
          border = "all",
          border_size = 5,
          T.label { definition = "title", label = "Defeat" } } },
      T.row { T.column { horizontal_alignment = "left",
          border = "all",
          border_size = 5,
          T.label { label = _"You have been defeated!" } } }
 }
}

local r = wesnoth.show_dialog(dialog)
            >>
        [/lua]

User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Dialog box containing text only - close with mouse click

Post by 8680 » August 13th, 2011, 5:28 am

Add click_dismiss = true to dialog. And you can omit that local r = at the end since you don't do anything with it.

mattsc
Posts: 1119
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Dialog box containing text only - close with mouse click

Post by mattsc » August 13th, 2011, 6:07 am

Great! Thanks!!

Anonymissimus
Inactive Developer
Posts: 2458
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Dialog box containing text only - close with mouse click

Post by Anonymissimus » August 13th, 2011, 12:02 pm

mattsc wrote:Also, I haven't understood yet if I need to use wesnoth.synchronize_choice for something as simple as this.
You need it only if the dialog is to be used in networked multiplayer, and even then strictly speaking only if the dialog is querying user input (such as entering text or choosing an option among several), what your dialog above doesn't do.
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

mattsc
Posts: 1119
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Dialog box containing text only - close with mouse click

Post by mattsc » August 13th, 2011, 2:08 pm

Ok, that's what I thought, but I wasn't sure. Thank you!

mattsc
Posts: 1119
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Dialog box containing text only - close with mouse click

Post by mattsc » August 15th, 2011, 9:50 pm

Hi All, I have a follow-up question. I wrote a little lua function that creates a tag [dialog_message]. It takes one key (message) and does nothing but display a dialog message until it is dismissed.

Code: Select all

function wesnoth.wml_actions.dialog_message(cfg)
    -- Set up tag [dialog_message]
    -- Displays centered, framed, clickable message
    -- Only key: message

    local message=(cfg.message)

    local dialog = {
        T.tooltip { id = "tooltip_large" },
        T.helptip { id = "tooltip_large" },
        T.grid { 
            T.row { T.column { horizontal_alignment = "left",
                border = "all",
                border_size = 5,
                T.label { label = message } } }
        },
        click_dismiss = true
    }

    wesnoth.delay(20)
    wesnoth.show_dialog(dialog)
end
It works, but notice the wesnoth.delay(20). If I do not put that there (or after show_dialog, that works too) and put several [dialog_message] tags in a row into a scenario, things will get very slow or even freeze entirely.

As this works, this isn't very important for this tag, and a 20 ms delay is not really noticeable anyway. However, it feels "inelegant" and I am wondering if I am doing something wrong in general that will cause bigger problems once I start diving into more complicated lua code.

Just in case it is important, this sits inside lua/wml-tags.lua in my campaign directory and is include in _main.cfg like this:

Code: Select all

#ifdef CAMPAIGN_GRNK
[lua]
    code = << wesnoth.dofile("~add-ons/Grnk/lua/wml-tags.lua") >>
[/lua]
#endif
Thanks much!

Post Reply