Exemple #1
0
C4ChatControl::ChatSheet *C4ChatControl::GetSheetByTitle(
    const char *szTitle, C4ChatControl::ChatSheet::SheetType eType) {
  int32_t i = 0;
  C4GUI::Tabular::Sheet *pSheet;
  const char *szCheckTitle;
  while (pSheet = pTabChats->GetSheet(i++))
    if (szCheckTitle = pSheet->GetTitle())
      if (SEqualNoCase(szCheckTitle, szTitle)) {
        ChatSheet *pChatSheet = static_cast<ChatSheet *>(pSheet);
        if (eType == pChatSheet->GetSheetType()) return pChatSheet;
      }
  return NULL;
}
void C4ChartDialog::AddChart(const StdStrBuf &rszName)
{
	// get graph by name
	if (!Game.pNetworkStatistics || !pChartTabular) return;
	bool fOwnGraph = false;
	C4Graph *pGraph = Game.pNetworkStatistics->GetGraphByName(rszName, fOwnGraph);
	if (!pGraph) return;
	// add sheet for name
	C4GUI::Tabular::Sheet *pSheet = pChartTabular->AddSheet(rszName.getData());
	if (!pSheet) { if (fOwnGraph) delete pGraph; return; }
	// add chart to sheet
	C4Chart *pNewChart = new C4Chart(pSheet->GetClientRect());
	pNewChart->SetGraph(pGraph, fOwnGraph);
	pSheet->AddElement(pNewChart);
}
Exemple #3
0
void C4ChatControl::UpdateSize() {
  // parent update
  typedef C4GUI::Window ParentClass;
  ParentClass::UpdateSize();
  // position child elements
  pTabMain->SetBounds(GetContainedClientRect());
  pTabChats->SetBounds(pTabChats->GetParent()->GetContainedClientRect());
  C4GUI::Tabular::Sheet *pSheetLogin = pTabMain->GetSheet(0);
  C4GUI::ComponentAligner caLoginSheet(pSheetLogin->GetContainedClientRect(), 0,
                                       0, false);
  CStdFont *pUseFont = &C4GUI::GetRes()->TextFont;
  int32_t iIndent1 = C4GUI_DefDlgSmallIndent / 2,
          iIndent2 = C4GUI_DefDlgIndent / 2;
  int32_t iLoginHgt = pUseFont->GetLineHeight() * 8 + iIndent1 * 10 +
                      iIndent2 * 10 + C4GUI_ButtonHgt + 20;
  int32_t iLoginWdt = iLoginHgt * 2 / 3;
  C4GUI::ComponentAligner caLogin(
      caLoginSheet.GetCentered(
          Min<int32_t>(iLoginWdt, caLoginSheet.GetInnerWidth()),
          Min<int32_t>(iLoginHgt, caLoginSheet.GetInnerHeight())),
      iIndent1, iIndent1);
  pLblLoginNick->SetBounds(caLogin.GetFromTop(pUseFont->GetLineHeight()));
  pEdtLoginNick->SetBounds(
      caLogin.GetFromTop(C4GUI::Edit::GetDefaultEditHeight()));
  caLogin.ExpandTop(2 * (iIndent1 - iIndent2));
  pLblLoginPass->SetBounds(caLogin.GetFromTop(pUseFont->GetLineHeight()));
  pEdtLoginPass->SetBounds(
      caLogin.GetFromTop(C4GUI::Edit::GetDefaultEditHeight()));
  caLogin.ExpandTop(2 * (iIndent1 - iIndent2));
  pLblLoginRealName->SetBounds(caLogin.GetFromTop(pUseFont->GetLineHeight()));
  pEdtLoginRealName->SetBounds(
      caLogin.GetFromTop(C4GUI::Edit::GetDefaultEditHeight()));
  caLogin.ExpandTop(2 * (iIndent1 - iIndent2));
  pLblLoginChannel->SetBounds(caLogin.GetFromTop(pUseFont->GetLineHeight()));
  pEdtLoginChannel->SetBounds(
      caLogin.GetFromTop(C4GUI::Edit::GetDefaultEditHeight()));
  caLogin.ExpandTop(2 * (iIndent1 - iIndent2));
  pBtnLogin->SetBounds(caLogin.GetFromTop(C4GUI_ButtonHgt, C4GUI_DefButtonWdt));
}
C4StartupNetDlg::C4StartupNetDlg() : C4StartupDlg(LoadResStr("IDS_DLG_NETSTART"))
{
	// ctor
	// key bindings
	C4CustomKey::CodeList keys;
	keys.emplace_back(K_BACK); keys.emplace_back(K_LEFT);
	pKeyBack = new C4KeyBinding(keys, "StartupNetBack", KEYSCOPE_Gui,
	                            new C4GUI::DlgKeyCB<C4StartupNetDlg>(*this, &C4StartupNetDlg::KeyBack), C4CustomKey::PRIO_Dlg);
	pKeyRefresh = new C4KeyBinding(C4KeyCodeEx(K_F5), "StartupNetReload", KEYSCOPE_Gui,
	                               new C4GUI::DlgKeyCB<C4StartupNetDlg>(*this, &C4StartupNetDlg::KeyRefresh), C4CustomKey::PRIO_CtrlOverride);

	// screen calculations
	UpdateSize();
	int32_t iIconSize = C4GUI_IconExWdt;
	int32_t iButtonWidth,iCaptionFontHgt, iSideSize = std::max<int32_t>(GetBounds().Wdt/6, iIconSize);
	int32_t iButtonHeight = C4GUI_ButtonHgt, iButtonIndent = GetBounds().Wdt/40;
	::GraphicsResource.CaptionFont.GetTextExtent("<< BACK", iButtonWidth, iCaptionFontHgt, true);
	iButtonWidth *= 3;
	C4GUI::ComponentAligner caMain(GetClientRect(), 0,0, true);
	C4GUI::ComponentAligner caButtonArea(caMain.GetFromBottom(caMain.GetHeight()/7),0,0);
	int32_t iButtonAreaWdt = caButtonArea.GetWidth()*7/8;
	iButtonWidth = std::min<int32_t>(iButtonWidth, (iButtonAreaWdt - 8 * iButtonIndent)/4);
	iButtonIndent = (iButtonAreaWdt - 4 * iButtonWidth) / 8;
	C4GUI::ComponentAligner caButtons(caButtonArea.GetCentered(iButtonAreaWdt, iButtonHeight),iButtonIndent,0);
	C4GUI::ComponentAligner caLeftBtnArea(caMain.GetFromLeft(iSideSize), std::min<int32_t>(caMain.GetWidth()/20, (iSideSize-C4GUI_IconExWdt)/2), caMain.GetHeight()/40);
	C4GUI::ComponentAligner caConfigArea(caMain.GetFromRight(iSideSize), std::min<int32_t>(caMain.GetWidth()/20, (iSideSize-C4GUI_IconExWdt)/2), caMain.GetHeight()/40);

	// left button area: Switch between chat and game list
	if (C4ChatDlg::IsChatEnabled())
	{
		btnGameList = new C4GUI::CallbackButton<C4StartupNetDlg, C4GUI::IconButton>(C4GUI::Ico_Ex_GameList, caLeftBtnArea.GetFromTop(iIconSize, iIconSize), '\0', &C4StartupNetDlg::OnBtnGameList);
		btnGameList->SetToolTip(LoadResStr("IDS_DESC_SHOWSAVAILABLENETWORKGAME"));
		btnGameList->SetText(LoadResStr("IDS_BTN_GAMES"));
		AddElement(btnGameList);
		btnChat = new C4GUI::CallbackButton<C4StartupNetDlg, C4GUI::IconButton>(C4GUI::Ico_Ex_Chat, caLeftBtnArea.GetFromTop(iIconSize, iIconSize), '\0', &C4StartupNetDlg::OnBtnChat);
		btnChat->SetToolTip(LoadResStr("IDS_DESC_CONNECTSTOANIRCCHATSERVER"));
		btnChat->SetText(LoadResStr("IDS_BTN_CHAT"));
		AddElement(btnChat);
	}
	else btnChat = nullptr;

	// main area: Tabular to switch between game list and chat
	pMainTabular = new C4GUI::Tabular(caMain.GetAll(), C4GUI::Tabular::tbNone);
	pMainTabular->SetDrawDecoration(false);
	pMainTabular->SetSheetMargin(0);
	AddElement(pMainTabular);

	// main area: game selection sheet
	C4GUI::Tabular::Sheet *pSheetGameList = pMainTabular->AddSheet(nullptr);
	C4GUI::ComponentAligner caGameList(pSheetGameList->GetContainedClientRect(), 0,0, false);
	C4GUI::WoodenLabel *pGameListLbl; int32_t iCaptHgt = C4GUI::WoodenLabel::GetDefaultHeight(&::GraphicsResource.TextFont);
	pGameListLbl = new C4GUI::WoodenLabel(LoadResStr("IDS_NET_GAMELIST"), caGameList.GetFromTop(iCaptHgt), C4GUI_Caption2FontClr, &::GraphicsResource.TextFont, ALeft);
	// search field
	C4GUI::WoodenLabel *pSearchLbl;
	const char *szSearchLblText = LoadResStr("IDS_NET_MSSEARCH");
	int32_t iSearchWdt=100, iSearchHgt;
	::GraphicsResource.TextFont.GetTextExtent(szSearchLblText, iSearchWdt, iSearchHgt, true);
	C4GUI::ComponentAligner caSearch(caGameList.GetFromTop(iSearchHgt), 0,0);
	pSearchLbl = new C4GUI::WoodenLabel(szSearchLblText, caSearch.GetFromLeft(iSearchWdt+10), C4GUI_Caption2FontClr, &::GraphicsResource.TextFont);
	const char *szSearchTip = LoadResStr("IDS_NET_MSSEARCH_DESC");
	pSearchLbl->SetToolTip(szSearchTip);
	pSheetGameList->AddElement(pSearchLbl);
	pSearchFieldEdt = new C4GUI::CallbackEdit<C4StartupNetDlg>(caSearch.GetAll(), this, &C4StartupNetDlg::OnSearchFieldEnter);
	pSearchFieldEdt->SetToolTip(szSearchTip);
	pSheetGameList->AddElement(pSearchFieldEdt);
	pSheetGameList->AddElement(pGameListLbl);
	pGameSelList = new C4GUI::ListBox(caGameList.GetFromTop(caGameList.GetHeight() - iCaptHgt));
	pGameSelList->SetDecoration(true, nullptr, true, true);
	pGameSelList->UpdateElementPositions();
	pGameSelList->SetSelectionDblClickFn(new C4GUI::CallbackHandler<C4StartupNetDlg>(this, &C4StartupNetDlg::OnSelDblClick));
	pGameSelList->SetSelectionChangeCallbackFn(new C4GUI::CallbackHandler<C4StartupNetDlg>(this, &C4StartupNetDlg::OnSelChange));
	pSheetGameList->AddElement(pGameSelList);
	C4GUI::ComponentAligner caIP(caGameList.GetAll(), 0,0);
	C4GUI::WoodenLabel *pIPLbl;
	const char *szIPLblText = LoadResStr("IDS_NET_IP");
	int32_t iIPWdt=100, Q;
	::GraphicsResource.TextFont.GetTextExtent(szIPLblText, iIPWdt, Q, true);
	pIPLbl = new C4GUI::WoodenLabel(szIPLblText, caIP.GetFromLeft(iIPWdt+10), C4GUI_Caption2FontClr, &::GraphicsResource.TextFont);
	const char *szIPTip = LoadResStr("IDS_NET_IP_DESC");
	pIPLbl->SetToolTip(szIPTip);
	pSheetGameList->AddElement(pIPLbl);
	pJoinAddressEdt = new C4GUI::CallbackEdit<C4StartupNetDlg>(caIP.GetAll(), this, &C4StartupNetDlg::OnJoinAddressEnter);
	pJoinAddressEdt->SetToolTip(szIPTip);
	pSheetGameList->AddElement(pJoinAddressEdt);

	// main area: chat sheet
	if (C4ChatDlg::IsChatEnabled())
	{
		C4GUI::Tabular::Sheet *pSheetChat = pMainTabular->AddSheet(nullptr);
		C4GUI::ComponentAligner caChat(pSheetChat->GetContainedClientRect(), 0,0, false);
		pSheetChat->AddElement(pChatTitleLabel = new C4GUI::WoodenLabel("", caChat.GetFromTop(iCaptHgt), C4GUI_Caption2FontClr, &::GraphicsResource.TextFont, ALeft, false));
		C4GUI::GroupBox *pChatGroup = new C4GUI::GroupBox(caChat.GetAll());
		pChatGroup->SetColors(0u, C4GUI_CaptionFontClr, C4GUI_StandardBGColor);
		pChatGroup->SetMargin(2);
		pSheetChat->AddElement(pChatGroup);
		pChatCtrl = new C4ChatControl(&Application.IRCClient);
		pChatCtrl->SetBounds(pChatGroup->GetContainedClientRect());
		pChatCtrl->SetTitleChangeCB(new C4GUI::InputCallback<C4StartupNetDlg>(this, &C4StartupNetDlg::OnChatTitleChange));
		StdStrBuf sCurrTitle; sCurrTitle.Ref(pChatCtrl->GetTitle()); OnChatTitleChange(sCurrTitle);
		pChatGroup->AddElement(pChatCtrl);
	}

	// config area
	btnInternet = new C4GUI::CallbackButton<C4StartupNetDlg, C4GUI::IconButton>(Config.Network.MasterServerSignUp ? C4GUI::Ico_Ex_InternetOn : C4GUI::Ico_Ex_InternetOff, caConfigArea.GetFromTop(iIconSize, iIconSize), '\0', &C4StartupNetDlg::OnBtnInternet);
	btnInternet->SetToolTip(LoadResStr("IDS_DLGTIP_SEARCHINTERNETGAME"));
	btnInternet->SetText(LoadResStr("IDS_CTL_INETSERVER"));
	AddElement(btnInternet);
	btnRecord = new C4GUI::CallbackButton<C4StartupNetDlg, C4GUI::IconButton>(Game.Record ? C4GUI::Ico_Ex_RecordOn : C4GUI::Ico_Ex_RecordOff, caConfigArea.GetFromTop(iIconSize, iIconSize), '\0', &C4StartupNetDlg::OnBtnRecord);
	btnRecord->SetToolTip(LoadResStr("IDS_DLGTIP_RECORD"));
	btnRecord->SetText(LoadResStr("IDS_CTL_RECORD"));
	AddElement(btnRecord);
#ifdef WITH_AUTOMATIC_UPDATE
	btnUpdate = new C4GUI::CallbackButton<C4StartupNetDlg, C4GUI::IconButton>(C4GUI::Ico_Ex_Update, caConfigArea.GetFromTop(iIconSize, iIconSize), '\0', &C4StartupNetDlg::OnBtnUpdate);
	btnUpdate->SetVisibility(false); // update only available if masterserver notifies it
	btnUpdate->SetToolTip(LoadResStr("IDS_DLGTIP_UPDATE"));
	btnUpdate->SetText(LoadResStr("IDS_CTL_UPDATE"));
	AddElement(btnUpdate);
#endif

	// button area
	C4GUI::CallbackButton<C4StartupNetDlg> *btn;
	AddElement(btn = new C4GUI::CallbackButton<C4StartupNetDlg>(LoadResStr("IDS_BTN_BACK"), caButtons.GetFromLeft(iButtonWidth), &C4StartupNetDlg::OnBackBtn));
	btn->SetToolTip(LoadResStr("IDS_DLGTIP_BACKMAIN"));
	AddElement(btnRefresh = new C4GUI::CallbackButton<C4StartupNetDlg>(LoadResStr("IDS_BTN_RELOAD"), caButtons.GetFromLeft(iButtonWidth), &C4StartupNetDlg::OnRefreshBtn));
	btnRefresh->SetToolTip(LoadResStr("IDS_NET_RELOAD_DESC"));
	AddElement(btnJoin = new C4GUI::CallbackButton<C4StartupNetDlg>(LoadResStr("IDS_NET_JOINGAME_BTN"), caButtons.GetFromLeft(iButtonWidth), &C4StartupNetDlg::OnJoinGameBtn));
	btnJoin->SetToolTip(LoadResStr("IDS_NET_JOINGAME_DESC"));
	AddElement(btn = new C4GUI::CallbackButton<C4StartupNetDlg>(LoadResStr("IDS_NET_NEWGAME"), caButtons.GetFromLeft(iButtonWidth), &C4StartupNetDlg::OnCreateGameBtn));
	btn->SetToolTip(LoadResStr("IDS_NET_NEWGAME_DESC"));

	// initial dlg mode
	UpdateDlgMode();

	// initial focus
	SetFocus(GetDlgModeFocusControl(), false);

	// initialize discovery
	DiscoverClient.Init(Config.Network.PortDiscovery);
	DiscoverClient.StartDiscovery();
	iGameDiscoverInterval = C4NetGameDiscoveryInterval;

	// register timer
	Application.Add(this);

	// register as receiver of reference notifies
	Application.InteractiveThread.SetCallback(Ev_HTTP_Response, this);

}
Exemple #5
0
C4ChatControl::C4ChatControl(C4Network2IRCClient *pnIRCClient)
    : C4GUI::Window(),
      pTitleChangeBC(NULL),
      pIRCClient(pnIRCClient),
      fInitialMessagesReceived(false) {
  // create elements - positioned later
  C4Rect rcDefault(0, 0, 10, 10);
  // main tabular tabs between chat components (login and channels)
  pTabMain = new C4GUI::Tabular(rcDefault, C4GUI::Tabular::tbNone);
  pTabMain->SetDrawDecoration(false);
  pTabMain->SetSheetMargin(0);
  AddElement(pTabMain);
  C4GUI::Tabular::Sheet *pSheetLogin = pTabMain->AddSheet(NULL);
  C4GUI::Tabular::Sheet *pSheetChats = pTabMain->AddSheet(NULL);
  // login sheet
  CStdFont *pUseFont = &C4GUI::GetRes()->TextFont;
  pSheetLogin->AddElement(pLblLoginNick = new C4GUI::Label(
                              LoadResStr("IDS_CTL_NICK"), rcDefault, ALeft,
                              C4GUI_CaptionFontClr, pUseFont, false, true));
  pSheetLogin->AddElement(
      pEdtLoginNick = new C4GUI::CallbackEdit<C4ChatControl>(
          rcDefault, this, &C4ChatControl::OnLoginDataEnter));
  pSheetLogin->AddElement(
      pLblLoginPass =
          new C4GUI::Label(LoadResStr("IDS_CTL_PASSWORDOPTIONAL"), rcDefault,
                           ALeft, C4GUI_CaptionFontClr, pUseFont, false, true));
  pSheetLogin->AddElement(
      pEdtLoginPass = new C4GUI::CallbackEdit<C4ChatControl>(
          rcDefault, this, &C4ChatControl::OnLoginDataEnter));
  pEdtLoginPass->SetPasswordMask('*');
  pSheetLogin->AddElement(pLblLoginRealName = new C4GUI::Label(
                              LoadResStr("IDS_CTL_REALNAME"), rcDefault, ALeft,
                              C4GUI_CaptionFontClr, pUseFont, false, true));
  pSheetLogin->AddElement(
      pEdtLoginRealName = new C4GUI::CallbackEdit<C4ChatControl>(
          rcDefault, this, &C4ChatControl::OnLoginDataEnter));
  pSheetLogin->AddElement(pLblLoginChannel = new C4GUI::Label(
                              LoadResStr("IDS_CTL_CHANNEL"), rcDefault, ALeft,
                              C4GUI_CaptionFontClr, pUseFont, false, true));
  pSheetLogin->AddElement(
      pEdtLoginChannel = new C4GUI::CallbackEdit<C4ChatControl>(
          rcDefault, this, &C4ChatControl::OnLoginDataEnter));
  pSheetLogin->AddElement(pBtnLogin =
                              new C4GUI::CallbackButtonEx<C4ChatControl>(
                                  LoadResStr("IDS_BTN_CONNECT"), rcDefault,
                                  this, &C4ChatControl::OnConnectBtn));
  // channel/query tabular
  pTabChats = new C4GUI::Tabular(rcDefault, C4GUI::Tabular::tbTop);
  pTabChats->SetSheetMargin(0);
  pSheetChats->AddElement(pTabChats);
  // initial connection values
  const char *szNick = Config.IRC.Nick, *szRealName = Config.IRC.RealName;
  StdStrBuf sNick, sRealName;
  if (!*szNick) szNick = Config.Network.Nick.getData();
  pEdtLoginNick->SetText(szNick, false);
  pEdtLoginRealName->SetText(szRealName, false);
  pEdtLoginChannel->SetText(Config.IRC.Channel, false);
  // initial sheets
  ClearChatSheets();
  // set IRC event callback
  Application.InteractiveThread.SetCallback(Ev_IRC_Message, this);
}