-
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.
- Loading branch information
Showing
40 changed files
with
2,573 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
using MMDUI.Properties; | ||
using MMEdit; | ||
using MMEdit.Fx; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace MMDUI | ||
{ | ||
public class IO : PluginClass, IImportPlugin, IExportPlugin | ||
{ | ||
#region Fields | ||
public Encoding Encoding; | ||
private Regex regex = new Regex(@"(?<static>static\s+)?(?<const>const\s+)?(?<type>string|float|float2|float3|float4|int)\s+(?<name>\w+)\s*<\s*(?<annotation>(?<a_type>\w+)\s+(?<a_name>\w+)\s*=\s*(?<a_value>[^;]+)\s*;\s*)+\s*>\s*=\s*(?<value>[^;]+);", RegexOptions.Multiline); | ||
#endregion | ||
|
||
#region Constructor | ||
public IO() | ||
{ | ||
Encoding = Encoding.GetEncoding(Settings.Default.Encoding); | ||
Settings.Default.PropertyChanged += Default_PropertyChanged; | ||
} | ||
#endregion | ||
|
||
#region Properties | ||
public override Guid Guid | ||
{ | ||
get | ||
{ | ||
return new Guid("{2461F59A-09EA-49B5-9A8E-37588AABDC9B}"); | ||
} | ||
} | ||
|
||
public override string Name | ||
{ | ||
get | ||
{ | ||
return "MMDUI Format Import/Export"; | ||
} | ||
} | ||
|
||
public override string Version | ||
{ | ||
get | ||
{ | ||
return Assembly.GetExecutingAssembly().GetName().Version.ToString(); | ||
} | ||
} | ||
|
||
public override string Description | ||
{ | ||
get | ||
{ | ||
return "提供 MMDUI 格式的 MME 文件的导入/导出程序。\r\n支持的类型:int / float / float2 / float3 / float4"; | ||
} | ||
} | ||
|
||
public string Caption | ||
{ | ||
get | ||
{ | ||
return "MMDUI File"; | ||
} | ||
} | ||
|
||
public string Pattern | ||
{ | ||
get | ||
{ | ||
return "*.fx"; | ||
} | ||
} | ||
|
||
public Image Image | ||
{ | ||
get | ||
{ | ||
return Resources.function; | ||
} | ||
} | ||
#endregion | ||
|
||
#region Methods | ||
public bool IsExportable(ObjectFX obj) | ||
{ | ||
return obj is MMDUIObjectFX; | ||
} | ||
|
||
public void Export(ObjectFX obj, string path) | ||
{ | ||
MMDUIObjectFX fx = (MMDUIObjectFX)obj; | ||
|
||
string originalText = fx.OriginalText; | ||
List<int> indexList = new List<int>(); | ||
|
||
foreach (ControlObject controlObject in fx.ControlObjects) | ||
{ | ||
indexList.Add(controlObject._Index); | ||
} | ||
indexList.Sort(); | ||
indexList.Reverse(); | ||
|
||
foreach (int index in indexList) | ||
{ | ||
foreach (ControlObject controlObject in fx.ControlObjects) | ||
{ | ||
int startIndex = controlObject._Index; | ||
|
||
if (startIndex == index) | ||
{ | ||
int length = controlObject._Length; | ||
|
||
originalText = originalText.Remove(startIndex, length); | ||
originalText = originalText.Insert(startIndex, Format(controlObject)); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
File.WriteAllText(path, originalText, Encoding); | ||
} | ||
|
||
private string Format(ControlObject controlObject) | ||
{ | ||
string data = | ||
$"{(controlObject.IsStatic ? "static " : "")}" + | ||
$"{(controlObject.IsConst ? "const " : "")}" + | ||
$"{controlObject.Type} {controlObject.Name} <"; | ||
|
||
foreach (Annotation annotation in controlObject.Annotations) | ||
{ | ||
data += Environment.NewLine + $"\t{annotation.Type} {annotation.Name} = {(annotation.Type == "string" ? $"\"{annotation.Value}\"" : annotation.Value)};"; | ||
} | ||
|
||
data += $"{Environment.NewLine}> = {controlObject.Value};"; | ||
|
||
return data; | ||
} | ||
|
||
public bool IsImportable(string path) | ||
{ | ||
if (Path.GetExtension(path) == ".fx") | ||
{ | ||
string data = File.ReadAllText(path, Encoding); | ||
return regex.IsMatch(data); | ||
} | ||
return false; | ||
} | ||
|
||
public ObjectFX Import(string path) | ||
{ | ||
if (!IsImportable(path)) | ||
throw new Exception($"{Name}:\r\n无法导入此文件,因为它不是 MMDUI 格式。"); | ||
|
||
MMDUIObjectFX fx = new MMDUIObjectFX | ||
{ | ||
WidgetID = "MMDUI.Widgets.WidgetProxy", | ||
OriginalText = File.ReadAllText(path, Encoding), | ||
}; | ||
|
||
foreach (Match match in regex.Matches(fx.OriginalText)) | ||
{ | ||
ControlObject controlObject = new ControlObject() | ||
{ | ||
Type = match.Groups["type"].Value, | ||
Name = match.Groups["name"].Value, | ||
Value = match.Groups["value"].Value | ||
}; | ||
|
||
for (int i = 0; i < match.Groups["a_type"].Captures.Count; i++) | ||
{ | ||
Annotation annotation = new Annotation() | ||
{ | ||
Type = match.Groups["a_type"].Captures[i].Value, | ||
Name = match.Groups["a_name"].Captures[i].Value, | ||
Value = match.Groups["a_value"].Captures[i].Value.Replace("\"", ""), | ||
}; | ||
|
||
controlObject.Annotations.Add(annotation); | ||
} | ||
|
||
controlObject.IsStatic = match.Groups["static"].Success; | ||
controlObject.IsConst = match.Groups["const"].Success; | ||
controlObject._Index = match.Index; | ||
controlObject._Length = match.Length; | ||
|
||
fx.ControlObjects.Add(controlObject); | ||
} | ||
|
||
return fx; | ||
} | ||
|
||
private void Default_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName == "Encoding") | ||
{ | ||
Encoding = Encoding.GetEncoding(Settings.Default.Encoding); | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
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,164 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{3771D3DB-C587-4994-B30A-B09A24C94C9E}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>MMDUI</RootNamespace> | ||
<AssemblyName>MMDUI</AssemblyName> | ||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>false</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>embedded</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<DebugSymbols>true</DebugSymbols> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="MMEdit.Framework, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>.\MMEdit.Framework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="IO.cs" /> | ||
<Compile Include="Menu.cs" /> | ||
<Compile Include="MMDUIObjectFX.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
</Compile> | ||
<Compile Include="WidgetProvider.cs" /> | ||
<Compile Include="Widgets\NumericWidget.cs"> | ||
<SubType>UserControl</SubType> | ||
</Compile> | ||
<Compile Include="Widgets\NumericWidget.Designer.cs"> | ||
<DependentUpon>NumericWidget.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Widgets\SliderWidget.cs"> | ||
<SubType>UserControl</SubType> | ||
</Compile> | ||
<Compile Include="Widgets\SliderWidget.Designer.cs"> | ||
<DependentUpon>SliderWidget.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Widgets\MMDUIWidgetBase.cs"> | ||
<SubType>UserControl</SubType> | ||
</Compile> | ||
<Compile Include="Widgets\WidgetProxy.cs"> | ||
<SubType>UserControl</SubType> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Widgets\NumericWidget.resx"> | ||
<DependentUpon>NumericWidget.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Widgets\SliderWidget.resx"> | ||
<DependentUpon>SliderWidget.cs</DependentUpon> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\function.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\color-adjustment-green.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\color-adjustment-red.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\color-swatch.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\color-swatches.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-color-picker.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-color-picker-default.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-color-picker-transparent.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\color.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\color-adjustment.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-label.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-slider.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-slider-050.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-slider-100.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-slider-vertical.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-slider-vertical-050.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-slider-vertical-100.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\Images\ui-spin.png" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<PropertyGroup> | ||
<PostBuildEvent>if not exist "..\..\..\..\MMEdit\MMEdit\$(OutDir)Plugins" md "..\..\..\..\MMEdit\MMEdit\$(OutDir)Plugins" | ||
xcopy /y "$(TargetPath)" "..\..\..\..\MMEdit\MMEdit\$(OutDir)Plugins" | ||
if exist "$(TargetDir)$(TargetName).pdb" xcopy /y "$(TargetDir)$(TargetName).pdb" "..\..\..\..\MMEdit\MMEdit\$(OutDir)Plugins"</PostBuildEvent> | ||
</PropertyGroup> | ||
</Project> |
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29709.97 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMDUI", "MMDUI.csproj", "{3771D3DB-C587-4994-B30A-B09A24C94C9E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3771D3DB-C587-4994-B30A-B09A24C94C9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3771D3DB-C587-4994-B30A-B09A24C94C9E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3771D3DB-C587-4994-B30A-B09A24C94C9E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3771D3DB-C587-4994-B30A-B09A24C94C9E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {4EE22029-6A7B-49D2-ABB6-58EFA14CC901} | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.