1
0
forked from MTSR/mapserver

add color to label, border and train

This commit is contained in:
NatureFreshMilk 2019-04-04 13:21:20 +02:00
parent 0f789385ff
commit 35038d52c7
7 changed files with 35 additions and 5 deletions

View File

@ -5,16 +5,20 @@ local last_name = ""
local update_formspec = function(meta)
local name = meta:get_string("name")
local index = meta:get_string("index")
local color = meta:get_string("color") or "rgb(10,10,200)"
meta:set_string("infotext", "Border: Name=" .. name .. ", Index=" .. index)
meta:set_string("formspec", "size[8,3;]" ..
meta:set_string("formspec", "size[8,4;]" ..
-- col 1
"field[0,1;4,1;name;Name;" .. name .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
-- col 2
"field[4,2.5;4,1;index;Index;" .. index .. "]" ..
-- col 3
"field[4,3.5;4,1;color;Color;" .. color .. "]" ..
"")
end
@ -35,6 +39,7 @@ minetest.register_node("mapserver:border", {
last_index = last_index + 5
meta:set_string("color", "rgb(10,10,200)")
meta:set_string("name", last_name)
meta:set_int("index", last_index)
@ -52,6 +57,7 @@ minetest.register_node("mapserver:border", {
if fields.save then
last_name = fields.name
meta:set_string("name", fields.name)
meta:set_string("color", fields.color)
local index = tonumber(fields.index)
if index ~= nil then
last_index = index

View File

@ -3,10 +3,11 @@ local update_formspec = function(meta)
local text = meta:get_string("text")
local size = meta:get_string("size")
local direction = meta:get_string("direction")
local color = meta:get_string("color") or "rgb(0,0,0)"
meta:set_string("infotext", "Label, Text:" .. text .. ", Size:" .. size .. ", Direction:" .. direction)
meta:set_string("formspec", "size[8,5;]" ..
meta:set_string("formspec", "size[8,6;]" ..
-- col 1
"field[0,1;4,1;text;Text;" .. text .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
@ -16,6 +17,10 @@ local update_formspec = function(meta)
-- col 3
"field[0,3.5;8,1;direction;Direction (0-360);" .. direction .. "]" ..
-- col 4
"field[0,4.5;8,1;color;Color;" .. color .. "]" ..
"")
end
@ -37,6 +42,7 @@ minetest.register_node("mapserver:label", {
meta:set_string("text", "")
meta:set_string("direction", "0")
meta:set_string("size", "1")
meta:set_string("color", "rgb(0,0,0)")
update_formspec(meta)
end,
@ -50,6 +56,7 @@ minetest.register_node("mapserver:label", {
local meta = minetest.get_meta(pos)
if fields.save then
meta:set_string("color", fields.color)
meta:set_string("text", fields.text)
meta:set_string("direction", fields.direction)
meta:set_string("size", fields.size)

View File

@ -6,17 +6,22 @@ local update_formspec = function(meta)
local line = meta:get_string("line")
local station = meta:get_string("station")
local index = meta:get_string("index")
local color = meta:get_string("color") or ""
meta:set_string("infotext", "Train: Line=" .. line .. ", Station=" .. station)
meta:set_string("formspec", "size[8,3;]" ..
meta:set_string("formspec", "size[8,4;]" ..
-- col 1
"field[0,1;4,1;line;Line;" .. line .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
-- col 2
"field[0,2.5;4,1;station;Station;" .. station .. "]" ..
"field[4,2.5;4,1;index;Index;" .. index .. "]"
"field[4,2.5;4,1;index;Index;" .. index .. "]" ..
-- col 3
"field[0,3.5;4,1;color;Color;" .. color .. "]" ..
""
)
end
@ -40,6 +45,7 @@ minetest.register_node("mapserver:train", {
meta:set_string("station", "")
meta:set_string("line", last_line)
meta:set_int("index", last_index)
meta:set_string("color", "rgb(10,10,200)")
update_formspec(meta)
end,
@ -54,6 +60,7 @@ minetest.register_node("mapserver:train", {
if fields.save then
last_line = fields.line
meta:set_string("color", fields.color)
meta:set_string("line", fields.line)
meta:set_string("station", fields.station)
local index = tonumber(fields.index)

View File

@ -14,6 +14,7 @@ func (this *BorderBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock
o.Attributes["name"] = md["name"]
o.Attributes["index"] = md["index"]
o.Attributes["owner"] = md["owner"]
o.Attributes["color"] = md["color"]
return o
}

View File

@ -15,6 +15,7 @@ func (this *LabelBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock)
o.Attributes["size"] = md["size"]
o.Attributes["direction"] = md["direction"]
o.Attributes["owner"] = md["owner"]
o.Attributes["color"] = md["color"]
return o
}

View File

@ -15,6 +15,7 @@ func (this *TrainBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock)
o.Attributes["line"] = md["line"]
o.Attributes["index"] = md["index"]
o.Attributes["owner"] = md["owner"]
o.Attributes["color"] = md["color"]
return o
}

View File

@ -22,10 +22,17 @@ var LabelOverlay = AbstractIconOverlay.extend({
},
getIcon: function(lbl){
const html = `
<svg height='30' width='100'>
<text x='0' y='15'>${lbl.attributes.text}</text>
</svg>
`;
return new LabelIcon({
iconAnchor: [15, 50],
iconSize: [30, 100],
html: "<svg height='30' width='100'><text x='0' y='15'>" + lbl.attributes.text + "</text></svg>"
html: html
});
},