Jibble

Author Topic: ENGINE PLUGIN: Clipboard v0.4  (Read 3319 times)

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
ENGINE PLUGIN: Clipboard v0.4
« on: 30 Mar 2018, 14:09 »
By popular demand: a plugin to support copy/paste, integrating with the Windows clipboard!
This plugin allows you to copy text from other applications and paste it into an AGS game, or vice versa.

The plugin provides two methods:

Code: Adventure Game Studio
  1. bool Clipboard.CopyText(String copyString);
  2. String Clipboard.PasteText();

Calling Clipboard.CopyText(copyString) will put copyString on the Windows clipboard (returning true if successful), accessible to other applications. Calling Clipboard.PasteText() returns the current text content of the Windows clipboard as a String (or null if none) that you can use in-game. Pretty simple.

As with all AGS engine plugins, you have to place the .dll file in the AGS engine folder, then activate it in the IDE from the project tree before you can use the methods. It should be unnecessary to state, but for the record: the game must be designed and created to use the plugin, you can't just drop it into the folder of a finished game and expect it to do anything.

This is my first AGS plugin, and my first C++ project in many years. It works on my machine, but I'm not 100% sure it will work on every Windows machine – in particular on older Windows versions. If you could try the demo and let me know if you experience any problems, I'd appreciate it.

The code is available on Github. (In the demo game, the example of how to use it is in TextField.HandleKeyPress(), starting on line 538.)

Download Clipboard plugin
Download Clipboard demo

Change log:
v0.4
-Initial release (untested except for on my own machine)
« Last Edit: 30 Mar 2018, 14:33 by Snarky »

Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #1 on: 30 Mar 2018, 15:05 »
I've just had a quick go with the demo and it works fine for me on Windows 10. :)

Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #2 on: 30 Mar 2018, 15:31 »
On Windows 7 it's working like a charm! Great work as usual Snarky!
Some extra notes aside: Should Ctrl+Z remove the previous paste text and Ctrl+Y add the latest text copied?

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #3 on: 30 Mar 2018, 15:41 »
I've just had a quick go with the demo and it works fine for me on Windows 10. :)
On Windows 7 it's working like a charm!

Good! I'm on Win10, so I thought that would probably work, but I'm very happy to hear it's working on Windows 7 as well. Hopefully that means that it's not terribly dependent on the Windows version. Thanks for testing!

Quote
Great work as usual Snarky!
Some extra notes aside: Should Ctrl+Z remove the previous paste text and Ctrl+Y add the latest text copied?

Thanks. Sure, undo/history would be useful to have, but it wouldn't be part of the plugin, but rather something you implement in your game logic. I'll think about adding it to the TextField module.

Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #4 on: 30 Mar 2018, 15:49 »
You are welcome Snarky!

Thanks. Sure, undo/history would be useful to have, but it wouldn't be part of the plugin, but rather something you implement in your game logic. I'll think about adding it to the TextField module.

In fact, I was thinking that it could be implemented in the TextField module as well instead of in the plugin itself after I had a look into the code on Github.

Gurok

  • Rottwheelers
  • When life hands you lemons, combine them with the mop
    • I can help with AGS tutoring
    • I can help with proof reading
    • I can help with scripting
    • Best Innovation Award Winner 2016, for improving and extending the AGS scripting language
    • Gurok worked on one or more games that won an AGS Award!
    •  
    • Gurok worked on one or more games that was nominated for an AGS Award!
Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #5 on: 31 Mar 2018, 01:05 »
Sorry if it wasn't clear, but I was talking about your TextField module. Give people a little credit, Snarky.

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #6 on: 31 Mar 2018, 06:59 »
Fair enough. I've moved your post over to the TextField module thread.

cat

  • Mittens Baronet
  • AGS Baker
    • cat worked on one or more games that won an AGS Award!
    •  
    • cat worked on one or more games that was nominated for an AGS Award!
Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #7 on: 08 May 2018, 20:52 »
A bite late, but I just saw this and ;-D

Dave Gilbert

  • Mittens Vassal
  • AGS Baker
  • Eye see you.
    • Lifetime Achievement Award Winner
    • Dave Gilbert worked on one or more games that won an AGS Award!
    •  
    • Dave Gilbert worked on one or more games that was nominated for an AGS Award!
Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #8 on: 09 May 2018, 11:43 »
This is SO COOL. And would have been super useful on my current project (no more copying debug info manually!). Will definitely use it in the future.

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #9 on: 13 Jul 2018, 08:25 »
Hmm. Testing it on a relatively untouched Win10 VM, this plugin turns out to have a dependency on some platform dll from Visual Studio that isn't universally deployed: probably (some version of) msvcp or msvcr. Without it, any game that includes the plugin will fail to run. I'll investigate more to identify the dependency and see if it can be bundled with the plugin.

Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #10 on: 30 Jun 2021, 08:10 »
Hi !

I found this nice plugin, but my question is : will it limits the possibilities to play my game using this plugin if the game is played on another OS than windows ?
I mean : MAC users or Linux users could play the game ? Or it will not run ?

The commands to copy/paste are not essential for the game, it's just a "luxure" for those who could use it (windows players, so).

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #11 on: 30 Jun 2021, 08:22 »
Yes, the plugin currently only works on Windows, and games compiled with it won't run on Mac/Linux. However, if you take a little bit of care, you can simply build it once for Windows, disable the plugin, and build it again for other platforms. For this to work, you should wrap all plugin calls within #ifdef CLIPBOARD_PLUGIN conditions, like so:

Code: Adventure Game Studio
  1.   #ifdef CLIPBOARD_PLUGIN
  2.     String s = Clipboard.PasteText();
  3.     if(!String.IsNullOrEmpty(s))
  4.     {
  5.       lblContent.Text = s;
  6.       return true;
  7.     }
  8.     else return false;
  9.   #endif
  10.   #ifndef CLIPBOARD_PLUGIN
  11.     return false;
  12.   #endif
  13.  

Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #12 on: 30 Jun 2021, 18:18 »
Thanks Snarky for the help !

Could you please explain me how to install your plugin in AGS, so ? I use 3.5.0

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: ENGINE PLUGIN: Clipboard v0.4
« Reply #13 on: 01 Jul 2021, 20:12 »
Check out the manual, "Other features | Plugins."