Skip to content

Commit

Permalink
fix right-click context menus
Browse files Browse the repository at this point in the history
  • Loading branch information
FluffierThanThou committed Aug 14, 2018
1 parent d542755 commit 0652cd3
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 71 deletions.
4 changes: 2 additions & 2 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>Blueprints</name>
<author>Fluffy</author>
<url>https://ludeon.com/forums/index.php?topic=16120.0</url>
<targetVersion>1.0.1970</targetVersion>
<targetVersion>0.19.1987</targetVersion>
<description>Blueprints allow the quick construction of repetitive rooms/areas.

&lt;size=24&gt;Features&lt;/size&gt;
Expand Down Expand Up @@ -35,7 +35,7 @@ Butter-Knife: Japanese translation
Kirill:

&lt;size=24&gt;Version&lt;/size&gt;
This is version 1.2.16, for RimWorld 1.0.1970.
This is version 1.2.21, for RimWorld 0.19.1987.

</description>
</ModMetaData>
Binary file modified Assemblies/Blueprints.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 @@ -48,4 +48,4 @@ Show your appreciation by buying me a coffee (or contribute towards a nice singl
[![Buy Me a Coffee](http://i.imgur.com/EjWiUwx.gif)](https://ko-fi.com/fluffymods)

# Version
This is version 1.2.16, for RimWorld 1.0.1970.
This is version 1.2.21, for RimWorld 0.19.1987.
3 changes: 0 additions & 3 deletions Source/Blueprints/Blueprint.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using Verse;

namespace Blueprints
Expand Down
2 changes: 1 addition & 1 deletion Source/Blueprints/Blueprints.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=1.0.6775.37815, Culture=neutral, PublicKeyToken=null">
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\dlls\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
Expand Down
4 changes: 4 additions & 0 deletions Source/Blueprints/BuildableInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public PlacementReport CanPlace(IntVec3 origin)
// get rotated cell position
var cell = origin + Position;

// if out of bounds, we clearly can't place it
if (!GenGrid.InBounds(cell, Find.CurrentMap))
return PlacementReport.CanNotPlace;

// if the designator's check passes, we can safely assume it's OK to build here
if (Designator.CanDesignateCell(cell).Accepted)
return PlacementReport.CanPlace;
Expand Down
69 changes: 31 additions & 38 deletions Source/Blueprints/Designator_Blueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Blueprints
{
[StaticConstructorOnStartup]
public class Designator_Blueprint : Designator
{
#region Fields
Expand Down Expand Up @@ -39,11 +38,41 @@ public Designator_Blueprint( Blueprint blueprint )
public Blueprint Blueprint => _blueprint;
public override int DraggableDimensions => 0;
public override string Label => _blueprint.name;
public override IEnumerable<FloatMenuOption> RightClickFloatMenuOptions
{
get
{
List<FloatMenuOption> options = new List<FloatMenuOption>();

// rename
options.Add(new FloatMenuOption("Fluffy.Blueprints.Rename".Translate(), delegate
{ Find.WindowStack.Add(new Dialog_NameBlueprint(this.Blueprint)); }));

// delete blueprint
options.Add(new FloatMenuOption("Fluffy.Blueprints.Remove".Translate(), delegate
{ Controller.Remove(this, false); }));

// delete blueprint and remove from disk
if (this.Blueprint.exported)
{
options.Add(new FloatMenuOption("Fluffy.Blueprints.RemoveAndDeleteXML".Translate(), delegate
{ Controller.Remove(this, true); }));
}

// store to xml
else
{
options.Add(new FloatMenuOption("Fluffy.Blueprints.SaveToXML".Translate(), delegate
{ Controller.SaveToXML(this.Blueprint); }));
}

return options;
}
}

#endregion Properties

#region Methods

public override AcceptanceReport CanDesignateCell( IntVec3 loc )
{
// always return true - we're looking at the larger blueprint in SelectedUpdate() and DesignateSingleCell() instead.
Expand Down Expand Up @@ -257,42 +286,6 @@ public override bool GroupsWith( Gizmo other )
return this.Blueprint == ( other as Designator_Blueprint ).Blueprint;
}

public override void ProcessInput( Event ev )
{
// float menu on right click
if ( ev.button == 1 )
{
List<FloatMenuOption> options = new List<FloatMenuOption>();

// rename
options.Add( new FloatMenuOption( "Fluffy.Blueprints.Rename".Translate(), delegate
{ Find.WindowStack.Add( new Dialog_NameBlueprint( this.Blueprint ) ); } ) );

// delete blueprint
options.Add( new FloatMenuOption( "Fluffy.Blueprints.Remove".Translate(), delegate
{ Controller.Remove( this, false ); } ) );

// delete blueprint and remove from disk
if ( this.Blueprint.exported )
{
options.Add( new FloatMenuOption( "Fluffy.Blueprints.RemoveAndDeleteXML".Translate(), delegate
{ Controller.Remove( this, true ); } ) );
}

// store to xml
else
{
options.Add( new FloatMenuOption( "Fluffy.Blueprints.SaveToXML".Translate(), delegate
{ Controller.SaveToXML( this.Blueprint ); } ) );
}

Find.WindowStack.Add( new FloatMenu( options ) );
return;
}

base.ProcessInput( ev );
}

public override void Selected()
{
base.Selected();
Expand Down
37 changes: 11 additions & 26 deletions Source/Blueprints/Designator_CreateBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using System.Linq;
using RimWorld;
using UnityEngine;
using Verse;

namespace Blueprints
Expand All @@ -14,16 +13,7 @@ public class Designator_CreateBlueprint : Designator

public Designator_CreateBlueprint()
{
// Silly A13+ workaround
LongEventHandler.ExecuteWhenFinished( delegate
{
Resources.Icon_AddBlueprint = ContentFinder<Texture2D>.Get( "Icons/AddBlueprint", true );
Resources.Icon_Blueprint = ContentFinder<Texture2D>.Get( "Icons/Blueprint", true );
Resources.Icon_Edit = ContentFinder<Texture2D>.Get( "Icons/Edit", true );

icon = Resources.Icon_AddBlueprint;
} );

// icon = Resources.Icon_AddBlueprint;
defaultLabel = "Fluffy.Blueprints.Create".Translate();
defaultDesc = "Fluffy.Blueprints.CreateHelp".Translate();
useMouseIcon = true;
Expand Down Expand Up @@ -57,28 +47,23 @@ public override void RenderHighlight( List<IntVec3> dragCells )
DesignatorUtility.RenderHighlightOverSelectableCells( this, dragCells);
}

public override void ProcessInput( Event ev )
{
if ( ev.button == 1 )
public override IEnumerable<FloatMenuOption> RightClickFloatMenuOptions {
get
{
var options = new List<FloatMenuOption>();

foreach ( var file in Controller.GetSavedFilesList() )
foreach (var file in Controller.GetSavedFilesList())
{
var name = Path.GetFileNameWithoutExtension( file.Name );
if ( Controller.FindBlueprint( name ) == null )
options.Add( new FloatMenuOption( "Fluffy.Blueprints.LoadFromXML".Translate( name ),
delegate { Controller.Add( Controller.LoadFromXML( file.Name ) ); } ) );
var name = Path.GetFileNameWithoutExtension(file.Name);
if (Controller.FindBlueprint(name) == null)
options.Add(new FloatMenuOption("Fluffy.Blueprints.LoadFromXML".Translate(name),
delegate { Controller.Add(Controller.LoadFromXML(file.Name)); }));
}

if ( options.NullOrEmpty() )
Messages.Message( "Fluffy.Blueprints.NoStoredBlueprints".Translate(), MessageTypeDefOf.RejectInput );
else
Find.WindowStack.Add( new FloatMenu( options ) );
return;
if (options.NullOrEmpty())
Messages.Message("Fluffy.Blueprints.NoStoredBlueprints".Translate(), MessageTypeDefOf.RejectInput);
return options;
}

base.ProcessInput( ev );
}

public override void DesignateMultiCell( IEnumerable<IntVec3> cells )
Expand Down
7 changes: 7 additions & 0 deletions Source/Blueprints/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public class Resources

#endregion Fields

static Resources()
{
Icon_AddBlueprint = ContentFinder<Texture2D>.Get("Icons/AddBlueprint", true);
Icon_Blueprint = ContentFinder<Texture2D>.Get("Icons/Blueprint", true);
Icon_Edit = ContentFinder<Texture2D>.Get("Icons/Edit", true);
}

#region Methods

public static IntVec3 CenterPosition( IntVec3 bottomLeft, IntVec2 size, Rot4 rotation )
Expand Down

0 comments on commit 0652cd3

Please sign in to comment.