//////////////////////////////////////////////////////////////////////////////
//
// Tools_Entity_ClockTrigger_Object.cpp
//
// Copyright (c) 2004 Rebellion. All rights reserved.
//
// Created by Nick Davis
//
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
//
// includes
//
//////////////////////////////////////////////////////////////////////////////

// core
#include "Core/Asura.h"

// header
#include "Entity/Tools_Entity_ClockTrigger_Object.h"

// asura
#include "Entity/Asura_StaticMessage_System.h"
#include "Entity/PhysicalObject/Asura_ServerEntity_PhysicalObject.h"
#include "Entity/Triggers/Asura_ServerEntity_ClockTrigger.h"
#include "Mesh/Asura_Mesh_System.h"
#include "Rendering/Asura_Text_Output.h"

// tools
#include "Entity/Tools_MessageEditor.h"
#include "Interface/Asura_Dialog.h"
#include "Interface/Asura_Overlay.h"
#include "Misc/Tools_Timed_Messages.h"
#include "Objects/Tools_Object_System.h"
#include "Load&Save/Tools_SaveAsura.h"

//////////////////////////////////////////////////////////////////////////////
//
// Tools_Entity_ClockTrigger_Object
//
//////////////////////////////////////////////////////////////////////////////

Tools_Entity_ClockTrigger_Object::Tools_Entity_ClockTrigger_Object( Asura_Entity* pxEntity )
: Tools_Entity_Trigger_Object( pxEntity )
{
    Type = TOT_Entity_ClockTrigger;
    SetMesh( "ToolsShape_ClockTrigger" );
}

void Tools_Entity_ClockTrigger_Object::Create()
{
    Tools_Object* pxObject = Create( false );
    Tools_Object_System::SelectObject( pxObject );
}

Tools_Entity_ClockTrigger_Object* Tools_Entity_ClockTrigger_Object::Create( bool bGenerateName )
{
    // get a name and the position data
    Asura_Guid         uGuid       = Asura_Entity_System::GetNextToolsCreatedGuid();
    Tools_Entity_Data* pxToolsData = NULL;
    if ( bGenerateName )
    {
        pxToolsData = Tools_Entity_Object::CreateToolsDataWithDefaultName( "Clock Trigger", "Clock Trigger", uGuid, GetNamePrefix() );
    }
    else
    {
        pxToolsData = Tools_Entity_Object::CreateToolsData( "Clock Trigger", 0, GetNamePrefix() );
    }
    if ( pxToolsData == NULL )
    {
        return NULL;
    }

    // create the asura data
    Asura_ServerEntity_ClockTrigger* pxAsuraEntity = new Asura_ServerEntity_ClockTrigger( true );
    pxAsuraEntity->ToolsData = pxToolsData;

    // create the tools object
    Tools_Entity_ClockTrigger_Object* pxObject = new Tools_Entity_ClockTrigger_Object( pxAsuraEntity );

    Tools_SaveAsura::SetEntityModified();

    return pxObject;
}

bool Tools_Entity_ClockTrigger_Object::HandlesThisMessage( int iMessageID )
{
    if ( iMessageID == ASURA_MSG_RESET )
    {
        return true;
    }
    return Tools_Entity_Trigger_Object::HandlesThisMessage( iMessageID );
}

void Tools_Entity_ClockTrigger_Object::Destroy()
{
    Asura_ServerEntity_ClockTrigger* pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )Entity;

    // clear out any message blocks associated with this
    for ( int i = 0; i < Asura_ServerEntity_ClockTrigger::NUM_TRIGGER_TYPES; ++i )
    {
        Asura_StaticMessage_System::DeleteMessageBlock( pxAsuraEntity->m_ausTriggerMessageBlocks[ i ] );
        pxAsuraEntity->m_ausTriggerMessageBlocks[ i ] = ASURA_STATICMESSAGE_EMPTYBLOCK;
    }

    Tools_Entity_Trigger_Object::Destroy();
}

void Tools_Entity_ClockTrigger_Object::AddOverlayControls( class Asura_Overlay* pxNewOverlay,
                                                           class Asura_Vector_2& xOffset )
{
    // note that we don't call the trigger object version as we have more than one trigger type
    Tools_Entity_Activatable_Object::AddOverlayControls( pxNewOverlay, xOffset );

    Asura_ServerEntity_ClockTrigger* pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )Entity;

    // overlay controls for message block editing
    Asura_Dialog* pxNewDialog;
    char axText[ 100 ];
    sprintf( axText, "On Activation (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock( pxAsuraEntity->MessageBlock[ ASURA_TRIGGER_ENTITY_ONACTIVATION ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_OnActivation );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    sprintf( axText, "On Deactivation (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock( pxAsuraEntity->MessageBlock[ ASURA_TRIGGER_ENTITY_ONDEACTIVATION ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_OnDeactivation );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    sprintf( axText,"On Destruction (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock( pxAsuraEntity->MessageBlock[ ASURA_TRIGGER_ENTITY_ONDESTRUCTION ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_OnDestruction );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_StringDisplay_Dialog( "-----------------", xOffset );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_FlagTickbox_Dialog( "Trigger on the quarter hour", xOffset,
        &pxAsuraEntity->m_iTriggerType, Asura_ServerEntity_ClockTrigger::TRIGGER_ON_THE_QUARTER_HOUR, &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    sprintf( axText,"On Trigger (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock(
            pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::QUARTER_HOUR_MESSAGES ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_EveryQuarterHour );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_StringDisplay_Dialog( "-----------------", xOffset );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_FlagTickbox_Dialog( "Trigger on the half hour", xOffset,
        &pxAsuraEntity->m_iTriggerType, Asura_ServerEntity_ClockTrigger::TRIGGER_ON_THE_HALF_HOUR, &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    sprintf( axText,"On Trigger (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock(
            pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HALF_HOUR_MESSAGES ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_EveryHalfHour );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_StringDisplay_Dialog( "-----------------", xOffset );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_FlagTickbox_Dialog( "Trigger on the three quarter hour", xOffset,
        &pxAsuraEntity->m_iTriggerType, Asura_ServerEntity_ClockTrigger::TRIGGER_ON_THE_THREE_QUARTER_HOUR, &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    sprintf( axText,"On Trigger (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock(
            pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::THREE_QUARTER_HOUR_MESSAGES ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_EveryThreeQuarterHour );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_StringDisplay_Dialog( "-----------------", xOffset );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_FlagTickbox_Dialog( "Trigger on the hour", xOffset,
        &pxAsuraEntity->m_iTriggerType, Asura_ServerEntity_ClockTrigger::TRIGGER_ON_THE_HOUR, &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    sprintf( axText,"On Trigger (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock(
            pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HOUR_MESSAGES ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_EveryHour );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_Tickbox_Dialog( "Include hour count", xOffset,
        &pxAsuraEntity->m_bIncludeHourCount, &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_Numerical_Dialog( "Hour count delay", xOffset,
        &pxAsuraEntity->m_fRepeatDelay, 0.0f, 60.0f, 0.1f, "%.1f", &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_Numerical_Dialog( "Time between hour count repeats", xOffset,
        &pxAsuraEntity->m_fTimeBetweenRepeats, 0.0f, 60.0f, 0.1f, "%.1f", &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    sprintf( axText,"On Trigger (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock(
            pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HOUR_COUNT_MESSAGES ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_HourCount );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_StringDisplay_Dialog( "-----------------", xOffset );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_FlagTickbox_Dialog( "Trigger at this time", xOffset,
        &pxAsuraEntity->m_iTriggerType, Asura_ServerEntity_ClockTrigger::TRIGGER_AT_SPECIFIED_TIME, &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_Numerical_Dialog( "hour (0 = midnight)", xOffset,
        &pxAsuraEntity->m_iSpecifiedTimeHour,
        0, 23, 1, "%d", &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_Numerical_Dialog( "minute", xOffset,
        &pxAsuraEntity->m_iSpecifiedTimeMinute,
        0, 59, 1, "%d", &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_Numerical_Dialog( "second", xOffset,
        &pxAsuraEntity->m_iSpecifiedTimeSecond,
        0, 59, 1, "%d", &Changed );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    sprintf( axText,"On Trigger (%d)",
        Asura_StaticMessage_System::GetNumberOfMessagesInBlock(
            pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::SPECIFIED_TIME_MESSAGES ] ) );
    pxNewDialog = new Asura_Function_Dialog( axText, xOffset, EditMessages_AtSpecifiedTime );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_StringDisplay_Dialog( "-----------------", xOffset );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_Function_Dialog( "Set Hour Hand Object", xOffset, SetHourHandObject, ( int )Entity );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();

    pxNewDialog = new Asura_Function_Dialog( "Set Minute Hand Object", xOffset, SetMinuteHandObject, ( int )Entity );
    pxNewOverlay->AddDialog( pxNewDialog );
    xOffset.y += Asura_Dialog::DefaultSpacing();
}

bool Tools_Entity_ClockTrigger_Object::OwnsThisMessageBlock( unsigned short uMessageBlockID )
{
    if ( Tools_Entity_Trigger_Object::OwnsThisMessageBlock( uMessageBlockID ) )
    {
        return true;
    }

    Asura_ServerEntity_ClockTrigger* pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )Entity;
    for ( int i = 0; i < Asura_ServerEntity_ClockTrigger::NUM_TRIGGER_TYPES; ++i )
    {
        if ( pxAsuraEntity->m_ausTriggerMessageBlocks[ i ] == uMessageBlockID )
        {
            return true;
        }
    }

    return false;
}

void Tools_Entity_ClockTrigger_Object::PrintInfo( float& x, float& y )
{
    Tools_Entity_Trigger_Object::PrintInfo( x, y );

    Asura_ServerEntity_ClockTrigger* pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )Entity;

    char acHourHandString[ 32 ];
    sprintf( acHourHandString, "Hour Hand Object Guid: %u", pxAsuraEntity->m_uHourHandObjectGuid );
    Asura_Text_Output::Print( x, y++ , 0xffffffff, 0, acHourHandString );

    char acMinuteHandString[ 32 ];
    sprintf( acMinuteHandString, "Minute Hand Object Guid: %u", pxAsuraEntity->m_uMinuteHandObjectGuid );
    Asura_Text_Output::Print( x, y++ , 0xffffffff, 0, acMinuteHandString );
}

void Tools_Entity_ClockTrigger_Object::Copy( const Tools_Object* pxObject )
{
	Tools_Entity_Trigger_Object::Copy( pxObject );

    const Tools_Entity_ClockTrigger_Object* pxFromObject = (const Tools_Entity_ClockTrigger_Object*)pxObject;

    Asura_ServerEntity_ClockTrigger* pxFromEntity = (Asura_ServerEntity_ClockTrigger*)pxFromObject->Entity;
    Asura_ServerEntity_ClockTrigger* pxToEntity = (Asura_ServerEntity_ClockTrigger*)Entity;

    // copy state members
    pxToEntity->m_fUpdateTimer         = pxFromEntity->m_fUpdateTimer;
    pxToEntity->m_xPrevTime            = pxFromEntity->m_xPrevTime;
    pxToEntity->m_iTriggerType         = pxFromEntity->m_iTriggerType;
    pxToEntity->m_iSpecifiedTimeHour   = pxFromEntity->m_iSpecifiedTimeHour;
    pxToEntity->m_iSpecifiedTimeMinute = pxFromEntity->m_iSpecifiedTimeMinute;
    pxToEntity->m_iSpecifiedTimeSecond = pxFromEntity->m_iSpecifiedTimeSecond;

    // copy across message blocks deleting old ones as we go, as in Tools_Entity_Trigger_Object::Copy
    for ( int i = 0; i < Asura_ServerEntity_ClockTrigger::NUM_TRIGGER_TYPES; ++i )
    {
        Asura_StaticMessage_System::DeleteMessageBlock( pxToEntity->m_ausTriggerMessageBlocks[ i ] );
        pxToEntity->m_ausTriggerMessageBlocks[ i ] =
            Asura_StaticMessage_System::CopyMessageBlock( pxFromEntity->m_ausTriggerMessageBlocks[ i ],
                                                          pxFromObject->GetGuid(),
                                                          GetGuid() );
    }
}

Tools_Object* Tools_Entity_ClockTrigger_Object::CreateObjectOfThisType() const
{
    return Create( true );
}

//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////

void Tools_Entity_ClockTrigger_Object::EditMessages_EveryQuarterHour()
{
	Asura_Assert( ThisEntity, "" );
	Tools_Entity_ClockTrigger_Object* pxToolsEntity = ( Tools_Entity_ClockTrigger_Object* )ThisEntity;
	Asura_ServerEntity_ClockTrigger*  pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )pxToolsEntity->Entity;

	#ifdef ASURA_TOOLS_USE_NEW_MESSAGE_EDITOR
	Tools_MessageEditor::StartMessageEditingMode(&pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::QUARTER_HOUR_MESSAGES ]);
	#else
	Tools_Object_System::EditMessageBlock( "Every Quarter Hour",
        &pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::QUARTER_HOUR_MESSAGES ] );
	#endif
}

void Tools_Entity_ClockTrigger_Object::EditMessages_EveryHalfHour()
{
	Asura_Assert( ThisEntity, "" );
	Tools_Entity_ClockTrigger_Object* pxToolsEntity = ( Tools_Entity_ClockTrigger_Object* )ThisEntity;
	Asura_ServerEntity_ClockTrigger*  pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )pxToolsEntity->Entity;

	#ifdef ASURA_TOOLS_USE_NEW_MESSAGE_EDITOR
	Tools_MessageEditor::StartMessageEditingMode(&pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HALF_HOUR_MESSAGES ]);
	#else
	Tools_Object_System::EditMessageBlock( "Every Half Hour",
        &pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HALF_HOUR_MESSAGES ] );
	#endif
}

void Tools_Entity_ClockTrigger_Object::EditMessages_EveryThreeQuarterHour()
{
	Asura_Assert( ThisEntity, "" );
	Tools_Entity_ClockTrigger_Object* pxToolsEntity = ( Tools_Entity_ClockTrigger_Object* )ThisEntity;
	Asura_ServerEntity_ClockTrigger*  pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )pxToolsEntity->Entity;

	#ifdef ASURA_TOOLS_USE_NEW_MESSAGE_EDITOR
	Tools_MessageEditor::StartMessageEditingMode(&pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::THREE_QUARTER_HOUR_MESSAGES ]);
	#else
	Tools_Object_System::EditMessageBlock( "Every Three Quarter Hour",
        &pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::THREE_QUARTER_HOUR_MESSAGES ] );
	#endif
}

void Tools_Entity_ClockTrigger_Object::EditMessages_EveryHour()
{
	Asura_Assert( ThisEntity, "" );
	Tools_Entity_ClockTrigger_Object* pxToolsEntity = ( Tools_Entity_ClockTrigger_Object* )ThisEntity;
	Asura_ServerEntity_ClockTrigger*  pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )pxToolsEntity->Entity;

	#ifdef ASURA_TOOLS_USE_NEW_MESSAGE_EDITOR
	Tools_MessageEditor::StartMessageEditingMode(&pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HOUR_MESSAGES ]);
	#else
	Tools_Object_System::EditMessageBlock( "Every Hour",
        &pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HOUR_MESSAGES ] );
	#endif
}

void Tools_Entity_ClockTrigger_Object::EditMessages_HourCount()
{
	Asura_Assert( ThisEntity, "" );
	Tools_Entity_ClockTrigger_Object* pxToolsEntity = ( Tools_Entity_ClockTrigger_Object* )ThisEntity;
	Asura_ServerEntity_ClockTrigger*  pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )pxToolsEntity->Entity;

	#ifdef ASURA_TOOLS_USE_NEW_MESSAGE_EDITOR
	Tools_MessageEditor::StartMessageEditingMode(&pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HOUR_COUNT_MESSAGES ]);
	#else
	Tools_Object_System::EditMessageBlock( "Hour Count",
        &pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::HOUR_COUNT_MESSAGES ] );
	#endif
}

void Tools_Entity_ClockTrigger_Object::EditMessages_AtSpecifiedTime()
{
	Asura_Assert( ThisEntity, "" );
	Tools_Entity_ClockTrigger_Object* pxToolsEntity = ( Tools_Entity_ClockTrigger_Object* )ThisEntity;
	Asura_ServerEntity_ClockTrigger*  pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )pxToolsEntity->Entity;

	#ifdef ASURA_TOOLS_USE_NEW_MESSAGE_EDITOR
	Tools_MessageEditor::StartMessageEditingMode(&pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::SPECIFIED_TIME_MESSAGES ]);
	#else
	Tools_Object_System::EditMessageBlock( "At Specified Time",
        &pxAsuraEntity->m_ausTriggerMessageBlocks[ Asura_ServerEntity_ClockTrigger::SPECIFIED_TIME_MESSAGES ] );
	#endif
}

void Tools_Entity_ClockTrigger_Object::SetHourHandObject( int iThis )
{
    Asura_ServerEntity_ClockTrigger* pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )iThis;
    if ( pxAsuraEntity == NULL )
    {
        Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_ERROR, "Internal error!" );
        return;
    }

    GetIntNumber_Overlay xGetNumberOverlay( "Enter Guid Of Hour Hand Object", ASURA_GUID_UNREGISTERED, 0, 999999 );
    if ( xGetNumberOverlay.DoModal() )
    {
        const Asura_Guid uHourHandObjectGuid = static_cast< Asura_Guid >( xGetNumberOverlay.GetNumber() );

        Asura_ServerEntity_PhysicalObject* pxPhysObj = Asura_ServerEntity_PhysicalObject::FindEntity( uHourHandObjectGuid );
        if ( pxPhysObj != NULL )
        {
            pxAsuraEntity->m_uHourHandObjectGuid = uHourHandObjectGuid;
            Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_DEFAULT, "Hour hand object set." );
        }
        else
        {
            Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_ERROR, "Please select a physical object!" );
        }
    }
    else
    {
        Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_ERROR, "Cancelled." );
    }
}

void Tools_Entity_ClockTrigger_Object::SetMinuteHandObject( int iThis )
{
    Asura_ServerEntity_ClockTrigger* pxAsuraEntity = ( Asura_ServerEntity_ClockTrigger* )iThis;
    if ( pxAsuraEntity == NULL )
    {
        Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_ERROR, "Internal error!" );
        return;
    }

    GetIntNumber_Overlay xGetNumberOverlay( "Enter Guid Of Minute Hand Object", ASURA_GUID_UNREGISTERED, 0, 999999 );
    if ( xGetNumberOverlay.DoModal() )
    {
        const Asura_Guid uMinuteHandObjectGuid = static_cast< Asura_Guid >( xGetNumberOverlay.GetNumber() );

        Asura_ServerEntity_PhysicalObject* pxPhysObj = Asura_ServerEntity_PhysicalObject::FindEntity( uMinuteHandObjectGuid );
        if ( pxPhysObj != NULL )
        {
            pxAsuraEntity->m_uMinuteHandObjectGuid = uMinuteHandObjectGuid;
            Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_DEFAULT, "Minute hand object set." );
        }
        else
        {
            Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_ERROR, "Please select a physical object!" );
        }
    }
    else
    {
        Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_ERROR, "Cancelled." );
    }
}

//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////
