Qt editor: Fix net menu

It didn't work, had the wrong labels and crashed.
qteditor
Sven Eberhardt 2016-08-06 21:12:04 -04:00
parent c0f95d97f7
commit 5bb204d69b
11 changed files with 51 additions and 22 deletions

View File

@ -520,8 +520,8 @@ IDS_MNU_FPS=FPS-Anzeige
IDS_MNU_JOIN=Beitritt
IDS_MNU_MUSIC=Musik
IDS_MNU_NET=Host
IDS_MNU_NETCLIENT=Client %s (%i) deaktivieren
IDS_MNU_NETCLIENTDE=Client %s (%i) deaktiviert
IDS_MNU_NETCLIENT_DEACTIVATE=Client %s (%i) deaktivieren
IDS_MNU_NETCLIENT_ACTIVATE=Client %s (%i) aktivieren
IDS_MNU_NETHOST=Host %s
IDS_MNU_NEW=Neu...
IDS_MNU_NEWVIEWPORT=Neues Sichtfenster
@ -775,6 +775,7 @@ IDS_NET_JOINGAME_BTN=&Beitreten
IDS_NET_JOINGAME_DESC=Tritt dem ausgewählten Netzwerkspiel bei.
IDS_NET_JOINREADY=Warten auf Start des Netzwerkspieles...
IDS_NET_KICKCLIENT=&Rauswerfen
IDS_NET_KICKCLIENTEX=%s (%d) rauswerfen
IDS_NET_KICKCLIENT_DESC=Diesen Client aus dem Spiel werfen
IDS_NET_LEAGUE_REGGAME=Spiel wird auf %s angemeldet...
IDS_NET_LEAGUE_SENDRESULT=Spielergebnis wird an %s gesendet...

View File

@ -520,8 +520,8 @@ IDS_MNU_FPS=FPS Display
IDS_MNU_JOIN=Join
IDS_MNU_MUSIC=Music
IDS_MNU_NET=Host
IDS_MNU_NETCLIENT=Client %s (%i)
IDS_MNU_NETCLIENTDE=Client %s (%i) deactivated
IDS_MNU_NETCLIENT_DEACTIVATE=Deactivate client %s (%i)
IDS_MNU_NETCLIENT_ACTIVATE=Activate client %s (%i)
IDS_MNU_NETHOST=Host %s
IDS_MNU_NEW=New...
IDS_MNU_NEWVIEWPORT=New viewport
@ -775,6 +775,7 @@ IDS_NET_JOINGAME_BTN=&Join game
IDS_NET_JOINGAME_DESC=Join the selected network or internet game, or entered IP address.
IDS_NET_JOINREADY=Waiting for network game start...
IDS_NET_KICKCLIENT=&Kick
IDS_NET_KICKCLIENTEX=Kick %s (%d)
IDS_NET_KICKCLIENT_DESC=Disconnect this client
IDS_NET_LEAGUE_REGGAME=Registering game at %s...
IDS_NET_LEAGUE_SENDRESULT=Sending game result to %s...

View File

@ -939,6 +939,8 @@ void C4ControlClientUpdate::Execute() const
break;
}
}
// Update console net menu to reflect activation/etc.
::Console.UpdateNetMenu();
}
void C4ControlClientUpdate::CompileFunc(StdCompiler *pComp)

View File

@ -492,13 +492,16 @@ void C4Console::UpdateNetMenu()
// Host
StdStrBuf str;
str.Format(LoadResStr("IDS_MNU_NETHOST"),Game.Clients.getLocalName(),Game.Clients.getLocalID());
AddNetMenuItemForPlayer(IDM_NET_CLIENT1+Game.Clients.getLocalID(), str);
AddNetMenuItemForPlayer(Game.Clients.getLocalID(), str.getData(), C4ConsoleGUI::CO_None);
// Clients
for (C4Network2Client *pClient=::Network.Clients.GetNextClient(NULL); pClient; pClient=::Network.Clients.GetNextClient(pClient))
{
str.Format(LoadResStr(pClient->isActivated() ? "IDS_MNU_NETCLIENT" : "IDS_MNU_NETCLIENTDE"),
if (pClient->isHost()) continue;
str.Format(LoadResStr(pClient->isActivated() ? "IDS_MNU_NETCLIENT_DEACTIVATE" : "IDS_MNU_NETCLIENT_ACTIVATE"),
pClient->getName(), pClient->getID());
AddNetMenuItemForPlayer(IDM_NET_CLIENT1+pClient->getID(), str);
AddNetMenuItemForPlayer(pClient->getID(), str.getData(), pClient->isActivated() ? C4ConsoleGUI::CO_Deactivate : C4ConsoleGUI::CO_Activate);
str.Format(LoadResStr("IDS_NET_KICKCLIENTEX"), pClient->getName(), pClient->getID());
AddNetMenuItemForPlayer(pClient->getID(), str.getData(), C4ConsoleGUI::CO_Kick);
}
return;
}
@ -598,7 +601,7 @@ class C4ToolsDlg::State: public C4ConsoleGUI::InternalState<class C4ToolsDlg>
};
void C4ConsoleGUI::AddKickPlayerMenuItem(C4Player*, StdStrBuf&, bool) {}
void C4ConsoleGUI::AddMenuItemForPlayer(C4Player*, StdStrBuf&) {}
void C4ConsoleGUI::AddNetMenuItemForPlayer(int, StdStrBuf&) {}
void C4ConsoleGUI::AddNetMenuItemForPlayer(int, StdStrBuf&, C4ConsoleGUI::ClientOperation) {}
void C4ConsoleGUI::AddNetMenu() {}
void C4ConsoleGUI::ToolsDlgClose() {}
bool C4ConsoleGUI::ClearLog() {return 0;}

View File

@ -415,7 +415,7 @@ void C4ConsoleGUI::ClearPlayerMenu()
{
}
void C4ConsoleGUI::AddNetMenuItemForPlayer(int32_t index, StdStrBuf &text)
void C4ConsoleGUI::AddNetMenuItemForPlayer(int32_t index, StdStrBuf &text, C4ConsoleGUI::ClientOperation op)
{
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithCString:text.getData() encoding:NSUTF8StringEncoding] action:@selector(kickPlayer:) keyEquivalent:[NSString string]];
[item setTarget:ctrler(this)];

View File

@ -68,6 +68,14 @@ public:
CURSOR_Wait
};
enum ClientOperation
{
CO_None,
CO_Deactivate,
CO_Activate,
CO_Kick
};
class State;
private:
@ -108,7 +116,7 @@ public:
bool UpdateModeCtrls(int iMode);
void AddNetMenu();
void ClearNetMenu();
void AddNetMenuItemForPlayer(int32_t index, StdStrBuf &text);
void AddNetMenuItemForPlayer(int32_t client_id, const char *text, ClientOperation co);
void ClearPlayerMenu();
void SetInputFunctions(std::list<const char*> &functions);

View File

@ -66,9 +66,9 @@ void C4ConsoleGUI::ClearNetMenu()
if (Active) state->ClearNetMenu();
}
void C4ConsoleGUI::AddNetMenuItemForPlayer(int32_t index, StdStrBuf &text)
void C4ConsoleGUI::AddNetMenuItemForPlayer(int32_t client_id, const char *text, C4ConsoleGUI::ClientOperation op)
{
if (Active) state->AddNetMenuItem(index, text.getData());
if (Active) state->AddNetMenuItem(client_id, text, op);
}
void C4ConsoleGUI::ClearPlayerMenu()

View File

@ -52,8 +52,8 @@ C4ConsoleQtTranslator qt_translator;
/* Kick client action */
C4ConsoleClientAction::C4ConsoleClientAction(int32_t client_id, const char *text, QObject *parent)
: QAction(text, parent), client_id(client_id)
C4ConsoleClientAction::C4ConsoleClientAction(int32_t client_id, const char *text, QObject *parent, C4ConsoleGUI::ClientOperation op)
: QAction(text, parent), client_id(client_id), op(op)
{
connect(this, SIGNAL(triggered()), this, SLOT(Execute()));
}
@ -61,7 +61,18 @@ C4ConsoleClientAction::C4ConsoleClientAction(int32_t client_id, const char *text
void C4ConsoleClientAction::Execute()
{
if (!::Control.isCtrlHost()) return;
::Game.Clients.CtrlRemove(Game.Clients.getClientByID(client_id), LoadResStr("IDS_MSG_KICKBYMENU"));
switch (op)
{
case C4ConsoleGUI::CO_Deactivate:
::Control.DoInput(CID_ClientUpdate, new C4ControlClientUpdate(client_id, CUT_Activate, false), CDT_Sync);
break;
case C4ConsoleGUI::CO_Activate:
::Control.DoInput(CID_ClientUpdate, new C4ControlClientUpdate(client_id, CUT_Activate, true), CDT_Sync);
break;
case C4ConsoleGUI::CO_Kick:
::Game.Clients.CtrlRemove(Game.Clients.getClientByID(client_id), LoadResStr("IDS_MSG_KICKBYMENU"));
break;
}
}
@ -676,9 +687,10 @@ void C4ConsoleGUIState::UpdateBackMatTex()
if (new_index >= 0) ui.backgroundMatTexComboBox->setCurrentIndex(new_index);
}
void C4ConsoleGUIState::AddNetMenuItem(int32_t index, const char *text)
void C4ConsoleGUIState::AddNetMenuItem(int32_t index, const char *text, C4ConsoleGUI::ClientOperation op)
{
auto *kick_action = new C4ConsoleClientAction(index, text, ui.menuNet);
auto *kick_action = new C4ConsoleClientAction(index, text, ui.menuNet, op);
if (op == C4ConsoleGUI::CO_None) kick_action->setDisabled(true);
client_actions.emplace_back(kick_action);
ui.menuNet->addAction(kick_action);
}

View File

@ -43,9 +43,11 @@ class C4ConsoleClientAction : public QAction
{
Q_OBJECT
int32_t client_id;
int32_t client_id;
C4ConsoleGUI::ClientOperation op;
public:
C4ConsoleClientAction(int32_t client_id, const char *text, QObject *parent);
C4ConsoleClientAction(int32_t client_id, const char *text, QObject *parent, C4ConsoleGUI::ClientOperation op);
int32_t GetClientID() const { return client_id; }
private slots:
void Execute();
@ -209,7 +211,7 @@ public:
void SetRecording(bool to_recording) { recording = to_recording; UpdateActionStates(); }
void SetNetEnabled(bool enabled) { net_enabled = enabled; UpdateActionStates(); }
void AddNetMenuItem(int32_t index, const char *text);
void AddNetMenuItem(int32_t index, const char *text, C4ConsoleGUI::ClientOperation op);
void ClearNetMenu();
void AddKickPlayerMenuItem(int32_t plr, const char *text, bool item_enabled);
void ClearPlayerMenu();

View File

@ -1019,7 +1019,7 @@ void C4ConsoleGUI::ClearNetMenu()
DrawMenuBar(hWindow);
}
void C4ConsoleGUI::AddNetMenuItemForPlayer(int32_t index, StdStrBuf &text)
void C4ConsoleGUI::AddNetMenuItemForPlayer(int32_t client_id, StdStrBuf &text, C4ConsoleGUI::ClientOperation op)
{
AddMenuItem(this, GetSubMenu(GetMenu(hWindow),state->MenuIndexNet), IDM_NET_CLIENT1+Game.Clients.getLocalID(), text.getData(), true);
}

View File

@ -339,7 +339,7 @@ void C4ClientList::SetLocalID(int32_t iID)
void C4ClientList::CtrlRemove(const C4Client *pClient, const char *szReason)
{
// host only
if (!pLocal || !pLocal->isHost()) return;
if (!pLocal || !pLocal->isHost() || !pClient) return;
// Net client? flag
if (pClient->getNetClient())
pClient->getNetClient()->SetStatus(NCS_Remove);