Skip to content

Commit

Permalink
complete core functionality (create/rename/delete)
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorVanGogh committed Sep 17, 2017
1 parent b5e259b commit 4b242a6
Show file tree
Hide file tree
Showing 19 changed files with 406 additions and 27 deletions.
Binary file modified Assemblies/ModSwitch.dll
Binary file not shown.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

# ModSwitch

_A Rimworld mod manager *(in the making)*_
_A Rimworld mod manager_

## Powered by ![Harmony](https://github.com/pardeike/Harmony)
Allows you to save and switch between sets of active mods with one click.

Supports importing your sets from ModListBackup.

## Third party acknowledgements

### Uses ![Open Iconic](www.useiconic.com/open)

Open Iconic is lisenced under a [MIT license](http://opensource.org/licenses/MIT).

### Powered by ![Harmony](https://github.com/pardeike/Harmony)

<p align="center">
<img alt="Powered by Harmony" src="https://camo.githubusercontent.com/074bf079275fa90809f51b74e9dd0deccc70328f/68747470733a2f2f7332342e706f7374696d672e6f72672f3538626c31727a33392f6c6f676f2e706e67" />
Expand Down
7 changes: 7 additions & 0 deletions Source/ModSwitch/ModSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using Verse;

namespace DoctorVanGogh.ModSwitch {

class ModSwitch : Mod {

private Settings _settings;

public ModSwitch(ModContentPack content) : base(content) {
Expand All @@ -30,5 +32,10 @@ public override void DoSettingsWindowContents(Rect inRect) {
public void DoModsConfigWindowContents(Rect bottom) {
_settings.DoModsConfigWindowContents(bottom);
}

public void DeleteSet(ModSet modSet) {
if (_settings.Sets.Remove(modSet))
WriteSettings();
}
}
}
7 changes: 6 additions & 1 deletion Source/ModSwitch/ModSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Model\ModAttributes.cs" />
<Compile Include="Model\ModSet.cs" />
<Compile Include="ModSwitch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Util.cs" />
<Compile Include="[UI]\Assets.cs" />
<Compile Include="[UI]\Dialog_SetText.cs" />
<Compile Include="[Util]\Util.cs" />
<Compile Include="[Patches]\Patches.cs" />
<Compile Include="[Util]\Linq.cs" />
<Compile Include="[Util]\Widgets.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
4 changes: 3 additions & 1 deletion Source/ModSwitch/ModSwitch.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=model/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=_005Bpatches_005D/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=_005Bpatches_005D/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=_005Bui_005D/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=_005Butil_005D/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
32 changes: 32 additions & 0 deletions Source/ModSwitch/Model/ModAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Security.Policy;
using UnityEngine;
using Verse;

namespace DoctorVanGogh.ModSwitch {

class ModAttributes : IExposable {
public string Key = String.Empty;

public List<IExposable> attributes = new List<IExposable>();

public void ExposeData() {
Scribe_Values.Look(ref Key, "key");
Scribe_Collections.Look(ref attributes, false, "attributes");
}
}

class MLBAttributes : IExposable {

public Color color = Color.white;
public string altName = String.Empty;
public string installName = String.Empty;

public void ExposeData() {
Scribe_Values.Look(ref color, "color");
Scribe_Values.Look(ref altName, "altName");
Scribe_Values.Look(ref installName, "installName");
}
}
}
68 changes: 65 additions & 3 deletions Source/ModSwitch/Model/ModSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,37 @@ class ModSet : IExposable {

private static readonly FieldInfo fiModsConfig_data;
private static readonly FieldInfo fiModsConfigData_activeMods;
private static readonly FieldInfo fiModsConfigData_buildNumber;

static ModSet() {
var tModsConfig = typeof(ModsConfig);
var tModsConfigData = AccessTools.Inner(tModsConfig, "ModsConfigData");
fiModsConfigData_activeMods = AccessTools.Field(tModsConfigData, "activeMods");
fiModsConfigData_buildNumber = AccessTools.Field(tModsConfigData, "buildNumber");
fiModsConfig_data = AccessTools.Field(tModsConfig, "data");

TipRename = new TipSignal("Rename");
TipDelete = new TipSignal("Delete");

}

public List<string> Mods = new List<string>();
public static TipSignal TipDelete { get; set; }

public static TipSignal TipRename { get; set; }

public List<string> Mods = new List<string>();
public int BuildNumber = -1;
public string Name = String.Empty;
public bool AutoGenerated = false;


private TipSignal? _tip;

public void ExposeData() {
Scribe_Collections.Look(ref Mods, false, "mods");
Scribe_Values.Look(ref Name, "name");
Scribe_Values.Look(ref BuildNumber, "buildNumber");
Scribe_Values.Look(ref AutoGenerated, "autoGenerated", false);
}

private TipSignal Tip {
Expand All @@ -40,8 +55,45 @@ public override string ToString() {
}

public void DoWindowContents(Rect rect) {
GUI.Label(rect, Name);
TooltipHandler.TipRegion(rect, Tip);
const float padding = 2f;
var height = rect.height;
var buttonSize = height - 2 * padding;

var leftColumnsWidth = rect.width - 8*padding - 2*buttonSize;

var left = new Rect(rect.x, rect.y +padding, leftColumnsWidth * 0.6f -padding, buttonSize);
Widgets.Label(left, Name);

var right = new Rect(rect.x + leftColumnsWidth*0.6f + 3*padding, rect.y + padding, leftColumnsWidth*0.4f, buttonSize);
Widgets.Label(right, $"{Mods.Count} items");
TooltipHandler.TipRegion(right, Tip);

var rctRename = new Rect(rect.x + leftColumnsWidth + 5*padding, rect.y + padding, buttonSize, buttonSize);

if (ExtraWidgets.ButtonImage(rctRename, Assets.Edit, false, TipRename, rctRename.ContractedBy(4))) {
Find.WindowStack.Add(
new Dialog_SetText(
s => {
Name = s;
LoadedModManager.GetMod<ModSwitch>().WriteSettings();
},
Name)
);
}

var rctDelete = new Rect(rect.x + leftColumnsWidth + 7*padding + buttonSize, rect.y + padding, buttonSize, buttonSize);


if (ExtraWidgets.ButtonImage(rctDelete, Assets.Delete, false, TipDelete, rctDelete.ContractedBy(4))) {
Find.WindowStack.Add(
Dialog_MessageBox.CreateConfirmation(
$"Really delete '{Name}'?",
() => {
LoadedModManager.GetMod<ModSwitch>().DeleteSet(this);
},
true,
"Confirmation needed"));
}
}

public void Apply() {
Expand Down Expand Up @@ -69,5 +121,15 @@ public void Apply() {
Find.WindowStack.Add(new Dialog_MessageBox(sb.ToString(), title: "Missing mods"));
}
}

public static ModSet FromCurrent(string name) {
object modsConfigData = fiModsConfig_data.GetValue(null);

return new ModSet {
Name = name,
BuildNumber = (int) fiModsConfigData_buildNumber.GetValue(modsConfigData),
Mods = new List<string>((IEnumerable<string>) fiModsConfigData_activeMods.GetValue(modsConfigData))
};
}
}
}
4 changes: 2 additions & 2 deletions Source/ModSwitch/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.1.0")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyVersion("0.0.2.0")]
[assembly: AssemblyFileVersion("0.0.2.0")]
Loading

0 comments on commit 4b242a6

Please sign in to comment.