private void OnIncomingStatusChange(NetPeer peer, NetIncomingMessage msg) { if (client.ConnectionStatus == NetConnectionStatus.Connected) { Debug.Log("Client connected!"); SessionDataRequestPacket sessionDataRequestPacket = new SessionDataRequestPacket(); SendPacket(sessionDataRequestPacket); Debug.Log("Sending session data request"); } if (client.ConnectionStatus == NetConnectionStatus.Disconnected && GameManager.getInstance().getGameState() is GameStateGame) { Debug.Log("Lost connection with the game server!"); void OnExitConfirm(object parameter) { GameManager.getInstance().setGameStateTitle(); Disconnect(); } GuiDefinitions.Callback callback = new GuiDefinitions.Callback(OnExitConfirm); if (!MessageBoxOk.Show(callback, "Disconnected from server", "Lost connection with the game server.")) { OnExitConfirm(null); // Failed to show message box } } }
public void OnGuiCreation(object sender, EventGui e) { if (e.Type == EventGui.GuiType.Action) { // We check if the selected module is a landing pad Selectable selected = Phi.Instance.GetSelection(); if (selected is Module) { Module module = (Module)selected; if (Phi.Instance.ModuleManager.GetModuleType(module) is ModuleTypeLandingPad) { // The player has selected a Landing Pad, we add the button ! // First, we need to retrieve the callback that opens // the GuiLandingPermissions when we click the button GameStateGame gameState = Phi.Instance.GetGameManager().getGameState() as GameStateGame; GuiDefinitions.Callback callback = gameState.toggleWindow <GuiLandingPermissions>; // We now add the button e.GuiMenu.addItem( new GuiMenuItem( ResourceList.getInstance().Icons.LandingPermissions, StringList.get("landing_permissions"), callback ) ); } } } }
public void ShowMessageBox(GuiDefinitions.Callback callback, string title, string text) { GuiGameOverWindow window = new GuiGameOverWindow(new GuiDefinitions.Callback(WindowCallback), title, text); this.window = window; this.windowCallback = callback; }
public override void ProcessPacket(Guid sourcePlayerId, Packet packet, IProcessorContext context) { ClientProcessorContext processorContext = (ClientProcessorContext)context; DisconnectRequestPacket disconnectRequestPacket = (DisconnectRequestPacket)packet; void OnExitConfirm(object parameter) { GameManager.getInstance().setGameStateTitle(); processorContext.Client.Disconnect(); } GuiDefinitions.Callback callback = new GuiDefinitions.Callback(OnExitConfirm); switch (disconnectRequestPacket.Reason) { case DisconnectReason.DisconnectRequestResponse: Debug.Log("Graceful disconnect response received, disconnecting."); OnExitConfirm(null); break; case DisconnectReason.KickedOut: if (!MessageBoxOk.Show(callback, "Disconnected from server", "You have been kicked out of the game.")) { OnExitConfirm(null); // Failed to show window } break; case DisconnectReason.ServerClosing: if (!MessageBoxOk.Show(callback, "Disconnected from server", "Server is shutting down.")) { OnExitConfirm(null); // Failed to show window } break; default: if (!MessageBoxOk.Show(callback, "Disconnected from server", "Unknown reason.")) { OnExitConfirm(null); // Failed to show window } break; } }
public static bool Show(GuiDefinitions.Callback callback, string title, string text) { GameState gameState = GameManager.getInstance().getGameState(); if (gameState is GameStateGame) { GuiGameOverWindow window = new GuiGameOverWindow(callback, title, text); GameStateGame gameStateGame = (GameStateGame)gameState; FieldInfo mGameGuiInfo = Reflection.GetPrivateFieldOrThrow(gameStateGame.GetType(), "mGameGui", true); GameGui mGameGui = (GameGui)Reflection.GetInstanceFieldValue(gameStateGame, mGameGuiInfo); mGameGui.setWindow(window); return(true); } if (gameState is GameStateMultiplayer) { GameStateMultiplayer gameStateMultiplayer = (GameStateMultiplayer)gameState; gameStateMultiplayer.ShowMessageBox(callback, title, text); return(true); } // Not supported return(false); }
private void WindowCallback(object parameter) { windowCallback?.Invoke(parameter); window = null; windowCallback = null; }