Untitled diff

Créé Le diff n'expire jamais
79 suppressions
514 lignes
26 ajouts
461 lignes
package.path = package.path .. ";data/scripts/lib/?.lua"
package.path = package.path .. ";data/scripts/lib/?.lua"
require ("galaxy")
require ("galaxy")
require ("utility")
require ("utility")
require ("faction")
require ("faction")
require ("randomext")
require ("randomext")
require("stringutility")
require("stringutility")
local Dialog = require("dialogutility")
local Dialog = require("dialogutility")


-- Don't remove or alter the following comment, it tells the game the namespace this script lives in. If you remove it, the script will break.
-- Don't remove or alter the following comment, it tells the game the namespace this script lives in. If you remove it, the script will break.
-- namespace Scrapyard
-- namespace Scrapyard
Scrapyard = {}
Scrapyard = {}


-- server
-- server
local licenses = {}
local licenses = {}
local illegalActions = {}
local illegalActions = {}
local newsBroadcastCounter = 0
local newsBroadcastCounter = 0




-- client
-- client
local tabbedWindow = 0
local tabbedWindow = 0
local planDisplayer = 0
local planDisplayer = 0
local sellButton = 0
local sellButton = 0
local sellWarningLabel = 0
local sellWarningLabel = 0
local priceLabel1 = 0
local priceLabel1 = 0
local priceLabel2 = 0
local priceLabel2 = 0
local priceLabel3 = 0
local priceLabel3 = 0
local priceLabel4 = 0
local priceLabel4 = 0
local licenseDuration = 0
local licenseDuration = 0
local uiMoneyValue = 0
local uiMoneyValue = 0
local visible = false
local visible = false


-- if this function returns false, the script will not be listed in the interaction window on the client,
-- if this function returns false, the script will not be listed in the interaction window on the client,
-- even though its UI may be registered
-- even though its UI may be registered
function Scrapyard.interactionPossible(playerIndex, option)
function Scrapyard.interactionPossible(playerIndex, option)
return CheckFactionInteraction(playerIndex, -10000)
return CheckFactionInteraction(playerIndex, -10000)
end
end


function Scrapyard.restore(data)
function Scrapyard.restore(data)
-- clear earlier data
-- clear earlier data
licenses = data.licenses
licenses = data.licenses
illegalActions = data.illegalActions
illegalActions = data.illegalActions
end
end


function Scrapyard.secure()
function Scrapyard.secure()
-- save licenses
-- save licenses
local data = {}
local data = {}
data.licenses = licenses
data.licenses = licenses
data.illegalActions = illegalActions
data.illegalActions = illegalActions


return data
return data
end
end


-- this function gets called on creation of the entity the script is attached to, on client and server
-- this function gets called on creation of the entity the script is attached to, on client and server
function Scrapyard.initialize()
function Scrapyard.initialize()


if onServer() then
if onServer() then
Sector():registerCallback("onHullHit", "onHullHit")
Sector():registerCallback("onHullHit", "onHullHit")


local station = Entity()
local station = Entity()
if station.title == "" then
if station.title == "" then
station.title = "Scrapyard"%_t
station.title = "Scrapyard"%_t
end
end


end
end


if onClient() and EntityIcon().icon == "" then
if onClient() and EntityIcon().icon == "" then
EntityIcon().icon = "data/textures/icons/pixel/scrapyard_fat.png"
EntityIcon().icon = "data/textures/icons/pixel/scrapyard_fat.png"
InteractionText().text = Dialog.generateStationInteractionText(Entity(), random())
InteractionText().text = Dialog.generateStationInteractionText(Entity(), random())
end
end


end
end


-- this function gets called on creation of the entity the script is attached to, on client only
-- this function gets called on creation of the entity the script is attached to, on client only
-- AFTER initialize above
-- AFTER initialize above
-- create all required UI elements for the client side
-- create all required UI elements for the client side
function Scrapyard.initUI()
function Scrapyard.initUI()


local res = getResolution()
local res = getResolution()
local size = vec2(700, 650)
local size = vec2(700, 650)


local menu = ScriptUI()
local menu = ScriptUI()
local mainWindow = menu:createWindow(Rect(res * 0.5 - size * 0.5, res * 0.5 + size * 0.5))
local mainWindow = menu:createWindow(Rect(res * 0.5 - size * 0.5, res * 0.5 + size * 0.5))
menu:registerWindow(mainWindow, "Scrapyard"%_t)
menu:registerWindow(mainWindow, "Scrapyard"%_t)
mainWindow.caption = "Scrapyard"%_t
mainWindow.caption = "Scrapyard"%_t
mainWindow.showCloseButton = 1
mainWindow.showCloseButton = 1
mainWindow.moveable = 1
mainWindow.moveable = 1


-- create a tabbed window inside the main window
-- create a tabbed window inside the main window
tabbedWindow = mainWindow:createTabbedWindow(Rect(vec2(10, 10), size - 10))
tabbedWindow = mainWindow:createTabbedWindow(Rect(vec2(10, 10), size - 10))


-- create a "Sell" tab inside the tabbed window
-- create a "Sell" tab inside the tabbed window
local sellTab = tabbedWindow:createTab("Sell Ship"%_t, "", "Sell your ship to the scrapyard"%_t)
local sellTab = tabbedWindow:createTab("Sell Ship"%_t, "", "Sell your ship to the scrapyard"%_t)
size = sellTab.size
size = sellTab.size


planDisplayer = sellTab:createPlanDisplayer(Rect(0, 0, size.x - 20, size.y - 60))
planDisplayer = sellTab:createPlanDisplayer(Rect(0, 0, size.x - 20, size.y - 60))
planDisplayer.showStats = 0
planDisplayer.showStats = 0


sellButton = sellTab:createButton(Rect(0, size.y - 40, 150, size.y), "Sell Ship"%_t, "onSellButtonPressed")
sellButton = sellTab:createButton(Rect(0, size.y - 40, 150, size.y), "Sell Ship"%_t, "onSellButtonPressed")
sellWarningLabel = sellTab:createLabel(vec2(200, size.y - 30), "Warning! You will not get refunds for crews or turrets!"%_t, 15)
sellWarningLabel = sellTab:createLabel(vec2(200, size.y - 30), "Warning! You will not get refunds for crews or turrets!"%_t, 15)
sellWarningLabel.color = ColorRGB(1, 1, 0)
sellWarningLabel.color = ColorRGB(1, 1, 0)