Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-03-2008, 05:44 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
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 ).

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?
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #2  
Old 08-03-2008, 01:27 PM
_Z3phyr_ _Z3phyr_ is offline
Banned
Join Date: Sep 2003
Location: Louisiane
Posts: 390
_Z3phyr_ is an unknown quantity at this point
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.
Reply With Quote
  #3  
Old 08-03-2008, 05:54 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #4  
Old 08-03-2008, 07:56 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
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);
  }

__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #5  
Old 08-03-2008, 10:21 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
For note, showimgs can not be shown over GUI's, so there's a problem with that method, for future reference.
Reply With Quote
  #6  
Old 08-03-2008, 10:23 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by DustyPorViva View Post
For note, showimgs can not be shown over GUI's, so there's a problem with that method, for future reference.
GuiShowImgCtrl's can.
__________________
Reply With Quote
  #7  
Old 08-03-2008, 10:49 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #8  
Old 08-03-2008, 10:29 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by LoneAngelIbesu View Post
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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #9  
Old 08-04-2008, 06:53 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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
Reply With Quote
  #10  
Old 08-04-2008, 06:55 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by [email protected] View Post
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?
Reply With Quote
  #11  
Old 08-04-2008, 06:58 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by [email protected] View Post
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.
__________________
Reply With Quote
  #12  
Old 08-04-2008, 07:00 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
add a sleep to avoid the loop limit, you wouldn't need to do any other functions in the script whilst moving an object.
Reply With Quote
  #13  
Old 08-04-2008, 07:05 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by [email protected] View Post
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.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #14  
Old 08-04-2008, 11:05 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xXziroXx View Post
Sleeps are evil.
I agree, they kill timeouts
__________________
Reply With Quote
  #15  
Old 08-04-2008, 07:59 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
I'll stick with a timeout.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
Reply

Tags
drag, drag & drop, drag and drop, drag'n'drop, drag-&-drop, drag-and-drop, drop


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:04 PM.


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