ESO Lua File v100010

ingame/guildkiosk/guildkiosk.lua

[◄ back to folders ]
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
local GUILD_KIOSK_DIALOG_WIDTH = 400
local CURRENCY_OPTIONS =
{
    showTooltips = true,
    font = "ZoFontGameBold",
    iconSide = RIGHT,
}
--Purchase Kiosk
------------------------------
local PurchaseKioskDialog = ZO_Object:Subclass()
function PurchaseKioskDialog:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)    
    return object
end
function PurchaseKioskDialog:Initialize(control)
    local accept = function(selectedGuildId)
        GuildKioskPurchase(selectedGuildId)
        PlaySound(SOUNDS.ITEM_MONEY_CHANGED)
        INTERACT_WINDOW:OnEndInteraction(ZO_PURCHASE_KIOSK_INTERACTION)
    end
    local decline = function()
        INTERACT_WINDOW:OnEndInteraction(ZO_PURCHASE_KIOSK_INTERACTION)
    end
    
    local dialog = ZO_SelectGuildDialog:New(control, "PURCHASE_KIOSK", accept, decline)
    dialog:SetTitle(GetString(SI_GUILD_KIOSK_PURCHASE_TITLE))
    dialog:SetPrompt(GetString(SI_GUILD_KIOSK_PURCHASE_GUILD_CHOICE_HEADER))
    dialog:SetSelectedCallback(function(guildId) self:OnGuildSelected(guildId) end)
    dialog:SetButtonText(1, GetString(SI_GUILD_KIOSK_PURCHASE))
    dialog:SetGuildFilter(function(guildId)
        return DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_GUILD_KIOSK_BID)
    end)
    dialog:SetDialogUpdateFn(function(_, gameTimeSecs) ZO_GuildKiosk_Purchase_OnUpdate(self.descriptionLabel, gameTimeSecs) end)
    
    control:GetNamedChild("Title"):SetWidth(GUILD_KIOSK_DIALOG_WIDTH)
    self.descriptionLabel = control:GetNamedChild("Description")
    self.purchaseControls = control:GetNamedChild("PurchaseControls")
    self.guildBalanceLabel = self.purchaseControls:GetNamedChild("GuildBalance")
    self.purchaseCostLabel = self.purchaseControls:GetNamedChild("PurchaseCost")
    self.errorControls = control:GetNamedChild("ErrorControls")
    self.errorLabel = self.errorControls:GetNamedChild("Text")
    self.acceptButton = control:GetNamedChild("Accept")
end
--Events
function PurchaseKioskDialog:OnGuildSelected(guildId)
    local guildBankedMoney = GetKioskGuildInfo(guildId)
    local ownedKioskName = GetGuildOwnedKioskInfo(guildId)
    local guildCanUseTradingHouse = DoesGuildHavePrivilege(guildId, GUILD_PRIVILEGE_TRADING_HOUSE)
    self.purchaseControls:SetHidden(true)
    self.errorControls:SetHidden(true)
    self.acceptButton:SetEnabled(false)
    if not guildCanUseTradingHouse then
        self.errorControls:SetHidden(false)
        self.errorLabel:SetText(zo_strformat(SI_GUILD_KIOSK_PURCHASE_ERROR_TRADING_HOUSE_LOCKED, GetNumGuildMembersRequiredForPrivilege(GUILD_PRIVILEGE_TRADING_HOUSE)))
    elseif ownedKioskName then
        self.errorControls:SetHidden(false)
        self.errorLabel:SetText(zo_strformat(SI_GUILD_KIOSK_PURCHASE_ERROR_KIOSK_RENTED, ownedKioskName))
    elseif guildBankedMoney then
        local enoughMoney = guildBankedMoney >= GetKioskPurchaseCost()
        ZO_CurrencyControl_SetSimpleCurrency(self.guildBalanceLabel, CURRENCY_TYPE_MONEY, guildBankedMoney, CURRENCY_OPTIONS)
        ZO_CurrencyControl_SetSimpleCurrency(self.purchaseCostLabel, CURRENCY_TYPE_MONEY, GetKioskPurchaseCost(), CURRENCY_OPTIONS, nil, not enoughMoney)
        self.purchaseControls:SetHidden(false)
        self.acceptButton:SetEnabled(enoughMoney)
    end
end
function PurchaseKioskDialog:OnGuildKioskConsiderPurchaseStart()
    if(not ZO_Dialogs_FindDialog("PURCHASE_KIOSK")) then
        ZO_Dialogs_ShowDialog("PURCHASE_KIOSK")
        INTERACT_WINDOW:OnBeginInteraction(ZO_PURCHASE_KIOSK_INTERACTION)
    end
end
function PurchaseKioskDialog:OnGuildKioskConsiderPurchaseStop()
    ZO_Dialogs_ReleaseDialog("PURCHASE_KIOSK")
end
--Global XML
    PURCHASE_KIOSK_DIALOG = PurchaseKioskDialog:New(self)
    SYSTEMS:RegisterKeyboardObject("guildKioskPurchase", PURCHASE_KIOSK_DIALOG)
end
--Bid On Kiosk
-------------------
local BidOnKioskDialog = ZO_Object:Subclass()
function BidOnKioskDialog:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)    
    return object
end
function BidOnKioskDialog:Initialize(control)
    local accept = function(selectedGuildId)
        local bidAmount = ZO_DefaultMoneyInputField_GetMoney(self.newBidInput)
        GuildKioskBid(selectedGuildId, bidAmount)
        PlaySound(SOUNDS.ITEM_MONEY_CHANGED)
        INTERACT_WINDOW:OnEndInteraction(ZO_BID_ON_KIOSK_INTERACTION)
    end
    local decline = function()
        INTERACT_WINDOW:OnEndInteraction(ZO_BID_ON_KIOSK_INTERACTION)
    end
    
    self.dialog = ZO_SelectGuildDialog:New(control, "BID_ON_KIOSK", accept, decline)
    self.dialog:SetTitle(GetString(SI_GUILD_KIOSK_BID_TITLE))
    self.dialog:SetPrompt(GetString(SI_GUILD_KIOSK_BID_GUILD_CHOICE_HEADER))
    self.dialog:SetSelectedCallback(function(guildId) self:OnGuildSelected(guildId) end)
    self.dialog:SetButtonText(1, GetString(SI_GUILD_KIOSK_BID))
    self.dialog:SetGuildFilter(function(guildId)
        return DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_GUILD_KIOSK_BID)
    end)
    self.dialog:SetDialogUpdateFn(function(_, gameTimeSecs) self:OnUpdate(gameTimeSecs) end)
    
    control:GetNamedChild("Title"):SetWidth(GUILD_KIOSK_DIALOG_WIDTH)
    control:GetNamedChild("Description"):SetText(GetString(SI_GUILD_KIOSK_BID_DESCRIPTION))
    self.control = control
    self.bidControls = control:GetNamedChild("BidControls")
    self.guildBalanceLabel = self.bidControls:GetNamedChild("GuildBalance")
    self.currentBidLabel = self.bidControls:GetNamedChild("CurrentBid")
    self.currentBidHeaderLabel = self.bidControls:GetNamedChild("CurrentBidHeader")
    self.biddingClosesLabel = self.bidControls:GetNamedChild("BiddingCloses")
    self.newBidInput = self.bidControls:GetNamedChild("NewBid")
    self.errorControls = control:GetNamedChild("ErrorControls")
    self.errorLabel = self.errorControls:GetNamedChild("Text")
    self.acceptButton = control:GetNamedChild("Accept")
    ZO_DefaultMoneyInputField_Initialize(self.newBidInput, function(input, money)
        self:OnMoneyChanged(money)
    end)
end
--Events
function BidOnKioskDialog:OnUpdate(gameTimeSecs)    
    if(self.nextUpdateSecs == nil or gameTimeSecs >= self.nextUpdateSecs) then
        self.nextUpdateSecs = gameTimeSecs + 1
        local secsRemaining = GetKioskBidWindowSecondsRemaining()
        local ownershipDuration = ZO_FormatTimeLargestTwo(secsRemaining, TIME_FORMAT_STYLE_DESCRIPTIVE)
        self.biddingClosesLabel:SetText(ownershipDuration)
    end
end
function BidOnKioskDialog:OnGuildSelected(guildId)
    local guildBankedMoney, existingBidAmount, existingBidIsOnThisKiosk, existingBidKioskName = GetKioskGuildInfo(guildId)
    local guildCanUseTradingHouse = DoesGuildHavePrivilege(guildId, GUILD_PRIVILEGE_TRADING_HOUSE)
    self.bidControls:SetHidden(true)
    self.errorControls:SetHidden(true)
    self.acceptButton:SetEnabled(false)
    if not guildCanUseTradingHouse then
        self.errorControls:SetHidden(false)
        self.errorLabel:SetText(zo_strformat(SI_GUILD_KIOSK_BID_ERROR_TRADING_HOUSE_LOCKED, GetNumGuildMembersRequiredForPrivilege(GUILD_PRIVILEGE_TRADING_HOUSE)))
    elseif not existingBidIsOnThisKiosk and existingBidKioskName then
        self.errorControls:SetHidden(false)
        self.errorLabel:SetText(zo_strformat(SI_GUILD_KIOSK_BID_ERROR_EXISTING_BID, existingBidKioskName))
    elseif guildBankedMoney and (existingBidAmount == 0 or existingBidIsOnThisKiosk) then
        local bidAmount = 0
        ZO_DefaultMoneyInputField_SetGoldMax(self.newBidInput, guildBankedMoney + existingBidAmount)
        self.bidControls:SetHidden(false)
        if(existingBidAmount == 0) then
            local kioskPurchaseCost = GetKioskPurchaseCost()
            ZO_CurrencyControl_SetSimpleCurrency(self.currentBidLabel, CURRENCY_TYPE_MONEY, kioskPurchaseCost, CURRENCY_OPTIONS)
            self.currentBidHeaderLabel:SetText(GetString(SI_GUILD_KIOSK_MINIMUM_BID_HEADER))
            if guildBankedMoney >= kioskPurchaseCost then
                bidAmount = kioskPurchaseCost
            else
                ZO_DefaultMoneyInputField_SetGoldMax(self.newBidInput, 0)
            end
        else
            ZO_CurrencyControl_SetSimpleCurrency(self.currentBidLabel, CURRENCY_TYPE_MONEY, existingBidAmount, CURRENCY_OPTIONS)
            self.currentBidHeaderLabel:SetText(GetString(SI_GUILD_KIOSK_CURRENT_BID_HEADER))
            if guildBankedMoney > 0 then
                bidAmount = existingBidAmount + 1
            else
                ZO_DefaultMoneyInputField_SetGoldMax(self.newBidInput, 0)
            end
        end
        
        ZO_CurrencyControl_SetSimpleCurrency(self.guildBalanceLabel, CURRENCY_TYPE_MONEY, guildBankedMoney, CURRENCY_OPTIONS)
        ZO_DefaultMoneyInputField_SetGoldMin(self.newBidInput, bidAmount)
        ZO_DefaultMoneyInputField_SetMoney(self.newBidInput, bidAmount)
        self:RefreshUpdateBidEnabled(bidAmount)
    end
end
function BidOnKioskDialog:RefreshUpdateBidEnabled(bidAmount)
    local guildId = self.dialog:GetSelectedGuildId()
    if(guildId) then
        local _, existingBidAmount, existingBidIsOnThisKiosk = GetKioskGuildInfo(guildId)
        if(existingBidAmount) then
            local bidOnADifferentKioskAlready = existingBidAmount > 0 and not existingBidIsOnThisKiosk
            local minBid = GetKioskPurchaseCost()
            self.acceptButton:SetEnabled(not bidOnADifferentKioskAlready and bidAmount > existingBidAmount and bidAmount >= minBid)
        else
            self.acceptButton:SetEnabled(false)
        end
    end
end
function BidOnKioskDialog:OnMoneyChanged(money)
end
function BidOnKioskDialog:OnGuildKioskConsiderBidStart()
    if(not ZO_Dialogs_FindDialog("BID_ON_KIOSK")) then
        ZO_Dialogs_ShowDialog("BID_ON_KIOSK")
        INTERACT_WINDOW:OnBeginInteraction(ZO_BID_ON_KIOSK_INTERACTION)
    end
end
function BidOnKioskDialog:OnGuildKioskConsiderBidStop()
    ZO_Dialogs_ReleaseDialog("BID_ON_KIOSK")
end
--Global XML
    BID_ON_KIOSK_DIALOG = BidOnKioskDialog:New(self)
    SYSTEMS:RegisterKeyboardObject("guildKioskBid", BID_ON_KIOSK_DIALOG)
end