diff options
| author | AShifter <[email protected]> | 2017-05-05 10:16:29 -0600 |
|---|---|---|
| committer | AShifter <[email protected]> | 2017-05-05 10:16:29 -0600 |
| commit | a7fff72826ba12a9a87ad4edf38526174e330acb (patch) | |
| tree | 2afba9246adeca69cffc98b77eb4183f680c6165 /ShiftOS.WinForms | |
| parent | 13b35b32c2c429e6bd2d7b41ca43cc62f305dbc5 (diff) | |
| parent | 9a2373ec42faeef719cff1c7076af87ef44179a7 (diff) | |
| download | shiftos_thereturn-a7fff72826ba12a9a87ad4edf38526174e330acb.tar.gz shiftos_thereturn-a7fff72826ba12a9a87ad4edf38526174e330acb.tar.bz2 shiftos_thereturn-a7fff72826ba12a9a87ad4edf38526174e330acb.zip | |
Merge remote-tracking branch 'refs/remotes/shiftos-game/master'
Diffstat (limited to 'ShiftOS.WinForms')
| -rw-r--r-- | ShiftOS.WinForms/Applications/Pong.cs | 245 | ||||
| -rw-r--r-- | ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.Designer.cs | 62 | ||||
| -rw-r--r-- | ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs | 51 | ||||
| -rw-r--r-- | ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.resx | 120 | ||||
| -rw-r--r-- | ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 |
5 files changed, 402 insertions, 85 deletions
diff --git a/ShiftOS.WinForms/Applications/Pong.cs b/ShiftOS.WinForms/Applications/Pong.cs index 04c963f..d63f406 100644 --- a/ShiftOS.WinForms/Applications/Pong.cs +++ b/ShiftOS.WinForms/Applications/Pong.cs @@ -123,7 +123,7 @@ namespace ShiftOS.WinForms.Applications int OpponentY = 0; - bool IsLeader = false; + bool IsLeader = true; int LeaderX = 0; int LeaderY = 0; @@ -368,75 +368,124 @@ namespace ShiftOS.WinForms.Applications public void ServerMessageReceivedHandler(ServerMessage msg) { - if (msg.Name == "pong_mp_setballpos") - { - var pt = JsonConvert.DeserializeObject<Point>(msg.Contents); - LeaderX = pt.X; - LeaderY = pt.Y; - } - else if(msg.Name == "pong_mp_left") + if (IsMultiplayerSession) { - this.Invoke(new Action(() => + if (msg.Name == "pong_mp_setballpos") { - AppearanceManager.Close(this); - })); - Infobox.Show("Opponent has closed Pong.", "The opponent has closed Pong, therefore the connection between you two has dropped."); - } - else if (msg.Name == "pong_mp_youlose") - { - this.Invoke(new Action(LoseMP)); - } - else if (msg.Name == "pong_mp_setopponenty") - { - int y = Convert.ToInt32(msg.Contents); - OpponentY = y; - } - else if (msg.Name == "pong_handshake_matchmake") - { - if (!PossibleMatchmakes.Contains(msg.Contents)) - PossibleMatchmakes.Add(msg.Contents); - this.Invoke(new Action(ListMatchmakes)); - } - else if (msg.Name == "pong_handshake_resendid") - { - ServerManager.Forward("all", "pong_handshake_matchmake", YouGUID); - } - else if (msg.Name == "pong_handshake_complete") - { - IsLeader = true; + var pt = JsonConvert.DeserializeObject<Point>(msg.Contents); + LeaderX = pt.X; + LeaderY = pt.Y; + } + else if (msg.Name == "pong_mp_left") + { + this.Invoke(new Action(() => + { + AppearanceManager.Close(this); + })); + Infobox.Show("Opponent has closed Pong.", "The opponent has closed Pong, therefore the connection between you two has dropped."); + } + else if (msg.Name == "pong_mp_youlose") + { + this.Invoke(new Action(LoseMP)); + } + else if (msg.Name == "pong_mp_setopponenty") + { + int y = Convert.ToInt32(msg.Contents); + OpponentY = y; + } + else if (msg.Name == "pong_handshake_matchmake") + { + if (!PossibleMatchmakes.Contains(msg.Contents)) + PossibleMatchmakes.Add(msg.Contents); + this.Invoke(new Action(ListMatchmakes)); + } + else if (msg.Name == "pong_handshake_resendid") + { + ServerManager.Forward("all", "pong_handshake_matchmake", YouGUID); + } + else if (msg.Name == "pong_handshake_complete") + { + IsLeader = true; - OpponentGUID = msg.Contents; - LeaveMatchmake(); - this.Invoke(new Action(() => + OpponentGUID = msg.Contents; + LeaveMatchmake(); + this.Invoke(new Action(() => + { + pnlmultiplayerhandshake.Hide(); + StartLevel(); + })); + } + else if(msg.Name == "pong_mp_levelcompleted") { - pnlmultiplayerhandshake.Hide(); - StartLevel(); - })); - } - else if (msg.Name == "pong_handshake_chosen") - { - IsLeader = false; - LeaveMatchmake(); - OpponentGUID = msg.Contents; - YouGUID = ServerManager.thisGuid.ToString(); - SendFollowerGUID(); - this.Invoke(new Action(() => + level = Convert.ToInt32(msg.Contents) + 1; + this.Invoke(new Action(CompleteLevel)); + } + else if (msg.Name == "pong_handshake_chosen") { - pnlmultiplayerhandshake.Hide(); - })); - } - else if (msg.Name == "pong_handshake_left") - { - if (this.PossibleMatchmakes.Contains(msg.Contents)) - this.PossibleMatchmakes.Remove(msg.Contents); - this.Invoke(new Action(ListMatchmakes)); - } - else if (msg.Name == "pong_mp_youwin") - { - this.Invoke(new Action(Win)); + IsLeader = false; + LeaveMatchmake(); + OpponentGUID = msg.Contents; + YouGUID = ServerManager.thisGuid.ToString(); + //Start the timers. + counter.Start(); + SendFollowerGUID(); + this.Invoke(new Action(() => + { + pnlmultiplayerhandshake.Hide(); + })); + } + else if(msg.Name == "pong_mp_cashedout") + { + this.Invoke(new Action(() => + { + btncashout_Click(this, EventArgs.Empty); + })); + Infobox.Show("Cashed out.", "The other player has cashed out their Codepoints. Therefore, we have automatically cashed yours out."); + } + else if(msg.Name == "pong_mp_startlevel") + { + OpponentAgrees = true; + if(YouAgree == false) + { + Infobox.PromptYesNo("Play another level?", "The opponent wants to play another level. Would you like to as well?", (answer)=> + { + YouAgree = answer; + ServerManager.Forward(OpponentGUID, "pong_mp_level_callback", YouAgree.ToString()); + }); + } + } + else if(msg.Name == "pong_mp_level_callback") + { + bool agreed = bool.Parse(msg.Contents); + OpponentAgrees = agreed; + if (OpponentAgrees) + { + if (IsLeader) + { + //this.Invoke(new Action(())) + } + } + } + else if (msg.Name == "pong_handshake_left") + { + if (this.PossibleMatchmakes.Contains(msg.Contents)) + this.PossibleMatchmakes.Remove(msg.Contents); + this.Invoke(new Action(ListMatchmakes)); + } + else if(msg.Name == "pong_mp_clockupdate") + { + secondsleft = Convert.ToInt32(msg.Contents); + } + else if (msg.Name == "pong_mp_youwin") + { + this.Invoke(new Action(Win)); + } } } + bool OpponentAgrees = false; + bool YouAgree = false; + public void ListMatchmakes() { lvotherplayers.Items.Clear(); @@ -543,37 +592,50 @@ namespace ShiftOS.WinForms.Applications } + public void CompleteLevel() + { + if (SaveSystem.CurrentSave.UniteAuthToken != null) + { + try + { + var unite = new ShiftOS.Unite.UniteClient("http://getshiftos.ml", SaveSystem.CurrentSave.UniteAuthToken); + if (unite.GetPongLevel() < level) + unite.SetPongLevel(level); + } + catch { } + } + //Only set these stats if the user is the leader. + if (IsLeader) + { + secondsleft = 60; + level = level + 1; + generatenextlevel(); + } + + pnlgamestats.Show(); + pnlgamestats.BringToFront(); + pnlgamestats.Location = new Point((pgcontents.Width / 2) - (pnlgamestats.Width / 2), (pgcontents.Height / 2) - (pnlgamestats.Height / 2)); + + counter.Stop(); + gameTimer.Stop(); + + } + // ERROR: Handles clauses are not supported in C# private void counter_Tick(object sender, EventArgs e) { - if (this.Left < Screen.PrimaryScreen.Bounds.Width) + if (IsLeader) { - secondsleft = secondsleft - 1; - if (secondsleft == 1) + if (this.Left < Screen.PrimaryScreen.Bounds.Width) { - secondsleft = 60; - level = level + 1; - if (SaveSystem.CurrentSave.UniteAuthToken != null) + secondsleft = secondsleft - 1; + if (secondsleft == 1) { - try - { - var unite = new ShiftOS.Unite.UniteClient("http://getshiftos.ml", SaveSystem.CurrentSave.UniteAuthToken); - if (unite.GetPongLevel() < level) - unite.SetPongLevel(level); - } - catch { } + CompleteLevel(); } - generatenextlevel(); - pnlgamestats.Show(); - pnlgamestats.BringToFront(); - pnlgamestats.Location = new Point((pgcontents.Width / 2) - (pnlgamestats.Width / 2), (pgcontents.Height / 2) - (pnlgamestats.Height / 2)); - - counter.Stop(); - gameTimer.Stop(); - SendHighscores(); - } - lblstatscodepoints.Text = Localization.Parse("{CODEPOINTS}: ") + (levelrewards[level - 1] + beatairewardtotal).ToString(); + lblstatscodepoints.Text = Localization.Parse("{CODEPOINTS}: ") + (levelrewards[level - 1] + beatairewardtotal).ToString(); + } } SetupStats(); } @@ -824,6 +886,19 @@ namespace ShiftOS.WinForms.Applications unite.SetPongCP(totalreward); } } + if (IsMultiplayerSession) + { + ServerManager.Forward(OpponentGUID, "pong_mp_cashedout", null); + StopMultiplayerSession(); + } + } + + public void StopMultiplayerSession() + { + IsMultiplayerSession = false; + IsLeader = true; + OpponentGUID = ""; + YouGUID = ""; } private void newgame() diff --git a/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.Designer.cs b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.Designer.cs new file mode 100644 index 0000000..c6a7d83 --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.Designer.cs @@ -0,0 +1,62 @@ +namespace ShiftOS.WinForms.DesktopWidgets +{ + partial class HeartbeatWidget + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.lbheartbeat = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // lbheartbeat + // + this.lbheartbeat.AutoSize = true; + this.lbheartbeat.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbheartbeat.Location = new System.Drawing.Point(0, 0); + this.lbheartbeat.Name = "lbheartbeat"; + this.lbheartbeat.Size = new System.Drawing.Size(35, 13); + this.lbheartbeat.TabIndex = 0; + this.lbheartbeat.Text = "label1"; + // + // HeartbeatWidget + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.Controls.Add(this.lbheartbeat); + this.Name = "HeartbeatWidget"; + this.Size = new System.Drawing.Size(35, 13); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lbheartbeat; + } +} diff --git a/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs new file mode 100644 index 0000000..d38cdc3 --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.WinForms.Tools; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.DesktopWidgets +{ + [DesktopWidget("Server ping", "See the time spent between client requests and server replies in the digital society.")] + public partial class HeartbeatWidget : UserControl, IDesktopWidget + { + public HeartbeatWidget() + { + InitializeComponent(); + tmr.Interval = 1; + tmr.Tick += (o, a) => + { + if(ts != ServerManager.DigitalSocietyPing) + { + ts = ServerManager.DigitalSocietyPing; + lbheartbeat.Text = "Server ping: " + ts.ToString(); + } + }; + } + + //Fun fact. I misspelled this as "TimeSpam." + TimeSpan ts; + + public void OnSkinLoad() + { + ControlManager.SetupControls(this); + } + + public void OnUpgrade() + { + } + + Timer tmr = new Timer(); + + public void Setup() + { + tmr.Start(); + } + } +} diff --git a/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.resx b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.resx @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root>
\ No newline at end of file diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 9fc237f..1607ae9 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -298,6 +298,12 @@ <Compile Include="DesktopWidgets\CodepointsWidget.Designer.cs"> <DependentUpon>CodepointsWidget.cs</DependentUpon> </Compile> + <Compile Include="DesktopWidgets\HeartbeatWidget.cs"> + <SubType>UserControl</SubType> + </Compile> + <Compile Include="DesktopWidgets\HeartbeatWidget.Designer.cs"> + <DependentUpon>HeartbeatWidget.cs</DependentUpon> + </Compile> <Compile Include="DesktopWidgets\TerminalWidget.cs"> <SubType>UserControl</SubType> </Compile> @@ -502,6 +508,9 @@ <EmbeddedResource Include="DesktopWidgets\CodepointsWidget.resx"> <DependentUpon>CodepointsWidget.cs</DependentUpon> </EmbeddedResource> + <EmbeddedResource Include="DesktopWidgets\HeartbeatWidget.resx"> + <DependentUpon>HeartbeatWidget.cs</DependentUpon> + </EmbeddedResource> <EmbeddedResource Include="DesktopWidgets\TerminalWidget.resx"> <DependentUpon>TerminalWidget.cs</DependentUpon> </EmbeddedResource> |
