2012-07-24 07:30:08 +02:00
deathWindow = nil
2012-07-14 12:59:32 +02:00
2015-03-07 06:09:00 +01:00
local deathTexts = {
regular = { text = ' Alas! Brave adventurer, you have met a sad fate. \n But do not despair, for the gods will bring you back \n into this world in exchange for a small sacrifice \n \n Simply click on Ok to resume your journeys! ' , height = 140 , width = 0 } ,
unfair = { text = ' Alas! Brave adventurer, you have met a sad fate. \n But do not despair, for the gods will bring you back \n into this world in exchange for a small sacrifice \n \n This death penalty has been reduced by %i%% \n because it was an unfair fight. \n \n Simply click on Ok to resume your journeys! ' , height = 185 , width = 0 } ,
blessed = { text = ' Alas! Brave adventurer, you have met a sad fate. \n But do not despair, for the gods will bring you back into this world \n \n This death penalty has been reduced by 100% \n because you are blessed with the Adventurer \' s Blessing \n \n Simply click on Ok to resume your journeys! ' , height = 170 , width = 90 }
}
2012-07-24 07:30:08 +02:00
function init ( )
2013-01-18 23:39:11 +01:00
g_ui.importStyle ( ' deathwindow ' )
2012-07-19 11:12:17 +02:00
2012-07-24 07:30:08 +02:00
connect ( g_game , { onDeath = display ,
onGameEnd = reset } )
2012-07-14 12:59:32 +02:00
end
2012-07-24 07:30:08 +02:00
function terminate ( )
disconnect ( g_game , { onDeath = display ,
onGameEnd = reset } )
2012-07-14 12:59:32 +02:00
2012-07-24 07:30:08 +02:00
reset ( )
2012-07-14 12:59:32 +02:00
end
2012-07-24 07:30:08 +02:00
function reset ( )
2012-07-15 13:49:28 +02:00
if deathWindow then
2012-07-14 12:59:32 +02:00
deathWindow : destroy ( )
2013-11-12 15:19:45 +01:00
deathWindow = nil
2012-07-14 12:59:32 +02:00
end
end
2015-03-07 06:09:00 +01:00
function display ( deathType , penalty )
2012-07-24 07:30:08 +02:00
displayDeadMessage ( )
2015-03-07 06:09:00 +01:00
openWindow ( deathType , penalty )
2012-07-14 12:59:32 +02:00
end
2012-07-24 07:30:08 +02:00
function displayDeadMessage ( )
2012-07-31 02:57:31 +02:00
local advanceLabel = modules.game_interface . getRootPanel ( ) : recursiveGetChildById ( ' middleCenterLabel ' )
if advanceLabel : isVisible ( ) then return end
2012-07-19 11:12:17 +02:00
2012-07-26 11:12:20 +02:00
modules.game_textmessage . displayGameMessage ( tr ( ' You are dead. ' ) )
2012-07-14 12:59:32 +02:00
end
2015-03-07 06:09:00 +01:00
function openWindow ( deathType , penalty )
2013-02-27 13:01:51 +01:00
if deathWindow then
deathWindow : destroy ( )
return
end
2015-03-07 06:09:00 +01:00
2012-07-14 12:59:32 +02:00
deathWindow = g_ui.createWidget ( ' DeathWindow ' , rootWidget )
2015-03-07 06:09:00 +01:00
local textLabel = deathWindow : getChildById ( ' labelText ' )
if deathType == DeathType.Regular then
if penalty == 100 then
textLabel : setText ( deathTexts.regular . text )
deathWindow : setHeight ( deathWindow.baseHeight + deathTexts.regular . height )
deathWindow : setWidth ( deathWindow.baseWidth + deathTexts.regular . width )
else
textLabel : setText ( string.format ( deathTexts.unfair . text , 100 - penalty ) )
deathWindow : setHeight ( deathWindow.baseHeight + deathTexts.unfair . height )
deathWindow : setWidth ( deathWindow.baseWidth + deathTexts.unfair . width )
end
elseif deathType == DeathType.Blessed then
textLabel : setText ( deathTexts.blessed . text )
deathWindow : setHeight ( deathWindow.baseHeight + deathTexts.blessed . height )
deathWindow : setWidth ( deathWindow.baseWidth + deathTexts.blessed . width )
end
2012-07-14 12:59:32 +02:00
local okButton = deathWindow : getChildById ( ' buttonOk ' )
local cancelButton = deathWindow : getChildById ( ' buttonCancel ' )
local okFunc = function ( )
CharacterList.doLogin ( )
okButton : getParent ( ) : destroy ( )
deathWindow = nil
end
local cancelFunc = function ( )
2013-07-02 22:40:19 +02:00
g_game.safeLogout ( )
2012-07-14 12:59:32 +02:00
cancelButton : getParent ( ) : destroy ( )
deathWindow = nil
end
deathWindow.onEnter = okFunc
deathWindow.onEscape = cancelFunc
2012-07-19 11:12:17 +02:00
2012-07-14 12:59:32 +02:00
okButton.onClick = okFunc
cancelButton.onClick = cancelFunc
2012-07-24 07:30:08 +02:00
end