-- Copyright Declaration
-- This file is part of the "Faction Commander Mod", a personal production of rgggclp.
-- You could copy, modify and distribute this file only if you keep this header intact as the originality of this file.
-- If you have questions, feel free to contact me at rggg_clp@163.com
-- 版权声明
-- 这个程序是“阵营指挥官”的一部分，它是Chen Lin Peng的个人作品
-- 你可以拷贝、修改和再次发布这个文件，不过你必须保留这个版权声明，它表示这个文件的来源，谢谢

class "UIFactionCommander" ( CUIScriptWnd )
function UIFactionCommander:__init() super()
    self:InitControls()
    self:InitCallBacks()
end
function UIFactionCommander:__finalize()
end

function UIFactionCommander:InitControls()
	local xml= CScriptXmlInit()
	xml:ParseFile( "ui_faction_commander.xml" )
	
	--1
	local background = xml:InitFrame( "faction_commander:frame", self )
	local workArea = CUIWindow()
	xml:InitWindow( "faction_commander:wrk_area", 0, workArea )
	workArea:SetAutoDelete( true )
	self:AttachChild( workArea )
	
	--2
	self.commands = xml:InitTab( "faction_commander:commands", workArea )
	self:Register( self.commands, "radio_commands" )	
	self.commands:SetActiveTab( faction_commander.facadeSinglton:getOrder() )
	xml:InitStatic( "faction_commander:cap_commands", self.commands )

	--3
	self.magnitudes = xml:InitTab( "faction_commander:magnitudes", workArea )
	self:Register( self.magnitudes, "radio_magnitudes" )	
	self.magnitudes:SetActiveTab( faction_commander.facadeSinglton:getMagnitude() )
	xml:InitStatic( "faction_commander:cap_magnitude", self.magnitudes )

	--4
	self.ai = xml:InitTab( "faction_commander:ai", workArea )
	self:Register( self.ai, "radio_ai" )	
	self.ai:SetActiveTab( faction_commander.facadeSinglton:getAI() )
	xml:InitStatic( "faction_commander:cap_ai", self.ai )
	
	--5
	local btn = xml:Init3tButton( "faction_commander:btn_summon_squad", workArea )
	self:Register( btn, "button_summon_squad" )
end

function UIFactionCommander:InitCallBacks()
	self:AddCallback( "radio_commands",			ui_events.TAB_CHANGED,		self.OnRadioCommandChanged,		self )
	self:AddCallback( "radio_magnitudes",		ui_events.TAB_CHANGED,		self.OnRadioMagnitudeChanged,	self )
	self:AddCallback( "radio_ai",				ui_events.TAB_CHANGED,		self.OnRadioAIChanged,			self )
	self:AddCallback( "button_summon_squad",	ui_events.BUTTON_CLICKED,	self.OnButtonSummonSquad,		self )
end

function UIFactionCommander:OnRadioCommandChanged()
	local id = self.commands:GetActiveId()
	faction_commander.facadeSinglton:giveOrder( id )
end

function UIFactionCommander:OnRadioMagnitudeChanged()
	local id = self.magnitudes:GetActiveId()
	faction_commander.facadeSinglton:setMagnitude( id )
end

function UIFactionCommander:OnRadioAIChanged()
	local id = self.ai:GetActiveId()
	faction_commander.facadeSinglton:setAI( id )
end

function UIFactionCommander:OnButtonSummonSquad()
	faction_commander.facadeSinglton:summonSquad()
end
















class "UIFactionChanger" ( CUIScriptWnd )
function UIFactionChanger:__init() super()
    self:InitControls()
    self:InitCallBacks()
end
function UIFactionChanger:__finalize()
end

function UIFactionChanger:InitControls()
	local xml= CScriptXmlInit()
	xml:ParseFile( "ui_faction_commander.xml" )
	
	--1
	local background = xml:InitFrame( "faction_commander:frame", self )
	local workArea = CUIWindow()
	xml:InitWindow( "faction_commander:wrk_area", 0, workArea )
	workArea:SetAutoDelete( true )
	self:AttachChild( workArea )
	
	--2
	self.factions = xml:InitTab( "faction_commander:faction_changer", workArea )
	self:Register( self.factions, "radio_factions" )	
	self.factions:SetActiveTab( faction_commander.factionChanger:getFaction() )
	xml:InitStatic( "faction_commander:cap_faction_changer", self.factions )
	
	--3
	self.timeAccelerate = xml:InitTab( "faction_commander:time_accelerate", workArea )
	self:Register( self.timeAccelerate, "radio_timeAccelerate" )	
	self.timeAccelerate:SetActiveTab( faction_commander.facadeSinglton:getTimeScale() )
	xml:InitStatic( "faction_commander:cap_time_accelerate", self.timeAccelerate )
end

function UIFactionChanger:InitCallBacks()
	self:AddCallback( "radio_factions",			ui_events.TAB_CHANGED,		self.OnRadioFactionChanged,		self )
	self:AddCallback( "radio_timeAccelerate",	ui_events.TAB_CHANGED,		self.OnRadioTimeChanged,		self )
end

function UIFactionChanger:OnRadioFactionChanged()
	local id = self.factions:GetActiveId()
	faction_commander.factionChanger:joinFaction( id )
end

function UIFactionChanger:OnRadioTimeChanged()
	local id = self.timeAccelerate:GetActiveId()
	faction_commander.facadeSinglton:setTimeScale( id )
end











class "UISummoner" ( CUIScriptWnd )
function UISummoner:__init() super()
    self:InitControls()
    self:InitCallBacks()
end
function UISummoner:__finalize()
end

function UISummoner:InitControls()
	local xml= CScriptXmlInit()
	xml:ParseFile( "ui_faction_commander.xml" )
	
	--1
	local background = xml:InitFrame( "faction_commander:frame", self )
	local workArea = CUIWindow()
	xml:InitWindow( "faction_commander:wrk_area", 0, workArea )
	workArea:SetAutoDelete( true )
	self:AttachChild( workArea )
	xml:InitStatic( "faction_commander:cap_summoner_comingsoon", workArea )
end

function UISummoner:InitCallBacks()
end
