Skip to content

Commit

Permalink
add toggle for opening architect, hide disallowed commands from recen…
Browse files Browse the repository at this point in the history
…t list, set default scale to 100%
  • Loading branch information
FluffierThanThou committed Apr 25, 2020
1 parent d8449fd commit 85d97dc
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 60 deletions.
4 changes: 3 additions & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Recently used commands will be immediately shown. Type a few letters to show com
None

<size=24>Version</size>
This is version 1.2.48, for RimWorld 1.1.2610.
This is version 1.2.52, for RimWorld 1.1.2610.

</description>
<url>https://steamcommunity.com/id/Fluffy/myworkshopfiles/?appid=294100</url>
Expand All @@ -37,5 +37,7 @@ This is version 1.2.48, for RimWorld 1.1.2610.
</modDependencies>
<loadAfter>
<li>brrainz.harmony</li>
<li>ludeon.rimworld</li>
<li>ludeon.rimworld.royalty</li>
</loadAfter>
</ModMetaData>
Binary file modified About/Preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 11 additions & 13 deletions About/dependencies.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"depends": [
{
"id": "brrainz.harmony",
"name": "Harmony",
"steam": 2009463077,
"url": "https://github.com/pardeike/HarmonyRimWorld/releases/latest"
}
],
"after": [
"brrainz.harmony"
]
}
{
"depends": [
{
"id": "brrainz.harmony",
"name": "Harmony",
"steam": 2009463077,
"url": "https://github.com/pardeike/HarmonyRimWorld/releases/latest"
}
],
"after": ["brrainz.harmony", "ludeon.rimworld", "ludeon.rimworld.royalty"]
}
Binary file modified Assemblies/CommandPalette.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ Show your appreciation by buying me a coffee (or contribute towards a nice singl
[![I Have a Black Dog](https://i.ibb.co/ss59Rwy/New-Project-2.png)](https://www.youtube.com/watch?v=XiCrniLQGYc)

# Version
This is version 1.2.48, for RimWorld 1.1.2610.
This is version 1.2.52, for RimWorld 1.1.2610.
14 changes: 3 additions & 11 deletions Source/ModConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@
"version": {
"major": 1,
"minor": 2,
"build": 48
"build": 52
},
"git_user": "fluffy-mods",
"git_repo": "CommandPalette",
"visibility": 0,
"packageId": "fluffy.commandpalette",
"changenote": "2020-04-25 :: Fluffy :: update desciption, fix nullref in equality comparer",
"changenotes": [
{
"repo": "CommandPalette",
"hash": "a345bfd96f59f765d57de86154f0ee2d8c02e0b2",
"date": "2020-04-25",
"author": "Fluffy",
"message": "update desciption, fix nullref in equality comparer"
}
],
"changenote": "",
"changenotes": [],
"contributors": {},
"tags": [
"1.1"
Expand Down
70 changes: 39 additions & 31 deletions Source/PaletteWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,38 @@

namespace CommandPalette
{
public class PaletteWindow: GameComponent
public class PaletteWindow : GameComponent
{
public static PaletteWindow Get { get; protected set; }

public PaletteWindow( Game game )
{
Get = this;
}

private Vector2 position;
private bool active;
private bool setFocus;
private bool active;
private bool setFocus;

private static string _query = "";

protected static string query
{
get => _query;
set
{
_query = value;
_query = value;
_filteredDesignators = null;
}
}

private const int WIDTH = GIZMO_SIZE * 4 + MARGIN * 3;
private const int MARGIN = 6;
private const int SEARCH_HEIGHT = 50;
private const int GIZMO_SIZE = 75;
private const int WIDTH = GIZMO_SIZE * 4 + MARGIN * 3;
private const int MARGIN = 6;
private const int SEARCH_HEIGHT = 50;
private const int GIZMO_SIZE = 75;
private const int PALETTE_HEIGHT = GIZMO_SIZE * 2 + MARGIN;

private const int FADE_OUT_START_DISTANCE = 10;
private const int FADE_OUT_START_DISTANCE = 10;
private const int FADE_OUT_FINISH_DISTANCE = 200;

private static List<Designator> _allDesignators;
Expand All @@ -54,7 +56,8 @@ public static List<Designator> AllDesignators
get
{
_allDesignators??=DefDatabase<DesignationCategoryDef>.AllDefsListForReading
.SelectMany( dcd => dcd.ResolvedAllowedDesignators )
.SelectMany(
dcd => dcd.ResolvedAllowedDesignators )
.Distinct( new DesignatorEqualityComparer() )
.ToList();
return _allDesignators;
Expand All @@ -63,7 +66,8 @@ public static List<Designator> AllDesignators

private static Dictionary<Designator, ArchitectCategoryTab> _designatorsByCategory;

private static FieldInfo _architectCategoryTabFieldInfo = AccessTools.Field( typeof( MainTabWindow_Architect ), "desPanelsCached" );
private static FieldInfo _architectCategoryTabFieldInfo =
AccessTools.Field( typeof( MainTabWindow_Architect ), "desPanelsCached" );

public static Dictionary<Designator, ArchitectCategoryTab> DesignatorsByCategory
{
Expand All @@ -72,7 +76,7 @@ public static Dictionary<Designator, ArchitectCategoryTab> DesignatorsByCategory
if ( _designatorsByCategory == null )
{
var categories = _architectCategoryTabFieldInfo
.GetValue( MainButtonDefOf.Architect.TabWindow )
.GetValue( MainButtonDefOf.Architect.TabWindow )
as List<ArchitectCategoryTab>;
_designatorsByCategory = DefDatabase<DesignationCategoryDef>.AllDefsListForReading.SelectMany(
catDef =>
Expand Down Expand Up @@ -103,12 +107,14 @@ public static IEnumerable<Designator> FilteredDesignators
}
}

public static HistoryList<Designator> RecentlyUsed = new HistoryList<Designator>( 10 );
private static HistoryList<Designator> _recentlyUsed = new HistoryList<Designator>( 10 );
public static IEnumerable<Designator> VisibleRecentlyUsed => _recentlyUsed.Where( d => d.Visible );

public static float Similarity( Designator des )
{
var name = Similarity( des.Label, query );
if ( des.Label.ToUpperInvariant().Contains( query.ToUpperInvariant() ) ) name *= 3f; // give exact (partial) name matches a much higher weight
if ( des.Label.ToUpperInvariant().Contains( query.ToUpperInvariant() ) )
name *= 3f; // give exact (partial) name matches a much higher weight
var desc = Similarity( des.Desc, query );
return Mathf.Max( name, desc );
}
Expand All @@ -117,7 +123,7 @@ public static float Similarity( string a, string b )
{
if ( a.NullOrEmpty() || b.NullOrEmpty() )
return 0;
var C = Math.Max( a.Length, b.Length );
var C = Math.Max( a.Length, b.Length );
var distance = Levenshtein.CalculateDistance( a, b, 1 );
return 1 - distance / (float) C;
}
Expand All @@ -130,8 +136,9 @@ public void HandleShortcuts()
Event.current.button == 1 && !WorldRendererUtility.WorldRenderedNow )
{
Event.current.Use();
position = Utilities.MousePositionOnUIScaledBeforeScaling - new Vector2( GIZMO_SIZE / 2f, SEARCH_HEIGHT );
active = true;
position = Utilities.MousePositionOnUIScaledBeforeScaling -
new Vector2( GIZMO_SIZE / 2f, SEARCH_HEIGHT );
active = true;
setFocus = true;
}
}
Expand All @@ -151,9 +158,9 @@ public override void GameComponentOnGUI()
Cancel();
return;
}

GUI.color = new Color( 1f, 1f, 1f, 1 - fade );
var searchCanvas = new Rect( canvas.xMin, canvas.yMin, WIDTH, SEARCH_HEIGHT );
var searchCanvas = new Rect( canvas.xMin, canvas.yMin, WIDTH, SEARCH_HEIGHT );
var paletteCanvas = new Rect( canvas.xMin, searchCanvas.yMax + MARGIN, WIDTH, PALETTE_HEIGHT );
DoSearch( searchCanvas );
DoPalette( paletteCanvas, fade );
Expand All @@ -164,9 +171,9 @@ public override void GameComponentOnGUI()

public void Cancel()
{
active = false;
position = Vector2.zero;
query = "";
active = false;
position = Vector2.zero;
query = "";
GUI.color = Color.white;
}

Expand All @@ -193,14 +200,14 @@ public void DoSearch( Rect canvas )

public void DoPalette( Rect canvas, float fade )
{
var pos = canvas.min;
var fadeColor = new Color( 1f, 1f, 1f, 1 - fade );
var designators = query.NullOrEmpty() ? RecentlyUsed : FilteredDesignators;
var pos = canvas.min;
var fadeColor = new Color( 1f, 1f, 1f, 1 - fade );
var designators = query.NullOrEmpty() ? VisibleRecentlyUsed : FilteredDesignators;
foreach ( var designator in designators )
{
if ( pos.x + GIZMO_SIZE > canvas.xMax )
{
pos.x = canvas.xMin;
pos.x = canvas.xMin;
pos.y += GIZMO_SIZE + MARGIN;
}

Expand All @@ -209,10 +216,10 @@ public void DoPalette( Rect canvas, float fade )

var iconColor = designator.defaultIconColor;
designator.defaultIconColor = fadeColor;
GUI.color = fadeColor;
GUI.color = fadeColor;
var result = designator.GizmoOnGUI( pos, GIZMO_SIZE );
designator.defaultIconColor = iconColor;
pos.x += GIZMO_SIZE + MARGIN;
designator.defaultIconColor = iconColor;
pos.x += GIZMO_SIZE + MARGIN;
switch ( result.State )
{
case GizmoState.Interacted:
Expand All @@ -229,10 +236,11 @@ public void DoPalette( Rect canvas, float fade )
public void Select( Designator designator, GizmoResult result )
{
Find.MainTabsRoot.SetCurrentTab( MainButtonDefOf.Architect, false );
if ( MainButtonDefOf.Architect.TabWindow is MainTabWindow_Architect architectTab
if ( CommandPalette.Settings.OpenArchitect
&& MainButtonDefOf.Architect.TabWindow is MainTabWindow_Architect architectTab
&& DesignatorsByCategory.TryGetValue( designator, out ArchitectCategoryTab tab ) )
architectTab.selectedDesPanel = tab;
RecentlyUsed.Add( designator );
_recentlyUsed.Add( designator );
designator.ProcessInput( result.InteractEvent );
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.2.48")]
[assembly: AssemblyFileVersion("1.2.52")]
9 changes: 7 additions & 2 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ namespace CommandPalette
{
public class Settings : ModSettings
{
public float PaletteScale = 2 / 3f;
public float PaletteScale = 1f;
public bool OpenArchitect = true;

public void DoWindowContents(Rect canvas)
{
var options = new Listing_Standard();
options.Begin(canvas);
options.Label( $"Palette scale, lower means smaller buttons ({PaletteScale:P0})" );
PaletteScale = options.Slider( PaletteScale, 1/3f, 1 );
options.CheckboxLabeled( "Open Architect window when selecting command", ref OpenArchitect,
"If enabled, when selecting a command in the command palette, the corresponding tab is opened in the Architect menu." );
options.End();
}

public override void ExposeData()
{
base.ExposeData();

Scribe_Values.Look( ref PaletteScale, "paletteScale", 2 / 3f );
Scribe_Values.Look( ref PaletteScale, "paletteScale", 1f );
Scribe_Values.Look( ref OpenArchitect, "openArchitect", true );
}
}
}

0 comments on commit 85d97dc

Please sign in to comment.