This commit is contained in:
commit
b50eecc779
|
@ -21,6 +21,18 @@ function destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function getCursorPosByNewLine(str, count)
|
||||||
|
local i = 0
|
||||||
|
for n = 1, count-1 do
|
||||||
|
local tPos = string.find(str, '\n', i)
|
||||||
|
if tPos then
|
||||||
|
i = tPos+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return i - 1
|
||||||
|
end
|
||||||
|
|
||||||
function onGameEditText(id, itemId, maxLength, text, writter, time)
|
function onGameEditText(id, itemId, maxLength, text, writter, time)
|
||||||
if textWindow then return end
|
if textWindow then return end
|
||||||
textWindow = g_ui.createWidget('TextWindow', rootWidget)
|
textWindow = g_ui.createWidget('TextWindow', rootWidget)
|
||||||
|
@ -32,11 +44,13 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
|
||||||
local okButton = textWindow:getChildById('okButton')
|
local okButton = textWindow:getChildById('okButton')
|
||||||
local cancelButton = textWindow:getChildById('cancelButton')
|
local cancelButton = textWindow:getChildById('cancelButton')
|
||||||
|
|
||||||
|
local textScroll = textWindow:getChildById('textScroll')
|
||||||
|
|
||||||
textItem:setItemId(itemId)
|
textItem:setItemId(itemId)
|
||||||
textEdit:setMaxLength(maxLength)
|
textEdit:setMaxLength(maxLength)
|
||||||
textEdit:setText(text)
|
textEdit:setText(text)
|
||||||
textEdit:setEnabled(writeable)
|
textEdit:setEnabled(writeable)
|
||||||
|
|
||||||
local desc = ''
|
local desc = ''
|
||||||
if #writter > 0 then
|
if #writter > 0 then
|
||||||
desc = tr('You read the following, written by \n%s\n', writter)
|
desc = tr('You read the following, written by \n%s\n', writter)
|
||||||
|
@ -74,7 +88,38 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
|
||||||
end
|
end
|
||||||
destroy()
|
destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local _, newLineCount = string.gsub(text, '\n', '\n')
|
||||||
|
if(newLineCount >= 9) then
|
||||||
|
textScroll:setMaximum(newLineCount-9)
|
||||||
|
end
|
||||||
|
|
||||||
|
local _prev, _next, _current = 0, 11, 0
|
||||||
|
local onValueChange = function()
|
||||||
|
local diff = textScroll:getValue() - _current
|
||||||
|
|
||||||
|
if(diff > 0) then
|
||||||
|
textEdit:setCursorPos(getCursorPosByNewLine(text, _next+(diff-1)))
|
||||||
|
else
|
||||||
|
textEdit:setCursorPos(getCursorPosByNewLine(text, _prev+(diff+1)))
|
||||||
|
end
|
||||||
|
|
||||||
|
_current = textScroll:getValue()
|
||||||
|
_next = _next + diff
|
||||||
|
_prev = _prev + diff
|
||||||
|
end
|
||||||
|
|
||||||
|
textScroll.onValueChange = onValueChange
|
||||||
|
g_keyboard.bindKeyPress("Up", function() textScroll:setValue(textScroll:getValue()-1) end, textWindow, 400)
|
||||||
|
g_keyboard.bindKeyPress("Down", function() textScroll:setValue(textScroll:getValue()+1) end, textWindow, 400)
|
||||||
|
|
||||||
|
if(not writeable) then
|
||||||
|
textEdit:setCursorPos(0)
|
||||||
|
else
|
||||||
|
textScroll:setValue(textScroll:getMaximum())
|
||||||
|
textEdit:setCursorPos(text:len())
|
||||||
|
end
|
||||||
|
|
||||||
okButton.onClick = doneFunc
|
okButton.onClick = doneFunc
|
||||||
cancelButton.onClick = destroy
|
cancelButton.onClick = destroy
|
||||||
--textWindow.onEnter = doneFunc -- this should be '\n'
|
--textWindow.onEnter = doneFunc -- this should be '\n'
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
TextScrollbar < VerticalScrollBar
|
||||||
|
|
||||||
TextWindow < MainWindow
|
TextWindow < MainWindow
|
||||||
id: textWindow
|
id: textWindow
|
||||||
size: 280 280
|
size: 280 280
|
||||||
|
@ -24,9 +26,21 @@ TextWindow < MainWindow
|
||||||
id: text
|
id: text
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.top: textItem.bottom
|
anchors.top: textItem.bottom
|
||||||
|
margin-right: 10
|
||||||
margin-top: 30
|
margin-top: 30
|
||||||
margin-bottom: 30
|
margin-bottom: 30
|
||||||
|
|
||||||
|
TextScrollbar
|
||||||
|
id: textScroll
|
||||||
|
anchors.left: prev.right
|
||||||
|
anchors.top: prev.top
|
||||||
|
anchors.bottom: prev.bottom
|
||||||
|
minimum: 0
|
||||||
|
maximum: 0
|
||||||
|
step: 1
|
||||||
|
value: 0
|
||||||
|
pixels-scroll: true
|
||||||
|
|
||||||
Button
|
Button
|
||||||
id: cancelButton
|
id: cancelButton
|
||||||
!text: tr('Cancel')
|
!text: tr('Cancel')
|
||||||
|
@ -42,4 +56,4 @@ TextWindow < MainWindow
|
||||||
anchors.top: text.bottom
|
anchors.top: text.bottom
|
||||||
anchors.right: text.right
|
anchors.right: text.right
|
||||||
margin-top: 10
|
margin-top: 10
|
||||||
width: 60
|
width: 60
|
Loading…
Reference in New Issue