Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerkiz committed Nov 13, 2023
1 parent a3f2d9d commit 1169ef9
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 132 deletions.
10 changes: 8 additions & 2 deletions maps/fish_defender_v2/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--require "modules.rpg"

local Public = require 'maps.fish_defender_v2.core'
local Gui = require 'utils.gui'
require 'modules.rocket_launch_always_yields_science'
require 'modules.launch_fish_to_win'
require 'modules.biters_yield_coins'
Expand All @@ -23,6 +24,9 @@ local random = math.random
local insert = table.insert
local enable_start_grace_period = true

Gui.mod_gui_button_enabled = true
Gui.button_style = 'mod_gui_button'

local starting_items = {
['pistol'] = 1,
['firearm-magazine'] = 20,
Expand Down Expand Up @@ -103,7 +107,8 @@ local function create_wave_gui(player)
if player.gui.top['fish_defense_waves'] then
player.gui.top['fish_defense_waves'].destroy()
end
local frame = player.gui.top.add({type = 'frame', name = 'fish_defense_waves'})
local frame = player.gui.top.add({type = 'frame', name = 'fish_defense_waves', style = 'finished_game_subheader_frame'})
frame.style.minimal_height = 38
frame.style.maximal_height = 38

local wave_count = 0
Expand Down Expand Up @@ -215,7 +220,8 @@ local function add_fd_stats_button(player)
player.gui.top.add {
type = 'sprite-button',
name = button_id,
sprite = 'item/submachine-gun'
sprite = 'item/submachine-gun',
style = Gui.button_style
}
b.style.maximal_height = 38
end
Expand Down
3 changes: 0 additions & 3 deletions maps/mountain_fortress_v3/highscore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ local function get_sorted_list(column_name, score_list)
for key, player in ipairs(score_list) do
sl[key] = player
i = i + 1
if i == 20 then
return sl
end
end
return sl
end
Expand Down
11 changes: 4 additions & 7 deletions modules/launch_fish_to_win.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- launch fish into space to win the game -- by mewmew

local Event = require 'utils.event'
local Gui = require 'utils.gui'

local function goals()
if not global.catplanet_goals then
Expand Down Expand Up @@ -98,14 +99,9 @@ local function fish_in_space_toggle_button(player)
if player.gui.top['fish_in_space_toggle'] then
return
end
local button = player.gui.top.add {name = 'fish_in_space_toggle', type = 'sprite-button', sprite = 'item/raw-fish', tooltip = 'Fish in Space'}
button.style.font = 'default-bold'
local button = player.gui.top.add {name = 'fish_in_space_toggle', type = 'sprite-button', sprite = 'item/raw-fish', tooltip = 'Fish in Space', style = Gui.button_style}
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.top_padding = 2
button.style.left_padding = 4
button.style.right_padding = 4
button.style.bottom_padding = 2
button.style.maximal_height = 38
end

local function level_up_popup(player)
Expand Down Expand Up @@ -138,6 +134,7 @@ local function fish_in_space_gui(player)
local frame = player.gui.left.add({type = 'frame', name = 'fish_in_space'})
local label = frame.add({type = 'label', caption = 'Fish rescued: '})
label.style.font_color = {r = 0.11, g = 0.8, b = 0.44}
frame.style.bottom_padding = -2

local progress = global.fish_in_space / global.catplanet_goals[i + 1].goal
if progress > 1 then
Expand Down
71 changes: 48 additions & 23 deletions modules/show_inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local Global = require 'utils.global'
local Color = require 'utils.color_presets'
local SpamProtection = require 'utils.spam_protection'
local Event = require 'utils.event'
local Gui = require 'utils.gui'

local this = {
data = {},
Expand All @@ -18,6 +19,8 @@ Global.register(
end
)

local main_frame_name = Gui.uid_name()

local space = {
minimal_height = 10,
top_padding = 0,
Expand Down Expand Up @@ -143,7 +146,7 @@ local function close_player_inventory(player)
return
end

local element = gui.inventory_gui
local element = gui[main_frame_name]

if not is_valid(element) then
return
Expand Down Expand Up @@ -186,7 +189,7 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
return
end

local inventory_gui = screen.inventory_gui
local inventory_gui = screen[main_frame_name]
inventory_gui.caption = 'Inventory of ' .. target.name

for i = 1, #panel_type do
Expand Down Expand Up @@ -271,7 +274,7 @@ local function open_inventory(source, target)
return
end

local inventory_gui = screen.inventory_gui
local inventory_gui = screen[main_frame_name]
if inventory_gui then
close_player_inventory(source)
end
Expand All @@ -282,7 +285,7 @@ local function open_inventory(source, target)
type = 'frame',
caption = 'Inventory',
direction = 'vertical',
name = 'inventory_gui'
name = main_frame_name
}
)

Expand Down Expand Up @@ -383,22 +386,6 @@ local function on_gui_click(event)
end
end
end
local function gui_closed(event)
local player = game.get_player(event.player_index)
if not this.data[player.index] then
return
end

local type = event.gui_type

if type == defines.gui_type.custom then
local data = get_player_data(player)
if not data then
return
end
close_player_inventory(player)
end
end

local function on_pre_player_left_game(event)
local player = game.get_player(event.player_index)
Expand Down Expand Up @@ -466,11 +453,36 @@ commands.add_command(
end
)

function Public.show_inventory(player, target_player)
if not player or not player.valid then
return false
end
if not target_player or not target_player.valid then
return false
end

local valid, opened = player_opened(player)
if valid then
if target_player.index == opened then
player.print('You are already viewing this players inventory.', Color.warning)
return false
end
end

if validate_player(target_player) then
open_inventory(player, target_player)
return true
else
player.print('[Inventory] Please type a name of a player who is connected.', Color.warning)
return false
end
end

function Public.get_active_frame(player)
if not player.gui.screen.inventory_gui then
if not player.gui.screen[main_frame_name] then
return false
end
return player.gui.screen.inventory_gui.tabbed_pane.tabs[player.gui.screen.inventory_gui.tabbed_pane.selected_tab_index].content
return player.gui.screen[main_frame_name].tabbed_pane.tabs[player.gui.screen[main_frame_name].tabbed_pane.selected_tab_index].content
end

function Public.get(key)
Expand All @@ -487,13 +499,26 @@ function Public.module_disabled(state)
this.module_disabled = state or false
end

Gui.on_custom_close(
main_frame_name,
function(event)
local player = game.get_player(event.player_index)
if not this.data[player.index] then
return
end

close_player_inventory(player)
end
)

Event.add(defines.events.on_player_main_inventory_changed, update_gui)
Event.add(defines.events.on_player_gun_inventory_changed, update_gui)
Event.add(defines.events.on_player_ammo_inventory_changed, update_gui)
Event.add(defines.events.on_player_armor_inventory_changed, update_gui)
Event.add(defines.events.on_player_trash_inventory_changed, update_gui)
Event.add(defines.events.on_gui_closed, gui_closed)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game)

Public.close_player_inventory = close_player_inventory

return Public
20 changes: 18 additions & 2 deletions utils/commands/where.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ local function create_mini_camera_gui(player, target, zoom, render, tooltip)
end
local player_data

if validate_player(target) then
if validate_player(target) or (target and target.valid and player.admin) then
player_data = create_player_data(player)
player_data.target = target
else
Expand All @@ -107,6 +107,8 @@ local function create_mini_camera_gui(player, target, zoom, render, tooltip)
frame = player.gui.screen.add({type = 'frame', name = locate_player_frame_name, caption = target.name})
end

player.opened = frame

frame.force_auto_center()

local surface = tonumber(target.surface.index)
Expand Down Expand Up @@ -219,14 +221,28 @@ Gui.on_click(
end
)

Gui.on_custom_close(
locate_player_frame_name,
function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Where Locate Player')
if is_spamming then
return
end
remove_camera_frame(event.player)
end
)

Gui.on_click(
player_frame_name,
function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Where Player Frame')
if is_spamming then
return
end
remove_camera_frame(event.player)
local type = event.gui_type
if type == defines.gui_type.custom then
remove_camera_frame(event.player)
end
end
)

Expand Down
Loading

0 comments on commit 1169ef9

Please sign in to comment.