Skip to content

Commit

Permalink
fix: Pick role gui, remove exclude current player in player list
Browse files Browse the repository at this point in the history
  • Loading branch information
danbka33 committed Aug 14, 2023
1 parent 9403149 commit b2cbf6a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 59 deletions.
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Fed1sServerMod",
"version": "1.1.22",
"version": "1.1.23",
"title": "Fed1sServerMod",
"author": "danbka33",
"contact": "",
Expand Down
1 change: 0 additions & 1 deletion scripts/permissions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function Permissions.create_groups_and_apply_permissions()
game.permissions.create_group(Permissions.groups.admin)
end


if game.is_multiplayer() then
return
end
Expand Down
4 changes: 2 additions & 2 deletions scripts/players_inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function PlayersInventory.fill_player_list_by_role(players_list, online, role, m
return
end

if player_index == players_list.player_index or player.connected ~= online then
if player.connected ~= online then
goto continue
end

Expand Down Expand Up @@ -399,7 +399,7 @@ function PlayersInventory.fill_player_list_by_name(players_list, name)
return
end

if player.index ~= players_list.player_index and string.match(string.lower(player.name), name) then
if string.match(string.lower(player.name), name) then
PlayersInventory.build_player_inventory_panel(players_list, player)
end
end
Expand Down
100 changes: 45 additions & 55 deletions scripts/server_mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,41 +147,41 @@ function ServerMod.open(player, target_page)
root.force_auto_center()
player.opened = root
if not root.valid then
game.print("ServerMod GUI was destroyed by another mod. Please report this to the mod author.")
return
end

do
-- Titlebar
local titlebar = root.add {
type = "flow",
name = ServerMod.name_title_flow,
direction = "horizontal",
style = "server_mod_titlebar_flow"
}
titlebar.drag_target = root
titlebar.add { -- Title
type = "label",
caption = { "server_mod.window_title_label" },
ignored_by_interaction = true,
style = "frame_title"
}
titlebar.add {
type = "empty-widget",
ignored_by_interaction = true,
style = "server_mod_drag_handle"
}

local playerData = ServerMod.get_make_playerdata(player.index)
if playerData.applied then
titlebar.add { -- Close button
type = "sprite-button",
sprite = "utility/close_white",
hovered_sprite = "utility/close_black",
clicked_sprite = "utility/close_black",
tags = { root = ServerMod.name_root, action = ServerMod.action_close_button },
style = "close_button"
}
end
-- Titlebar
local titlebar = root.add {
type = "flow",
name = ServerMod.name_title_flow,
direction = "horizontal",
style = "server_mod_titlebar_flow"
}
titlebar.drag_target = root
titlebar.add { -- Title
type = "label",
caption = { "server_mod.window_title_label" },
ignored_by_interaction = true,
style = "frame_title"
}
titlebar.add {
type = "empty-widget",
ignored_by_interaction = true,
style = "server_mod_drag_handle"
}

local playerData = ServerMod.get_make_playerdata(player.index)
if playerData.applied then
titlebar.add { -- Close button
type = "sprite-button",
sprite = "utility/close_white",
hovered_sprite = "utility/close_black",
clicked_sprite = "utility/close_black",
tags = { root = ServerMod.name_root, action = ServerMod.action_close_button },
style = "close_button"
}
end

local main_flow = root.add {
Expand Down Expand Up @@ -391,10 +391,10 @@ function ServerMod.on_player_created(event)

if not game.is_multiplayer() and player.admin then
Permissions.set_group(player, Permissions.groups.admin)
return
else
Permissions.set_group(player, Permissions.groups.pick_role)
end

Permissions.set_group(player, Permissions.groups.pick_role)
PlayerColor.apply_player_color(player)
ServerMod.open(player)
end
Expand All @@ -409,10 +409,6 @@ function ServerMod.on_player_joined_game(event)

ServerMod.update_overhead_button(player)

if not game.is_multiplayer() then
return
end

local playerData = ServerMod.get_make_playerdata(player.index)

if not playerData.applied then
Expand Down Expand Up @@ -452,19 +448,19 @@ end
---Calls update functions every second.
---@param event NthTickEventData Event data
function ServerMod.on_nth_tick_60(event)
-- for _, player in pairs(game.connected_players) do
-- local playerData = ServerMod.get_make_playerdata(player.index)
for _, player in pairs(game.connected_players) do
local playerData = ServerMod.get_make_playerdata(player.index)

-- if not playerData.applied then
-- local root = ServerMod.get(player)
if not playerData.applied then
local root = ServerMod.get(player)

-- if not root then
-- ServerMod.open(player)
-- end
-- end
if not root then
ServerMod.open(player)
end
end

-- -- ServerMod.update(player, event.tick)
-- end
ServerMod.update(player, event.tick)
end
end

---Handles gui clicks, including for the overhead button.
Expand All @@ -477,12 +473,7 @@ function ServerMod.on_gui_click(event)
local player = game.get_player(event.player_index) --[[@as LuaPlayer]]

if event.element.name == ServerMod.name_overhead_button then
local playerData = ServerMod.get_make_playerdata(player.index)

if playerData.applied then
ServerMod.toggle(player --[[@as LuaPlayer]])
end

ServerMod.toggle(player --[[@as LuaPlayer]])
return
end

Expand Down Expand Up @@ -582,7 +573,7 @@ end

local event_handlers = {}
event_handlers.on_init = ServerMod.on_init
event_handlers.on_nth_tick = {[60] = ServerMod.on_nth_tick_60}
event_handlers.on_nth_tick = { [60] = ServerMod.on_nth_tick_60 }
event_handlers.on_configuration_changed = ServerMod.on_configuration_changed
event_handlers.events = {
[defines.events.on_runtime_mod_setting_changed] = ServerMod.on_runtime_mod_setting_changed,
Expand All @@ -595,5 +586,4 @@ event_handlers.events = {
}
EventHandler.add_lib(event_handlers)


return ServerMod

0 comments on commit b2cbf6a

Please sign in to comment.