bind clock, fixes to waiting list
This commit is contained in:
parent
587db0d89f
commit
4f9ca15ef0
|
@ -6,6 +6,8 @@ local loadBox
|
||||||
local characterList
|
local characterList
|
||||||
local errorBox
|
local errorBox
|
||||||
local waitingWindow
|
local waitingWindow
|
||||||
|
local updateWaitEvent
|
||||||
|
local resendWaitEvent
|
||||||
|
|
||||||
-- private functions
|
-- private functions
|
||||||
local function tryLogin(charInfo, tries)
|
local function tryLogin(charInfo, tries)
|
||||||
|
@ -41,11 +43,12 @@ local function tryLogin(charInfo, tries)
|
||||||
Settings.set('lastUsedCharacter', charInfo.characterName)
|
Settings.set('lastUsedCharacter', charInfo.characterName)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateWait()
|
local function updateWait(timeStart, timeEnd)
|
||||||
if waitingWindow then
|
if waitingWindow then
|
||||||
if waitingWindow.elapsedTime <= waitingWindow.totalTime then
|
local time = g_clock.seconds()
|
||||||
local percent = (waitingWindow.elapsedTime / waitingWindow.totalTime) * 100
|
if time <= timeEnd then
|
||||||
local timeStr = string.format("%.0f", (waitingWindow.totalTime - waitingWindow.elapsedTime))
|
local percent = ((time - timeStart) / (timeEnd - timeStart)) * 100
|
||||||
|
local timeStr = string.format("%.0f", timeEnd - time)
|
||||||
|
|
||||||
local progressBar = waitingWindow:getChildById('progressBar')
|
local progressBar = waitingWindow:getChildById('progressBar')
|
||||||
progressBar:setPercent(percent)
|
progressBar:setPercent(percent)
|
||||||
|
@ -53,10 +56,15 @@ local function updateWait()
|
||||||
local label = waitingWindow:getChildById('timeLabel')
|
local label = waitingWindow:getChildById('timeLabel')
|
||||||
label:setText('Trying to reconnect in ' .. timeStr .. ' seconds.')
|
label:setText('Trying to reconnect in ' .. timeStr .. ' seconds.')
|
||||||
|
|
||||||
waitingWindow.elapsedTime = waitingWindow.elapsedTime + (waitingWindow.totalTime / 100)
|
updateWaitEvent = scheduleEvent(function() updateWait(timeStart, timeEnd) end, 1000 * progressBar:getPercentPixels() / 100 * (timeEnd - timeStart))
|
||||||
scheduleEvent(updateWait, (waitingWindow.totalTime / 100) * 1000)
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if updateWaitEvent then
|
||||||
|
updateWaitEvent:cancel()
|
||||||
|
updateWaitEvent = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function resendWait()
|
local function resendWait()
|
||||||
|
@ -64,6 +72,11 @@ local function resendWait()
|
||||||
waitingWindow:destroy()
|
waitingWindow:destroy()
|
||||||
waitingWindow = nil
|
waitingWindow = nil
|
||||||
|
|
||||||
|
if updateWaitEvent then
|
||||||
|
updateWaitEvent:cancel()
|
||||||
|
updateWaitEvent = nil
|
||||||
|
end
|
||||||
|
|
||||||
if charactersWindow then
|
if charactersWindow then
|
||||||
local selected = charactersWindow:getChildById('characterList'):getFocusedChild()
|
local selected = charactersWindow:getChildById('characterList'):getFocusedChild()
|
||||||
if selected then
|
if selected then
|
||||||
|
@ -77,16 +90,15 @@ local function resendWait()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onLoginWait(message, time)
|
local function onLoginWait(message, time)
|
||||||
|
CharacterList.destroyLoadBox()
|
||||||
|
|
||||||
waitingWindow = displayUI('waitinglist.otui')
|
waitingWindow = displayUI('waitinglist.otui')
|
||||||
|
|
||||||
local label = waitingWindow:getChildById('infoLabel')
|
local label = waitingWindow:getChildById('infoLabel')
|
||||||
label:setText(message)
|
label:setText(message)
|
||||||
|
|
||||||
waitingWindow.elapsedTime = 0
|
updateWaitEvent = scheduleEvent(function() updateWait(g_clock.seconds(), g_clock.seconds() + time) end, 0)
|
||||||
waitingWindow.totalTime = time
|
resendWaitEvent = scheduleEvent(resendWait, time * 1000)
|
||||||
|
|
||||||
scheduleEvent(updateWait, 0)
|
|
||||||
scheduleEvent(resendWait, time * 1000)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onCharactersWindowKeyPress(self, keyCode, keyboardModifiers)
|
local function onCharactersWindowKeyPress(self, keyCode, keyboardModifiers)
|
||||||
|
@ -151,6 +163,22 @@ function CharacterList.terminate()
|
||||||
loadBox:destroy()
|
loadBox:destroy()
|
||||||
loadBox = nil
|
loadBox = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if waitingWindow then
|
||||||
|
waitingWindow:destroy()
|
||||||
|
waitingWindow = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if updateWaitEvent then
|
||||||
|
updateWaitEvent:cancel()
|
||||||
|
updateWaitEvent = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if resendWaitEvent then
|
||||||
|
resendWaitEvent:cancel()
|
||||||
|
resendWaitEvent = nil
|
||||||
|
end
|
||||||
|
|
||||||
CharacterList = nil
|
CharacterList = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -245,7 +273,18 @@ function CharacterList.cancelWait()
|
||||||
if waitingWindow then
|
if waitingWindow then
|
||||||
waitingWindow:destroy()
|
waitingWindow:destroy()
|
||||||
waitingWindow = nil
|
waitingWindow = nil
|
||||||
CharacterList.destroyLoadBox()
|
|
||||||
CharacterList.showAgain()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if updateWaitEvent then
|
||||||
|
updateWaitEvent:cancel()
|
||||||
|
updateWaitEvent = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if resendWaitEvent then
|
||||||
|
resendWaitEvent:cancel()
|
||||||
|
resendWaitEvent = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
CharacterList.destroyLoadBox()
|
||||||
|
CharacterList.showAgain()
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
function math.round(num, idp)
|
||||||
|
local mult = 10^(idp or 0)
|
||||||
|
if num >= 0 then
|
||||||
|
return math.floor(num * mult + 0.5) / mult
|
||||||
|
else
|
||||||
|
return math.ceil(num * mult - 0.5) / mult
|
||||||
|
end
|
||||||
|
end
|
|
@ -19,8 +19,12 @@ function UIProgressBar:getPercent()
|
||||||
return self.percent
|
return self.percent
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UIProgressBar:getPercentPixels()
|
||||||
|
return 100 / self:getWidth()
|
||||||
|
end
|
||||||
|
|
||||||
function UIProgressBar:updateBackground()
|
function UIProgressBar:updateBackground()
|
||||||
local width = math.max((self.percent * self:getWidth())/100, 1)
|
local width = math.round(math.max((self.percent * self:getWidth())/100, 1))
|
||||||
local height = self:getHeight()
|
local height = self:getHeight()
|
||||||
self:setBackgroundSize({width=width, height=height})
|
self:setBackgroundSize({width=width, height=height})
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,6 +52,11 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassStaticFunction("g_crypt", "encrypt", Crypt::encrypt);
|
g_lua.bindClassStaticFunction("g_crypt", "encrypt", Crypt::encrypt);
|
||||||
g_lua.bindClassStaticFunction("g_crypt", "decrypt", Crypt::decrypt);
|
g_lua.bindClassStaticFunction("g_crypt", "decrypt", Crypt::decrypt);
|
||||||
|
|
||||||
|
g_lua.registerStaticClass("g_clock");
|
||||||
|
g_lua.bindClassStaticFunction("g_clock", "micros", std::bind(&Clock::micros, &g_clock));
|
||||||
|
g_lua.bindClassStaticFunction("g_clock", "millis", std::bind(&Clock::millis, &g_clock));
|
||||||
|
g_lua.bindClassStaticFunction("g_clock", "seconds", std::bind(&Clock::seconds, &g_clock));
|
||||||
|
|
||||||
// Event
|
// Event
|
||||||
g_lua.registerClass<Event>();
|
g_lua.registerClass<Event>();
|
||||||
g_lua.bindClassMemberFunction<Event>("cancel", &Event::cancel);
|
g_lua.bindClassMemberFunction<Event>("cancel", &Event::cancel);
|
||||||
|
|
Loading…
Reference in New Issue