Back to Home

ESO Lua File v101041

ingame/guildkiosk/keyboard/guildkiosk_keyboard.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
local GUILD_KIOSK_DIALOG_WIDTH = 450
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:EndInteraction(ZO_PURCHASE_KIOSK_INTERACTION)
    end
    local decline = function()
        INTERACT_WINDOW:EndInteraction(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)
    dialog:SetUpdateGuildListWhileShown(false)
    
    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, CURT_MONEY, guildBankedMoney, CURRENCY_OPTIONS)
        ZO_CurrencyControl_SetSimpleCurrency(self.purchaseCostLabel, CURT_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_DefaultCurrencyInputField_GetCurrency(self.newBidInput)
        GuildKioskBid(selectedGuildId, bidAmount)
        PlaySound(SOUNDS.ITEM_MONEY_CHANGED)
        INTERACT_WINDOW:EndInteraction(ZO_BID_ON_KIOSK_INTERACTION)
    end
    local decline = function()
        INTERACT_WINDOW:EndInteraction(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:SetGuildFilter(function(guildId)
        return DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_GUILD_KIOSK_BID)
    end)
    self.dialog:SetDialogUpdateFn(function(_, gameTimeSecs) self:OnUpdate(gameTimeSecs) end)
    self.dialog:SetUpdateGuildListWhileShown(false)
    control:GetNamedChild("Title"):SetWidth(GUILD_KIOSK_DIALOG_WIDTH)
    control:GetNamedChild("Description"):SetText(zo_strformat(SI_GUILD_KIOSK_BID_DESCRIPTION, GetMaxKioskBidsPerGuild()))
    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.weeklyBidsLabel = self.bidControls:GetNamedChild("WeeklyBids")
    self.newBidInput = self.bidControls:GetNamedChild("NewBid")
    self.errorControls = control:GetNamedChild("ErrorControls")
    self.errorLabel = self.errorControls:GetNamedChild("Text")
    self.acceptButton = control:GetNamedChild("Accept")
    ZO_DefaultCurrencyInputField_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, numTotalBids = GetKioskGuildInfo(guildId)
    local maxBidsPerGuild = GetMaxKioskBidsPerGuild()
    local hasBidOnThisTraderAlready = existingBidAmount > 0
    local guildCanUseTradingHouse = DoesGuildHavePrivilege(guildId, GUILD_PRIVILEGE_TRADING_HOUSE)
    self.bidControls:SetHidden(true)
    self.errorControls:SetHidden(true)
    self.acceptButton:SetEnabled(false)
    self.dialog:SetButtonText(1, ZO_GuildKiosk_Bid_Shared.GetBidActionText(hasBidOnThisTraderAlready))
    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 hasBidOnThisTraderAlready and numTotalBids >= maxBidsPerGuild then
        self.errorControls:SetHidden(false)
        self.errorLabel:SetText(GetString("SI_GUILDKIOSKRESULT", GUILD_KIOSK_TOO_MANY_BIDS))
    elseif guildBankedMoney then
        local minBidAllowed = 0
        ZO_DefaultCurrencyInputField_SetCurrencyMax(self.newBidInput, guildBankedMoney + existingBidAmount)
        local shouldGuildBankGoldShowErrorColor = false
        self.bidControls:SetHidden(false)
        if existingBidAmount == 0 then
            local kioskPurchaseCost = GetKioskPurchaseCost()
            self.currentBidHeaderLabel:SetText(GetString(SI_GUILD_KIOSK_MINIMUM_BID_HEADER))
            local shouldKioskPurchaseCostShowErrorColor = false
            if guildBankedMoney >= kioskPurchaseCost then
                minBidAllowed = kioskPurchaseCost
            else
                shouldKioskPurchaseCostShowErrorColor = true
                ZO_DefaultCurrencyInputField_SetCurrencyMax(self.newBidInput, 0)
            end
            --Show red on the minimum bid text when making the first bid if you don't have enough (less than the kiosk purchase cost in the guild bank)
            ZO_CurrencyControl_SetSimpleCurrency(self.currentBidLabel, CURT_MONEY, kioskPurchaseCost, CURRENCY_OPTIONS, CURRENCY_SHOW_ALL, shouldKioskPurchaseCostShowErrorColor)
        else
            self.currentBidHeaderLabel:SetText(GetString(SI_GUILD_KIOSK_CURRENT_BID_HEADER))
            if guildBankedMoney > 0 then
                minBidAllowed = existingBidAmount + 1
            else
                shouldGuildBankGoldShowErrorColor = true
                ZO_DefaultCurrencyInputField_SetCurrencyMax(self.newBidInput, 0)
            end
            ZO_CurrencyControl_SetSimpleCurrency(self.currentBidLabel, CURT_MONEY, existingBidAmount, CURRENCY_OPTIONS)
        end
        
        self.weeklyBidsLabel:SetText(ZO_FormatFraction(numTotalBids, maxBidsPerGuild))
        --Show red on the guild bank money when updating an existing bid if you don't have enough (0 gold in the guild bank)
        ZO_CurrencyControl_SetSimpleCurrency(self.guildBalanceLabel, CURT_MONEY, guildBankedMoney, CURRENCY_OPTIONS, CURRENCY_SHOW_ALL, shouldGuildBankGoldShowErrorColor)
        ZO_DefaultCurrencyInputField_SetCurrencyMin(self.newBidInput, minBidAllowed)
        ZO_DefaultCurrencyInputField_SetCurrencyAmount(self.newBidInput, minBidAllowed)
        self:RefreshUpdateBidEnabled(minBidAllowed)
    end
end
function BidOnKioskDialog:RefreshUpdateBidEnabled(bidAmount)
    local guildId = self.dialog:GetSelectedGuildId()
    if(guildId) then
        local _, existingBidAmount, numTotalBids = GetKioskGuildInfo(guildId)
        if(existingBidAmount) then
            local hasBidOnThisTraderAlready = existingBidAmount > 0
            if hasBidOnThisTraderAlready then
                self.acceptButton:SetEnabled(bidAmount > existingBidAmount)
            else
                if numTotalBids >= GetMaxKioskBidsPerGuild() then
                    self.acceptButton:SetEnabled(false)
                else
                    local minBid = GetKioskPurchaseCost()
                    self.acceptButton:SetEnabled(bidAmount >= minBid)
                end
            end
        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