manager.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ########################################################################
  2. # Hello Worlds - Libre 3D RPG game.
  3. # Copyright (C) 2020 CYBERDEViL
  4. #
  5. # This file is part of Hello Worlds.
  6. #
  7. # Hello Worlds is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # Hello Worlds is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. ########################################################################
  21. from ui.startMenu import UI_StartMenu
  22. from ui.game import UI_CreatureInfoBox, UI_SpellBar, UI_PlayerInfoBox, UI_ItemInfo, UI_ActionMessages
  23. class UI_Manager:
  24. def __init__(self):
  25. self._startMenu = UI_StartMenu(base.luiRegion.root)
  26. self._hasGameUI = False
  27. self._npcInfoBox = None
  28. self._spellBar = None
  29. self._playerInfoBox = None
  30. self._spellInfoFrame = None
  31. self._actionMessenger = None
  32. ## Holds a model for a core.game.UI_Item while dragging.
  33. self._dragModel = None
  34. @property
  35. def actionMessenger(self): return self._actionMessenger
  36. @property
  37. def npcInfoBox(self): return self._npcInfoBox
  38. @property
  39. def spellInfoFrame(self): return self._spellInfoFrame
  40. @property
  41. def startMenu(self): return self._startMenu
  42. @property
  43. def dragModel(self): return self._dragModel
  44. @dragModel.setter
  45. def dragModel(self, model):
  46. if model and self._dragModel:
  47. print("WARNING! Trying to set a dragModel of type ({}) in UI_Manager, but there is already one set of type ({}).".format(type(model), type(self._dragModel)))
  48. return
  49. self._dragModel = model
  50. def characterChanged(self):
  51. self._spellBar.characterChanged()
  52. self._playerInfoBox.characterChanged()
  53. def destroyGameUI(self):
  54. if self._hasGameUI:
  55. self._npcInfoBox.close()
  56. self._spellBar.close()
  57. self._playerInfoBox.close()
  58. self._spellInfoFrame.close()
  59. self._actionMessenger.close()
  60. self._npcInfoBox = None
  61. self._spellBar = None
  62. self._playerInfoBox = None
  63. self._spellInfoFrame = None
  64. self._actionMessenger = None
  65. self._hasGameUI = False
  66. def loadGameUI(self):
  67. self._npcInfoBox = UI_CreatureInfoBox()
  68. self._spellBar = UI_SpellBar(parent=base.luiRegion.root)
  69. self._playerInfoBox = UI_PlayerInfoBox(parent=base.luiRegion.root)
  70. self._spellInfoFrame = UI_ItemInfo(parent=base.luiRegion.root)
  71. self._actionMessenger = UI_ActionMessages(parent=base.luiRegion.root)
  72. self._hasGameUI = True
  73. def hasMouse(self):
  74. if self._startMenu.hasMouse():
  75. return True
  76. if (self._hasGameUI and (self._npcInfoBox.hasMouse()
  77. or self._spellBar.hasMouse()
  78. or self._playerInfoBox.hasMouse())):
  79. return True
  80. return False
  81. def close(self):
  82. self._startMenu.close()
  83. self._startMenu = None