Skip to content

Commit

Permalink
v1.2.3.0 filter contract types
Browse files Browse the repository at this point in the history
contracts list can now be filtered
  • Loading branch information
Mmtrx committed Apr 4, 2022
1 parent 7630d8d commit 77b33c8
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 90 deletions.
106 changes: 86 additions & 20 deletions betterContracts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
-- v1.2.1.0 09.02.2022 support for FS22_SupplyTransportContracts by GtX
-- v1.2.2.0 30.03.2022 recognize conflict FS22_Contracts_Plus, adjust harvest keep formulas to FS22 1.3.1
-- details for transport missions
-- v1.2.3.0 04.04.2022 filter contracts per jobtype
--=======================================================================================================
InitRoyalUtility(Utils.getFilename("lib/utility/", g_currentModDirectory))
InitRoyalMod(Utils.getFilename("lib/rmod/", g_currentModDirectory))
Expand Down Expand Up @@ -85,7 +86,7 @@ function BetterContracts:initialize()
self.SPEEDLIMS = {15, 12, 15, 15, 0, 10, 12, 20}
self.WORKWIDTH = {42, 24, 6, 6, 0, 9, 4.9, 9}
--[[ contract types:
1 mow/ bale
1 mow_bale
2 plow
3 cultivate
4 sow
Expand All @@ -96,23 +97,25 @@ function BetterContracts:initialize()
9 transport
10 supplyTransport (Mod)
]]
self.typeToCat = {4, 3, 3, 2, 1, 3, 2, 2, 5, 6} -- mission.type to self category: harvest, spread, simple, mow, transport
self.harvest = {} -- harvest missions 1
self.spread = {} -- sow, spray, fertilize 2
self.simple = {} -- plow, cultivate, weed 3
self.baling = {} -- mow/ bale 4
self.transp = {} -- transport 5
self.supply = {} -- supplyTransport mod 6
-- mission.type to BC category: harvest, spread, simple, mow, transp, supply
self.typeToCat = {4, 3, 3, 2, 1, 3, 2, 2, 5, 6}
self.harvest = {} -- harvest missions 1
self.spread = {} -- sow, spray, fertilize 2
self.simple = {} -- plow, cultivate, weed 3
self.mow_bale = {} -- mow/ bale 4
self.transp = {} -- transport 5
self.supply = {} -- supplyTransport mod 6
self.IdToCont = {} -- to find a contract from its mission id
self.fieldToMission = {} -- to find a contract from its field number
self.catHarvest = "BEETHARVESTING BEETVEHICLES CORNHEADERS COTTONVEHICLES CUTTERS POTATOHARVESTING POTATOVEHICLES SUGARCANEHARVESTING SUGARCANEVEHICLES"
self.catSpread = "fertilizerspreaders seeders planters sprayers sprayervehicles slurrytanks manurespreaders"
self.catSimple = "CULTIVATORS DISCHARROWS PLOWS POWERHARROWS SUBSOILERS WEEDERS"
self.isOn = false
self.numCont = 0 -- # of contracts in our tables
self.my = {} -- will hold my gui element adresses
self.sort = 0 -- sorted status: 1 cat, 2 prof, 3 permin
self.lastSort = 0 -- last sorted status
self.numCont = 0 -- # of contracts in our tables
self.numHidden = 0 -- # of hidden (filtered) contracts
self.my = {} -- will hold my gui element adresses
self.sort = 0 -- sorted status: 1 cat, 2 prof, 3 permin
self.lastSort = 0 -- last sorted status
self.buttons = {
{"sortcat", g_i18n:getText("SC_sortCat")}, -- {button id, help text}
{"sortprof", g_i18n:getText("SC_sortProf")},
Expand Down Expand Up @@ -145,7 +148,7 @@ function BetterContracts:initialize()
InGameMenuContractsFrame.onFrameClose = Utils.appendedFunction(InGameMenuContractsFrame.onFrameClose, onFrameClose)
InGameMenuContractsFrame.updateFarmersBox = Utils.appendedFunction(InGameMenuContractsFrame.updateFarmersBox, updateFarmersBox)
InGameMenuContractsFrame.populateCellForItemInSection = Utils.appendedFunction(InGameMenuContractsFrame.populateCellForItemInSection, populateCell)
InGameMenuContractsFrame.updateList = Utils.prependedFunction(InGameMenuContractsFrame.updateList, updateList)
InGameMenuContractsFrame.updateList = Utils.overwrittenFunction(InGameMenuContractsFrame.updateList, updateList)
InGameMenuContractsFrame.sortList = Utils.overwrittenFunction(InGameMenuContractsFrame.sortList, sortList)
-- to allow multiple missions:
MissionManager.hasFarmReachedMissionLimit =
Expand Down Expand Up @@ -242,6 +245,52 @@ function BetterContracts:onPostLoadMap(mapNode, mapFile)
for _, name in pairs(SC.CONTROLS) do
self.my[name] = self.frCon.farmerBox:getDescendantById(name)
end

-- setup fieldjob types:
local fjobs = {
mow_bale = g_i18n:getText("fieldJob_jobType_baling"),
cultivate = g_i18n:getText("fieldJob_jobType_cultivating"),
fertilize = g_i18n:getText("fieldJob_jobType_fertilizing"),
harvest = g_i18n:getText("fieldJob_jobType_harvesting" ),
plow = g_i18n:getText("fieldJob_jobType_plowing"),
sow = g_i18n:getText("fieldJob_jobType_sowing"),
spray = g_i18n:getText("fieldJob_jobType_spraying"),
weed = g_i18n:getText("fieldJob_jobType_weeding"),
}
self.fieldjobs = {}
for i = 1, 8 do
local type = g_missionManager.missionTypes[i]
table.insert(self.fieldjobs, {type.typeId, type.name, fjobs[type.name]})
end
table.sort(self.fieldjobs, function(a,b)
return a[3] < b[3]
end)
self.fieldjobs[9] = {9,"transport", g_i18n:getText("bc_other")}
-- initial state: show all types
self.filterState = {
mow_bale = true,
cultivate = true,
fertilize = true,
harvest = true,
plow = true,
sow = true,
spray = true,
weed = true,
transport = true,
supplyTransport = true
}
-- set controls for filterbox:
self.my.filterlayout = self.frCon.contractsContainer:getDescendantById("filterlayout")
self.my.hidden = self.frCon.contractsContainer:getDescendantById("hidden")
for i, name in ipairs({"fb1","fb2","fb3",
"fb4","fb5","fb6","fb7","fb8","fb9"}) do
self.my[name] = self.frCon.contractsContainer:getDescendantById(name)
local button = self.my[name]
button.onClickCallback = onClickFilterButton
button.pressed = true
-- set button text
button.elements[1]:setText(self.fieldjobs[i][3])
end
-- set callbacks for our 3 sort buttons
for _, name in ipairs({"sortcat", "sortprof", "sortpmin"}) do
self.my[name].onClickCallback = onClickSortButton
Expand All @@ -250,9 +299,9 @@ function BetterContracts:onPostLoadMap(mapNode, mapFile)
self.my[name].onFocusCallback = onHighSortButton
self.my[name].onLeaveCallback = onRemoveSortButton
end
-- set static texts: "SORT"
self.my.sort:setText(g_i18n:getText("SC_sort"))

self.my.filterlayout:setVisible(true)
self.my.hidden:setVisible(false)
self.my.npcbox:setVisible(false)
self.my.sortbox:setVisible(false)
self.initialized = true
Expand All @@ -277,13 +326,14 @@ function BetterContracts:loadGUI(canLoad, guiPath)
else
canLoad = false
end
local xmlFile, layout
-- load "SCGui.xml"
fname = guiPath .. "SCGui.xml"
if canLoad and fileExists(fname) then
local xmlFile = loadXMLFile("Temp", fname)
xmlFile = loadXMLFile("Temp", fname)
local fbox = self.frCon.farmerBox
g_gui:loadGuiRec(xmlFile, "GUI", fbox, self.frCon)
local layout = fbox:getDescendantById("layout")
layout = fbox:getDescendantById("layout")
layout:invalidateLayout(true) -- adjust sort buttons
fbox:applyScreenAlignment()
fbox:updateAbsolutePosition()
Expand All @@ -293,12 +343,28 @@ function BetterContracts:loadGUI(canLoad, guiPath)
canLoad = false
Logging.error("[GuiLoader %s] Required file '%s' could not be found!", self.name, fname)
end
-- load "filterGui.xml"
fname = guiPath .. "filterGui.xml"
if canLoad and fileExists(fname) then
xmlFile = loadXMLFile("Temp", fname)
local cont = self.frCon.contractsContainer
g_gui:loadGuiRec(xmlFile, "GUI", cont, self.frCon)
layout = cont:getDescendantById("filterlayout")
cont:applyScreenAlignment()
cont:updateAbsolutePosition()
layout:invalidateLayout(true) -- adjust filter buttons
delete(xmlFile)
else
canLoad = false
Logging.error("[GuiLoader %s] Required file '%s' could not be found!", self.name, fname)
end
end
return canLoad
end
function BetterContracts:refresh()
-- refresh our contract tables. Called by onFrameOpen/updateList, and every 15 sec by self:onUpdate
self.harvest, self.spread, self.simple, self.baling, self.transp = {}, {}, {}, {}, {}
self.harvest, self.spread, self.simple, self.mow_bale, self.transp, self.supply =
{}, {}, {}, {}, {}, {}
self.IdToCont, self.fieldToMission = {}, {}
local list = g_missionManager:getMissionsList(g_currentMission:getFarmId())
local res = {}
Expand Down Expand Up @@ -409,7 +475,7 @@ function BetterContracts:addMission(m)
permin = profit / dura / 3 * 60,
reward = rew
}
table.insert(self.baling, cont)
table.insert(self.mow_bale, cont)
elseif cat == SC.SUPPLY then
cont = {
miss = m,
Expand Down Expand Up @@ -469,4 +535,4 @@ function abstractMissionNew(isServer, superf, isClient, customMt )
self.mission = g_currentMission
-- Fix for error in AbstractMission 'self.mission' still missing in Version 1.2.0.2
return self
end
end
43 changes: 43 additions & 0 deletions gui/filterGui.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--=====================================================================================================
BetterContracts GUI additions
Purpose: Enhance ingame contracts menu with filterbox
Author: Mmtrx
Changelog:
v1.2.0.1 29.03.2022 initial beta
v1.2.3.0 04.04.2022 filter contracts per jobtype
======================================================================================================-->
<GUI name="bc_filterbox">
<!-- filter buttons -->
<GuiElement type="boxLayout" profile="myFilterOptionPage" id="filterlayout" size="1186px 46px" position="212px 410px" debugEnabled="false">
<GuiElement type="button" profile="myFilterDynamicButton" id="fb1" onClick="" >
<GuiElement type="text" profile="myFilterDynamicText" />
</GuiElement>
<GuiElement type="button" profile="myFilterDynamicButtonAlt" id="fb2" >
<GuiElement type="text" profile="myFilterDynamicText" />
</GuiElement>
<GuiElement type="button" profile="myFilterDynamicButton" id="fb3" >
<GuiElement type="text" profile="myFilterDynamicText" />
</GuiElement>
<GuiElement type="button" profile="myFilterDynamicButtonAlt" id="fb4" >
<GuiElement type="text" profile="myFilterDynamicText" />
</GuiElement>
<GuiElement type="button" profile="myFilterDynamicButton" id="fb5" >
<GuiElement type="text" profile="myFilterDynamicText" />
</GuiElement>
<GuiElement type="button" profile="myFilterDynamicButtonAlt" id="fb6" >
<GuiElement type="text" profile="myFilterDynamicText" />
</GuiElement>
<GuiElement type="button" profile="myFilterDynamicButton" id="fb7" >
<GuiElement type="text" profile="myFilterDynamicText" />
</GuiElement>
<GuiElement type="button" profile="myFilterDynamicButtonAlt" id="fb8" >
<GuiElement type="text" profile="myFilterDynamicText" />
</GuiElement>
<GuiElement type="button" profile="myFilterDynamicButton" id="fb9" >
<GuiElement type="text" profile="myFilterDynamicText" text="Other"/>
</GuiElement>
</GuiElement>
<!-- number hidden contracts (anchor middleLeft)-->
<GuiElement type="text" profile="myFilterDynamicTextInactive" id="hidden" size="140px 40px" position="0px -398px" anchors="0 0 0.5 0.5" textAlignment="left" />
</GUI>
Loading

0 comments on commit 77b33c8

Please sign in to comment.