Dialog box containing text only - close with mouse click?
Moderator: Forum Moderators
Dialog box containing text only - close with mouse click?
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!
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]
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Dialog box containing text only - close with mouse click
Add
click_dismiss = true
to dialog
. And you can omit that local r =
at the end since you don't do anything with it.Re: Dialog box containing text only - close with mouse click
Great! Thanks!!
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Dialog box containing text only - close with mouse click
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.mattsc wrote:Also, I haven't understood yet if I need to use wesnoth.synchronize_choice for something as simple as this.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: Dialog box containing text only - close with mouse click
Ok, that's what I thought, but I wasn't sure. Thank you!
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Dialog box containing text only - close with mouse click
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.
It works, but notice the
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:
Thanks much!
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
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
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on