Skip to content

Commit

Permalink
v1.2.7.5
Browse files Browse the repository at this point in the history
- display other farms active contracts (MP only)
- read userDefined missions from "BCuserDefined.xml" in modSettings dir
- update l10n: br, cz, ru
  • Loading branch information
Mmtrx committed Mar 2, 2023
1 parent aa4472d commit 05108a6
Show file tree
Hide file tree
Showing 18 changed files with 325 additions and 125 deletions.
138 changes: 71 additions & 67 deletions betterContracts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
-- Icon for roller missions. Don't show negative togos
-- v1.2.7.3 20.02.2023 double progress bar active contracts. Fix PnH BGA/ Maize+
-- v1.2.7.4 22.02.2023 increase range for "toDeliver". Add setting "toDeliverBale"
-- v1.2.7.5 26.02.2023 display other farms active contracts (MP only).
-- Read userDefined missions from "BCuserDefined.xml" in modSettings dir
--=======================================================================================================
SC = {
FERTILIZER = 1, -- prices index
Expand All @@ -62,15 +64,15 @@ SC = {
BALING = 4,
TRANSP = 5,
SUPPLY = 6,
OTHER = 7,
-- refresh MP:
ADMIN = 1,
FARMMANAGER = 2,
PLAYER = 3,
-- hardMode expire:
DAY = 1,
MONTH = 2,
-- Gui controls:
OTHER = 7,
-- refresh MP:
ADMIN = 1,
FARMMANAGER = 2,
PLAYER = 3,
-- hardMode expire:
DAY = 1,
MONTH = 2,
-- Gui farmerBox controls:
CONTROLS = {
npcbox = "npcbox",
sortbox = "sortbox",
Expand All @@ -95,7 +97,10 @@ SC = {
sortcat = "sortcat",
sortprof = "sortprof",
sortpmin = "sortpmin",
helpsort = "helpsort"
helpsort = "helpsort",
container = "container",
mTable = "mTable",
mToggle = "mToggle",
},
-- Gui contractBox controls:
CONTBOX = {
Expand Down Expand Up @@ -128,28 +133,30 @@ function catMissionTypes(self)
mission.type to BC category: harvest, spread, simple, mow, transp, supply
self.typeToCat = {4, 3, 3, 2, 1, 3, 2, 2, 5, 6}
]]
self.typeToCat = {}
local function addMapping(name, category)
local missionType = g_missionManager:getMissionType(name)
if missionType ~= nil then
self.typeToCat[missionType.typeId] = category
end
end
addMapping("mow_bale", SC.BALING)
addMapping("plow", SC.SIMPLE)
addMapping("cultivate", SC.SIMPLE)
addMapping("sow", SC.SPREAD)
addMapping("harvest", SC.HARVEST)
addMapping("weed", SC.SIMPLE)
addMapping("spray", SC.SPREAD)
addMapping("fertilize", SC.SPREAD)
addMapping("transport", SC.TRANSP)
addMapping("supplyTransport", SC.SUPPLY) -- mod by GtX
addMapping("deadwood", SC.OTHER) -- Platinum DLC mission by Giants
addMapping("treeTransport", SC.OTHER) -- Platinum DLC mission by Giants
addMapping("destructibleRocks", SC.OTHER) -- Platinum DLC mission by Giants
addMapping("roll", SC.SIMPLE) -- roller mission by tn4799
addMapping("lime", SC.SPREAD) -- lime mission by Mmtrx
self.typeToCat = {}
self.jobText = {}
local function addMapping(name, title, category)
local missionType = g_missionManager:getMissionType(name)
if missionType ~= nil then
self.typeToCat[missionType.typeId] = category
self.jobText[name] = g_i18n:getText(title)
end
end
addMapping("mow_bale", "fieldJob_jobType_baling", SC.BALING)
addMapping("plow","fieldJob_jobType_plowing", SC.SIMPLE)
addMapping("cultivate","fieldJob_jobType_cultivating", SC.SIMPLE)
addMapping("sow","fieldJob_jobType_sowing", SC.SPREAD)
addMapping("harvest","fieldJob_jobType_harvesting", SC.HARVEST)
addMapping("weed","fieldJob_jobType_weeding", SC.SIMPLE)
addMapping("spray","fieldJob_jobType_spraying", SC.SPREAD)
addMapping("fertilize","fieldJob_jobType_fertilizing", SC.SPREAD)
addMapping("transport","helpLine_Misc_Transport", SC.TRANSP)
addMapping("supplyTransport","ai_jobTitleDeliver", SC.SUPPLY) -- mod by GtX
addMapping("deadwood","deadwoodMission_title", SC.OTHER) -- Platinum DLC mission by Giants
addMapping("treeTransport","treeTransportMission_title", SC.OTHER) -- Platinum DLC mission by Giants
addMapping("destructibleRocks","destructibleRockMission_title", SC.OTHER) -- Platinum DLC mission by Giants
addMapping("roll","helpLine_ImproveYield_Rolling", SC.SIMPLE) -- roller mission by tn4799
addMapping("lime","helpLine_ImproveYield_Liming", SC.SPREAD) -- lime mission by Mmtrx
for _, missionType in pairs(g_missionManager.missionTypes) do
if self.typeToCat[missionType.typeId] == nil then
addMapping(missionType.name, SC.OTHER) -- default category for not registered mission types
Expand Down Expand Up @@ -281,36 +288,25 @@ function loadPrices(self)
return prices
end
function setupMissionFilter(self)
-- setup fieldjob types:
self.jobText = {
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"),
-- lime is g_missionManager.missionTypes[2] !
}
self.fieldjobs = {}
self.buttonNames = {}
self.otherTypes = {}
self.filterState = {}
for _, type in ipairs(g_missionManager.missionTypes) do
-- initial state: show all types
self.filterState[type.name] = true
-- setup button names
local name = self.jobText[type.name]
if name ~= nil then
table.insert(self.fieldjobs, {type.typeId, type.name, name})
if string.find("mow_balecultivatefertilizeharvestplowsowsprayweed",type.name) then
table.insert(self.buttonNames, {type.typeId, type.name, name})
else
table.insert(self.otherTypes,{type.typeId, type.name})
table.insert(self.otherTypes,{type.typeId, type.name, name})
end
end
table.sort(self.fieldjobs, function(a,b)
table.sort(self.buttonNames, function(a,b)
return a[3] < b[3]
end)
-- this is for all other mission types:
table.insert(self.fieldjobs,
table.insert(self.buttonNames,
{nil,"other", g_i18n:getText("bc_other")})

-- set controls for filterbox:
Expand All @@ -323,7 +319,7 @@ function setupMissionFilter(self)
button.onClickCallback = onClickFilterButton
button.pressed = true
-- set button text
button.elements[1]:setText(self.fieldjobs[i][3])
button.elements[1]:setText(self.buttonNames[i][3])
end
end
function initGui(self)
Expand Down Expand Up @@ -378,7 +374,7 @@ function initGui(self)

-- set controls for npcbox, sortbox and their elements:
for _, name in pairs(SC.CONTROLS) do
self.my[name] = self.frCon.farmerBox:getDescendantById(name)
self.my[name] = self.frCon.detailsBox:getDescendantById(name)
end
-- set controls for contractBox:
for _, name in pairs(SC.CONTBOX) do
Expand All @@ -394,12 +390,18 @@ function initGui(self)
end
setupMissionFilter(self)

-- init other farms mission table
self.my.mTable:initialize()
self.my.container:setVisible(false)
self.mapTableOn = false -- visibility of other farms mission table
self.my.mToggle.onClickCallback = onClickToggle
self.my.mToggle:setVisible(self.isMultiplayer)

self.my.filterlayout:setVisible(true)
self.my.hidden:setVisible(false)
self.my.npcbox:setVisible(false)
self.my.sortbox:setVisible(false)
end

function BetterContracts:initialize()
debugPrint("[%s] initialize(): %s", self.name,self.initialized)
if self.initialized ~= nil then return end -- run only once
Expand Down Expand Up @@ -447,7 +449,7 @@ function BetterContracts:initialize()
self.mow_bale = {} -- mow/ bale 4
self.transp = {} -- transport 5
self.supply = {} -- supplyTransport mod 6
self.other = {} -- deadwood, treeTrans 7
self.other = {} -- deadwood, treeTrans 7
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"
Expand Down Expand Up @@ -516,8 +518,8 @@ function BetterContracts:initialize()
Utility.appendedFunction(AbstractFieldMission, "onVehicleReset", onVehicleReset)

-- rename mission vehicle:
for name, typeDef in pairs(g_vehicleTypeManager.types) do
if typeDef ~= nil and not TableUtility.contains({"horse","pallet","locomotive"}, name) then
for name, typeDef in pairs(g_vehicleTypeManager.types) do
if typeDef ~= nil and not TableUtility.contains({"horse","pallet","locomotive"}, name) then
SpecializationUtil.registerOverwrittenFunction(typeDef, "getName", vehicleGetName)
end
end
Expand Down Expand Up @@ -577,8 +579,9 @@ function BetterContracts:onPostLoadMap(mapNode, mapFile)
if self.config.discountMode then txt = txt..", discountMode" end
debugPrint(txt)
end
addConsoleCommand("bcprint","Print detail stats for all available missions.","consoleCommandPrint",self)
addConsoleCommand("bcMissions","Print stats for other clients active missions.","bcMissions",self)
if self.config.debug then
addConsoleCommand("bcprint", "Print detail stats for all available missions.", "consoleCommandPrint", self)
addConsoleCommand("bcFieldGenerateMission", "Force generating a new mission for given field", "consoleGenerateFieldMission", g_missionManager)
addConsoleCommand("gsMissionLoadAllVehicles", "Loading and unloading all field mission vehicles", "consoleLoadAllFieldMissionVehicles", g_missionManager)
addConsoleCommand("gsMissionHarvestField", "Harvest a field and print the liters", "consoleHarvestField", g_missionManager)
Expand All @@ -591,6 +594,7 @@ function BetterContracts:onPostLoadMap(mapNode, mapFile)
BetterContracts:updateGenerationSettings()

-- initialize constants depending on game manager instances
self.isMultiplayer = g_currentMission.missionDynamicInfo.isMultiplayer
self.ft = g_fillTypeManager.fillTypes
self.prices = loadPrices()
self.sprUse = {
Expand Down Expand Up @@ -859,18 +863,18 @@ function BetterContracts:addMission(m)
reward = rew
}
table.insert(self.transp, cont)
elseif cat == SC.OTHER then
cont = {
miss = m,
worktime = 0,
profit = rew,
permin = 0,
reward = rew
}
table.insert(self.other, cont)
elseif cat == SC.OTHER then
cont = {
miss = m,
worktime = 0,
profit = rew,
permin = 0,
reward = rew
}
table.insert(self.other, cont)
else
Logging.warning("[%s]: Unknown cat %s in addMission(m)", self.name, cat)
end
end
return {cat, cont}
end
function getPalletType(m)
Expand Down
32 changes: 31 additions & 1 deletion gui/SCGui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
v1.0.0 20.04.2021 submit for release
v1.1.0.4 07.07.2021 (Mmtrx) add user-defined missionVehicles.xml, allow missions with no vehicles
v1.2.0.0 18.01.2022 (Mmtrx) adapt for FS22
v1.2.7.5 26.02.2023 display other farms active contracts (general table)
======================================================================================================-->

<GUI name="npcDetails">
<GuiElement type="empty" id="npcbox" size="305px 300px" anchors="0 0 1 1" hasFrame="true" debugEnabled="false">
<!-- left column -->
Expand Down Expand Up @@ -42,4 +42,34 @@
<GuiElement type="text" profile="betterContractsRight" id="helpsort" size="125px 40px" position="55px 0px" text="" debugEnabled="false"/>
</GuiElement>
</GuiElement>

<!-- active missions display (anchor top right: 1 1 1 1) -->
<GuiElement type="button" profile="buttonOK" id="mToggle" anchors="1 1 1 1" inputAction="BC_MTOGGLE" size="34px 34px" position="78px -3px" debugEnabled="false" />

<GuiElement type="empty" positionOrigin="topLeft" id="container" profile="myContainer" anchors="1 1 1 1" debugEnabled="false" >
<!-- header: -->
<GuiElement type="flowLayout" profile="myHeaderBox" id="missionHeaderBox" >
<GuiElement type="tableHeader" profile="myHeaderText1" text="$l10n_ui_farm" />
<GuiElement type="tableHeader" profile="myHeaderText" text="$l10n_ui_contracts" />
<GuiElement type="tableHeader" profile="myHeaderText" text="$l10n_ui_fieldNo" />
<GuiElement type="tableHeader" profile="myHeaderText" text="$l10n_statistic_fillType" />
<GuiElement type="tableHeader" profile="myHeaderText" text="$l10n_fieldJob_progress" />
</GuiElement>

<!-- table + slider: -->
<GuiElement type="empty" position="0px -40px" debugEnabled="false" >
<!-- table: -->
<GuiElement type="table" id="mTable" handleFocus="false" profile="myTable" rowTemplateName="myRowTemplate" columnNames="c1 c2 c3 c4 c5" periodicUpdate="false" updateInterval="20" onUpdate="updateStats">
<GuiElement type="listItem" profile="myRow" name="myRowTemplate" >
<GuiElement type="bitmap" profile="myRowBg" debugEnabled="true" >
<GuiElement type="text" profile="myCell1" name="c1" />
<GuiElement type="text" profile="myCell" name="c2" position="140px 0px"/>
<GuiElement type="text" profile="myCell" name="c3" position="250px 0px"/>
<GuiElement type="text" profile="myCell" name="c4" position="360px 0px"/>
<GuiElement type="text" profile="myCell" name="c5" position="470px 0px"/>
</GuiElement>
</GuiElement>
</GuiElement>
</GuiElement>
</GuiElement>
</GUI>
68 changes: 66 additions & 2 deletions gui/guiProfiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
v1.0.0 20.04.2021 submit for release
v1.1.0.4 07.07.2021 (Mmtrx) add user-defined missionVehicles.xml, allow missions with no vehicles
v1.2.0.0 18.01.2022 (Mmtrx) adapt for FS22
v1.2.7.5 26.02.2023 display other farms active contracts (general table)
=======================================================================================================-->

<GUIProfiles>
<Presets>
<Preset name="len398" value="398px 40px" />
<Preset name="len398" value="600px 30px" />
<Preset name="colorTransparent" value="0 0 0 0"/>
<Preset name="colorMainUI" value="0.0227 0.5346 0.8519 1.0" />
<Preset name="colorMainUI_60" value="0.0227 0.5346 0.8519 0.6"/>
Expand All @@ -21,6 +21,16 @@
<Preset name="colorGlass" value="0.0036 0.0056 0.0065 0.5" />
<Preset name="colorWhite" value="1 1 1 1" />
<Preset name="colorDisabled" value="0.4 0.4 0.4 1"/>
<!-- general table - - - - - - - - - - - - - - - - - - - - - - - -->
<Preset name="container" value="580px 300px"/>
<Preset name="header" value="580px 40px"/>
<Preset name="tableSize" value="580px 260px"/> <!-- y = container - header -->
<Preset name="rowSize" value="580px 30px"/>
<Preset name="cellSize" value="110px 30px"/>
<Preset name="col1" value="138px 30px"/> <!-- column 1 length -->
<Preset name="textMax" value="105px"/> <!-- leave 5px space before next cell -->
<Preset name="textMax1" value="129px"/> <!-- col1 - 6px offset - 5px -->
<Preset name="textSize" value="16px"/>
</Presets>
<Traits>
<Trait name="buttonActive">
Expand Down Expand Up @@ -133,4 +143,58 @@
<Profile name="myVehiclesBox" extends="ingameMenuContractsVehiclesBox">
<Value name="size" value="856px 104px" />
</Profile>

<!-- general table - - - - - - - - - - - - - - - - - - - - - -->
<Profile name="myRow" extends="ingameMenuStatisticsRow">
<Value name="size" value="$preset_rowSize"/>
</Profile>
<Profile name="myRowBg" extends="ingameMenuStatisticsRowBackground">
<Value name="size" value="$preset_rowSize"/>
</Profile>
<Profile name="myRowBgAlt" extends="ingameMenuStatisticsRowBackgroundAlternate">
<Value name="size" value="$preset_rowSize"/>
</Profile>
<Profile name="myContainer" extends="ingameMenuStatisticsContainer" with="lightFrame">
<Value name="size" value="$preset_container"/>
</Profile>
<Profile name="myHeaderBox" extends="ingameMenuTableHeaderBox">
<Value name="size" value="$preset_header"/>
</Profile>
<Profile name="myTable" extends="ingameMenuStatisticsTable">
<Value name="size" value="$preset_tableSize"/>
<Value name="itemsPerCol" value="6"/>
<Value name="rowBackgroundProfile" value="myRowBg"/>
<Value name="rowBackgroundProfileAlternate" value="myRowBgAlt"/>
</Profile>
<Profile name="myHeaderText" extends="ingameMenuStatisticsTableHeader">
<Value name="size" value="$preset_cellSize"/>
<Value name="textSize" value="16px"/>
<Value name="textOffset" value="-7px 0px"/>
</Profile>
<Profile name="myHeaderText1" extends="myHeaderText">
<Value name="size" value="$preset_col1"/>
<Value name="textAlignment" value="left"/>
<Value name="textOffset" value="7px 0px"/>
<Value name="allowSortingDesc" value="true"/>
<Value name="columnName" value="c1"/> <!-- allow sorting on column 1 -->
</Profile>
<Profile name="myCell1" extends="myCell">
<Value name="size" value="$preset_col1"/>
<Value name="textMaxWidth" value="$preset_textMax1"/>
<Value name="textOffset" value="7px 0px"/>
<Value name="textAlignment" value="left" />
<Value name="textBold" value="true"/>
</Profile>
<Profile name="myCell" extends="ingameMenuStatisticsRowCell">
<Value name="size" value="$preset_cellSize"/>
<Value name="textMaxWidth" value="$preset_textMax"/>
<Value name="textSize" value="$preset_textSize"/>
<Value name="textOffset" value="-7px 0px"/>
</Profile>
<Profile name="mySlider" extends="verticalListSliderRightDocked">
<Value name="size" value="12px 260px"/>
</Profile>
<Profile name="mySliderBar" extends="verticalListSliderBar">
<Value name="size" value="6px 260px"/> <!-- height = table height -->
</Profile>
</GUIProfiles>
Loading

0 comments on commit 05108a6

Please sign in to comment.