move window

This commit is contained in:
Henrique Santiago
2012-01-25 23:11:05 -02:00
parent cfcc3fd428
commit 1983a08cbe
11 changed files with 182 additions and 7 deletions

View File

@@ -10,6 +10,7 @@ Module
require 'uilabel'
require 'uicheckbox'
require 'uicombobox'
require 'uispinbox'
require 'uiprogressbar'
require 'uitabbar'
require 'uipopupmenu'

View File

@@ -4,13 +4,17 @@ function UIItem:onDragEnter(mousePos)
self:setBorderWidth(1)
self.parsed = false
self.currentDragThing = item
setTargetCursor()
return true
end
function UIItem:onDragLeave(widget, mousePos)
self.currentDragThing = nil
if not self.parsed then
self.currentDragThing = nil
end
restoreCursor()
self:setBorderWidth(0)
return true
@@ -20,9 +24,22 @@ function UIItem:onDrop(widget, mousePos)
if not widget or not widget.currentDragThing then return false end
local pos = self.position
local count = widget.currentDragThing:getData()
local data = widget.currentDragThing:getData()
if widget.currentDragThing:isStackable() and data > 1 then
widget.parsed = true
local moveWindow = displayUI('/game/movewindow.otui')
local spinbox = moveWindow:getChildById('spinbox')
spinbox:setMaximum(data)
spinbox:setMinimum(1)
spinbox:setCurrentIndex(data)
local okButton = moveWindow:getChildById('buttonOk')
okButton.onClick = function() Game.move(widget.currentDragThing, pos, spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
moveWindow.onEnter = okButton.onClick
else
Game.move(widget.currentDragThing, pos, 1)
end
Game.move(widget.currentDragThing, pos, count)
self:setBorderWidth(0)
return true
end

View File

@@ -0,0 +1,73 @@
UISpinBox = extends(UILineEdit)
function UISpinBox.create()
local spinbox = UISpinBox.internalCreate()
spinbox:setValidCharacters('0123456789')
spinbox.m_minimum = 0
spinbox.m_maximum = 0
spinbox:setCurrentIndex(0)
return spinbox
end
function UISpinBox:setCurrentIndex(index)
if index >= self.m_minimum and index <= self.m_maximum then
self.m_currentIndex = index
self:setText(index)
self:onIndexChange(index)
end
end
function UISpinBox:setMinimum(minimum)
if minimum > self.m_maximum then
print("[UISpinBox:setMinimum]: minimum value cant be greater than maximum")
return false
end
if self.m_currentIndex < minimum then
self:setCurrentIndex(minimum)
end
self.m_minimum = minimum
end
function UISpinBox:setMaximum(maximum)
if maximum < self.m_minimum then
print("[UISpinBox:setMaximum]: maximum value cant be lower than minimum")
return false
end
if self.m_currentIndex > maximum then
self:setCurrentIndex(maximum)
end
self.m_maximum = maximum
end
function UISpinBox:getCurrentIndex()
return self.m_currentIndex
end
function UISpinBox:onMouseWheel(mousePos, direction)
if direction == MouseWheelUp then
self:setCurrentIndex(self.m_currentIndex + 1)
elseif direction == MouseWheelDown then
self:setCurrentIndex(self.m_currentIndex - 1)
end
return true
end
function UISpinBox:onStyleApply(styleName, styleNode)
if styleNode.options then
for k,option in pairs(styleNode.options) do
self:addOption(option)
end
end
end
function UISpinBox:onTextChange(text)
local number = tonumber(text)
if not number or number > self.m_maximum or number < self.m_minimum then
-- todo: restore old text instead of setting minimum
self:setCurrentIndex(self.m_minimum)
end
end
function UISpinBox:onIndexChange(index)
-- nothing todo
end