No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

playerdeath.lua 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. deathWindow = nil
  2. function init()
  3. g_ui.importStyle('deathwindow')
  4. connect(g_game, { onDeath = display,
  5. onGameEnd = reset })
  6. end
  7. function terminate()
  8. disconnect(g_game, { onDeath = display,
  9. onGameEnd = reset })
  10. reset()
  11. end
  12. function reset()
  13. if deathWindow then
  14. deathWindow:destroy()
  15. end
  16. end
  17. function display()
  18. displayDeadMessage()
  19. openWindow()
  20. end
  21. function displayDeadMessage()
  22. local advanceLabel = modules.game_interface.getRootPanel():recursiveGetChildById('middleCenterLabel')
  23. if advanceLabel:isVisible() then return end
  24. modules.game_textmessage.displayGameMessage(tr('You are dead.'))
  25. end
  26. function openWindow()
  27. if deathWindow then
  28. deathWindow:destroy()
  29. return
  30. end
  31. deathWindow = g_ui.createWidget('DeathWindow', rootWidget)
  32. local okButton = deathWindow:getChildById('buttonOk')
  33. local cancelButton = deathWindow:getChildById('buttonCancel')
  34. local okFunc = function()
  35. CharacterList.doLogin()
  36. okButton:getParent():destroy()
  37. deathWindow = nil
  38. end
  39. local cancelFunc = function()
  40. g_game.safeLogout()
  41. cancelButton:getParent():destroy()
  42. deathWindow = nil
  43. end
  44. deathWindow.onEnter = okFunc
  45. deathWindow.onEscape = cancelFunc
  46. okButton.onClick = okFunc
  47. cancelButton.onClick = cancelFunc
  48. end