示例#1
0
void ResourceWindow::selectPawn(const std::string& name)
{
	Fl_Tree_Item* tree = getTreeFromName("pawn");

	for (int c = 0; c < tree->children(); c++)
	{
		Fl_Tree_Item* child = tree->child(c);
		if (strcmp(child->label(), name.c_str()) == 0)
		{
			if (child->is_selected())
				return;
			resourceTree->deselect_all();
			child->select();
			resourceTree->redraw();
			return;
		}
	}

	tree = getTreeFromName("character");
	for (int c = 0; c < tree->children(); c++)
	{
		Fl_Tree_Item* child = tree->child(c);
		if (strcmp(child->label(), name.c_str()) == 0)
		{
			if (child->is_selected())
				return;
			resourceTree->deselect_all();
			child->select();
			resourceTree->redraw();
			return;
		}
	}

}
示例#2
0
	int RemoveAIButton::handle(int evt) {
		if(evt == 2) {
			if(appended_ai_tree) 
			{
				std::shared_ptr<AppendAIPatch> aip = std::dynamic_pointer_cast<AppendAIPatch>(mods->get("aip"));
				Fl_Tree_Item* first = appended_ai_tree->first();

				if(first->is_selected()) {
					for(int child = 0; child < first->children(); child++) {
						delete (int*)(first->child(child)->user_data());
					}
					first->clear_children();
					aip->undo();
					aip->set_appended_ai(AppendAIPatch::entity_storage());
					mods_window->redraw();
					return Fl_Button::handle(evt);
				}

				for(int pos = 0; pos < first->children(); pos++)
				{
					if(!first->child(pos)->is_selected()) {
						continue;
					}

					Fl_Tree_Item* selected = first->child(pos);

					int appended_idx = *(int*)selected->user_data();

					//correct indices after removal
					for(int child = 0; child < first->children(); child++) {
						int* idx = (int*)(first->child(child)->user_data());
						if(*idx > appended_idx) {
							(*idx)--;
						}
					}

					AppendAIPatch::entity_storage appended = aip->appended_ai();
					appended.erase(appended.begin()+appended_idx);
					aip->set_appended_ai(appended);
					
					delete (int*)(selected->user_data());
					appended_ai_tree->remove(selected);
				}

				mods_window->redraw();
				if(aip->appended_ai().empty()) {
					aip->undo();
				}
			}
		}

		return Fl_Button::handle(evt);
	}
示例#3
0
int ResourceWindow::handle( int event )
{
	int ret = Fl_Group::handle(event);
	std::string dndText;
	switch ( event ) {
		case FL_DND_RELEASE:
			//LOG("DND Release");
			ret = 1;
			break;
		case FL_DND_ENTER:          // return(1) for these events to 'accept' dnd
			//LOG("DND Enter");
			//Fl::belowmouse(this); // send the leave events first
			//Fl::focus(this);
			//handle(FL_FOCUS);		
			ret = 1;
			break;
		case FL_DND_DRAG:			
			ret = 1;
			break;
		case FL_DND_LEAVE:
			//LOG("DND Leave");
			ret = 1;
			break;	  
		case FL_PASTE:              // handle actual drop (paste) operation		   
			{
				//label(Fl::event_text());
				//fprintf(stderr, "PASTE: %s\n", Fl::event_text());
				//LOG("PASTE: %s\n", Fl::event_text());
				dndText = Fl::event_text();
				bool hasAsset = processedDragAndDrop(dndText);
				ret = 1;				
			}
			break;	
		case FL_PUSH:  
		{// do 'copy/dnd' when someone clicks on box
			if (Fl::event_button() == 2)
			{
				LOG("press middle button");
				LOG("lastClickedItemPath = %s",lastClickedItemPath.c_str());
				Fl_Tree_Item* lastItem = resourceTree->find_item(lastClickedItemPath.c_str());	
				if (lastItem)
				{
					const char* itemType = (const char*)lastItem->user_data();
					bool sendDND = false;
					std::string dndMsg = "";
					if (strcmp(itemType, "skeleton") == 0)
					{
						std::string skName = lastItem->label();
						dndMsg = "SKELETON:";
						dndMsg += skName;
						sendDND = true;
					}
					else if (strcmp(itemType, "pawn") == 0)
					{
						dndMsg = "PAWN:dummy";
						sendDND = true;
					}
					
					//Fl::copy("message",7,0);
					if (sendDND)
					{
						Fl::copy(dndMsg.c_str(),dndMsg.length(),0);
						Fl::dnd();
					}					
					ret = 1;
				}			
			}			
			break;
		}
		case FL_KEYDOWN:  
		{
		  switch (Fl::event_key())
		  {
			case FL_Delete:
				{
					// check pawns and characters for selection
					Fl_Tree_Item* tree = getTreeFromName("pawn");
					int numChildren = tree->children();
					for (int c = 0; c < numChildren; c++)
					{
						Fl_Tree_Item* child = tree->child(c);
						if (child->is_selected())
						{
							const char* name = child->label();
							int confirm = fl_choice(vhcl::Format("Are you sure you want to delete '%s'?",name).c_str(), "No", "Yes", NULL);
							if (confirm == 0)
								return 0;
							SmartBody::SBScene::getScene()->removePawn(name);
							updateGUI();
							return 1;
						}
					}

					tree = getTreeFromName("character");
					numChildren = tree->children();
					for (int c = 0; c < numChildren; c++)
					{
						Fl_Tree_Item* child = tree->child(c);
						if (child->is_selected())
						{
							const char* name = child->label();
							int confirm = fl_choice(vhcl::Format("Are you sure you want to delete '%s'?",name).c_str(), "No", "Yes", NULL);
							if (confirm == 0)
								return 0;
							SmartBody::SBScene::getScene()->removeCharacter(name);
							updateGUI();
							return 1;
						}
					}
				
				}
				break;
			default:
				break;
		  }
		}
	}
	return ret;
}