Add color=value to [message] (#651)
Add support for the pango attributes as keys in [message] This is equivalent to surrounding the entire string in a span with the specified attribtues.
This commit is contained in:
parent
893607e077
commit
d22b15b19b
3 changed files with 133 additions and 1 deletions
|
@ -26,6 +26,7 @@ Version 1.13.4+dev:
|
|||
* Improved the dialog for choosing what to do when a player leaves in
|
||||
multiplayer.
|
||||
* WML engine:
|
||||
* Add color= attribute to [message].
|
||||
* Fix some issues with [foreach]
|
||||
* Fix some issues with backstab-like weapon specials
|
||||
* Support [effect]times=<integer>
|
||||
|
|
|
@ -1320,6 +1320,9 @@
|
|||
name = "Paŭlo Ebermann (Pauxlo)"
|
||||
wikiuser = "Pauxlo"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "Pentarctagon"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "Peter Elmers"
|
||||
[/entry]
|
||||
|
|
|
@ -52,6 +52,131 @@ local function get_caption(cfg, speaker)
|
|||
return caption
|
||||
end
|
||||
|
||||
local function get_pango_color(color)
|
||||
local pango_color = "#"
|
||||
|
||||
-- if a hex color was passed in
|
||||
-- or if a color string was passed in - contains no non-letter characters
|
||||
-- just use that
|
||||
if string.sub(color, 1, 1) == "#" or not string.match(color, "%A+") then
|
||||
pango_color = color
|
||||
-- decimal color was passed in, convert to hex color for pango
|
||||
else
|
||||
for s in string.gmatch(color, "%d+") do
|
||||
pango_color = pango_color .. tonumber(s, 16)
|
||||
end
|
||||
end
|
||||
|
||||
return pango_color
|
||||
end
|
||||
|
||||
-- add formatting
|
||||
local function add_formatting(cfg, text)
|
||||
-- span tag
|
||||
local formatting = "<span"
|
||||
|
||||
-- if message text, add formatting
|
||||
if text and cfg then
|
||||
-- add font
|
||||
if cfg.font and cfg.font ~= '' then
|
||||
formatting = formatting .. " font='" .. cfg.font .. "'"
|
||||
end
|
||||
|
||||
-- add font_family
|
||||
if cfg.font_family and cfg.font_family ~= '' then
|
||||
formatting = formatting .. " font_family='" .. cfg.font_family .. "'"
|
||||
end
|
||||
|
||||
-- add font_size
|
||||
if cfg.font_size and cfg.font_size ~= '' then
|
||||
formatting = formatting .. " font_size='" .. cfg.font_size .. "'"
|
||||
end
|
||||
|
||||
-- font_style
|
||||
if cfg.font_style and cfg.font_style ~= '' then
|
||||
formatting = formatting .. " font_style='" .. cfg.font_style .. "'"
|
||||
end
|
||||
|
||||
-- font_weight
|
||||
if cfg.font_weight and cfg.font_weight ~= '' then
|
||||
formatting = formatting .. " font_weight='" .. cfg.font_weight .. "'"
|
||||
end
|
||||
|
||||
-- font_variant
|
||||
if cfg.font_variant and cfg.font_variant ~= '' then
|
||||
formatting = formatting .. " font_variant='" .. cfg.font_variant .. "'"
|
||||
end
|
||||
|
||||
-- font_stretch
|
||||
if cfg.font_stretch and cfg.font_stretch ~= '' then
|
||||
formatting = formatting .. " font_stretch='" .. cfg.font_stretch .. "'"
|
||||
end
|
||||
|
||||
-- add color
|
||||
if cfg.color and cfg.color ~= '' then
|
||||
formatting = formatting .. " color='" .. get_pango_color(cfg.color) .. "'"
|
||||
end
|
||||
|
||||
-- bgcolor
|
||||
if cfg.bgcolor and cfg.bgcolor ~= '' then
|
||||
formatting = formatting .. " bgcolor='" .. get_pango_color(cfg.bgcolor) .. "'"
|
||||
end
|
||||
|
||||
-- underline
|
||||
if cfg.underline and cfg.underline ~= '' then
|
||||
formatting = formatting .. " underline='" .. cfg.underline .. "'"
|
||||
end
|
||||
|
||||
-- underline_color
|
||||
if cfg.underline_color and cfg.underline_color ~= '' then
|
||||
formatting = formatting .. " underline_color='" .. get_pango_color(cfg.underline_color) .. "'"
|
||||
end
|
||||
|
||||
-- rise
|
||||
if cfg.rise and cfg.rise ~= '' then
|
||||
formatting = formatting .. " rise='" .. cfg.rise .. "'"
|
||||
end
|
||||
|
||||
-- strikethrough
|
||||
if cfg.strikethrough and tostring(cfg.strikethrough) ~= '' then
|
||||
formatting = formatting .. " strikethrough='" .. tostring(cfg.strikethrough) .. "'"
|
||||
end
|
||||
|
||||
-- strikethrough_color
|
||||
if cfg.strikethrough_color and cfg.strikethrough_color ~= '' then
|
||||
formatting = formatting .. " strikethrough_color='" .. get_pango_color(cfg.strikethrough_color) .. "'"
|
||||
end
|
||||
|
||||
-- fallback
|
||||
if cfg.fallback and tostring(cfg.fallback) ~= '' then
|
||||
formatting = formatting .. " fallback='" .. tostring(cfg.fallback) .. "'"
|
||||
end
|
||||
|
||||
-- letter_spacing
|
||||
if cfg.letter_spacing and cfg.letter_spacing ~= '' then
|
||||
formatting = formatting .. " letter_spacing='" .. cfg.letter_spacing .. "'"
|
||||
end
|
||||
|
||||
-- gravity
|
||||
if cfg.gravity and cfg.gravity ~= '' then
|
||||
formatting = formatting .. " gravity='" .. cfg.gravity .. "'"
|
||||
end
|
||||
|
||||
-- gravity_hint
|
||||
if cfg.gravity_hint and cfg.gravity_hint ~= '' then
|
||||
formatting = formatting .. " gravity_hint='" .. cfg.gravity_hint .. "'"
|
||||
end
|
||||
|
||||
-- wrap in span tags and return if a color was added
|
||||
if formatting ~= "<span" then
|
||||
return formatting .. ">" .. text .. "</span>"
|
||||
end
|
||||
end
|
||||
|
||||
-- or return unmodified message
|
||||
return text
|
||||
end
|
||||
|
||||
local function get_speaker(cfg)
|
||||
local speaker
|
||||
local context = wesnoth.current.event_context
|
||||
|
@ -87,7 +212,10 @@ local function message_user_choice(cfg, speaker, options, text_input)
|
|||
msg_cfg.message = cfg.female_message
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- add formatting
|
||||
msg_cfg.message = add_formatting(cfg, cfg.message)
|
||||
|
||||
-- Parse input text, if not available all fields are empty
|
||||
if text_input then
|
||||
local input_max_size = tonumber(text_input.max_length) or 256
|
||||
|
|
Loading…
Add table
Reference in a new issue