/sound reenabled. Sound-creating client now shown in client list box (F4). No sounds played when client is ignored.

stable-5.3
Sven Eberhardt 2012-10-13 13:37:59 +02:00
parent 6bbabdfc41
commit db84b849b1
6 changed files with 81 additions and 11 deletions

View File

@ -33,6 +33,7 @@
#include <C4Object.h>
#include <C4GameSave.h>
#include <C4GameLobby.h>
#include <C4Network2Dialogs.h>
#include <C4Random.h>
#include <C4Console.h>
#include <C4Log.h>
@ -1141,12 +1142,18 @@ void C4ControlMessage::Execute() const
break;
case C4CMT_Sound:
{
// tehehe, sound!
if (StartSoundEffect(szMessage, false, 100, NULL))
{
if (pLobby) pLobby->OnClientSound(Game.Clients.getClientByID(iByClient));
}
C4Client *singer = Game.Clients.getClientByID(iByClient);
if (!singer || !singer->IsIgnored())
if (!StartSoundEffect(szMessage, false, 100, NULL))
// probably wrong sound file name
break;
// Sound icon even if someone you ignored just tried. So you know you still need to ignore.
if (pLobby) pLobby->OnClientSound(singer);
if (C4Network2ClientListDlg::GetInstance()) C4Network2ClientListDlg::GetInstance()->OnSound(singer);
break;
}
case C4CMT_Alert:
// notify inactive users

View File

@ -83,7 +83,7 @@ bool C4Console::In(const char *szText)
// done
return true;
}
// begins with '#'? then it's a message. Route cia ProcessInput to allow #/sound
// begins with '#'? then it's a message. Route via ProcessInput to allow #/sound
if (*szText == '#')
{
::MessageInput.ProcessInput(szText + 1);

View File

@ -586,7 +586,7 @@ namespace C4GameLobby
LogF("/kick [client] - %s", LoadResStr("IDS_TEXT_KICKTHESPECIFIEDCLIENT"));
LogF("/observer [client] - %s", LoadResStr("IDS_TEXT_SETTHESPECIFIEDCLIENTTOOB"));
LogF("/me [action] - %s", LoadResStr("IDS_TEXT_PERFORMANACTIONINYOURNAME"));
// LogF("/sound [sound] - %s", LoadResStr("IDS_TEXT_PLAYASOUNDFROMTHEGLOBALSO"));
LogF("/sound [sound] - %s", LoadResStr("IDS_TEXT_PLAYASOUNDFROMTHEGLOBALSO"));
LogF("/team [message] - %s", LoadResStr("IDS_MSG_SENDAPRIVATEMESSAGETOYOUR"));
LogF("/plrclr [player] [RGB] - %s", LoadResStr("IDS_TEXT_CHANGETHECOLOROFTHESPECIF"));
LogF("/plrclr [RGB] - %s", LoadResStr("IDS_TEXT_CHANGEYOUROWNPLAYERCOLOR"));

View File

@ -372,11 +372,11 @@ bool C4MessageInput::ProcessInput(const char *szText)
szMsg = szText+4;
}
// Starts with "/sound ": Sound-Message
/* else if (SEqual2NoCase(szText, "/sound "))
else if (SEqual2NoCase(szText, "/sound "))
{
eMsgType = C4CMT_Sound;
szMsg = szText+7;
}*/
}
// Disabled due to spamming
// Starts with "/alert": Taskbar flash (message optional)
else if (SEqual2NoCase(szText, "/alert ") || SEqualNoCase(szText, "/alert"))
@ -458,7 +458,7 @@ bool C4MessageInput::ProcessCommand(const char *szCommand)
LogF("/private [player] [message] - %s", LoadResStr("IDS_MSG_SENDAPRIVATEMESSAGETOTHES"));
LogF("/team [message] - %s", LoadResStr("IDS_MSG_SENDAPRIVATEMESSAGETOYOUR"));
LogF("/me [action] - %s", LoadResStr("IDS_TEXT_PERFORMANACTIONINYOURNAME"));
//LogF("/sound [sound] - %s", LoadResStr("IDS_TEXT_PLAYASOUNDFROMTHEGLOBALSO"));
LogF("/sound [sound] - %s", LoadResStr("IDS_TEXT_PLAYASOUNDFROMTHEGLOBALSO"));
LogF("/kick [client] - %s", LoadResStr("IDS_TEXT_KICKTHESPECIFIEDCLIENT"));
LogF("/observer [client] - %s", LoadResStr("IDS_TEXT_SETTHESPECIFIEDCLIENTTOOB"));
LogF("/fast [x] - %s", LoadResStr("IDS_TEXT_SETTOFASTMODESKIPPINGXFRA"));

View File

@ -122,7 +122,7 @@ void C4Network2ClientDlg::UpdateText()
// C4Network2ClientListBox::ClientListItem
C4Network2ClientListBox::ClientListItem::ClientListItem(class C4Network2ClientListBox *pForDlg, int iClientID) // ctor
: ListItem(pForDlg, iClientID), pStatusIcon(NULL), pName(NULL), pPing(NULL), pActivateBtn(NULL), pKickBtn(NULL)
: ListItem(pForDlg, iClientID), pStatusIcon(NULL), pName(NULL), pPing(NULL), pActivateBtn(NULL), pKickBtn(NULL), last_sound_time(0)
{
// get associated client
const C4Client *pClient = GetClient();
@ -234,6 +234,21 @@ void C4Network2ClientListBox::ClientListItem::Update()
break;
}
}
// sound icon?
if (last_sound_time)
{
time_t dt = time(NULL) - last_sound_time;
if (dt >= SoundIconShowTime)
{
// stop showing sound icon
last_sound_time = 0;
}
else
{
// time not up yet: show sound icon
icoStatus = C4GUI::Ico_Sound;
}
}
// network OK - control ready?
if (!pForDlg->IsStartup() && (icoStatus == C4GUI::Ico_Ready))
{
@ -252,6 +267,22 @@ const C4Client *C4Network2ClientListBox::ClientListItem::GetClient() const
return Game.Clients.getClientByID(iClientID);
}
C4Network2ClientListBox::ClientListItem *C4Network2ClientListBox::GetClientListItem(int32_t client_id)
{
// find list item that is not the connection item
// search through listbox
for (C4GUI::Element *list_item = GetFirst(); list_item; list_item = list_item->GetNext())
{
// only playerlistitems in this box
ListItem *list_item2 = static_cast<ListItem *>(list_item);
if (list_item2->GetClientID() == client_id)
if (list_item2->GetConnectionID() == -1)
return static_cast<ClientListItem *>(list_item2);
}
// nothing found
return NULL;
}
void C4Network2ClientListBox::ClientListItem::OnButtonActivate(C4GUI::Control *pButton)
{
// league: Do not deactivate clients with players
@ -274,6 +305,14 @@ void C4Network2ClientListBox::ClientListItem::OnButtonKick(C4GUI::Control *pButt
Game.Clients.CtrlRemove(GetClient(), LoadResStr(pForDlg->IsStartup() ? "IDS_MSG_KICKFROMSTARTUPDLG" : "IDS_MSG_KICKFROMCLIENTLIST"));
}
void C4Network2ClientListBox::ClientListItem::SetSoundIcon()
{
// remember time for reset
last_sound_time = time(NULL);
// force icon
Update();
}
// --------------------------------------------------
// C4Network2ClientListBox::ConnectionListItem
@ -452,6 +491,13 @@ void C4Network2ClientListBox::Update()
}
}
void C4Network2ClientListBox::SetClientSoundIcon(int32_t client_id)
{
// sound icon on client element
ClientListItem *item = GetClientListItem(client_id);
if (item) item->SetSoundIcon();
}
// --------------------------------------------------
// C4Network2ClientListDlg
@ -504,6 +550,11 @@ bool C4Network2ClientListDlg::Toggle()
return ::pGUI->ShowRemoveDlg(pInstance = new C4Network2ClientListDlg());
}
void C4Network2ClientListDlg::OnSound(class C4Client *singer)
{
if (singer) pListBox->SetClientSoundIcon(singer->getID());
}
// --------------------------------------------------
// C4Network2StartWaitDlg

View File

@ -95,7 +95,10 @@ public:
class C4Network2ClientListBox : public C4GUI::ListBox, private C4ApplicationSec1Timer
{
public:
enum { IconLabelSpacing = 2 }; // space between an icon and its text
enum {
IconLabelSpacing = 2,
SoundIconShowTime = 1 // seconds. min time a sound icon is shown}; // space between an icon and its text
};
private:
class ListItem : public C4GUI::Window
@ -122,6 +125,7 @@ private:
C4GUI::Label *pPing; // client control ping
C4GUI::IconButton *pActivateBtn, *pKickBtn; // buttons for host
bool fShownActive;
time_t last_sound_time; // now() when the client last issued a sound (display as sound icon). 0 for no sound.
public:
ClientListItem(class C4Network2ClientListBox *pForDlg, int iClientID); // ctor
@ -131,6 +135,8 @@ private:
void OnButtonActivate(C4GUI::Control *pButton);
void OnButtonKick(C4GUI::Control *pButton);
void SetSoundIcon();
};
class ConnectionListItem : public ListItem
@ -156,6 +162,8 @@ private:
private:
bool fStartup;
ClientListItem *GetClientListItem(int32_t iForClientID);
public:
C4Network2ClientListBox(C4Rect &rcBounds, bool fStartup);
~C4Network2ClientListBox() { Application.Remove(this); }
@ -165,6 +173,8 @@ public:
void Update();
bool IsStartup() { return fStartup; }
void SetClientSoundIcon(int32_t client_id);
};
// dialog framing the C4Network2ClientListBox and a game option list and a status label
@ -184,8 +194,10 @@ public:
void OnSec1Timer() { Update(); }
void Update();
void OnSound(class C4Client *singer); // mark the specified client
static bool Toggle(); // toggle dlg on/off
static C4Network2ClientListDlg *GetInstance() { return pInstance; }
};
// host dialog shown at initial wait