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_widgets/uispinbox.lua b/modules/core_widgets/uispinbox.lua index 5c060fa3..a6521d96 100644 --- a/modules/core_widgets/uispinbox.lua +++ b/modules/core_widgets/uispinbox.lua @@ -6,13 +6,16 @@ function UISpinBox.create() spinbox.m_minimum = 0 spinbox.m_maximum = 0 spinbox:setCurrentIndex(0) + spinbox:setText("0") return spinbox end function UISpinBox:setCurrentIndex(index) if index >= self.m_minimum and index <= self.m_maximum then + if self:getText():len() > 0 then + self:setText(index) + end self.m_currentIndex = index - self:setText(index) self:onIndexChange(index) end end @@ -52,14 +55,34 @@ function UISpinBox:onMouseWheel(mousePos, direction) return true end -function UISpinBox:onTextChange(text) +function UISpinBox:onTextChange(text, oldText) + + if text:len() == 0 then + self:setCurrentIndex(self.m_minimum) + return + end + 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) + self:setText(oldText) + return end + + self:setCurrentIndex(number) end function UISpinBox:onIndexChange(index) -- nothing todo end + +function UISpinBox:onStyleApply(styleName, styleNode) + -- tonumber converts to 0 if not valid + if styleNode.maximum and tonumber(styleNode.maximum) then + self:setMaximum(tonumber(styleNode.maximum)) + end + + if styleNode.minimum and tonumber(styleNode.minimum) then + self:setMinimum(tonumber(styleNode.minimum)) + end +end + diff --git a/modules/game/game.otui b/modules/game/game.otui index 461c7b5d..baa5ca45 100644 --- a/modules/game/game.otui +++ b/modules/game/game.otui @@ -30,4 +30,5 @@ UIGame id: mouseGrabber focusable: false visible: false - phantom: true \ No newline at end of file + phantom: true + diff --git a/src/framework/ui/uilineedit.cpp b/src/framework/ui/uilineedit.cpp index 5ab397cd..1825505e 100644 --- a/src/framework/ui/uilineedit.cpp +++ b/src/framework/ui/uilineedit.cpp @@ -285,11 +285,12 @@ void UILineEdit::appendText(std::string text) } } + std::string oldText = m_text; m_text.insert(m_cursorPos, text); m_cursorPos += text.length(); blinkCursor(); update(); - UIWidget::onTextChange(m_text); + UIWidget::onTextChange(m_text, oldText); } } } @@ -305,16 +306,18 @@ void UILineEdit::appendCharacter(char c) std::string tmp; tmp = c; + std::string oldText = m_text; m_text.insert(m_cursorPos, tmp); m_cursorPos++; blinkCursor(); update(); - UIWidget::onTextChange(m_text); + UIWidget::onTextChange(m_text, oldText); } } void UILineEdit::removeCharacter(bool right) { + std::string oldText = m_text; if(m_cursorPos >= 0 && m_text.length() > 0) { if((uint)m_cursorPos >= m_text.length()) { m_text.erase(m_text.begin() + (--m_cursorPos)); @@ -326,7 +329,7 @@ void UILineEdit::removeCharacter(bool right) } blinkCursor(); update(); - UIWidget::onTextChange(m_text); + UIWidget::onTextChange(m_text, oldText); } } @@ -376,12 +379,12 @@ std::string UILineEdit::getDisplayedText() return m_text; } -void UILineEdit::onTextChange(const std::string& text) +void UILineEdit::onTextChange(const std::string& text, const std::string& oldText) { m_cursorPos = text.length(); blinkCursor(); update(); - UIWidget::onTextChange(text); + UIWidget::onTextChange(text, oldText); } void UILineEdit::onFontChange(const std::string& font) diff --git a/src/framework/ui/uilineedit.h b/src/framework/ui/uilineedit.h index 7ce674a2..1754c9b9 100644 --- a/src/framework/ui/uilineedit.h +++ b/src/framework/ui/uilineedit.h @@ -57,7 +57,7 @@ public: bool isTextHidden() { return m_textHidden; } protected: - virtual void onTextChange(const std::string& text); + virtual void onTextChange(const std::string& text, const std::string& oldText); virtual void onFontChange(const std::string& font); virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect); diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 50379cce..a523d57f 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -426,7 +426,7 @@ private: protected: void drawText(const Rect& screenCoords); - virtual void onTextChange(const std::string& text); + virtual void onTextChange(const std::string& text, const std::string& oldText); virtual void onFontChange(const std::string& font); std::string m_text; diff --git a/src/framework/ui/uiwidgettext.cpp b/src/framework/ui/uiwidgettext.cpp index 87e95af6..ad386ee6 100644 --- a/src/framework/ui/uiwidgettext.cpp +++ b/src/framework/ui/uiwidgettext.cpp @@ -74,9 +74,9 @@ void UIWidget::drawText(const Rect& screenCoords) m_textFramebuffer->draw(screenCoords); } -void UIWidget::onTextChange(const std::string& text) +void UIWidget::onTextChange(const std::string& text, const std::string& oldText) { - callLuaField("onTextChange", text); + callLuaField("onTextChange", text, oldText); } void UIWidget::onFontChange(const std::string& font) @@ -94,6 +94,7 @@ void UIWidget::setText(const std::string& text) if(m_text == text) return; + std::string oldText = m_text; m_text = text; // update rect size @@ -107,7 +108,7 @@ void UIWidget::setText(const std::string& text) setSize(newSize); } - onTextChange(text); + onTextChange(text, oldText); m_textMustRecache = true; }