Bugs Fixed

This commit is contained in:
Cooldude2606
2019-05-06 13:38:05 +01:00
parent 2119378fad
commit 6d1c907484
7 changed files with 69 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ local Token = require 'utils.token'
local Event = require 'utils.event'
local Game = require 'utils.game'
local Global = require 'utils.global'
local mod_gui = require 'mod-gui'
local Gui = {}
@@ -179,7 +180,7 @@ Gui.on_player_show_top = custom_handler_factory(on_visible_handlers)
Gui.on_pre_player_hide_top = custom_handler_factory(on_pre_hidden_handlers)
--- Allows the player to show / hide this element.
-- The element must be part in gui.top.
-- The element must be in Gui.get_top_element_flow(player).
-- This function must be called in the control stage, i.e not inside an event.
-- @param element_name<string> This name must be globally unique.
function Gui.allow_player_to_toggle_top_element_visibility(element_name)
@@ -189,6 +190,15 @@ function Gui.allow_player_to_toggle_top_element_visibility(element_name)
top_elements[#top_elements + 1] = element_name
end
--- Returns the flow where top elements can be added and will be effected by google visibility
-- For the toggle to work it must be registed with Gui.allow_player_to_toggle_top_element_visibility(element_name)
-- @tparam player LuaPlayer pointer to the player who has the gui
-- @treturn LuaGuiEelement the top element flow
function Gui.get_top_element_flow(player)
player = Game.get_player_from_any(player)
return mod_gui.get_button_flow(player)
end
local toggle_button_name = Gui.uid_name()
Event.add(
@@ -201,15 +211,16 @@ Event.add(
end
local b =
player.gui.top.add {
Gui.get_top_element_flow(player).add {
type = 'button',
name = toggle_button_name,
caption = '<',
style=mod_gui.button_style,
tooltip = 'Shows / hides the Redmew Gui buttons.'
}
local style = b.style
style.width = 18
style.height = 38
style.height = 36
style.left_padding = 0
style.top_padding = 0
style.right_padding = 0
@@ -223,21 +234,16 @@ Gui.on_click(
function(event)
local button = event.element
local player = event.player
local top = player.gui.top
local top = Gui.get_top_element_flow(player)
if button.caption == '<' then
for i = 1, #top_elements do
local name = top_elements[i]
local ele = top[name]
if ele and ele.valid then
local style = ele.style
-- if visible is not set it has the value of nil.
-- Hence nil is treated as is visible.
local v = style.visible
if v or v == nil then
if ele.visible then
custom_raise(on_pre_hidden_handlers, ele, player)
style.visible = false
ele.visible = false
end
end
end
@@ -249,17 +255,15 @@ Gui.on_click(
local name = top_elements[i]
local ele = top[name]
if ele and ele.valid then
local style = ele.style
if not style.visible then
style.visible = true
if not ele.visible then
ele.visible = true
custom_raise(on_visible_handlers, ele, player)
end
end
end
button.caption = '<'
button.style.height = 38
button.style.height = 36
end
end
)