More Market fixes
* Fixed NextButton and PreviousButton style * Little update to SpinBox including dontSignal * Market cleanup and more check to be safe * Limit Market amountWindow by player balance * Set proper maximum amount when creating offers * Fixed fee label not calculating the correct fee sometimes
This commit is contained in:
parent
3157e7924f
commit
eb3c244023
|
@ -46,6 +46,7 @@ NextButton < UIButton
|
|||
size: 12 21
|
||||
image-source: /images/ui/arrow_horizontal
|
||||
image-clip: 12 0 12 21
|
||||
image-color: #ffffff
|
||||
|
||||
$hover !disabled:
|
||||
image-clip: 12 21 12 21
|
||||
|
@ -54,12 +55,13 @@ NextButton < UIButton
|
|||
image-clip: 12 21 12 21
|
||||
|
||||
$disabled:
|
||||
image-color: #dfdfdf55
|
||||
image-color: #dfdfdf88
|
||||
|
||||
PreviousButton < UIButton
|
||||
size: 12 21
|
||||
image-source: /images/ui/arrow_horizontal
|
||||
image-clip: 0 0 12 21
|
||||
image-color: #ffffff
|
||||
|
||||
$hover !disabled:
|
||||
image-clip: 0 21 12 21
|
||||
|
@ -68,7 +70,7 @@ PreviousButton < UIButton
|
|||
image-clip: 0 21 12 21
|
||||
|
||||
$disabled:
|
||||
image-color: #dfdfdf55
|
||||
image-color: #dfdfdf88
|
||||
|
||||
AddButton < UIButton
|
||||
size: 20 20
|
||||
|
|
|
@ -12,7 +12,7 @@ function UISpinBox.create()
|
|||
spinbox.step = 1
|
||||
spinbox.firstchange = true
|
||||
spinbox.mouseScroll = true
|
||||
spinbox:setText("0")
|
||||
spinbox:setText("1")
|
||||
spinbox:setValue(1)
|
||||
return spinbox
|
||||
end
|
||||
|
@ -23,7 +23,7 @@ function UISpinBox:onSetup()
|
|||
end
|
||||
|
||||
function UISpinBox:onMouseWheel(mousePos, direction)
|
||||
if not self.mouseScroll then
|
||||
if not self.mouseScroll then
|
||||
return false
|
||||
end
|
||||
if direction == MouseWheelUp then
|
||||
|
@ -66,7 +66,15 @@ function UISpinBox:onTextChange(text, oldText)
|
|||
end
|
||||
|
||||
function UISpinBox:onValueChange(value)
|
||||
-- nothing todo
|
||||
-- nothing to do
|
||||
end
|
||||
|
||||
function UISpinBox:onFocusChange(focused)
|
||||
if not focused then
|
||||
if self:getText():len() == 0 then
|
||||
self:setText(self.minimum)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UISpinBox:onStyleApply(styleName, styleNode)
|
||||
|
@ -109,14 +117,16 @@ function UISpinBox:down()
|
|||
self:setValue(self.value - self.step)
|
||||
end
|
||||
|
||||
function UISpinBox:setValue(value)
|
||||
function UISpinBox:setValue(value, dontSignal)
|
||||
value = value or 0
|
||||
value = math.max(math.min(self.maximum, value), self.minimum)
|
||||
|
||||
if value == self.value then return end
|
||||
|
||||
self.value = value
|
||||
if self:getText():len() > 0 then
|
||||
self:setText(value)
|
||||
end
|
||||
self.value = value
|
||||
|
||||
local upButton = self:getChildById('up')
|
||||
local downButton = self:getChildById('down')
|
||||
|
@ -127,7 +137,9 @@ function UISpinBox:setValue(value)
|
|||
downButton:setEnabled(self.maximum ~= self.minimum and self.value ~= self.minimum)
|
||||
end
|
||||
|
||||
signalcall(self.onValueChange, self, value)
|
||||
if not dontSignal then
|
||||
signalcall(self.onValueChange, self, value)
|
||||
end
|
||||
end
|
||||
|
||||
function UISpinBox:getValue()
|
||||
|
|
|
@ -144,7 +144,7 @@ end
|
|||
|
||||
local function clearFee()
|
||||
feeLabel:setText('')
|
||||
fee = 0
|
||||
fee = 20
|
||||
end
|
||||
|
||||
local function refreshTypeList()
|
||||
|
@ -399,46 +399,55 @@ local function destroyAmountWindow()
|
|||
end
|
||||
end
|
||||
|
||||
local function openAmountWindow(callback, type, actionText)
|
||||
local actionText = actionText or ''
|
||||
if not Market.isOfferSelected(type) then
|
||||
local function openAmountWindow(callback, actionType, actionText)
|
||||
if not Market.isOfferSelected(actionType) then
|
||||
return
|
||||
end
|
||||
|
||||
amountWindow = g_ui.createWidget('AmountWindow', rootWidget)
|
||||
amountWindow:lock()
|
||||
local item = selectedOffer[type]:getItem()
|
||||
|
||||
local max = selectedOffer[type]:getAmount(item:getId())
|
||||
if type == MarketAction.Sell then
|
||||
local offer = selectedOffer[actionType]
|
||||
local item = offer:getItem()
|
||||
|
||||
local maximum = offer:getAmount()
|
||||
if actionType == MarketAction.Sell then
|
||||
local depot = Market.getDepotCount(item:getId())
|
||||
if max > depot then
|
||||
max = depot
|
||||
if maximum > depot then
|
||||
maximum = depot
|
||||
end
|
||||
else
|
||||
maximum = math.min(maximum, math.floor(information.balance / offer:getPrice()))
|
||||
end
|
||||
|
||||
if item:isStackable() then
|
||||
maximum = math.min(maximum, MarketMaxAmountStackable)
|
||||
else
|
||||
maximum = math.min(maximum, MarketMaxAmount)
|
||||
end
|
||||
|
||||
local itembox = amountWindow:getChildById('item')
|
||||
itembox:setItemId(item:getId())
|
||||
itembox:setText(1)
|
||||
|
||||
local scrollbar = amountWindow:getChildById('amountScrollBar')
|
||||
scrollbar:setText(tostring(selectedOffer[type]:getPrice())..'gp')
|
||||
scrollbar:setMaximum(max)
|
||||
scrollbar:setMinimum(1)
|
||||
scrollbar:setValue(1)
|
||||
scrollbar:setText(offer:getPrice()..'gp')
|
||||
|
||||
scrollbar.onValueChange = function(widget, value)
|
||||
widget:setText(tostring(value*selectedOffer[type]:getPrice())..'gp')
|
||||
itembox:setText(tostring(value))
|
||||
widget:setText((value*offer:getPrice())..'gp')
|
||||
itembox:setText(value)
|
||||
end
|
||||
|
||||
scrollbar:setRange(1, maximum)
|
||||
scrollbar:setValue(1)
|
||||
|
||||
local okButton = amountWindow:getChildById('buttonOk')
|
||||
if actionText ~= '' then
|
||||
if actionText then
|
||||
okButton:setText(actionText)
|
||||
end
|
||||
|
||||
local okFunc = function()
|
||||
local counter = selectedOffer[type]:getCounter()
|
||||
local timestamp = selectedOffer[type]:getTimeStamp()
|
||||
local counter = offer:getCounter()
|
||||
local timestamp = offer:getTimeStamp()
|
||||
callback(scrollbar:getValue(), timestamp, counter)
|
||||
destroyAmountWindow()
|
||||
end
|
||||
|
@ -532,46 +541,47 @@ local function onChangeSlotFilter(combobox, option)
|
|||
end
|
||||
|
||||
local function onChangeOfferType(combobox, option)
|
||||
local id = selectedItem.item.marketData.tradeAs
|
||||
local item = selectedItem.item
|
||||
local maximum = item.thingType:isStackable() and MarketMaxAmountStackable or MarketMaxAmount
|
||||
|
||||
if option == 'Sell' then
|
||||
local max = Market.getDepotCount(id)
|
||||
amountEdit:setMaximum(max)
|
||||
maximum = math.min(maximum, Market.getDepotCount(item.marketData.tradeAs))
|
||||
amountEdit:setMaximum(maximum)
|
||||
else
|
||||
amountEdit:setMaximum(999999)
|
||||
amountEdit:setMaximum(maximum)
|
||||
end
|
||||
end
|
||||
|
||||
local function onTotalPriceChange()
|
||||
local totalPrice = totalPriceEdit:getValue()
|
||||
local piecePrice = piecePriceEdit:getValue()
|
||||
local amount = amountEdit:getValue()
|
||||
local totalPrice = totalPriceEdit:getValue()
|
||||
local piecePrice = math.floor(totalPrice/amount)
|
||||
|
||||
piecePriceEdit:setValue(math.floor(totalPrice/amount))
|
||||
piecePriceEdit:setValue(piecePrice, true)
|
||||
if Market.isItemSelected() then
|
||||
updateFee(totalPrice, amount)
|
||||
updateFee(piecePrice, amount)
|
||||
end
|
||||
end
|
||||
|
||||
local function onPiecePriceChange()
|
||||
local amount = amountEdit:getValue()
|
||||
local totalPrice = totalPriceEdit:getValue()
|
||||
local piecePrice = piecePriceEdit:getValue()
|
||||
local amount = amountEdit:getValue()
|
||||
|
||||
totalPriceEdit:setValue(piecePrice*amount)
|
||||
totalPriceEdit:setValue(piecePrice*amount, true)
|
||||
if Market.isItemSelected() then
|
||||
updateFee(totalPrice, amount)
|
||||
updateFee(piecePrice, amount)
|
||||
end
|
||||
end
|
||||
|
||||
local function onAmountChange()
|
||||
local totalPrice = totalPriceEdit:getValue()
|
||||
local piecePrice = piecePriceEdit:getValue()
|
||||
local amount = amountEdit:getValue()
|
||||
local piecePrice = piecePriceEdit:getValue()
|
||||
local totalPrice = piecePrice * amount
|
||||
|
||||
piecePriceEdit:setValue(math.floor(totalPrice/amount))
|
||||
totalPriceEdit:setValue(piecePrice*amount)
|
||||
totalPriceEdit:setValue(piecePrice*amount, true)
|
||||
if Market.isItemSelected() then
|
||||
updateFee(totalPrice, amount)
|
||||
updateFee(piecePrice, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -801,7 +811,7 @@ end
|
|||
|
||||
function Market.clearSelectedItem()
|
||||
if Market.isItemSelected() then
|
||||
Market.resetCreateOffer()
|
||||
Market.resetCreateOffer(true)
|
||||
offerTypeList:clearOptions()
|
||||
offerTypeList:setText('Please Select')
|
||||
offerTypeList:setEnabled(false)
|
||||
|
@ -878,12 +888,17 @@ function Market.updateCurrentItems()
|
|||
Market.loadMarketItems(id)
|
||||
end
|
||||
|
||||
function Market.resetCreateOffer()
|
||||
function Market.resetCreateOffer(resetFee)
|
||||
piecePriceEdit:setValue(1)
|
||||
totalPriceEdit:setValue(1)
|
||||
amountEdit:setValue(1)
|
||||
refreshTypeList()
|
||||
clearFee()
|
||||
|
||||
if resetFee then
|
||||
clearFee()
|
||||
else
|
||||
updateFee(0, 0)
|
||||
end
|
||||
end
|
||||
|
||||
function Market.refreshItemsWidget(selectItem)
|
||||
|
@ -990,8 +1005,6 @@ function Market.createNewOffer()
|
|||
local spriteId = selectedItem.item.marketData.tradeAs
|
||||
|
||||
local piecePrice = piecePriceEdit:getValue()
|
||||
local totalPrice = totalPriceEdit:getValue()
|
||||
|
||||
local amount = amountEdit:getValue()
|
||||
local anonymous = anonymous:isChecked() and 1 or 0
|
||||
|
||||
|
@ -1002,6 +1015,9 @@ function Market.createNewOffer()
|
|||
errorMsg = errorMsg..'Not enough balance to create this offer.\n'
|
||||
end
|
||||
elseif type == MarketAction.Sell then
|
||||
if information.balance < fee then
|
||||
errorMsg = errorMsg..'Not enough balance to create this offer.\n'
|
||||
end
|
||||
if Market.getDepotCount(spriteId) < amount then
|
||||
errorMsg = errorMsg..'Not enough items in your depot to create this offer.\n'
|
||||
end
|
||||
|
@ -1012,12 +1028,21 @@ function Market.createNewOffer()
|
|||
elseif piecePrice < piecePriceEdit.minimum then
|
||||
errorMsg = errorMsg..'Price is too low.\n'
|
||||
end
|
||||
|
||||
if amount > amountEdit.maximum then
|
||||
errorMsg = errorMsg..'Amount is too high.\n'
|
||||
elseif amount < amountEdit.minimum then
|
||||
errorMsg = errorMsg..'Amount is too low.\n'
|
||||
end
|
||||
|
||||
if amount * piecePrice > MarketMaxPrice then
|
||||
errorMsg = errorMsg..'Total price is too high.\n'
|
||||
end
|
||||
|
||||
if information.totalOffers >= MarketMaxOffers then
|
||||
errorMsg = errorMsg..'You cannot create more offers.\n'
|
||||
end
|
||||
|
||||
local timeCheck = os.time() - lastCreatedOffer
|
||||
if timeCheck < offerExhaust[type] then
|
||||
local waitTime = math.ceil(offerExhaust[type] - timeCheck)
|
||||
|
|
|
@ -135,8 +135,7 @@ Panel
|
|||
font: verdana-11px-rounded
|
||||
text-offset: 0 2
|
||||
anchors.top: offerTypeLabel.top
|
||||
anchors.left: prev.right
|
||||
margin-left: 32
|
||||
anchors.left: amountEdit.left
|
||||
|
||||
PreviousButton
|
||||
id: prevAmountButton
|
||||
|
@ -147,7 +146,7 @@ Panel
|
|||
|
||||
SpinBox
|
||||
id: amountEdit
|
||||
anchors.verticalCenter: prev.verticalCenter
|
||||
anchors.top: prev.top
|
||||
anchors.left: prev.right
|
||||
margin-left: 3
|
||||
width: 55
|
||||
|
@ -184,8 +183,6 @@ Panel
|
|||
Label
|
||||
id: feeLabel
|
||||
font: verdana-11px-rounded
|
||||
text-offset: 0 2
|
||||
anchors.top: createOfferButton.bottom
|
||||
anchors.right: parent.right
|
||||
margin-right: 8
|
||||
margin-top: 3
|
||||
anchors.left: createOfferButton.left
|
||||
margin: 2
|
|
@ -1,3 +1,8 @@
|
|||
MarketMaxAmount = 2000
|
||||
MarketMaxAmountStackable = 64000
|
||||
MarketMaxPrice = 999999999
|
||||
MarketMaxOffers = 100
|
||||
|
||||
MarketAction = {
|
||||
Buy = 0,
|
||||
Sell = 1
|
||||
|
|
Loading…
Reference in New Issue