forked from CadeEvs/FrostyToolsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FsLocalizationPlugin] Add StringID convert (Not Finish)
- Loading branch information
1 parent
b7fce43
commit d3c8aa3
Showing
3 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Plugins/FsLocalizationPlugin/Windows/ConvertStringWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<ctrl:FrostyDockableWindow x:Class="FsLocalizationPlugin.ConvertIDWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:FsLocalizationPlugin" | ||
xmlns:ctrl="clr-namespace:Frosty.Controls;assembly=FrostyControls" | ||
mc:Ignorable="d" | ||
Title="Convert Hash to String ID" Height="Auto" Width="350" | ||
ResizeMode="NoResize" WindowStartupLocation="CenterOwner"> | ||
|
||
<Window.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="/FrostyControls;component/Themes/Generic.xaml"/> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Window.Resources> | ||
<Grid Background="{StaticResource WindowBackground}"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition/> | ||
<RowDefinition Height="38"/> | ||
</Grid.RowDefinitions> | ||
|
||
<Grid Background="{StaticResource ListBackground}"> | ||
<StackPanel> | ||
|
||
<DockPanel LastChildFill="True" Margin="5"> | ||
<Label Content="Hash: " FontFamily="Global User Interface" Width="90"/> | ||
<TextBox x:Name="varHashTextBox" VerticalContentAlignment="Center" Text="" Margin="1" BorderThickness="1" TextChanged="varHashTextBox_TextChanged"/> | ||
</DockPanel> | ||
<DockPanel Margin="5,0,5,5" LastChildFill="True"> | ||
<Label Content="String: " FontFamily="Global User Interface" Width="90"/> | ||
<TextBox IsReadOnly="True" x:Name="varCurrentValueTextBox" Text="" Margin="1" BorderThickness="1" Height="64" AcceptsReturn="True" TextWrapping="Wrap" MaxLines="999999" VerticalScrollBarVisibility="Auto" Background="#FF141414"/> | ||
</DockPanel> | ||
<DockPanel LastChildFill="True" Margin="5"> | ||
<Label Content="ID: " FontFamily="Global User Interface" Width="90"/> | ||
<TextBox x:Name="StringIDTextBox" VerticalContentAlignment="Center" Text="" Margin="1" BorderThickness="1" IsReadOnly="True"/> | ||
</DockPanel> | ||
</StackPanel> | ||
</Grid> | ||
|
||
<Border Grid.Row="1"> | ||
<Grid Margin="8"> | ||
<DockPanel LastChildFill="False"> | ||
<Button x:Name="CloseButton" Content="Close" DockPanel.Dock="Left" Width="50" Click="CloseButton_Click"/> | ||
<Label x:Name="TryTimesLable" Content="Times: NULL" FontFamily="Global User Interface" Width="90"/> | ||
<Button x:Name="GenerateButton" Content="Generate" DockPanel.Dock="Right" Width="75" Click="GenerateButton_Click" IsEnabled="False"/> | ||
<Button x:Name="RevertButton" Content="Revert" DockPanel.Dock="Right" Margin="8,0" Width="50" Click="RevertButton_Click" IsEnabled="False"/> | ||
</DockPanel> | ||
</Grid> | ||
</Border> | ||
</Grid> | ||
</ctrl:FrostyDockableWindow> |
130 changes: 130 additions & 0 deletions
130
Plugins/FsLocalizationPlugin/Windows/ConvertStringWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using Frosty.Controls; | ||
using Frosty.Core; | ||
|
||
namespace FsLocalizationPlugin | ||
{ | ||
/// <summary> | ||
/// Interaction logic for AddProfileWindow.xaml | ||
/// </summary> | ||
public partial class ConvertIDWindow : FrostyDockableWindow | ||
{ | ||
public string ProfileName { get; set; } | ||
|
||
public FsLocalizationStringDatabase db = LocalizedStringDatabase.Current as FsLocalizationStringDatabase; | ||
|
||
public ConvertIDWindow() | ||
{ | ||
InitializeComponent(); | ||
Owner = Application.Current.MainWindow; | ||
CheckLastResult(); | ||
} | ||
private uint HashStringId(string stringId) | ||
{ | ||
uint result = 0xFFFFFFFF; | ||
for (int i = 0; i < stringId.Length; i++) | ||
result = stringId[i] + 33 * result; | ||
return result; | ||
} | ||
|
||
private bool LazySolution = true; | ||
|
||
private string LastResult = null; | ||
|
||
private int? TryTimes = null; | ||
|
||
public string Remove0X(string Hash) | ||
{ | ||
if (Hash.StartsWith("0x")) | ||
{ | ||
return Hash.Remove(0, 2); | ||
} | ||
return Hash; | ||
} | ||
|
||
private void CloseButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
Close(); | ||
} | ||
|
||
private void GenerateButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
string hash = varHashTextBox.Text; | ||
} | ||
|
||
private void RevertButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
StringIDTextBox.Text = LastResult; | ||
LastResult = null; | ||
CheckLastResult(); | ||
} | ||
|
||
private void varHashTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) | ||
{ | ||
TryTimes = null; | ||
StringIDTextBox.Text = null; | ||
LastResult = null; | ||
CheckLastResult(); | ||
CheckGenerateButton(); | ||
RefreshTryTimes(); | ||
try | ||
{ | ||
string MyHash = Remove0X(varHashTextBox.Text); | ||
uint result = Convert.ToUInt32(MyHash, 16); | ||
if (db.GetString(result) != "Invalid StringId: " + result.ToString("X8")) | ||
{ | ||
varCurrentValueTextBox.Text = db.GetString(result); | ||
GenerateButton.IsEnabled = true; | ||
} | ||
else | ||
{ | ||
varCurrentValueTextBox.Text = "No matching hash found in localisation database."; | ||
GenerateButton.IsEnabled = false; | ||
} | ||
} | ||
catch | ||
{ | ||
varCurrentValueTextBox.Text = "Invalid hash input."; | ||
GenerateButton.IsEnabled = false; | ||
} | ||
} | ||
|
||
private void CheckLastResult() | ||
{ | ||
if (LastResult == null) | ||
{ | ||
RevertButton.IsEnabled = false; | ||
} else if (!(LastResult == null)) | ||
{ | ||
RevertButton.IsEnabled = true; | ||
} | ||
} | ||
|
||
private void CheckGenerateButton() | ||
{ | ||
if (StringIDTextBox.Text == null) | ||
{ | ||
GenerateButton.Content = "Generate next"; | ||
GenerateButton.Width = 100; | ||
} else | ||
{ | ||
GenerateButton.Content = "Generate"; | ||
GenerateButton.Width = 75; | ||
} | ||
} | ||
|
||
private void RefreshTryTimes() | ||
{ | ||
if (!TryTimes.HasValue) | ||
{ | ||
TryTimesLable.Content = "Times: NULL"; | ||
} | ||
else | ||
{ | ||
TryTimesLable.Content = "Times: " + TryTimes; | ||
} | ||
} | ||
} | ||
} |