⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trackerdialog.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	OnOnlineStatusChanged(COnlineStatus::OFFLINE);


	// modify system menu
	Menu *sysMenu = GetSysMenu();
	sysMenu->AddMenuItem("About", "&About...", "About", this);
	MenuItem *panel = dynamic_cast<MenuItem *>(sysMenu->FindChildByName("Close"));
	if (panel)
	{
		panel->SetText("#TrackerUI_MenuHide");
	}

	m_bNeedUpdateToFriendStatus = false;

	// load settings (they are dynamically resized after this)
	LoadControlSettings("Friends/TrackerDialog.res");

	// Start minimized
	SetVisible(false);

	if (Tracker_StandaloneMode())
	{
		// initialize auto-away
		system()->SetWatchForComputerUse(true);
	}

	ivgui()->AddTickSignal(this->GetVPanel());
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTrackerDialog::OpenServerBrowser()
{
	if (!g_pIServerBrowser)
		return;

	g_pIServerBrowser->Activate();
}


//-----------------------------------------------------------------------------
// Purpose: Opens the options/preferences dialog
//-----------------------------------------------------------------------------
void CTrackerDialog::OpenOptionDialog()
{
	if (!m_hDialogOptions.Get())
	{
		m_hDialogOptions = new CDialogOptions();
		surface()->CreatePopup(m_hDialogOptions->GetVPanel(), false);
		m_hDialogOptions->AddActionSignalTarget(this);
	}   

	// open the dialog
	m_hDialogOptions->Run();
}	

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTrackerDialog::OpenAboutDialog()
{
	if (!m_hDialogAbout.Get())
	{
		m_hDialogAbout = new CDialogAbout();
		surface()->CreatePopup(m_hDialogAbout->GetVPanel(), false);
	}

	// open the dialog
	m_hDialogAbout->Run();
}

//-----------------------------------------------------------------------------
// Purpose: Message handler
// Input  : userid - 
//-----------------------------------------------------------------------------
void CTrackerDialog::OnUserCreateFinished(int userid, const char *password)
{
	OnUserCreated(userid, password);
}

//-----------------------------------------------------------------------------
// Purpose: Handles when user creation has been cancelled
//-----------------------------------------------------------------------------
void CTrackerDialog::OnUserCreateCancel()
{
	if (!GetDoc()->GetUserID())
	{
		// if we aren't logged in, and we can't create a user, just close the program
		ivgui()->PostMessage(this->GetVPanel(), new KeyValues("Command", "command", "Quit"), this->GetVPanel());
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : newStatus - 
//-----------------------------------------------------------------------------
void CTrackerDialog::OnOnlineStatusChanged(int newStatus)
{
	if (newStatus < 1)
	{
		// we're offline, so clear our buddy states
		GetDoc()->ClearBuddyStatus();

		// mark ourselves as being offline
		SetTitle("#TrackerUI_Friends_OfflineTitle", true);
	}
	else
	{
		SetTitle("#TrackerUI_Friends_Title", true);
	}

	// set the check in the menu
	// first uncheck all in the submenu.
	if (m_pTrackerMenu)
	{
		Menu *subMenu =  m_pTrackerMenu->GetMenuItem(0)->GetMenu();
		assert(subMenu);
		for (int i = 0; i < subMenu->GetNumberOfMenuItems(); i++)
		{
			subMenu->GetMenuItem(i)->SetChecked(false);
		}
		// now set the correct item checked
		if (newStatus == COnlineStatus::ONLINE)
		{
			subMenu->GetMenuItem(0)->SetChecked(true);
		}
		else if (newStatus == COnlineStatus::AWAY)
		{
			subMenu->GetMenuItem(1)->SetChecked(true);
		}
		else if (newStatus == COnlineStatus::BUSY)
		{
			subMenu->GetMenuItem(2)->SetChecked(true);
		}
		else if ( (newStatus == COnlineStatus::OFFLINE) ||
			(newStatus == COnlineStatus::CONNECTING) || 
			(newStatus == COnlineStatus::RECENTLYONLINE) )

		{
			subMenu->GetMenuItem(3)->SetChecked(true);
		}
	}
	
	
	m_pBuddyListPanel->InvalidateAll();
	m_pStatePanel->InvalidateLayout();
	InvalidateLayout();
	Repaint();
}

//-----------------------------------------------------------------------------
// Purpose: Called when the use selects a new status from the menu
//-----------------------------------------------------------------------------
void CTrackerDialog::OnUserChangeStatus(int status)
{
	if (m_bInGame && m_iGameIP && status == COnlineStatus::ONLINE)
	{
		// online status in the game means ingame status
		status = COnlineStatus::INGAME;
	}

	// set the requested mode
	ServerSession().UserSelectNewStatus(status);


	input()->SetMouseCapture(NULL);
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTrackerDialog::OnMinimize()
{
	BaseClass::OnMinimize();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTrackerDialog::OnSetFocus()
{
	BaseClass::OnSetFocus();
}

//-----------------------------------------------------------------------------
// Purpose: Handles messages from the tracker system
//-----------------------------------------------------------------------------
void CTrackerDialog::OnSystemMessage(KeyValues *msg)
{
	// play the message sound, if they have it enabled
	if (GetDoc()->Data()->GetInt("User/Sounds/Message", 1))
	{
		surface()->PlaySound("Friends\\Message.wav");
	}

	// display the message in a message box
	MessageBox *box = new MessageBox("#TrackerUI_FriendsSystemMessageTitle", msg->GetString("text"));
	box->DoModal();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTrackerDialog::OnReceivedMessage(KeyValues *data)
{
	int friendID = data->GetInt("uid");
	int chatID = data->GetInt("ChatID", 0);

	if (data->GetInt("flags") & MESSAGEFLAG_SYSTEM)
	{
		// it's a message from the tracker system, handle it specially
		OnSystemMessage(data);
		return;
	}
	
	KeyValues *buddy = GetDoc()->GetBuddy(friendID)->Data();
	if (!buddy && friendID > 0)
	{
		// create the buddy
		buddy = new KeyValues("Buddy");

		buddy->SetInt("uid", friendID);
		buddy->SetInt("Status", COnlineStatus::UNKNOWNUSER);

		if (data->GetString("UserName", NULL))
		{
			buddy->SetString("UserName", data->GetString("UserName"));
		}
		else
		{
			// just use their ID for now
			char buf[52];
			sprintf(buf, "(user #%d)", friendID);
			buddy->SetString("UserName", buf);
		}
		if (!data->GetString("DisplayName", NULL))
		{
			data->SetString("DisplayName", buddy->GetString("UserName"));
		}
	
		GetDoc()->AddNewBuddy(buddy);
		if (buddy)
		{
			buddy->deleteThis();
		}

		buddy = GetDoc()->GetBuddy(friendID)->Data();

		InvalidateLayout();
		Repaint();
	}

	if (!buddy)
		return;

	if (chatID > 0)
	{
		// it's a multi-user chat, let the chat dialog handle it
	}
	else
	{
		// check for special messages
		int flags = data->GetInt("flags");

		if (flags & MESSAGEFLAG_AUTHED)
		{
			if (buddy->GetInt("Status", COnlineStatus::OFFLINE) == COnlineStatus::AWAITINGAUTHORIZATION)
			{
				// move them to offline right away
				buddy->SetInt("Status", COnlineStatus::OFFLINE);
			}

			// removed any not authed flag
			buddy->SetInt("NotAuthed", 0);

			// only display the message if there is more than just an auth
			if (!(flags & MESSAGEFLAG_REQUESTAUTH))
			{
				InvalidateLayout();
				Repaint();
				return;
			}
		}

		// add it into the buddies message queue
		KeyValues *msg = buddy->FindKey("Messages", true)->CreateNewKey();

		// copy in the text
		msg->SetString("text", data->GetString("text"));
		msg->SetInt("flags", flags);

		// make sure the buddy status is up to date
		int status = data->GetInt("Status", COnlineStatus::ONLINE);
		GetDoc()->UpdateBuddyStatus(friendID, status, 0, 0, NULL, NULL, NULL, NULL, NULL);

		if (flags & MESSAGEFLAG_REQUESTAUTH)
		{
			buddy->SetInt("Status", COnlineStatus::REQUESTINGAUTHORIZATION);
			buddy->SetInt("RequestingAuth", 1);

			// removed any not authed flag
			buddy->SetInt("NotAuthed", 0);
		}

		// make sure we have a user name set
		const char *buddyName = buddy->GetString("UserName", "");
		if (!buddyName[0] || !stricmp(buddyName, "Unnamed"))
		{
			buddy->SetString("UserName", data->GetString("UserName"));
			buddy->SetString("DisplayName", data->GetString("UserName"));
		}

		// flag the buddy as having a message available
		buddy->SetInt("MessageAvailable", 1);

		if (flags & MESSAGEFLAG_REQUESTAUTH)
		{
			GetDoc()->GetBuddy(friendID)->OpenAuthRequestDialog(true);
		}
		else
		{
			GetDoc()->GetBuddy(friendID)->OpenChatDialog(true);
		}
	}

	InvalidateLayout();
	Repaint();
}

//-----------------------------------------------------------------------------
// Purpose: Friend is telling us about a game they're in
//-----------------------------------------------------------------------------
void CTrackerDialog::OnReceivedGameInfo(KeyValues *data)
{
	// redraw the current screen
	m_pBuddyListPanel->InvalidateAll();
}

//-----------------------------------------------------------------------------
// Purpose: Called when we receive information about a specific friend
//-----------------------------------------------------------------------------
void CTrackerDialog::OnReceivedFriendInfo(KeyValues *data)
{
	unsigned int friendID = data->GetInt("uid");
	if (!friendID)
		return;

	if (GetDoc()->GetUserID() == friendID)
	{
		// the information is about the currently logged in user
		KeyValues *self = GetDoc()->Data()->FindKey("User", true);
		self->SetString("UserName", data->GetString("UserName"));
		self->SetString("FirstName", data->GetString("FirstName"));
		self->SetString("LastName", data->GetString("LastName"));
		self->SetString("Email", data->GetString("Email"));
		InvalidateLayout();
	}

	// it's information about a friend
	CBuddy *buddy = GetDoc()->GetBuddy(friendID);

	// find out if we're authorized to see this users info
	if (data->GetInt("NotAuthed"))
	{
		// don't show this buddy
		if (buddy)
		{
			buddy->Data()->SetInt("NotAuthed", 1);
		}
	}
	else
	{
		// get data
		if (buddy)
		{
			// if user hasn't changed the buddies username, update the buddies displayname as well
			const char *displayName = buddy->Data()->GetString("DisplayName");
			if (!stricmp(displayName, "Unnamed") || !stricmp(buddy->Data()->GetString("UserName"), displayName))
			{
				buddy->Data()->SetString("DisplayName", data->GetString("UserName"));
			}

			buddy->Data()->SetString("UserName", data->GetString("UserName"));
			buddy->Data()->SetString("FirstName", data->GetString("FirstName"));
			buddy->Data()->SetString("LastName", data->GetString("LastName"));
			buddy->Data()->SetString("Email", data->GetString("Email"));

			if (!buddy->Data()->GetString("DisplayName"))
			{
				buddy->Data()->SetString("DisplayName", data->GetString("UserName"));
			}

			buddy->Data()->SetInt("NotAuthed", 0);
		}
		else
		{
			// create a new entry
			GetDoc()->AddNewBuddy(data);
		}

		OnFriendsStatusChanged(1);
	}

	MarkUserDataAsNeedsSaving();
	InvalidateLayout();
}

//-----------------------------------------------------------------------------
// Purpose: Sets the block level of a user
//-----------------------------------------------------------------------------
void CTrackerDialog::OnReceivedUserBlock(KeyValues *msg)
{
	int buddyID = msg->GetInt("uid");
	int blockLevel = msg->GetInt("Block");
	int fakeStatus = msg->GetInt("FakeStatus");

	CBuddy *buddy = GetDoc()->GetBuddy(buddyID);
	if (!buddy)
		return;

	buddy->SetBlock(blockLevel, fakeStatus);
}

//-----------------------------------------------------------------------------
// Purpose: Called when friends' status is updated
//-----------------------------------------------------------------------------
void CTrackerDialog::OnFriendsStatusChanged(int numberOfFriends)
{
	if (numberOfFriends > 1)
	{
		// we've got our full friends list, so don't bother to get again
		m_bNeedUpdateToFriendStatus = false;
	}

	m_pBuddyListPanel->InvalidateAll();
	m_pStatePanel->InvalidateLayout();
	InvalidateLayout();
	Repaint();
}

//-----------------------------------------------------------------------------
// Purpose: MENU INPUT HANDLING
//-----------------------------------------------------------------------------
void CTrackerDialog::OnCommand(const char *command)
{
	if (!strcmp(command, "OpenFindBuddyDialog"))
	{
		// pop up the find buddy dialog
		if (m_hDialogFindBuddy.Get())
		{
			m_hDialogFindBuddy->Open();
		}
		else
		{
			CDialogFindBuddy *pDialogFindBuddy = new CDialogFindBuddy();
			surface()->CreatePopup(pDialogFindBuddy->GetVPanel(), false);
			pDialogFindBuddy->Run();
			m_hDialogFindBuddy = pDialogFindBuddy;
		}
	}
	else if (!stricmp(command, "OpenCreateNewUserDialog"))
	{
		PopupCreateNewUserDialog(false);
	}
	else if (!stricmp(command, "AddFriends"))
	{
		// delay the dialog opening
		PostMessage(this, new KeyValues("Command", "command", "OpenFindBuddyDialog"), 0.5f);
	}
	else if (!stricmp(command, "Quit"))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -