[open] Custom dialog text "center" placement

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

Moderator: Forum Moderators

white_haired_uncle
Posts: 1252
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Custom dialog text "center" placement

Post by white_haired_uncle »

I don't know why there is a close button there. I'm sure it comes from click_dismiss, but it doesn't always add a close button and I don't know why it works one way or the other. I didn't notice it when I had the invisible text_box in there.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 234
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Custom dialog text "center" placement

Post by ZombieKnight »

Maybe it's caused by the slider?
Thanks for patience with me ^^ I read too fast, type even faster and think slowly.
And thanks for the result ofc!
...
How to put a screenshot there?
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: 1252
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Custom dialog text "center" placement

Post by white_haired_uncle »

You have to use the "Post Reply" button. Then there will be an Attachments tab below the edit box.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 234
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Custom dialog text "center" placement

Post by ZombieKnight »

Thanks I've allways seen only the [img ].
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: 234
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: [solved] Custom dialog text "center" placement

Post by ZombieKnight »

white_haired_uncle wrote: April 28th, 2024, 7:37 pm I said vertical_alignment. Like this:
Beautiful ... why does my look different? :cry:
Why does it exceed the right border?
(Really what am I missing?)
Screenshot_20240429_095120.png

Code: Select all

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.grid {
			T.row {
				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"
									}
								}
							}
						}
					}
				}
			}
		}
	}
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: 1252
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: [solved] Custom dialog text "center" placement

Post by white_haired_uncle »

If you post the rest of your code I can try it here.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 234
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Unsolved Custom dialog text "center" placement

Post by ZombieKnight »

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 = cfg.speaker_unit or true
	local unit
	local is_unit_hidden
	if speaker_unit == true then
		local filter = wml.shallow_literal(cfg)
		filter.title = nil
		filter.image = nil
		filter.message = nil
		--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
			return
		end
	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.grid {
			T.row {
				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.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]
            image=""
            message="You rush forward to get the traitor, followed with your men.
And then you hear that heroic meow"
        [/narration]
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: 1252
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Unsolved Custom dialog text "center" placement

Post by white_haired_uncle »

Looks pretty good here. Do you have any other add-ons installed, on perhaps another part of your add-on has a problem? It's probably more likely a version thing, what version of wesnoth are you running (I'm running a very recent 1.19 from git)? What resolution (mine is 1920x1010)?

P.S. You probably want to say, "followed by your men"
narration.png
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 234
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Unsolved Custom dialog text "center" placement

Post by ZombieKnight »

Oh
Ok, anther problem for 1.18 me.
... not sure how to put the unit images there now
Thanks for help <3
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: 1252
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Unsolved Custom dialog text "center" placement

Post by white_haired_uncle »

If you want it to look like [message] you'll probably add another column with a T.image, most likely with dialog.narration_image.label = unit.profile
Speak softly, and carry Doombringer.
white_haired_uncle
Posts: 1252
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Unsolved Custom dialog text "center" placement

Post by white_haired_uncle »

BTW, in the code you comment "TODO Why two columns doest work, 2 columns everywhere needed"

Do you mean "why can't this row have two columns?"? If so, it's because all rows in a grid must have the same number of columns. To get around this, you put grids in grids. I can provide an example if that doesn't make sense.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 234
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Unsolved Custom dialog text "center" placement

Post by ZombieKnight »

It makes sense.
Thanks that's an old note, I've seen, I had no idea about nested [grid] tags.
... (I feel like the most grateful person rn XD)
Thanks... any idea what to set the image when the unit hasn't portrait?

Code: Select all

dialog.narration_image.label = unit.portrait or WhatToPutHere?
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: 1252
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Unsolved Custom dialog text "center" placement

Post by white_haired_uncle »

You mean dialog.narration_image.label = unit.profile ?

If your unit doesn't have a profile, I'd fix your unit. If you want a fallback (instead of the image not found icon), you could pick something from data/core/images/portraits/
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 234
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Unsolved Custom dialog text "center" placement

Post by ZombieKnight »

Oki
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: 234
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Unsolved Custom dialog text "center" placement

Post by ZombieKnight »

It's been a long time... ported to 1.18 and found the problem...
However, I don't know how to solve it:
Dialog is in the center while in the non-start event...
Do you know how to move it into the center at the start event? / Why it isn't in the center at the start event?
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