HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] Using _PropMouseTargetableDecorator  (Read 1904 times)

Sands_Dethston

  • World Owners
  • ****
  • Posts: 44
    • View Profile
[Resolved] Using _PropMouseTargetableDecorator
« on: Jan 13, 13, 06:14:39 PM »

I have been implementing the Prop System described here: http://hewiki.heroengine.com/wiki/Prop_System

I have managed to instantiate a prop with the decorators _PropVisualizationDecorator and _PropMouseTargetableDecorator glommed on using the PropSpecOracle and its functions.

Unfortunately I can't find any information in either the wiki or forums on how to use these decorators.

I have already done the HSL tutorial that adds mouse interaction and I understand how that works, I really want to know how to do it through the decorator as I am attempting to use the prop system.

I know through experimenting and commenting HE files:

 _PropMouseTargetableDecorator gloms on the class _MouseTargetableProp onto the prop and the accepts mouse events and queries for functions and sends the args and prop through a number of them such as _PropMouseEvent, _OnPropMouseEvent and _OnPropSpecMouseEvent.

My current solution is to edit the shared function _OnPropMouseEvent in _MouseTargetableProp class methods like so: (it is originally empty except for the comment  //ensure shared function exists

Code: [Select]
shared function _OnPropMouseEvent(prop as NodeRef of Class _Prop, args references Class _MouseEvent)
  //ensure shared function exists
  Println ("Entered _OnPropMouseEvent")
  where prop is kindof _MouseTargetableProp
    Println ("prop is kindof _MouseTargetableProp")
    when args.MouseEventType
      is Enter
        println("onMouseEnter for " + Prop)
        println("Click to Target")
        println("DoubleClick to open Menu")
        ///change cursor using $Cursor - have to create a new cursor spec and add a graphic
      .
      is Click
        println ("Trying to set the target to: "+Prop)
        $E_TargetCircle.E_SetTargetCircle(Prop)
       
      . 
      is DoubleClick
        Println("onMouseDoubleClick for "+prop)
        $IPopUp.ObjectMenuOpenTest(prop)
      . 
      default
        // Allow other events to fall through, doing a println
        println(args.MouseEventType)
      .
    .
  .
.

Though this does work and gives me my menu etc, this does not seem like the right way to do it....Could someone please explain how I can access the mouse arguments and prop without changing the HE files?

Cheers

« Last Edit: Feb 05, 13, 09:48:46 AM by HE-Cooper »
Logged

Sands_Dethston

  • World Owners
  • ****
  • Posts: 44
    • View Profile
Re: Using _PropMouseTargetableDecorator
« Reply #1 on: Jan 15, 13, 07:07:41 PM »

Is this question just too silly? (which I'm willing to accept, I'm not a highly experienced programmer), is the Prop System not working correctly or am I missing some information on the forums or wiki? (The lack of forum posts and info makes this possible) or is there no one who knows the answer to this?

It's very possible that I'm just missing something silly, but any feedback would be appreciated as I'm still clueless...

« Last Edit: Jan 15, 13, 07:10:29 PM by Sands_Dethston »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1156
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Using _PropMouseTargetableDecorator
« Reply #2 on: Jan 15, 13, 09:30:23 PM »

I am not quite that far yet in coding, so this will be just a guess.

I believe many of the HE_ scripts can be overridden, though I have seen some are tricky to override. Basically, use the same name after the _ and if there is an invokeHE somewhere, (it might be in the E_ ) it can be used to point to your over ride code. Make sure to add a class in the DOM with the same name, changing the HE to your values. Usually in the DOM, you can make the script there, as it will supply the correct name on the script.

add:
HE_CSSInvokeGUI is the call that will override, can do a search on these.
« Last Edit: Jan 15, 13, 09:33:30 PM by Thazager »
Logged

Sands_Dethston

  • World Owners
  • ****
  • Posts: 44
    • View Profile
Re: Using _PropMouseTargetableDecorator
« Reply #3 on: Jan 18, 13, 03:31:33 AM »

I am not quite that far yet in coding, so this will be just a guess.

I believe many of the HE_ scripts can be overridden, though I have seen some are tricky to override. Basically, use the same name after the _ and if there is an invokeHE somewhere, (it might be in the E_ ) it can be used to point to your over ride code. Make sure to add a class in the DOM with the same name, changing the HE to your values. Usually in the DOM, you can make the script there, as it will supply the correct name on the script.

add:
HE_CSSInvokeGUI is the call that will override, can do a search on these.

Thanks for the reply, I'm still looking into this (delayed to look at other issues since I have the HSL tut method), I'll post a reply when I have a definite solution.

It would be nice to get confirmation from a Heroengine representative that this is actually the correct way to do it, since there is no documentation on this that I can find, I'd also be happy to be pointed to the correct docs or part of the forum if I'm incorrect about that...

 
« Last Edit: Jan 18, 13, 03:33:32 AM by Sands_Dethston »
Logged

Sands_Dethston

  • World Owners
  • ****
  • Posts: 44
    • View Profile
Re: Using _PropMouseTargetableDecorator
« Reply #4 on: Jan 27, 13, 02:40:08 AM »

I have moved forward into making my own game specific versions of the propspecoracle and attached files (propspec, prop, prop decorators). Everything seems to be working fine when compiling my prop test scripts (client and server, no errors) using the game specific propspecoracle and attached files.

However, when I add my prop using the test script's addprop() method, my prop does not appear. I am getting no errors on either the client or server.

My prop test script is based on the test script I wrote to use the basic _prop system and that script works (adds a prop into the world that can be clicked on). I will give relevant code for both versions, _prop and prop (client and server) and my debug readout (client and server) for each.

The first scripts work with the basic _prop system and they give me a functional prop in the world when the addprop() method is called on the client--

Old_PropTestScriptClassMethods: Client

Code: [Select]
function AddProp ()
    call server Old_PropTestScriptClassMethods:AddProp()
.

Old_PropTestScriptClassMethods: Server

Code: [Select]
untrusted function AddProp ()
  //Set Speckey for testing
  specKey as ID = 2 //use any valid specKey for a spec within the _PropSpecOracle
 
  //get _prop
  propSpecOracle as NodeRef of Class _PropSpecOracle
 
  //get our prop spec oracle
  propSpecOracle = $_PROPS._GetPropSpecOracle()
  println ("PropSpecOracle ref == "+PropSpecOracle)
 
  //get the spec we're interested in creating a prop from
  propSpec as NodeRef of Class _PropSpec = propSpecOracle.GetSpecByKey(specKey)
  println ("PropSpec ref == "+PropSpec)
 
  //cast a version of the prop to access the _visibleprop fields
  prop_VisibleProp as NodeRef of Class _VisibleProp = propSpec.CreateFromSpec()
 
  //create our normal cast version
  prop as NodeRef of Class _Prop = prop_VisibleProp
 
  //get the character's position
  account as NodeRef of Class _PlayerAccount = ( SYSTEM.REMOTE.CLIENT )
  char as NodeRef of Class E_playerCharacter = account.GetMyChar()
  pos as Vector3 = Char.GetPosition() 
  println("Char.GetPosition() = "+Char.GetPosition())
 
  //set field attributes for prop
  rot as Vector3 = (0,0,0)
  scale as Vector3 = (1,1,1)
  Prop._SetPosition(pos)
  Prop._SetRotation(rot)
  Prop._SetScale(scale)
 
  println ("Prop ref == "+Prop)
  println("prop.GetMySpecKey() = "+Prop.GetMySpecKey()) 
 
  //Set the Asset FQN for Testing
  myAsset as String = "\world\livecontent\resources\grenmeerlowlands\ruin_tower_floor_lowlands_02.gr2"
  prop_VisibleProp._PropFQN = myAsset
 
  //Reply to the Client
  call reply Old_PropTestScriptClassMethods:CallbackReceive("server got the message to Add a Prop!")
.

Debug Readout Old_PropTestScriptClassMethods: Client

Code: [Select]
20:00:46: call old_proptestscriptclassmethods addprop
20:00:46: SYSTEM:System:call OK 0 : "HeroScript called"
20:00:46: SCRIPT:[Old_PropTestScriptClassMethods]:server got the message to Add a Prop!

Debug Readout Old_PropTestScriptClassMethods: Server

Code: [Select]
[hsl_debug] 9223372057975021938,3: SCRIPT[Old_PropTestScriptClassMethods]: PropSpecOracle ref == 9223372055737621487
[hsl_debug] 9223372057975021938,3: SCRIPT[Old_PropTestScriptClassMethods]: PropSpec ref == 9223372058340021567
[hsl_debug] 9223372057975021938,3: SCRIPT[Old_PropTestScriptClassMethods]: Char.GetPosition() = (89.7667,0.9974,3.46121)
[hsl_debug] 9223372057975021938,3: SCRIPT[Old_PropTestScriptClassMethods]: Prop ref == 9223372060880021767
[hsl_debug] 9223372057975021938,3: SCRIPT[Old_PropTestScriptClassMethods]: prop.GetMySpecKey() = 2


The second set of scripts work with the my prop system and they compile and run fine but do not gives me a functional prop in the world when the addprop() method is called on the client--

PropTestScriptClassMethods: Client

Code: [Select]
function AddProp ()
  call server PropTestScriptClassMethods:AddProp()
.

PropTestScriptClassMethods: Server

Code: [Select]
untrusted function AddProp ()
  //set speckey for testing
  specKey as ID = 2 //use any valid specKey for a spec within the _PropSpecOracle
 
  //create propspec oracle
  var propSpecOracle = $SPECORACLEUTILS._GetOracleFromType( "PropSpecOracle" )
  println ("PropSpecOracle ref == "+PropSpecOracle)
 
  //get the spec we're interested in creating a prop from
  propSpec as NodeRef of Class PropSpec = propSpecOracle.GetSpecByKey(specKey)
  println ("PropSpec ref == "+PropSpec)
   
  //cast a version of the prop to access the _visibleprop fields
  myVisibleProp as NodeRef of Class Sands_VisibleProp = propSpec.CreateFromSpec()
 
  //create our normal cast version
  myProp as NodeRef of Class Prop = myVisibleProp 
 
  //get the character's position
  account as NodeRef of Class _PlayerAccount = ( SYSTEM.REMOTE.CLIENT )
  char as NodeRef of Class E_playerCharacter = account.GetMyChar()
  pos as Vector3 = Char.GetPosition()
  println("Char.GetPosition() = "+Char.GetPosition())
 
  //set field attributes for prop
  rot as Vector3 = (0,0,0)
  scale as Vector3 = (1,1,1)
  myProp._SetPosition(pos)
  myProp._SetRotation(rot)
  myProp._SetScale(scale)
 
  println ("Prop ref == "+myProp)
  println("prop.GetMySpecKey() = "+myProp.GetMySpecKey()) 
 
  //Set the Asset FQN for Testing
  myAsset as String = "\world\livecontent\resources\grenmeerlowlands\ruin_tower_floor_lowlands_02.gr2"
  myVisibleProp._PropFQN = myAsset
  println("myVisibleProp._PropFQN = "+myVisibleProp._PropFQN)
 
  //Reply to the Client
  call reply PropTestScriptClassMethods:CallbackReceive("server got the message to Add a Prop!")
.

Debug Readout PropTestScriptClassMethods: Client

Code: [Select]
20:04:51: call proptestscriptclassmethods addprop
20:04:51: SYSTEM:System:call OK 0 : "HeroScript called"
20:04:51: SCRIPT:[PropTestScriptClassMethods]:server got the message to Add a Prop!

Debug Readout PropTestScriptClassMethods: Server

Code: [Select]
[hsl_debug] 9223372057975021938,3: SCRIPT[PropTestScriptClassMethods]: PropSpecOracle ref == 9223372058675021589
[hsl_debug] 9223372057975021938,3: SCRIPT[PropTestScriptClassMethods]: PropSpec ref == 9223372060765021857
[hsl_debug] 9223372057975021938,3: SCRIPT[PropClassMethods]: Entered GetMySpecOracle
[hsl_debug] 9223372057975021938,3: SCRIPT[Sands_PropMouseTargetableDecoratorClassMethods]: After Sands_MouseTargetableProp Glom
[hsl_debug] 9223372057975021938,3: SCRIPT[Sands_PropVisualizationDecoratorClassMethods]: After Sands_VisibleProp Glom
[hsl_debug] 9223372057975021938,3: SCRIPT[PropClassMethods]: Entered GetMySpecOracle
[hsl_debug] 9223372057975021938,3: SCRIPT[Sands_PropMouseTargetableDecoratorClassMethods]: After Sands_MouseTargetableProp Glom
[hsl_debug] 9223372057975021938,3: SCRIPT[Sands_PropVisualizationDecoratorClassMethods]: After Sands_VisibleProp Glom
[hsl_debug] 9223372057975021938,3: SCRIPT[PropTestScriptClassMethods]: Char.GetPosition() = (89.346,0.9974,4.27099)
[hsl_debug] 9223372057975021938,3: SCRIPT[PropTestScriptClassMethods]: Prop ref == 9223372060880021770
[hsl_debug] 9223372057975021938,3: SCRIPT[PropTestScriptClassMethods]: prop.GetMySpecKey() = 2
[hsl_debug] 9223372057975021938,3: SCRIPT[PropTestScriptClassMethods]: myVisibleProp._PropFQN = \world\livecontent\resources\grenmeerlowlands\ruin_tower_floor_lowlands_02.gr2

Nothing appears in the world when I run this second set of scripts, but I don't have any errors that I can see, what am I doing wrong here, any help appreciated.

Cheers
« Last Edit: Jan 27, 13, 03:10:12 AM by Sands_Dethston »
Logged

Sands_Dethston

  • World Owners
  • ****
  • Posts: 44
    • View Profile
Re: Using _PropMouseTargetableDecorator
« Reply #5 on: Jan 27, 13, 03:56:33 AM »

After adding some debug code to the original _prop scripts I can see that my sands_visibleprop helper class isn't firing, so the dovisualise() method is not getting called, I think this is to do with replication and could indicate that my prop is not replicating correctly, but that's a guess, now to find out what it is...

any help appreciated if anyone can think of something that I should check

Cheers
Logged

Sands_Dethston

  • World Owners
  • ****
  • Posts: 44
    • View Profile
Re: Using _PropMouseTargetableDecorator
« Reply #6 on: Jan 27, 13, 09:05:37 PM »

Turns out my _PropSASIntroductionRange was set to 0 in the propspec (in the propspecoracle spec editor) so the SAS was not being triggered by my character, therefore the prop was never coming into range and being visualized for the character.  :P

Extending the prop system is definitely the best way and was working fine except for this mistake.
Logged