Added a Google Translate button
This commit is contained in:
parent
5bd386ff01
commit
46745b94a9
|
@ -33,9 +33,9 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net451" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net451" />
|
||||
</packages>
|
|
@ -1,6 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
this.lineOpsPanel = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.copyCodesButton = new System.Windows.Forms.Button();
|
||||
this.previewButton = new System.Windows.Forms.Button();
|
||||
this.previewer = new ScriptToolGui.StringPreviewer();
|
||||
this.translateButton = new System.Windows.Forms.Button();
|
||||
this.codeSplitContainer = new System.Windows.Forms.SplitContainer();
|
||||
this.codeList = new System.Windows.Forms.ListBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
|
@ -65,6 +65,7 @@
|
|||
this.statusBar = new System.Windows.Forms.StatusStrip();
|
||||
this.writeLabel = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.writeTimer = new System.Windows.Forms.Timer(this.components);
|
||||
this.previewer = new ScriptToolGui.StringPreviewer();
|
||||
this.mainMenu.SuspendLayout();
|
||||
this.topPanel.SuspendLayout();
|
||||
this.mainPanel.SuspendLayout();
|
||||
|
@ -121,7 +122,7 @@
|
|||
this.checkCompletionMenu,
|
||||
this.autosaveMenu});
|
||||
this.toolsMenu.Name = "toolsMenu";
|
||||
this.toolsMenu.Size = new System.Drawing.Size(48, 20);
|
||||
this.toolsMenu.Size = new System.Drawing.Size(47, 20);
|
||||
this.toolsMenu.Text = "Tools";
|
||||
//
|
||||
// resolveDuplicateLabelsMenu
|
||||
|
@ -337,6 +338,7 @@
|
|||
this.lineOpsPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.lineOpsPanel.Controls.Add(this.copyCodesButton);
|
||||
this.lineOpsPanel.Controls.Add(this.previewButton);
|
||||
this.lineOpsPanel.Controls.Add(this.translateButton);
|
||||
this.lineOpsPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.lineOpsPanel.Location = new System.Drawing.Point(0, 489);
|
||||
this.lineOpsPanel.Name = "lineOpsPanel";
|
||||
|
@ -363,18 +365,15 @@
|
|||
this.previewButton.UseVisualStyleBackColor = true;
|
||||
this.previewButton.Click += new System.EventHandler(this.previewButton_Click);
|
||||
//
|
||||
// previewer
|
||||
// translateButton
|
||||
//
|
||||
this.previewer.AutoScroll = true;
|
||||
this.previewer.CharLookup = null;
|
||||
this.previewer.DisplayedString = null;
|
||||
this.previewer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.previewer.Location = new System.Drawing.Point(0, 0);
|
||||
this.previewer.M12Compiler = null;
|
||||
this.previewer.MaxWidth = 0;
|
||||
this.previewer.Name = "previewer";
|
||||
this.previewer.Size = new System.Drawing.Size(796, 133);
|
||||
this.previewer.TabIndex = 0;
|
||||
this.translateButton.Location = new System.Drawing.Point(214, 3);
|
||||
this.translateButton.Name = "translateButton";
|
||||
this.translateButton.Size = new System.Drawing.Size(114, 23);
|
||||
this.translateButton.TabIndex = 2;
|
||||
this.translateButton.Text = "Google Translate";
|
||||
this.translateButton.UseVisualStyleBackColor = true;
|
||||
this.translateButton.Click += new System.EventHandler(this.translateButton_Click);
|
||||
//
|
||||
// codeSplitContainer
|
||||
//
|
||||
|
@ -500,6 +499,18 @@
|
|||
this.writeTimer.Interval = 10000;
|
||||
this.writeTimer.Tick += new System.EventHandler(this.writeTimer_Tick);
|
||||
//
|
||||
// previewer
|
||||
//
|
||||
this.previewer.AutoScroll = true;
|
||||
this.previewer.CharLookup = null;
|
||||
this.previewer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.previewer.Location = new System.Drawing.Point(0, 0);
|
||||
this.previewer.M12Compiler = null;
|
||||
this.previewer.MaxWidth = 0;
|
||||
this.previewer.Name = "previewer";
|
||||
this.previewer.Size = new System.Drawing.Size(796, 133);
|
||||
this.previewer.TabIndex = 0;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -584,6 +595,7 @@
|
|||
private System.Windows.Forms.Button prevButton;
|
||||
private System.Windows.Forms.Button nextButton;
|
||||
private System.Windows.Forms.ToolStripMenuItem autosaveMenu;
|
||||
private System.Windows.Forms.Button translateButton;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace ScriptToolGui
|
|||
static Compiler ebCompiler = new Compiler(EbControlCode.Codes, (rom, address) => rom[address] < 0x20);
|
||||
static readonly Game[] validGames;
|
||||
static IDictionary<byte, string> ebCharLookup;
|
||||
static IDictionary<byte, string> m12CharLookup;
|
||||
|
||||
// Lookups
|
||||
Dictionary<Game, TextBox> textboxLookup;
|
||||
|
@ -64,6 +65,7 @@ namespace ScriptToolGui
|
|||
{
|
||||
validGames = new Game[] { Game.Eb, Game.M12, Game.M12English };
|
||||
ebCharLookup = JsonConvert.DeserializeObject<Dictionary<byte, string>>(File.ReadAllText("eb-char-lookup.json"));
|
||||
m12CharLookup = JsonConvert.DeserializeObject<Dictionary<byte, string>>(File.ReadAllText("m12-char-lookup.json"));
|
||||
}
|
||||
|
||||
string ReadEbString(byte[] rom, int address, int length)
|
||||
|
@ -730,7 +732,7 @@ namespace ScriptToolGui
|
|||
if (collectionSelector.SelectedIndex == -1)
|
||||
{
|
||||
groupSelector.Items.Clear();
|
||||
previewer.DisplayedString = null;
|
||||
previewer.DisplayString(null, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -765,7 +767,7 @@ namespace ScriptToolGui
|
|||
|
||||
private void previewButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
previewer.DisplayedString = m12StringEnglish.Text;
|
||||
previewer.DisplayString(m12StringEnglish.Text, true);
|
||||
}
|
||||
|
||||
private void m12StringEnglish_MouseClick(object sender, MouseEventArgs e)
|
||||
|
@ -933,6 +935,55 @@ namespace ScriptToolGui
|
|||
{
|
||||
writeTimer.Enabled = autosaveMenu.Checked;
|
||||
}
|
||||
|
||||
private void translateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
string toTranslate = StripCodes(m12String.Text);
|
||||
Translate(toTranslate);
|
||||
}
|
||||
|
||||
private void Translate(string toTranslate)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
builder.Append("https://translate.google.com/#ja/en/");
|
||||
|
||||
var bytes = Encoding.UTF8.GetBytes(toTranslate);
|
||||
foreach (byte b in bytes)
|
||||
{
|
||||
builder.Append('%');
|
||||
builder.Append(b.ToString("X2"));
|
||||
}
|
||||
|
||||
System.Diagnostics.Process.Start(builder.ToString());
|
||||
}
|
||||
|
||||
private string StripCodes(string str)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
bool inCode = false;
|
||||
foreach(char c in str)
|
||||
{
|
||||
if (c == '[')
|
||||
{
|
||||
inCode = true;
|
||||
}
|
||||
else if (c == ']')
|
||||
{
|
||||
inCode = false;
|
||||
builder.Append(' ');
|
||||
}
|
||||
else if (c == '^')
|
||||
{
|
||||
inCode = !inCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!inCode)
|
||||
builder.Append(c);
|
||||
}
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
enum Game
|
||||
|
|
|
@ -33,9 +33,9 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
|
|
@ -18,30 +18,16 @@ namespace ScriptToolGui
|
|||
|
||||
public int MaxWidth { get; set; }
|
||||
|
||||
private string text;
|
||||
public string DisplayedString
|
||||
{
|
||||
get
|
||||
{
|
||||
return text;
|
||||
}
|
||||
set
|
||||
{
|
||||
text = value;
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
|
||||
public StringPreviewer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Redraw()
|
||||
private void RedrawFancy(string str)
|
||||
{
|
||||
stringPanel.Controls.Clear();
|
||||
|
||||
if (M12Compiler == null || CharLookup == null || text == null)
|
||||
if (M12Compiler == null || CharLookup == null || str == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -49,7 +35,7 @@ namespace ScriptToolGui
|
|||
try
|
||||
{
|
||||
IList<int> widths;
|
||||
IList<string> parsed = M12Compiler.FormatPreviewM12(text, out widths, CharLookup);
|
||||
IList<string> parsed = M12Compiler.FormatPreviewM12(str, out widths, CharLookup);
|
||||
|
||||
for (int i = 0; i < parsed.Count; i++)
|
||||
{
|
||||
|
@ -77,5 +63,28 @@ namespace ScriptToolGui
|
|||
stringPanel.Controls.Add(errLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void RedrawPlain(string str)
|
||||
{
|
||||
stringPanel.Controls.Clear();
|
||||
|
||||
if (str == null)
|
||||
return;
|
||||
|
||||
var label = new Label
|
||||
{
|
||||
AutoSize = true,
|
||||
Text = str
|
||||
};
|
||||
stringPanel.Controls.Add(label);
|
||||
}
|
||||
|
||||
public void DisplayString(string str, bool fancy)
|
||||
{
|
||||
if (fancy)
|
||||
RedrawFancy(str);
|
||||
else
|
||||
RedrawPlain(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net451" />
|
||||
</packages>
|
Loading…
Reference in New Issue