示例#1
0
void C4StartupNetDlg::OnShown()
{
	// callback when shown: Start searching for games
	C4StartupDlg::OnShown();
	CheckVersionUpdate();
	UpdateList();
	UpdateUpdateButton(); // in case update check was finished before callback registration
	UpdateMasterserver();
	OnSec1Timer();
	tLastRefresh = time(nullptr);
	// also update chat
	if (pChatCtrl) pChatCtrl->OnShown();
}
C4StartupAboutDlg::C4StartupAboutDlg() : C4StartupDlg("")
	{
	// ctor
	UpdateSize();
	
	// key bindings: No longer back on any key
	pKeyBack = NULL;
	//C4CustomKey::CodeList keys;
	//keys.push_back(C4KeyCodeEx(KEY_Any)); keys.push_back(C4KeyCodeEx(KEY_JOY_AnyButton));
	//pKeyBack = new C4KeyBinding(keys, "StartupAboutBack", KEYSCOPE_Gui,
	//	new C4GUI::DlgKeyCB<C4StartupAboutDlg>(*this, &C4StartupAboutDlg::KeyBack), C4CustomKey::PRIO_Dlg);

	// version and registration info in topright corner
	C4Rect rcClient = GetContainedClientRect();
	StdStrBuf sVersion; sVersion.Format(LoadResStr("IDS_DLG_VERSION"), C4VERSION);
	CStdFont &rUseFont = C4GUI::GetRes()->TextFont;
	int32_t iInfoWdt = Min<int32_t>(rcClient.Wdt/2, rUseFont.GetTextWidth("General info text width")*2);
	C4GUI::ComponentAligner caInfo(C4Rect(rcClient.x + rcClient.Wdt - iInfoWdt, rcClient.y, iInfoWdt, rcClient.Hgt/8), 0,0, false);
	AddElement(new C4GUI::Label(sVersion.getData(), caInfo.GetGridCell(0,1,0,4), ARight));
	StdStrBuf sRegStr, sKeyFile;
	if (Config.Registered())
		{
		StdStrBuf sRegName, sFirstName, sLastName, sNick;
		sFirstName.Copy(Config.GetRegistrationData("FirstName"));
		sLastName.Copy(Config.GetRegistrationData("LastName"));
		sNick.Copy(Config.GetRegistrationData("Nick"));
		sRegName.Format("%s %s (%s)", sFirstName.getData(), sLastName.getData(), sNick.getData());
		sRegStr.Format(LoadResStr("IDS_PRC_REG"), sRegName.getData());
		sKeyFile.Format(LoadResStr("IDS_CTL_KEYFILE")); sKeyFile+=" "; sKeyFile+=Config.GetKeyFilename();
		C4GUI::Label *pLbl;
		AddElement(pLbl = new C4GUI::Label(sRegStr.getData(), caInfo.GetGridCell(0,1,1,4), ARight));
		pLbl->SetToolTip(sKeyFile.getData());
		AddElement(pLbl = new C4GUI::Label(FormatString("%s %s", LoadResStr("IDS_CTL_CUID"), Config.GetRegistrationData("Cuid")).getData(), caInfo.GetGridCell(0,1,2,4), ARight));
		pLbl->SetToolTip(sKeyFile.getData());
		AddElement(pWebCodeLbl = new C4GUI::Label("", caInfo.GetGridCell(0,1,3,4), ARight));
		pWebCodeLbl ->SetToolTip(sKeyFile.getData());
		}
	else
		{
		/*AddElement(new C4GUI::Label(FormatString("%s - %s", "FREEWARE", LoadResStr("IDS_CTL_UNREGISTERED")).getData(), caInfo.GetGridCell(0,1,1,4), ARight));*/
		AddElement(new C4GUI::Label("FREEWARE", caInfo.GetGridCell(0,1,1,4), ARight));
		AddElement(new C4GUI::Label(Config.GetRegistrationError(), caInfo.GetGridCell(0,1,2,4), ARight));
		pWebCodeLbl = NULL;
		}
	// webcode-display timer
	iWebCodeTimer = C4AboutWebCodeShowTime + 1;
	pSec1Timer = new C4Sec1TimerCallback<C4StartupAboutDlg>(this);
	OnSec1Timer();

	// bottom line buttons
	C4GUI::ComponentAligner caMain(rcClient, 0,0, true);
	C4GUI::ComponentAligner caButtons(caMain.GetFromBottom(caMain.GetHeight()*1/8), 0,0, false);
	C4GUI::CallbackButton<C4StartupAboutDlg> *btn;
	int32_t iButtonWidth = caButtons.GetInnerWidth() / 4;
	AddElement(btn = new C4GUI::CallbackButton<C4StartupAboutDlg>(LoadResStr("IDS_BTN_BACK"), caButtons.GetGridCell(0,3,0,1,iButtonWidth,C4GUI_ButtonHgt,true), &C4StartupAboutDlg::OnBackBtn));
	btn->SetToolTip(LoadResStr("IDS_DLGTIP_BACKMAIN"));
	/*if (!Config.Registered())
		{
		AddElement(btn = new C4GUI::CallbackButton<C4StartupAboutDlg>(LoadResStr("IDS_BTN_REGISTERNOW"), caButtons.GetGridCell(1,3,0,1,iButtonWidth,C4GUI_ButtonHgt,true), &C4StartupAboutDlg::OnRegisterBtn));
		btn->SetToolTip(LoadResStr("IDS_DESC_GOTOTHEONLINEREGISTRATION"));
		}*/
#ifdef NETWORK
	AddElement(btn = new C4GUI::CallbackButton<C4StartupAboutDlg>(LoadResStr("IDS_BTN_CHECKFORUPDATES"), caButtons.GetGridCell(2,3,0,1,iButtonWidth,C4GUI_ButtonHgt,true), &C4StartupAboutDlg::OnUpdateBtn));
	btn->SetToolTip(LoadResStr("IDS_DESC_CHECKONLINEFORNEWVERSIONS"));
#endif
	}