fix the hud enabling/autohiding for new players
This commit is contained in:
		
							
								
								
									
										17
									
								
								hud.lua
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								hud.lua
									
									
									
									
									
								
							| @@ -15,7 +15,7 @@ local hud_config = { position = {x = 1, y = 0.2}, | |||||||
|  |  | ||||||
| -- call this function to enable the HUD for the player that shows his quests | -- call this function to enable the HUD for the player that shows his quests | ||||||
| -- the HUD can only show up to show_max quests | -- the HUD can only show up to show_max quests | ||||||
| function quests.show_hud(playername, autohide)  | function quests.show_hud(playername, autohide) | ||||||
| 	if (quests.hud[playername] == nil) then | 	if (quests.hud[playername] == nil) then | ||||||
| 		quests.hud[playername] = { autohide = autohide} | 		quests.hud[playername] = { autohide = autohide} | ||||||
| 	end | 	end | ||||||
| @@ -60,8 +60,8 @@ function quests.hide_hud(playername) | |||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
| local function get_quest_hud_string(questname, quest)  | local function get_quest_hud_string(questname, quest) | ||||||
| 	local quest_string = quests.registered_quests[questname].title  | 	local quest_string = quests.registered_quests[questname].title | ||||||
| 	if (quests.registered_quests[questname].max ~= 1) then | 	if (quests.registered_quests[questname].max ~= 1) then | ||||||
| 		quest_string = quest_string .. "\n               ("..quests.round(quest.value, 2).."/"..quests.registered_quests[questname].max..")" | 		quest_string = quest_string .. "\n               ("..quests.round(quest.value, 2).."/"..quests.registered_quests[questname].max..")" | ||||||
| 	end | 	end | ||||||
| @@ -70,7 +70,7 @@ end | |||||||
|  |  | ||||||
| -- only for internal use | -- only for internal use | ||||||
| -- updates the hud | -- updates the hud | ||||||
| function quests.update_hud(playername)  | function quests.update_hud(playername) | ||||||
| 	if (quests.hud[playername] == nil or quests.active_quests[playername] == nil) then | 	if (quests.hud[playername] == nil or quests.active_quests[playername] == nil) then | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| @@ -112,7 +112,7 @@ function quests.update_hud(playername) | |||||||
| 				end | 				end | ||||||
| 				visible[hud_element.name] = true | 				visible[hud_element.name] = true | ||||||
| 				i = i + 1 | 				i = i + 1 | ||||||
| 			else  | 			else | ||||||
| 				player:hud_remove(hud_element.id) | 				player:hud_remove(hud_element.id) | ||||||
| 				if (hud_element.id_background ~= nil) then | 				if (hud_element.id_background ~= nil) then | ||||||
| 					player:hud_remove(hud_element.id_background) | 					player:hud_remove(hud_element.id_background) | ||||||
| @@ -131,7 +131,7 @@ function quests.update_hud(playername) | |||||||
| 			i = i - 1 | 			i = i - 1 | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| 	 |  | ||||||
| 	if (i >= show_max + 1) then | 	if (i >= show_max + 1) then | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| @@ -163,7 +163,7 @@ function quests.update_hud(playername) | |||||||
| 							 text = "quests_questbar.png" }) | 							 text = "quests_questbar.png" }) | ||||||
| 			end | 			end | ||||||
|  |  | ||||||
| 			table.insert(quests.hud[playername].list, {  name          = questname,  | 			table.insert(quests.hud[playername].list, {  name          = questname, | ||||||
| 								id            = id, | 								id            = id, | ||||||
| 								id_background = id_background, | 								id_background = id_background, | ||||||
| 								id_bar        = id_bar, | 								id_bar        = id_bar, | ||||||
| @@ -217,5 +217,8 @@ minetest.register_on_joinplayer(function(player) | |||||||
| 				quests.show_hud(playername) | 				quests.show_hud(playername) | ||||||
| 			end, playername) | 			end, playername) | ||||||
| 		end | 		end | ||||||
|  | 	else --new player | ||||||
|  | 		quests.hud[playername] = {autohide = true} | ||||||
|  | 		quests.active_quests[playername] = {} | ||||||
| 	end | 	end | ||||||
| end) | end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user