Overhaul template engine and rework default game menu
This commit is contained in:
parent
102dfee583
commit
bf1cfff244
2 changed files with 1197 additions and 493 deletions
324
init.lua
324
init.lua
|
|
@ -71,7 +71,7 @@ minetest.set_formspec_prepend("\
|
|||
style_type[image_button;border=false]\
|
||||
style_type[button;border=false;bgimg="..assets.."btn_bg_2.png;bgimg_middle=8,8]\
|
||||
style_type[button:hovered;border=false;bgimg="..assets.."btn_bg_2_hover.png;bgimg_middle=8,8]\
|
||||
style[nobg,nobg:hovered,nobg:focused,nobg:hovered+focused;border=false;bgimg="..default_textures.."blank.png;bgimg_middle=0]\
|
||||
style[nobg,nobg:hovered,nobg:focused,nobg:hovered+focused;border=false;bgimg="..default_textures.."blank.png;bgimg_middle=0;content_offset=0,0]\
|
||||
")
|
||||
|
||||
local meta_header = "formspec_version[8]\
|
||||
|
|
@ -101,150 +101,208 @@ local content_header = "formspec_version[8]\
|
|||
"
|
||||
|
||||
local default_game_menu = [[
|
||||
<meta>
|
||||
enable_clouds = true
|
||||
</meta>
|
||||
<main>
|
||||
@if:@selected_world:fi2
|
||||
@set:list_width:@WIDTH * 0.3
|
||||
@else:fi2
|
||||
@set:list_width:@WIDTH * 0.8
|
||||
@endif:fi2
|
||||
{% macro field(x, y, w, h, name, value) %}
|
||||
image[{{ x }},{{ y }};{{ w }},{{ h }};{{ DEFAULT_ASSETS }}btn_bg_2_light.png;8,8]
|
||||
field[{{ x + 0.1 }},{{ y }};{{ w - 0.2 }},{{ h }};{{ name }};;{{ value }}]
|
||||
{% endmacro %}
|
||||
{% view main %}
|
||||
|
||||
label[0,0;{{ selected_world }}]
|
||||
{% set worlds = get_worlds() %}
|
||||
|
||||
image[${@WIDTH * 0.1 +-0.1},${@HEIGHT * 0.1 +-0.1};${@WIDTH * 0.8 + 0.2},${@HEIGHT * 0.8 + 0.2};$DEFAULT_ASSET_PATH/bg_translucent.png;8,8]
|
||||
scroll_container[${@WIDTH * 0.1},${@HEIGHT * 0.1};${@list_width},${@HEIGHT * 0.8};worldscroll;vertical;;0,0]
|
||||
@foreach:@WORLDS:worlds
|
||||
@if:@i % 2:sel
|
||||
style[.select_world_${@path};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
style[.select_world_${@path}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
style[.select_world_${@path}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
@else:sel
|
||||
style[.select_world_${@path};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
style[.select_world_${@path}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
style[.select_world_${@path}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
@endif:sel
|
||||
button[0,${(@i +-1) * 0.5};${@list_width},0.5;.select_world_${@path};${@name}]
|
||||
@endforeach:worlds
|
||||
{{ field(2, 2, 4, 0.75, 'test', '???') }}
|
||||
|
||||
{# Special layouts are applied when there are less than four worlds for a given game. #}
|
||||
{% if len(worlds) == 1 %}
|
||||
|
||||
image[{{ WIDTH * 0.5 - 2 }},{{ HEIGHT * 0.5 - 2 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 - 1.5 }},{{ HEIGHT * 0.5 - 1.75 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[1]) }};]
|
||||
button[{{ WIDTH * 0.5 - 2 }},{{ HEIGHT * 0.5 + 1 }};4,0.75;nobg;{{ worlds[1].name }}]
|
||||
|
||||
{% elseif len(worlds) == 2 %}
|
||||
|
||||
image[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 - 2 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 - 4 }},{{ HEIGHT * 0.5 - 1.75 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[1]) }};]
|
||||
button[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 + 1 }};4,0.75;nobg;{{ worlds[1].name }}]
|
||||
|
||||
image[{{ WIDTH * 0.5 + 0.5 }},{{ HEIGHT * 0.5 - 2 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 + 1 }},{{ HEIGHT * 0.5 - 1.75 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[2]) }};]
|
||||
button[{{ WIDTH * 0.5 + 0.5 }},{{ HEIGHT * 0.5 + 1 }};4,0.75;nobg;{{ worlds[2].name }}]
|
||||
|
||||
{% elseif len(worlds) == 3 %}
|
||||
|
||||
image[{{ WIDTH * 0.5 - 2 }},{{ HEIGHT * 0.5 - 4.5 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 - 1.5 }},{{ HEIGHT * 0.5 - 4.25 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[1]) }};]
|
||||
button[{{ WIDTH * 0.5 - 2 }},{{ HEIGHT * 0.5 - 1.5 }};4,0.75;nobg;{{ worlds[1].name }}]
|
||||
|
||||
image[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 + 0.5 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 - 4 }},{{ HEIGHT * 0.5 + 0.75 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[2]) }};]
|
||||
button[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 + 3.5 }};4,0.75;nobg;{{ worlds[2].name }}]
|
||||
|
||||
image[{{ WIDTH * 0.5 + 0.5 }},{{ HEIGHT * 0.5 + 0.5 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 + 1 }},{{ HEIGHT * 0.5 + 0.75 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[3]) }};]
|
||||
button[{{ WIDTH * 0.5 + 0.5 }},{{ HEIGHT * 0.5 + 3.5 }};4,0.75;nobg;{{ worlds[3].name }}]
|
||||
|
||||
{% elseif len(worlds) == 4 %}
|
||||
|
||||
image[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 - 4.5 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 - 4 }},{{ HEIGHT * 0.5 - 4.25 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[1]) }};]
|
||||
button[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 - 1.5 }};4,0.75;nobg;{{ worlds[1].name }}]
|
||||
|
||||
image[{{ WIDTH * 0.5 + 0.5 }},{{ HEIGHT * 0.5 - 4.5 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 + 1 }},{{ HEIGHT * 0.5 - 4.25 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[2]) }};]
|
||||
button[{{ WIDTH * 0.5 + 0.5 }},{{ HEIGHT * 0.5 - 1.5 }};4,0.75;nobg;{{ worlds[2].name }}]
|
||||
|
||||
image[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 + 0.5 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 - 4 }},{{ HEIGHT * 0.5 + 0.75 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[3]) }};]
|
||||
button[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 + 3.5 }};4,0.75;nobg;{{ worlds[3].name }}]
|
||||
|
||||
image[{{ WIDTH * 0.5 + 0.5 }},{{ HEIGHT * 0.5 + 0.5 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 + 1 }},{{ HEIGHT * 0.5 + 0.75 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[4]) }};]
|
||||
button[{{ WIDTH * 0.5 + 0.5 }},{{ HEIGHT * 0.5 + 3.5 }};4,0.75;nobg;{{ worlds[4].name }}]
|
||||
|
||||
{% else %}
|
||||
scroll_container[0,0;{{ WIDTH }},{{ HEIGHT }};worldscroll;vertical;;1,0]
|
||||
{% set cols = floor((WIDTH - 2) / 5) %}
|
||||
{% set trailing_cols = len(worlds) % cols %}
|
||||
{% set rows = ceil(len(worlds) / cols) %}
|
||||
{% set col = 0 %}
|
||||
{% set row = 0 %}
|
||||
{% set rx = cols * 2.5 %}
|
||||
{% set ry = min(rows * 2.5, (HEIGHT - 2) / 2) %}
|
||||
{% for world in worlds %}
|
||||
|
||||
image[{{ WIDTH * 0.5 - rx + col * 5 }},{{ HEIGHT * 0.5 - ry + row * 5 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
|
||||
image_button[{{ WIDTH * 0.5 - rx + col * 5 + 0.5 }},{{ HEIGHT * 0.5 - ry + row * 5 + 0.25 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', world) }};]
|
||||
button[{{ WIDTH * 0.5 - rx + col * 5 }},{{ HEIGHT * 0.5 - ry + row * 5 + 3 }};4,0.75;nobg;{{ fe(world.name) }}]
|
||||
|
||||
{% set col = col + 1 %}
|
||||
{% if col > cols - 1 %}
|
||||
{% set col = 0 %}
|
||||
{% set row = row + 1 %}
|
||||
{% if row == rows - 1 and trailing_cols > 0 %}
|
||||
{% set rx = min(trailing_cols, cols) * 2.5 %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
scroll_container_end[]
|
||||
scrollbar[-800,0;0,0;vertical;worldscroll;]
|
||||
{% endif %}
|
||||
|
||||
{% if selected_world %}
|
||||
box[0,0;{{ WIDTH }},{{ HEIGHT }};#0003]
|
||||
image[{{ WIDTH * 0.05 }},{{ HEIGHT * 0.05 }};{{ WIDTH * 0.9 }},{{ HEIGHT * 0.9 }};{{ DEFAULT_ASSETS }}btn_bg.png;8,8]
|
||||
label[1,1;Selected world: {{ fe(selected_world.name) }}]
|
||||
button[1,1;3,1;{{ action('set', 'selected_world', nil) }};Back]
|
||||
{% endif %}
|
||||
|
||||
{#
|
||||
|
||||
image[{{ WIDTH * 0.1 - 0.1 }},{{ HEIGHT * 0.1 - 0.1}};{{ WIDTH * 0.8 + 0.2 }},{{ HEIGHT * 0.8 + 0.2 }};{{ DEFAULT_ASSETS }}bg_translucent.png;8,8]
|
||||
scroll_container[{{ WIDTH * 0.1 }},{{ HEIGHT * 0.1 }};{{ list_width }},{{ HEIGHT * 0.8 }};worldscroll;vertical;;0,0]
|
||||
{% for world in get_worlds() %}
|
||||
style[.select_world_{{ world.path }};bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
style[.select_world_{{ world.path }}:hovered;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
style[.select_world_{{ world.path }}:hovered+focused;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
|
||||
button[0,{{ loop.index0 * 0.5}};{{ list_width }},0.5;.select_world_{{ world.path }};{{ world.name }}]
|
||||
{% endfor %}
|
||||
scroll_container_end[]
|
||||
|
||||
@if:@selected_world:fi
|
||||
box[${@WIDTH * 0.4 +-0.05},${@HEIGHT * 0.1 +-0.1};0.1,${@HEIGHT * 0.8 + 0.2};#292d2fff]
|
||||
scroll_container[${@WIDTH * 0.4 + 0.05},${@HEIGHT * 0.1};${@WIDTH * 0.8 +-0.05},${@HEIGHT * 0.8};worlconfigscroll;vertical;;0,0]
|
||||
@set:j:0
|
||||
{% if selected_world %}
|
||||
box[{{ WIDTH * 0.4 - 0.05 }},{{ HEIGHT * 0.1 - 0.1 }};0.1,{{ HEIGHT * 0.8 + 0.2 }};#292d2fff]
|
||||
scroll_container[{{ WIDTH * 0.4 + 0.05 }},{{ HEIGHT * 0.1 }};{{ WIDTH * 0.8 - 0.05 }},{{ HEIGHT * 0.8 }};worlconfigscroll;vertical;;0,0]
|
||||
{% set j = 0 %}
|
||||
|
||||
@if:@setting_damage:fii
|
||||
@if:@damage_enabled:fiii
|
||||
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_filled.png;.set_damage_enabled_to_0;]
|
||||
@else:fiii
|
||||
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_empty.png;.set_damage_enabled_to_1;]
|
||||
@endif:fiii
|
||||
label[0.5,${@j + 0.25};Damage]
|
||||
@set:j:@j + 0.5
|
||||
@else:fii
|
||||
{% if setting_damage %}
|
||||
{% if damage_enabled %}
|
||||
image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_filled.png;.set_damage_enabled_to_false;]
|
||||
{% else %}
|
||||
image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_empty.png;.set_damage_enabled_to_true;]
|
||||
{% endif %}
|
||||
label[0.5,{{ j + 0.25 }};Damage]
|
||||
{% set j = j + 0.5 %}
|
||||
{% endif %}
|
||||
|
||||
@endif:fii
|
||||
{% if setting_creative %}
|
||||
{% if creative_enabled %}
|
||||
image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_filled.png;.set_creative_enabled_to_false;]
|
||||
{% else %}
|
||||
image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_empty.png;.set_creative_enabled_to_true;]
|
||||
{% endif %}
|
||||
label[0.5,{{ j + 0.25 }};Creative]
|
||||
{% set j = j + 0.5 %}
|
||||
{% endif %}
|
||||
|
||||
@if:@setting_creative:fii
|
||||
@if:@creative_enabled:fiii
|
||||
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_filled.png;.set_creative_enabled_to_0;]
|
||||
@else:fiii
|
||||
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_empty.png;.set_creative_enabled_to_1;]
|
||||
@endif:fiii
|
||||
label[0.5,${@j + 0.25};Creative]
|
||||
@set:j:@j + 0.5
|
||||
@else:fii
|
||||
{% set play_str = "Play" %}
|
||||
|
||||
@endif:fii
|
||||
{% if setting_server %}
|
||||
{% if server_enabled %}
|
||||
image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_filled.png;.set_server_enabled_to_false;]
|
||||
{% set play_str = "Host server" %}
|
||||
{% else %}
|
||||
image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_empty.png;.set_server_enabled_to_true;]
|
||||
{% set play_str = "Play" %}
|
||||
{% endif %}
|
||||
|
||||
@set:play_str:Play
|
||||
label[0.5,{{ j + 0.25 }};Server]
|
||||
{% set j = j + 0.5 %}
|
||||
{% endif %}
|
||||
|
||||
@if:@setting_server:fii
|
||||
@if:@server_enabled:fiii
|
||||
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_filled.png;.set_server_enabled_to_0;]
|
||||
@set:play_str:Host server
|
||||
@else:fiii
|
||||
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_empty.png;.set_server_enabled_to_1;]
|
||||
@set:play_str:Play
|
||||
@endif:fiii
|
||||
{% set j = j + 1 %}
|
||||
|
||||
label[0.5,${@j + 0.25};Server]
|
||||
@set:j:@j + 0.5
|
||||
@else:fii
|
||||
|
||||
@endif:fii
|
||||
|
||||
@set:j:@j + 1
|
||||
|
||||
button[${@WIDTH * 0.05},${@j};${@WIDTH * 0.4},0.75;.overlay_dialog_modconfig;Configure mods]
|
||||
button[${@WIDTH * 0.05},${@j + 1};${@WIDTH * 0.4},0.75;.play;${@play_str}]
|
||||
button[{{ WIDTH * 0.05 }},{{ j }};{{ WIDTH * 0.4 }},0.75;.overlay_view_modconfig;Configure mods]
|
||||
button[{{ WIDTH * 0.05 }},{{ j + 1 }};{{ WIDTH * 0.4 }},0.75;.play;{{ play_str }}]
|
||||
|
||||
scroll_container_end[]
|
||||
scrollbar[-800,6;0,2;vertical;worldconfigscroll;]
|
||||
@else:fi
|
||||
{% endif %}
|
||||
#}
|
||||
|
||||
@endif:fi
|
||||
scrollbaroptions[arrows=hide]
|
||||
scrollbar[-800,6;0,2;vertical;worldscroll;]
|
||||
</main>
|
||||
<modconfig>
|
||||
image[${@WIDTH * 0.05 +-0.1},${@HEIGHT * 0.05 +-0.1};${@WIDTH * 0.4 + 0.2},${@HEIGHT * 0.9 +-0.75};$DEFAULT_ASSET_PATH/btn_bg.png;8,8]
|
||||
hypertext[${@WIDTH * 0.05},${@HEIGHT * 0.05};${@WIDTH * 0.4},0.75;;<global valign=middle halign=center><b>Available mods</b>]
|
||||
scroll_container[${@WIDTH * 0.05},${@HEIGHT * 0.05 + 0.75};${@WIDTH * 0.4},${@HEIGHT * 0.9 +-1.7};modsscroll;vertical;;0,0]
|
||||
@foreach:@MODS:m
|
||||
@if:@i % 2:sel
|
||||
style[.select_mod_${@name};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
style[.select_mod_${@name}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
style[.select_mod_${@name}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
@else:sel
|
||||
style[.select_mod_${@name};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
style[.select_mod_${@name}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
style[.select_mod_${@name}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
@endif:sel
|
||||
button[0,${@i * 0.5 +-0.5};${@WIDTH * 0.4},0.5;.select_mod_${@name};${@name}]
|
||||
@endforeach:m
|
||||
|
||||
{% endview %}
|
||||
{% view modconfig %}
|
||||
|
||||
image[{{ WIDTH * 0.05 - 0.1 }},{{ HEIGHT * 0.05 - 0.1 }};{{ WIDTH * 0.4 + 0.2 }},{{ HEIGHT * 0.9 - 0.75 }};{{ DEFAULT_ASSETS }}btn_bg.png;8,8]
|
||||
hypertext[{{ WIDTH * 0.05 }},{{ HEIGHT * 0.05 }};{{ WIDTH * 0.4 }},0.75;;<global valign=middle halign=center><b>Available mods</b>]
|
||||
scroll_container[{{ WIDTH * 0.05 }},{{ HEIGHT * 0.05 + 0.75 }};{{ WIDTH * 0.4 }},{{ HEIGHT * 0.9 - 1.7 }};modsscroll;vertical;;0,0]
|
||||
{% for mod in get_mods() %}
|
||||
style[.select_mod_{{ mod.name }};bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
style[.select_mod_{{ mod.name }}:hovered;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
style[.select_mod_{{ mod.name }}:hovered+focused;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
button[0,{{ loop.index0 * 0.5 }};{{ WIDTH * 0.4 }},0.5;.select_mod_{{ mod.name }};{{ mod.name }}]
|
||||
{% endfor %}
|
||||
scroll_container_end[]
|
||||
scrollbar[-800,6;0,2;vertical;modsscroll;]
|
||||
|
||||
image[${@WIDTH * 0.55 +-0.1},${@HEIGHT * 0.05 +-0.1};${@WIDTH * 0.4 + 0.2},${@HEIGHT * 0.9 +-0.75};$DEFAULT_ASSET_PATH/btn_bg.png;8,8]
|
||||
hypertext[${@WIDTH * 0.55},${@HEIGHT * 0.05};${@WIDTH * 0.4},0.75;;<global valign=middle halign=center><b>Mods for ${@selected_world_name}</b>]
|
||||
scroll_container[${@WIDTH * 0.55},${@HEIGHT * 0.05 + 0.75};${@WIDTH * 0.4},${@HEIGHT * 0.9 +-1.7};worldmodsscroll;vertical;;0,0]
|
||||
@foreach:@WORLDMODS:wm
|
||||
@if:@game_mod:gm
|
||||
@if:@i % 2:sel
|
||||
style[.select_mod_${@name};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
style[.select_mod_${@name}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
style[.select_mod_${@name}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530]
|
||||
@else:sel
|
||||
style[.select_mod_${@name};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
style[.select_mod_${@name}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
style[.select_mod_${@name}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
|
||||
@endif:sel
|
||||
button[0,${@i * 0.5 +-0.5};${@WIDTH * 0.4},0.5;.select_mod_${@name};${@name}]
|
||||
@else:gm
|
||||
|
||||
@endif:gm
|
||||
@endforeach:wm
|
||||
image[{{ WIDTH * 0.55 - 0.1 }},{{ HEIGHT * 0.05 - 0.1 }};{{ WIDTH * 0.4 + 0.2 }},{{ HEIGHT * 0.9 - 0.75 }};{{ DEFAULT_ASSETS }}btn_bg.png;8,8]
|
||||
hypertext[{{ WIDTH * 0.55 }},{{ HEIGHT * 0.05 }};{{ WIDTH * 0.4 }},0.75;;<global valign=middle halign=center><b>Enabled mods</b>]
|
||||
scroll_container[{{ WIDTH * 0.55 }},{{ HEIGHT * 0.05 + 0.75 }};{{ WIDTH * 0.4 }},{{ HEIGHT * 0.9 - 1.7 }};worldmodsscroll;vertical;;0,0]
|
||||
{% for mod in get_world_mods() %}
|
||||
{% if not mod.game_provided %}
|
||||
style[.select_mod_{{ mod.name }};bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
style[.select_mod_{{ mod.name }}:hovered;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
style[.select_mod_{{ mod.name }}:hovered+focused;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
|
||||
button[0,{{ loop.index0 * 0.5 }};{{ WIDTH * 0.4 }},0.5;.select_mod_{{ mod.name }};{{ mod.name }}]
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
scroll_container_end[]
|
||||
scrollbar[-800,6;0,2;vertical;worldmodsscroll;]
|
||||
|
||||
image_button[${@WIDTH * 0.45},${@HEIGHT * 0.5 +-(@WIDTH * 0.1)};${@WIDTH * 0.1},${@WIDTH * 0.1};$DEFAULT_ASSET_PATH/arrow_right.png;.add_mod_to_world;]
|
||||
image_button[${@WIDTH * 0.45},${@HEIGHT * 0.5};${@WIDTH * 0.1},${@WIDTH * 0.1};$DEFAULT_ASSET_PATH/arrow_left.png;.remove_mod_from_world;]
|
||||
image_button[{{ WIDTH * 0.45 }},{{ HEIGHT * 0.5 - WIDTH * 0.1 }};{{ WIDTH * 0.1 }},{{ WIDTH * 0.1 }};{{ DEFAULT_ASSETS }}arrow_right.png;.add_mod_to_world;]
|
||||
image_button[{{ WIDTH * 0.45 }},{{ HEIGHT * 0.5 }};{{ WIDTH * 0.1 }},{{ WIDTH * 0.1 }};{{ DEFAULT_ASSETS }}arrow_left.png;.remove_mod_from_world;]
|
||||
tooltip[.add_mod_to_world;Add mod to world;#444;#aaa]
|
||||
tooltip[.remove_mod_from_world;Remove mod from world;#444;#aaa]
|
||||
|
||||
button[${@WIDTH * 0.1},${@HEIGHT * 0.95 +-0.75};${@WIDTH * 0.4},0.75;.unoverlay_dialog;Cancel]
|
||||
button[${@WIDTH * 0.5},${@HEIGHT * 0.95 +-0.75};${@WIDTH * 0.4},0.75;.unoverlay_dialog;Confirm]
|
||||
</modconfig>
|
||||
<addworld>
|
||||
label[2,2;Add World, asset path is $ASSET_PATH]
|
||||
button[2,3;3,1;.show_dialog_main;back]
|
||||
button[{{ WIDTH * 0.1 }},{{ HEIGHT * 0.95 - 0.75 }};{{ WIDTH * 0.4 }},0.75;.unoverlay_view;Cancel]
|
||||
button[{{ WIDTH * 0.5 }},{{ HEIGHT * 0.95 - 0.75 }};{{ WIDTH * 0.4 }},0.75;.unoverlay_view;Confirm]
|
||||
|
||||
@foreach:[hello,there,bob]:myloop
|
||||
label[6,${@i + 3};${@item}]
|
||||
@endforeach:myloop
|
||||
</addworld>
|
||||
{% endview %}
|
||||
{% view addworld %}
|
||||
|
||||
{% endview %}
|
||||
]]
|
||||
|
||||
|
||||
|
|
@ -342,6 +400,9 @@ function get_worlds_for_game(id)
|
|||
out[#out +1] = x
|
||||
end
|
||||
end
|
||||
table.sort(out, function(a, b)
|
||||
return a.name < b.name
|
||||
end)
|
||||
return out
|
||||
end
|
||||
|
||||
|
|
@ -996,9 +1057,16 @@ function show_game_menu(args)
|
|||
end
|
||||
end
|
||||
|
||||
game.menu = build_game_menu(file)
|
||||
game.menu = template.build(file)
|
||||
|
||||
state.menu_vars = {}
|
||||
state.menu_vars = {
|
||||
get_worlds = function() return get_worlds_for_game(game.id) end,
|
||||
get_mods = function() return get_mods_for_game(game.id) end,
|
||||
get_world_mods = function(world)
|
||||
world = world or state.menu_vars.selected_world
|
||||
return world and get_mods_for_world(state.menu_vars.selected_world) or {}
|
||||
end
|
||||
}
|
||||
|
||||
state.menu_vars.setting_damage = game.disabled_settings.damage == nil
|
||||
state.menu_vars.setting_creative = game.disabled_settings.creative == nil
|
||||
|
|
@ -1024,16 +1092,14 @@ function show_game_menu(args)
|
|||
"
|
||||
end
|
||||
|
||||
|
||||
for i, x in ipairs(state.menu_current) do
|
||||
if i > 1 then
|
||||
fs = fs.."\
|
||||
box[0,0;"..size.x..","..size.y..";#0009]\
|
||||
"
|
||||
end
|
||||
fs = fs..evaluate_game_dialog(game.menu[x], state.menu_vars)
|
||||
fs = fs..template.evaluate(game.menu[x], state.menu_vars)
|
||||
end
|
||||
-- print(fs)
|
||||
|
||||
minetest.update_formspec(game_header..fs.."\
|
||||
button[0,"..(size.y -1)..";1,1;to_meta_menu;<]\
|
||||
|
|
@ -1872,13 +1938,13 @@ function minetest.button_handler(data)
|
|||
singleplayer = true
|
||||
}
|
||||
minetest.start()
|
||||
elseif k:sub(1, string.len(".show_dialog_")) == ".show_dialog_" then
|
||||
elseif k:sub(1, string.len(".show_view_")) == ".show_view_" then
|
||||
show_game_menu {
|
||||
show_dialog = k:sub(string.len(".show_dialog_>"))
|
||||
show_dialog = k:sub(string.len(".show_view_>"))
|
||||
}
|
||||
elseif k:sub(1, string.len(".overlay_dialog_")) == ".overlay_dialog_" then
|
||||
elseif k:sub(1, string.len(".overlay_view_")) == ".overlay_view_" then
|
||||
show_game_menu {
|
||||
overlay_dialog = k:sub(string.len(".overlay_dialog_>"))
|
||||
overlay_dialog = k:sub(string.len(".overlay_view_>"))
|
||||
}
|
||||
elseif k:sub(1, string.len(".select_world_")) == ".select_world_" then
|
||||
state.menu_vars.selected_world = k:sub(string.len(".select_world_>"))
|
||||
|
|
@ -1906,8 +1972,8 @@ function minetest.button_handler(data)
|
|||
unoverlay_dialog = true
|
||||
}
|
||||
elseif k:sub(1, string.len(".set_")) == ".set_" then
|
||||
local name, value = k:match "%.set_(.+)_to_(.*)"
|
||||
state.menu_vars[name] = value == "" and "0" or value
|
||||
local name, value = k:match "%.set_|(.+)|_to_(.*)"
|
||||
state.menu_vars[name] = minetest.parse_json(value:gsub("\\([];,$\\[])", "%1"))
|
||||
show_game_menu()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
1354
templates.lua
1354
templates.lua
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue