Skip to content

Commit

Permalink
feat: PlayersInventory: Now warnings saves in table and shows in tool…
Browse files Browse the repository at this point in the history
…tips.
  • Loading branch information
Ajick2013 committed Jun 16, 2023
1 parent 39514e7 commit d4e820d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 32 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.4",
"version": "1.1.5",
"title": "Fed1sServerMod",
"author": "danbka33",
"contact": "",
Expand Down
2 changes: 2 additions & 0 deletions locale/en/strings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ message-demoted=Player __1__ in no longer a Manager
message-inventory-full=There is no space in the inventory for given items type.
message-no-items=__1__ already don't have items: __2__ __3__
message-promoted=__1__ is now the Manager
message-warning=__1__ has been warned __2__ times: __3__
tooltip-ban=Ban
tooltip-button-ammo=[color=#7674ff]ctrl+click[/color] - take ammo
tooltip-button-armor-only-show=[color=#7674ff]left click[/color] - show armor
Expand All @@ -99,6 +100,7 @@ tooltip-unban=Unban
tooltip-unfavorite=Remove from Favorites
tooltip-unmute=Unmute
tooltip-warn=Warn
tooltip-warnings=Warnings:
[statistics]
heading-1=[font=heading-1]__1__[/font]
Expand Down
4 changes: 3 additions & 1 deletion locale/ru/strings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ label-online-badge=[онлайн]
label-trash-inventory=Мусорные слоты
label-undecided-badge=[неопределившийся]
label-warnings-badge=[предупреждений: __1__]
label-warnings-info=Уже предупреждений вынесено: __1__
label-warnings-info=Уже вынесено предупреждений: __1__
label-warrior-badge=[color=#ff8f00][атакующий][/color]
message-demoted=Игрок __1__ больше не Руководитель
message-inventory-full=В инвентаре больше нет места для перемещаемых предметов.
message-no-items=__1__ уже успел куда-то сныкать все предметы __2__ __3__
message-promoted=__1__ теперь Руководитель
message-warning=Игроку __1__ вынесено предупреждение __2__: __3__
tooltip-ban=Забанить
tooltip-button-ammo=[color=#7674ff]ctrl+click[/color] - забрать боеприпасы
tooltip-button-armor-only-show=[color=#7674ff]left click[/color] - показать броню
Expand All @@ -99,6 +100,7 @@ tooltip-unban=Разбанить
tooltip-unfavorite=Удалить из Избранных
tooltip-unmute=Разрешить писать сообщения
tooltip-warn=Вынести предупреждение
tooltip-warnings=Прудпреждения:

[statistics]
heading-1=[font=heading-1]__1__[/font]
Expand Down
74 changes: 44 additions & 30 deletions scripts/players_inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function PlayersInventory.settingup_and_fill_current_tab(player_index, in_search
local current_tab = player_data.current_tab

if current_tab.name == "favorites" and #player_filters.favorites == 0
or current_tab.name == "warnings" and table_size(global.players_inventory_warnings) == 0
or current_tab.name == "warnings" and #global.players_inventory_warnings == 0
or current_tab.name == "muted" and #global.players_inventory_muted == 0
or current_tab.name == "banned" and #global.players_inventory_banned == 0
then
Expand Down Expand Up @@ -286,7 +286,7 @@ function PlayersInventory.build_player_inventory_panel(players_list, target_play
local self_player = game.players[players_list.player_index]
local muted = PlayersInventory.is_muted(target_player.index)
local banned = PlayersInventory.is_banned(target_player.index)
local warnings = global.players_inventory_warnings[target_player.index] or 0
local warnings = global.players_inventory_warnings[target_player.index] or {}
local tab_name = PlayersInventory.players_data[self_player.index].current_tab.name
local role_index = global.players_inventory_filters[self_player.index].role_index

Expand Down Expand Up @@ -334,8 +334,8 @@ function PlayersInventory.build_player_inventory_panel(players_list, target_play
end

header.add{
type="label", name="warnings", caption={"players-inventory.label-warnings-badge", warnings},
visible=(warnings > 0)
type="label", name="warnings", caption={"players-inventory.label-warnings-badge", #warnings},
visible=(#warnings > 0), tooltip=PlayersInventory.get_warn_tooltip(warnings)
}

header.add{
Expand Down Expand Up @@ -806,11 +806,18 @@ function PlayersInventory.build_accept_prompt_window(self_player, tags)
reason_textbox.style.width = 450
reason_textbox.style.height = 100

local player_warnings = global.players_inventory_warnings[target_player.index] or 0
local warnings = global.players_inventory_warnings[target_player.index] or {}
local tooltip

if #warnings > 0 then
tooltip = PlayersInventory.get_warn_tooltip(warnings)
end

if tags.action == "warn" then
local warn_info = window.add{
type="label", caption={"players-inventory.label-warnings-info", player_warnings}
type = "label",
caption = {"players-inventory.label-warnings-info", #warnings},
tooltip = tooltip
}
warn_info.style.font_color = {0.6 ,0.6, 0.6, 1}
end
Expand Down Expand Up @@ -843,11 +850,12 @@ function PlayersInventory.build_accept_prompt_window(self_player, tags)
end

function PlayersInventory.warn_player(self_index, target_player, reason)
local warnings_count = PlayersInventory.warn(target_player, reason)
local warnings = PlayersInventory.warn(target_player, reason)
local current_tab = PlayersInventory.players_data[self_index].current_tab
local panel = current_tab.players.list[target_player.name]

panel.header.warnings.caption = {"players-inventory.label-warnings-badge", warnings_count}
panel.header.warnings.caption = {"players-inventory.label-warnings-badge", #warnings}
panel.header.warnings.tooltip = PlayersInventory.get_warn_tooltip(warnings)
panel.header.warnings.visible = true
end

Expand Down Expand Up @@ -1287,18 +1295,16 @@ function PlayersInventory.unfavorite(self_index, player_index)
end

function PlayersInventory.warn(target_player, reason)
local warnings_count = global.players_inventory_warnings[target_player.index] or 0
warnings_count = warnings_count + 1
if not global.players_inventory_warnings[target_player.index] then
global.players_inventory_warnings[target_player.index] = {}
end

global.players_inventory_warnings[target_player.index] = warnings_count
local warnings = global.players_inventory_warnings[target_player.index]
table.insert(warnings, reason)

if target_player.connected then
local counts = {"первое", "второе", "третье"}
target_player.print("Вам вынесено "..counts[warnings_count].." предупреждение:")
target_player.print(reason)
end
game.print({"players-inventory.message-warning", target_player.name, #warnings, reason})

return warnings_count
return warnings
end

function PlayersInventory.mute(target_player)
Expand Down Expand Up @@ -1347,6 +1353,16 @@ function PlayersInventory.decrise_selected(self_index, target_index)
buttons.players_inventory_take_selected_button.enabled = (selected_count > 0)
end

function PlayersInventory.get_warn_tooltip(warnings)
local tooltip = {"", {"players-inventory.tooltip-warnings"}}

for index, warning in pairs(warnings) do
table.insert(tooltip, "\n" .. index .. ". " .. warning)
end

return tooltip
end


function PlayersInventory.remove(list, item)
for index = 1, #list do
Expand All @@ -1371,21 +1387,19 @@ function PlayersInventory.on_init()
end

function PlayersInventory.on_configuration_changed(data)
PlayersInventory.on_init()

for _, player in pairs(game.players) do
local player_filters = global.players_inventory_filters[player.index] or {}

player_filters.favorites = player_filters.favorites or {}
player_filters.tab_index = player_filters.tab_index or 1
player_filters.role_index = player_filters.role_index or 1

global.players_inventory_filters[player.index] = player_filters
if not data then
return
end

PlayersInventory.create_toggle_button(player)
if data.mod_changes
and data.mod_changes["Fed1sServerMod"]
and data.mod_changes["Fed1sServerMod"].old_version < "1.1.4"
then
global.players_inventory_warnings[2] = {}
table.insert(global.players_inventory_warnings[2], "МАЛО ПИЛ ВОДКИ НА ВЫХОДНЫХ!")
end

if gebug then
if in_gebug then
game.print("Configuration updated")
end
end
Expand Down Expand Up @@ -1527,7 +1541,7 @@ function PlayersInventory.on_clear_search(event)
event.element.parent.parent.players.visible = false
event.element.parent.parent.placeholder.visible = true

PlayersInventory.player_data[event.player_index].selected = nil
PlayersInventory.players_data[event.player_index].selected = nil
end

function PlayersInventory.on_toggle_expand_panel(event)
Expand Down

0 comments on commit d4e820d

Please sign in to comment.