54 lines
1.7 KiB
Plaintext
54 lines
1.7 KiB
Plaintext
|
function onLoad()
|
||
|
self.createInput({
|
||
|
input_function = "jumpToPage",
|
||
|
function_owner = self,
|
||
|
label = "jump to page",
|
||
|
alignment = 3,
|
||
|
position = Vector(-1.6,0.1,-2.2),
|
||
|
rotation = Vector(0,0,0),
|
||
|
scale = Vector(0.5,0.5,0.5),
|
||
|
width = 2000,
|
||
|
height = 300,
|
||
|
font_size = 250,
|
||
|
font_color = {0.95,0.95,0.95,0.9},
|
||
|
color = {0.3,0.3,0.3,0.6},
|
||
|
tooltip = "Type which page you wish to jump to, then click off",
|
||
|
value = "",
|
||
|
validation = 1,
|
||
|
tab = 1,
|
||
|
})
|
||
|
end
|
||
|
|
||
|
function jumpToPage(_, _, inputValue, stillEditing)
|
||
|
if inputValue == "" or inputValue == nil then return end -- do nothing if input is empty
|
||
|
|
||
|
if not stillEditing then -- jump to page if not selecting the textbox anymore
|
||
|
jump((tonumber(inputValue) + 2)/2)
|
||
|
return
|
||
|
elseif string.find(inputValue, "%\n") ~= nil then -- jump to page if enter is pressed
|
||
|
inputValue = inputValue.gsub(inputValue, "%\n", "")
|
||
|
jump((tonumber(inputValue) + 2)/2)
|
||
|
return
|
||
|
end
|
||
|
|
||
|
if (tonumber(inputValue:sub(-1)) == nil) then -- check and remove non numeric character
|
||
|
Wait.time(function()
|
||
|
self.editInput({
|
||
|
index = 0,
|
||
|
value = inputValue:sub(1,-2)
|
||
|
})
|
||
|
end, 0.01)
|
||
|
return
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function jump(page)
|
||
|
self.Book.setPage(page - 1) -- offset since 0 index
|
||
|
Wait.time(function() -- clear page search
|
||
|
self.editInput({
|
||
|
index = 0,
|
||
|
value = "",
|
||
|
})
|
||
|
end, 0.01)
|
||
|
end
|