From 7c37ad57bd5858bc15a10d1e9f0deaa57a22467a Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Wed, 16 Mar 2016 17:32:27 -0400 Subject: [PATCH] Two new [message] features - ~LEFT() does the opposite of ~RIGHT(), but takes higher priority; use it to force an image to the left that's normally on the right (eg female silver mage) - image=~RIGHT() means "use normal portrait, but on the right" --- data/core/units/humans/Mage_Silver.cfg | 2 +- data/lua/wml/message.lua | 34 +++++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/data/core/units/humans/Mage_Silver.cfg b/data/core/units/humans/Mage_Silver.cfg index cd5a0c668ca7..1fefde626fb4 100644 --- a/data/core/units/humans/Mage_Silver.cfg +++ b/data/core/units/humans/Mage_Silver.cfg @@ -161,7 +161,7 @@ Silver magi are often more physically adept than other magi, and their skills ar name= _ "female^Silver Mage" gender=female image="units/human-magi/silver-mage+female.png" - profile="portraits/humans/mage-silver+female.png" + profile="portraits/humans/mage-silver+female.png~LEFT()" die_sound={SOUND_LIST:HUMAN_FEMALE_DIE} {DEFENSE_ANIM "units/human-magi/silver-mage+female-defend.png" "units/human-magi/silver-mage+female.png" {SOUND_LIST:HUMAN_FEMALE_HIT} } [attack_anim] diff --git a/data/lua/wml/message.lua b/data/lua/wml/message.lua index 01c8f61137ae..8f5b3629bca9 100644 --- a/data/lua/wml/message.lua +++ b/data/lua/wml/message.lua @@ -13,16 +13,36 @@ end local function get_image(cfg, speaker) local image = cfg.image + local left_side = true + + if image == "~RIGHT()" then + image = nil + left_side = false + end if speaker and (image == nil or image == "") then image = speaker.portrait end + if image:find("~RIGHT%(%)") then + left_side = false + -- The percent signs escape the parentheses for a literal match + image = image:gsub("~RIGHT%(%)", "") + end + + if image:find("~LEFT%(%)") then + -- This currently overrides ~RIGHT() + -- Use if a portrait defaults to ~RIGHT(), + -- or in [unit_type] to force it to left. + left_side = true + image = image:gsub("~LEFT%(%)", "") + end + if image == "none" or image == nil then - return "" + return "", true end - return image + return image, left_side end local function get_caption(cfg, speaker) @@ -53,17 +73,9 @@ local function get_speaker(cfg) end local function message_user_choice(cfg, speaker, options, text_input) - local image = get_image(cfg, speaker) + local image, left_side = get_image(cfg, speaker) local caption = get_caption(cfg, speaker) - local left_side = true - -- If this doesn't work, might need tostring() - if image:find("~RIGHT()") then - left_side = false - -- The percent signs escape the parentheses for a literal match - image = image:gsub("~RIGHT%(%)", "") - end - local msg_cfg = { left_side = left_side, title = caption,