added texture replacement in themes support

This commit is contained in:
Alexander Weber 2018-03-03 16:30:31 +01:00
parent fc5920eb6d
commit 0b98d57d99
3 changed files with 10 additions and 3 deletions

3
API.md
View File

@ -144,13 +144,14 @@ Definitiontable:
- `table_highlight_bgcolor` - Table highlighted background
- `table_highlight_textcolor` - Table highlighted textcolor
- `table_border` - draw border (true or false)
- `texture_replacements` - A table with texture replacements, defined as { ['orig_texture_name.png'] = 'themed_texture_name.png', }
### Theme methods
`function laptop.get_theme(theme_name)`
- `theme:get_button(area, prefix, code, text)` get a themed [prefix]_button in area 'x,y;w,h' with code and text
- `theme:get_image_button(area, prefix, code, image, text)` get a themed [prefix]_button in area 'x,y;w,h' with code an image and text. Text is colorized by [prefix]_textcolor or textcolor
- `theme:get_label(pos, text, color_prefix)` get a themed label text starting at pos 'x,y', colorize theme by color prefix (usually the button text colors)
- `theme:get_texture(image)` get replacement for texture image if set in theme or the image. Called internally from get_image_button()
## Block devices / Data objects
`mtos.bdev = laptop.get_bdev_handler(mtos)`

View File

@ -125,7 +125,7 @@ laptop.register_app("tntsweeper", {
local field = sweeper.data.board[w][h]
if not field.is_revealed then
if field.bomb_marked then
formspec = formspec .. "image_button["..pos..";"..config.icon_size..","..config.icon_size..";"..mtos.theme.minor_button.."^laptop_tnt.png;field:"..w..":"..h..";]"
formspec = formspec .. "image_button["..pos..";"..config.icon_size..","..config.icon_size..";"..mtos.theme.minor_button.."^"..mtos.theme:get_texture("laptop_tnt.png")..";field:"..w..":"..h..";]"
else
formspec = formspec .. "image_button["..pos..";"..config.icon_size..","..config.icon_size..";"..mtos.theme.minor_button..";field:"..w..":"..h..";]"
end

View File

@ -25,6 +25,7 @@ laptop.themes = {
table_highlight_bgcolor='#FFFF00',
table_highlight_textcolor='#0000FF',
table_border='false',
texture_replacements = {}, -- No replacements in default theme
},
}
@ -59,7 +60,7 @@ end
-- get prepared button textures
function theme_class:get_image_button(area, prefix, code, image, text, tooltip)
local formspec = 'image_button['..area..';'..self[prefix.."_button"]..'^'..image..';'..code..';'.. minetest.colorize(self[prefix.."_textcolor"] or self.textcolor,minetest.formspec_escape(text))..']'
local formspec = 'image_button['..area..';'..self[prefix.."_button"]..'^'..self:get_texture(image)..';'..code..';'.. minetest.colorize(self[prefix.."_textcolor"] or self.textcolor,minetest.formspec_escape(text))..']'
if tooltip then
formspec = formspec.."tooltip["..code..";"..minetest.formspec_escape(tooltip).."]"
end
@ -76,6 +77,11 @@ function theme_class:get_label(area, label, color_prefix)
end
end
-- Get themed texture name
function theme_class:get_texture(texture_name)
return self.texture_replacements[texture_name] or texture_name
end
function theme_class:get_tableoptions()
return "tableoptions[background="..self.table_bgcolor..
";color="..self.table_textcolor..