Skip to content

Commit

Permalink
Two new [message] features
Browse files Browse the repository at this point in the history
- ~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"
  • Loading branch information
CelticMinstrel committed Apr 2, 2016
1 parent 20b07c6 commit 7c37ad5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion data/core/units/humans/Mage_Silver.cfg
Expand Up @@ -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]
Expand Down
34 changes: 23 additions & 11 deletions data/lua/wml/message.lua
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7c37ad5

Please sign in to comment.