Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Drag and Drop (https://forums.graalonline.com/forums/showthread.php?t=81034)

LoneAngelIbesu 08-03-2008 05:44 AM

Drag and Drop
 
For Valikorlia's trading GUI, I'm wanting to implement dragging and dropping. So far, I've gotten dragging down. However, I can't seem to figure out dropping. The "3" is arbitrary; I just copied another NAT's method (which obviously isn't working in this case :D).

This is how I'm doing it. First, we have onRecordSelection(obj), which is just obj.onSelect(). This triggers onDragIcon(obj). (I do it this way to prevent a different icon from being selected when dragging the mouse over it.) From there, a GuiShowImgCtrl is created, which is the floating icon that the user's dragging around. The problem I'm having is detecting when the mouse is over TradeOfferScroll.
PHP Code:

function onDragIcon(obj) {
  if(
this.dragging) {
    return;
  }
  new 
GuiShowImgCtrl("TradeInventoryFloater") {
    
this.width 32;
    
this.height 32;
    
System.parseimage(thisstaticdata.tradeitems[(@ obj).itemid].icon);
    
this.mousescreenx;
    
this.mousescreeny;
  }
  
setTimer(0.05);


PHP Code:

function onTimeout() {
  if(
leftmousebuttonglobal) {
    
with(TradeInventoryFloater) {
      
this.mousescreenx;
      
this.mousescreeny;
    }
    
this.dragging true;
    
setTimer(0.05);
  }
  else {
    if(
mousescreenx in  |TradeOfferScroll.xTradeOfferScroll.3|) {
      if(
mousescreeny in |TradeOfferScroll.yTradeOfferScroll.3|) {
        echo(
"Added to offer");
      }
    }
    else {
      echo(
"Destroyed");
    }
    
this.dragging false;
    
System.destroyobject("TradeInventoryFloater");
    
setTimer(0);
  }


Another NAT on Valikorlia suggested using showimg() instead of a GuiShowImgCtrl. Is there any benefit with doing this, as opposed to using a GUI control?

_Z3phyr_ 08-03-2008 01:27 PM

i only see this code breaking down on the else block after the leftmousebuttonglobal bit and/or the in || requirements inside that else block.

my experience tells me that your tradeofferscroll.x/y are not equal to what you think they are.

cbk1994 08-03-2008 05:54 PM

mousescreenx/y are relevant to the screen. Your scroll is relevant to the control it is in.

The scroll might have an x of 10, but it's really at 450 x on the screen.

Try using control.globaltolocalcoord( { x, y } )

I'm assuming that the scroll actually is in a control (besides GraalControl), however.

LoneAngelIbesu 08-03-2008 07:56 PM

Thank you, Chris. That worked.

PHP Code:

function onTimeout() {
  if(
leftmousebuttonglobal) {
    
with(TradeInventoryFloater) {
      
this.mousescreenx;
      
this.mousescreeny;
    }
    
this.dragging true;
    
setTimer(0.05);
  }
  else {
    
temp.target TradeOfferScroll.globaltolocalcoord({mousescreenx,mousescreeny});
    if(
temp.target[0in  |0138|) { //TradeOfferScroll.width
      
if(temp.target[1in |0260|) { //TradeOfferScroll.height
        
echo("Added to offer");
      }
    }
    else {
      echo(
"Destroyed");
    }
    
this.dragging false;
    
System.destroyobject("TradeInventoryFloater");
    
setTimer(0);
  }



DustyPorViva 08-03-2008 10:21 PM

For note, showimgs can not be shown over GUI's, so there's a problem with that method, for future reference.

cbk1994 08-03-2008 10:23 PM

Quote:

Originally Posted by DustyPorViva (Post 1411146)
For note, showimgs can not be shown over GUI's, so there's a problem with that method, for future reference.

GuiShowImgCtrl's can.

LoneAngelIbesu 08-03-2008 10:29 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1411032)
Another NAT on Valikorlia suggested using showimg() instead of a GuiShowImgCtrl. Is there any benefit with doing this, as opposed to using a GUI control?

Dusty was addressing this. Thanks for the info, though, Dusty. ^^

DustyPorViva 08-03-2008 10:49 PM

Quote:

Originally Posted by cbk1994 (Post 1411148)
GuiShowImgCtrl's can.

Yes they can, but they're treated like GUI's, which result in having the same problems GUI's have with catching mouse info and all.

[email protected] 08-04-2008 06:53 PM

hmm generally i'd use a while button in this case

HTML Code:

while (mousebuttons > 0) { //Mouse down
  Showimg[data]
}
if (mousex in |player.x - 5, player.x + 5| && mousey in |player.y - 5, player.y + 5|) {
  //drop the item
}

no need for a timeout, personal preference i suppose

DustyPorViva 08-04-2008 06:55 PM

Quote:

Originally Posted by [email protected] (Post 1411312)
hmm generally i'd use a while button in this case

HTML Code:

while (mousebuttons > 0) { //Mouse down
  Showimg[data]
}
if (mousex in |player.x - 5, player.x + 5| && mousey in |player.y - 5, player.y + 5|) {
  //drop the item
}

no need for a timeout, personal preference i suppose

A loop is a loop, whether it's a timeout or while, right?

cbk1994 08-04-2008 06:58 PM

Quote:

Originally Posted by [email protected] (Post 1411312)
hmm generally i'd use a while button in this case

HTML Code:

while (mousebuttons > 0) { //Mouse down
  Showimg[data]
}
if (mousex in |player.x - 5, player.x + 5| && mousey in |player.y - 5, player.y + 5|) {
  //drop the item
}

no need for a timeout, personal preference i suppose

You could eventually hit a loop limit; also, it would stop any other functions in that script.

[email protected] 08-04-2008 07:00 PM

add a sleep to avoid the loop limit, you wouldn't need to do any other functions in the script whilst moving an object.

xXziroXx 08-04-2008 07:05 PM

Quote:

Originally Posted by [email protected] (Post 1411318)
add a sleep to avoid the loop limit, you wouldn't need to do any other functions in the script whilst moving an object.

Sleeps are evil.

LoneAngelIbesu 08-04-2008 07:59 PM

I'll stick with a timeout. ^^

cbk1994 08-04-2008 11:05 PM

Quote:

Originally Posted by xXziroXx (Post 1411319)
Sleeps are evil.

I agree, they kill timeouts :\

WhiteDragon 08-05-2008 01:40 AM

Sleeps make the script lose focus.

zokemon 08-05-2008 11:29 AM

Why don't you just use the built-in dragging functions the Graal has for GUIs? You can set canmove=false and the drag functions will still be triggered when dragging, just the GUI wouldn't move.

I think you can figure out what to do with that data, right?

DustyPorViva 08-05-2008 11:32 AM

Quote:

Originally Posted by zokemon (Post 1411543)
Why don't you just use the built-in dragging functions the Graal has for GUIs? You can set canmove=false and the drag functions will still be triggered when dragging, just the GUI wouldn't move.

I think you can figure out what to do with that data, right?

I've always had problems with this... for instance, it looses focus and stops triggering when the mouse is moved outside of the GUI. I don't think anyone moves their mouse slow enough to allow the client to keep up. At least, this was one of my problems. I also had problems with focus and such... it was just a pain that I gave up. Perhaps there are fixes for this, however.


All times are GMT +2. The time now is 07:25 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.