Beispiel #1
0
void DebugOverlayHandler::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
    if (value == "load_debug_overlay")
    {   
        gFpsField = event.GetTargetElement()->GetElementById("fps");
        gPos0Field = event.GetTargetElement()->GetElementById("pos0");
        gPos1Field = event.GetTargetElement()->GetElementById("pos1");
    }
}
Beispiel #2
0
// Processes an event coming through from Rocket.
void EventManager::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
	Rocket::Core::StringList commands;
	Rocket::Core::StringUtilities::ExpandString(commands, value, ';');
	for (size_t i = 0; i < commands.size(); ++i)
	{
		// Check for a generic 'load' or 'exit' command.
		Rocket::Core::StringList values;
		Rocket::Core::StringUtilities::ExpandString(values, commands[i], ' ');

		if (values.empty())
			return;

		if (values[0] == "goto" &&
 			values.size() > 1)
		{
			// Load the window, and if successful close the old window.
			if (LoadWindow(values[1]))
				event.GetTargetElement()->GetOwnerDocument()->Close();
		}
		else if (values[0] == "load" &&
 			values.size() > 1)
		{
			// Load the window.
			LoadWindow(values[1]);
		}
		else if (values[0] == "close")
		{
			Rocket::Core::ElementDocument* target_document = NULL;

			if (values.size() > 1)
				target_document = context->GetDocument(values[1].CString());
			else
				target_document = event.GetTargetElement()->GetOwnerDocument();

			if (target_document != NULL)
				target_document->Close();
		}
		else if (values[0] == "exit")
		{
			Shell::RequestExit();
		}
		else if (values[0] == "pause")
		{
			GameDetails::SetPaused(true);
		}
		else if (values[0] == "unpause")
		{
			GameDetails::SetPaused(false);
		}
		else
		{
			if (event_handler != NULL)
				event_handler->ProcessEvent(event, commands[i]);
		}
	}
}
void EventHandlerHighScore::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
	if (value == "add_score")
	{
		int score = GameDetails::GetScore();
		if (score > 0)
		{
			// Submit the score the player just got to the high scores chart.
			HighScores::SubmitScore(GameDetails::GetDefenderColour(), GameDetails::GetWave(), GameDetails::GetScore());
			// Reset the score so the chart won't get confused next time we enter.
			GameDetails::ResetScore();
		}
	}
	else if (value == "enter_name")
	{
		if (event.GetParameter< int >("key_identifier", Rocket::Core::Input::KI_UNKNOWN) == Rocket::Core::Input::KI_RETURN)
		{
			Rocket::Core::String name = event.GetCurrentElement()->GetAttribute< Rocket::Core::String >("value", "Anon.");
			HighScores::SubmitName(name);
		}
	}
	else if (value == "check_input")
	{
		Rocket::Core::Element* name_input_field = event.GetTargetElement()->GetElementById("player_input");
		if (name_input_field)
		{
			name_input_field->Focus();
		}
	}
	else if (value == "check_name")
	{
		/* TODO: Check if the player hasn't set their name first. */
		HighScores::SubmitName("Anon.");
	}
}
Beispiel #4
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();
      }
   }
}
void UI_ScriptDocument::ProcessEvent( Rocket::Core::Event &event )
{
	if( event.GetType() == "afterLoad" && event.GetTargetElement() == this ) {
		if( module ) {
			owner = event.GetParameter<void *>( "owner", NULL );

			as->finishBuilding( module );
			as->setModuleUserData( module, owner );
		}

		isLoading = false;

		// handle postponed onload events (HOWTO handle these in cached documents?)
		for( PostponedList::iterator it = onloads.begin(); it != onloads.end(); ++it ) {
			Rocket::Core::Event *load = *it;
			this->DispatchEvent( load->GetType(), *(load->GetParameters()), true );
			load->RemoveReference();
		}

		// and clear the events
		onloads.clear();
		return;
	}

	if( event.GetType() == "beforeUnload" && event.GetTargetElement() == this ) {
		if( module ) {
			// FIXME: destroy script event listeners here somehow!

			// destroy the AS module by name to prevent crashes in case multiple document instances share the same module pointer
			as->buildReset( GetSourceURL().CString() );
			module = NULL;
		}
		return;
	}

	if( isLoading ) {
		Rocket::Core::Event *instanced = Rocket::Core::Factory::InstanceEvent( event.GetTargetElement(),
			event.GetType(), *event.GetParameters(), true );
		onloads.push_back( instanced );
		event.StopPropagation();
		return;
	}

	Rocket::Core::ElementDocument::ProcessEvent( event );
}
Beispiel #6
0
// Regenerates the element's geometry.
void ElementImage::ProcessEvent(Rocket::Core::Event& event)
{
	Element::ProcessEvent(event);

	if (event.GetTargetElement() == this &&
		event == "resize")
	{
		GenerateGeometry();
	}
}
Beispiel #7
0
void ChatHandler::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
    if (value == "load_chat")
    {   
        gChatLogField = event.GetTargetElement()->GetElementById("chatlog");
    }

    if (value == "enter_key")
    {
        if (event.GetParameter< int >("key_identifier", Rocket::Core::Input::KI_UNKNOWN) == Rocket::Core::Input::KI_RETURN)
        {
            DoChat(event);
        }
    }
}
Beispiel #8
0
void ChatHandler::DoChat(Rocket::Core::Event& event)
{
    auto chatline = event.GetTargetElement()->GetElementById("chatline");
    if (chatline)
    {
        auto line = chatline->GetAttribute<Rocket::Core::String>("value", "");
        if (line.Length() > 0)
        {
            cl_player_chat(line.CString());
        }
    }
    else
    {
        // ASSERT
    }
    
}
void DragListener::ProcessEvent(Rocket::Core::Event& event)
{
	if (event == "dragdrop")
	{
		Rocket::Core::Element* dest_container = event.GetCurrentElement();
		Rocket::Core::Element* dest_element = event.GetTargetElement();
		Rocket::Core::Element* drag_element = static_cast< Rocket::Core::Element* >(event.GetParameter< void* >("drag_element", NULL));

		if (dest_container == dest_element)
		{
			// The dragged element was dragged directly onto a container.
			drag_element->GetParentNode()->RemoveChild(drag_element);
			dest_container->AppendChild(drag_element);
		}
		else
		{
			// The dragged element was dragged onto an item inside a container. In order to get the
			// element in the right place, it will be inserted into the container before the item
			// it was dragged on top of.
			Rocket::Core::Element* insert_before = dest_element;

			// Unless of course if it was dragged on top of an item in its own container; we need
			// to check then if it was moved up or down with the container.
			if (drag_element->GetParentNode() == dest_container)
			{
				// Check whether we're moving this icon from the left or the right.

				Rocket::Core::Element* previous_icon = insert_before->GetPreviousSibling();
				while (previous_icon != NULL)
				{
					if (previous_icon == drag_element)
					{
						insert_before = insert_before->GetNextSibling();
						break;
					}

					previous_icon = previous_icon->GetPreviousSibling();
				}
			}

			drag_element->GetParentNode()->RemoveChild(drag_element);
			dest_container->InsertBefore(drag_element, insert_before);
		}
	}
}
Beispiel #10
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);
      }
   }
}
Beispiel #11
0
	void ProcessEvent( Rocket::Core::Event &ev )
	{
		if( ev.GetType() == "change" )
			setCvar( ev.GetTargetElement() );
	}
Beispiel #12
0
  void UI::processEvent(const Rocket::Core::Event& event) {
    Rocket::Core::String type = event.GetType();
    event_count_++;

    //if (event == "resize") {
    //  if (renderer_content_ != NULL && renderer_content_->HasChildNodes()) {
    //    renderer_content_->GetLastChild()->ScrollIntoView();
    //  }
    //  return;
    //}

    if (type == "mouseover" || type == "dragstart") {
      mouse_over_count_++;
    } else if (type == "mouseout" || type == "dragend") {
      mouse_over_count_--;
    } else if (type == "change") {
      // An input element changed:
      Element* target = event.GetTargetElement();
      if (target != NULL) {
        // All our "changable" elements need to have a type attribute (we
        // need to put them there).  Make sure this one has one and that
        // it is of type string.
        if (target->GetAttribute("type") == NULL || 
          target->GetAttribute("type")->GetType() != Variant::Type::STRING) {
            std::wstringstream ss;
            ss << L"UI::processEvent() - ERROR: the current target element";
            ss << L" either does not have an attribute named type or that";
            ss << L" attribute is not of type string";
            throw wruntime_error(ss.str());
        }
        String elem_type = target->GetAttribute("type")->Get<String>();
        // Do the same for the value element (which stores the setting string)
        if (target->GetAttribute("value") == NULL || 
          target->GetAttribute("value")->GetType() != Variant::Type::STRING) {
            std::wstringstream ss;
            ss << L"UI::processEvent() - ERROR: the current target element";
            ss << L" either does not have an attribute named value or that";
            ss << L" attribute is not of type string";
            throw wruntime_error(ss.str());
        }
        String val_str = target->GetAttribute("value")->Get<String>();

        // Now handle the different types of elements
        if (elem_type == "checkbox") {  // Handle checkbox
          bool old_value = false;
          GET_SETTING(val_str.CString(), bool, old_value);

          // Set the internal setting (in the setting manager)
          bool value = false;
          if (target->GetAttribute("checked")) {
            value = true;
          }
          SET_SETTING(val_str.CString(), bool, value);

          // Handle special cases (that need to do something immediately)
          if (val_str == "fullscreen") {
            if (old_value != value) {
              Renderer::requestReloadRenderer();
              return;
            }
          }

          // Handle special cases that require the app to do something after 
          // the variable has been set.
          if (val_str == "render_ui") {
            setVisibility(value, renderer_doc_);
          }
        } else if (elem_type == "selectbox") {
// Processes an event coming through from Rocket.
void EventManager::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
    Rocket::Core::StringList commands;
    Rocket::Core::StringUtilities::ExpandString(commands, value, ';');

    if(commands.size() == 0)
    {
        //send only the event to event handlers
        for(EventHandlerMap::iterator it = event_handlers.begin(); it != event_handlers.end(); it++)
            if(it->second != NULL)
                it->second->ProcessEvent(event, "");
    }
    else
    {
        for (size_t i = 0; i < commands.size(); ++i)
        {
            // Check for a generic 'load' or 'exit' command.
            Rocket::Core::StringList values;
            Rocket::Core::StringUtilities::ExpandString(values, commands[i], ' ');

            //if (values.empty())
            //	return;

            if (values[0] == "goto" &&
                    values.size() > 1)
            {
                // Load the window, and if successful close the old window.
                if (LoadWindow(values[1]))
                    event.GetTargetElement()->GetOwnerDocument()->Close();
            }
            else if (values[0] == "load" &&
                     values.size() > 1)
            {
                // Load the window.
                LoadWindow(values[1]);
            }
            else if (values[0] == "close")
            {
                Rocket::Core::ElementDocument* target_document = NULL;

                if (values.size() > 1)
                    target_document = Context->GetDocument(values[1].CString());
                else
                    target_document = event.GetTargetElement()->GetOwnerDocument();

                if (target_document != NULL)
                    target_document->Close();
            }
            else if (values[0] == "exit")
            {
                Shell::RequestExit();
            }
            /*
            		else if (values[0] == "pause")
            		{
            			GameDetails::SetPaused(true);
            		}
            		else if (values[0] == "unpause")
            		{
            			GameDetails::SetPaused(false);
            		}
            */
            else
            {
                //send the event to all windows
                for(EventHandlerMap::iterator it = event_handlers.begin(); it != event_handlers.end(); it++)
                    if(it->second != NULL)
                        it->second->ProcessEvent(event, commands[i]);

                /*
                if (event_handler != NULL)
                {
                	event_handler->ProcessEvent(event, commands[i]);
                }
                */
            }
        }
    }
}
Beispiel #14
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();
         }
      }
   }
}
/// \brief Event listener callback for "mouseup" events generated by libRocket.
///
/// \param ev     The object containing event info.
/// \param store  The UIDataViewList widget to use.
/// \param db     The cards database to use for comparison against model
///               (table) data.
/// \param model  The data source model to use.
/// \param player_hand  The mock player hand object to use for holding card
///                     data, such as totals on number of cards of a type.
void on_mouseup(  Rocket::Core::Event& ev,
                  UIDataViewList* store,
                  const std::shared_ptr<CardCollection> db,
                  std::shared_ptr<CardsPageDataSource> model,
                  std::map<int,Card>& player_hand )
{
  EXPECT_TRUE( store != nullptr );
  EXPECT_TRUE( db != nullptr );
  EXPECT_TRUE( model != nullptr );

  // ID of card selection
  int selection = 0;
  Rocket::Core::Element* target = ev.GetTargetElement();

  if( ev == "mouseup" )
  {
    Rocket::Core::Input::KeyIdentifier button =
      (Rocket::Core::Input::KeyIdentifier) ev.GetParameter<int>("button", 3);

    EXPECT_TRUE( model->per_page() == model->GetNumRows("cards") );
    EXPECT_EQ( 57, model->num_rows() );

    if( target ) {

      Card card = model->lookup_by_name( target->GetInnerRML().CString() );
      selection = card.id();

      if( target->GetTagName() == "card" && button == 0 ) // Left click
      {
        // Card selection logic; player hand receives a card
        //
        // 1. Decrease available card count by one
        // 2. Sync the cards model to reflect modified card count (-1)
        // 3. Update player hand w/ a copy of the reference card
        if( card.num() > 0 )
        {
          card.set_num( card.num() - 1 );
          model->insert_card(selection, card);
          player_hand[card.id()] = card;
        }

      } // end if button == 0
      else if( target->GetTagName() == "card" && button == 1 )  // Right click
      {
        // Compare the selected card from the current model with the game
        // database; we rely on the game database to be the "safe" -- read-only.
        Card ref_card = db->lookup_by_id(selection);

        // Card selection logic; player hand removes a card
        //
        // 1. Increase available card count by one
        // 2. Sync the cards model to reflect modified card count (+1)
        // 3. Remove the card from the player's hand
        if( card.num() < ref_card.num() )
        {
          card.set_num( card.num() + 1 );
          model->insert_card(selection, card);
          player_hand.erase( card.id() );
        }
      } // end if button == 1

      NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, "Card ID:", selection );
      NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, "Card name:", target->GetInnerRML().CString() );

    } // end if target

  } // end if click
} // end func on_mouseup