diff --git a/modules/client_tibiafiles b/modules/client_tibiafiles index 9beb17da..dd648e14 160000 --- a/modules/client_tibiafiles +++ b/modules/client_tibiafiles @@ -1 +1 @@ -Subproject commit 9beb17daaeb170c127c39c5a5e4feb9d95ebed92 +Subproject commit dd648e1431171bffe091b748744395780df7eba1 diff --git a/modules/core_styles/core_styles.otmod b/modules/core_styles/core_styles.otmod index 4ca1c408..6858dec0 100644 --- a/modules/core_styles/core_styles.otmod +++ b/modules/core_styles/core_styles.otmod @@ -19,3 +19,4 @@ Module importStyle 'styles/creatures.otui' importStyle 'styles/popupmenus.otui' importStyle 'styles/comboboxes.otui' + importStyle 'styles/spinboxes.otui' diff --git a/modules/core_styles/styles/spinboxes.otui b/modules/core_styles/styles/spinboxes.otui new file mode 100644 index 00000000..f9cd80ca --- /dev/null +++ b/modules/core_styles/styles/spinboxes.otui @@ -0,0 +1,10 @@ +SpinBox < UISpinBox + font: verdana-11px-antialised + color: #aaaaaa + size: 86 20 + text-margin: 3 + image-source: /core_styles/images/panel_flat.png + image-border: 1 + + $disabled: + color: #aaaaaa88 diff --git a/modules/core_widgets/core_widgets.otmod b/modules/core_widgets/core_widgets.otmod index 62e085d3..635ea906 100644 --- a/modules/core_widgets/core_widgets.otmod +++ b/modules/core_widgets/core_widgets.otmod @@ -10,6 +10,7 @@ Module require 'uilabel' require 'uicheckbox' require 'uicombobox' + require 'uispinbox' require 'uiprogressbar' require 'uitabbar' require 'uipopupmenu' diff --git a/modules/core_widgets/uiitem.lua b/modules/core_widgets/uiitem.lua index 70dac2bf..ebb41d41 100644 --- a/modules/core_widgets/uiitem.lua +++ b/modules/core_widgets/uiitem.lua @@ -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 diff --git a/modules/core_widgets/uispinbox.lua b/modules/core_widgets/uispinbox.lua new file mode 100644 index 00000000..8a6f0b97 --- /dev/null +++ b/modules/core_widgets/uispinbox.lua @@ -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 diff --git a/modules/game/map.lua b/modules/game/map.lua index f366b4e1..33b5cf24 100644 --- a/modules/game/map.lua +++ b/modules/game/map.lua @@ -5,13 +5,17 @@ function UIMap:onDragEnter(mousePos) local thing = tile:getTopMoveThing() if not thing then return false end + self.parsed = false self.currentDragThing = thing setTargetCursor() return true end function UIMap:onDragLeave(widget, mousePos) - self.currentDragThing = nil + if not self.parsed then + self.currentDragThing = nil + end + restoreCursor() return true end @@ -21,9 +25,23 @@ function UIMap:onDrop(widget, mousePos) local tile = self:getTile(mousePos) if not tile then return false end - 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, tile:getPos(), spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end + moveWindow.onEnter = okButton.onClick + else + Game.move(widget.currentDragThing, tile:getPos(), 1) + end - Game.move(widget.currentDragThing, tile:getPos(), count) return true end diff --git a/modules/game/movewindow.otui b/modules/game/movewindow.otui new file mode 100644 index 00000000..0371ad9a --- /dev/null +++ b/modules/game/movewindow.otui @@ -0,0 +1,40 @@ +MainWindow + text: Move Item + size: 196 112 + @onEscape: self:getParent():destroy() + + Label + text: Amount: + width: 64 + anchors.left: parent.left + anchors.top: parent.top + margin-top: 2 + + SpinBox + id: spinbox + anchors.left: prev.right + anchors.right: parent.right + anchors.top: parent.top + + HorizontalSeparator + id: separator + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: next.top + margin-bottom: 10 + + Button + id: buttonOk + text: Ok + width: 64 + anchors.right: next.left + anchors.bottom: parent.bottom + margin-right: 10 + + Button + id: buttonCancel + text: Cancel + width: 64 + anchors.right: parent.right + anchors.bottom: parent.bottom + @onClick: self:getParent():destroy() diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 922b9b28..24397901 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -338,6 +338,7 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("setCursorEnabled", &UILineEdit::setCursorEnabled); g_lua.bindClassMemberFunction("setTextHidden", &UILineEdit::setTextHidden); g_lua.bindClassMemberFunction("setAlwaysActive", &UILineEdit::setAlwaysActive); + g_lua.bindClassMemberFunction("setValidCharacters", &UILineEdit::setValidCharacters); g_lua.bindClassMemberFunction("moveCursor", &UILineEdit::moveCursor); g_lua.bindClassMemberFunction("appendText", &UILineEdit::appendText); g_lua.bindClassMemberFunction("removeCharacter", &UILineEdit::removeCharacter); diff --git a/src/framework/ui/uilineedit.cpp b/src/framework/ui/uilineedit.cpp index 6c56f0c4..5ab397cd 100644 --- a/src/framework/ui/uilineedit.cpp +++ b/src/framework/ui/uilineedit.cpp @@ -276,6 +276,15 @@ void UILineEdit::appendText(std::string text) boost::replace_all(text, "\r", " "); if(text.length() > 0) { + + // only ignore text append if it contains invalid characters + if(m_validCharacters.size() > 0) { + for(uint i = 0; i < text.size(); ++i) { + if(m_validCharacters.find(text[i]) == std::string::npos) + return; + } + } + m_text.insert(m_cursorPos, text); m_cursorPos += text.length(); blinkCursor(); @@ -291,6 +300,9 @@ void UILineEdit::appendCharacter(char c) return; if(m_cursorPos >= 0) { + if(m_validCharacters.size() > 0 && m_validCharacters.find(c) == std::string::npos) + return; + std::string tmp; tmp = c; m_text.insert(m_cursorPos, tmp); diff --git a/src/framework/ui/uilineedit.h b/src/framework/ui/uilineedit.h index e65cfda2..7ce674a2 100644 --- a/src/framework/ui/uilineedit.h +++ b/src/framework/ui/uilineedit.h @@ -41,6 +41,7 @@ public: void setCursorEnabled(bool enable); void setTextHidden(bool hidden); void setAlwaysActive(bool enable); + void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; } void moveCursor(bool right); void appendText(std::string text); @@ -76,6 +77,7 @@ private: int m_textHorizontalMargin; bool m_textHidden; bool m_alwaysActive; + std::string m_validCharacters; std::vector m_glyphsCoords; std::vector m_glyphsTexCoords;