Skip to content

Commit

Permalink
Merge pull request #416 from Aragas/dev
Browse files Browse the repository at this point in the history
v5.8.2
  • Loading branch information
Aragas authored Jul 12, 2023
2 parents 4d1d0d4 + 8e96f19 commit e42ab29
Show file tree
Hide file tree
Showing 13 changed files with 2,291 additions and 78 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<GameVersion>1.0.0</GameVersion>
<Version>5.8.1</Version>
<Version>5.8.2</Version>
<HarmonyVersion>2.2.2</HarmonyVersion>
<ButterLibVersion>2.8.8</ButterLibVersion>
<UIExtenderExVersion>2.8.0</UIExtenderExVersion>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 5.8.2
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0,v1.2.1
* Added Preset Import/Export/Deleting
---------------------------------------------------------------------------------------------------
Version: 5.8.1
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0,v1.2.1
* Fixed missing Preset saving
Expand Down
3 changes: 2 additions & 1 deletion src/MCM.Abstractions/GameFeatures/IFileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ interface IFileSystemProvider
GameFile[] GetFiles(GameDirectory directory, string searchPattern);
GameFile? GetFile(GameDirectory directory, string fileName);
GameFile GetOrCreateFile(GameDirectory directory, string fileName);
bool WriteData(GameFile file, byte[] data);
bool WriteData(GameFile file, byte[]? data);
byte[]? ReadData(GameFile file);
string? GetSystemPath(GameFile file);
}
}
8 changes: 8 additions & 0 deletions src/MCM.Abstractions/Presets/JsonSettingsPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ private sealed class PresetContainer : PresetContainerDefinition
public BaseSettings? Settings { get; set; }
}

public static string? GetPresetId(string content)
{
var container = JsonConvert.DeserializeObject<PresetContainerDefinition?>(content);
if (container is null) return null;

return container.Id;
}

public static JsonSettingsPreset? FromFile(BaseSettings settings, GameFile file) => FromFile(settings.Id, file, settings.CreateNew);
public static JsonSettingsPreset? FromFile(string settingsId, GameFile file, Func<BaseSettings> getNewSettings)
{
Expand Down
12 changes: 11 additions & 1 deletion src/MCM.Bannerlord/GameFeatures/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ public GameFile GetOrCreateFile(GameDirectory directory, string fileName)
return new GameFile(directory, fileName);
}

public bool WriteData(GameFile file, byte[] data)
public bool WriteData(GameFile file, byte[]? data)
{
var baseFile = new TWPlatformFilePath(new TWPlatformDirectoryPath((PlatformFileType) file.Owner.Type, file.Owner.Path), file.Name);

if (data is null)
return PlatformFileHelper.DeleteFile(baseFile);

return PlatformFileHelper.SaveFile(baseFile, data) == SaveResult.Success;
}

Expand All @@ -75,5 +79,11 @@ public bool WriteData(GameFile file, byte[] data)
var baseFile = new TWPlatformFilePath(new TWPlatformDirectoryPath((PlatformFileType) file.Owner.Type, file.Owner.Path), file.Name);
return !PlatformFileHelper.FileExists(baseFile) ? null : PlatformFileHelper.GetFileContent(baseFile);
}

public string? GetSystemPath(GameFile file)
{
var baseFile = new TWPlatformFilePath(new TWPlatformDirectoryPath((PlatformFileType) file.Owner.Type, file.Owner.Path), file.Name);
return PlatformFileHelper.GetFileFullPath(baseFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@
<string id="ModOptionsVM_SaveAsPresetDesc" text="Choose the name of the preset"/>
<string id="ModOptionsVM_OverridePreset" text="Preset Already Exists"/>
<string id="ModOptionsVM_OverridePresetDesc" text="Preset already exists! Do you want to override it?"/>
<string id="ModOptionsVM_ManagePresets" text="Manage Presets"/>
<string id="ModOptionsVM_ManagePresetsImport" text="Import a new Preset"/>
<string id="ModOptionsVM_ManagePresetsExport" text="Export Preset '{PRESETNAME}'"/>
<string id="ModOptionsVM_ManagePresetsDelete" text="Delete Preset '{PRESETNAME}'"/>
</strings>
</base>
6 changes: 6 additions & 0 deletions src/MCM.UI/GUI/Brushes/SettingsBrush.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<Brushes>
<Brush Name="MCM.Settings" GlobalAlphaFactor="1">
<Layers>
<BrushLayer Name="Default" Sprite="StdAssets\plus_button" />
</Layers>
</Brush>

<Brush Name="MCM.Setting.Item">
<Layers>
<BrushLayer Name="Default" Sprite="mcm_entry" Color="#FFEBC1FF" />
Expand Down
23 changes: 5 additions & 18 deletions src/MCM.UI/GUI/Prefabs/ModOptionsPageView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
</Children>
</Widget>

<!-- Manage Presets -->
<ButtonWidget Id="ExtendButtonWidget" WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="40" SuggestedHeight="40" MarginLeft="10" MarginRight="30"
HorizontalAlignment="Right" VerticalAlignment="Center" Brush="MCM.Settings" Command.Click="ExecuteManagePresets" >
</ButtonWidget>

<!-- Title -->
<RichTextWidget WidthSizePolicy="StretchToParent" HeightSizePolicy="Fixed" SuggestedHeight="80" Brush="MCM.Title.Text"
Text="@SelectedDisplayName" HorizontalAlignment="Center" VerticalAlignment="Top"/>
Expand All @@ -98,24 +103,6 @@
</Children>
</ListPanel>

<!-- Preset Section -->
<ListPanel WidthSizePolicy="StretchToParent" HeightSizePolicy="Fixed" SuggestedHeight="80" LayoutImp.LayoutMethod="HorizontalLeftToRight"
HorizontalAlignment="Center" VerticalAlignment="Top" MarginBottom="-20" MarginTop="-30" >
<Children>

<!-- Save As Preset -->
<ButtonWidget SuggestedWidth="200" SuggestedHeight="64" HorizontalAlignment="Left" VerticalAlignment="Center"
MarginLeft="10" DoNotPassEventsToChildren="true" Brush="MCM.Cancel.Button" Command.Click="ExecuteSaveAsPreset"
IsVisible="@CanSaveAsPreset" >
<Children>
<TextWidget WidthSizePolicy="StretchToParent" HeightSizePolicy="StretchToParent" VerticalAlignment="Center" HorizontalAlignment="Center"
Text="@SaveAsPreset" Brush="MCM.Button.Text" />
</Children>
</ButtonWidget>

</Children>
</ListPanel>

<!-- Separator -->
<BrushWidget WidthSizePolicy="StretchToParent" HeightSizePolicy="Fixed" SuggestedHeight="2" VerticalAlignment="Top" Brush="MCM.Divider.Yellow" MarginLeft="15" MarginRight="15"/>

Expand Down
23 changes: 5 additions & 18 deletions src/MCM.UI/GUI/Prefabs/ModOptionsView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
</Children>
</Widget>

<!-- Manage Presets -->
<ButtonWidget Id="ExtendButtonWidget" WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="40" SuggestedHeight="40" MarginLeft="10" MarginRight="30"
HorizontalAlignment="Right" VerticalAlignment="Center" Brush="MCM.Settings" Command.Click="ExecuteManagePresets" >
</ButtonWidget>

<!-- Title -->
<RichTextWidget WidthSizePolicy="StretchToParent" HeightSizePolicy="Fixed" SuggestedHeight="80" Brush="MCM.Title.Text"
Text="@SelectedDisplayName" HorizontalAlignment="Center" VerticalAlignment="Top"/>
Expand All @@ -128,24 +133,6 @@
</Children>
</ListPanel>

<!-- Preset Section -->
<ListPanel WidthSizePolicy="StretchToParent" HeightSizePolicy="Fixed" SuggestedHeight="80" LayoutImp.LayoutMethod="HorizontalLeftToRight"
HorizontalAlignment="Center" VerticalAlignment="Top" MarginBottom="-20" MarginTop="-30" >
<Children>

<!-- Save As Preset -->
<ButtonWidget SuggestedWidth="200" SuggestedHeight="64" HorizontalAlignment="Left" VerticalAlignment="Center"
MarginLeft="10" DoNotPassEventsToChildren="true" Brush="MCM.Cancel.Button" Command.Click="ExecuteSaveAsPreset"
IsVisible="@CanSaveAsPreset" >
<Children>
<TextWidget WidthSizePolicy="StretchToParent" HeightSizePolicy="StretchToParent" VerticalAlignment="Center" HorizontalAlignment="Center"
Text="@SaveAsPreset" Brush="MCM.Button.Text" />
</Children>
</ButtonWidget>

</Children>
</ListPanel>

<!-- Separator -->
<BrushWidget WidthSizePolicy="StretchToParent" HeightSizePolicy="Fixed" SuggestedHeight="2" VerticalAlignment="Top" Brush="MCM.Divider.Yellow" MarginLeft="15" MarginRight="15"/>

Expand Down
Loading

0 comments on commit e42ab29

Please sign in to comment.