Skip to content

Commit

Permalink
Ls-Modcompany#82 change bale system
Browse files Browse the repository at this point in the history
  • Loading branch information
kevink98 committed Feb 6, 2020
1 parent 5f64a6a commit c420458
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 53 deletions.
75 changes: 65 additions & 10 deletions gui/objects/GlobalMarket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function Gc_Gui_GlobalMarket:onOpen()
self.gui_btn_sellBuy:setVisible(false)
self.gui_btn_sellBuyText:setVisible(false)
self.gui_btn_outsource:setVisible(false)
self.gui_btn_outsourceText:setVisible(false)
self.gui_btn_outsourceBale1:setVisible(false)
self.gui_btn_outsourceBale1Text:setVisible(false)
self.gui_btn_outsourceBale2:setVisible(false)
self.gui_btn_outsourceBale2Text:setVisible(false)
end

function Gc_Gui_GlobalMarket:onClose()
Expand All @@ -62,15 +67,19 @@ end
function Gc_Gui_GlobalMarket:onCreate() end

function Gc_Gui_GlobalMarket:keyEvent(unicode, sym, modifier, isDown, eventUsed)
if sym == 120 and isDown then
if sym == 120 and isDown then
self:openTab(Gc_Gui_GlobalMarket.tabs.STORAGE)
elseif sym == 99 and isDown then
elseif sym == 99 and isDown then
self:openTab(Gc_Gui_GlobalMarket.tabs.BUY)
elseif sym == 13 then
elseif sym == 13 and self.gui_btn_sellBuy:getVisible() then
self:onClickSellBuy()
elseif sym == 32 then
elseif sym == 32 and self.gui_btn_outsource:getVisible() then
self:onClickOutsource()
end
elseif sym == 113 and self.gui_btn_outsourceBale1:getVisible() then
self:onClickOutsourceBale1()
elseif sym == 101 and self.gui_btn_outsourceBale2:getVisible() then
self:onClickOutsourceBale2()
end
end

function Gc_Gui_GlobalMarket:setCloseCallback(target, func)
Expand All @@ -88,14 +97,42 @@ end
function Gc_Gui_GlobalMarket:onClickStorageItem(element)
self.currentSelectedItem = element
self.gui_btn_sellBuy:setVisible(true)
self.gui_btn_sellBuyText:setVisible(true)
self.gui_btn_outsource:setVisible(self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE and self:getCanOutsource())
self.gui_btn_sellBuyText:setVisible(true)

local havePallet, haveBale1, haveBale2 = self:getCanOutsource()
self.gui_btn_outsource:setVisible(self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE and havePallet)
self.gui_btn_outsourceText:setVisible(self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE and havePallet)
self.gui_btn_outsourceBale1:setVisible(self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE and haveBale1)
self.gui_btn_outsourceBale1Text:setVisible(self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE and haveBale1)
self.gui_btn_outsourceBale2:setVisible(self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE and haveBale2)
self.gui_btn_outsourceBale2Text:setVisible(self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE and haveBale2)
end

function Gc_Gui_GlobalMarket:getCanOutsource(item)
local havePallet = g_fillTypeManager:getFillTypeByIndex(self.currentSelectedItem.fillTypeIndex).palletFilename ~= nil
local haveBale = g_company.globalMarket.baleToFilename[string.upper(g_fillTypeManager:getFillTypeNameByIndex(self.currentSelectedItem.fillTypeIndex))] ~= nil
return havePallet or haveBale
local havePallet = false
local haveBale1 = false
local haveBale2 = false
if self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE then
havePallet = g_company.globalMarket:getPalletFilenameFromFillTypeIndex(self.currentSelectedItem.fillTypeIndex) ~= nil
local balePaths = g_company.globalMarket.baleToFilename[string.upper(g_fillTypeManager:getFillTypeNameByIndex(self.currentSelectedItem.fillTypeIndex))]
haveBale = balePaths ~= nil

if haveBale then
if balePaths[1] ~= nil then
local capacityPerPallet1, numBales1 = g_company.globalMarket:getCapacityByStoreXml(balePaths[1], false)
haveBale1 = self.currentSelectedItem.fillTypeLevel >= capacityPerPallet1
else
haveBale1 = false
end
if balePaths[2] ~= nil then
local capacityPerPallet2, numBales2 = g_company.globalMarket:getCapacityByStoreXml(balePaths[2], false)
haveBale2 = self.currentSelectedItem.fillTypeLevel >= capacityPerPallet2
else
haveBale2 = false
end
end
end
return havePallet, haveBale1, haveBale2
end

function Gc_Gui_GlobalMarket:onClickTabStorage(element)
Expand Down Expand Up @@ -187,6 +224,24 @@ function Gc_Gui_GlobalMarket:onClickOutsource()
self:loadTableSell()
end

function Gc_Gui_GlobalMarket:onClickOutsourceBale1()
g_company.gui:setCanExit("gc_globalMarketLevelDialog", false)
if self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE then
g_company.gui:closeActiveGui("gc_globalMarketLevelDialog", false, self.market, self.currentSelectedItem.fillTypeLevel, self.currentSelectedItem.fillTypeIndex, true, true, true)
end
self:loadTableBuy()
self:loadTableSell()
end

function Gc_Gui_GlobalMarket:onClickOutsourceBale2()
g_company.gui:setCanExit("gc_globalMarketLevelDialog", false)
if self.activeTab == Gc_Gui_GlobalMarket.tabs.STORAGE then
g_company.gui:closeActiveGui("gc_globalMarketLevelDialog", false, self.market, self.currentSelectedItem.fillTypeLevel, self.currentSelectedItem.fillTypeIndex, true, true, false)
end
self:loadTableBuy()
self:loadTableSell()
end

function Gc_Gui_GlobalMarket:onClickSynch(button)
self.gui_table_buy:removeElements()
self.manualSychRun = true
Expand Down
9 changes: 8 additions & 1 deletion gui/objects/GlobalMarket.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@
<GuiElement type="text" template="gcBaseGuiButtonText" text="$l10n_GC_globalMarket_btn_storageScreen" />
<GuiElement type="button" position="50px 0px" template="gcBaseGuiButtonNext" inputAction="MENU_EXTRA_2" onClick="onClickBuyScreen" />
<GuiElement type="text" template="gcBaseGuiButtonText" text="$l10n_GC_globalMarket_btn_buyScreen" />

<GuiElement type="button" position="80px 0px" template="gcBaseGuiButtonNext" id="gui_btn_outsource" inputAction="MENU_ACTIVATE" onClick="onClickOutsource" />
<GuiElement type="text" template="gcBaseGuiButtonText" id="gui_btn_outsourceText" text="$l10n_GC_globalMarket_btn_outsource" />
<GuiElement type="text" template="gcBaseGuiButtonText" id="gui_btn_outsourceText" text="$l10n_GC_globalMarket_btn_outsource" />

<GuiElement type="button" position="80px 0px" template="gcBaseGuiButtonNext" id="gui_btn_outsourceBale1" inputAction="MENU_PAGE_PREV" onClick="onClickOutsourceBale1" />
<GuiElement type="text" template="gcBaseGuiButtonText" id="gui_btn_outsourceBale1Text" text="$l10n_GC_globalMarket_btn_outsourceBale1" />
<GuiElement type="button" position="80px 0px" template="gcBaseGuiButtonNext" id="gui_btn_outsourceBale2" inputAction="MENU_PAGE_NEXT" onClick="onClickOutsourceBale2" />
<GuiElement type="text" template="gcBaseGuiButtonText" id="gui_btn_outsourceBale2Text" text="$l10n_GC_globalMarket_btn_outsourceBale2" />

<GuiElement type="button" position="80px 0px" template="gcBaseGuiButtonNext" id="gui_btn_sellBuy" inputAction="MENU_ACCEPT" onClick="onClickSellBuy" />
<GuiElement type="text" template="gcBaseGuiButtonText" id="gui_btn_sellBuyText" />
</GuiElement>
Expand Down
22 changes: 17 additions & 5 deletions gui/objects/GlobalMarketLevelDialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,38 @@ function Gc_Gui_GlobalMarketLevelDialog:setCloseCallback(target, func)
self.closeCallback = {target=target, func=func}
end

function Gc_Gui_GlobalMarketLevelDialog:setData(market, fillLevel, fillTypeIndex, sell, isOutsource)
function Gc_Gui_GlobalMarketLevelDialog:setData(market, fillLevel, fillTypeIndex, sell, isOutsource, asRoundBale)
self.market = market
self.fillTypeIndex = fillTypeIndex
self.sell = sell
self.maximum = fillLevel
self.isOutsource = isOutsource
self.asRoundBale = asRoundBale

local isPallet = true
if isOutsource then
local path = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex).palletFilename
local isPallet = true
local path = g_company.globalMarket:getPalletFilenameFromFillTypeIndex(fillTypeIndex)
if path == nil then
path = g_company.globalMarket.baleToFilename[string.upper(g_fillTypeManager:getFillTypeNameByIndex(fillTypeIndex))]
if asRoundBale then
path = path[1]
else
path = path[2]
end
isPallet = false
end
self.capacityPerPallet, self.numBales = g_company.globalMarket:getCapacityByStoreXml(path, isPallet)
self.maximum = math.ceil(fillLevel / self.capacityPerPallet)
if isPallet then
self.maximum = math.ceil(fillLevel / self.capacityPerPallet)
else
self.maximum = math.floor(fillLevel / self.capacityPerPallet)
end

if not isPallet then
if fillLevel < self.capacityPerPallet then
self.maximum = 0
self:onClickClose();
return
--elseif self.maximum > self.numBales then
-- self.maximum = self.numBales
end
Expand Down Expand Up @@ -204,7 +216,7 @@ end

function Gc_Gui_GlobalMarketLevelDialog:onClickSellBuy()
if self.isOutsource then
self.market:spawnPallets(self.fillTypeIndex, self:getCurrentAmount(), g_currentMission:getFarmId(), self.capacityPerPallet, self.numBales)
self.market:spawnPallets(self.fillTypeIndex, self:getCurrentAmount(), g_currentMission:getFarmId(), self.capacityPerPallet, self.numBales, self.asRoundBale)
g_company.gui:closeActiveGui("gc_globalMarket", false, self.market)
else
self.market:sellBuyOnMarket(self.fillTypeIndex, self:getCurrentAmount(), g_currentMission:getFarmId(), self.sell)
Expand Down
7 changes: 6 additions & 1 deletion languages/l10n_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,21 @@ Kosten: %s"/>

<e k="GC_globalMarket_tbl_header_filltype" v="Fruchttyp"/>
<e k="GC_globalMarket_tbl_header_level" v="Liter"/>
<e k="GC_globalMarket_tbl_header_pallets" v="Palette"/>
<e k="GC_globalMarket_tbl_header_pallets" v="Paletten"/>
<e k="GC_globalMarket_tbl_header_bales" v="Ballen"/>
<e k="GC_globalMarket_tbl_header_price" v="aktueller Preis"/>
<e k="GC_globalMarket_tbl_header_price2" v="aktueller Preis / 1000 Liter"/>
<e k="GC_globalMarket_btn_outsource" v="Auslagern"/>
<e k="GC_globalMarket_btn_outsourceBale1" v="Rundballen"/>
<e k="GC_globalMarket_btn_outsourceBale2" v="Quaderballen"/>
<e k="GC_globalMarket_btn_sell" v="Verkaufen"/>
<e k="GC_globalMarket_btn_buy" v="Kaufen "/>
<e k="GC_globalMarket_externIsOffline" v="Starte die benötigte externe Software, damit du Ware ankaufen kannst oder deine abgegebene Ware verkaufen kannst."/>


<e k="GC_globalMarket_storeItem_squareBaleGrass" v="Quaderballen Gras"/>
<e k="GC_globalMarket_storeItem_roundBaleGrass" v="Rundballen Gras"/>
<e k="GC_globalMarket_storeItem_cotton" v="Baumwolle"/>



Expand Down
6 changes: 6 additions & 0 deletions modDesc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,10 @@ Changelog 1.1.0.0.0 :
<binding device="KB_MOUSE_DEFAULT" input="KEY_lctrl KEY_t" axisComponent="+" neutralInput="0" index="1"/>
</actionBinding>
</inputBinding>

<storeItems>
<storeItem xmlFilename="shop/buyableBales_grassRound.xml" />
<storeItem xmlFilename="shop/buyableBales_grass.xml" />
<storeItem xmlFilename="shop/buyableBales_cotton.xml" />
</storeItems>
</modDesc>
61 changes: 48 additions & 13 deletions objects/GC_GlobalMarket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ GC_GlobalMarket.fillTypeTypes.PALLET = 3
GC_GlobalMarket.fillTypeTypes.BALE = 4
GC_GlobalMarket.fillTypeTypes.LIQUID = 5
GC_GlobalMarket.fillTypeTypes.WOOD = 6
GC_GlobalMarket.fillTypeTypes.CONVEYORANDBALE = 7

GC_GlobalMarket.priceTrends = {}
GC_GlobalMarket.priceTrends.DOWN = 1
Expand All @@ -41,13 +42,28 @@ GC_GlobalMarket.ownFillTypes = {}
GC_GlobalMarket.ownFillTypes.WOOD = -10

GC_GlobalMarket.baleToFilename = {}
--GC_GlobalMarket.baleToFilename["ROUNDBALE_GRASS"] = "$data/objects/buyableBales"
GC_GlobalMarket.baleToFilename["ROUNDBALE_DRYGRASS"] = "data/objects/buyableBales/buyableBales_dryGrassRound.xml"
GC_GlobalMarket.baleToFilename["ROUNDBALE_WHEAT"] = "data/objects/buyableBales/buyableBales_strawRound.xml"
GC_GlobalMarket.baleToFilename["ROUNDBALE_BARLEY"] = "data/objects/buyableBales/buyableBales_strawRound.xml"

GC_GlobalMarket.baleToFilename["SQUAREBALE_WHEAT"] = "data/objects/buyableBales/buyableBales_straw.xml"
GC_GlobalMarket.baleToFilename["SQUAREBALE_BARLEY"] = "data/objects/buyableBales/buyableBales_straw.xml"
GC_GlobalMarket.baleToFilename["GRASS_WINDROW"] = {g_company.dir .. "shop/buyableBales_grassRound.xml", g_company.dir .. "shop/buyableBales_grass.xml" }
GC_GlobalMarket.baleToFilename["DRYGRASS_WINDROW"] = {"data/objects/buyableBales/buyableBales_dryGrassRound.xml", "data/objects/buyableBales/buyableBales_dryGrass.xml"}
GC_GlobalMarket.baleToFilename["STRAW"] = {"data/objects/buyableBales/buyableBales_strawRound.xml", "data/objects/buyableBales/buyableBales_straw.xml"}
GC_GlobalMarket.baleToFilename["SILAGE"] = {"data/objects/buyableBales/buyableBales_silage.xml"}
GC_GlobalMarket.baleToFilename["COTTON"] = {nil, g_company.dir .. "shop/buyableBales_cotton.xml"}


GC_GlobalMarket.fillTypeToFilename = {}
GC_GlobalMarket.fillTypeToFilename["TREESAPLINGS"] = "data/objects/pallets/treeSaplingPallet/treeSaplingPallet.xml"
GC_GlobalMarket.fillTypeToFilename["WOOL"] = "data/objects/pallets/woolPallet/woolPallet.xml"
GC_GlobalMarket.fillTypeToFilename["EGG"] = "data/objects/pallets/eggBox/eggBox.xml"
GC_GlobalMarket.fillTypeToFilename["POPLAR"] = "data/objects/pallets/palletPoplar/palletPoplar.xml"

GC_GlobalMarket.fillTypeMapping = {}
GC_GlobalMarket.fillTypeMapping["GRASS"] = "GRASS_WINDROW"
GC_GlobalMarket.fillTypeMapping["DRYGRASS"] = "DRYGRASS_WINDROW"
GC_GlobalMarket.fillTypeMapping["ROUNDBALE_GRASS"] = "GRASS_WINDROW"
GC_GlobalMarket.fillTypeMapping["ROUNDBALE_DRYGRASS"] = "DRYGRASS_WINDROW"
GC_GlobalMarket.fillTypeMapping["ROUNDBALE_WHEAT"] = "STRAW"
GC_GlobalMarket.fillTypeMapping["ROUNDBALE_BARLEY"] = "STRAW"
GC_GlobalMarket.fillTypeMapping["SQUAREBALE_WHEAT"] = "STRAW"
GC_GlobalMarket.fillTypeMapping["SQUAREBALE_BARLEY"] = "STRAW"

function GC_GlobalMarket:new()
local self = setmetatable({}, GC_GlobalMarket._mt)
Expand Down Expand Up @@ -209,9 +225,11 @@ function GC_GlobalMarket:getProvidedFillTypes(fillTyp)

local fillTypes = {}
for typ, tab in pairs(self.fillTypes) do
if typ == fillTyp then
for index, _ in pairs(tab) do
fillTypes[index] = true
for _,typ2 in pairs(fillTyp) do
if typ == typ2 then
for index, _ in pairs(tab) do
fillTypes[index] = true
end
end
end
end
Expand All @@ -222,8 +240,25 @@ function GC_GlobalMarket:getFillTypesByType(typ)
return self.fillTypes[typ]
end

function GC_GlobalMarket:getIsFillTypeFromType(fillTypeIndex, typ)
return self.fillTypes[typ] ~= nil and self.fillTypes[typ][fillTypeIndex] ~= nil
function GC_GlobalMarket:getIsFillTypeFromType(fillTypeIndex, types)
for _,typ in pairs(types) do
if self.fillTypes[typ] ~= nil and self.fillTypes[typ][fillTypeIndex] ~= nil then
return true
end
end
return false
end

function GC_GlobalMarket:getPalletFilenameFromFillTypeIndex(fillTypeIndex)
local path = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex).palletFilename
local name = string.upper(g_fillTypeManager:getFillTypeNameByIndex(fillTypeIndex))
if path == nil then
path = self.fillTypeToFilename[name]
end
if name == "COTTON" then
path = nil
end
return path
end

function GC_GlobalMarket:getPriceTrendByFillType(fillTypeIndex)
Expand Down Expand Up @@ -288,7 +323,7 @@ function GC_GlobalMarket:getCapacityByStoreXml(path, isPallet)
if self.storeXmlToCapacity[paths] ~= nil then
capacity = self.storeXmlToCapacity[paths]
else
local xmlFile = loadXMLFile("tempXml", path)
local xmlFile = loadXMLFile("tempXml", path)
if isPallet then
local key = "vehicle.fillUnit.fillUnitConfigurations.fillUnitConfiguration.fillUnits.fillUnit"
if hasXMLProperty(xmlFile, key) then
Expand Down
Loading

0 comments on commit c420458

Please sign in to comment.