Overhaul template engine and rework default game menu

This commit is contained in:
Signal 2025-10-09 12:46:56 -04:00
parent 102dfee583
commit bf1cfff244
2 changed files with 1197 additions and 493 deletions

328
init.lua
View file

@ -71,7 +71,7 @@ minetest.set_formspec_prepend("\
style_type[image_button;border=false]\ style_type[image_button;border=false]\
style_type[button;border=false;bgimg="..assets.."btn_bg_2.png;bgimg_middle=8,8]\ 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_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]\ local meta_header = "formspec_version[8]\
@ -101,150 +101,208 @@ local content_header = "formspec_version[8]\
" "
local default_game_menu = [[ local default_game_menu = [[
<meta> {% macro field(x, y, w, h, name, value) %}
enable_clouds = true image[{{ x }},{{ y }};{{ w }},{{ h }};{{ DEFAULT_ASSETS }}btn_bg_2_light.png;8,8]
</meta> field[{{ x + 0.1 }},{{ y }};{{ w - 0.2 }},{{ h }};{{ name }};;{{ value }}]
<main> {% endmacro %}
@if:@selected_world:fi2 {% view main %}
@set:list_width:@WIDTH * 0.3
@else:fi2
@set:list_width:@WIDTH * 0.8
@endif:fi2
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] {{ field(2, 2, 4, 0.75, 'test', '???') }}
scroll_container[${@WIDTH * 0.1},${@HEIGHT * 0.1};${@list_width},${@HEIGHT * 0.8};worldscroll;vertical;;0,0]
@foreach:@WORLDS:worlds {# Special layouts are applied when there are less than four worlds for a given game. #}
@if:@i % 2:sel {% if len(worlds) == 1 %}
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] image[{{ WIDTH * 0.5 - 2 }},{{ HEIGHT * 0.5 - 2 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
style[.select_world_${@path}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530] 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]) }};]
@else:sel button[{{ WIDTH * 0.5 - 2 }},{{ HEIGHT * 0.5 + 1 }};4,0.75;nobg;{{ worlds[1].name }}]
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] {% elseif len(worlds) == 2 %}
style[.select_world_${@path}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39]
@endif:sel image[{{ WIDTH * 0.5 - 4.5 }},{{ HEIGHT * 0.5 - 2 }};4,4;{{ DEFAULT_ASSETS }}btn_bg.png;]
button[0,${(@i +-1) * 0.5};${@list_width},0.5;.select_world_${@path};${@name}] image_button[{{ WIDTH * 0.5 - 4 }},{{ HEIGHT * 0.5 - 1.75 }};3,3;{{ DEFAULT_ASSETS }}menu_content.png;{{ action('set', 'selected_world', worlds[1]) }};]
@endforeach:worlds 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[] scroll_container_end[]
@if:@selected_world:fi {% if selected_world %}
box[${@WIDTH * 0.4 +-0.05},${@HEIGHT * 0.1 +-0.1};0.1,${@HEIGHT * 0.8 + 0.2};#292d2fff] 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] 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 {% set j = 0 %}
@if:@setting_damage:fii {% if setting_damage %}
@if:@damage_enabled:fiii {% if damage_enabled %}
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_filled.png;.set_damage_enabled_to_0;] image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_filled.png;.set_damage_enabled_to_false;]
@else:fiii {% else %}
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_empty.png;.set_damage_enabled_to_1;] image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_empty.png;.set_damage_enabled_to_true;]
@endif:fiii {% endif %}
label[0.5,${@j + 0.25};Damage] label[0.5,{{ j + 0.25 }};Damage]
@set:j:@j + 0.5 {% set j = j + 0.5 %}
@else:fii {% endif %}
@endif:fii
@if:@setting_creative:fii {% if setting_creative %}
@if:@creative_enabled:fiii {% if creative_enabled %}
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_filled.png;.set_creative_enabled_to_0;] image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_filled.png;.set_creative_enabled_to_false;]
@else:fiii {% else %}
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_empty.png;.set_creative_enabled_to_1;] image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_empty.png;.set_creative_enabled_to_true;]
@endif:fiii {% endif %}
label[0.5,${@j + 0.25};Creative] label[0.5,{{ j + 0.25 }};Creative]
@set:j:@j + 0.5 {% set j = j + 0.5 %}
@else:fii {% endif %}
@endif:fii
@set:play_str:Play {% set play_str = "Play" %}
@if:@setting_server:fii {% if setting_server %}
@if:@server_enabled:fiii {% if server_enabled %}
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_filled.png;.set_server_enabled_to_0;] image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_filled.png;.set_server_enabled_to_false;]
@set:play_str:Host server {% set play_str = "Host server" %}
@else:fiii {% else %}
image_button[0,${@j};0.5,0.5;$DEFAULT_ASSET_PATH/checkbox_empty.png;.set_server_enabled_to_1;] image_button[0,{{ j }};0.5,0.5;{{ DEFAULT_ASSETS }}checkbox_empty.png;.set_server_enabled_to_true;]
@set:play_str:Play {% set play_str = "Play" %}
@endif:fiii {% endif %}
label[0.5,${@j + 0.25};Server] label[0.5,{{ j + 0.25 }};Server]
@set:j:@j + 0.5 {% set j = j + 0.5 %}
@else:fii {% endif %}
@endif:fii
@set:j:@j + 1 {% set j = j + 1 %}
button[${@WIDTH * 0.05},${@j};${@WIDTH * 0.4},0.75;.overlay_dialog_modconfig;Configure mods] 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}] button[{{ WIDTH * 0.05 }},{{ j + 1 }};{{ WIDTH * 0.4 }},0.75;.play;{{ play_str }}]
scroll_container_end[] scroll_container_end[]
scrollbar[-800,6;0,2;vertical;worldconfigscroll;] scrollbar[-800,6;0,2;vertical;worldconfigscroll;]
@else:fi {% endif %}
#}
@endif:fi
scrollbaroptions[arrows=hide] scrollbaroptions[arrows=hide]
scrollbar[-800,6;0,2;vertical;worldscroll;] scrollbar[-800,6;0,2;vertical;worldscroll;]
</main>
<modconfig> {% endview %}
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] {% view modconfig %}
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] 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]
@foreach:@MODS:m hypertext[{{ WIDTH * 0.05 }},{{ HEIGHT * 0.05 }};{{ WIDTH * 0.4 }},0.75;;<global valign=middle halign=center><b>Available mods</b>]
@if:@i % 2:sel scroll_container[{{ WIDTH * 0.05 }},{{ HEIGHT * 0.05 + 0.75 }};{{ WIDTH * 0.4 }},{{ HEIGHT * 0.9 - 1.7 }};modsscroll;vertical;;0,0]
style[.select_mod_${@name};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530] {% for mod in get_mods() %}
style[.select_mod_${@name}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530] style[.select_mod_{{ mod.name }};bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
style[.select_mod_${@name}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530] style[.select_mod_{{ mod.name }}:hovered;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
@else:sel style[.select_mod_{{ mod.name }}:hovered+focused;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
style[.select_mod_${@name};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39] button[0,{{ loop.index0 * 0.5 }};{{ WIDTH * 0.4 }},0.5;.select_mod_{{ mod.name }};{{ mod.name }}]
style[.select_mod_${@name}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39] {% endfor %}
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
scroll_container_end[] scroll_container_end[]
scrollbar[-800,6;0,2;vertical;modsscroll;] 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] 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>Mods for ${@selected_world_name}</b>] 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] 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 {% for mod in get_world_mods() %}
@if:@game_mod:gm {% if not mod.game_provided %}
@if:@i % 2:sel style[.select_mod_{{ mod.name }};bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
style[.select_mod_${@name};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530] style[.select_mod_{{ mod.name }}:hovered;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
style[.select_mod_${@name}:hovered;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530] style[.select_mod_{{ mod.name }}:hovered+focused;bgimg={{ DEFAULT_ASSETS }}white.png;bgimg_middle=0;bgcolor={{ loop.cycle('#373530', '#403e39') }}]
style[.select_mod_${@name}:hovered+focused;bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#373530] button[0,{{ loop.index0 * 0.5 }};{{ WIDTH * 0.4 }},0.5;.select_mod_{{ mod.name }};{{ mod.name }}]
@else:sel {% endif %}
style[.select_mod_${@name};bgimg=$DEFAULT_ASSET_PATH/white.png;bgimg_middle=0;bgcolor=#403e39] {% endfor %}
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
scroll_container_end[] scroll_container_end[]
scrollbar[-800,6;0,2;vertical;worldmodsscroll;] 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 }},{{ 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_ASSET_PATH/arrow_left.png;.remove_mod_from_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[.add_mod_to_world;Add mod to world;#444;#aaa]
tooltip[.remove_mod_from_world;Remove mod from 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.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_dialog;Confirm] button[{{ WIDTH * 0.5 }},{{ HEIGHT * 0.95 - 0.75 }};{{ WIDTH * 0.4 }},0.75;.unoverlay_view;Confirm]
</modconfig>
<addworld>
label[2,2;Add World, asset path is $ASSET_PATH]
button[2,3;3,1;.show_dialog_main;back]
@foreach:[hello,there,bob]:myloop {% endview %}
label[6,${@i + 3};${@item}] {% view addworld %}
@endforeach:myloop
</addworld> {% endview %}
]] ]]
@ -342,6 +400,9 @@ function get_worlds_for_game(id)
out[#out +1] = x out[#out +1] = x
end end
end end
table.sort(out, function(a, b)
return a.name < b.name
end)
return out return out
end end
@ -996,9 +1057,16 @@ function show_game_menu(args)
end end
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_damage = game.disabled_settings.damage == nil
state.menu_vars.setting_creative = game.disabled_settings.creative == nil state.menu_vars.setting_creative = game.disabled_settings.creative == nil
@ -1023,17 +1091,15 @@ function show_game_menu(args)
bgcolor[#000;true;#151618]\ bgcolor[#000;true;#151618]\
" "
end end
for i, x in ipairs(state.menu_current) do for i, x in ipairs(state.menu_current) do
if i > 1 then if i > 1 then
fs = fs.."\ fs = fs.."\
box[0,0;"..size.x..","..size.y..";#0009]\ box[0,0;"..size.x..","..size.y..";#0009]\
" "
end end
fs = fs..evaluate_game_dialog(game.menu[x], state.menu_vars) fs = fs..template.evaluate(game.menu[x], state.menu_vars)
end end
-- print(fs)
minetest.update_formspec(game_header..fs.."\ minetest.update_formspec(game_header..fs.."\
button[0,"..(size.y -1)..";1,1;to_meta_menu;<]\ button[0,"..(size.y -1)..";1,1;to_meta_menu;<]\
@ -1872,13 +1938,13 @@ function minetest.button_handler(data)
singleplayer = true singleplayer = true
} }
minetest.start() 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_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 { 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 elseif k:sub(1, string.len(".select_world_")) == ".select_world_" then
state.menu_vars.selected_world = k:sub(string.len(".select_world_>")) state.menu_vars.selected_world = k:sub(string.len(".select_world_>"))
@ -1906,8 +1972,8 @@ function minetest.button_handler(data)
unoverlay_dialog = true unoverlay_dialog = true
} }
elseif k:sub(1, string.len(".set_")) == ".set_" then elseif k:sub(1, string.len(".set_")) == ".set_" then
local name, value = k:match "%.set_(.+)_to_(.*)" local name, value = k:match "%.set_|(.+)|_to_(.*)"
state.menu_vars[name] = value == "" and "0" or value state.menu_vars[name] = minetest.parse_json(value:gsub("\\([];,$\\[])", "%1"))
show_game_menu() show_game_menu()
end end
end end

File diff suppressed because it is too large Load diff