Пример #1
0
void ShortcutBar::shortcutClicked(Rocket::Core::Event& event)
{
   Rocket::Core::Element* shortcutElement = event.GetTargetElement();

   while(shortcutElement != nullptr && shortcutElement->GetParentNode() != m_shortcutContainer)
   {
      shortcutElement = shortcutElement->GetParentNode();
   }

   // Only handle the click if it went to a shortcut
   // (direct child of the shortcut bar container)
   if (shortcutElement != nullptr)
   {
      // Find the index of the shortcut
      int shortcutIndex = 0;

      for(;;)
      {
         shortcutElement = shortcutElement->GetPreviousSibling();
         if (shortcutElement == nullptr) break;
         ++shortcutIndex;
      }

      bool shortcutInvoked = invokeShortcut(shortcutIndex);
      if (shortcutInvoked)
      {
         refresh();
      }
   }
}
Пример #2
0
void SaveMenu::saveGameClicked(Rocket::Core::Event& event)
{
   Rocket::Core::Element* target = event.GetTargetElement();

   // Move up the DOM to the datagridrow item holding this element
   while(target->GetParentNode() != nullptr && target->GetTagName() != "datagridrow")
   {
      target = target->GetParentNode();
   }

   if(target != nullptr)
   {
      // If we found a row element, cast it and get its index
      Rocket::Controls::ElementDataGridRow* rowElement = dynamic_cast<Rocket::Controls::ElementDataGridRow*>(target);
      if(rowElement != nullptr)
      {
         int saveGameIndex = rowElement->GetParentRelativeIndex();
         showConfirmDialog(saveGameIndex);
      }
   }
}
Пример #3
0
void RocketMenuPlugin::ProcessEvent(Rocket::Core::Event& event) {
    Rocket::Core::Element *element = event.GetCurrentElement();

    if (event.GetType() == "click") {
        if (element->GetTagName() == "ftr") {
            SetNextItemValue(element->GetParentNode()->GetParentNode());
            event.StopPropagation();
        } else if (element->GetTagName() == "hdr") {
            SetPreviousItemValue(element->GetParentNode()->GetParentNode());
            event.StopPropagation();
        } else {
            DoItemAction(ItemActionEnter, element);
        }
    } else if (event.GetType() == "mousemove") {
        if (element->GetTagName() == "div") {
            HighlightItem(element);
        } else if (element->GetTagName() == "key1") {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            SetActiveKeySlot(menu_item, 0);
        } else if (element->GetTagName() == "key2") {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            SetActiveKeySlot(menu_item, 1);
        }
    } else if (event.GetType() == "change") {
        if (m_delegate != NULL && element->GetOwnerDocument()->IsVisible()) {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            RangeData *data = GetRangeData(menu_item);
            const Rocket::Core::Dictionary  *p = event.GetParameters();
            float v = p->Get("value")->Get<float>();
            float new_value = data->min + v*(data->max - data->min);
            if (fabs(new_value-data->value) > 0.001f) {
                data->value = new_value;
                m_delegate->DidChangeRangeValue(menu_item, data->value);
            }
        }
    }
}
Пример #4
0
  bool RocketUIManager::doCapture(Rocket::Core::Context* ctx)
  {
    Rocket::Core::Element* e = ctx->GetHoverElement();

    if(e && e != ctx->GetRootElement())
    {
      if(e->GetTagName() == "body")
        return false;

      bool isVisible = true;
      while(e && (isVisible = e->IsVisible()))
      {
        e = e->GetParentNode();
      }

      return isVisible;
    }

    return false;
  }
Пример #5
0
void Rocket_GetProperty( const char *name, void *out, int len, rocketVarType_t type )
{
    if ( activeElement )
    {
        const Rocket::Core::Property *property = activeElement->GetProperty( name );

        if ( !property )
        {
            return;
        }

        switch ( type )
        {
        case ROCKET_STRING:
        {
            char *string = ( char * ) out;

            if ( property )
            {
                Q_strncpyz( string, property->Get<Rocket::Core::String>().CString(), len );
            }

            return;
        }

        case ROCKET_FLOAT:
        {
            float *f = ( float * ) out;

            if ( len != sizeof( float ) )
            {
                return;
            }

            // HACK: special case for width and height specified in non absolute units

            if ( !Q_stricmp( "width", name ) && property->unit & Rocket::Core::Property::RELATIVE_UNIT )
            {
                float base_size = 0;
                Rocket::Core::Element *parent = activeElement;

                while ( ( parent = parent->GetParentNode() ) )
                {
                    if ( ( base_size = parent->GetOffsetWidth() ) != 0 )
                    {
                        *f = activeElement->ResolveProperty( "width", base_size );
                        return;
                    }
                }
            }

            if ( !Q_stricmp( "height", name ) && property->unit & Rocket::Core::Property::RELATIVE_UNIT )
            {
                float base_size = 0;
                Rocket::Core::Element *parent = activeElement;

                while ( ( parent = parent->GetParentNode() ) )
                {
                    if ( ( base_size = parent->GetOffsetHeight() ) != 0 )
                    {
                        *f = activeElement->ResolveProperty( "height", base_size );
                        return;
                    }
                }
            }

            *f = property->Get<float>();
            return;
        }

        case ROCKET_INT:
        {
            int *i = ( int * ) out;

            if ( len != sizeof( int ) )
            {
                return;
            }

            *i = property->Get<int>();
            return;
        }

        case ROCKET_COLOR:
        {
            vec_t *outColor = ( vec_t * ) out;

            if ( len != sizeof( vec4_t ) )
            {
                return;
            }

            Rocket::Core::Colourb color = property->Get<Rocket::Core::Colourb>();
            outColor[ 0 ] = color.red, outColor[ 1 ] = color.green, outColor[ 2 ] = color.blue, outColor[ 3 ] = color.alpha;
            Vector4Scale( outColor, 1 / 255.0f, outColor );
            return;
        }
        }
    }
}
Пример #6
0
void ShortcutBar::usableDropped(Rocket::Core::Event& event)
{
   Rocket::Core::Element* dragElement = static_cast<Rocket::Core::Element*>(event.GetParameter< void* >("drag_element", nullptr));
   if (dragElement != nullptr)
   {
      const bool isItem = dragElement->HasAttribute("itemId");
      const bool isSkill = dragElement->HasAttribute("skillId") && dragElement->HasAttribute("characterId");

      UsableId usableId = 0;

      if(isItem)
      {
         usableId = static_cast<UsableId>(dragElement->GetAttribute<int>("itemId", 0));
      }
      else if(isSkill)
      {
         usableId = static_cast<UsableId>(dragElement->GetAttribute<int>("skillId", 0));
      }

      if(usableId > 0)
      {
         Rocket::Core::Element* dropElement = event.GetTargetElement();

         // Only drops on direct children of the shortcut container count as
         // shortcut drops
         if(dropElement->GetParentNode() == m_shortcutContainer)
         {
            // Find the index of the shortcut
            int dropTargetIndex = 0;

            for(;;)
            {
               dropElement = dropElement->GetPreviousSibling();
               if (dropElement == nullptr) break;
               ++dropTargetIndex;
            }

            bool isShortcutSet = false;
            if(isItem)
            {
               DEBUG("Dropping item %d on shortcut index %d.", usableId, dropTargetIndex);
               m_playerData.setShortcut(dropTargetIndex, usableId);
               isShortcutSet = true;
            }
            else if(isSkill)
            {
               const std::string characterId = dragElement->GetAttribute<Rocket::Core::String>("characterId", "").CString();
               Character* character = m_playerData.getRoster()->getCharacter(characterId);

               if(character != nullptr)
               {
                  DEBUG("Dropping skill %d on shortcut index %d.", usableId, dropTargetIndex);
                  m_playerData.setShortcut(dropTargetIndex, usableId, characterId);
                  isShortcutSet = true;
               }
            }

            if(isShortcutSet)
            {
               // If the drag was initiated from the shortcut bar, then
               // clear out the shortcut's original slot
               if (dragElement->GetParentNode() == m_shortcutContainer)
               {
                  int dragTargetIndex = 0;
                  for(;;)
                  {
                     dragElement = dragElement->GetPreviousSibling();
                     if (dragElement == nullptr) break;
                     ++dragTargetIndex;
                  }

                  m_playerData.clearShortcut(dragTargetIndex);
               }
            }

            refresh();
         }
      }
   }
}