00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "unitnaming.h"
00011 #include "../gamemap.h"
00012 #include "../actions/renamecontainercommand.h"
00013 #include "../contextutils.h"
00014
00015 bool UnitNaming::ok()
00016 {
00017 if ( publicName->GetText() != unit->name || privateName->GetText() != unit->privateName ) {
00018 auto_ptr<RenameContainerCommand> rcc ( new RenameContainerCommand( unit ));
00019 rcc->setName( publicName->GetText(), privateName->GetText() );
00020 ActionResult res = rcc->execute( createContext( unit->getMap() ));
00021 if ( res.successful() )
00022 rcc.release();
00023 }
00024 QuitModal();
00025 return true;
00026 }
00027
00028 bool UnitNaming::cancel()
00029 {
00030 QuitModal();
00031 return true;
00032 }
00033
00034 bool UnitNaming::line1completed()
00035 {
00036 if ( privateName ) {
00037 privateName->EditBegin();
00038 return true;
00039 } else
00040 return false;
00041 }
00042
00043 UnitNaming::UnitNaming ( ContainerBase* myUnit) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 300, 150), "Enter Names")
00044 {
00045 unit = myUnit;
00046
00047 int width = 90;
00048 new PG_Label( this, PG_Rect( border, 40, width, 20), "Public: ");
00049
00050 int fieldwidth = Width() - 3 * border - width;
00051 publicName = new PG_LineEdit( this, PG_Rect( border*2 + width, 40, fieldwidth, 20));
00052 publicName->SetText( myUnit->name );
00053 publicName->sigEditReturn.connect( SigC::slot( *this, &UnitNaming::line1completed ));
00054
00055 new PG_Label( this, PG_Rect( border, 70, width, 20), "Private: ");
00056 privateName = new PG_LineEdit( this, PG_Rect( border*2 + width, 70, fieldwidth, 20));
00057 privateName->SetText( myUnit->privateName);
00058 privateName->sigEditReturn.connect( SigC::slot( *this, &UnitNaming::ok ));
00059
00060 AddStandardButton( "~O~k" )->sigClick.connect( SigC::slot( *this, &UnitNaming::ok ));
00061 };
00062
00063 int UnitNaming::RunModal()
00064 {
00065 publicName->EditBegin();
00066 return ASC_PG_Dialog::RunModal();
00067 }
00068