Skip to content

Commit

Permalink
ctrl XCV cut copy paste dragged objects, change desc of kill/revive i…
Browse files Browse the repository at this point in the history
…n options
  • Loading branch information
woutkolkman committed Sep 6, 2023
1 parent 4e4f402 commit 3045f3f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
16 changes: 16 additions & 0 deletions MouseDrag/Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ static void RainWorldGameRawUpdateHook(On.RainWorldGame.orig_RawUpdate orig, Rai
if (Options.duplicateOneKey?.Value != null && Input.GetKeyDown(Options.duplicateOneKey.Value))
Duplicate.DuplicateObject();

if (Options.clipboardCtrlXCV?.Value == true) {
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) {
if (Input.GetKeyDown(KeyCode.X))
Clipboard.CutObject();
if (Input.GetKeyDown(KeyCode.C))
Clipboard.CopyObject();
if (Input.GetKeyDown(KeyCode.V) && self.cameras[0]?.room != null) {
Clipboard.PasteObject(
self,
self.cameras[0].room,
self.cameras[0].room.ToWorldCoordinate((Vector2)Futile.mousePosition + self.cameras[0].pos)
);
}
}
}

if (Options.tameOneKey?.Value != null && Input.GetKeyDown(Options.tameOneKey.Value))
Tame.TameCreature(self);

Expand Down
12 changes: 7 additions & 5 deletions MouseDrag/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Options : OptionInterface
public static Configurable<bool> pauseAllCreaturesMenu, pauseAllObjectsMenu;
public static Configurable<bool> killOneMenu, killAllCreaturesMenu, reviveOneMenu, reviveAllCreaturesMenu;
public static Configurable<bool> duplicateOneMenu;
public static Configurable<bool> clipboardMenu;
public static Configurable<bool> clipboardMenu, clipboardCtrlXCV;
public static Configurable<bool> tameOneMenu, tameAllCreaturesMenu, clearRelOneMenu, clearRelAllMenu;
public static Configurable<bool> stunOneMenu, stunRoomMenu, unstunAllMenu, stunAllMenu;
public static Configurable<bool> destroyOneMenu, destroyAllCreaturesMenu, destroyAllObjectsMenu;
Expand Down Expand Up @@ -68,9 +68,9 @@ public Options()
unpauseAllKey = config.Bind("unpauseAllKey", KeyCode.None, new ConfigurableInfo("KeyBind to unpause all objects/creatures, including individually paused creatures.", null, "", "Unpause all"));
pauseAllCreaturesKey = config.Bind("pauseAllCreaturesKey", KeyCode.None, new ConfigurableInfo("KeyBind to pause/unpause all creatures except Player and SlugNPC, including creatures that still need to spawn.\nIndividually (un)paused creatures remain paused.", null, "", "Pause all creatures"));
pauseAllObjectsKey = config.Bind("pauseAllObjectsKey", KeyCode.None, new ConfigurableInfo("KeyBind to pause/unpause all objects except creatures, including objects that still need to spawn.\nIndividually (un)paused objects remain paused.", null, "", "Pause all objects"));
killOneKey = config.Bind("killOneKey", KeyCode.None, new ConfigurableInfo("KeyBind to kill the creature which you're currently dragging.", null, "", "Kill"));
killOneKey = config.Bind("killOneKey", KeyCode.None, new ConfigurableInfo("KeyBind to kill the creature which you're currently dragging. Can also trigger objects like bombs.", null, "", "Kill"));
killAllCreaturesKey = config.Bind("killAllCreaturesKey", KeyCode.None, new ConfigurableInfo("KeyBind to kill all creatures in current room except Player and SlugNPC.", null, "", "Kill creatures\nin room"));
reviveOneKey = config.Bind("reviveOneKey", KeyCode.None, new ConfigurableInfo("KeyBind to revive and heal the creature which you're currently dragging.", null, "", "Revive/heal"));
reviveOneKey = config.Bind("reviveOneKey", KeyCode.None, new ConfigurableInfo("KeyBind to revive and heal the creature which you're currently dragging. Can also reset objects like popcorn plants.", null, "", "Revive/heal"));
reviveAllCreaturesKey = config.Bind("reviveAllCreaturesKey", KeyCode.None, new ConfigurableInfo("KeyBind to revive and heal all creatures in current room.", null, "", "Revive/heal\ncreatures\nin room"));
duplicateOneKey = config.Bind("duplicateOneKey", KeyCode.None, new ConfigurableInfo("KeyBind to duplicate the object/creature which you're currently dragging. Hold button to repeat.", null, "", "Duplicate"));

Expand All @@ -97,6 +97,7 @@ public Options()
reviveAllCreaturesMenu = config.Bind("reviveAllCreaturesMenu", defaultValue: true, new ConfigurableInfo("Add action to menu.", null, "", ""));
duplicateOneMenu = config.Bind("duplicateOneMenu", defaultValue: true, new ConfigurableInfo("Add action to menu.", null, "", ""));
clipboardMenu = config.Bind("clipboardMenu", defaultValue: false, new ConfigurableInfo("Add action to menu.\nCut/paste AbstractPhysicalObjects with a clipboard (LIFO buffer). Clipboard is lost when game is closed.", null, "", ""));
clipboardCtrlXCV = config.Bind("clipboardCtrlXCV", defaultValue: false, new ConfigurableInfo("Using Control + X/C/V will cut, copy or paste the object/creature which you're currently dragging.", null, "", "Ctrl + X/C/V"));

tameOneMenu = config.Bind("tameOneMenu", defaultValue: true, new ConfigurableInfo("Add action to menu.", null, "", ""));
tameAllCreaturesMenu = config.Bind("tameAllCreaturesMenu", defaultValue: false, new ConfigurableInfo("Add action to menu.", null, "", ""));
Expand Down Expand Up @@ -156,7 +157,7 @@ public override void Initialize()
curTab++;
x = 70;
y = 600f;
AddKeyBinder(menuOpen, new Vector2(x, y -= 50f));
AddKeyBinder(menuOpen, new Vector2(x, y -= 40f));
AddKeyBinder(pauseOneKey, new Vector2(x, y -= 50f));
AddIcon(new Vector2(x - 25f, y + 6f), "mousedragPause");
AddCheckbox(pauseOneMenu, new Vector2(x - 56f, y + 3f));
Expand Down Expand Up @@ -190,10 +191,11 @@ public override void Initialize()
AddCheckbox(clipboardMenu, new Vector2(x - 56f, (y -= 50f) + 3f));
AddIcon(new Vector2(x - 25f, y + 6f), "mousedragCut");
AddIcon(new Vector2(x, y + 6f), "mousedragPaste");
AddCheckbox(clipboardCtrlXCV, new Vector2(x + 25f, y + 3f));

x += 300;
y = 600f;
AddKeyBinder(tameOneKey, new Vector2(x, y -= 50f));
AddKeyBinder(tameOneKey, new Vector2(x, y -= 40f));
AddIcon(new Vector2(x - 25f, y + 6f), "mousedragHeart");
AddCheckbox(tameOneMenu, new Vector2(x - 56f, y + 3f));
AddKeyBinder(tameAllCreaturesKey, new Vector2(x, y -= 50f));
Expand Down
7 changes: 7 additions & 0 deletions MouseDrag/Tools/Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public static void CutObject(PhysicalObject obj = null)
}


public static void CopyObject(PhysicalObject obj = null)
{
PhysicalObject dup = Duplicate.DuplicateObject(obj);
CutObject(dup);
}


public static void PasteObject(RainWorldGame game, Room room, WorldCoordinate pos)
{
if (room?.world == null || room?.abstractRoom == null || game == null)
Expand Down
9 changes: 5 additions & 4 deletions MouseDrag/Tools/Duplicate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ namespace MouseDrag
{
public static class Duplicate
{
public static void DuplicateObject(PhysicalObject obj = null)
public static PhysicalObject DuplicateObject(PhysicalObject obj = null)
{
if (obj == null)
obj = Drag.dragChunk?.owner;
if (obj?.room?.abstractRoom == null || obj.room.game == null)
return;
return null;

WorldCoordinate coord = obj.room.GetWorldCoordinate(obj.firstChunk?.pos ?? new Vector2());
AbstractPhysicalObject oldApo = obj?.abstractPhysicalObject ?? (obj as Creature)?.abstractCreature;
AbstractPhysicalObject newApo = null;

if (oldApo == null)
return;
return null;

if (obj is Creature) {
EntityID id = Options.copyID?.Value == false ? obj.room.game.GetNewID() : oldApo.ID;
Expand Down Expand Up @@ -50,7 +50,7 @@ public static void DuplicateObject(PhysicalObject obj = null)

} catch (Exception ex) {
Plugin.Logger.LogWarning("DuplicateObject exception: " + ex.ToString());
return;
return null;
}
newApo.pos = coord;
}
Expand All @@ -59,6 +59,7 @@ public static void DuplicateObject(PhysicalObject obj = null)
Plugin.Logger.LogDebug("DuplicateObject, AddEntity " + newApo.type + " at " + coord.SaveToString());
obj.room.abstractRoom.AddEntity(newApo);
newApo.RealizeInRoom(); //actually places object/creature
return newApo.realizedObject;
}


Expand Down
Binary file modified MouseDrag/bin/mousedrag/plugins/MouseDrag.dll
Binary file not shown.

0 comments on commit 3045f3f

Please sign in to comment.