コード例 #1
0
ファイル: Menu.cpp プロジェクト: acremean/urho3d
void Menu::HandleFocusChanged(StringHash eventType, VariantMap& eventData)
{
    if (!showPopup_)
        return;
    
    using namespace FocusChanged;
    
    UIElement* element = static_cast<UIElement*>(eventData[P_ELEMENT].GetPtr());
    UIElement* root = GetRoot();
    
    // If another element was focused due to the menu button being clicked, do not hide the popup
    if (eventType == E_FOCUSCHANGED && static_cast<UIElement*>(eventData[P_CLICKEDELEMENT].GetPtr()))
        return;
    
    // If clicked emptiness or defocused, hide the popup
    if (!element)
    {
        ShowPopup(false);
        return;
    }
    
    // Otherwise see if the clicked element has either the menu item or the popup in its parent chain.
    // In that case, do not hide
    while (element)
    {
        if (element == this || element == popup_)
            return;
        if (element->GetParent() == root)
            element = static_cast<UIElement*>(element->GetVar(originHash).GetPtr());
        else
            element = element->GetParent();
    }
    
    ShowPopup(false);
}
コード例 #2
0
void MechanicsHud::HandleRelease(StringHash eventType, VariantMap& eventData)
{
	using namespace Released;

	UIElement* ele = static_cast<UIElement*>(eventData[Released::P_ELEMENT].GetPtr());

	String mechanicID = ele->GetVar("mechanicID").GetString();

	VariantMap vm;
	vm[MechanicRequest::P_MECHANICID] = mechanicID;
	SendEvent(E_MECHANICREQUEST, vm);
}
コード例 #3
0
	void EditorSelection::OnHierarchyListSelectionChange(const PODVector<UIElement*>& items, const PODVector<unsigned>& indices)
	{
		ClearSelection();

		for (unsigned int i = 0; i < indices.Size(); ++i)
		{
			unsigned int index = indices[i];
			UIElement* item = items[index];
			int type = item->GetVar(TYPE_VAR).GetInt();
			if (type == ITEM_COMPONENT)
			{
				Component* comp = editor_->GetListComponent(item);

				AddSelectedComponent(comp);
			}
			else if (type == ITEM_NODE)
			{
				Node* node = editor_->GetListNode(item);

				AddSelectedNode(node);
			}
			else if (type == ITEM_UI_ELEMENT)
			{
				UIElement* element = editor_->GetListUIElement(item);
				AddSelectedUIElement(element);
			}
		}

		// If only one node/UIElement selected, use it for editing
		if (GetNumSelectedNodes() == 1)
			editNode_ = selectedNodes_[0];

		
		if (GetNumSelectedUIElements() == 1)
			editUIElement_ = selectedUIElements_[0];
		

		// If selection contains only components, and they have a common node, use it for editing
		if (selectedNodes_.Empty() && !selectedComponents_.Empty())
		{
			Node* commonNode = NULL;
			for (unsigned int i = 0; i < GetNumSelectedComponents(); ++i)
			{
				if (i == 0)
					commonNode = GetSelectedComponents()[i]->GetNode();
				else
				{
					if (selectedComponents_[i]->GetNode() != commonNode)
						commonNode = NULL;
				}
			}
			editNode_ = commonNode;
		}

		// Now check if the component(s) can be edited. If many selected, must have same type or have same edit node
		if (!selectedComponents_.Empty())
		{
			if (editNode_ == NULL)
			{
				StringHash compType = selectedComponents_[0]->GetType();
				bool sameType = true;
				for (unsigned int i = 1; i < GetNumSelectedComponents(); ++i)
				{
					if (selectedComponents_[i]->GetType() != compType)
					{
						sameType = false;
						break;
					}
				}
				if (sameType)
					editComponents_ = selectedComponents_;
			}
			else
			{
				editComponents_ = selectedComponents_;
				numEditableComponentsPerNode_ = GetNumSelectedComponents();
			}
		}

		// If just nodes selected, and no components, show as many matching components for editing as possible
		if (!selectedNodes_.Empty() && selectedComponents_.Empty() && selectedNodes_[0]->GetNumComponents() > 0)
		{
			unsigned int count = 0;
			for (unsigned int j = 0; j < selectedNodes_[0]->GetNumComponents(); ++j)
			{
				StringHash compType = selectedNodes_[0]->GetComponents()[j]->GetType();
				bool sameType = true;
				for (unsigned int i = 1; i < GetNumSelectedNodes(); ++i)
				{
					if (selectedNodes_[i]->GetNumComponents() <= j || selectedNodes_[i]->GetComponents()[j]->GetType() != compType)
					{
						sameType = false;
						break;
					}
				}

				if (sameType)
				{
					++count;
					for (unsigned int i = 0; i < GetNumSelectedNodes(); ++i)
						AddEditComponent(selectedNodes_[i]->GetComponents()[j]);
				}
			}
			if (count > 1)
				numEditableComponentsPerNode_ = count;
		}

		if (selectedNodes_.Empty() && editNode_ != NULL)
			AddEditNode(editNode_);
		else
		{
			editNodes_ = selectedNodes_;

			// Cannot multi-edit on scene and node(s) together as scene and node do not share identical attributes,
			// editing via gizmo does not make too much sense either
			if (editNodes_.Size() > 1 && editNodes_[0] == editor_->GetScene())
				editNodes_.Erase(0);
		}

		if (selectedUIElements_.Empty() && editUIElement_ != NULL)
			AddEditUIElement(editUIElement_);
		else
			editUIElements_ = selectedUIElements_;


	}
コード例 #4
0
	void InGameEditor::HandleHierarchyListSelectionChange(StringHash eventType, VariantMap& eventData)
	{
		ListView* hierarchyList = hierarchyWindow_->GetHierarchyList();
		const PODVector<UIElement*>& items = hierarchyList->GetItems();
		const PODVector<unsigned>& indices = hierarchyList->GetSelections();

		editorData_->ClearSelection();

		for (unsigned int i = 0; i < indices.Size(); ++i)
		{
			unsigned int index = indices[i];
			UIElement* item = items[index];
			int type = item->GetVar(TYPE_VAR).GetInt();
			if (type == ITEM_COMPONENT)
			{
				Component* comp = GetListComponent(item);

				editorData_->AddSelectedComponent(comp);
			}
			else if (type == ITEM_NODE)
			{
				Node* node = GetListNode(item);

				editorData_->AddSelectedNode(node);
			}
			else if (type == ITEM_UI_ELEMENT)
			{
				UIElement* element = GetListUIElement(item);
				editorData_->AddSelectedUIElement(element);
			}
		}

		// If only one node/UIElement selected, use it for editing
		if (editorData_->GetNumSelectedNodes() == 1)
			editorData_->SetEditNode(editorData_->GetSelectedNodes()[0]);
		if (editorData_->GetNumSelectedUIElements() == 1)
			editorData_->SetEditUIElement(editorData_->GetSelectedUIElements()[0]);

		// If selection contains only components, and they have a common node, use it for editing
		if (editorData_->GetSelectedNodes().Empty() && !editorData_->GetSelectedComponents().Empty())
		{
			Node* commonNode = NULL;
			for (unsigned int i = 0; i < editorData_->GetNumSelectedComponents(); ++i)
			{
				if (i == 0)
					commonNode = editorData_->GetSelectedComponents()[i]->GetNode();
				else
				{
					if (editorData_->GetSelectedComponents()[i]->GetNode() != commonNode)
						commonNode = NULL;
				}
			}
			editorData_->SetEditNode(commonNode);
		}

		// Now check if the component(s) can be edited. If many selected, must have same type or have same edit node
		if (!editorData_->GetSelectedComponents().Empty())
		{
			if (editorData_->GetEditNode() == NULL)
			{
				StringHash compType = editorData_->GetSelectedComponents()[0]->GetType();
				bool sameType = true;
				for (unsigned int i = 1; i < editorData_->GetNumSelectedComponents(); ++i)
				{
					if (editorData_->GetSelectedComponents()[i]->GetType() != compType)
					{
						sameType = false;
						break;
					}
				}
				if (sameType)
					editorData_->SetEditComponents(editorData_->GetSelectedComponents());
			}
			else
			{
				editorData_->SetEditComponents(editorData_->GetSelectedComponents());
				editorData_->SetNumEditableComponentsPerNode(editorData_->GetNumSelectedComponents());
			}
		}

		// If just nodes selected, and no components, show as many matching components for editing as possible
		if (!editorData_->GetSelectedNodes().Empty() && editorData_->GetSelectedComponents().Empty() && editorData_->GetSelectedNodes()[0]->GetNumComponents() > 0)
		{
			unsigned int count = 0;
			for (unsigned int j = 0; j < editorData_->GetSelectedNodes()[0]->GetNumComponents(); ++j)
			{
				StringHash compType = editorData_->GetSelectedNodes()[0]->GetComponents()[j]->GetType();
				bool sameType = true;
				for (unsigned int i = 1; i < editorData_->GetNumSelectedNodes(); ++i)
				{
					if (editorData_->GetSelectedNodes()[i]->GetNumComponents() <= j || editorData_->GetSelectedNodes()[i]->GetComponents()[j]->GetType() != compType)
					{
						sameType = false;
						break;
					}
				}

				if (sameType)
				{
					++count;
					for (unsigned int i = 0; i < editorData_->GetNumSelectedNodes(); ++i)
						editorData_->AddEditComponent(editorData_->GetSelectedNodes()[i]->GetComponents()[j]);
				}
			}
			if (count > 1)
				editorData_->SetNumEditableComponentsPerNode(count);
		}

		if (editorData_->GetSelectedNodes().Empty() && editorData_->GetEditNode() != NULL)
			editorData_->AddEditNode(editorData_->GetEditNode());
		else
		{
			editorData_->SetEditNodes(editorData_->GetSelectedNodes());

			// Cannot multi-edit on scene and node(s) together as scene and node do not share identical attributes,
			// editing via gizmo does not make too much sense either
			if (editorData_->GetEditNodes().Size() > 1 && editorData_->GetEditNodes()[0] == scene_)
				editorData_->GetEditNodes().Erase(0);
		}

		if (editorData_->GetSelectedUIElements().Empty() && editorData_->GetEditUIElement() != NULL)
			editorData_->AddEditUIElement(editorData_->GetEditUIElement());
		else
			editorData_->SetEditUIElements(editorData_->GetSelectedUIElements());

		//	OnSelectionChange();
		// 		PositionGizmo();
		UpdateAttributeInspector();
		// 		UpdateCameraPreview();
	}