unitnaming.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
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 

Generated on Mon May 21 01:26:39 2012 for Advanced Strategic Command by  doxygen 1.5.1