Skip to content

Commit

Permalink
v1.2.7.3
Browse files Browse the repository at this point in the history
-add 2nd progress bar for active harvest missions
- fix PnH BGA issue with Maize+
  • Loading branch information
Mmtrx committed Feb 20, 2023
1 parent 0a5774e commit 24ff474
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 9 deletions.
18 changes: 16 additions & 2 deletions betterContracts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
-- v1.2.7.1 10.02.2023 fix mission visual tags for MP: renderIcon().
-- v1.2.7.2 15.02.2023 Add settings to adjust contract generation
-- 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+
--=======================================================================================================
SC = {
FERTILIZER = 1, -- prices index
Expand All @@ -68,7 +69,6 @@ SC = {
-- hardMode expire:
DAY = 1,
MONTH = 2,

-- Gui controls:
CONTROLS = {
npcbox = "npcbox",
Expand All @@ -95,6 +95,11 @@ SC = {
sortprof = "sortprof",
sortpmin = "sortpmin",
helpsort = "helpsort"
},
-- Gui contractBox controls:
CONTBOX = {
"box1", "box2", "prog1", "prog2",
"progressBarBg", "progressBar1", "progressBar2"
}
}
function debugPrint(text, ...)
Expand Down Expand Up @@ -373,6 +378,10 @@ function initGui(self)
for _, name in pairs(SC.CONTROLS) do
self.my[name] = self.frCon.farmerBox:getDescendantById(name)
end
-- set controls for contractBox:
for _, name in pairs(SC.CONTBOX) do
self.my[name] = self.frCon.contractBox:getDescendantById(name)
end
-- set callbacks for our 3 sort buttons
for _, name in ipairs({"sortcat", "sortprof", "sortpmin"}) do
self.my[name].onClickCallback = onClickSortButton
Expand Down Expand Up @@ -722,7 +731,12 @@ function BetterContracts:getFilltypePrice(m)
self.name, m.type.name, self.ft[m.fillType].title, m.field.fieldId)
return 0
end
return m.sellPoint:getEffectiveFillTypePrice(m.fillType)
-- check for Maize+ filltype
local fillType = m.fillType
if m.sellPoint.fillTypePrices[fillType] == nil then
fillType = FillType.SILAGE
end
return m.sellPoint:getEffectiveFillTypePrice(fillType)
end
function BetterContracts:calcProfit(m, successFactor)
-- calculate brutto income as reward + value of kept harvest
Expand Down
13 changes: 13 additions & 0 deletions gui/guiProfiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,17 @@
<Value name="textColor" value="$preset_colorMainUI" />
</Profile>

<Profile name="myProgressLayout" extends="emptyPanel" with="anchorTopCenter" >
<Value name="alignmentY" value="bottom"/>
<Value name="flowDirection" value="horizontal"/>
</Profile>

<!-- Smaller vehicles - - - - - - - - - - - - - - - - - - - - - -->
<Profile name="myVehiclesItem" extends="ingameMenuContractsVehiclesItem">
<Value name="size" value="104px 104px"/>
<Value name="margin" value="1px 0 2px 0"/>
</Profile>
<Profile name="myVehiclesBox" extends="ingameMenuContractsVehiclesBox">
<Value name="size" value="856px 104px" />
</Profile>
</GUIProfiles>
30 changes: 30 additions & 0 deletions gui/progressGui.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--=====================================================================================================
BetterContracts GUI additions
Purpose: Enhance active contracts progress bar
Author: Mmtrx
Changelog:
v1.2.7.3 18.02.2023 initial beta
======================================================================================================-->
<GUI name="bc_progress">
<!-- progr bar 1 -->
<GuiElement type="boxLayout" profile="myProgressLayout" id="box1" size="800px 46px" position="0px -240px" debugEnabled="false">
<GuiElement type="text" profile="ingameMenuContractsContractTextSmall" id="prog1Label" text="$l10n_bc_progField" textAlignment="left" textAutoWidth="true" size="100px 40px" >
</GuiElement>
<GuiElement type="bitmap" profile="ingameMenuContractsProgressBarBackground" id="progressBarBg">
<GuiElement type="bitmap" profile="ingameMenuContractsProgressBar" id="progressBar1"/>
</GuiElement>
<GuiElement type="text" profile="ingameMenuContractsContractTextSmall" id="prog1" textAlignment="left" textAutoWidth="true" size="0 40px" >
</GuiElement>
</GuiElement>
<!-- progr bar 2 -->
<GuiElement type="boxLayout" profile="myProgressLayout" id="box2" size="800px 46px" position="0px -290px" debugEnabled="false">
<GuiElement type="text" profile="ingameMenuContractsContractTextSmall" id="prog2Label" text="$l10n_bc_progDeliver" textAlignment="left" textAutoWidth="true" size="100px 40px" >
</GuiElement>
<GuiElement type="bitmap" profile="ingameMenuContractsProgressBarBackground" >
<GuiElement type="bitmap" profile="ingameMenuContractsProgressBar" id="progressBar2"/>
</GuiElement>
<GuiElement type="text" profile="ingameMenuContractsContractTextSmall" id="prog2" textAlignment="left" textAutoWidth="true" size="0 40px" >
</GuiElement>
</GuiElement>
</GUI>
4 changes: 4 additions & 0 deletions l10n/l10n_br.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<text name="SC_sortProf" text="Lucro líquido" />
<text name="SC_sortpMin" text="Lucro por minuto" />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Settings Page (and v1.2.6.0 additions) -->
<text name="bc_jobsCompleted" text="Trabalhos concluídos: %d" />
<text name="bc_leaseNotEnough" text="Você precisa concluir mais %d trabalhos para %s com equipamento próprio antes de poder emprestar máquinas." />
Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_cs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<text name="SC_togo" text="未完成:" />
<text name="SC_timeleft" text="剩余时间:" />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Sort button help text -->
<text name="SC_sortCat" text="任务类型" />
<text name="SC_sortProf" text="净利润" />
Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_cz.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<text name="SC_sortProf" text="Čistý zisk" />
<text name="SC_sortpMin" text="Zisk za minutu" />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Settings Page (and v1.2.6.0 additions) -->
<text name="bc_jobsCompleted" text="Dokončené zakázky: %d" />
<text name="bc_leaseNotEnough" text="Než si budete moci půjčit stroje, musíte dokončit %d dalších úloh za %s s vlastním vybavením." />
Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<text name="SC_sortProf" text="Nettoprofit" />
<text name="SC_sortpMin" text="Profit pro Minute" />

<!-- progress bars -->
<text name="bc_progField" text="Fortschritt Feld" />
<text name="bc_progDeliver" text="Fortschritt Lieferung" />

<!-- Settings Page -->
<text name="bc_settingsPage_title" text="BetterContracts Einstellungen" />

Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<text name="SC_togo" text="To go:" />
<text name="SC_timeleft" text="Time left:" />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Sort button help text -->
<text name="SC_sortCat" text="mission type" />
<text name="SC_sortProf" text="net profit" />
Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<text name="SC_sortProf" text="Profit net" />
<text name="SC_sortpMin" text="Profit par minute" />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Settings Page (and v1.2.6.0 additions) -->
<text name="bc_jobsCompleted" text="Jobs completed: %d" />
<text name="bc_leaseNotEnough" text="You need to complete %d more jobs for %s with own equipment, before you can borrow machines." />
Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_it.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<text name="SC_sortProf" text="net profit" />
<text name="SC_sortpMin" text="profit per minute" />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Settings Page (and v1.2.6.0 additions) -->
<text name="bc_jobsCompleted" text="Jobs completed: %d" />
<text name="bc_leaseNotEnough" text="You need to complete %d more jobs for %s with own equipment, before you can borrow machines." />
Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_jp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<text name="SC_sortProf" text="純利益" />
<text name="SC_sortpMin" text="分利益" />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Settings Page (and v1.2.6.0 additions) -->
<text name="bc_jobsCompleted" text="Jobs completed: %d" />
<text name="bc_leaseNotEnough" text="You need to complete %d more jobs for %s with own equipment, before you can borrow machines." />
Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_pl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<text name="SC_sortProf" text="Zysk netto" />
<text name="SC_sortpMin" text="Zysk na minutę" />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Settings Page (and v1.2.6.0 additions) -->
<text name="bc_jobsCompleted" text="Jobs completed: %d" />
<text name="bc_leaseNotEnough" text="You need to complete %d more jobs for %s with own equipment, before you can borrow machines." />
Expand Down
4 changes: 4 additions & 0 deletions l10n/l10n_ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<text name="SC_sortProf" text="Чистая прибыль" />
<text name="SC_sortpMin" text="Доход в мин." />

<!-- progress bars -->
<text name="bc_progField" text="Field progress" />
<text name="bc_progDeliver" text="Delivery progress" />

<!-- Settings Page (and v1.2.6.0 additions) -->
<text name="bc_jobsCompleted" text="Выполненные контракты: %d" />
<text name="bc_leaseNotEnough" text="Вам нужно выполнить еще %d контрактов для %s с помощью собственного оборудования, прежде чем вы сможете брать машины в аренду." />
Expand Down
6 changes: 4 additions & 2 deletions modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="72">
<author>Mmtrx</author>
<version>1.2.7.2</version>
<version>1.2.7.3</version>
<title>
<en>Better Contracts</en>
</title>
Expand All @@ -24,7 +24,9 @@ Disclaimer: All values shown in details display are ESTIMATES. You should not ta
The mod keeps track of the amount of contracts you completed for each of the NPC farmers (number of completed jobs is displayed below the farmers image, if "Details" on). If you enable the optional discount mode or hard mode options (on the mods settings page), the amount of completed jobs influence gameplay.
Changelog v1.2.7.2:
Changelog v1.2.7.3:
- add 2nd progress bar for active harvest contracts
- fix Maize+ issue with Pumps'n Hoses BGA
- add setting to change time interval between contract generation runs
- fix missing icon for roller missions, do not display negative "to go" values
- fix mission visual tags for MP: renderIcon().
Expand Down
28 changes: 26 additions & 2 deletions scripts/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
-- v1.2.7.0 29.01.2023 visual tags for mission fields and vehicles.
-- show leased vehicles for active contracts
-- v1.2.7.2 12.02.2023 don't show negative togos
-- v1.2.7.3 20.02.2023 double progress bar active contracts. Fix PnH BGA/ Maize+
--=======================================================================================================

--- Adds a new page to the in game menu.
Expand Down Expand Up @@ -116,6 +117,8 @@ function BetterContracts:loadGUI(guiPath)
return false
end
local xmlFile, layout
local cont = self.frCon.contractsContainer

-- load "SCGui.xml"
fname = guiPath .. "SCGui.xml"
if fileExists(fname) then
Expand All @@ -137,7 +140,6 @@ function BetterContracts:loadGUI(guiPath)
fname = guiPath .. "filterGui.xml"
if fileExists(fname) then
xmlFile = loadXMLFile("Temp", fname)
local cont = self.frCon.contractsContainer
g_gui:loadGuiRec(xmlFile, "GUI", cont, self.frCon)
layout = cont:getDescendantById("filterlayout")
layout:applyScreenAlignment()
Expand All @@ -152,6 +154,25 @@ function BetterContracts:loadGUI(guiPath)
return false
end

-- load "progressGui.xml"
fname = guiPath .. "progressGui.xml"
if fileExists(fname) then
xmlFile = loadXMLFile("Temp", fname)
local contBox = self.frCon.contractBox
-- load our "progressbar" as child of contractBox:
g_gui:loadGuiRec(xmlFile, "GUI", contBox, self.frCon)
for _,id in ipairs({"box1","box2"}) do
layout = contBox:getDescendantById(id)
layout:applyScreenAlignment()
layout:updateAbsolutePosition()
layout:invalidateLayout(true) -- adjust text fields
end
delete(xmlFile)
else
Logging.error("[GuiLoader %s] Required file '%s' could not be found!", self.name, fname)
return false
end

-- load "BCsettingsPage.lua"
if g_gui ~= nil and g_gui.guis.BCSettingsFrame == nil then
local luaPath = guiPath .. "BCsettingsPage.lua"
Expand Down Expand Up @@ -629,7 +650,7 @@ function updateFarmersBox(frCon, field, npc)
local active = cont.active
local text, text4a, text4b
--get current price
local price = m.sellPoint:getEffectiveFillTypePrice(m.fillType)
local price = self:getFilltypePrice(m)
self.my.filltype:setText(c.ftype)

if active then
Expand All @@ -656,6 +677,9 @@ function updateFarmersBox(frCon, field, npc)
self.my.valu4a:setText(val4a)
self.my.line4b:setText(text4b)
self.my.valu4b:setText(val4b)
-- save values for progress bars:
self.fieldPercent = m.fieldPercentageDone
self.deliverPercent = depo/c.deliver
else
text4a = g_i18n:formatVolume(MathUtil.round(c.deliver / 100) * 100)
text4b = g_i18n:formatVolume(MathUtil.round(c.keep / 100) * 100)
Expand Down
38 changes: 35 additions & 3 deletions scripts/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
-- show leased vehicles for active contracts
-- v1.2.7.1 10.02.2023 fix mission visual tags for MP: renderIcon().
-- v1.2.7.2 12.02.2023 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+
--=======================================================================================================

--------------------- lazyNPC ---------------------------------------------------------------------------
Expand Down Expand Up @@ -204,6 +205,7 @@ function harvestCalcStealing(self,superf)
return steal + penal
end
function updateDetails(self, section, index)
-- appended to InGameMenuContractsFrame:updateDetailContents()
local bc = BetterContracts
local contract = nil
local sectionContracts = self.sectionContracts[section]
Expand All @@ -229,11 +231,20 @@ function updateDetails(self, section, index)
self.tallyBox:getDescendantByName("stealing"):setText(g_i18n:formatMoney(penal, 0, true, true))
self.tallyBox:getDescendantByName("total"):setText(g_i18n:formatMoney(total, 0, true, true))
end
local noActive = not contract.active or not bc.isOn

-- show leased vecs for active contract
if contract.active and mission:hasLeasableVehicles() and mission.spawnedVehicles
and bc.isOn then
-- toggle standard / enhanced progress bars
bc:showProgressBars(contract, not noActive and
table.hasElement({"harvest","mow_bale"}, mission.type.name))
if noActive then return end

-- update display for active contracts
if mission:hasLeasableVehicles() and mission.spawnedVehicles then
-- show leased vecs for active contract
local totalWidth = 0
-- smaller vehiclesBox to not interfere with 2nd progress bar
self.vehicleTemplate:applyProfile("myVehiclesItem")
self.vehiclesBox:applyProfile("myVehiclesBox")
for _, v in ipairs(mission.vehiclesToLoad) do
local storeItem = g_storeManager:getItemByXMLFilename(v.filename)
local element = self.vehicleTemplate:clone(self.vehiclesBox)
Expand All @@ -248,7 +259,28 @@ function updateDetails(self, section, index)
self.vehiclesBox:invalidateLayout()
end
end
function BetterContracts:showProgressBars(contract, on)
-- hide standard progress bar
local off = not on
local cbox = self.frCon
cbox.progressText:setVisible(off and contract.active)
cbox.progressTitleText:setVisible(off and contract.active)
cbox.extraProgressText:setVisible(off and contract.active)
cbox.progressBarBg:setVisible(off and contract.active)

-- show my progress bars
self.my.box1:setVisible(on)
self.my.box2:setVisible(on)
if off then return end

local fullWidth = self.my.progressBarBg.size[1] - self.my.progressBar1.margin[1] * 2
local fieldPercent = math.min(self.fieldPercent, 1)
local deliverPercent = math.min(self.deliverPercent, 1)
self.my.prog1:setText(string.format(" %.0f%%", fieldPercent * 100))
self.my.progressBar1:setSize(fullWidth * fieldPercent, nil)
self.my.prog2:setText(string.format(" %.0f%%", deliverPercent * 100))
self.my.progressBar2:setSize(fullWidth * deliverPercent, nil)
end
function dismiss(self)
-- appended to AbstractMission:dismiss()
if not BetterContracts.config.hardMode or not self.isServer then return end
Expand Down

0 comments on commit 24ff474

Please sign in to comment.