// FogColorProps.cpp : implementation file
//

#include "stdafx.h"
#include "mw4gameed2.h"
#include "FogColorProps.h"
#include "GameInterface.h"
#include "ObjectManager.h"
#include "Refresher.h"
#include "ColorDlgProDlg.h"


/////////////////////////////////////////////////////////////////////////////
// CFogColorProps dialog


CFogColorProps::CFogColorProps(ObjectManager *gobj,UndoCommand **cmd,CWnd* pParent)
	: CPanelDlg(CFogColorProps::IDD, pParent)
{
	coldlg=NULL;
	ObjMan=gobj;
	CmdList=cmd;
	//{{AFX_DATA_INIT(CFogColorProps)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CFogColorProps::DoDataExchange(CDataExchange* pDX)
{
	CPanelDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFogColorProps)
	DDX_Control(pDX, IDC_SMOKEFOG, m_SmokeFogBut);
	DDX_Control(pDX, IDC_UNDERWATERFOG, m_UnderWaterBut);
	DDX_Control(pDX, IDC_NIGHTGROUND, m_NightGround);
	DDX_Control(pDX, IDC_NIGHTFOG, m_NightFog);
	DDX_Control(pDX, IDC_COLBUT, m_ColBut);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFogColorProps, CPanelDlg)
	//{{AFX_MSG_MAP(CFogColorProps)
	ON_BN_CLICKED(IDC_COLBUT, OnColbut)
	ON_BN_CLICKED(IDC_NIGHTFOG, OnNightfog)
	ON_BN_CLICKED(IDC_NIGHTGROUND, OnNightground)
	ON_BN_CLICKED(IDC_SMOKEFOG, OnSmokefog)
	ON_BN_CLICKED(IDC_UNDERWATERFOG, OnUnderwaterfog)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFogColorProps message handlers

void CFogColorProps::OnColbut()  { EditOn(&m_ColBut); }
void CFogColorProps::OnNightfog() { EditOn(&m_NightFog); }
void CFogColorProps::OnNightground()  { EditOn(&m_NightGround); }
void CFogColorProps::OnSmokefog()  { EditOn(&m_SmokeFogBut); }
void CFogColorProps::OnUnderwaterfog()  { EditOn(&m_UnderWaterBut); }

void CFogColorProps::EditOn(CColorButton *but)
{
coldlg=new CColorDlgProDlg(&(but->Color),this);

	if(coldlg->DoModal()==IDOK)
	{
		but->SetColor(coldlg->m_Color);
	}
UpdateGame();
delete coldlg;
coldlg=NULL;

}


BOOL CFogColorProps::OnInitDialog() 
{
	CPanelDlg::OnInitDialog();

OldDayFog=ObjMan->MisDat.GetDayFogColor();
OldNightFog=ObjMan->MisDat.GetNightFogColor();
OldNightGround=ObjMan->MisDat.GetNightGroundColor();
OldUnderWater=ObjMan->MisDat.GetFogColorUnderWater();
OldSmoke=ObjMan->MisDat.GetFogColorSmoke();

	m_ColBut.SetColor(ObjMan->MisDat.GetDayFogColor());
	m_NightFog.SetColor(ObjMan->MisDat.GetNightFogColor());
	m_NightGround.SetColor(ObjMan->MisDat.GetNightGroundColor());
	m_UnderWaterBut.SetColor(ObjMan->MisDat.GetFogColorUnderWater());
	m_SmokeFogBut.SetColor(ObjMan->MisDat.GetFogColorSmoke());
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFogColorProps::UpdateGame()
{
	m_ColBut.InvalidateRect(NULL);
	m_NightFog.InvalidateRect(NULL);
	m_NightGround.InvalidateRect(NULL);
	m_ColBut.UpdateWindow();
	m_NightFog.UpdateWindow();
	m_NightGround.UpdateWindow();
	ObjMan->MisDat.SetDayFogColor(m_ColBut.GetRGBAColor());
	ObjMan->MisDat.SetNightFogColor(m_NightFog.GetRGBAColor());
	ObjMan->MisDat.SetNightGroundColor(m_NightGround.GetRGBAColor());
	AdoptFogColors();
	Refresher::Instance->View3DRefresh();
}

void CFogColorProps::OnOK() 
{
	UpdateData(TRUE);	


	ObjMan->MisDat.SetDayFogColor(m_ColBut.GetRGBAColor());
	ObjMan->MisDat.SetNightFogColor(m_NightFog.GetRGBAColor());
	ObjMan->MisDat.SetNightGroundColor(m_NightGround.GetRGBAColor());
	ObjMan->MisDat.SetFogColorUnderWater(m_UnderWaterBut.GetRGBAColor());
	ObjMan->MisDat.SetFogColorSmoke(m_SmokeFogBut.GetRGBAColor());
}

void CFogColorProps::OnCancel() 
{
ObjMan->MisDat.SetDayFogColor(OldDayFog);
ObjMan->MisDat.SetNightFogColor(OldNightFog);
ObjMan->MisDat.SetNightGroundColor(OldNightGround);
ObjMan->MisDat.SetFogColorUnderWater(OldUnderWater);
ObjMan->MisDat.SetFogColorSmoke(OldSmoke);
AdoptFogColors();
Refresher::Instance->View3DRefresh();
}

