SPProfileBox::SPProfileBox ( AUI_ERRCODE *retval, uint32 id, MBCHAR *ldlBlock ) :
	m_spClan(NULL),m_spGender(NULL),m_spName(NULL),
	m_spPreferences(NULL),m_spCustom(NULL),
	m_PTOP(NULL),
	m_PHEADER(NULL),
	m_PBOT(NULL),
	m_PLEFT(NULL),
	m_PRIGHT(NULL)
{
	{
		int i=0,numClans;

		numClans = g_theCivilisationDB->NumRecords();

		m_spClan		= spNew_c3_DropDown(retval,ldlBlock,"Clan",spnewgamescreen_clanSelect);

		while(i<numClans) {
			aui_Item	*item = NULL;
			const MBCHAR *cName = g_theStringDB->GetNameStr(g_theCivilisationDB->Get(i)->GetPluralCivName());
			item = (aui_Item*)new SPDropDownListItem(retval, "SPDropDownListItem", "Clan", cName);
			if (item)
				m_spClan->AddItem(item );
			i++;
		}
	}
	{
		m_spGender		= spNew_c3_DropDown(retval,ldlBlock,"Gender",spnewgamescreen_genderSelect);
		aui_StringTable * gender = spNewStringTable(retval,"SPGenderChoicesStringTable");
		spFillDropDown(retval,m_spGender,gender,"SPDropDownListItem","Gender");
		delete gender;
	}
	m_spName		= spNewTextEntry(retval,ldlBlock,"Name");
	m_spPreferences = spNew_ctp2_Button(retval,ldlBlock,"Preferences",spnewgamescreen_preferencePress);
	m_spCustom		= spNew_ctp2_Button(retval,ldlBlock,"PCustom", spnewgamescreen_pCustomPress);

	m_PTOP			= spNew_c3_Static(retval,ldlBlock, "PTOP");
	m_PHEADER		= spNew_c3_Static(retval,ldlBlock, "PHEADER");
	m_PBOT			= spNew_c3_Static(retval,ldlBlock, "PBOT");
	m_PLEFT			= spNew_c3_Static(retval,ldlBlock, "PLEFT");
	m_PRIGHT		= spNew_c3_Static(retval,ldlBlock, "PRIGHT");
}
AUI_ERRCODE passwordscreen_Initialize( void )
{
	AUI_ERRCODE errcode = AUI_ERRCODE_OK;
	MBCHAR		windowBlock[ k_AUI_LDL_MAXBLOCK + 1 ];
	MBCHAR		controlBlock[ k_AUI_LDL_MAXBLOCK + 1 ];

	if ( s_passwordScreen ) return AUI_ERRCODE_OK;
	strcpy(windowBlock, "passwordscreen");

	s_passwordScreen = new ns_Window(
		&errcode,
		aui_UniqueId(),
		windowBlock,
		0,
		AUI_WINDOW_TYPE_FLOATING);
	Assert( AUI_NEWOK(s_passwordScreen, errcode) );
	if ( !AUI_NEWOK(s_passwordScreen, errcode) ) errcode;

	s_okButton = spNew_ctp2_Button(
				&errcode,
				windowBlock,
				"button0",
				PasswordScreenCallback);
	Assert( AUI_NEWOK(s_okButton, errcode) );
	if ( !AUI_NEWOK(s_okButton, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "askstatic" );
	s_askStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_askStatic, errcode) );
	if ( !AUI_NEWOK(s_askStatic, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "joinstatic" );
	s_joinStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_joinStatic, errcode) );
	if ( !AUI_NEWOK(s_joinStatic, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "yesnoswitchgroup" );
	s_yesnoSwitchGroup = new aui_SwitchGroup(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_yesnoSwitchGroup, errcode) );
	if ( !AUI_NEWOK(s_yesnoSwitchGroup, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "yesnoswitchgroup.yesradio" );
	s_yesRadio = new aui_Radio(
		&errcode,
		aui_UniqueId(),
		controlBlock,
		PasswordScreenCallback );

	Assert( AUI_NEWOK(s_yesRadio, errcode) );
	if ( !AUI_NEWOK(s_yesRadio, errcode) ) return errcode;

	s_yesnoSwitchGroup->AddSwitch( s_yesRadio );

	sprintf( controlBlock, "%s.%s", windowBlock, "yesnoswitchgroup.noradio" );
	s_noRadio = new aui_Radio(
		&errcode,
		aui_UniqueId(),
		controlBlock,
		PasswordScreenCallback );
	Assert( AUI_NEWOK(s_noRadio, errcode) );
	if ( !AUI_NEWOK(s_noRadio, errcode) ) return errcode;

	s_yesnoSwitchGroup->AddSwitch( s_noRadio );

	sprintf( controlBlock, "%s.%s", windowBlock, "inputstatic" );
	s_inputStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_inputStatic, errcode) );
	if ( !AUI_NEWOK(s_inputStatic, errcode) ) return errcode;
	Assert( AUI_NEWOK(s_yesnoSwitchGroup, errcode) );
	if ( !AUI_NEWOK(s_yesnoSwitchGroup, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "inputtextfield" );
	s_inputTextField = new C3TextField(
		&errcode,
		aui_UniqueId(),
		controlBlock,
		PasswordScreenCallback );
	Assert( AUI_NEWOK(s_inputTextField, errcode) );
	if ( !AUI_NEWOK(s_inputTextField, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "denystatic" );
	s_denyStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_denyStatic, errcode) );
	if ( !AUI_NEWOK(s_denyStatic, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "fullstatic" );
	s_fullStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_fullStatic, errcode) );
	if ( !AUI_NEWOK(s_fullStatic, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "nolobbystatic" );
	s_nolobbyStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_nolobbyStatic, errcode) );
	if ( !AUI_NEWOK(s_nolobbyStatic, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "connectionloststatic" );
	s_connectionlostStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_connectionlostStatic, errcode) );
	if ( !AUI_NEWOK(s_connectionlostStatic, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "nodialupstatic" );
	s_nodialupStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_nodialupStatic, errcode) );
	if ( !AUI_NEWOK(s_nodialupStatic, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "connectionerrstatic" );
	s_connectionerrStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_connectionerrStatic, errcode) );
	if ( !AUI_NEWOK(s_connectionerrStatic, errcode) ) return errcode;

	sprintf( controlBlock, "%s.%s", windowBlock, "noscenariostatic" );
	s_scenarionotfoundStatic = new c3_Static(
		&errcode,
		aui_UniqueId(),
		controlBlock );
	Assert( AUI_NEWOK(s_scenarionotfoundStatic, errcode) );
	if ( !AUI_NEWOK(s_scenarionotfoundStatic, errcode) ) return errcode;

	return AUI_ERRCODE_OK;
}
InitPlayWindow::InitPlayWindow
(
    AUI_ERRCODE *       retval, 
    uint32              id,
    MBCHAR *			ldlBlock, 
    sint32              bpp, 
    AUI_WINDOW_TYPE     type, 
    bool                bevel
)
: 
    C3Window        (retval, id, ldlBlock, bpp, type, bevel),
    m_spriteTest    (spNew_ctp2_Button
                       (retval, ldlBlock, 
		   		        "SpriteTestButton", "Sprite Test", spritetest_spPress, 
                        "CTP2_BUTTON_TEXT_RIGHT_LARGE"
                       )
                    ),
    m_email         (spNew_ctp2_Button
                       (retval, ldlBlock, 
		   		        "EmailButton", "Email",	initialplayscreen_emailPress, 
                        "CTP2_BUTTON_TEXT_RIGHT_LARGE"
                       )
                    ),
    m_hotseat       (spNew_ctp2_Button
                       (retval, ldlBlock, 
		   		        "HotSeatButton", "Hotseat", initialplayscreen_hotseatPress, 
                        "CTP2_BUTTON_TEXT_RIGHT_LARGE"
                       )
                    ),
    m_mp            (spNew_ctp2_Button
                       (retval, ldlBlock, 
		   		        "MPButton", "Multiplayer", initialplayscreen_mpPress, 
                        "CTP2_BUTTON_TEXT_RIGHT_LARGE"
                       )
                    ),
    m_credits       (spNew_ctp2_Button
                       (retval, ldlBlock, 
		   		        "CreditsButton", "Credits", initialplayscreen_creditsPress, 
                        "CTP2_BUTTON_TEXT_RIGHT_LARGE"
                       )
                    ),
    m_quit          (spNew_ctp2_Button
                       (retval, ldlBlock, 
		   		        "QuitButton", "Quit Out", initialplayscreen_quitPress, 
                        "CTP2_BUTTON_TEXT_RIGHT_LARGE"
                       )
                    ),
    // New buttons moved from the SP screen (code taken from spwindow.cpp)
    m_tutorial      (spNew_ctp2_Button
                       (retval, ldlBlock, "TutorialButton", initialplayscreen_tutorialPress)
                    ),
    m_newgame       (spNew_ctp2_Button
                       (retval, ldlBlock, "NewGameButton", initialplayscreen_newgamePress)
                    ),
    m_loadgame      (spNew_ctp2_Button
                       (retval, ldlBlock, "LoadGameButton", initialplayscreen_loadgamePress)
                    ),
    m_options       (spNew_ctp2_Button
                       (retval, ldlBlock, "OptionsButton", initialplayscreen_optionsPress)
                    ),
    m_background    (spNew_c3_Static(retval, ldlBlock, "Background")),
    m_testBox       (new ctp2_Static
                        (retval, aui_UniqueId(), "InitPlayWindow.TestTextBox")
                    )
{
#ifndef _DEBUG
    m_spriteTest->Hide();
#endif
}
AUI_ERRCODE graphicsscreen_Initialize( void )
{
	s_gridToggled = FALSE;
	s_cityInfluenceToggled = FALSE;
	s_politicalBordersToggled = FALSE;

	if ( s_graphicsWindow ) return AUI_ERRCODE_OK;

	AUI_ERRCODE errcode = AUI_ERRCODE_OK;
	MBCHAR		windowBlock[ k_AUI_LDL_MAXBLOCK + 1 ];

	strcpy(windowBlock, "GraphicsWindow");
	s_graphicsWindow = new c3_PopupWindow(
		&errcode,
		aui_UniqueId(),
		windowBlock,
		16,
		AUI_WINDOW_TYPE_FLOATING,
		false );
	Assert( AUI_NEWOK(s_graphicsWindow, errcode) );
	if ( !AUI_NEWOK(s_graphicsWindow, errcode) ) return errcode;

	s_graphicsWindow->SetStronglyModal(TRUE);


	s_walk				= spNew_aui_Switch(&errcode,windowBlock,"WalkButton",graphicsscreen_checkPress,&check[GS_WALK]);
	s_trade				= spNew_aui_Switch(&errcode,windowBlock,"TradeButton",graphicsscreen_checkPress,&check[GS_TRADE]);
	s_wonder			= spNew_aui_Switch(&errcode,windowBlock,"WonderButton",graphicsscreen_checkPress,&check[GS_WONDER]);
	s_politicalBorders	= spNew_aui_Switch(&errcode,windowBlock,"PoliticalBordersButton",graphicsscreen_checkPress,&check[GS_POLITICALBORDERS]);
	s_tradeRoutes		= spNew_aui_Switch(&errcode,windowBlock,"TradeRoutesButton",graphicsscreen_checkPress,&check[GS_TRADEROUTES]);
	s_cityInfluence		= spNew_aui_Switch(&errcode,windowBlock,"CityInflenceButton",graphicsscreen_checkPress,&check[GS_CITYINFLUENCE]);
	s_grid				= spNew_aui_Switch(&errcode,windowBlock,"GridButton",graphicsscreen_checkPress,&check[GS_GRID]);
	s_cityNames			= spNew_aui_Switch(&errcode,windowBlock,"CityNamesButton", graphicsscreen_checkPress, &check[GS_CITYNAMES]);
	s_armyNames			= spNew_aui_Switch(&errcode,windowBlock,"ArmyNamesButton", graphicsscreen_checkPress, &check[GS_ARMYNAMES]);
	s_civflags			= spNew_aui_Switch(&errcode,windowBlock,"CivFlagButton", graphicsscreen_checkPress, &check[GS_CIVFLAGS]);

	s_resScreenButton	= spNew_ctp2_Button( &errcode, windowBlock, "ResolutionButton", graphicsscreen_selectResolution );

	s_smooth			= spNew_aui_Switch(&errcode,windowBlock,"SmoothButton", graphicsscreen_checkPress, &check[GS_SMOOTH]);
	s_goodAnims			= spNew_aui_Switch(&errcode,windowBlock,"GoodsButton",graphicsscreen_checkPress,&check[GS_GOODANIMS]);
	s_cityProd			= spNew_aui_Switch(&errcode,windowBlock,"ShowCityProdButton",graphicsscreen_checkPress,&check[GS_CITYPROD]);

	s_unitSpeed			= spNew_C3Slider(&errcode, windowBlock, "UnitSpeedSlider", graphicsscreen_unitSpeedSlide);
	s_unitSpeedN		= spNew_c3_Static(&errcode, windowBlock, "UnitSpeedName");

	if(g_theProfileDB) {
		s_unitSpeed->SetValue(g_theProfileDB->GetUnitSpeed(), 0);
	} else {
		s_unitSpeed->SetValue(0,0);
	}

	s_walk				->SetState(g_theProfileDB->IsUnitAnim());
	s_trade				->SetState(g_theProfileDB->IsTradeAnim());
	s_wonder			->SetState(g_theProfileDB->IsWonderMovies());
	s_politicalBorders	->SetState(g_theProfileDB->GetShowPoliticalBorders());
	s_tradeRoutes		->SetState(g_theProfileDB->GetShowTradeRoutes());
	s_cityNames			->SetState(g_theProfileDB->GetShowCityNames());
	s_armyNames			->SetState(g_theProfileDB->GetShowArmyNames());
	s_civflags			->SetState(g_theProfileDB->IsCivFlags());
	s_smooth			->SetState(g_theProfileDB->IsSmoothBorders());
	s_goodAnims			->SetState(g_theProfileDB->IsGoodAnim());
	s_cityInfluence		->SetState(g_theProfileDB->IsShowCityInfluence());
	s_grid				->SetState(g_isGridOn);
	s_cityProd			->SetState(g_theProfileDB->IsShowCityProduction());

	MBCHAR block[ k_AUI_LDL_MAXBLOCK + 1 ];
	sprintf( block, "%s.%s", windowBlock, "Name" );
	s_graphicsWindow->AddTitle( block );
	s_graphicsWindow->AddClose( graphicsscreen_exitPress );

	errcode = aui_Ldl::SetupHeirarchyFromRoot( windowBlock );
	Assert( AUI_SUCCESS(errcode) );

	return AUI_ERRCODE_OK;
}
SPWorldBox::SPWorldBox ( AUI_ERRCODE *retval, uint32 id, MBCHAR *ldlBlock ) :
	m_mapSize(NULL), m_worldType(NULL), m_worldShape(NULL),
	m_difficulty(NULL), m_riskLevel(NULL), m_opponent(NULL), m_spCustom(NULL),
	m_WTOP(NULL),
	m_WHEADER(NULL),
	m_WBOT(NULL),
	m_WLEFT(NULL),
	m_WRIGHT(NULL)
{
	m_mapSize		= spNew_c3_DropDown(retval,ldlBlock,"MapSize",spnewgamescreen_mapSizeSelect);
	{
		aui_StringTable * mysizes = spNewStringTable(retval,"SPMapSizeStringTable");
		spFillDropDown(retval,m_mapSize,mysizes,"SPDropDownListItem","MapSize");
		delete mysizes;
	}
	m_worldType		= spNew_c3_DropDown(retval,ldlBlock,"WorldType",spnewgamescreen_worldTypeSelect);
	{
		aui_StringTable * mytypes = spNewStringTable(retval,"SPWorldTypeStringTable");
		spFillDropDown(retval,m_worldType,mytypes,"SPDropDownListItem","WorldType");
		delete mytypes;
	}
	m_worldShape	= spNew_c3_DropDown(retval,ldlBlock,"WorldShape",spnewgamescreen_worldShapeSelect);
	{
		aui_StringTable * myshapes	= spNewStringTable(retval,"SPWorldShapeStringTable");
		spFillDropDown(retval,m_worldShape,myshapes,"SPDropDownListItem","WorldShape");
		delete myshapes;
	}
	m_difficulty	= spNew_c3_DropDown(retval,ldlBlock,"Difficulty",spnewgamescreen_difficultySelect);
	{
		aui_StringTable * mydiffs = spNewStringTable(retval,"SPDifficultyStringTable");
		spFillDropDown(retval,m_difficulty,mydiffs,"SPDropDownListItem","Difficulty");
		delete mydiffs;

		m_difficulty->SetSelectedItem(g_theProfileDB->GetDifficulty());
	}
	m_riskLevel		= spNew_c3_DropDown(retval,ldlBlock,"RiskLevel",spnewgamescreen_riskLevelSelect);
	{
		aui_StringTable * myrisks = spNewStringTable(retval,"SPRiskLevelStringTable");
		spFillDropDown(retval,m_riskLevel,myrisks,"SPDropDownListItem","RiskLevel");
		delete myrisks;

		m_riskLevel->SetSelectedItem(g_theProfileDB->GetRiskLevel());
	}
	m_opponent		= spNew_c3_DropDown(retval,ldlBlock,"Opponent",spnewgamescreen_opponentSelect);
	{
		for(uint32 i=3; i<=16; i++) {
			MBCHAR			textBlock[ k_AUI_LDL_MAXBLOCK + 1 ];
			sprintf(textBlock, "%d",i);
			c3_ListItem *myitem = new SPDropDownListItem(retval,"SPDropDownListItem","Opponent", textBlock);
			if(myitem) m_opponent->AddItem(myitem);
		}

		uint32 numPlayers = g_theProfileDB->GetNPlayers();
		Assert((numPlayers>2) && (numPlayers<17));
		m_opponent->SetSelectedItem(numPlayers-3);
	}
	m_spCustom		= spNew_ctp2_Button(retval,ldlBlock,"WCustom", spnewgamescreen_wCustomPress);

	m_WTOP			= spNew_c3_Static(retval,ldlBlock, "WTOP");
	m_WHEADER		= spNew_c3_Static(retval,ldlBlock, "WHEADER");
	m_WBOT			= spNew_c3_Static(retval,ldlBlock, "WBOT");
	m_WLEFT			= spNew_c3_Static(retval,ldlBlock, "WLEFT");
	m_WRIGHT		= spNew_c3_Static(retval,ldlBlock, "WRIGHT");
}
SPNewGameWindow::SPNewGameWindow(AUI_ERRCODE *retval, uint32 id,
		MBCHAR *ldlBlock, sint32 bpp, AUI_WINDOW_TYPE type, bool bevel)
:
    C3Window                (retval, id, ldlBlock, bpp, type, bevel),
	m_spStart               (NULL),
    m_spOk                  (NULL),
    m_spReturn              (NULL),
	m_spTribe               (NULL),
    m_spDifficulty          (NULL),
	m_spMapSize             (NULL),
    m_spPlayers             (NULL),
	m_spMap                 (NULL),
    m_spRules               (NULL),
	m_spEditor              (NULL),
	m_spScenario            (NULL),
	m_spGeneral             (NULL),
    m_spWorld               (NULL),
    m_spCustom              (NULL),
    m_spName                (NULL),
	m_mapTypeButton         (NULL),
	m_mapTypeLabel          (NULL),
	m_worldShapeButton      (NULL),
	m_worldShapeLabel       (NULL),
    m_useCustomMap          (false),
    m_civilizationLabel     (NULL),
	m_leaderNameLabel       (NULL),
	m_difficultyLabel       (NULL),
	m_worldSizeLabel        (NULL),
	m_rulesLabel            (NULL),
	m_playersLabel          (NULL),
	m_worldTypeLabel        (NULL),
	m_quitButton            (NULL),
	m_spTitle               (NULL),
	m_spBackground          (NULL),
	m_string                (NULL),
	m_scenarioName          (NULL),
	m_scenarioStaticText    (NULL)
{
	Assert(AUI_SUCCESS(*retval));

	m_spStart = spNew_ctp2_Button(retval,ldlBlock,"StartButton",spnewgamescreen_startPress);
	m_spReturn = spNew_ctp2_Button(retval,ldlBlock,"ReturnButton",spnewgamescreen_returnPress);
	m_scenarioName = spNew_c3_Static(retval, ldlBlock, "ScenarioName");
	m_scenarioStaticText = spNew_c3_Static(retval, ldlBlock, "ScenarioStaticText");
	m_spTribe		= spNew_ctp2_Button( retval, ldlBlock, "TribeButton", spnewgamescreen_tribePress );
	m_spDifficulty	= spNew_ctp2_Button( retval, ldlBlock, "DifficultyButton", spnewgamescreen_difficultyPress );
	m_spMapSize		= spNew_ctp2_Button( retval, ldlBlock, "MapSizeButton", spnewgamescreen_mapSizePress );
	m_spPlayers		= spNew_ctp2_Button( retval, ldlBlock, "PlayersButton", spnewgamescreen_playersPress );
	m_spMap			= spNew_ctp2_Button( retval, ldlBlock, "MapButton", spnewgamescreen_mapPress );
	m_spRules		= spNew_ctp2_Button( retval, ldlBlock, "RulesButton", spnewgamescreen_rulesPress );
	m_spEditor = spNew_ctp2_Button(retval, ldlBlock, "EditorButton", spnewgamescreen_editorPress);
	m_spScenario = spNew_ctp2_Button(retval, ldlBlock, "ScenarioButton", spnewgamescreen_scenarioPress);
	m_spName = spNewTextEntry(retval,ldlBlock,"Name");
	m_worldShapeLabel = spNew_c3_Static( retval, ldlBlock, "WorldShapeLabel" );
	m_worldShapeButton = spNew_ctp2_Button( retval, ldlBlock, "WorldShapeButton", spnewgamescreen_worldShapePress );
	m_civilizationLabel = spNew_c3_Static( retval, ldlBlock, "CivilizationLabel" );
	m_leaderNameLabel = spNew_c3_Static( retval, ldlBlock, "LeaderNameLabel" );
	m_difficultyLabel = spNew_c3_Static( retval, ldlBlock, "DifficultyLabel" );
	m_worldSizeLabel = spNew_c3_Static( retval, ldlBlock, "MapSizeLabel" );
	m_rulesLabel = spNew_c3_Static( retval, ldlBlock, "RulesLabel" );
	m_playersLabel = spNew_c3_Static( retval, ldlBlock, "PlayersLabel" );
	m_worldTypeLabel = spNew_c3_Static( retval, ldlBlock, "MapButtonLabel" );
	m_quitButton = spNew_ctp2_Button( retval, ldlBlock, "QuitButton", spnewgamescreen_quitPress );
	m_spTitle			= spNew_c3_Static(retval,ldlBlock,"Title");
	m_spBackground		= spNew_c3_Static(retval,ldlBlock,"Background");
	m_string			= spNewStringTable(retval,"SPNewGameStrings");

	// Reset failsafe start/end ages here, so they're correct before agesscreen is initialized.
	g_theProfileDB->SetSPStartingAge(0);
	g_theProfileDB->SetSPEndingAge(g_theAgeDB->NumRecords() - 1);
	g_theProfileDB->Save();

    Update();
}
AUI_ERRCODE PlayerSelectWindow::CreateControls( void )
{
	AUI_ERRCODE errcode = AUI_ERRCODE_OK;


	
	aui_Control *control;

	control = new c3_Static(
		&errcode,
		aui_UniqueId(),
		"playerselectwindow.titlestatictext" );
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_TITLESTATICTEXT ] = control;

	control = new c3_Static(
		&errcode,
		aui_UniqueId(),
		"playerselectwindow.currentplayerstatictext" );
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_CURRENTPLAYERSTATICTEXT ] = control;

	control = new C3TextField(
		&errcode,
		aui_UniqueId(),
		"playerselectwindow.playernametextfield" );
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_PLAYERNAMETEXTFIELD ] = control;

	control = new ns_PlayerSetupListBox(
		&errcode,
		aui_UniqueId(),
		"playerselectwindow.playernamelistbox" );
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_PLAYERNAMELISTBOX ] = control;

	control = new c3_Static(
		&errcode,
		aui_UniqueId(),
		"playerselectwindow.playernamelistbox.playernamestatictext" );
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_PLAYERNAMESTATICTEXT ] = control;

	control = spNew_ctp2_Button(&errcode,
		"playerselectwindow",
		"newbutton", NULL);
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_NEWBUTTON ] = control;

	control = spNew_ctp2_Button(&errcode,
		"playerselectwindow",
		"editbutton", NULL);
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_EDITBUTTON ] = control;

	control = spNew_ctp2_Button(&errcode,
		"playerselectwindow",
		"deletebutton", NULL);
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_DELETEBUTTON ] = control; 

 
	control = new aui_Button(
		&errcode,
		aui_UniqueId(),
		"playerselectwindow.okbutton" );
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_OKBUTTON ] = control;

	control = new aui_Button(
		&errcode,
		aui_UniqueId(),
		"playerselectwindow.cancelbutton" );
	Assert( AUI_NEWOK(control,errcode) );
	if ( !AUI_NEWOK(control,errcode) ) return errcode;
	m_controls[ CONTROL_CANCELBUTTON ] = control;


	
	aui_Ldl::SetupHeirarchyFromRoot( "playerselectwindow" );


	
	aui_Action *action;

	action = new PlayerNameTextFieldAction;
	Assert( action != NULL );
	if ( !action ) return AUI_ERRCODE_MEMALLOCFAILED;
	m_controls[ CONTROL_PLAYERNAMETEXTFIELD ]->SetAction( action );

	action = new NewButtonAction;
	Assert( action != NULL );
	if ( !action ) return AUI_ERRCODE_MEMALLOCFAILED;
	m_controls[ CONTROL_NEWBUTTON ]->SetAction( action );

	action = new EditButtonAction;
	Assert( action != NULL );
	if ( !action ) return AUI_ERRCODE_MEMALLOCFAILED;
	m_controls[ CONTROL_EDITBUTTON ]->SetAction( action );

	action = new DeleteButtonAction;
	Assert( action != NULL );
	if ( !action ) return AUI_ERRCODE_MEMALLOCFAILED;
	m_controls[ CONTROL_DELETEBUTTON ]->SetAction( action );

	action = new OKButtonAction;
	Assert( action != NULL );
	if ( !action ) return AUI_ERRCODE_MEMALLOCFAILED;
	m_controls[ CONTROL_OKBUTTON ]->SetAction( action );

	action = new CancelButtonAction;
	Assert( action != NULL );
	if ( !action ) return AUI_ERRCODE_MEMALLOCFAILED;
	m_controls[ CONTROL_CANCELBUTTON ]->SetAction( action );

	action = new PlayerListBoxAction;
	Assert( action != NULL );
	if ( !action ) return AUI_ERRCODE_MEMALLOCFAILED;
	m_controls[ CONTROL_PLAYERNAMELISTBOX ]->SetAction( action );

	
		((aui_ListBox *)m_controls[ CONTROL_PLAYERNAMELISTBOX ])->
		SetForceSelect( TRUE );

	Update();

	return AUI_ERRCODE_OK;
}
void
SpriteEditWindow::InitializeControls(AUI_ERRCODE *errcode,MBCHAR *windowBlock)
{

	m_Load = spNew_ctp2_Button(errcode,windowBlock,"STLoadButton","No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_Save = spNew_ctp2_Button(errcode,windowBlock,"STSaveButton","No Data",NULL,"CTP2_BUTTON_TITLE_BAR");

	m_fileName		= spNewTextEntry(errcode,windowBlock,"Name");

	m_MOVEAnim  	=spNew_ctp2_Button(errcode,windowBlock,"STMOVEAnim"   ,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_ATTACKAnim	=spNew_ctp2_Button(errcode,windowBlock,"STATTACKAnim" ,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_IDLEAnim  	=spNew_ctp2_Button(errcode,windowBlock,"STIDLEAnim"   ,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_VICTORYAnim	=spNew_ctp2_Button(errcode,windowBlock,"STVICTORYAnim","No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_WORKAnim		=spNew_ctp2_Button(errcode,windowBlock,"STWORKAnim"   ,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");

	m_MOVEAnim		->SetActionFuncAndCookie(AnimCallback,(void *)UNITACTION_MOVE   );
	m_ATTACKAnim	->SetActionFuncAndCookie(AnimCallback,(void *)UNITACTION_ATTACK );
	m_IDLEAnim		->SetActionFuncAndCookie(AnimCallback,(void *)UNITACTION_IDLE   );
	m_VICTORYAnim	->SetActionFuncAndCookie(AnimCallback,(void *)UNITACTION_VICTORY);
	m_WORKAnim		->SetActionFuncAndCookie(AnimCallback,(void *)UNITACTION_WORK   );

	m_stepPlus		=spNew_ctp2_Button(errcode,windowBlock,"STPlayStepPlus"	,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_stepMinus		=spNew_ctp2_Button(errcode,windowBlock,"STPlayStepMinus","No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_playOnce		=spNew_ctp2_Button(errcode,windowBlock,"STPlayOnce"		,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_playLoop		=spNew_ctp2_Button(errcode,windowBlock,"STPlayLoop"		,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_facingPlus	=spNew_ctp2_Button(errcode,windowBlock,"STFacingPlus"	,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");
	m_facingMinus	=spNew_ctp2_Button(errcode,windowBlock,"STFacingMinus"	,"No Data",NULL,"CTP2_BUTTON_TITLE_BAR");

	m_Load ->SetActionFuncAndCookie(FileButtonActionCallback,(void *)true );
	m_Save ->SetActionFuncAndCookie(FileButtonActionCallback,(void *)false);

	m_stepPlus		->SetActionFuncAndCookie(StepCallback	,(void *) 1);
	m_stepMinus		->SetActionFuncAndCookie(StepCallback	,(void *)-1);
	m_playOnce		->SetActionFuncAndCookie(PlayCallback	,(void *)true);
	m_playLoop		->SetActionFuncAndCookie(PlayCallback	,(void *)false);
	m_facingPlus	->SetActionFuncAndCookie(FacingCallback	,(void *) 1);
	m_facingMinus	->SetActionFuncAndCookie(FacingCallback	,(void *)-1);

	m_largeImage = new C3Window(errcode, aui_UniqueId(),"STLargeImage", 16 );

	g_c3ui->AddWindow( m_largeImage );

	m_hotCoordsCurrent = new c3_Static(errcode, aui_UniqueId(),"SpriteEditor.CoordsHotSpot");
	m_hotCoordsMouse   = new c3_Static(errcode, aui_UniqueId(),"SpriteEditor.CoordsCursor" );
	m_hotCoordsHerald  = new c3_Static(errcode, aui_UniqueId(),"SpriteEditor.CoordsHerald");





	m_Load		->SetParent(g_spriteEditWindow);
	m_Save		->SetParent(g_spriteEditWindow);

	m_fileName	 ->SetParent(g_spriteEditWindow);

	m_MOVEAnim   ->SetParent(g_spriteEditWindow);
	m_ATTACKAnim ->SetParent(g_spriteEditWindow);
	m_IDLEAnim   ->SetParent(g_spriteEditWindow);
	m_VICTORYAnim->SetParent(g_spriteEditWindow);
	m_WORKAnim	 ->SetParent(g_spriteEditWindow);

	m_stepPlus	 ->SetParent(g_spriteEditWindow);
	m_stepMinus	 ->SetParent(g_spriteEditWindow);
	m_playOnce	 ->SetParent(g_spriteEditWindow);
	m_playLoop	 ->SetParent(g_spriteEditWindow);
	m_facingPlus ->SetParent(g_spriteEditWindow);
	m_facingMinus->SetParent(g_spriteEditWindow);

	m_largeImage ->SetParent(g_spriteEditWindow);

	m_hotCoordsCurrent->SetParent(g_spriteEditWindow);
	m_hotCoordsMouse  ->SetParent(g_spriteEditWindow);
	m_hotCoordsHerald ->SetParent(g_spriteEditWindow);

	m_Load		->Show();
	m_Save		->Show();

	m_fileName	->Show();

	m_MOVEAnim   ->Show();
	m_ATTACKAnim ->Show();
	m_IDLEAnim   ->Show();
	m_VICTORYAnim->Show();
	m_WORKAnim	 ->Show();

	m_stepPlus	 ->Show();
	m_stepMinus	 ->Show();
	m_playOnce	 ->Show();
	m_playLoop	 ->Show();
	m_facingPlus ->Show();
	m_facingMinus->Show();

	m_largeImage ->Show();

	m_hotCoordsCurrent->Show();
	m_hotCoordsMouse  ->Show();
	m_hotCoordsHerald ->Show();

	m_largeSurface=m_largeImage->TheSurface();
}