[WIP] standardize more label measurements.

This commit is contained in:
iliekprogrammar 2021-09-30 20:49:35 +08:00
parent f09db9098c
commit dcfe175303
2 changed files with 16 additions and 21 deletions

View File

@ -5,12 +5,17 @@ mcl_formspec = {}
local mcl_formspec = mcl_formspec
mcl_formspec.padding = 0.375
mcl_formspec.margin = 0.078125
--------------------------------------------------------------------------------
-- Label --
--------------------------------------------------------------------------------
mcl_formspec.label_color = "#313131"
mcl_formspec.label_size = tonumber(minetest.settings:get("mcl_label_font_size")) or 24
-- NOTE: labels are vertically aligned to "center" (which is also affected by padding of the font) in the new coordinate system.
mcl_formspec.label_height = 0.625
mcl_formspec.label_y_offset = 0.25 * mcl_formspec.label_height -- offset to counter the font padding.
mcl_formspec.label_style = string.format("style_type[label;font_size=%f]", mcl_formspec.label_size)
mcl_formspec.label_style_reset = "style_type[label;font=;font_size=;noclip=]"

View File

@ -5,10 +5,15 @@ local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape
local C = minetest.colorize
local margin = mcl_formspec.margin
local padding = mcl_formspec.padding
local bu = mcl_formspec.itemslot_bu
local iu = mcl_formspec.itemslot_iu
local label_color = mcl_formspec.label_color
local label_height = mcl_formspec.label_height
local label_y_offset = mcl_formspec.label_y_offset
mcl_inventory = {}
--local mod_player = minetest.get_modpath("mcl_player")
@ -149,26 +154,14 @@ local function set_inventory(player, armor_change_only)
}
-- Crafting formspec
-- NOTE: according to screenshots from MC inventory dialog, crafting_x
-- doesn't need to offset 0.25 itemslot unit to the left, but if it's not
-- included, the crafting output itemslot will protrude out of the inner
-- inventory dialog and look awkward. So we deviate from MC for the sake of
-- looking nicer.
-- NOTE: text usually depends on eyeballed values due to how minetest
-- handles them. e.g.: labels are verically aligned to "center" (which is
-- also affected by padding of the font) in the new coordinate system.
local crafting_label_height = 0.625 -- eyeballed value.
local crafting_label_y = padding + 0.25 * crafting_label_height -- 0.25 * crafting_label_height for nicer text spacing, see notes.
local crafting_x = padding + 5 * iu - 0.25 * iu -- 0.25 * iu offset for nicer crafting formspec spacing, see notes.
local crafting_y = padding + crafting_label_height
local crafting_x = padding + 5 * iu
local crafting_y = padding + label_height
local crafting_length = 2 * iu
local crafting_arrow_spacing = 0.078125 -- eyeballed value
local crafting_arrow_x = crafting_x + crafting_length + crafting_arrow_spacing
local crafting_arrow_x = crafting_x + crafting_length + margin
local crafting_arrow_y = crafting_y + iu / 2
local crafting_arrow_length = iu
local crafting_formspec = table.concat{
"label[",
crafting_x - bu, ",", crafting_label_y, ";",
crafting_x - bu, ",", padding + label_y_offset, ";",
F(C(mcl_formspec.label_color, S("Crafting"))),
"]",
mcl_formspec.create_itemslot_bg(crafting_x, crafting_y, 2, 2),
@ -180,12 +173,9 @@ local function set_inventory(player, armor_change_only)
crafting_arrow_x, ",", crafting_arrow_y, ";",
"1,1;crafting_formspec_arrow.png",
"]",
mcl_formspec.create_itemslot_bg(
crafting_arrow_x + crafting_arrow_length + crafting_arrow_spacing, crafting_arrow_y,
1, 1
),
mcl_formspec.create_itemslot_bg(crafting_arrow_x + 1 + margin + bu, crafting_arrow_y, 1, 1),
"list[current_player;craftpreview;",
crafting_arrow_x + crafting_arrow_length + crafting_arrow_spacing, ",", crafting_arrow_y, ";",
crafting_arrow_x + 1 + margin + bu, ",", crafting_arrow_y, ";",
"1,1;",
"]",
}