// OverviewProperties.cpp : implementation file
//

#include "stdafx.h"
#include "mw4gameed2.h"
#include "OverviewProperties.h"

#include "ObjectManager.h"
#include "Refresher.h"

/////////////////////////////////////////////////////////////////////////////
// COverviewProperties dialog


COverviewProperties::COverviewProperties(ObjectManager  *object_manager,
										 DWORD *sflag,
										 CWnd* pParent /*=NULL*/)
	: DefaultDialog(COverviewProperties::IDD,  pParent)
{
	//{{AFX_DATA_INIT(COverviewProperties)
	//}}AFX_DATA_INIT
	ObjMan=object_manager;
	ShowFlag=sflag;
	Create(COverviewProperties::IDD,pParent);
}


void COverviewProperties::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COverviewProperties)
	DDX_Control(pDX, IDC_SHOWLIST, m_ShowList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COverviewProperties, CDialog)
	//{{AFX_MSG_MAP(COverviewProperties)
	ON_LBN_SELCHANGE(IDC_SHOWLIST, OnSelchangeShowList)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_HIDEALL, OnHideall)
	ON_BN_CLICKED(IDC_SHOWALL, OnShowall)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COverviewProperties message handlers

void COverviewProperties::Refresh()
{
	UpdateShowList();
}

BOOL COverviewProperties::OnInitDialog() 
{
	CDialog::OnInitDialog();

int itm;
itm=m_ShowList.AddString("Friendly alignment");
m_ShowList.SetItemData(itm,SHOW_FRIENDLY);	
itm=m_ShowList.AddString("Neutral alignment");
m_ShowList.SetItemData(itm,SHOW_NEUTRAL);	
itm=m_ShowList.AddString("Enemy alignment");
m_ShowList.SetItemData(itm,SHOW_ENEMY);	
itm=m_ShowList.AddString("Vehicles");
m_ShowList.SetItemData(itm,SHOW_VEHICLES);	
itm=m_ShowList.AddString("Mechs");
m_ShowList.SetItemData(itm,SHOW_MECHS);	
itm=m_ShowList.AddString("Airplanes");
m_ShowList.SetItemData(itm,SHOW_AIRPLANES);	
itm=m_ShowList.AddString("NonComs");
m_ShowList.SetItemData(itm,SHOW_NONCOMS);	
itm=m_ShowList.AddString("Buildings");
m_ShowList.SetItemData(itm,SHOW_BUILDINGS);	
itm=m_ShowList.AddString("Culturals");
m_ShowList.SetItemData(itm,SHOW_CULTURALS);	
itm=m_ShowList.AddString("Water");
m_ShowList.SetItemData(itm,SHOW_WATER);	
itm=m_ShowList.AddString("Camera Ships");
m_ShowList.SetItemData(itm,SHOW_CAMERASHIPS);	
itm=m_ShowList.AddString("Lights");
m_ShowList.SetItemData(itm,SHOW_LIGHTS);	
itm=m_ShowList.AddString("Effects");
m_ShowList.SetItemData(itm,SHOW_FX);	
itm=m_ShowList.AddString("Flags");
m_ShowList.SetItemData(itm,SHOW_FLAGS);	
itm=m_ShowList.AddString("Teams");
m_ShowList.SetItemData(itm,SHOW_TEAMS);	
itm=m_ShowList.AddString("Drop Zones");
m_ShowList.SetItemData(itm,SHOW_DROPZONES);	
itm=m_ShowList.AddString("Nav Points");
m_ShowList.SetItemData(itm,SHOW_NAVPOINTS);	
itm=m_ShowList.AddString("No AI");
m_ShowList.SetItemData(itm,SHOW_AI_NONE);	
itm=m_ShowList.AddString("AI");
m_ShowList.SetItemData(itm,SHOW_AI);	
itm=m_ShowList.AddString("MoverAI");
m_ShowList.SetItemData(itm,SHOW_MOVERAI);	
itm=m_ShowList.AddString("CombatAI");
m_ShowList.SetItemData(itm,SHOW_COMBATAI);	
itm=m_ShowList.AddString("NonComAI");
m_ShowList.SetItemData(itm,SHOW_NONCOMAI);	
itm=m_ShowList.AddString("ShooterAI");
m_ShowList.SetItemData(itm,SHOW_SHOOTERAI);	
itm=m_ShowList.AddString("MechAI");
m_ShowList.SetItemData(itm,SHOW_MECHAI);	
itm=m_ShowList.AddString("PlaneAI");
m_ShowList.SetItemData(itm,SHOW_PLANEAI);	
itm=m_ShowList.AddString("Paths");
m_ShowList.SetItemData(itm,SHOW_PATHS);	

UpdateShowList();

	Refresh();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}




void COverviewProperties::UpdateShowFlag()
{
DWORD flag;
for(int i=0;i<m_ShowList.GetCount();i++)
{
flag=m_ShowList.GetItemData(i);
if(m_ShowList.GetSel(i))
	{
	*ShowFlag|=flag;
	}
	else
	{
	*ShowFlag&=~flag;
	}
}

}

void COverviewProperties::UpdateShowList()
{

DWORD flag;

for(int i=0;i<m_ShowList.GetCount();i++)
{
flag=m_ShowList.GetItemData(i);
m_ShowList.SetSel(i,*ShowFlag&flag);
}

}
	

void COverviewProperties::OnSelchangeShowList() 
{
UpdateShowFlag();
ObjMan->UpdateVisibility(*ShowFlag);
	Refresher::Instance->WorldRefresh(this,true);
}

void COverviewProperties::OnHideall() 
{
	
	*ShowFlag&=SHOW_LATTICE|SHOW_BOUNDS;
	UpdateShowList();
	ObjMan->UpdateVisibility(*ShowFlag);
	Refresher::Instance->WorldRefresh(this,true);
}

void COverviewProperties::OnShowall() 
{
	*ShowFlag|=0xffffffff&(~(SHOW_LATTICE|SHOW_BOUNDS));
	UpdateShowList();
	ObjMan->UpdateVisibility(*ShowFlag);
	Refresher::Instance->WorldRefresh(this,true);
}

void COverviewProperties::OnClose() 
{	ShowWindow(SW_HIDE);}
