Merge pull request #275 from KNiedziela/master

Detective Squirrel [2016-07-27 12:23:41]
Merge pull request #275 from KNiedziela/master

Pretty PokeUi v2.0
Filename
PokemonGo/RocketAPI/Window/MainForm.cs
PokemonGo/RocketAPI/Window/PokeUi.Designer.cs
PokemonGo/RocketAPI/Window/PokeUi.cs
PokemonGo/RocketAPI/Window/PokeUi.resx
PokemonGo/RocketAPI/Window/PokemonGo.RocketAPI.Window.csproj
diff --git a/PokemonGo/RocketAPI/Window/MainForm.cs b/PokemonGo/RocketAPI/Window/MainForm.cs
index 1fa506e..9d2d616 100644
--- a/PokemonGo/RocketAPI/Window/MainForm.cs
+++ b/PokemonGo/RocketAPI/Window/MainForm.cs
@@ -783,7 +783,7 @@ namespace PokemonGo.RocketAPI.Window

         private void showAllToolStripMenuItem3_Click(object sender, EventArgs e)
         {
-            var pForm = new PokemonForm();
+            var pForm = new PokeUi();
             pForm.Show();
         }

diff --git a/PokemonGo/RocketAPI/Window/PokeUi.Designer.cs b/PokemonGo/RocketAPI/Window/PokeUi.Designer.cs
new file mode 100644
index 0000000..1558cda
--- /dev/null
+++ b/PokemonGo/RocketAPI/Window/PokeUi.Designer.cs
@@ -0,0 +1,73 @@
+namespace PokemonGo.RocketAPI.Window
+{
+    partial class PokeUi
+    {
+        /// <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 Windows Form 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.listView1 = new System.Windows.Forms.ListView();
+            this.button1 = new System.Windows.Forms.Button();
+            this.SuspendLayout();
+            //
+            // listView1
+            //
+            this.listView1.Location = new System.Drawing.Point(12, 12);
+            this.listView1.Name = "listView1";
+            this.listView1.Size = new System.Drawing.Size(411, 314);
+            this.listView1.TabIndex = 0;
+            this.listView1.UseCompatibleStateImageBehavior = false;
+            this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
+            //
+            // button1
+            //
+            this.button1.Location = new System.Drawing.Point(12, 332);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(411, 19);
+            this.button1.TabIndex = 3;
+            this.button1.Text = "Reload";
+            this.button1.UseVisualStyleBackColor = true;
+            this.button1.Click += new System.EventHandler(this.button1_Click);
+            //
+            // PokeUi
+            //
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(435, 363);
+            this.Controls.Add(this.button1);
+            this.Controls.Add(this.listView1);
+            this.Name = "PokeUi";
+            this.Text = "PokeUi";
+            this.Load += new System.EventHandler(this.PokeUi_Load);
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.ListView listView1;
+        private System.Windows.Forms.Button button1;
+    }
+}
\ No newline at end of file
diff --git a/PokemonGo/RocketAPI/Window/PokeUi.cs b/PokemonGo/RocketAPI/Window/PokeUi.cs
new file mode 100644
index 0000000..690a57c
--- /dev/null
+++ b/PokemonGo/RocketAPI/Window/PokeUi.cs
@@ -0,0 +1,129 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using PokemonGo.RocketAPI.Enums;
+using PokemonGo.RocketAPI.GeneratedCode;
+
+namespace PokemonGo.RocketAPI.Window
+{
+    public partial class PokeUi : Form
+    {
+        public PokeUi()
+        {
+            InitializeComponent();
+            ClientSettings = Settings.Instance;
+        }
+
+        private void PokeUi_Load(object sender, EventArgs e)
+        {
+            Execute();
+        }
+
+        public static ISettings ClientSettings;
+
+        private async void Execute()
+        {
+            button1.Enabled = false;
+
+            var client = new Client(ClientSettings);
+
+            try
+            {
+                switch (ClientSettings.AuthType)
+                {
+                    case AuthType.Ptc:
+                        await client.DoPtcLogin(ClientSettings.PtcUsername, ClientSettings.PtcPassword);
+                        break;
+                    case AuthType.Google:
+                        await client.DoGoogleLogin();
+                        break;
+                }
+                //
+                await client.SetServer();
+                var inventory = await client.GetInventory();
+                var pokemons =
+                    inventory.InventoryDelta.InventoryItems
+                    .Select(i => i.InventoryItemData?.Pokemon)
+                        .Where(p => p != null && p?.PokemonId > 0)
+                        .OrderByDescending(key => key.Cp);
+                var families = inventory.InventoryDelta.InventoryItems
+                    .Select(i => i.InventoryItemData?.PokemonFamily)
+                    .Where(p => p != null && (int) p?.FamilyId > 0)
+                    .OrderByDescending(p => (int)p.FamilyId);
+
+
+
+
+                var imageList = new ImageList { ImageSize = new Size(50, 50) };
+                listView1.ShowItemToolTips = true;
+
+                foreach (var pokemon in pokemons)
+                {
+
+                    var pokemonImage = GetPokemonImage((int)pokemon.PokemonId);
+                    imageList.Images.Add(pokemon.PokemonId.ToString(),pokemonImage);
+
+                    listView1.LargeImageList = imageList;
+                    var listViewItem = new ListViewItem();
+                    listViewItem.SubItems.Add("Cp: " + pokemon.Cp);
+
+
+                    var currentCandy = families
+                        .Where(i => (int) i.FamilyId <= (int) pokemon.PokemonId)
+                        .Select(f=>f.Candy)
+                        .First();
+                    var currIv = Math.Round(Perfect(pokemon));
+                    //listViewItem.SubItems.Add();
+                    listViewItem.ImageKey = pokemon.PokemonId.ToString();
+                    listViewItem.Text = string.Format("{0}\nCp:{1}", pokemon.PokemonId, pokemon.Cp);
+                    listViewItem.ToolTipText = "Candy: " + currentCandy+"\n"+"IV: "+currIv+"%";
+
+
+                    this.listView1.Items.Add(listViewItem);
+
+
+                }
+                button1.Enabled = true;
+
+            }
+            catch (TaskCanceledException){ Execute(); }
+            catch (UriFormatException) { Execute(); }
+            catch (ArgumentOutOfRangeException) {  Execute(); }
+            catch (ArgumentNullException) { Execute(); }
+            catch (NullReferenceException) { Execute(); }
+            catch (Exception ex) {  Execute(); }
+        }
+
+        private static Bitmap GetPokemonImage(int pokemonId)
+        {
+            var url = "http://pokeapi.co/media/sprites/pokemon/" + pokemonId + ".png";
+            PictureBox picbox = new PictureBox();
+            picbox.Load(url);
+            Bitmap bitmapRemote = (Bitmap)picbox.Image;
+            return bitmapRemote;
+        }
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            this.listView1.Clear();
+            Execute();
+        }
+
+        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            //if (listView1.SelectedItems.Count == 0) return;
+            //label1.Text = listView1.SelectedItems[0]?.SubItems[1].Text;
+            //label2.Text = listView1.SelectedItems[0]?.SubItems[2].Text;
+        }
+        public static float Perfect(PokemonData poke)
+        {
+            return ((float)(poke.IndividualAttack + poke.IndividualDefense + poke.IndividualStamina) / (3.0f * 15.0f)) * 100.0f;
+        }
+    }
+}
diff --git a/PokemonGo/RocketAPI/Window/PokeUi.resx b/PokemonGo/RocketAPI/Window/PokeUi.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/PokemonGo/RocketAPI/Window/PokeUi.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/PokemonGo/RocketAPI/Window/PokemonGo.RocketAPI.Window.csproj b/PokemonGo/RocketAPI/Window/PokemonGo.RocketAPI.Window.csproj
index 1ad592b..d83e624 100644
--- a/PokemonGo/RocketAPI/Window/PokemonGo.RocketAPI.Window.csproj
+++ b/PokemonGo/RocketAPI/Window/PokemonGo.RocketAPI.Window.csproj
@@ -74,6 +74,12 @@
     <Compile Include="PokemonForm.Designer.cs">
       <DependentUpon>PokemonForm.cs</DependentUpon>
     </Compile>
+    <Compile Include="PokeUi.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="PokeUi.Designer.cs">
+      <DependentUpon>PokeUi.cs</DependentUpon>
+    </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Settings.cs" />
@@ -89,6 +95,9 @@
     <EmbeddedResource Include="PokemonForm.resx">
       <DependentUpon>PokemonForm.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="PokeUi.resx">
+      <DependentUpon>PokeUi.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
You may download the files in Public Git.