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
master
TheSumm 9 years ago
parent 3157e7924f
commit eb3c244023

@ -46,6 +46,7 @@ NextButton < UIButton
size: 12 21 size: 12 21
image-source: /images/ui/arrow_horizontal image-source: /images/ui/arrow_horizontal
image-clip: 12 0 12 21 image-clip: 12 0 12 21
image-color: #ffffff
$hover !disabled: $hover !disabled:
image-clip: 12 21 12 21 image-clip: 12 21 12 21
@ -54,12 +55,13 @@ NextButton < UIButton
image-clip: 12 21 12 21 image-clip: 12 21 12 21
$disabled: $disabled:
image-color: #dfdfdf55 image-color: #dfdfdf88
PreviousButton < UIButton PreviousButton < UIButton
size: 12 21 size: 12 21
image-source: /images/ui/arrow_horizontal image-source: /images/ui/arrow_horizontal
image-clip: 0 0 12 21 image-clip: 0 0 12 21
image-color: #ffffff
$hover !disabled: $hover !disabled:
image-clip: 0 21 12 21 image-clip: 0 21 12 21
@ -68,7 +70,7 @@ PreviousButton < UIButton
image-clip: 0 21 12 21 image-clip: 0 21 12 21
$disabled: $disabled:
image-color: #dfdfdf55 image-color: #dfdfdf88
AddButton < UIButton AddButton < UIButton
size: 20 20 size: 20 20

@ -12,7 +12,7 @@ function UISpinBox.create()
spinbox.step = 1 spinbox.step = 1
spinbox.firstchange = true spinbox.firstchange = true
spinbox.mouseScroll = true spinbox.mouseScroll = true
spinbox:setText("0") spinbox:setText("1")
spinbox:setValue(1) spinbox:setValue(1)
return spinbox return spinbox
end end
@ -23,7 +23,7 @@ function UISpinBox:onSetup()
end end
function UISpinBox:onMouseWheel(mousePos, direction) function UISpinBox:onMouseWheel(mousePos, direction)
if not self.mouseScroll then if not self.mouseScroll then
return false return false
end end
if direction == MouseWheelUp then if direction == MouseWheelUp then
@ -66,7 +66,15 @@ function UISpinBox:onTextChange(text, oldText)
end end
function UISpinBox:onValueChange(value) 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 end
function UISpinBox:onStyleApply(styleName, styleNode) function UISpinBox:onStyleApply(styleName, styleNode)
@ -109,14 +117,16 @@ function UISpinBox:down()
self:setValue(self.value - self.step) self:setValue(self.value - self.step)
end end
function UISpinBox:setValue(value) function UISpinBox:setValue(value, dontSignal)
value = value or 0 value = value or 0
value = math.max(math.min(self.maximum, value), self.minimum) value = math.max(math.min(self.maximum, value), self.minimum)
if value == self.value then return end if value == self.value then return end
self.value = value
if self:getText():len() > 0 then if self:getText():len() > 0 then
self:setText(value) self:setText(value)
end end
self.value = value
local upButton = self:getChildById('up') local upButton = self:getChildById('up')
local downButton = self:getChildById('down') local downButton = self:getChildById('down')
@ -127,7 +137,9 @@ function UISpinBox:setValue(value)
downButton:setEnabled(self.maximum ~= self.minimum and self.value ~= self.minimum) downButton:setEnabled(self.maximum ~= self.minimum and self.value ~= self.minimum)
end end
signalcall(self.onValueChange, self, value) if not dontSignal then
signalcall(self.onValueChange, self, value)
end
end end
function UISpinBox:getValue() function UISpinBox:getValue()

@ -144,7 +144,7 @@ end
local function clearFee() local function clearFee()
feeLabel:setText('') feeLabel:setText('')
fee = 0 fee = 20
end end
local function refreshTypeList() local function refreshTypeList()
@ -399,46 +399,55 @@ local function destroyAmountWindow()
end end
end end
local function openAmountWindow(callback, type, actionText) local function openAmountWindow(callback, actionType, actionText)
local actionText = actionText or '' if not Market.isOfferSelected(actionType) then
if not Market.isOfferSelected(type) then
return return
end end
amountWindow = g_ui.createWidget('AmountWindow', rootWidget) amountWindow = g_ui.createWidget('AmountWindow', rootWidget)
amountWindow:lock() amountWindow:lock()
local item = selectedOffer[type]:getItem()
local max = selectedOffer[type]:getAmount(item:getId()) local offer = selectedOffer[actionType]
if type == MarketAction.Sell then local item = offer:getItem()
local maximum = offer:getAmount()
if actionType == MarketAction.Sell then
local depot = Market.getDepotCount(item:getId()) local depot = Market.getDepotCount(item:getId())
if max > depot then if maximum > depot then
max = depot maximum = depot
end 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 end
local itembox = amountWindow:getChildById('item') local itembox = amountWindow:getChildById('item')
itembox:setItemId(item:getId()) itembox:setItemId(item:getId())
itembox:setText(1)
local scrollbar = amountWindow:getChildById('amountScrollBar') local scrollbar = amountWindow:getChildById('amountScrollBar')
scrollbar:setText(tostring(selectedOffer[type]:getPrice())..'gp') scrollbar:setText(offer:getPrice()..'gp')
scrollbar:setMaximum(max)
scrollbar:setMinimum(1)
scrollbar:setValue(1)
scrollbar.onValueChange = function(widget, value) scrollbar.onValueChange = function(widget, value)
widget:setText(tostring(value*selectedOffer[type]:getPrice())..'gp') widget:setText((value*offer:getPrice())..'gp')
itembox:setText(tostring(value)) itembox:setText(value)
end end
scrollbar:setRange(1, maximum)
scrollbar:setValue(1)
local okButton = amountWindow:getChildById('buttonOk') local okButton = amountWindow:getChildById('buttonOk')
if actionText ~= '' then if actionText then
okButton:setText(actionText) okButton:setText(actionText)
end end
local okFunc = function() local okFunc = function()
local counter = selectedOffer[type]:getCounter() local counter = offer:getCounter()
local timestamp = selectedOffer[type]:getTimeStamp() local timestamp = offer:getTimeStamp()
callback(scrollbar:getValue(), timestamp, counter) callback(scrollbar:getValue(), timestamp, counter)
destroyAmountWindow() destroyAmountWindow()
end end
@ -532,46 +541,47 @@ local function onChangeSlotFilter(combobox, option)
end end
local function onChangeOfferType(combobox, option) 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 if option == 'Sell' then
local max = Market.getDepotCount(id) maximum = math.min(maximum, Market.getDepotCount(item.marketData.tradeAs))
amountEdit:setMaximum(max) amountEdit:setMaximum(maximum)
else else
amountEdit:setMaximum(999999) amountEdit:setMaximum(maximum)
end end
end end
local function onTotalPriceChange() local function onTotalPriceChange()
local totalPrice = totalPriceEdit:getValue()
local piecePrice = piecePriceEdit:getValue()
local amount = amountEdit: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 if Market.isItemSelected() then
updateFee(totalPrice, amount) updateFee(piecePrice, amount)
end end
end end
local function onPiecePriceChange() local function onPiecePriceChange()
local amount = amountEdit:getValue()
local totalPrice = totalPriceEdit:getValue() local totalPrice = totalPriceEdit:getValue()
local piecePrice = piecePriceEdit:getValue() local piecePrice = piecePriceEdit:getValue()
local amount = amountEdit:getValue()
totalPriceEdit:setValue(piecePrice*amount) totalPriceEdit:setValue(piecePrice*amount, true)
if Market.isItemSelected() then if Market.isItemSelected() then
updateFee(totalPrice, amount) updateFee(piecePrice, amount)
end end
end end
local function onAmountChange() local function onAmountChange()
local totalPrice = totalPriceEdit:getValue()
local piecePrice = piecePriceEdit:getValue()
local amount = amountEdit:getValue() local amount = amountEdit:getValue()
local piecePrice = piecePriceEdit:getValue()
local totalPrice = piecePrice * amount
piecePriceEdit:setValue(math.floor(totalPrice/amount)) totalPriceEdit:setValue(piecePrice*amount, true)
totalPriceEdit:setValue(piecePrice*amount)
if Market.isItemSelected() then if Market.isItemSelected() then
updateFee(totalPrice, amount) updateFee(piecePrice, amount)
end end
end end
@ -801,7 +811,7 @@ end
function Market.clearSelectedItem() function Market.clearSelectedItem()
if Market.isItemSelected() then if Market.isItemSelected() then
Market.resetCreateOffer() Market.resetCreateOffer(true)
offerTypeList:clearOptions() offerTypeList:clearOptions()
offerTypeList:setText('Please Select') offerTypeList:setText('Please Select')
offerTypeList:setEnabled(false) offerTypeList:setEnabled(false)
@ -878,12 +888,17 @@ function Market.updateCurrentItems()
Market.loadMarketItems(id) Market.loadMarketItems(id)
end end
function Market.resetCreateOffer() function Market.resetCreateOffer(resetFee)
piecePriceEdit:setValue(1) piecePriceEdit:setValue(1)
totalPriceEdit:setValue(1) totalPriceEdit:setValue(1)
amountEdit:setValue(1) amountEdit:setValue(1)
refreshTypeList() refreshTypeList()
clearFee()
if resetFee then
clearFee()
else
updateFee(0, 0)
end
end end
function Market.refreshItemsWidget(selectItem) function Market.refreshItemsWidget(selectItem)
@ -990,8 +1005,6 @@ function Market.createNewOffer()
local spriteId = selectedItem.item.marketData.tradeAs local spriteId = selectedItem.item.marketData.tradeAs
local piecePrice = piecePriceEdit:getValue() local piecePrice = piecePriceEdit:getValue()
local totalPrice = totalPriceEdit:getValue()
local amount = amountEdit:getValue() local amount = amountEdit:getValue()
local anonymous = anonymous:isChecked() and 1 or 0 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' errorMsg = errorMsg..'Not enough balance to create this offer.\n'
end end
elseif type == MarketAction.Sell then 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 if Market.getDepotCount(spriteId) < amount then
errorMsg = errorMsg..'Not enough items in your depot to create this offer.\n' errorMsg = errorMsg..'Not enough items in your depot to create this offer.\n'
end end
@ -1012,12 +1028,21 @@ function Market.createNewOffer()
elseif piecePrice < piecePriceEdit.minimum then elseif piecePrice < piecePriceEdit.minimum then
errorMsg = errorMsg..'Price is too low.\n' errorMsg = errorMsg..'Price is too low.\n'
end end
if amount > amountEdit.maximum then if amount > amountEdit.maximum then
errorMsg = errorMsg..'Amount is too high.\n' errorMsg = errorMsg..'Amount is too high.\n'
elseif amount < amountEdit.minimum then elseif amount < amountEdit.minimum then
errorMsg = errorMsg..'Amount is too low.\n' errorMsg = errorMsg..'Amount is too low.\n'
end 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 local timeCheck = os.time() - lastCreatedOffer
if timeCheck < offerExhaust[type] then if timeCheck < offerExhaust[type] then
local waitTime = math.ceil(offerExhaust[type] - timeCheck) local waitTime = math.ceil(offerExhaust[type] - timeCheck)

@ -135,8 +135,7 @@ Panel
font: verdana-11px-rounded font: verdana-11px-rounded
text-offset: 0 2 text-offset: 0 2
anchors.top: offerTypeLabel.top anchors.top: offerTypeLabel.top
anchors.left: prev.right anchors.left: amountEdit.left
margin-left: 32
PreviousButton PreviousButton
id: prevAmountButton id: prevAmountButton
@ -147,7 +146,7 @@ Panel
SpinBox SpinBox
id: amountEdit id: amountEdit
anchors.verticalCenter: prev.verticalCenter anchors.top: prev.top
anchors.left: prev.right anchors.left: prev.right
margin-left: 3 margin-left: 3
width: 55 width: 55
@ -184,8 +183,6 @@ Panel
Label Label
id: feeLabel id: feeLabel
font: verdana-11px-rounded font: verdana-11px-rounded
text-offset: 0 2
anchors.top: createOfferButton.bottom anchors.top: createOfferButton.bottom
anchors.right: parent.right anchors.left: createOfferButton.left
margin-right: 8 margin: 2
margin-top: 3

@ -1,3 +1,8 @@
MarketMaxAmount = 2000
MarketMaxAmountStackable = 64000
MarketMaxPrice = 999999999
MarketMaxOffers = 100
MarketAction = { MarketAction = {
Buy = 0, Buy = 0,
Sell = 1 Sell = 1

Loading…
Cancel
Save