aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/textures/advtrains_hud_jp_ars.pngbin249 -> 0 bytes
-rw-r--r--advtrains/textures/advtrains_hud_jp_atc.pngbin136 -> 0 bytes
-rw-r--r--advtrains/textures/advtrains_hud_jp_autocouple.pngbin200 -> 0 bytes
-rw-r--r--advtrains/textures/advtrains_hud_jp_forward.pngbin104 -> 0 bytes
-rw-r--r--advtrains/textures/advtrains_hud_jp_lzb.pngbin190 -> 0 bytes
-rw-r--r--advtrains/textures/advtrains_hud_jp_reverse.pngbin118 -> 0 bytes
-rw-r--r--advtrains/textures/advtrains_hud_jp_shunt.pngbin156 -> 0 bytes
-rw-r--r--advtrains/trainhud_presets.lua72
-rw-r--r--advtrains/unifont.lua27
9 files changed, 70 insertions, 29 deletions
diff --git a/advtrains/textures/advtrains_hud_jp_ars.png b/advtrains/textures/advtrains_hud_jp_ars.png
deleted file mode 100644
index d090474..0000000
--- a/advtrains/textures/advtrains_hud_jp_ars.png
+++ /dev/null
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_jp_atc.png b/advtrains/textures/advtrains_hud_jp_atc.png
deleted file mode 100644
index bedc00d..0000000
--- a/advtrains/textures/advtrains_hud_jp_atc.png
+++ /dev/null
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_jp_autocouple.png b/advtrains/textures/advtrains_hud_jp_autocouple.png
deleted file mode 100644
index 09be074..0000000
--- a/advtrains/textures/advtrains_hud_jp_autocouple.png
+++ /dev/null
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_jp_forward.png b/advtrains/textures/advtrains_hud_jp_forward.png
deleted file mode 100644
index 60a4659..0000000
--- a/advtrains/textures/advtrains_hud_jp_forward.png
+++ /dev/null
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_jp_lzb.png b/advtrains/textures/advtrains_hud_jp_lzb.png
deleted file mode 100644
index 968669b..0000000
--- a/advtrains/textures/advtrains_hud_jp_lzb.png
+++ /dev/null
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_jp_reverse.png b/advtrains/textures/advtrains_hud_jp_reverse.png
deleted file mode 100644
index 3b08077..0000000
--- a/advtrains/textures/advtrains_hud_jp_reverse.png
+++ /dev/null
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_jp_shunt.png b/advtrains/textures/advtrains_hud_jp_shunt.png
deleted file mode 100644
index 6761bf8..0000000
--- a/advtrains/textures/advtrains_hud_jp_shunt.png
+++ /dev/null
Binary files differ
diff --git a/advtrains/trainhud_presets.lua b/advtrains/trainhud_presets.lua
index 19ff4b7..81226f0 100644
--- a/advtrains/trainhud_presets.lua
+++ b/advtrains/trainhud_presets.lua
@@ -1,5 +1,7 @@
advtrains.hud.presets = {}
+local sformat = string.format
+
local default_renderers = {}
for _, width in pairs {30,45,82} do
for _, color in pairs {"cyan", "darkslategray", "orange", "red"} do
@@ -7,20 +9,23 @@ for _, width in pairs {30,45,82} do
end
end
local default_indicators = {
- ars = {"ARS", [true] = "darkslategray30", [false] = "cyan30"},
- atc = {"ATC", [true] = "cyan30", [false] = "darkslategray30"},
- lzb = {"LZB", [true] = "red30", [false] = "darkslategray30"},
- shunt = {"Shunt", [true] = "orange45", [false] = "darkslategray45"},
- autocouple = {"Autocouple", [true] = "orange82", [false] = "darkslategray82"}
+ ars = {"ARS", 10, 10, [true] = "darkslategray30", [false] = "cyan30"},
+ atc = {"ATC", 100, 45, [true] = "cyan30", [false] = "darkslategray30"},
+ lzb = {"LZB", 50, 10, [true] = "red30", [false] = "darkslategray30"},
+ shunt = {"Shunt", 90, 10, [true] = "orange45", [false] = "darkslategray45"},
+ autocouple = {"Autocouple", 145, 10, [true] = "orange82", [false] = "darkslategray82"}
}
-for _, t in pairs(default_indicators) do
- local text = t[1]
- t[1] = nil
- for k, v in pairs(t) do
- t[k] = advtrains.hud.texture_escape(default_renderers[v](text))
+local function make_indicators(renderers, indicators)
+ for _, t in pairs(indicators) do
+ local text, x, y = unpack(t)
+ t[1], t[2], t[3] = nil
+ for k, v in pairs(t) do
+ t[k] = sformat("%d,%d=%s", x, y, advtrains.hud.texture_escape(renderers[v](text)))
+ end
end
+ return indicators
end
-advtrains.hud.default_indicators = default_indicators
+default_indicators = make_indicators(default_renderers, default_indicators)
function advtrains.hud.presets.default(train, flip)
if not train then return "" end
local sformat = string.format -- this appears to be faster than (...):format
@@ -40,10 +45,10 @@ function advtrains.hud.presets.default(train, flip)
ht[#ht+1] = "250,35=(advtrains_hud_bg.png^[colorize\\:darkslategray^[resize\\:5x50)"
ht[#ht+1] = sformat("240,%s=(advtrains_hud_bg.png^[resize\\:25x15^[colorize\\:gray)", flip and 75 or 30)
-- first row
- ht[#ht+1] = sformat("10,10=%s", default_indicators.ars[advtrains.interlocking and ars_disable or false])
- ht[#ht+1] = sformat("50,10=%s", default_indicators.lzb[train.hud_lzb_effect_tmr or false])
- ht[#ht+1] = sformat("90,10=%s", default_indicators.shunt[train.is_shunt or false])
- ht[#ht+1] = sformat("145,10=%s", default_indicators.autocouple[train.autocouple or false])
+ ht[#ht+1] = default_indicators.ars[advtrains.interlocking and ars_disable or false]
+ ht[#ht+1] = default_indicators.lzb[train.hud_lzb_effect_tmr and true or false]
+ ht[#ht+1] = default_indicators.shunt[train.is_shunt or false]
+ ht[#ht+1] = default_indicators.autocouple[train.autocouple or false]
-- second row
local asp, dist = advtrains.hud.getlzb(train)
if dist then
@@ -63,7 +68,7 @@ function advtrains.hud.presets.default(train, flip)
ht[#ht+1] = "10,67=(advtrains_hud_ms.png^[multiply\\:darkslategray)"
ht[#ht+1] = advtrains.hud.number(888, 3, 35, 45, 9, 4, 2, "darkslategray")
end
- ht[#ht+1] = sformat("100,45=%s", default_indicators.atc[(train.tarvelocity or train.atc_command) and true or false])
+ ht[#ht+1] = default_indicators.atc[(train.tarvelocity or train.atc_command) and true or false]
if tar and tar >= 0 then
local tc = math.min(max, tar)
ht[#ht+1] = advtrains.hud.number(tar, 2, 135, 45, 5, 2, 2, "cyan", "darkslategray")
@@ -80,6 +85,25 @@ function advtrains.hud.presets.default(train, flip)
return table.concat(ht,":"), 120
end
+local japan_renderers = {}
+for _, color in pairs{"orange", "darkslategray"} do
+ for _, length in pairs{52, 100} do
+ japan_renderers[color .. length] = advtrains.font.renderer{width = length, height = 20, minwidth = length-4, textcolor = color}
+ end
+ for name, align in pairs{["37l"] = 0, ["37r"] = 1} do
+ japan_renderers[color .. name] = advtrains.font.renderer{x = 2, width = 33, height = 20, halign = align, textcolor = color}
+ end
+end
+local japan_indicators = {
+ atc = {"自動", 235, 5, [true] = "orange52", [false] = "darkslategray52"},
+ ars = {"自動路線設定", 235, 30, [true] = "darkslategray100", [false] = "orange100"},
+ lzb = {"LZB制限", 235, 55, [true] = "orange100", [false] = "darkslategray100"},
+ shunt = {"入換", 235, 80, [true] = "orange100", [false] = "darkslategray100"},
+ autocouple = {"自動連結", 235, 105, [true] = "orange100", [false] = "darkslategray100"},
+ forward = {"前", 151, 5, [true] = "darkslategray37l", [false] = "orange37l"},
+ reverse = {"後", 188, 5, [true] = "orange37r", [false] = "darkslategray37r"},
+}
+japan_indicators = make_indicators(japan_renderers, japan_indicators)
function advtrains.hud.presets.japan(train, flip)
if not train then return "" end
local sformat = string.format -- this appears to be faster than (...):format
@@ -95,8 +119,8 @@ function advtrains.hud.presets.japan(train, flip)
ht[#ht+1] = advtrains.hud.speed_horizontal(train, 5, 100, 217, 25, 3)
ht[#ht+1] = advtrains.hud.lever(advtrains.hud.leverof(train), 122, 5, 3, 20, 90)
- ht[#ht+1] = sformat("151,5=(advtrains_hud_jp_forward.png^[multiply\\:%s)", flip and "darkslategray" or "orange")
- ht[#ht+1] = sformat("188,5=(advtrains_hud_jp_reverse.png^[multiply\\:%s)", flip and "orange" or "darkslategray")
+ ht[#ht+1] = japan_indicators.forward[flip or false]
+ ht[#ht+1] = japan_indicators.reverse[flip or false]
ht[#ht+1] = advtrains.hud.door(train.door_open, 151, 30, 72, 39, 2)
@@ -119,11 +143,11 @@ function advtrains.hud.presets.japan(train, flip)
ht[#ht+1] = advtrains.hud.number(888, 3, 177, 74, 10, 2, 2, "darkslategray")
end
- ht[#ht+1] = sformat("235,5=(advtrains_hud_jp_atc.png^[multiply\\:%s)", (train.tarvelocity or train.atc_command) and "orange" or "darkslategray")
- ht[#ht+1] = sformat("235,30=(advtrains_hud_jp_ars.png^[multiply\\:%s)", (not (advtrains.interlocking and train.ars_disable)) and "orange" or "darkslategray")
- ht[#ht+1] = sformat("235,55=(advtrains_hud_jp_lzb.png^[multiply\\:%s)", train.hud_lzb_effect_tmr and "orange" or "darkslategray")
- ht[#ht+1] = sformat("235,80=(advtrains_hud_jp_shunt.png^[multiply\\:%s)", train.is_shunt and "orange" or "darkslategray")
- ht[#ht+1] = sformat("235,105=(advtrains_hud_jp_autocouple.png^[multiply\\:%s)", train.autocouple and "orange" or "darkslategray")
+ ht[#ht+1] = japan_indicators.atc[(train.tarvelocity or train.atc_command) and true or false]
+ ht[#ht+1] = japan_indicators.ars[advtrains.interlocking and train.ars_disable or false]
+ ht[#ht+1] = japan_indicators.lzb[train.hud_lzb_effect_tmr and true or false]
+ ht[#ht+1] = japan_indicators.shunt[train.is_shunt or false]
+ ht[#ht+1] = japan_indicators.autocouple[train.autocouple or false]
if tar and tar >= 0 then
local tc = math.min(max, tar)
@@ -136,3 +160,5 @@ function advtrains.hud.presets.japan(train, flip)
return table.concat(ht,":"), 130
end
+
+--advtrains.hud.presets.default = advtrains.hud.presets.japan
diff --git a/advtrains/unifont.lua b/advtrains/unifont.lua
index 426be94..3db4de8 100644
--- a/advtrains/unifont.lua
+++ b/advtrains/unifont.lua
@@ -45,10 +45,13 @@ local function mbstocps(str)
c = 0
elseif c < 224 then
bt = {sbyte(str, i, i)}
+ c = c%32
elseif c < 240 then
bt = {sbyte(str, i, i+1)}
+ c = c%16
elseif c < 248 then
bt = {sbyte(str, i, i+2)}
+ c = c%8
else
c = 0
end
@@ -65,12 +68,14 @@ local function renderer(opts)
local opts = opts or {}
local x0, y0 = (opts.x or 0), (opts.y or 0)
local width, height = opts.width, opts.height
+ local minwidth, minheight = opts.minwidth, opts.minheight
local halign, valign = (opts.halign or 0.5), (opts.valign or 0.5)
local textcolor = opts.textcolor or "black"
local bgcolor = opts.bgcolor
local function break_lines(cps)
local lastline = {width = 0}
local lines = {lastline}
+ local maxwidth = 0
local i = 1
while i <= #cps do
local char = cps[i]
@@ -78,16 +83,19 @@ local function renderer(opts)
lastline = {width = 0}
lines[#lines+1] = lastline
elseif cpwidth[char] then
- lastline.width = lastline.width + cpwidth[char]
+ local newwidth = lastline.width + cpwidth[char]
+ lastline.width = newwidth
+ maxwidth = math.max(newwidth, maxwidth)
lastline[#lastline+1] = char
end
i = i+1
end
- return lines
+ return lines, maxwidth, 16*#lines
end
return function(str)
- local lines = break_lines(mbstocps(str))
- local textheight = 16*#lines
+ local lines, textwidth, textheight = break_lines(mbstocps(str))
+ local width = math.max(minwidth or 0, width or 0, textwidth)
+ local height = math.max(minheight or 0, height or 0, textheight)
local y = y0 + (height-textheight)*valign
local st = {
"[combine",
@@ -96,18 +104,24 @@ local function renderer(opts)
for i = 1, #lines do
local line = lines[i]
local x = x0 + (width - line.width)*halign
+ local spacing = 0
+ if minwidth and line.width < minwidth then
+ x = x0 + (width - minwidth)*halign
+ spacing = (minwidth - line.width) / (#line - 1)
+ end
for j = 1, #line do
local cp = line[j]
st[#st+1] = sformat("%d,%d=%s", x, y, texture_file(cp))
- x = x + cpwidth[cp]
+ x = x + cpwidth[cp] + spacing
end
+ y = y + 16
end
local prefix = ""
if bgcolor then
prefix = sformat("[combine:%dx%d:%d,%d=\\(advtrains_hud_bg.png\\^[resize\\:%dx%d\\^[colorize\\:%s\\:alpha\\)^",
x0+width, y0+height, x0, y0, width, height, bgcolor)
end
- return sformat("(%s(%s^[makealpha:000000^[multiply:%s))", prefix, tconcat(st, ":"), textcolor)
+ return sformat("(%s(%s^[makealpha:000000^[multiply:%s))", prefix, tconcat(st, ":"), textcolor), width, height
end
end
@@ -168,6 +182,7 @@ minetest.log("action",sformat("[advtrains/unifont] Generated textures in %f seco
return {
texture_dir = texture_dir,
+ mbstocps = mbstocps,
renderer = renderer,
render = render
}