[solved] Gui2 dialog formatting

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

Moderator: Forum Moderators

Post Reply
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

[solved] Gui2 dialog formatting

Post by ZombieKnight »

Hi
Could someone help me with my dialog?
Screenshot_20240512_171736.png

Code: Select all

-- to make code shorter
local wml_actions = wesnoth.wml_actions
-- starting values
local font_size_title = 70000
local font_size_message = 70000
local font_family_title = "Oldania ADF Std"
local font_family_message = "Oldania ADF Std"
-- metatable for GUI tags
local T = wml.tag
-- [narration]
-- an alternative interface for messages
-- TODO add [options], [text_input]
function wml_actions.narration( cfg )
	local show_when_unit_hidden = cfg.show_when_unit_hidden or false
	local speaker_unit = true if cfg.speaker_unit == false then speaker_unit = false
	local left_image = cfg.left_image
	local right_image = cfg.right_image
	local unit
	local is_unit_hidden
	if speaker_unit == true then
		local filter = wml.shallow_literal(cfg)
		filter.title = nil
		filter.left_image = nil
		filter.right_image = nil
		filter.message = nil
		table.insert(filter, wml.tag.filter_vision{side = 1})
		--wml.remove_children(filter, 'tag_you_want_to_remove', 'another_tag_you_want_to_remove')
		filter = wml.tovconfig(filter)
		unit = wesnoth.units.find(filter)[1]
		if unit == nil then
			if show_when_unit_hidden == false then
				return
			else
				is_unit_hidden = true
				local filter = wml.shallow_literal(cfg)
				filter.title = nil
				filter.image = nil
				filter.message = nil
				filter = wml.tovconfig(filter)
				unit = wesnoth.units.find(filter)[1]
				if unit == nil then
					return
				end
			end
		else
			is_unit_hidden = false
		end
	end
	--TODO NOW SET IMAGE, IF ANY IMAGE IS PASSED, TO IT, ELSE LEFT FRIEND, RIGHT ENEMY
	if (speaker_unit == true) and (left_image == nil or left_image == "") and (cfg.right_image == nil or cfg.right_image == "") then
		left_image = unit.portrait
		std_print(filesystem.image_size(left_image)) --for original values
	end
	-- if unit is hidden is_unit_hidden = 
	local narration = {
		T.helptip { id="tooltip_large" }, -- mandatory field
        T.tooltip { id="tooltip_large" }, -- mandatory field
        maximum_height = "(gamemap_height)",
        maximum_width = "(gamemap_width)",
        height = "(gamemap_height)",
        width = "(gamemap_width)",
        automatic_placement = false,
        x=0,
    	y="(screen_height-gamemap_height)",
        vertical_grow = true,
        click_dismiss = true,
		-- T.background{
		-- 	T.draw{}
		-- },
		-- T.foreground{
		-- 	T.draw{
		-- 		T.image{
		-- 			x = 100,
		-- 			y = 100,
		-- 			w = 100,
		-- 			h = 100,
		-- 			name = "items/ring-gold.png",
		-- 			mirror = true,
		-- 		}
		-- 	}
		-- },
		T.grid {
			T.row {
				T.column {
					vertical_alignment="bottom",
					horizontal_alignment = "left",
					grow_factor = 1,
					border = "all",
					border_size = 5,
					T.image {
						id = "left_image"
					}
				},
				T.column {
					vertical_alignment="bottom",
					T.stacked_widget{
						id = "narration_stacked_widget",
						definition = "default",
						T.layer{
							T.row {
								T.column {
									horizontal_alignment = "center",
									grow_factor = 1,
									border = "all",
									border_size = 5,
									T.label {
										definition = "title",
										text_alignment = "center",
										id = "narration_title"
									}
								}
							},
							T.row {
								--grow_factor = 0, --TODO idk what this does
								T.column {
									horizontal_alignment = "center",
									grow_factor = 1,
									border = "all",
									border_size = 5,
									T.label {
										definition = "text",
										text_alignment = "center",
										id = "narration_message"
									}
								} --TODO Why two columns doest work, 2 columns everywhere needed
							}
						},
						T.layer{
							T.row {
								T.column {
									horizontal_placement = "left",
        							vertical_placement = "bottom",
									grow_factor = 1,
									border = "all",
									border_size = 5,
									T.text_box {
										id = "space_closing"
									}
								}
							}
						}
					}
				}
			}
		}
	}
	local function narration_preshow(dialog)
		-- here set all widget starting values
		dialog:set_canvas(1, { } )
		dialog.space_closing:focus()
		dialog.space_closing.on_modified = function()
			if dialog.space_closing.text == " " then dialog:close() end
   			dialog.space_closing.text =""
		end
		dialog.narration_stacked_widget.narration_message.visible = true
        dialog.narration_stacked_widget.narration_title.visible = true
		dialog.narration_stacked_widget.space_closing.visible = false
		--dialog.on_left_click = dialog:close() BREAKS WESNOTH
		dialog.narration_title.use_markup = true
		dialog.narration_message.use_markup = true
		local title
		if unit == nil then
			title = cfg.title or  "Narrator"
		else
			title = cfg.title or unit.name
		end
		dialog.left_image.label = "portraits/humans/mage-arch.webp"
		dialog.narration_title.label = "<span size='"..font_size_title.."' font_family='"..font_family_title.."' >"..title.."</span>"
		local message = cfg.message or ""
		dialog.narration_message.label = "<span size='"..font_size_message.."' font_family='"..font_family_message.."' >"..message.."</span>"
		--dialog.image_name.label = cfg.image or ""
	end
	local function narration_postshow(dialog)
		-- here get all widget values
	end
	-- close_func = function close_dialog(dialog)
	-- 	dialog:close()
   	-- end
   	-- dialog:find("narration_message").on_left_click = close_func
	gui.show_dialog( narration, narration_preshow, narration_postshow )
end
called with

Code: Select all

[narration]
            speaker_unit=no
            message=_"This is short message"
        [/narration]
Any idea how to: 1. Align the image to the bottom of the screen?
2. Center the text right into the center between image and right border?

(I'm planning to add an option to add even image from the right)
Last edited by ZombieKnight on May 16th, 2024, 7:20 am, edited 1 time in total.
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Gui2 dialog formatting

Post by ZombieKnight »

I'm sorry I'm pinging you, Vultraz, but you're quite hard to contact and I'm not sure if you check Lua Labs
If that disturbs you, tell me and I won't repeat that ^^
(I've been told you know gui2 a lot)
vultraz wrote:
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
white_haired_uncle
Posts: 1288
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Gui2 dialog formatting

Post by white_haired_uncle »

Well, I'm terrible with lining things up, but it looks like this column is right justified:

Code: Select all

		T.column {
		-- SHOULD HORIZONTAL_ALIGNMENT = "CENTER" GO HERE???
					vertical_alignment="bottom",
					T.stacked_widget{
						id = "narration_stacked_widget",
So, while it looks like you've centered your text inside that column, it's the column itself that (also) needs to be centered. You might add a colored border so you can see what part of the gui the column resides (something I've wanted to test but haven't done yet). If you do try the borders I'd be interested to see the code/results.

Also, and again I'm terrible at this, I would be tempted to go ahead and add the right image (or a spacer of the same size), set grow_factor=0 on the columns of the images and grow factor=1 on the center/text column.

BTW, I doubt it matters but I notice you're using *_placement on your text_box. Is that even valid? I thought placement was only for dialogs.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Gui2 dialog formatting

Post by ZombieKnight »

white_haired_uncle wrote: May 12th, 2024, 4:55 pm Well, I'm terrible with lining things up, but it looks like this column is right justified:

Code: Select all

		T.column {
		-- SHOULD HORIZONTAL_ALIGNMENT = "CENTER" GO HERE???
					vertical_alignment="bottom",
					T.stacked_widget{
						id = "narration_stacked_widget",
So, while it looks like you've centered your text inside that column, it's the column itself that (also) needs to be centered. You might add a colored border so you can see what part of the gui the column resides (something I've wanted to test but haven't done yet). If you do try the borders I'd be interested to see the code/results.

Also, and again I'm terrible at this, I would be tempted to go ahead and add the right image (or a spacer of the same size), set grow_factor=0 on the columns of the images and grow factor=1 on the center/text column.

BTW, I doubt it matters but I notice you're using *_placement on your text_box. Is that even valid? I thought placement was only for dialogs.
You were right! (I had no idea what grow factor actually is)
Screenshot_20240512_193833.png
Thanks <3
Any idea how to move it to the VERY bottom now? ^^
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Gui2 dialog formatting

Post by ZombieKnight »

About that box... idk it's just for skiping messages and I don't really care where it is.
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
white_haired_uncle
Posts: 1288
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Gui2 dialog formatting

Post by white_haired_uncle »

ZombieKnight wrote: May 12th, 2024, 5:40 pm Any idea how to move it to the VERY bottom now? ^^
I think it is at the very bottom, but it has a border:

Code: Select all

border = "all",
border_size = 5,
Try border = "left,right,top" ?
About that box... idk it's just for skiping messages and I don't really care where it is.
Yes, you do. It is a layer of a stacked_widget so wherever it is is where the other layers are too. At least, I think that's how it works.

I don't think those placement lines do anything since (I believe) they are invalid for a column, so they shouldn't change where it is. But if they don't do anything it'd be less confusing if they weren't there.

BTW, when you get this working, please post the completed code. I want to write up some examples using alignment/grow/etc but I have a hard time coming up with them. This would might make a good one.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Gui2 dialog formatting

Post by ZombieKnight »

white_haired_uncle wrote: May 12th, 2024, 6:07 pm I think it is at the very bottom, but it has a border:

Code: Select all

border = "all",
border_size = 5,
Try border = "left,right,top" ?
No, didn't worked (I've tried to set them all to 0 (default value))
Any other idea?
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
User avatar
Ravana
Forum Moderator
Posts: 3070
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Gui2 dialog formatting

Post by Ravana »

Cant explain why it works but it does

Code: Select all

# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
[lua]
	code=<<
-- to make code shorter
local wml_actions = wesnoth.wml_actions
-- starting values
local font_size_title = 70000
local font_size_message = 70000
local font_family_title = "Oldania ADF Std"
local font_family_message = "Oldania ADF Std"
-- metatable for GUI tags
local T = wml.tag
-- [narration]
-- an alternative interface for messages
-- TODO add [options], [text_input]
function wml_actions.narration( cfg )
	local show_when_unit_hidden = cfg.show_when_unit_hidden or false
	local speaker_unit = true 
	if cfg.speaker_unit == false then speaker_unit = false end
	local left_image = cfg.left_image
	local right_image = cfg.right_image
	local unit
	local is_unit_hidden
	if speaker_unit == true then
		local filter = wml.shallow_literal(cfg)
		filter.title = nil
		filter.left_image = nil
		filter.right_image = nil
		filter.message = nil
		table.insert(filter, wml.tag.filter_vision{side = 1})
		filter = wml.tovconfig(filter)
		unit = wesnoth.units.find(filter)[1]
		if unit == nil then
			if show_when_unit_hidden == false then
				return
			else
				is_unit_hidden = true
				local filter = wml.shallow_literal(cfg)
				filter.title = nil
				filter.image = nil
				filter.message = nil
				filter = wml.tovconfig(filter)
				unit = wesnoth.units.find(filter)[1]
				if unit == nil then
					return
				end
			end
		else
			is_unit_hidden = false
		end
	end
	--TODO NOW SET IMAGE, IF ANY IMAGE IS PASSED, TO IT, ELSE LEFT FRIEND, RIGHT ENEMY
	if (speaker_unit == true) and (left_image == nil or left_image == "") and (cfg.right_image == nil or cfg.right_image == "") then
		left_image = unit.portrait
		std_print(filesystem.image_size(left_image)) --for original values
	end
	-- if unit is hidden is_unit_hidden = 
	local narration = {
		T.helptip { id="tooltip_large" }, -- mandatory field
        T.tooltip { id="tooltip_large" }, -- mandatory field
        maximum_height = "(screen_height)",
        maximum_width = "(gamemap_width)",
        height = "(screen_height)",
        width = "(gamemap_width)",
        automatic_placement = false,
        x=0,
    	y="((screen_height-gamemap_height)/2)",
        vertical_grow = true,
        click_dismiss = true,
		T.grid {
			T.row {
				T.column {
					vertical_alignment="bottom",
					horizontal_alignment = "left",
					grow_factor = 1,
					border = "all",
					border_size = 0,
					T.image {
						id = "left_image"
					}
				},
				T.column {
					vertical_alignment="bottom",
					T.stacked_widget{
						id = "narration_stacked_widget",
						definition = "default",
						T.layer{
							T.row {
								T.column {
									horizontal_alignment = "center",
									grow_factor = 1,
									border = "all",
									border_size = 0,
									T.label {
										definition = "title",
										text_alignment = "center",
										id = "narration_title"
									}
								}
							},
							T.row {
								--grow_factor = 0, --TODO idk what this does
								T.column {
									horizontal_alignment = "center",
									grow_factor = 1,
									border = "all",
									border_size = 0,
									T.label {
										definition = "text",
										text_alignment = "center",
										id = "narration_message"
									}
								} --TODO Why two columns doest work, 2 columns everywhere needed
							}
						}
						
					}
				}
			}
		}
	}
	local function narration_preshow(dialog)
		-- here set all widget starting values
		dialog:set_canvas(1, { } )
		dialog.narration_stacked_widget.narration_message.visible = true
        dialog.narration_stacked_widget.narration_title.visible = true
		--dialog.on_left_click = dialog:close() BREAKS WESNOTH
		dialog.narration_title.use_markup = true
		dialog.narration_message.use_markup = true
		local title
		if unit == nil then
			title = cfg.title or  "Narrator"
		else
			title = cfg.title or unit.name
		end
		dialog.left_image.label = "portraits/humans/mage-arch.webp"
		dialog.narration_title.label = "<span size='"..font_size_title.."' font_family='"..font_family_title.."' >"..title.."</span>"
		local message = cfg.message or ""
		dialog.narration_message.label = "<span size='"..font_size_message.."' font_family='"..font_family_message.."' >"..message.."</span>"
		--dialog.image_name.label = cfg.image or ""
	end
	local function narration_postshow(dialog)
		-- here get all widget values
	end
	-- close_func = function close_dialog(dialog)
	-- 	dialog:close()
   	-- end
   	-- dialog:find("narration_message").on_left_click = close_func
	gui.show_dialog( narration, narration_preshow, narration_postshow )
end

wesnoth.wml_actions.narration{
	speaker_unit=false,
	message="This is short message"
}
>>
[/lua]
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Gui2 dialog formatting

Post by ZombieKnight »

Great, works
Thanks ^^
Now any idea how to remove that cancel button (one due to the text input window)
Screenshot_20240513_123535.png
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
User avatar
Ravana
Forum Moderator
Posts: 3070
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Gui2 dialog formatting

Post by Ravana »

Remove text input.
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Gui2 dialog formatting

Post by ZombieKnight »

I need it there.
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
User avatar
Ravana
Forum Moderator
Posts: 3070
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Gui2 dialog formatting

Post by Ravana »

Why?
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Gui2 dialog formatting

Post by ZombieKnight »

Okay, maybe I don't but it took me so much time to ad it there...
Ok I'll remove it.
Thanks for help Ravana and white uncle ^^ <3
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
User avatar
Ravana
Forum Moderator
Posts: 3070
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Gui2 dialog formatting

Post by Ravana »

Code: Select all

# lua wesnoth.require("wml-utils").handle_event_commands(wml.load("~add-ons/EventLoader/action.cfg"))
[lua]
	code=<<
-- to make code shorter
local wml_actions = wesnoth.wml_actions
-- starting values
local font_size_title = 70000
local font_size_message = 70000
local font_family_title = "Oldania ADF Std"
local font_family_message = "Oldania ADF Std"
-- metatable for GUI tags
local T = wml.tag

function ct(c,t)
	if c then 
		return t 
	else 
		return nil
	end
end

local enableRight = true
-- [narration]
-- an alternative interface for messages
-- TODO add [options], [text_input]
function wml_actions.narration( cfg )
	local show_when_unit_hidden = cfg.show_when_unit_hidden or false
	local speaker_unit = true 
	if cfg.speaker_unit == false then speaker_unit = false end
	local left_image = cfg.left_image
	local right_image = cfg.right_image
	local unit
	local is_unit_hidden
	if speaker_unit == true then
		local filter = wml.shallow_literal(cfg)
		filter.title = nil
		filter.left_image = nil
		filter.right_image = nil
		filter.message = nil
		table.insert(filter, wml.tag.filter_vision{side = 1})
		filter = wml.tovconfig(filter)
		unit = wesnoth.units.find(filter)[1]
		if unit == nil then
			if show_when_unit_hidden == false then
				return
			else
				is_unit_hidden = true
				local filter = wml.shallow_literal(cfg)
				filter.title = nil
				filter.image = nil
				filter.message = nil
				filter = wml.tovconfig(filter)
				unit = wesnoth.units.find(filter)[1]
				if unit == nil then
					return
				end
			end
		else
			is_unit_hidden = false
		end
	end
	--TODO NOW SET IMAGE, IF ANY IMAGE IS PASSED, TO IT, ELSE LEFT FRIEND, RIGHT ENEMY
	if (speaker_unit == true) and (left_image == nil or left_image == "") and (cfg.right_image == nil or cfg.right_image == "") then
		left_image = unit.portrait
		std_print(filesystem.image_size(left_image)) --for original values
	end
	-- if unit is hidden is_unit_hidden = 
	local narration = {
		T.helptip { id="tooltip_large" }, -- mandatory field
        T.tooltip { id="tooltip_large" }, -- mandatory field
        maximum_height = "(screen_height)",
        --maximum_height = "(gamemap_height)",
        maximum_width = "(gamemap_width)",
        --height = "(screen_height)",
        --height = "(gamemap_height)",
        --width = "(gamemap_width)",
        automatic_placement = true,
        --x=0,
    	--y="((screen_height-gamemap_height)/2)",
    	--y="42",
		vertical_placement="bottom",
		horizontal_placement="left",
        --vertical_grow = true,
        click_dismiss = true,
		T.grid {
			T.row {
				T.column {
					vertical_alignment="bottom",
					horizontal_alignment = "left",
					--grow_factor = 1,
					border = "all",
					border_size = 0,
					T.image {
						id = "left_image",
						x=0,
						y=500
					}
				},
				ct(enableRight,T.column {
					vertical_alignment="bottom",
					vertical_grow=false,
					T.stacked_widget{
						id = "narration_stacked_widget",
						definition = "default",
						T.layer{
							T.row {
								T.column {
									horizontal_alignment = "center",
									--grow_factor = 1,
									--border = "all",
									--border_size = 0,
									T.label {
										definition = "title",
										text_alignment = "center",
										id = "narration_title"
									}
								}
							},
							T.row {
								--grow_factor = 0, --TODO idk what this does
								T.column {
									horizontal_alignment = "center",
									--grow_factor = 1,
									--border = "all",
									--border_size = 0,
									T.label {
										definition = "text",
										text_alignment = "center",
										id = "narration_message",
										wrap=true
									}
								}
							}
						}
						
					}
				})
			}
		}
	}
	
	local function narration_preshow(dialog)
		-- here set all widget starting values
		--dialog:set_canvas(1, { } )
		--dialog:set_canvas(1, {T.image{name="portraits/humans/mage-arch.webp" }} )
		--dialog:set_canvas(1,  {wml.tag.rectangle { x = 0, y = 0, w = "(width)", h = "(height)", fill_color= "0,0,255,255"} } )
		dialog:set_canvas(1,  {wml.tag.image { x = 0, y = "(height-image_height)", w = "(image_width)", h = "(image_height)", name= "portraits/humans/mage-arch.webp"} } )
		--dialog.left_image.label = "portraits/humans/mage-arch.webp~CROP(200,200,200,200)~O(0)"
		dialog.left_image.label = "portraits/humans/mage-arch.webp~O(0)"
		if enableRight then
			dialog.narration_stacked_widget.narration_message.visible = true
			dialog.narration_stacked_widget.narration_title.visible = true
			dialog.narration_title.use_markup = true
			dialog.narration_message.use_markup = true
			local title
			if unit == nil then
				title = cfg.title or  "Narrator"
			else
				title = cfg.title or unit.name
			end
			dialog.narration_title.label = "<span size='"..font_size_title.."' font_family='"..font_family_title.."' >"..title.."</span>"
			local message = cfg.message or ""
			dialog.narration_message.label = "<span size='"..font_size_message.."' font_family='"..font_family_message.."' >"..message.."</span>"
			--dialog.image_name.label = cfg.image or ""
		end
	end
	local function narration_postshow(dialog)
		-- here get all widget values
	end
	gui.show_dialog( narration, narration_preshow, narration_postshow )
end

wesnoth.wml_actions.narration{
	speaker_unit=false,
	message="This is short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message short message"
}
>>
[/lua]
User avatar
ZombieKnight
Posts: 250
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Gui2 dialog formatting

Post by ZombieKnight »

Code showing two images for comparison of the grid and canvas

Lua:

Code: Select all

-- to make code shorter
local wml_actions = wesnoth.wml_actions
-- starting values
local font_size_title = 70000
local font_size_message = 70000
local font_family_title = "Oldania ADF Std"
local font_family_message = "Oldania ADF Std"
-- metatable for GUI tags
local T = wml.tag
-- [narration]
-- an alternative interface for messages
-- TODO add [options], [text_input]
function wml_actions.narration( cfg )
	local show_when_unit_hidden = cfg.show_when_unit_hidden or false
	local speaker_unit = true 
	if cfg.speaker_unit == false then speaker_unit = false end
	local left_image = cfg.left_image
	local right_image = cfg.right_image
	local unit
	local is_unit_hidden
	if speaker_unit == true then
		local filter = wml.shallow_literal(cfg)
		table.insert(filter, wml.tag.filter_vision{side = 1})
		filter = wml.tovconfig(filter)
		unit = wesnoth.units.find_on_map(filter)[1]
		if unit == nil then
			if show_when_unit_hidden == false then
				return
			else
				is_unit_hidden = true
				local filter = wml.shallow_literal(cfg)
				filter = wml.tovconfig(filter)
				unit = wesnoth.units.find_on_map(filter)[1]
				if unit == nil then
					return
				end
			end
		else
			wesnoth.interface.scroll_to_hex(unit.x,unit.y, false, false, true)
			wesnoth.interface.highlight_hex(unit.x,unit.y)
			wesnoth.interface.select_unit(unit,false,false)
			is_unit_hidden = false
		end
	end
	--TODO NOW SET IMAGE, IF ANY IMAGE IS PASSED, TO IT, ELSE LEFT FRIEND, RIGHT ENEMY
	if (speaker_unit == true) and (left_image == nil or left_image == "" ) and (cfg.right_image == nil or cfg.right_image == "") and (left_image ~= "no_image") then
		
		if wesnoth.units.find_on_map({id = unit.id, {'filter_side',{{'allied_with',{side = 1}}}}})[1] == nil then
			right_image = ""..unit.portrait.."~FL(horizontal)"
		else
			left_image = unit.portrait
		end
	end
	local left_image_table
	if left_image == nil or left_image == "" then
		left_image = ""
		left_image_table = T.label {
			definition = "invalid_image",
			id = "left_image"
		}
	else
		left_image_table = T.image {
			id = "left_image"
		}
	end
	local right_image_table
	if right_image == nil or right_image == "" then
		right_image = ""
		right_image_table = T.label {
			definition = "invalid_image",
			id = "right_image"
		}
	else
		right_image_table = T.image {
			id = "right_image"
		}
	end
	--if unit is hidden is_unit_hidden = 
	local narration = {
		T.helptip { id="tooltip_large" }, -- mandatory field
        T.tooltip { id="tooltip_large" }, -- mandatory field
        maximum_height = "(screen_height)",
        maximum_width = "(gamemap_width)",
        height = "(screen_height)",
        width = "(gamemap_width)",
        automatic_placement = false,
        x=0,
    	y="((screen_height-gamemap_height)/2)",
        vertical_grow = true,
        click_dismiss = true,
		T.grid {
			T.row {
				T.column {
					vertical_alignment="bottom",
					horizontal_alignment = "left",
					grow_factor = 0,
					border = "all",
					border_size = 0,
					left_image_table
				},
				T.column {
					vertical_alignment="bottom",
					grow_factor = 1,
					T.stacked_widget{
						id = "narration_stacked_widget",
						definition = "default",
						T.layer{
							T.row {
								T.column {
									horizontal_alignment = "center",
									grow_factor = 1,
									border = "all",
									border_size = 0,
									T.label {
										definition = "title",
										text_alignment = "center",
										id = "narration_title"
									}
								}
							},
							T.row {
								--grow_factor = 0, --TODO idk what this does
								T.column {
									horizontal_alignment = "center",
									grow_factor = 1,
									border = "all",
									border_size = 0,
									T.scroll_label {
										definition = "text",
										text_alignment = "center",
										id = "narration_message"
									}
								} --TODO Why two columns doest work, 2 columns everywhere needed
							}
						}
					}
				},
				T.column {
					vertical_alignment="bottom",
					horizontal_alignment = "left",
					grow_factor = 0,
					border = "all",
					border_size = 0,
					right_image_table
				}
			}
		}
	}
	local function narration_preshow(dialog)
		-- here set all widget starting values
		dialog:set_canvas(1,  {wml.tag.image { x = 0, y = "(screen_height-image_height)", w = "(image_width)", h = "(image_height)", name = left_image}, wml.tag.image { x = "(gamemap_width-image_width)", y = "(height-image_height)", w = "(image_width)", h = "(image_height)", name = right_image}} )
		dialog.narration_stacked_widget.narration_message.visible = true
        dialog.narration_stacked_widget.narration_title.visible = true
		--dialog.on_left_click = dialog:close() BREAKS WESNOTH
		dialog.narration_title.use_markup = true
		dialog.narration_message.use_markup = true
		local title
		if unit == nil then
			title = cfg.title or  "Narrator"
		else
			title = cfg.title or unit.name
		end
		dialog.left_image.label = left_image
		dialog.right_image.label = right_image
		dialog.narration_title.label = "<span size='"..font_size_title.."' font_family='"..font_family_title.."' >"..title.."</span>"
		local message = cfg.message or ""
		dialog.narration_message.label = "<span size='"..font_size_message.."' font_family='"..font_family_message.."' >"..message.."</span>"
		--dialog.image_name.label = cfg.image or ""
	end
	local function narration_postshow(dialog)
		-- here get all widget values
	end
	-- close_func = function close_dialog(dialog)
	-- 	dialog:close()
   	-- end
   	-- dialog:find("narration_message").on_left_click = close_func
	gui.show_dialog( narration, narration_preshow, narration_postshow )
end



called with:

Code: Select all

[narration]
    speaker_unit=yes
    message=_"I'm really not sure if I want to leave the space behind blank or put there my own background"
[/narration]
I had saurian in profile before, but I've merged my discord profile with forum one...
Working on campaign Bandits from Brown Hills
Post Reply