########################################################################
#	Hello Worlds - Libre 3D RPG game.
#	Copyright (C) 2020  CYBERDEViL
#
#	This file is part of Hello Worlds.
#
#	Hello Worlds is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	Hello Worlds is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
########################################################################


from ui.startMenu import UI_StartMenu
from ui.game import UI_CreatureInfoBox, UI_SpellBar, UI_PlayerInfoBox, UI_ItemInfo, UI_ActionMessages

class UI_Manager:
	def __init__(self):
		self._startMenu = UI_StartMenu(base.luiRegion.root)

		self._hasGameUI = False
		self._npcInfoBox = None
		self._spellBar = None
		self._playerInfoBox = None
		self._spellInfoFrame = None

		self._actionMessenger = None

		## Holds a model for a core.game.UI_Item while dragging.
		self._dragModel = None

	@property
	def actionMessenger(self): return self._actionMessenger

	@property
	def npcInfoBox(self): return self._npcInfoBox

	@property
	def spellInfoFrame(self): return self._spellInfoFrame

	@property
	def startMenu(self): return self._startMenu

	@property
	def dragModel(self): return self._dragModel

	@dragModel.setter
	def dragModel(self, model):
		if model and self._dragModel:
			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)))
			return

		self._dragModel = model

	def characterChanged(self):
		self._spellBar.characterChanged()
		self._playerInfoBox.characterChanged()

	def destroyGameUI(self):
		if self._hasGameUI:
			self._npcInfoBox.close()
			self._spellBar.close()
			self._playerInfoBox.close()
			self._spellInfoFrame.close()
			self._actionMessenger.close()

			self._npcInfoBox = None
			self._spellBar = None
			self._playerInfoBox = None
			self._spellInfoFrame = None
			self._actionMessenger = None

			self._hasGameUI = False

	def loadGameUI(self):
		self._npcInfoBox = UI_CreatureInfoBox()
		self._spellBar = UI_SpellBar(parent=base.luiRegion.root)
		self._playerInfoBox = UI_PlayerInfoBox(parent=base.luiRegion.root)
		self._spellInfoFrame = UI_ItemInfo(parent=base.luiRegion.root)
		self._actionMessenger = UI_ActionMessages(parent=base.luiRegion.root)

		self._hasGameUI = True

	def hasMouse(self):
		if self._startMenu.hasMouse():
			return True

		if (self._hasGameUI and (self._npcInfoBox.hasMouse()
			or self._spellBar.hasMouse()
			or self._playerInfoBox.hasMouse())):
			return True
		return False

	def close(self):
		self._startMenu.close()
		self._startMenu = None
