//
// Tools_ModuleSelect_Overlay.cpp
//
// Created by Richard Rice - 18/10/2005
// 
// Copyright (C) 2005 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"
#include "Interface/Tools_ModuleSelect_Overlay.h"

#include "Interface/Asura_Overlay.h"
#include "Interface/Asura_Dialog.h"
#include "Mesh/Asura_Mesh.h"
#include "Rendering/Asura_Module.h"



Tools_ModuleSelect_Overlay::Tools_ModuleSelect_Overlay(const char* pszTitle,int iDefaultModule)
:ListSelection_Overlay(pszTitle)
{
	//add all the module names to the list
	for(int i=0;i<Asura_Module_System::GetNumberOfModules();i++)
	{
		Asura_Mesh* pxMesh = Asura_Module_System::GetMeshForModule(i);
		AddItem(pxMesh->Name.GetString(),i,iDefaultModule==i);
	}

	m_iModuleIndex = 0;
	m_bModuleIndexChanged = false;
}

void Tools_ModuleSelect_Overlay::AddExtraOverlayControls(class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset)
{
	Asura_Dialog* pxDialog;

	//initialise module index
	m_iModuleIndex = GetSelectionData();

	//and add overlay control for it
	pxDialog = new Asura_Numerical_Dialog("Module Index",xOffset,&m_iModuleIndex,0,Asura_Module_System::GetNumberOfModules()-1,1,"%d",&m_bModuleIndexChanged);
	pxOverlay->AddDialog(pxDialog);
	xOffset.y += 1.5f;

	xOffset.y += 1.0f;
}

void Tools_ModuleSelect_Overlay::Update()
{
	ListSelection_Overlay::Update();
	if(m_bModuleIndexChanged)
	{
		//update the selection in the list
		SetSelectionByData(m_iModuleIndex);
		m_bModuleIndexChanged = false;
	}
	else
	{
		//make sure the module index matches that selected from the list
		m_iModuleIndex = GetSelectionData();
	}
}
