forked from berntseb/FS22_UpgradableFactories
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInGameMenuUpgradableFactories.lua
More file actions
82 lines (71 loc) · 3.38 KB
/
InGameMenuUpgradableFactories.lua
File metadata and controls
82 lines (71 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
InGameMenuUpgradableFactories = {}
InGameMenuProductionFrame.UPDATE_INTERVAL = 1000
function InGameMenuUpgradableFactories:initialize()
self.inGameMenu = g_currentMission.inGameMenu
self.pageProduction = g_currentMission.inGameMenu.pageProduction
self.pageProduction.upgradeButtonInfo = {
profile = "buttonOK",
inputAction = InputAction.MENU_EXTRA_1,
text = g_i18n:getText("uf_upgrade"),
callback = InGameMenuUpgradableFactories.onButtonUpgrade
}
InGameMenuProductionFrame.updateMenuButtons = Utils.appendedFunction(InGameMenuProductionFrame.updateMenuButtons, InGameMenuUpgradableFactories.updateMenuButtons)
InGameMenuProductionFrame.onListSelectionChanged = Utils.appendedFunction(InGameMenuProductionFrame.onListSelectionChanged, InGameMenuUpgradableFactories.onListSelectionChanged)
end
function InGameMenuUpgradableFactories:onButtonUpgrade()
local _, prodpoint = self.pageProduction:getSelectedProduction()
local money = g_farmManager:getFarmById(g_currentMission:getFarmId()):getBalance()
UFInfo(
"Request upgrade %s to level %d of %d [cost: %s | money: %s]",
prodpoint.owningPlaceable:getName(),
prodpoint.productionLevel,
UpgradableFactories.MAX_LEVEL,
g_i18n:formatMoney(prodpoint.owningPlaceable.upgradePrice),
g_i18n:formatMoney(money)
)
if prodpoint.productionLevel >= UpgradableFactories.MAX_LEVEL then
g_gui:showInfoDialog({text = g_i18n:getText("uf_max_level")})
UFInfo("Production already at max level")
elseif money >= prodpoint.owningPlaceable.upgradePrice then
local text = string.format(
g_i18n:getText("uf_upgrade_dialog"),
prodpoint.owningPlaceable:getName(),
prodpoint.productionLevel+1,
g_i18n:formatMoney(prodpoint.owningPlaceable.upgradePrice)
)
g_gui:showYesNoDialog({
text = text,
title = "Upgrade Factory",
callback = InGameMenuUpgradableFactories.onUpgradeConfirm,
target=InGameMenuUpgradableFactories,
args=prodpoint
})
else
g_gui:showInfoDialog({text = self.l10n:getText(ShopConfigScreen.L10N_SYMBOL.NOT_ENOUGH_MONEY_BUY)})
UFInfo("Not enough money")
end
end
function InGameMenuUpgradableFactories.onListSelectionChanged(pageProduction, list, section, index)
local prodpoints = pageProduction:getProductionPoints()
if #prodpoints > 0 then
local prodpoint = prodpoints[section]
pageProduction.upgradeButtonInfo.disabled = prodpoint == nil or not prodpoint.isUpgradable
pageProduction:setMenuButtonInfoDirty()
end
end
function InGameMenuUpgradableFactories:onUpgradeConfirm(confirm, prodpoint)
if confirm then
g_currentMission:addMoney(-prodpoint.owningPlaceable.upgradePrice, 1, MoneyType.SHOP_PROPERTY_BUY, true, true)
prodpoint.productionLevel = prodpoint.productionLevel + 1
UpgradableFactories:adjProdPoint2lvl(prodpoint, prodpoint.productionLevel)
self.pageProduction.productionList:reloadData()
UFInfo("Upgrade confirmed")
else
UFInfo("Upgrade canceled")
end
end
function InGameMenuUpgradableFactories.updateMenuButtons(pageProduction)
if #pageProduction:getProductionPoints() > 0 then
table.insert(pageProduction.menuButtonInfo, pageProduction.upgradeButtonInfo)
end
end