MODULE: DragDrop 1.1.0: helps to drag things around your AGS game!

Started by Crimson Wizard, Mon 14/03/2016 00:09:54

Previous topic - Next topic

Amir

The module works as in the video with AGS engine Android port (the app). Not quite drag and drop ;-D  by pressing and holding an inventory item, but I like it that way. It's practical too. I made the mouse cursor transparent so that it looks like it does on smartphones or iPads.



Quote from: eri0o on Thu 01/07/2021 19:22:32
WoaM and Kathy Rain use a different code that works with the old android port - I actually have the script code because I asked by mail the dev, but I think you should just ask them yourself. If you want to use this module and use the same behavior for mouse and fingers, you need to use the Android SDL Port.

I have a little game that uses this module too here: https://github.com/ericoporto/dungeonhands

It has touch on the webport, but I don't know how well it runs on old devices. :/

What do you mean exactly by Android SDL Port? Do you mean by creating an APK with monkeys plugin or your way with Android Studio? I wanted to try that anyway.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Updated DragDropCommon module to 1.0.1, fixing default settings, to avoid people stumbling into a missing GUI crash if they forgot to explicitly set a drag mode.

Amir

Quote from: Crimson Wizard on Sun 18/07/2021 22:11:28
Updated DragDropCommon module to 1.0.1, fixing default settings, to avoid people stumbling into a missing GUI crash if they forgot to explicitly set a drag mode.

Thank u.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

deadsuperhero

This is an amazing module, but I'm absolutely confused by the examples and the reference. Please do not take my following comments as hostile or critical - I have nothing but praise for what you're doing. What's confusing for me is this: the module does a fabulous job when the automation is turned on...but I'm having a very hard time grasping how to do the behavior without automation.

In a nutshell, what I'm trying to do is make draggable GUIs to create a fake desktop. However, I only want to target a specific handful of game GUIs, not all of them. If I have DragDrop.AutoTrackHookKey set to true in my script, every game GUI is draggable in the way that I expect...except, this works with every GUI in the game, not just some of them.

I've tried to follow the examples and use a little scripting to get it to work, but I'm stuck. Here's what I've managed to do so far:

Global Script:
Code: ags


function dragWindow(GUI* Window) { // This is wrong
  if (DragDrop.HookKeyDown()){
    DragDrop.HookObject(1, mouse.x, mouse.y, Window.ID);
  }
  else if (DragDrop.HookKeyUp())
    DragDrop.Drop();{
  }
}


function checkGUI() // running under repeatedly_execute_always{
  if (GUI.GetAtScreenXY(mouse.x, mouse.y)) {
    hoverOver = GUI.GetAtScreenXY(mouse.x, mouse.y);
      if ((hoverOver == gConfirmation)) {
        dragWindow(hoverOver);
      }
  }
  else {
    hoverOver = null;
  }
}



function game_start()
{
  Mouse.Mode = eModePointer;
  DragDrop.Enabled = true;
  DragDropCommon.ModeEnabled[eDragDropGUI] = true;
  DragDropCommon.DragMove = eDDCmnMoveSelf;
  DragDrop.AutoTrackHookKey = false;
  DragDrop.DefaultHookKey = 0;
  DragDrop.DefaultHookMouseButton = eMouseLeft;
  DragDrop.DragMinDistance = 10;
  DragDrop.DragMinTime = 0;
}




I've tried a few different variations for my dragGUI function. If I include the DragDrop.Drop() call, dragging doesn't work at all. If I omit it, the window instead just sticks to my cursor the minute I hover over it.
I've tried going over your code examples and post a couple of times, but I'm feeling pretty lost. What's the proper order of operations for hooking a GUI, dragging it, and dropping it?


I guess what's also confusing involves figuring out how to register when the player is holding down the mouse button and dragging the mouse. Is HookKeyDown supposed to be called from within on_mouse_click / on_key_press and nowhere else?
The fediverse needs great indie game developers! Find me there!

deadsuperhero

I ended up doing a dirty hack for the time being, but I hope to sit down and adapt it properly at some point. :)

Code: ags

function checkGUI() {
  if (GUI.GetAtScreenXY(mouse.x, mouse.y)) {
    hoverOver = GUI.GetAtScreenXY(mouse.x, mouse.y);
      if ((hoverOver == gExplorer)) {
        DragDrop.AutoTrackHookKey = true;
      }
      else if ((hoverOver == gDetails)) {
        DragDrop.AutoTrackHookKey = true;
      }
      else if ((hoverOver == gResume)) {
        DragDrop.AutoTrackHookKey = true;
      }
      else if ((hoverOver == gConfirmation)) {
       DragDrop.AutoTrackHookKey = true;
      }
      else if ((hoverOver == gDropdown)) {
       DragDrop.AutoTrackHookKey = false;
      }
      else if ((hoverOver == gMainMenu)) {
       DragDrop.AutoTrackHookKey = false;
      }
  }
  else {
    hoverOver = null;
    DragDrop.AutoTrackHookKey = false;
  }
}


Hacky, but it works for now.
The fediverse needs great indie game developers! Find me there!

Crimson Wizard

I'm sorry, I did not have time to look into this yet, and I definitely should have written a better documentation.

Quote from: deadsuperhero on Fri 07/01/2022 22:16:37
I ended up doing a dirty hack for the time being, but I hope to sit down and adapt it properly at some point. :)

Just as a note, you may use switch for simplier code:
Code: ags

switch (hoverOver)
{
case gDetails:
case gResume:
// etc
    DragDrop.AutoTrackHookKey = true;
    break;
default:
    DragDrop.AutoTrackHookKey = false;
    break;
}

deadsuperhero

Quote from: Crimson Wizard on Sat 08/01/2022 06:46:31
I'm sorry, I did not have time to look into this yet, and I definitely should have written a better documentation.
Hey, it's totally okay - again, I appreciate what you've made, and am getting great use out of it!

That switch example is nice - I didn't even know about those!
The fediverse needs great indie game developers! Find me there!

Crimson Wizard

Updated DragDrop & DragDropCommon modules to 1.1.0

* Introduced DragDrop.EvtCancelled attribute, telling that the action was cancelled and object "unhooked" even before the dragging itself started.
* Consequently, fixed a mistake in DragDropCommon when it did not reset some public attributes when the drag was cancelled.


PS. I still have to write a better documentation and examples...

PPS. Started rewriting module docs, I also found a number of logical mistakes in the module, so likely there will be 1.2 update after this...

Mehrdad

Thanks for update

In the game, I haven't items (objects) in room 3.
My official site: http://www.pershaland.com/


Mehrdad

Quote from: Crimson Wizard on Tue 12/07/2022 12:57:02
Quote from: Mehrdad on Tue 12/07/2022 12:08:06
In the game, I haven't items (objects) in room 3.

Sorry, what do you mean by this?

Room 3 is empty and doesn't have any items for drag
My official site: http://www.pershaland.com/

Crimson Wizard

Quote from: Mehrdad on Tue 12/07/2022 14:42:49
Room 3 is empty and doesn't have any items for drag

Are you talking about Demo Game? I don't observe this problem. Please tell, where did you download the game, and which version of AGS are you using to open it?
Does anyone else have same issue?

Mehrdad

Quote from: Crimson Wizard on Wed 13/07/2022 18:07:23
Quote from: Mehrdad on Tue 12/07/2022 14:42:49
Room 3 is empty and doesn't have any items for drag

Are you talking about Demo Game? I don't observe this problem. Please tell, where did you download the game, and which version of AGS are you using to open it?
Does anyone else have same issue?


Yes, Demo Game. I hadn't problem with previous versions. It happens for me in 1.1.0
I use 3.6 last version.
My official site: http://www.pershaland.com/

Crimson Wizard

Quote from: Mehrdad on Thu 14/07/2022 06:00:37
Yes, Demo Game. I hadn't problem with previous versions. It happens for me in 1.1.0
I use 3.6 last version.

So what happens, you download the demo game, open the game in the editor, go to room 3, switch to display room objects, and there are none? And when you run the game, there are also none?

Mehrdad

Quote from: Crimson Wizard on Thu 14/07/2022 07:31:47
Quote from: Mehrdad on Thu 14/07/2022 06:00:37
Yes, Demo Game. I hadn't problem with previous versions. It happens for me in 1.1.0
I use 3.6 last version.

So what happens, you download the demo game, open the game in the editor, go to room 3, switch to display room objects, and there are none? And when you run the game, there are also none?

Both. editor and run game. All images point to sprite 0. I could fix it manually and replace image 0 with other sprites.


My official site: http://www.pershaland.com/

Crimson Wizard

Quote from: Mehrdad on Thu 14/07/2022 13:01:38
Both. editor and run game. All images point to sprite 0. I could fix it manually and replace image 0 with other sprites.

Do I understand correctly, that objects themselves exist, but they lost their sprites?
Do you get any errors or other messages when opening the game in the editor? Which sprites are present in the sprite manager?

EDIT: alright, I finally reproduced this, if I save & rebuild whole game without opening a room first.
It appears that the game contains mistakes, where objects reference sprites which are no longer present in the sprite manager, but somehow remained present in the sprite file. The newer version of AGS 3.6.0 detects such case and cleans the sprite file.


Mehrdad

My official site: http://www.pershaland.com/

Crimson Wizard

NOTE: I reuploaded demo once more, fixing another problem that caused incorrect drawing colors in room 2.

Mehrdad

Quote from: Crimson Wizard on Thu 14/07/2022 16:00:35
NOTE: I reuploaded demo once more, fixing another problem that caused incorrect drawing colors in room 2.

The demo Game link is broken.
My official site: http://www.pershaland.com/

SMF spam blocked by CleanTalk