Add QR functionality via Web (Google)

This commit is contained in:
Kurt 2015-02-25 23:12:38 -08:00
parent fe3b1f5650
commit b9b553a0e9
6 changed files with 161 additions and 76 deletions

View file

@ -5,6 +5,7 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
namespace PKHeX
{
@ -56,6 +57,46 @@ namespace PKHeX
PB_QR.BackgroundImage = newpic;
}
}
public QR(Image qr, Image pkm, string top, string bottom, string left, string right)
{
InitializeComponent();
Font font = FontLabel.Font; // PKX.getPKXFont(8);
Image preview = new Bitmap(45, 45);
using (Graphics gfx = Graphics.FromImage(preview))
{
gfx.FillRectangle(new SolidBrush(Color.White), 0, 0, preview.Width, preview.Height);
gfx.DrawImage(pkm, preview.Width / 2 - pkm.Width / 2, preview.Height / 2 - pkm.Height / 2);
}
Image pic = Util.LayerImage(qr, preview, qr.Width / 2 - preview.Width / 2, qr.Height / 2 - preview.Height / 2, 1); // Middle
// Image pic = Util.LayerImage(qr, preview, 2, 2, 1); // Top Left
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
if (ModifierKeys == Keys.Control)
{
Graphics g = Graphics.FromImage(pic);
g.DrawString(top, font, Brushes.Black, new PointF(20, 5));
g.DrawString(bottom, font, Brushes.Black, new PointF(20, pic.Width - 15));
g.DrawString(left, font, Brushes.Black, new PointF(0, 20));
g.DrawString(right, font, Brushes.Black, new PointF(pic.Width - 15, 20), new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical));
PB_QR.BackgroundImage = pic;
}
else
{
int stretch = 50;
Height += stretch;
Image newpic = new Bitmap(PB_QR.Width, PB_QR.Height);
Graphics g = Graphics.FromImage(newpic);
g.FillRectangle(new SolidBrush(Color.White), 0, 0, newpic.Width, newpic.Height);
g.DrawImage(pic, 0, 0);
g.DrawString(top, font, Brushes.Black, new PointF(20, qr.Height - 5));
g.DrawString(bottom, font, Brushes.Black, new PointF(20, qr.Height + 8));
g.DrawString(left.Replace(Environment.NewLine.ToString(), "/").Replace("//", " ").Replace(":/", ": "), font, Brushes.Black, new PointF(20, qr.Height + 20));
g.DrawString(right, font, Brushes.Black, new PointF(20, qr.Height + 32));
PB_QR.BackgroundImage = newpic;
}
}
private void PB_QR_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy QR Image to Clipboard?")) return;

View file

@ -11,7 +11,8 @@
<RootNamespace>PKHeX</RootNamespace>
<AssemblyName>PKHeX</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
@ -61,6 +62,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />

View file

@ -1565,37 +1565,77 @@ namespace PKHeX
string server = "http://loadcode.projectpokemon.org/b1s1.html#"; // Rehosted with permission from LC/MS -- massive thanks!
string qrdata = Convert.ToBase64String(ekx);
string message = server + qrdata;
string webURL = "http://chart.apis.google.com/chart?chs=500x500&cht=qr&chl=http%3A%2F%2Floadcode.projectpokemon.org%2Fb1s1.html%23" + qrdata;
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy QR URL to Clipboard?")) return;
try { Clipboard.SetText(webURL); }
catch { Util.Alert("Failed to set text to Clipboard"); }
return;
}
string webURL = "http://chart.apis.google.com/chart?chs=365x365&cht=qr&chl=" + System.Web.HttpUtility.UrlEncode("http://loadcode.projectpokemon.org/b1s1.html#" + qrdata);
// Old Broken QR Code
PKX data = new PKX(pkx, "Tabs");
string filename = data.Nickname;
if (filename != data.Species)
filename += " (" + data.Species + ")";
string s1 = String.Format("{0} [{4}] lv{3} @ {1} -- {2}", filename, data.HeldItem, data.Nature, data.Level.ToString(), data.Ability);
string s2 = String.Format("{0} / {1} / {2} / {3}", data.Move1, data.Move2, data.Move3, data.Move4);
string IVs = String.Format(
"IV:{0}{1}{2}{3}{4}{5}"
+ Environment.NewLine + Environment.NewLine +
"EV:{6}{7}{8}{9}{10}{11}",
Environment.NewLine + data.HP_IV.ToString("00"),
Environment.NewLine + data.ATK_IV.ToString("00"),
Environment.NewLine + data.DEF_IV.ToString("00"),
Environment.NewLine + data.SPA_IV.ToString("00"),
Environment.NewLine + data.SPD_IV.ToString("00"),
Environment.NewLine + data.SPE_IV.ToString("00"),
Environment.NewLine + data.HP_EV.ToString("00"),
Environment.NewLine + data.ATK_EV.ToString("00"),
Environment.NewLine + data.DEF_EV.ToString("00"),
Environment.NewLine + data.SPA_EV.ToString("00"),
Environment.NewLine + data.SPD_EV.ToString("00"),
Environment.NewLine + data.SPE_EV.ToString("00"));
new QR(ekx, dragout.Image, s1, s2, IVs, "ProjectPokemon.org & PKHeX").ShowDialog();
Image qr = null;
try
{
System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(webURL);
System.Net.HttpWebResponse httpWebReponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();
qr = Image.FromStream(stream);
}
catch
{
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Unable to connect to the internet to receive QR code.", "Copy QR URL to Clipboard?"))
{
try { Clipboard.SetText(webURL); }
catch { Util.Alert("Failed to set text to Clipboard"); }
return;
}
}
PKX data = new PKX(pkx, "Tabs");
string filename = data.Nickname;
if (filename != data.Species)
filename += " (" + data.Species + ")";
string s1 = String.Format("{0} [{4}] lv{3} @ {1} -- {2}", filename, data.HeldItem, data.Nature, data.Level.ToString(), data.Ability);
string s2 = String.Format("{0} / {1} / {2} / {3}", data.Move1, data.Move2, data.Move3, data.Move4);
string IVs = String.Format(
"IV:{0}{1}{2}{3}{4}{5}"
+ Environment.NewLine + Environment.NewLine +
"EV:{6}{7}{8}{9}{10}{11}",
Environment.NewLine + data.HP_IV.ToString("00"),
Environment.NewLine + data.ATK_IV.ToString("00"),
Environment.NewLine + data.DEF_IV.ToString("00"),
Environment.NewLine + data.SPA_IV.ToString("00"),
Environment.NewLine + data.SPD_IV.ToString("00"),
Environment.NewLine + data.SPE_IV.ToString("00"),
Environment.NewLine + data.HP_EV.ToString("00"),
Environment.NewLine + data.ATK_EV.ToString("00"),
Environment.NewLine + data.DEF_EV.ToString("00"),
Environment.NewLine + data.SPA_EV.ToString("00"),
Environment.NewLine + data.SPD_EV.ToString("00"),
Environment.NewLine + data.SPE_EV.ToString("00"));
new QR(qr, dragout.Image, s1, s2, IVs, "ProjectPokemon.org & PKHeX").ShowDialog();
}
else
{
// Old Broken QR Code
PKX data = new PKX(pkx, "Tabs");
string filename = data.Nickname;
if (filename != data.Species)
filename += " (" + data.Species + ")";
string s1 = String.Format("{0} [{4}] lv{3} @ {1} -- {2}", filename, data.HeldItem, data.Nature, data.Level.ToString(), data.Ability);
string s2 = String.Format("{0} / {1} / {2} / {3}", data.Move1, data.Move2, data.Move3, data.Move4);
string IVs = String.Format(
"IV:{0}{1}{2}{3}{4}{5}"
+ Environment.NewLine + Environment.NewLine +
"EV:{6}{7}{8}{9}{10}{11}",
Environment.NewLine + data.HP_IV.ToString("00"),
Environment.NewLine + data.ATK_IV.ToString("00"),
Environment.NewLine + data.DEF_IV.ToString("00"),
Environment.NewLine + data.SPA_IV.ToString("00"),
Environment.NewLine + data.SPD_IV.ToString("00"),
Environment.NewLine + data.SPE_IV.ToString("00"),
Environment.NewLine + data.HP_EV.ToString("00"),
Environment.NewLine + data.ATK_EV.ToString("00"),
Environment.NewLine + data.DEF_EV.ToString("00"),
Environment.NewLine + data.SPA_EV.ToString("00"),
Environment.NewLine + data.SPD_EV.ToString("00"),
Environment.NewLine + data.SPE_EV.ToString("00"));
new QR(ekx, dragout.Image, s1, s2, IVs, "ProjectPokemon.org & PKHeX").ShowDialog();
}
}
private void clickFriendship(object sender, EventArgs e)
{

View file

@ -14680,7 +14680,7 @@ namespace PKHeX.Properties {
///! For the Menu Bar, separate the DropDown Item names with &apos; ; &apos;
///!
///! -----------------------------------------------------
///- DO NO [rest of string was truncated]&quot;;.
///- DO NOT CHANGE THIS [rest of string was truncated]&quot;;.
/// </summary>
internal static string lang_de {
get {
@ -14702,7 +14702,7 @@ namespace PKHeX.Properties {
///! For the Menu Bar, separate the DropDown Item names with &apos; ; &apos;
///!
///! -----------------------------------------------------
///- DO NO [rest of string was truncated]&quot;;.
///- DO NOT CHANGE THIS [rest of string was truncated]&quot;;.
/// </summary>
internal static string lang_en {
get {
@ -14724,7 +14724,7 @@ namespace PKHeX.Properties {
///! For the Menu Bar, separate the DropDown Item names with &apos; ; &apos;
///!
///! -----------------------------------------------------
///- DO NO [rest of string was truncated]&quot;;.
///- DO NOT CHANGE THIS [rest of string was truncated]&quot;;.
/// </summary>
internal static string lang_es {
get {
@ -14746,7 +14746,7 @@ namespace PKHeX.Properties {
///! For the Menu Bar, separate the DropDown Item names with &apos; ; &apos;
///!
///! -----------------------------------------------------
///- DO NO [rest of string was truncated]&quot;;.
///- DO NOT CHANGE THIS [rest of string was truncated]&quot;;.
/// </summary>
internal static string lang_fr {
get {
@ -14768,7 +14768,7 @@ namespace PKHeX.Properties {
///! For the Menu Bar, separate the DropDown Item names with &apos; ; &apos;
///!
///! -----------------------------------------------------
///- DO NO [rest of string was truncated]&quot;;.
///- DO NOT CHANGE THIS [rest of string was truncated]&quot;;.
/// </summary>
internal static string lang_ja {
get {
@ -15040,12 +15040,13 @@ namespace PKHeX.Properties {
}
/// <summary>
/// Looks up a localized string similar to If you are having issues viewing gender symbols, Options -&gt; Toggle Unicode Text.
/// Looks up a localized string similar to If you are having issues viewing certain symbols: Options -&gt; Toggle Unicode Text.
///
///
///// Main Window
///
///Right Click on Nickname/Nickname box to bring up the ingame-special characters.
///Hold Control when dragging out the Tab PKM to save as ekx.
///Control Click on a Nickname/OT box to bring up the ingame-special characters.
///
///Control + Click on...
///Randomize IVs: Set all IVs to max.
@ -15053,12 +15054,12 @@ namespace PKHeX.Properties {
///PP Ups Label: Set all PP Ups to 3.
///Friendship Label: Reset Friendship
///
///Click on the Save File path (above Boxes): Auto-detect/Reload save.
///Click on the OT label to set relevant details to that of the save file.
///
///Control-Drag a Box Slot to Copy-Overwrite
///Alt-Drag a Box Slot to Delete-Overwrite
///
///C [rest of string was truncated]&quot;;.
///// Save File
///
///Click [rest of string was truncated]&quot;;.
/// </summary>
internal static string shortcuts {
get {
@ -19062,10 +19063,10 @@ namespace PKHeX.Properties {
///Tall Grass
///
///Dialga/Palkia
///Cave/Hall of Origin
///
///Surfing/Fishing
///
///
///
///Building
///Marsh/Safari
///
@ -19095,10 +19096,10 @@ namespace PKHeX.Properties {
///Tall Grass
///
///Dialga/Palkia
///Cave/Hall of Origin
///
///Surfing/Fishing
///
///
///
///Building
///Marsh/Safari
///
@ -19128,10 +19129,10 @@ namespace PKHeX.Properties {
///Tall Grass
///
///Dialga/Palkia
///Cave/Hall of Origin
///
///Surfing/Fishing
///
///
///
///Building
///Marsh/Safari
///
@ -19161,10 +19162,10 @@ namespace PKHeX.Properties {
///Tall Grass
///
///Dialga/Palkia
///Cave/Hall of Origin
///
///Surfing/Fishing
///
///
///
///Building
///Marsh/Safari
///
@ -19194,10 +19195,10 @@ namespace PKHeX.Properties {
///Tall Grass
///
///Dialga/Palkia
///Cave/Hall of Origin
///
///Surfing/Fishing
///
///
///
///Building
///Marsh/Safari
///
@ -19227,10 +19228,10 @@ namespace PKHeX.Properties {
///Tall Grass
///
///Dialga/Palkia
///Cave/Hall of Origin
///
///Surfing/Fishing
///
///
///
///Building
///Marsh/Safari
///
@ -19260,10 +19261,10 @@ namespace PKHeX.Properties {
///Tall Grass
///
///Dialga/Palkia
///Cave/Hall of Origin
///
///Surfing/Fishing
///
///
///
///Building
///Marsh/Safari
///
@ -19293,10 +19294,10 @@ namespace PKHeX.Properties {
///Tall Grass
///
///Dialga/Palkia
///Cave/Hall of Origin
///
///Surfing/Fishing
///
///
///
///Building
///Marsh/Safari
///
@ -23235,18 +23236,18 @@ namespace PKHeX.Properties {
/// <summary>
/// Looks up a localized string similar to
///サファイア
///ルビー
///エメラルド
///ファイアレッド
///リーフグリーン
///蓝宝石
///红宝石
///绿宝石
///火红
///叶绿
///
///ハートゴールド
///ソウルシルバー
///心金
///魂银
///
///ダイヤモンド
///パール
///プラチナ
///钻石
///珍珠
///白金
///
///
///コロシアム/XD
@ -23254,14 +23255,15 @@ namespace PKHeX.Properties {
///
///
///
///ホワイト
///ブラック
///ホワイト2
///ブラック2
///
///
///2
///2
///X
///Y
///AS
///OR.
///OR
///.
/// </summary>
internal static string text_Games_zh {
get {

View file

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.296
// Runtime Version:4.0.30319.17929
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<connectionStrings />
</configuration>
<connectionStrings/>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>