private void SendMessage() { //we need to send message out string user = ""; if (string.IsNullOrEmpty(MPManager.Instance().lastSender)) //server will broadcast the message to everyone { user = MPManager.IsServer() ? string.Join("", MPManager.OnlineTrains.Players.Keys.Select((string k) => $"{k}\r")) + "0END" : "0Server\r0END"; } string msg = messageText.ToString(); int index = msg.IndexOf(':'); if (index > 0) { msg = messageText.ToString(index + 1, messageText.Length - index - 1); IEnumerable <string> onlinePlayers = messageLabel.Text.Substring(0, index) .Split(',') .Select((string n) => n.Trim()) .Where((string nt) => MPManager.OnlineTrains.Players.ContainsKey(nt)) .Select((string nt) => $"{nt}\r"); string newUser = string.Join("", onlinePlayers); if (newUser.Length > 0) { user = newUser; } user += "0END"; } string msgText = new MSGText(MPManager.GetUserName(), user, msg).ToString(); try { MPManager.Notify(msgText); } #pragma warning disable CA1031 // Do not catch general exception types catch #pragma warning restore CA1031 // Do not catch general exception types { } finally { Visible = false; messageText.Clear(); game.Window.TextInput -= Window_TextInput; keyboardInput.ResumeFromOverlayInput(); } }
public static void HandleUserInput() { //In Multiplayer, I maybe the helper, but I can request to be the controller if (UserInput.IsPressed(UserCommands.GameRequestControl)) { MPManager.RequestControl(); } if (UserInput.IsPressed(UserCommands.ControlHorn)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HORN", 1)).ToString()); if (UserInput.IsReleased(UserCommands.ControlHorn)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HORN", 0)).ToString()); if (UserInput.IsPressed(UserCommands.ControlPantograph2)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO2", (++PantoSecondCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlPantograph1)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO1", (++PantoFirstCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlBell)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 1)).ToString()); if (UserInput.IsReleased(UserCommands.ControlBell)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 0)).ToString()); if (UserInput.IsPressed(UserCommands.ControlBellToggle)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", (++BellCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlWiper)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "WIPER", (++WiperCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlDoorLeft)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORL", (++DoorLeftCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlDoorRight)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORR", (++DoorRightCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlMirror)) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "MIRRORS", (++MirrorsCount) % 2)).ToString()); if (UserInput.IsPressed(UserCommands.ControlHeadlightIncrease)) { HeadLightCount++; if (HeadLightCount >= 3) HeadLightCount = 2; MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString()); } if (UserInput.IsPressed(UserCommands.ControlHeadlightDecrease)) { HeadLightCount--; if (HeadLightCount < 0) HeadLightCount = 0; MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString()); } }
public static void RegisterInputEvents(Viewer viewer) { if (null == viewer) { throw new ArgumentNullException(nameof(viewer)); } //In Multiplayer, I maybe the helper, but I can request to be the controller // Horn and bell are managed by UpdateHornAndBell in MSTSLocomotive.cs viewer.UserCommandController.AddEvent(UserCommand.GameRequestControl, KeyEventType.KeyPressed, MPManager.RequestControl); viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph1, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "PANTO1", (++panto1) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph2, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "PANTO2", (++panto2) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph3, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "PANTO3", (++panto3) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlPantograph4, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "PANTO4", (++panto4) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlWiper, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "WIPER", (++wiper) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlDoorLeft, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "DOORL", (++doorLeft) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlDoorRight, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "DOORR", (++doorRight) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlMirror, KeyEventType.KeyPressed, () => MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "MIRRORS", (++mirrors) % 2).ToString())); viewer.UserCommandController.AddEvent(UserCommand.ControlHeadlightIncrease, KeyEventType.KeyPressed, () => { headlight++; if (headlight >= 3) { headlight = 2; } MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", headlight).ToString()); }); viewer.UserCommandController.AddEvent(UserCommand.ControlHeadlightDecrease, KeyEventType.KeyPressed, () => { headlight--; if (headlight < 0) { headlight = 0; } MPManager.Notify(new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", headlight).ToString()); }); }
public static void HandleUserInput() { //In Multiplayer, I maybe the helper, but I can request to be the controller // Horn and bell are managed by UpdateHornAndBell in MSTSLocomotive.cs if (UserInput.IsPressed(UserCommand.GameRequestControl)) { MPManager.RequestControl(); } if (UserInput.IsPressed(UserCommand.ControlPantograph2)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO2", (++PantoSecondCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlPantograph1)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO1", (++PantoFirstCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlPantograph4)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO4", (++PantoFourthCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlPantograph3)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "PANTO3", (++PantoThirdCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlWiper)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "WIPER", (++WiperCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlDoorLeft)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORL", (++DoorLeftCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlDoorRight)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "DOORR", (++DoorRightCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlMirror)) { MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "MIRRORS", (++MirrorsCount) % 2)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlHeadlightIncrease)) { HeadLightCount++; if (HeadLightCount >= 3) { HeadLightCount = 2; } MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString()); } if (UserInput.IsPressed(UserCommand.ControlHeadlightDecrease)) { HeadLightCount--; if (HeadLightCount < 0) { HeadLightCount = 0; } MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "HEADLIGHT", HeadLightCount)).ToString()); } }
public void AppendMessage(Keys[] newKeys, Keys[] oldKeys) { #if false foreach (var k in keys) { if (k == Keys.Enter) { this.Visible = false; UserInput.ComposingMessage = false; } if (k == Keys.Back) { if (Message.Text.Length <= 1) { Message.Text = ""; } else { Message.Text = Message.Text.Remove(Message.Text.Length - 1); } } else if (k == Keys.OemComma) { Message.Text += ","; } else if (k == Keys.OemPeriod) { Message.Text += "."; } else if (k == Keys.OemMinus) { Message.Text += "-"; } else if (k == Keys.OemQuestion) { Message.Text += "?"; } else if (k == Keys.OemQuotes) { Message.Text += "\""; } else if (k == Keys.OemSemicolon) { Message.Text += ";"; } else if (k == Keys.OemPlus) { Message.Text += "+"; } else { char c = (char)k; if (char.IsLetterOrDigit(c)) { Message.Text += char.ToLower(c); } if (c == ' ' || char.IsPunctuation(c)) { Message.Text += c; } } } #endif EnterReceived = false; string input = Convert(newKeys); foreach (char x in input) { //process backspace if (x == '\b') { if (Message.Text.Length >= 1) { Message.Text = Message.Text.Remove(Message.Text.Length - 1, 1); } } else { Message.Text += x; } } //we need to send message out if (EnterReceived == true) { string user = ""; if (MPManager.Instance().lastSender == "") //server will broadcast the message to everyone { user = MPManager.IsServer() ? string.Join("", MPManager.OnlineTrains.Players.Keys.Select((string k) => $"{k}\r")) + "0END" : "0Server\r0END"; } int index = Message.Text.IndexOf(':'); string msg = Message.Text; if (index > 0) { msg = Message.Text.Remove(0, index + 1); var onlinePlayers = Message.Text.Substring(0, index) .Split(',') .Select((string n) => n.Trim()) .Where((string nt) => MPManager.OnlineTrains.Players.ContainsKey(nt)) .Select((string nt) => $"{nt}\r"); string newUser = string.Join("", onlinePlayers); if (newUser != "") { user = newUser; } user += "0END"; } string msgText = new MSGText(MPManager.GetUserName(), user, msg).ToString(); try { MPManager.Notify(msgText); } catch { } finally { Visible = false; UserInput.ComposingMessage = false; Message.Text = ""; } } }