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

Author Topic: Overriding $INPUT._GetDragSelectControl()  (Read 843 times)

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Overriding $INPUT._GetDragSelectControl()
« on: Apr 19, 13, 06:52:43 PM »

When updating our override class for the $INPUT system node, I was reminded of this workaround that I had to put in before.

The desire was to use our own prototype in the method _GetDragSelectControl() for the dragSelectControl instead of "_dragSelectRectangle".

Code: [Select]
// Gets the default DragSelect GUIControl which will be rendered during DragSelect operations.
// The returned control must inherit from _AbstractInputDragSelectionListener.
method _GetDragSelectControl() as NodeRef of Class GUIControl
  dragSelectControl as NodeRef of Class GUIControl
  handled as Boolean
  if HasMethod(me, "HE_GetDragSelectControl")
    handled = me.HE_GetDragSelectControl(dragSelectControl)
   
    #if DEVELOPMENTASSERTS
      if handled
        assert(dragSelectControl is kindof _AbstractInputDragSelectionListener, "Error! Drag selection control(" + dragSelectControl + ") does not inherit from _AbstractInputDragSelectionListener!")
      .
    #endif
  .
 
  if not handled
    dragSelectControl = FindGUIControlByName($GUI._getBaseGameLayer(), "_dragSelectRectangle")
    if dragSelectControl = None
      dragSelectControl = CreateNodeFromPrototype("_dragSelectRectangle")

      dragSelectControl.build = true
      dragSelectControl.layer = $GUI._getBaseGameLayer().getMyLayerName()
    .
  .
  return dragSelectControl
.

So we added a definition for HE_GetDragSelectControl() to our class, but the problem is that in _MethodCallbacksClassMethods, it is defined with this form:
Code: [Select]
method HE_GetDragSelectControl(dragSelectControl as NodeRef of Class GUIControl) as Boolean
  return false
.

Since dragSelectControl  is passed in using "as", we cannot assign to it in order to use our own prototype like so:
Code: [Select]
dragSelectControl = CreateNodeFromPrototype("Voz_DragSelectRectangle")
To workaround this, we changed the definition of HE_GetDragSelectControl() in _MethodCallbacksClassMethods to use "references" for the dragSelectControl.  I didn't like having to change  _MethodCallbacksClassMethods, but I could not see a way around this.  Hopefully that can be added to the Clean Engine in the future.  An alternative would be an override method that allows us to specify the name of the prototype to use.

------------------------

I did just recently think of another way to work around this.  By ensuring that our control is added to the $GUI._getBaseGameLayer() and calling it "_dragSelectRectangle" and then returning FALSE, the remaining default code in _GetDragSelectControl() will find that control using FindGUIControlByName() and so not change it and also will correctly return dragSelectControl with its value filled in.

But naturally, that is a less than ideal situation and still would not work if HE_GetDragSelectControl() returned true.
« Last Edit: Apr 19, 13, 06:57:47 PM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.