*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeSetComboBoxSelection(
		JNIEnv* env, jclass clazz, jint handle, jint idx) {
	if (handle) {
		IrrlichtDevice* device = (IrrlichtDevice*) handle;
		IGUIEnvironment* irrenv = device->getGUIEnvironment();
		IGUIElement* element = irrenv->getFocus();
		if (element && element->getParent()->getType() == EGUIET_COMBO_BOX) {
			IGUIComboBox* combo = (IGUIComboBox*) (element->getParent());
			core::list<IGUIElement*> children = combo->getChildren();
			core::list<IGUIElement*>::Iterator current = children.begin();
			do {
				if ((*current)->getType() == EGUIET_LIST_BOX) {
					break;
				}
				current++;
			} while (current != children.end());
			if (current == children.end()) {
				return;
			}
			IGUIListBox* list = (IGUIListBox*) *current;
			list->setSelected(idx);
			SEvent changeEvent;
			changeEvent.EventType = EET_GUI_EVENT;
			changeEvent.GUIEvent.Caller = list;
			changeEvent.GUIEvent.Element = 0;
			changeEvent.GUIEvent.EventType = EGET_LISTBOX_CHANGED;
			combo->OnEvent(changeEvent);
		}
	}
}
Ejemplo n.º 2
0
//Return the currently loot item. (Should be moved back in the gui manager)
DynamicObject* GUIGame::getActiveLootItem()
{
	vector<DynamicObject*> lootitems = DynamicObjectsManager::getInstance()->getPlayer()->getLootItems();
	IGUIListBox* guiPlayerItems =(IGUIListBox*)GUIManager::getInstance()->getGUIElement(GUIManager::LB_ID_PLAYER_ITEMS);

	s32 item=guiPlayerItems->getSelected();
	if (item>-1 && lootitems.size()>0)
		return lootitems[item];
	else
		return NULL;
}
Ejemplo n.º 3
0
//! adds a list box
IGUIListBox* CGUIEnvironment::addListBox(const core::rect<s32>& rectangle,
                                         IGUIElement* parent, s32 id,
                                         bool drawBackground)
{
	IGUIListBox* b = new CGUIListBox(this, parent ? parent : this, id, rectangle,
	                                 true, drawBackground, false);
	b->setIconFont(getBuiltInFont());
	b->drop();
	return b;

}
Ejemplo n.º 4
0
void NBEditor::load()
{
	IGUIStaticText* sidebar = state->menu->sidebar;
	IGUIEnvironment* guienv = state->device->getGUIEnvironment();

	if (sidebar) {
		sidebar->setText(L"Node Box Tool");
		IGUIStaticText* t = guienv->addStaticText(L"No node selected",
				rect<s32>(20, 30, 140, 100),
				false, true, sidebar, ENB_GUI_MAIN_MSG);
		
		IGUIListBox* lb = guienv->addListBox(rect<s32>(20, 30, 230, 128),
				sidebar, ENB_GUI_MAIN_LISTBOX, true);

		if (lb) {
			lb->setVisible(false);
			IGUIButton* b1 = guienv->addButton(rect<s32>(0, 100, 50, 125),
					lb, GUI_PROJ_NEW_BOX, L"+", L"Add a node box");
			IGUIButton* b2 = guienv->addButton(rect<s32>(60, 100, 110,125),
					lb, GUI_PROJ_DELETE_BOX, L"-", L"Delete node box");
			b1->setNotClipped(true);
			b2->setNotClipped(true);
		}

		// Create nodebox properties
		t = guienv->addStaticText(L"Properties",
				rect<s32>(0, 170, 120, 190),
				false, true, sidebar, ENB_GUI_PROP);
		t->setVisible(false);

		// Add name properties box
		guienv->addStaticText(L"Name:", rect<s32>(10, 30, 50, 50), false,
				true, t)->setNotClipped(true);
		guienv->addEditBox(L"", rect<s32>(60, 30, 210, 50), true,
				t, ENB_GUI_PROP_NAME)->setNotClipped(true);

		// Add positioning
		addXYZ(t, guienv, vector2di(10, 60),  ENB_GUI_PROP_X1);
		addXYZ(t, guienv, vector2di(10, 160), ENB_GUI_PROP_X2); // 60

		// Add buttons
		guienv->addButton(rect<s32>(30, 250, 100, 280), t, ENB_GUI_PROP_UPDATE,
				L"Update", L"")->setNotClipped(true);
		guienv->addButton(rect<s32>(110, 250, 180, 280), t, ENB_GUI_PROP_REVERT,
				L"Revert", L"")->setNotClipped(true);
	}
	load_ui();
}
Ejemplo n.º 5
0
void NBEditor::load(){
	IGUIStaticText* sidebar = GetState()->Menu()->GetSideBar();
	IGUIEnvironment* guienv = GetState()->GetDevice()->getGUIEnvironment();
	sidebar->setText(L"Node boxes");
	IGUIStaticText* t = guienv->addStaticText(L"No node selected",rect<s32>(20,30,140,100),false,true,sidebar,GUI_SIDEBAR_LABEL);
	
	if (t)
		t->setVisible(false);
	
	IGUIListBox* lb = guienv->addListBox(rect<s32>(20,30,230,128),sidebar,GUI_SIDEBAR_LISTBOX,true);

	if (lb){
		lb->setVisible(false);
		IGUIButton* b = guienv->addButton(rect<s32>(20-20,130-30,70-20,155-30),lb,GUI_PROJ_NEW_BOX,L"+",L"Add a node box");
		IGUIButton* c = guienv->addButton(rect<s32>(80-20,130-30,130-20,155-30),lb,GUI_PROJ_DELETE_BOX,L"-",L"Delete node box");
		b->setNotClipped(true);
		c->setNotClipped(true);
	}

	load_ui();
}
Ejemplo n.º 6
0
void NBEditor::load_ui()
{
	IGUIStaticText *sidebar = state->menu->sidebar;

	if (!sidebar) {
		return;
	}

	IGUIEnvironment *guienv = state->device->getGUIEnvironment();
	Node *node = state->project->GetCurrentNode();
	if (!node) {
		sidebar->getElementFromId(ENB_GUI_MAIN_MSG)->setVisible(true);
		sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX)->setVisible(false);
		sidebar->getElementFromId(ENB_GUI_PROP)->setVisible(false);
	} else {
		IGUIListBox *lb = (IGUIListBox *) sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);		
		sidebar->getElementFromId(ENB_GUI_MAIN_MSG)->setVisible(false);
		sidebar->getElementFromId(ENB_GUI_PROP)->setVisible(false);

		if (lb) {
			lb->clear();
			lb->setVisible(true);
			std::vector<NodeBox*> & boxes = node->boxes;
			for (std::vector<NodeBox*>::const_iterator it = boxes.begin();
					it != boxes.end();
					++it) {
				lb->addItem(narrow_to_wide((*it)->name).c_str());
			}
			lb->setSelected(lb->getListItem(node->GetId()));
		}

		fillProperties();
	}
}
Ejemplo n.º 7
0
void NBEditor::load_ui(){
	IGUIStaticText* sidebar = GetState()->Menu()->GetSideBar();
	IGUIEnvironment* guienv = GetState()->GetDevice()->getGUIEnvironment();
	Node* node = GetState()->project->GetCurrentNode();
	if (!node){
		sidebar->getElementFromId(GUI_SIDEBAR_LABEL)->setVisible(true);
		sidebar->getElementFromId(GUI_SIDEBAR_LISTBOX)->setVisible(false);
	}else{
		IGUIListBox* lb = (IGUIListBox*) sidebar->getElementFromId(GUI_SIDEBAR_LISTBOX);		
		sidebar->getElementFromId(GUI_SIDEBAR_LABEL)->setVisible(false);

		if (lb){
			lb->clear();
			lb->setVisible(true);
			for (int i = 0;i<NODEB_MAX;i++){
				NodeBox* box = node->GetNodeBox(i);
				if (box){
					size_t origsize = strlen(box->name.c_str()) + 1;
					static wchar_t wcstring[1024];
					mbstowcs(wcstring, box->name.c_str(), origsize);
					wcscat(wcstring, L"");
					lb->addItem(wcstring);
				}
			}
			lb->setSelected(lb->getListItem(node->GetId()));
		}
	}
}
Ejemplo n.º 8
0
//Update the items list in gameplay
void GUIGame::updateItemsList()
{
	IGUIImage* guiPlayerLootImage = (IGUIImage*)GUIManager::getInstance()->getGUIElement(GUIManager::IMG_LOOT);
	IGUIListBox* guiPlayerItems =(IGUIListBox*)GUIManager::getInstance()->getGUIElement(GUIManager::LB_ID_PLAYER_ITEMS);
    guiPlayerItems->clear();
   
	vector<DynamicObject*> lootitems = DynamicObjectsManager::getInstance()->getPlayer()->getLootItems();
	std::sort(lootitems.begin(), lootitems.end());

    
	for(int i = 0; i<(int)lootitems.size(); i++)
	{
		//internalname is the Alias name of the object. If undefined it use the internal name
		guiPlayerItems->addItem(stringw(lootitems[i]->internalname).c_str());
	}

	if (guiPlayerItems->getSelected()<0)
	{
		ITexture* info_none = driver->getTexture("../media/editor/info_none.jpg");
		guiPlayerLootImage->setImage(info_none);
		((IGUIStaticText*)guienv->getRootGUIElement()->getElementFromId(GUIManager::TXT_ID_LOOT_DESCRIPTION,true))->setText(L"");
	}
}
Ejemplo n.º 9
0
bool NBEditor::OnEvent(const irr::SEvent &event){
	if (event.EventType == EET_GUI_EVENT){
		if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED){
			switch (event.GUIEvent.Caller->getID()){
			case GUI_PROJ_NEW_BOX:
				{
					Node* node = GetState()->project->GetCurrentNode();
					if (node){
						printf("Clicked add nb!\n");
						node->addNodeBox();
						load_ui();
					}
				}
				break;
			case GUI_PROJ_DELETE_BOX:
				{
					Node* node = GetState()->project->GetCurrentNode();
					IGUIListBox* lb = (IGUIListBox*) GetState()->Menu()->GetSideBar()->getElementFromId(GUI_SIDEBAR_LISTBOX);	
					if (node && node->GetNodeBox(lb->getSelected())){
						printf("Clicked delete nb!\n");
						node->deleteNodebox(lb->getSelected());
						load_ui();
					}
				}
				break;
			}
		}else if (event.GUIEvent.EventType == EGET_LISTBOX_CHANGED){
			Node* node = GetState()->project->GetCurrentNode();
			IGUIListBox* lb = (IGUIListBox*) GetState()->Menu()->GetSideBar()->getElementFromId(GUI_SIDEBAR_LISTBOX);	
			if (node && lb && node->GetNodeBox(lb->getSelected())){
				node->select(lb->getSelected());
				load_ui();
			}
					
		}
	}

	return false;
}
Ejemplo n.º 10
0
//Return the current active player item
stringc GUIGame::getActivePlayerItem()
{
	IGUIListBox* guiPlayerItems =(IGUIListBox*)GUIManager::getInstance()->getGUIElement(GUIManager::LB_ID_PLAYER_ITEMS);

    return stringc(guiPlayerItems->getListItem(guiPlayerItems->getSelected()));
}
Ejemplo n.º 11
0
bool EditorEventReceiver::OnEvent(const SEvent& event)
{
	if (event.EventType == irr::EET_KEY_INPUT_EVENT)
	{
		KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
		if (KeyIsDown[KEY_ESCAPE])
		{ //Return to the main menu
			delete Universe::instance->gameName;
			Universe::instance->gameName = NULL;
			Universe::instance->state = NextLevel;
		}
	}
	else if (event.EventType == EET_GUI_EVENT)
	{
		s32 eventCallerId = event.GUIEvent.Caller->getID();

		switch(event.GUIEvent.EventType)
		{
			case EGET_BUTTON_CLICKED:
				if (eventCallerId >= MapCellSelectWindowToggleButton && eventCallerId <= CharacterSelectWindowToggleButton)
				{
					if (!Universe::instance->guienv->getRootGUIElement()->getElementFromId(eventCallerId - 10))
					{ //Window is not created
						wchar_t wstr[512]; //Buffer
						MapObject** mapObjects; //General pointer to any MapObjects in GameResources. Is defined in the switch below
						int mapObjectsCount; //'mapObjects' count
						int brushIndex; //Current brush (0: MapCell, 1:NPC, 2:Item, 3:Static, 4:Character)

						brushIndex = eventCallerId - MapCellSelectWindowToggleButton;

						switch (eventCallerId)
						{
							case MapCellSelectWindowToggleButton:
								//Define specific title
								wcscpy(wstr, L"Map cell selection");
								//Define that we would use MapCells as MapObjects
								mapObjects = (MapObject**)Universe::instance->game->resources->mapCells;
								mapObjectsCount = Universe::instance->game->resources->mapCellsCount;
								break;
							case NPCSelectWindowToggleButton:
								//Define specific title
								wcscpy(wstr, L"NPC selection");
								//Define that we would use NPCs as MapObjects
								mapObjects = (MapObject**)Universe::instance->game->resources->npcs;
								mapObjectsCount = Universe::instance->game->resources->npcsCount;
								break;
							case ItemSelectWindowToggleButton:
								//Define specific title
								wcscpy(wstr, L"Item selection");
								//Define that we would use Items as MapObjects
								mapObjects = (MapObject**)Universe::instance->game->resources->items;
								mapObjectsCount = Universe::instance->game->resources->itemsCount;
								break;
							case StaticSelectWindowToggleButton:
								//Define specific title
								wcscpy(wstr, L"Static selection");
								//Define that we would use Statics as MapObjects
								mapObjects = (MapObject**)Universe::instance->game->resources->statics;
								mapObjectsCount = Universe::instance->game->resources->staticsCount;
								break;
							case CharacterSelectWindowToggleButton:
								//Define specific title
								wcscpy(wstr, L"Character selection");
								//Define that we would use Characters as MapObjects
								mapObjects = (MapObject**)Universe::instance->game->resources->characters;
								mapObjectsCount = Universe::instance->game->resources->charactersCount;
								break;
						}

						char** tags;
						int tagsCount;
						IGUIWindow* wnd1;

						//Create window with the specific title 'wstr'
						wnd1 = Universe::instance->guienv->addWindow(rect< s32 >(224, 64, 760, 536), false, wstr, 0, eventCallerId - 10);

						//ListBox for MapObjects
						IGUIListBox* molb = Universe::instance->guienv->addListBox(rect< s32 >(128, 64, 128 + 224, 64 + 320), wnd1, eventCallerId + 5, true);
						for (int i = 0; i < mapObjectsCount; i++)
						{
							swprintf(wstr, L"[%d] ", mapObjects[i]->id);
							mbstowcs(wstr + wcslen(wstr), mapObjects[i]->name, 511);
							molb->addItem(wstr);
							if (Universe::instance->brush[brushIndex] == mapObjects[i])
								molb->setSelected(i); //Select item in list that was used last time in this MapObject list
						}

						tagsCount = Universe::instance->game->resources->GetMapObjectsTags(mapObjects, mapObjectsCount, tags);
						if (tagsCount > 0)
						{ //Tags exists. Therefore we're to put 'All' CheckBox
							Universe::instance->guienv->addCheckBox(true, rect< s32 >(32, 64, 32 + 92, 64 + 16), wnd1, -1, L"All");
							//IGUIElement* container = Universe::instance->guienv->addModalScreen(wnd1);
							//IGUIElement* container = Universe::instance->guienv->addScrollBar(false, rect< s32 >(16, 64, 16 + 92, 64 + 256), wnd1, -1);
							for (int i = 0; i < tagsCount; i++)
							{
								mbstowcs(wstr, tags[i], 511);
								Universe::instance->guienv->addCheckBox(true, rect< s32 >(32, 80 + 16 * i, 32 + 92, 80 + 16 * (i + 1)), wnd1, -1, wstr);
							}
							delete[] tags;
						}

						Universe::instance->guienv->addButton(rect< s32 >(415, 420, 415 + 96, 420 + 32), wnd1, eventCallerId + 10, L"OK", L"Select current map object");
					}
					//Focus just created MapObject selection window (or focus old window)
					Universe::instance->guienv->setFocus(Universe::instance->guienv->getRootGUIElement()->getElementFromId(eventCallerId - 10));
				}
				else if (eventCallerId >= MapCellSelectWindowOKButton && eventCallerId <= CharacterSelectWindowOKButton)
				{
					IGUIListBox* lb = (IGUIListBox*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(eventCallerId - 20)->getElementFromId(eventCallerId - 5);
					if (lb->getSelected() >= 0)
					{
						int mapObjectId;
						swscanf(lb->getListItem(lb->getSelected()), L"[%d]", &mapObjectId);
						switch (eventCallerId)
						{
							case MapCellSelectWindowOKButton:
								Universe::instance->brush[0] = Universe::instance->game->resources->GetMapCell(mapObjectId);
								break;
							case NPCSelectWindowOKButton:
								Universe::instance->brush[1] = Universe::instance->game->resources->GetNPC(mapObjectId);
								break;
							case ItemSelectWindowOKButton:
								Universe::instance->brush[2] = Universe::instance->game->resources->GetItem(mapObjectId);
								break;
							case StaticSelectWindowOKButton:
								Universe::instance->brush[3] = Universe::instance->game->resources->GetStatic(mapObjectId);
								break;
							case CharacterSelectWindowOKButton:
								Universe::instance->brush[4] = Universe::instance->game->resources->GetCharacter(mapObjectId);
								break;
						}
						//Close parent window (MapObject selection window)
						lb->getParent()->remove();
					}
				}
				else
				{
					switch (eventCallerId)
					{
						case LocationsEditButton:
						{
							IGUIWindow* wnd;
							wnd = (IGUIWindow*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow);
							if (wnd)
							{
								wnd->remove();
								Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox)->setEnabled(true);
							}
							else
							{
								wnd = Universe::instance->guienv->addWindow(rect< s32 >(Universe::instance->toolbarWidth, 0, Universe::instance->toolbarWidth + 242, 184), false, L"Locations edit", 0, LocationsEditWindow);
								wnd->getCloseButton()->setEnabled(false);
								wnd->getCloseButton()->setVisible(false);
								Universe::instance->guienv->addEditBox(Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox)->getText(), rect< s32 >(32, 32, 208, 56), true, wnd, LocationNameEditBox);
								Universe::instance->guienv->addEditBox(L"64", rect< s32 >(32, 80, 112, 104), true, wnd, LocationWidthEditBox);
								Universe::instance->guienv->addEditBox(L"64", rect< s32 >(128, 80, 208, 104), true, wnd, LocationHeightEditBox);
								Universe::instance->guienv->addButton(rect< s32 >(32, 128, 32 + 48, 160), wnd, LocationsEditDeleteButton, L"Delete", L"Delete current location");
								Universe::instance->guienv->addButton(rect< s32 >(96, 128, 96 + 48, 160), wnd, LocationsEditSaveButton, L"Save", L"Apply settings to the current location")->setEnabled(false);
								Universe::instance->guienv->addButton(rect< s32 >(160, 128, 160 + 48, 160), wnd, LocationsEditAddButton, L"Save as", L"Apply settings to the new location");
								Universe::instance->guienv->setFocus(wnd);
								Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox)->setEnabled(false);
							}
							break;
						}
						case LocationsEditSaveButton:
						{
							char str[256];
							int width, height;
							wcstombs(str, Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->getElementFromId(LocationNameEditBox)->getText(), 256);
							//swscanf(Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->getElementFromId(LocationWidthEditBox)->getText(), L"%d", &width);
							//swscanf(Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->getElementFromId(LocationHeightEditBox)->getText(), L"%d", &height);
							delete Universe::instance->currentLocation->name;
							Universe::instance->currentLocation->name = new char[strlen(str) + 1];
							strcpy(Universe::instance->currentLocation->name, str);
							Universe::instance->currentLocation->Update();
							//Update ComboBox
								// ((IGUIComboBox*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox))->updateItem(L"sd");
							//Close locations edit Window and enable locations ComboBox
							Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->remove();
							Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox)->setEnabled(true);
							break;
						}
						case LocationsEditAddButton:
						{
							char str[256];
							int width, height;
							wcstombs(str, Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->getElementFromId(LocationNameEditBox)->getText(), 255);
							swscanf(Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->getElementFromId(LocationWidthEditBox)->getText(), L"%d", &width);
							swscanf(Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->getElementFromId(LocationHeightEditBox)->getText(), L"%d", &height);
							//Add location to DB and spawn it
							Universe::instance->game->data->LocationSpawn(Universe::instance->game->data->AddLocation(str, width, height), Editor);
							//Add location to the locations list
							((IGUIComboBox*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox))->addItem(Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->getElementFromId(LocationNameEditBox)->getText());
							//Close locations edit Window and enable locations ComboBox
							Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->remove();
							Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox)->setEnabled(true);
							break;
						}
						case LocationsEditDeleteButton:
						{
							IGUIComboBox* lcb = (IGUIComboBox*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox);
							if (lcb->getItemCount() > 1)
							{ //It's not the last location
								//Delete location from DB and unspawn it
								Universe::instance->game->data->LocationDelete(lcb->getSelected());
								//Delete location from the locations list
								lcb->removeItem(lcb->getSelected());
								//Select another location
								lcb->setSelected(0);
								//Close locations edit Window and enable locations ComboBox
								Universe::instance->guienv->getRootGUIElement()->getElementFromId(LocationsEditWindow)->remove();
								Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox)->setEnabled(true);
							}
							break;
						}
					}
				}
				break;
			case EGET_COMBO_BOX_CHANGED:
				switch (eventCallerId)
				{
					case LocationsComboBox:
						Universe::instance->render->smgr->clear();
						Universe::instance->SetLocation(Universe::instance->game->data->locations[((IGUIComboBox*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(LocationsComboBox))->getSelected()]);
						//The code below (3 lines) does not prevent exception during loading another locations due to camera test mode
						ISceneNode* camPos = Universe::instance->render->smgr->addEmptySceneNode();
						camPos->setPosition(vector3df(50,50,10));
						ICameraSceneNode *camera = Universe::instance->render->smgr->addCameraSceneNode(0, vector3df(50,50,10), vector3df(50,0,40));
						Universe::instance->DrawScene();
						break;
				}
				break;
			case EGET_TAB_CHANGED:
				switch (eventCallerId)
				{
					case MapObjectsTabControl:
						Universe::instance->brushIndex = ((IGUITabControl*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(ToolBarWindow)->getElementFromId(MapObjectsTabControl))->getActiveTab();
						break;
				}
				break;
			case EGET_CHECKBOX_CHANGED:
				/*
				IGUIListBox* molb = Universe::instance->guienv->addListBox(rect< s32 >(128, 64, 128 + 224, 64 + 320), wnd1, eventCallerId + 5, true);
				for (int i = 0; i < mapObjectsCount; i++)
				{
					swprintf(wstr, L"[%d] ", mapObjects[i]->id);
					mbstowcs(wstr + wcslen(wstr), mapObjects[i]->name, 511);
					molb->addItem(wstr);
					if (Universe::instance->brush[brushIndex] == mapObjects[i])
						molb->setSelected(i); //Select item in list that was used last time in this MapObject list
				}
				*/
				//Filter
				//Universe::instance->game->resources->FilterByTag<MapCell>(Universe::instance->game->resources->mapCells, Universe::instance->game->resources->mapCellsCount, , );
				break;
		}
	}

	return false;
}
Ejemplo n.º 12
0
void EventHandler::navigateDown(const int playerID, Input::InputType type, const bool pressedDown)
{
    //std::cout << "Naviagte down!\n";

    IGUIElement *el = NULL, *closest = NULL;

    if (type == Input::IT_STICKBUTTON && !pressedDown)
        return;

    Widget* w = GUIEngine::getFocusForPlayer(playerID);
    if (w != NULL)
    {
        el = w->getIrrlichtElement();
    }
    //std::cout << "!!! Player " << playerID << " navigating down of " << w->m_element->getID() << std::endl;

    // list widgets are a bit special, because up/down keys are also used
    // to navigate between various list items, not only to navigate between
    // components
    if (w != NULL && w->m_type == WTYPE_LIST)
    {
        ListWidget* list = (ListWidget*)w;

        const bool stay_within_list = list->getSelectionID() < list->getItemCount()-1;

        if (stay_within_list)
        {
            list->setSelectionID(list->getSelectionID()+1);
            return;
        }
        else
        {
            list->setSelectionID(-1);
        }
    }

    if (w != NULL && w->m_tab_down_root != -1)
    {
        Widget* down = GUIEngine::getWidget( w->m_tab_down_root );
        assert(down != NULL);
        el = down->getIrrlichtElement();

        if (el == NULL)
        {
            std::cerr << "WARNING : m_tab_down_root is set to an ID for which I can't find the widget\n";
            return;
        }
    }

    // don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog
    if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyIrrChild(el))
    {
        el = NULL;
    }

    bool found = false;

    if (el != NULL && el->getTabGroup() != NULL)
    {
        // if the current widget is e.g. 5, search for widget 6, 7, 8, 9, ..., 15 (up to 10 IDs may be missing)
        for (int n=1; n<10 && !found; n++)
        {
            closest = GUIEngine::getGUIEnv()->getRootGUIElement()->getElementFromId(el->getTabOrder() + n, true);

            if (closest != NULL && Widget::isFocusableId(closest->getID()))
            {

                Widget* closestWidget = GUIEngine::getWidget( closest->getID() );
                if (playerID != PLAYER_ID_GAME_MASTER && !closestWidget->m_supports_multiplayer) return;

                // if a dialog is shown, restrict to items in the dialog
                if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(closestWidget))
                {
                    continue;
                }

                if (NAVIGATION_DEBUG)
                {
                    std::cout << "Navigating down to " << closestWidget->getID() << "\n";
                }

                assert( closestWidget != NULL );
                closestWidget->setFocusForPlayer(playerID);

                // another list exception : when entering a list, select the first item
                if (closestWidget->m_type == WTYPE_LIST)
                {
                    IGUIListBox* list = (IGUIListBox*)(closestWidget->m_element);
                    assert(list != NULL);

                    list->setSelected(0);
                }

                found = true;
            }
        } // end for
    }

    if (!found)
    {

        if (NAVIGATION_DEBUG) std::cout << "Navigating down : wrap around\n";

        // select the first widget
        Widget* firstWidget = NULL;

        if (ModalDialog::isADialogActive())
        {
            //std::cout <<  "w = ModalDialog::getCurrent()->getFirstWidget();\n";
            firstWidget = ModalDialog::getCurrent()->getFirstWidget();
        }
        else
        {
            Screen* screen = GUIEngine::getCurrentScreen();
            if (screen == NULL) return;
            firstWidget = screen->getFirstWidget();
        }

        if (firstWidget != NULL)  firstWidget->setFocusForPlayer(playerID);
    }
}
Ejemplo n.º 13
0
bool NBEditor::OnEvent(const irr::SEvent &event) {
	if (event.EventType == EET_GUI_EVENT) {
		if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) {
			switch (event.GUIEvent.Caller->getID()) {
			case GUI_PROJ_NEW_BOX: {
				Node* node = state->project->GetCurrentNode();
				if (node) {
					node->addNodeBox();
					load_ui();
				}
				break;
			}
			case GUI_PROJ_DELETE_BOX: {
				Node* node = state->project->GetCurrentNode();
				IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);	
				if (node && node->GetNodeBox(lb->getSelected())){
					node->deleteNodebox(lb->getSelected());
					load_ui();
				}
				break;
			}
			case ENB_GUI_PROP_REVERT:
				fillProperties();
				break;
			case ENB_GUI_PROP_UPDATE:
				updateProperties();
				break;
			}
		} else if (event.GUIEvent.EventType == EGET_LISTBOX_CHANGED) {
			Node* node = state->project->GetCurrentNode();
			IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);	
			if (node && lb && node->GetNodeBox(lb->getSelected())){
				node->select(lb->getSelected());
			}
			load_ui();
		}
	} else if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) {
		if (event.KeyInput.Key == KEY_RETURN) {
			updateProperties();
			return false;
		}

		if (
				state->device->getGUIEnvironment()->getFocus() &&
				state->device->getGUIEnvironment()->getFocus()->getType() == EGUIET_EDIT_BOX) {
			return false;
		}

		if (event.KeyInput.Key == KEY_INSERT) {
			Node *node = state->project->GetCurrentNode();
			if (node) {
				node->addNodeBox();
				load_ui();
			}
		} else if (event.KeyInput.Key == KEY_DELETE) {
			Node* node = state->project->GetCurrentNode();
			IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);
			if (node && node->GetNodeBox(lb->getSelected())) {
				node->deleteNodebox(lb->getSelected());
			}
			load_ui();
		} else if (event.KeyInput.Key == KEY_DOWN) {
			IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);
			Node* node = state->project->GetCurrentNode();
			if (node) {
				int idx = node->GetId();
				if (lb && idx < node->boxes.size() - 1){
					node->select(idx + 1);
				}
			}
			load_ui();
		} else if (event.KeyInput.Key == KEY_UP) {
			IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);
			Node* node = state->project->GetCurrentNode();
			if (node) {
				int idx = node->GetId();
				if (lb && idx > 0) {
					node->select(idx - 1);
				}
			}
			load_ui();
		}
	}
	return false;
}