mirror of
				https://github.com/minetest-mods/i3.git
				synced 2025-10-31 08:15:26 +01:00 
			
		
		
		
	Fix HUD
This commit is contained in:
		
							
								
								
									
										8
									
								
								API.md
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								API.md
									
									
									
									
									
								
							| @@ -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) | 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) | 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) | 3. [**Minitabs**](https://github.com/minetest-mods/i3/blob/main/API.md#minitabs) | ||||||
| @@ -49,7 +49,7 @@ i3.new_tab("stuff", { | |||||||
| 			-- Do things | 			-- Do things | ||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		i3.set_fs(player) -- Update the formspec, mandatory | 		i3.set_fs(player) -- Update the formspec | ||||||
| 	end, | 	end, | ||||||
| }) | }) | ||||||
| ``` | ``` | ||||||
| @@ -194,7 +194,7 @@ Example: | |||||||
| ```Lua | ```Lua | ||||||
| i3.new_minitab("Test", { | i3.new_minitab("Test", { | ||||||
| 	access = function(player, data) | 	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" | 		return player:get_player_name() == "singleplayer" | ||||||
| 	end, | 	end, | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								init.lua
									
									
									
									
									
								
							| @@ -34,7 +34,7 @@ i3 = { | |||||||
| 		save_interval = 600, -- Player data save interval (in seconds) | 		save_interval = 600, -- Player data save interval (in seconds) | ||||||
|  |  | ||||||
| 		hud_speed = 1, | 		hud_speed = 1, | ||||||
| 		hud_timer_max = 1.5, | 		hud_timer_max = 3, | ||||||
|  |  | ||||||
| 		damage_enabled = core.settings:get_bool"enable_damage", | 		damage_enabled = core.settings:get_bool"enable_damage", | ||||||
| 		progressive_mode = core.settings:get_bool"i3_progressive_mode", | 		progressive_mode = core.settings:get_bool"i3_progressive_mode", | ||||||
|   | |||||||
							
								
								
									
										61
									
								
								src/hud.lua
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								src/hud.lua
									
									
									
									
									
								
							| @@ -15,16 +15,18 @@ local function init_hud(player) | |||||||
| 	data.hud = { | 	data.hud = { | ||||||
| 		bg = player:hud_add { | 		bg = player:hud_add { | ||||||
| 			hud_elem_type = "image", | 			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}, | 			alignment     = {x = 1,    y = 1}, | ||||||
| 			scale         = {x = 370,  y = 112}, | 			scale         = {x = 300,  y = 100}, | ||||||
| 			text          = "i3_bg.png", | 			text          = "i3_bg.png", | ||||||
| 			z_index       = 0xDEAD, | 			z_index       = 0xDEAD, | ||||||
| 		}, | 		}, | ||||||
|  |  | ||||||
| 		img = player:hud_add { | 		img = player:hud_add { | ||||||
| 			hud_elem_type = "image", | 			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}, | 			alignment     = {x = 1,    y = 1}, | ||||||
| 			scale         = {x = 1,    y = 1}, | 			scale         = {x = 1,    y = 1}, | ||||||
| 			text          = "", | 			text          = "", | ||||||
| @@ -33,7 +35,8 @@ local function init_hud(player) | |||||||
|  |  | ||||||
| 		text = player:hud_add { | 		text = player:hud_add { | ||||||
| 			hud_elem_type = "text", | 			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}, | 			alignment     = {x = 1,    y = 1}, | ||||||
| 			number        = 0xffffff, | 			number        = 0xffffff, | ||||||
| 			text          = "", | 			text          = "", | ||||||
| @@ -55,13 +58,12 @@ local function init_hud(player) | |||||||
| end | end | ||||||
|  |  | ||||||
| local function show_hud(player, data) | 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 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.show_hud = false | ||||||
| 		data.hud_timer = (data.hud_timer or 0) + dt | 		data.hud_timer = (data.hud_timer or 0) + dt | ||||||
| 	end | 	end | ||||||
| @@ -73,31 +75,34 @@ local function show_hud(player, data) | |||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	if data.show_hud then | 	if data.show_hud then | ||||||
| 		for _, def in pairs(data.hud) do | 		for name, def in pairs(data.hud) do | ||||||
| 			local hud_info = player:hud_get(def) | 			if name ~= "wielditem" then | ||||||
|  |  | ||||||
| 			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 |  | ||||||
| 				local hud_info = player:hud_get(def) | 				local hud_info = player:hud_get(def) | ||||||
|  |  | ||||||
| 				player:hud_change(def, "position", { | 				player:hud_change(def, "offset", { | ||||||
| 					x = hud_info.position.x, | 					x = hud_info.offset.x, | ||||||
| 					y = hud_info.position.y + ((dt / 5) * i3.settings.hud_speed) | 					y = hud_info.offset.y - speed | ||||||
| 				}) | 				}) | ||||||
| 			end | 			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 | 					player:hud_change(def, "offset", { | ||||||
| 				data.show_hud = nil | 						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_timer = nil | ||||||
| 				data.hud_msg = nil | 				data.hud_msg   = nil | ||||||
| 				data.hud_img = nil | 				data.hud_img   = nil | ||||||
| 			end | 			end | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
|   | |||||||
| @@ -3,8 +3,8 @@ local hud_notif = i3.hud_notif | |||||||
| local POLL_FREQ = 0.25 | local POLL_FREQ = 0.25 | ||||||
|  |  | ||||||
| IMPORT("reg_items", "reg_nodes") | IMPORT("reg_items", "reg_nodes") | ||||||
| IMPORT("fmt", "search", "table_merge", "array_diff") | IMPORT("fmt", "table_merge", "array_diff") | ||||||
| IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters") | IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters", "sort_by_category") | ||||||
|  |  | ||||||
| i3.remove_minitab"Nodes" | i3.remove_minitab"Nodes" | ||||||
| i3.remove_minitab"Items" | i3.remove_minitab"Items" | ||||||
| @@ -154,9 +154,8 @@ local function poll_new_items(player, data, join) | |||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		data.items_progress = items | 		data.items_progress = items | ||||||
| 		data.itab = 1 |  | ||||||
|  |  | ||||||
| 		search(data) | 		sort_by_category(data) | ||||||
| 		set_fs(player) | 		set_fs(player) | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user