This commit is contained in:
Jean-Patrick Guerrero 2023-01-19 17:30:57 +01:00
parent d833199628
commit 8289d290a3
4 changed files with 41 additions and 37 deletions

8
API.md
View File

@ -1,6 +1,6 @@
# :screwdriver: API
# API :screwdriver:
## Table of Contents
### Table of Contents
1. [**Tabs**](https://github.com/minetest-mods/i3/blob/main/API.md#tabs)
2. [**Recipes**](https://github.com/minetest-mods/i3/blob/main/API.md#recipes)
3. [**Minitabs**](https://github.com/minetest-mods/i3/blob/main/API.md#minitabs)
@ -49,7 +49,7 @@ i3.new_tab("stuff", {
-- Do things
end
i3.set_fs(player) -- Update the formspec, mandatory
i3.set_fs(player) -- Update the formspec
end,
})
```
@ -194,7 +194,7 @@ Example:
```Lua
i3.new_minitab("Test", {
access = function(player, data)
-- Whether a player can access this tab or not. Optional.
-- Whether this tab is visible or not. Optional.
return player:get_player_name() == "singleplayer"
end,

View File

@ -34,7 +34,7 @@ i3 = {
save_interval = 600, -- Player data save interval (in seconds)
hud_speed = 1,
hud_timer_max = 1.5,
hud_timer_max = 3,
damage_enabled = core.settings:get_bool"enable_damage",
progressive_mode = core.settings:get_bool"i3_progressive_mode",

View File

@ -15,16 +15,18 @@ local function init_hud(player)
data.hud = {
bg = player:hud_add {
hud_elem_type = "image",
position = {x = 0.78, y = 1},
position = {x = 1, y = 1},
offset = {x = -320, y = 0},
alignment = {x = 1, y = 1},
scale = {x = 370, y = 112},
scale = {x = 300, y = 100},
text = "i3_bg.png",
z_index = 0xDEAD,
},
img = player:hud_add {
hud_elem_type = "image",
position = {x = 0.79, y = 1.02},
position = {x = 1, y = 1},
offset = {x = -310, y = 20},
alignment = {x = 1, y = 1},
scale = {x = 1, y = 1},
text = "",
@ -33,7 +35,8 @@ local function init_hud(player)
text = player:hud_add {
hud_elem_type = "text",
position = {x = 0.84, y = 1.04},
position = {x = 1, y = 1},
offset = {x = -235, y = 40},
alignment = {x = 1, y = 1},
number = 0xffffff,
text = "",
@ -55,13 +58,12 @@ local function init_hud(player)
end
local function show_hud(player, data)
-- It would better to have an engine function `hud_move` to only need
-- 2 calls for the notification's back and forth.
local hud_info_bg = player:hud_get(data.hud.bg)
local dt = 0.025
local dt = 0.016
local offset_y = hud_info_bg.offset.y
local speed = 5 * i3.settings.hud_speed
if hud_info_bg.position.y <= 0.9 then
if offset_y < -100 then
data.show_hud = false
data.hud_timer = (data.hud_timer or 0) + dt
end
@ -73,31 +75,34 @@ local function show_hud(player, data)
end
if data.show_hud then
for _, def in pairs(data.hud) do
local hud_info = player:hud_get(def)
player:hud_change(def, "position", {
x = hud_info.position.x,
y = hud_info.position.y - ((dt / 5) * i3.settings.hud_speed)
})
end
elseif data.show_hud == false then
if data.hud_timer >= i3.settings.hud_timer_max then
for _, def in pairs(data.hud) do
for name, def in pairs(data.hud) do
if name ~= "wielditem" then
local hud_info = player:hud_get(def)
player:hud_change(def, "position", {
x = hud_info.position.x,
y = hud_info.position.y + ((dt / 5) * i3.settings.hud_speed)
player:hud_change(def, "offset", {
x = hud_info.offset.x,
y = hud_info.offset.y - speed
})
end
end
elseif data.show_hud == false then
if data.hud_timer >= i3.settings.hud_timer_max then
for name, def in pairs(data.hud) do
if name ~= "wielditem" then
local hud_info = player:hud_get(def)
if hud_info_bg.position.y >= 1 then
data.show_hud = nil
player:hud_change(def, "offset", {
x = hud_info.offset.x,
y = hud_info.offset.y + speed
})
end
end
if offset_y > 0 then
data.show_hud = nil
data.hud_timer = nil
data.hud_msg = nil
data.hud_img = nil
data.hud_msg = nil
data.hud_img = nil
end
end
end

View File

@ -3,8 +3,8 @@ local hud_notif = i3.hud_notif
local POLL_FREQ = 0.25
IMPORT("reg_items", "reg_nodes")
IMPORT("fmt", "search", "table_merge", "array_diff")
IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters")
IMPORT("fmt", "table_merge", "array_diff")
IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters", "sort_by_category")
i3.remove_minitab"Nodes"
i3.remove_minitab"Items"
@ -154,9 +154,8 @@ local function poll_new_items(player, data, join)
end
data.items_progress = items
data.itab = 1
search(data)
sort_by_category(data)
set_fs(player)
end