1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/maps/pirates/gui/fuel.lua

194 lines
5.5 KiB
Lua
Raw Normal View History

-- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/danielmartin0/ComfyFactorio-Pirates.
2021-10-13 10:21:53 +02:00
local Memory = require 'maps.pirates.memory'
2022-03-19 23:20:55 +02:00
-- local Common = require 'maps.pirates.common'
-- local CoreData = require 'maps.pirates.coredata'
2021-10-13 10:21:53 +02:00
local Utils = require 'maps.pirates.utils_local'
2022-03-19 23:20:55 +02:00
-- local Math = require 'maps.pirates.math'
2021-10-13 10:21:53 +02:00
local Balance = require 'maps.pirates.balance'
2022-03-19 23:20:55 +02:00
-- local Surfaces = require 'maps.pirates.surfaces.surfaces'
2021-10-13 10:21:53 +02:00
local Roles = require 'maps.pirates.roles.roles'
local Crew = require 'maps.pirates.crew'
local Shop = require 'maps.pirates.shop.shop'
2022-03-19 23:20:55 +02:00
-- local Progression = require 'maps.pirates.progression'
-- local Structures = require 'maps.pirates.structures.structures'
local _inspect = require 'utils.inspect'.inspect
-- local Boats = require 'maps.pirates.structures.boats.boats'
2021-10-13 10:21:53 +02:00
local GuiCommon = require 'maps.pirates.gui.common'
local Public = {}
2022-02-24 21:39:03 +02:00
local window_name = 'fuel'
2021-10-13 10:21:53 +02:00
function Public.toggle_window(player)
2022-03-19 23:20:55 +02:00
local flow, flow2, flow3
2021-10-13 10:21:53 +02:00
2022-03-07 20:41:42 +02:00
local shop_data_1 = Shop.Captains.main_shop_data_1
local shop_data_2 = Shop.Captains.main_shop_data_2
2021-10-13 10:21:53 +02:00
if player.gui.screen[window_name .. '_piratewindow'] then player.gui.screen[window_name .. '_piratewindow'].destroy() return end
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
flow = GuiCommon.new_window(player, window_name)
2022-02-27 18:42:25 +02:00
flow.caption = 'Captain\'s Store'
2021-10-13 10:21:53 +02:00
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
flow2 = flow.add({
name = 'trades',
type = 'flow',
direction = 'vertical',
})
flow2.style.top_margin = 3
flow2.style.bottom_margin = 3
flow2.style.horizontal_align = 'center'
flow2.style.vertical_align = 'center'
for k, _ in pairs(shop_data_1) do
2022-03-19 23:20:55 +02:00
GuiCommon.flow_add_shop_item(flow2, k)
2021-10-13 10:21:53 +02:00
end
flow3 = flow2.add({
name = 'line_1',
type = 'line',
})
flow3.style.width = 100
for k, _ in pairs(shop_data_2) do
2022-03-19 23:20:55 +02:00
GuiCommon.flow_add_shop_item(flow2, k)
2021-10-13 10:21:53 +02:00
end
flow2 = GuiCommon.flow_add_close_button(flow, window_name .. '_piratebutton')
2022-03-19 23:20:55 +02:00
flow2.add({
2021-10-13 10:21:53 +02:00
name = 'tospend',
type = 'sprite-button',
2022-02-24 21:39:03 +02:00
sprite = 'item/coin',
2021-10-13 10:21:53 +02:00
index = 1,
enabled = false,
})
end
2022-03-13 03:44:32 +02:00
function Public.regular_update(player)
2022-03-19 23:20:55 +02:00
local flow
2022-03-13 03:44:32 +02:00
2022-03-19 23:20:55 +02:00
-- local memory = Memory.get_crew_memory()
2021-10-13 10:21:53 +02:00
2022-03-13 03:44:32 +02:00
if not player.gui.screen[window_name .. '_piratewindow'] then return end
flow = player.gui.screen[window_name .. '_piratewindow']
2021-10-13 10:21:53 +02:00
2022-03-13 03:44:32 +02:00
if Roles.player_privilege_level(player) >= Roles.privilege_levels.OFFICER then
flow.close_button_flow.hflow.tospend.visible = true
local inv = player.get_inventory(defines.inventory.character_main)
if inv and inv.valid then
local coin_amount = inv.get_item_count('coin') or 0
2021-10-13 10:21:53 +02:00
2022-03-13 03:44:32 +02:00
flow.close_button_flow.hflow.tospend.number = coin_amount
flow.close_button_flow.hflow.tospend.tooltip = string.format("You're holding " .. Utils.bignumber_abbrevform2(coin_amount) .. " doubloons.")
end
else
flow.close_button_flow.hflow.tospend.visible = false
end
end
function Public.full_update(player)
2022-03-20 13:41:23 +02:00
if Public.regular_update then Public.regular_update(player) end
2022-03-19 23:20:55 +02:00
local flow
2021-10-13 10:21:53 +02:00
2022-03-13 20:19:59 +02:00
2021-10-13 10:21:53 +02:00
local memory = Memory.get_crew_memory()
2022-03-07 20:41:42 +02:00
local shop_data = Utils.nonrepeating_join_dict(Shop.Captains.main_shop_data_1, Shop.Captains.main_shop_data_2)
local shop_data_1 = Shop.Captains.main_shop_data_1
local shop_data_2 = Shop.Captains.main_shop_data_2
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
local availability_data = memory.mainshop_availability_bools
if not player.gui.screen[window_name .. '_piratewindow'] then return end
flow = player.gui.screen[window_name .. '_piratewindow']
--*** WHAT TO SHOW ***--
2022-02-24 21:39:03 +02:00
-- if memory.stored_fuel then
-- flow.close_button_flow.hflow.tospend.number = memory.stored_fuel
-- flow.close_button_flow.hflow.tospend.tooltip = string.format('The crew has %01d stored coal.', memory.stored_fuel)
-- else
-- flow.close_button_flow.hflow.tospend.number = 0
-- flow.close_button_flow.hflow.tospend.tooltip = string.format('The crew has %01d stored coal.', 0)
-- end
2021-10-13 10:21:53 +02:00
if memory.crewstatus == Crew.enum.ADVENTURING then
flow.trades.visible = true
else
flow.trades.visible = false
end
local anything_in_shop_1 = false
for k, _ in pairs(shop_data_1) do
if availability_data and availability_data[k] == true then
flow.trades[k].visible = true
anything_in_shop_1 = true
2022-02-27 01:33:19 +02:00
if Roles.player_privilege_level(player) >= Roles.privilege_levels.OFFICER then
2021-10-13 10:21:53 +02:00
flow.trades[k].buy_button.visible = true
else
flow.trades[k].buy_button.visible = false
end
else
flow.trades[k].visible = false
end
end
flow.trades.line_1.visible = anything_in_shop_1
for k, _ in pairs(shop_data_2) do
if availability_data and availability_data[k] == true then
flow.trades[k].visible = true
2022-02-27 01:33:19 +02:00
if Roles.player_privilege_level(player) >= Roles.privilege_levels.OFFICER then
2021-10-13 10:21:53 +02:00
flow.trades[k].buy_button.visible = true
else
flow.trades[k].buy_button.visible = false
end
else
flow.trades[k].visible = false
end
end
--*** UPDATE CONTENT ***--
local multiplier = Balance.main_shop_cost_multiplier()
for k, v in pairs(shop_data) do
for k2, v2 in pairs(v.base_cost) do
if v2 == false then
flow.trades[k]['cost_' .. k2].number = nil
else
flow.trades[k]['cost_' .. k2].number = multiplier * v2
end
end
end
end
function Public.click(event)
local player = game.players[event.element.player_index]
local eventname = event.element.name
if not player.gui.screen[window_name .. '_piratewindow'] then return end
2022-03-19 23:20:55 +02:00
-- local flow = player.gui.screen[window_name .. '_piratewindow']
2021-10-13 10:21:53 +02:00
2022-03-19 23:20:55 +02:00
-- local memory = Memory.get_crew_memory()
2021-10-13 10:21:53 +02:00
if eventname == 'buy_button' then
2022-03-08 00:00:14 +02:00
Shop.Captains.main_shop_try_purchase(player, event.element.parent.name)
2021-10-13 10:21:53 +02:00
end
end
return Public