-------------------------------------------------------------------------------
-- Содержит в себе ссылки на инвентарь, хо-, комикс и прочие выезжающие
-- панельки, отвечает за их правильное отображение в зависимости от игрового
-- режима.
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
class 'PanelBase' (Node)
-------------------------------------------------------------------------------

function PanelBase:__init(game_scene)
	Node.__init(self, game_scene:getMainEntity(), 'Panel', 5)
	self.game_scene = game_scene

	self:createGuiElements()
	self:setModeElements()

	
	for element_name, info in pairs(self.gui_elements) do
		self:hideElements({element_name}, 0)
	end

	self.current_mode = EPanelMode.NONE
	self.default_move_time = 0.6
end
-------------------------------------------------------------------------------

function PanelBase:createGuiElements()
	self.gui_elements = {}

	local function createElement(name, element)
		self.gui_elements[name] = { entity = element }
	end

	createElement('inventory',		Inventory(self))
	createElement('ho_panel',		HOPanel(self))
	createElement('hp_panel',		HPPanel(self))
	createElement('mg_panel',		MGPanel(self))
	createElement('black_bar',		BlackBar(self))
	createElement('controls_panel',	ControlsPanel(self))
	createElement('comics_panel',	ComicsPanel(self))
	createElement('cut_scene',		CutScene(self))
end
-------------------------------------------------------------------------------

function PanelBase:setModeElements()
	self.mode_elements =
	{
		[EPanelMode.NONE		 ] = {},
		[EPanelMode.QUEST		 ] = { 'inventory', 'controls_panel' },
		[EPanelMode.HIDDENOBJECT ] = { 'ho_panel', 'controls_panel' },
		[EPanelMode.COMICS		 ] = { 'comics_panel' },
		[EPanelMode.MINIGAME	 ] = { 'mg_panel', 'controls_panel' },
		[EPanelMode.CLEAN		 ] = {},
		[EPanelMode.HIDDENPICTURE] = { 'hp_panel', 'controls_panel' },
		[EPanelMode.CUTSCENE	 ] = { 'cut_scene' },
	}
end
-------------------------------------------------------------------------------

function PanelBase:setMode(mode, ...)
	if self.current_mode ~= mode then
	local args = {...}
		if mode == EPanelMode.NONE then
		elseif mode == EPanelMode.QUEST then
			self:setQuestMode(args)
		elseif mode == EPanelMode.HIDDENOBJECT then
			self:setHiddenObjectMode(args)
		elseif mode == EPanelMode.COMICS then
			self:setComicsMode(args)
		elseif mode == EPanelMode.MINIGAME then
			self:setMinigameMode(args)
		elseif mode == EPanelMode.CLEAN then
			self:setCleanMode(args)
		elseif mode == EPanelMode.HIDDENPICTURE then
			self:setHiddenPictureMode(args)
		elseif mode == EPanelMode.CUTSCENE then
			self:setCutSceneMode(args)
		end

		self.current_mode = mode
		self.gui_elements['controls_panel'].entity:setMode(mode)
	end
end
-------------------------------------------------------------------------------

function PanelBase:getMode()
	return self.current_mode
end
-------------------------------------------------------------------------------

function PanelBase:showElements(elements, move_time)
	for _, element_name in pairs(elements) do
		self.gui_elements[element_name].entity:moveIn(move_time)
	end
end
-------------------------------------------------------------------------------

function PanelBase:hideElements(elements, move_time)
	for _, element_name in pairs(elements) do
		self.gui_elements[element_name].entity:moveOut(move_time)
	end
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- CUSTOM SET_MODE METHODS ----------------------------------------------------
-------------------------------------------------------------------------------

function PanelBase:setQuestMode(args)
	local move_time = args[1] or self.default_move_time
	self:hideElements(self.mode_elements[self.current_mode], move_time)
	self:showElements(self.mode_elements[EPanelMode.QUEST], move_time)
end
-------------------------------------------------------------------------------

function PanelBase:setHiddenObjectMode(args)
	local move_time = args[1] or self.default_move_time
	self:hideElements(self.mode_elements[self.current_mode], move_time)
	self:showElements(self.mode_elements[EPanelMode.HIDDENOBJECT], move_time)
end
-------------------------------------------------------------------------------

function PanelBase:setComicsMode(args)
	local move_time = args[1] or self.default_move_time
	self:hideElements(self.mode_elements[self.current_mode], move_time)
	self:showElements(self.mode_elements[EPanelMode.COMICS], move_time)
end
-------------------------------------------------------------------------------

function PanelBase:setMinigameMode(args)
	local move_time = args[1] or self.default_move_time
	self:hideElements(self.mode_elements[self.current_mode], move_time)
	self:showElements(self.mode_elements[EPanelMode.MINIGAME], move_time)

	self.gui_elements['mg_panel'].entity:updateTextMG()
end
-------------------------------------------------------------------------------

function PanelBase:setCleanMode(args)
	local move_time = args[1] or self.default_move_time
	self:hideElements(self.mode_elements[self.current_mode], move_time)
	self:showElements(self.mode_elements[EPanelMode.CLEAN], move_time)

	self.gui_elements['mg_panel'].entity:updateTextMG()
end
-------------------------------------------------------------------------------

function PanelBase:setHiddenPictureMode(args)
	local move_time = args[1] or self.default_move_time
	self:hideElements(self.mode_elements[self.current_mode], move_time)
	self:showElements(self.mode_elements[EPanelMode.HIDDENPICTURE], move_time)
end
-------------------------------------------------------------------------------

function PanelBase:setCutSceneMode(args)
	local move_time = args[1] or self.default_move_time
	local skip_callback = args[2]
	local show_skip = true 
	if args[3] ~= nil then
		show_skip = args[3]
	end

	local bttn_skip = self.gui_elements['cut_scene'].entity:getSkipButton()
	if skip_callback then
		bttn_skip.onPress:removeAll()
		bttn_skip.onPress:add(skip_callback)
	end

	if show_skip then
		if isDebugMode() then
			bttn_skip:show()
		else
			bttn_skip:hide()
			self.game_scene:getPlayField().timer:add(function() bttn_skip:show() end, 2)
		end
	else
		bttn_skip:hide()
	end

	self:hideElements(self.mode_elements[self.current_mode], move_time)
	self:showElements(self.mode_elements[EPanelMode.CUTSCENE], move_time)

end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- GETTERS --------------------------------------------------------------------
-------------------------------------------------------------------------------

function PanelBase:getInventory()
	return self.gui_elements['inventory'].entity
end
-------------------------------------------------------------------------------

function PanelBase:getHOPanel()
	return self.gui_elements['ho_panel'].entity
end
-------------------------------------------------------------------------------

function PanelBase:getHPPanel()
	return self.gui_elements['hp_panel'].entity
end
-------------------------------------------------------------------------------

function PanelBase:getMGPanel()
	return self.gui_elements['mg_panel'].entity
end
-------------------------------------------------------------------------------

function PanelBase:getBlackBar()
	return self.gui_elements['black_bar'].entity
end
-------------------------------------------------------------------------------

function PanelBase:getControlsPanel()
	return self.gui_elements['controls_panel'].entity
end
-------------------------------------------------------------------------------

function PanelBase:getComicsPanel()
	return self.gui_elements['comics_panel'].entity
end
-------------------------------------------------------------------------------

function PanelBase:getCutScenePanel()
	return self.gui_elements['cut_scene'].entity
end
-------------------------------------------------------------------------------