// CulturalPanel.cpp : implementation file
//

#include "stdafx.h"
#include "MapCreator.h"
#include "CulturalPanel.h"
#include <Stuff\Stuff.hpp>

/////////////////////////////////////////////////////////////////////////////
// CCulturalPanel dialog

using namespace Stuff;

CCulturalPanel::CCulturalPanel(CWnd* pParent /*=NULL*/)
	: CDialog(CCulturalPanel::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCulturalPanel)
	m_TGAA = _T("");
	m_TGAB = _T("");
	m_TGAC = _T("");
	m_FadeEnd = 100.0f;
	m_FadeStart = 50.0f;
	m_sayYestoCulturals = FALSE;
	m_billboardA1 = TRUE;
	m_billboardA2 = TRUE;
	m_billboardA3 = TRUE;
	m_billboardB1 = TRUE;
	m_billboardB2 = TRUE;
	m_billboardB3 = TRUE;
	m_billboardC1 = TRUE;
	m_billboardC2 = TRUE;
	m_billboardC3 = TRUE;
	m_ERFA1 = _T("");
	m_ERFA2 = _T("");
	m_ERFA3 = _T("");
	m_ERFB1 = _T("");
	m_ERFB2 = _T("");
	m_ERFB3 = _T("");
	m_ERFC1 = _T("");
	m_ERFC2 = _T("");
	m_ERFC3 = _T("");
	//}}AFX_DATA_INIT
		Create(IDD,pParent);
	SetWindowPos(NULL,5,25,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);

}


void CCulturalPanel::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCulturalPanel)
	DDX_Control(pDX, IDC_TGABROWSEA, m_TGABrowseACon);
	DDX_Control(pDX, IDC_TGABROWSEB, m_TGABrowseBCon);
	DDX_Control(pDX, IDC_TGABROWSEC, m_TGABrowseCCon);
	DDX_Control(pDX, IDC_FADESTART, m_FadeStartCon);
	DDX_Control(pDX, IDC_FADEEND, m_FadeEndCon);
	DDX_Control(pDX, IDC_ERFBROWSEA1, m_ErfBrowseA1Con);
	DDX_Control(pDX, IDC_ERFBROWSEA2, m_ErfBrowseA2Con);
	DDX_Control(pDX, IDC_ERFBROWSEA3, m_ErfBrowseA3Con);
	DDX_Control(pDX, IDC_ERFBROWSEB1, m_ErfBrowseB1Con);
	DDX_Control(pDX, IDC_ERFBROWSEB2, m_ErfBrowseB2Con);
	DDX_Control(pDX, IDC_ERFBROWSEB3, m_ErfBrowseB3Con);
	DDX_Control(pDX, IDC_ERFBROWSEC1, m_ErfBrowseC1Con);
	DDX_Control(pDX, IDC_ERFBROWSEC2, m_ErfBrowseC2Con);
	DDX_Control(pDX, IDC_ERFBROWSEC3, m_ErfBrowseC3Con);
	DDX_Control(pDX, IDC_ERFA1, m_ERFA1Con);
	DDX_Control(pDX, IDC_ERFA2, m_ERFA2Con);
	DDX_Control(pDX, IDC_ERFA3, m_ERFA3Con);
	DDX_Control(pDX, IDC_ERFB1, m_ERFB1Con);
	DDX_Control(pDX, IDC_ERFB2, m_ERFB2Con);
	DDX_Control(pDX, IDC_ERFB3, m_ERFB3Con);
	DDX_Control(pDX, IDC_ERFC1, m_ERFC1Con);
	DDX_Control(pDX, IDC_ERFC2, m_ERFC2Con);
	DDX_Control(pDX, IDC_ERFC3, m_ERFC3Con);
	DDX_Control(pDX, IDC_BILLBOARDA1, m_BillBoardA1Con);
	DDX_Control(pDX, IDC_BILLBOARDA2, m_BillBoardA2Con);
	DDX_Control(pDX, IDC_BILLBOARDA3, m_BillBoardA3Con);
	DDX_Control(pDX, IDC_BILLBOARDB1, m_BillBoardB1Con);
	DDX_Control(pDX, IDC_BILLBOARDB2, m_BillBoardB2Con);
	DDX_Control(pDX, IDC_BILLBOARDB3, m_BillBoardB3Con);
	DDX_Control(pDX, IDC_BILLBOARDC1, m_BillBoardC1Con);
	DDX_Control(pDX, IDC_BILLBOARDC2, m_BillBoardC2Con);
	DDX_Control(pDX, IDC_BILLBOARDC3, m_BillBoardC3Con);
	DDX_Control(pDX, IDC_TGAA, m_TGAACon);
	DDX_Control(pDX, IDC_TGAB, m_TGABCon);
	DDX_Control(pDX, IDC_TGAC, m_TGACCon);
	DDX_Text(pDX, IDC_TGAA, m_TGAA);
	DDX_Text(pDX, IDC_TGAB, m_TGAB);
	DDX_Text(pDX, IDC_TGAC, m_TGAC);
	DDX_Text(pDX, IDC_FADEEND, m_FadeEnd);
	DDV_MinMaxFloat(pDX, m_FadeEnd, 50.f, 500.f);
	DDX_Text(pDX, IDC_FADESTART, m_FadeStart);
	DDV_MinMaxFloat(pDX, m_FadeStart, 50.f, 500.f);
	DDX_Check(pDX, IDC_CULTURALYESNO, m_sayYestoCulturals);
	DDX_Check(pDX, IDC_BILLBOARDA1, m_billboardA1);
	DDX_Check(pDX, IDC_BILLBOARDA2, m_billboardA2);
	DDX_Check(pDX, IDC_BILLBOARDA3, m_billboardA3);
	DDX_Check(pDX, IDC_BILLBOARDB1, m_billboardB1);
	DDX_Check(pDX, IDC_BILLBOARDB2, m_billboardB2);
	DDX_Check(pDX, IDC_BILLBOARDB3, m_billboardB3);
	DDX_Check(pDX, IDC_BILLBOARDC1, m_billboardC1);
	DDX_Check(pDX, IDC_BILLBOARDC2, m_billboardC2);
	DDX_Check(pDX, IDC_BILLBOARDC3, m_billboardC3);
	DDX_Text(pDX, IDC_ERFA1, m_ERFA1);
	DDX_Text(pDX, IDC_ERFA2, m_ERFA2);
	DDX_Text(pDX, IDC_ERFA3, m_ERFA3);
	DDX_Text(pDX, IDC_ERFB1, m_ERFB1);
	DDX_Text(pDX, IDC_ERFB2, m_ERFB2);
	DDX_Text(pDX, IDC_ERFB3, m_ERFB3);
	DDX_Text(pDX, IDC_ERFC1, m_ERFC1);
	DDX_Text(pDX, IDC_ERFC2, m_ERFC2);
	DDX_Text(pDX, IDC_ERFC3, m_ERFC3);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCulturalPanel, CDialog)
	//{{AFX_MSG_MAP(CCulturalPanel)
	ON_BN_CLICKED(IDC_ERFBROWSEA1, OnErfbrowsea1)
	ON_BN_CLICKED(IDC_ERFBROWSEA2, OnErfbrowsea2)
	ON_BN_CLICKED(IDC_ERFBROWSEA3, OnErfbrowsea3)
	ON_BN_CLICKED(IDC_ERFBROWSEB1, OnErfbrowseb1)
	ON_BN_CLICKED(IDC_ERFBROWSEB2, OnErfbrowseb2)
	ON_BN_CLICKED(IDC_ERFBROWSEB3, OnErfbrowseb3)
	ON_BN_CLICKED(IDC_ERFBROWSEC1, OnErfbrowsec1)
	ON_BN_CLICKED(IDC_ERFBROWSEC2, OnErfbrowsec2)
	ON_BN_CLICKED(IDC_ERFBROWSEC3, OnErfbrowsec3)
	ON_BN_CLICKED(IDC_TGABROWSEA, OnTgabrowsea)
	ON_BN_CLICKED(IDC_TGABROWSEB, OnTgabrowseb)
	ON_BN_CLICKED(IDC_TGABROWSEC, OnTgabrowsec)
	ON_BN_CLICKED(IDC_CULTURALYESNO, OnCulturalyesno)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCulturalPanel message handlers

void CCulturalPanel::OnErfbrowsea1() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFA1,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFA1=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
}

void CCulturalPanel::OnErfbrowsea2() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFA2,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFA2=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
}

void CCulturalPanel::OnErfbrowsea3() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFA3,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFA3=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
}

void CCulturalPanel::OnErfbrowseb1() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFB1,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFB1=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
	
}

void CCulturalPanel::OnErfbrowseb2() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFB2,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFB2=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
	
}

void CCulturalPanel::OnErfbrowseb3() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFB3,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFB3=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
	
}

void CCulturalPanel::OnErfbrowsec1() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFC1,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFC1=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
	
}

void CCulturalPanel::OnErfbrowsec2() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFC2,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFC2=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
	
}

void CCulturalPanel::OnErfbrowsec3() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_ERFC3,OFN_NOCHANGEDIR,"ERF Files (*.erf)|*.erf||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_ERFC3=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
	
}

void CCulturalPanel::OnTgabrowsea() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_TGAA,OFN_NOCHANGEDIR,"TGA Files (*.tga)|*.tga||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_TGAA=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
}

void CCulturalPanel::OnTgabrowseb() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_TGAB,OFN_NOCHANGEDIR,"TGA Files (*.tga)|*.tga||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_TGAB=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
}

void CCulturalPanel::OnTgabrowsec() 
{
	UpdateData(TRUE);
	CFileDialog fdlg(TRUE,NULL,m_TGAC,OFN_NOCHANGEDIR,"TGA Files (*.tga)|*.tga||",NULL);	
	if(fdlg.DoModal()==IDOK) 
	{
		m_TGAC=fdlg.GetPathName();	
		UpdateData(FALSE);
		
	}			
	
}

void CCulturalPanel::WriteEntries(Stuff::Page *page, CString cultpath)
{
	UpdateData(TRUE);
	
	Page::NoteIterator *notes=page->MakeNoteIterator();

	Note *note;
	CString notename;
	while(note=notes->ReadAndNext())
	{
	notename=note->GetName();
	if( !notename.CompareNoCase("culturalaobject")   ||
		!notename.CompareNoCase("culturalbobject")    ||
		!notename.CompareNoCase("culturalcobject")	  ||	
		!notename.CompareNoCase("culturalalocations") ||
		!notename.CompareNoCase("culturalblocations") ||
		!notename.CompareNoCase("culturalclocations")
		)
		page->DeleteNote(note->GetName());
	}


	CString temp_str, fname, dname;
	int loc;
	if(m_sayYestoCulturals==TRUE)
	{
		if(m_FadeEnd<=m_FadeStart)
		{
			m_FadeEnd = m_FadeStart+10.0f;
		}

		temp_str.Format("%.1f %.1f", m_FadeStart, m_FadeEnd);
		page->SetEntry("CulturalFadeValues", temp_str);

//=========================================================================

		loc = m_TGAA.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_TGAA.Mid(loc+1);
		}
		else
		{
			fname = m_TGAA;
		}

		page->SetEntry("CulturalALocations", fname);
		CopyFile(m_TGAA,cultpath+'\\'+fname,FALSE);


		loc = m_TGAB.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_TGAB.Mid(loc+1);
		}
		else
		{
			fname = m_TGAB;
		}

		page->SetEntry("CulturalBLocations", fname);
		CopyFile(m_TGAB,cultpath+'\\'+fname,FALSE);

		loc = m_TGAC.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_TGAC.Mid(loc+1);
		}
		else
		{
			fname = m_TGAC;
		}

		page->SetEntry("CulturalCLocations", fname);
		CopyFile(m_TGAC,cultpath+'\\'+fname,FALSE);

//=========================================================================

		loc = m_ERFA1.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFA1.Mid(loc+1);
		}
		else
		{
			fname = m_ERFA1;
		}

		CopyFile(m_ERFA1,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardA1==TRUE?" 1":" 0");

		page->AppendEntry("CulturalAObject", fname);

		loc = m_ERFA2.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFA2.Mid(loc+1);
		}
		else
		{
			fname = m_ERFA2;
		}

		CopyFile(m_ERFA2,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardA2==TRUE?" 1":" 0");

		page->AppendEntry("CulturalAObject", fname);

		loc = m_ERFA3.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFA3.Mid(loc+1);
		}
		else
		{
			fname = m_ERFA3;
		}

		CopyFile(m_ERFA3,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardA3==TRUE?" 1":" 0");

		page->AppendEntry("CulturalAObject", fname);

//=========================================================================

		loc = m_ERFB1.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFB1.Mid(loc+1);
		}
		else
		{
			fname = m_ERFB1;
		}

		CopyFile(m_ERFB1,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardB1==TRUE?" 1":" 0");
		page->AppendEntry("CulturalBObject", fname);

		loc = m_ERFB2.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFB2.Mid(loc+1);
		}
		else
		{
			fname = m_ERFB2;
		}

		CopyFile(m_ERFB2,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardB2==TRUE?" 1":" 0");
		page->AppendEntry("CulturalBObject", fname);

		loc = m_ERFB3.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFB3.Mid(loc+1);
		}
		else
		{
			fname = m_ERFB3;
		}

		CopyFile(m_ERFB3,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardB3==TRUE?" 1":" 0");
		page->AppendEntry("CulturalBObject", fname);

//=========================================================================

		loc = m_ERFC1.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFC1.Mid(loc+1);
		}
		else
		{
			fname = m_ERFC1;
		}

		CopyFile(m_ERFC1,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardC1==TRUE?" 1":" 0");
		page->AppendEntry("CulturalCObject", fname);

		loc = m_ERFC2.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFC2.Mid(loc+1);
		}
		else
		{
			fname = m_ERFC2;
		}

		CopyFile(m_ERFC2,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardC2==TRUE?" 1":" 0");
		page->AppendEntry("CulturalCObject", fname);

		loc = m_ERFC3.ReverseFind('\\');

		if(loc>=0)
		{
			fname = m_ERFC3.Mid(loc+1);
		}
		else
		{
			fname = m_ERFC3;
		}

		CopyFile(m_ERFC3,cultpath+'\\'+fname,FALSE);
		fname += (m_billboardC3==TRUE?" 1":" 0");
		page->AppendEntry("CulturalCObject", fname);
	}
}

void CCulturalPanel::OnCulturalyesno() 
{
	// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_BillBoardA1Con.EnableWindow(m_sayYestoCulturals);
m_BillBoardA2Con.EnableWindow(m_sayYestoCulturals);
m_BillBoardA3Con.EnableWindow(m_sayYestoCulturals);
m_BillBoardB1Con.EnableWindow(m_sayYestoCulturals);
m_BillBoardB2Con.EnableWindow(m_sayYestoCulturals);
m_BillBoardB3Con.EnableWindow(m_sayYestoCulturals);
m_BillBoardC1Con.EnableWindow(m_sayYestoCulturals);
m_BillBoardC2Con.EnableWindow(m_sayYestoCulturals);
m_BillBoardC3Con.EnableWindow(m_sayYestoCulturals);
m_ERFA1Con.EnableWindow(m_sayYestoCulturals);
m_ERFA2Con.EnableWindow(m_sayYestoCulturals);
m_ERFA3Con.EnableWindow(m_sayYestoCulturals);
m_ERFB1Con.EnableWindow(m_sayYestoCulturals);
m_ERFB2Con.EnableWindow(m_sayYestoCulturals);
m_ERFB3Con.EnableWindow(m_sayYestoCulturals);
m_ERFC1Con.EnableWindow(m_sayYestoCulturals);
m_ERFC2Con.EnableWindow(m_sayYestoCulturals);
m_ERFC3Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseA1Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseA2Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseA3Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseB1Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseB2Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseB3Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseC1Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseC2Con.EnableWindow(m_sayYestoCulturals);
m_ErfBrowseC3Con.EnableWindow(m_sayYestoCulturals);
m_TGAACon.EnableWindow(m_sayYestoCulturals);
m_TGABCon.EnableWindow(m_sayYestoCulturals);
m_TGACCon.EnableWindow(m_sayYestoCulturals);
m_FadeStartCon.EnableWindow(m_sayYestoCulturals);
m_FadeEndCon.EnableWindow(m_sayYestoCulturals);
m_TGABrowseACon.EnableWindow(m_sayYestoCulturals);
m_TGABrowseBCon.EnableWindow(m_sayYestoCulturals);
m_TGABrowseCCon.EnableWindow(m_sayYestoCulturals);	
}

BOOL CCulturalPanel::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	OnCulturalyesno();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
