*/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);
		}
	}
}
示例#2
0
bool CGUIModalScreen::isVisible() const
{
    // any parent invisible?
    IGUIElement * parentElement = getParent();
    while ( parentElement )
    {
        if ( !parentElement->isVisible() )
            return false;
        parentElement = parentElement->getParent();
    }

    // if we have no children then the modal is probably abused as a way to block input
    if ( Children.empty() )
    {
        return IGUIElement::isVisible();
    }

    // any child visible?
    bool visible = false;
    core::list<IGUIElement*>::ConstIterator it = Children.begin();
    for (; it != Children.end(); ++it)
    {
        if ( (*it)->isVisible() )
        {
            visible = true;
            break;
        }
    }
    return visible;
}
示例#3
0
/*
Function hasModalDialog() checks if we currently have a modal dialog open.
*/
bool hasModalDialog()
{
	IGUIEnvironment* env = Device->getGUIEnvironment();
	IGUIElement * focused = env->getFocus();
	while ( focused )
	{
		if ( focused->isVisible() && focused->hasType(EGUIET_MODAL_SCREEN) )
			return true;
		focused = focused->getParent();
	}
	return false;
}
示例#4
0
void SSGUIStatusBar::draw()
{
	IVideoDriver *driver = Environment->getVideoDriver();

	if (!IsVisible)
		return;

	if (Background)
	{
		driver->draw2DImage(Background, AbsoluteRect.UpperLeftCorner, rect<s32>(position2d<s32>(0,0), Background->getOriginalSize()), 0, SColor(255,255,255,255), true);

		IGUIElement *ElementUnderCursor = Environment->getRootGUIElement()->getElementFromPoint(CursorControl->getPosition());

		s32 index = -1;
		
		while (ElementUnderCursor && ElementUnderCursor != this && ElementUnderCursor != Environment->getRootGUIElement() && index == -1)
		{
			index = RegisteredElements.binary_search(ElementUnderCursor);

			if (ElementUnderCursor != this && index == -1)
				ElementUnderCursor = ElementUnderCursor->getParent();
		}

		if (index >= 0 || ElementUnderCursor == this)
		{
			if (ElementUnderCursor->getType() == EGUIET_BUTTON)
				Label.Text = ((SSGUIButton*)ElementUnderCursor)->getHelpText().c_str();
			if (ElementUnderCursor->getType() == EGUIET_SCROLL_BAR)
				Label.Text = ((SSGUIScrollBar*)ElementUnderCursor)->getHelpText().c_str();
			if (ElementUnderCursor->getType() == EGUIET_WINDOW)
				Label.Text = ((SSGUISatelliteInfoWindow*)ElementUnderCursor)->getHelpText().c_str();
			if (ElementUnderCursor == this)
				Label.Text = HelpText.c_str();

			if (Label.Text)
				Label.Font->draw(Label.Text, Label.Rect, Label.Color, false, true);
		}
		else
			Label.Text = 0;
	}
}
示例#5
0
bool ClientEventReceiver::OnEvent(const SEvent& event)
{
	if (event.EventType == irr::EET_KEY_INPUT_EVENT)
	{
		KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
		if (event.KeyInput.Key >= KEY_KEY_1 && event.KeyInput.Key <= KEY_KEY_9)
		{
			if (Universe::instance->guienv->getFocus() != Universe::instance->guienv->getRootGUIElement()->getElementFromId(ChatBox)->getElementFromId(ChatInputEditBox))
			{
				IGUIElement* hkb = Universe::instance->guienv->getRootGUIElement()->getElementFromId(HotkeyBar);
				CGUIButton* btn = ((IGUIIconTable*)hkb)->getButtonAt(event.KeyInput.Key - KEY_KEY_1);
				if (btn)
				{
					SEvent clickEvent;
					clickEvent.EventType = EET_GUI_EVENT;
					clickEvent.GUIEvent.EventType = EGET_BUTTON_CLICKED;
					clickEvent.GUIEvent.Caller = btn;
					Universe::instance->render->device->postEventFromUser(clickEvent);
				}
			}
		}
		else if (KeyIsDown[KEY_ESCAPE])
		{ //Return to the main menu
			delete Universe::instance->login;
			delete Universe::instance->password;
			Universe::instance->login = NULL;
			Universe::instance->password = NULL;
			Universe::instance->state = NextLevel;
		}
		else if (KeyIsDown[KEY_RETURN])
		{
			Universe::instance->guienv->setFocus(Universe::instance->guienv->getRootGUIElement()->getElementFromId(ChatBox)->getElementFromId(ChatInputEditBox));
		}
	}
	else if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
	{
		for (s32 i = 0; i < EMIE_COUNT; ++i)
            Mouse[i] = i == event.MouseInput.Event;
		IGUIElement* guiElement = Universe::instance->guienv->getRootGUIElement()->getElementFromPoint(vector2di(event.MouseInput.X, event.MouseInput.Y));
		if (guiElement != NULL)
		{ //Mouse is in a window area
			if (guiElement->getID() != 0) //Mouse is on GUI element
				return false;
		}
		else //Mouse is not in a window area
			return false;
		if (Mouse[EMIE_LMOUSE_PRESSED_DOWN])
		{
			CurrentMapObject<MapObject>* targetCurrentMapObject;

			CGUIButton* leftMouseBind = ((IGUIIconTable*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(HotkeyBar))->selectedButton;
			if (leftMouseBind)
			{
				int targetType;
				char outPacket[256];
				
				if (targetCurrentMapObject = (CurrentMapObject<MapObject>*)Universe::instance->render->GetCurrentMapObjectUnderCursor<CurrentNPC>(Universe::instance->currentLocation->currentNPCs, Universe::instance->currentLocation->currentNPCsCount))
				{
					targetType = 0;
				}
				else if (targetCurrentMapObject = (CurrentMapObject<MapObject>*)Universe::instance->render->GetCurrentMapObjectUnderCursor<CurrentCharacter>(Universe::instance->currentLocation->currentCharacters, Universe::instance->currentLocation->currentCharactersCount))
				{
					targetType = 3;
				}
				else
					targetType = -1;

				CreatePacket(outPacket, SkillUse, "%i%b%i", leftMouseBind->currentGameObject->id, targetType, targetCurrentMapObject ? targetCurrentMapObject->id : 0);
				Universe::instance->connectSocket->Send(outPacket);
			}
		}
		else if (Mouse[EMIE_RMOUSE_PRESSED_DOWN])
		{
			CurrentMapObject<MapObject>* targetCurrentMapObject;
			if (targetCurrentMapObject = (CurrentMapObject<MapObject>*)Universe::instance->render->GetCurrentMapObjectUnderCursor<CurrentNPC>(Universe::instance->currentLocation->currentNPCs, Universe::instance->currentLocation->currentNPCsCount))
			{
				char outPacket[256];

				CreatePacket(outPacket, DialogOpen, "%i%i", targetCurrentMapObject->id, 0);
				Universe::instance->connectSocket->Send(outPacket);
			}
			else if (targetCurrentMapObject = (CurrentMapObject<MapObject>*)Universe::instance->render->GetCurrentMapObjectUnderCursor<CurrentItem>(Universe::instance->currentLocation->currentItems, Universe::instance->currentLocation->currentItemsCount))
			{
				char outPacket[256];

				f32 distance = vector2d<f32>(targetCurrentMapObject->x, targetCurrentMapObject->y).getDistanceFrom(vector2d<f32>(Universe::instance->currentCharacter->x, Universe::instance->currentCharacter->y));
				if (distance < 3.0f)
				{
					CreatePacket(outPacket, ItemPickUp, "%i", targetCurrentMapObject->id);
				}
				else
				{ //Emulate character's move request to this item
					double targetX, targetY;
					//TODO: other angles
					targetX = targetCurrentMapObject->x + (targetCurrentMapObject->x < Universe::instance->currentCharacter->x ? 1.0f : -1.0f);
					targetY = targetCurrentMapObject->y + (targetCurrentMapObject->y < Universe::instance->currentCharacter->y ? 1.0f : -1.0f);
					CreatePacket(outPacket, Move, "%f%f", targetX, targetY);
				}

				Universe::instance->connectSocket->Send(outPacket);
			}
			else
			{ //Move
				char outPacket[256];
				vector2d<f32> clickPos = Universe::instance->render->MouseCoordToWorldCoord();
				if (clickPos.X > 0 && clickPos.X < Universe::instance->currentLocation->width && clickPos.Y > 0 && clickPos.Y < Universe::instance->currentLocation->height)
					if (Universe::instance->currentLocation->mask[(int)clickPos.Y][(int)clickPos.X] == Free) //TODO: see 'void Location::SpawnStatic(CurrentStatic* currentStatic)'
					{
						CreatePacket(outPacket, Move, "%f%f", clickPos.X, clickPos.Y);
						Universe::instance->connectSocket->Send(outPacket);
					}
			}
		}
		else if (Mouse[EMIE_MOUSE_WHEEL])
		{
			f32 cameraNextY = Universe::instance->cameraY + event.MouseInput.Wheel * 5.0f;
			if (cameraNextY > 5.0f && cameraNextY < 200.0f)
				Universe::instance->cameraY = cameraNextY;
		}
	}
	else if (event.EventType == EET_GUI_EVENT)
	{
		s32 eventCallerId = event.GUIEvent.Caller->getID();
		IGUIElement* eventCaller = event.GUIEvent.Caller;

		switch(event.GUIEvent.EventType)
		{
			case RPGATOR_EET_ELEMENT_DRAGGED:
				if (event.GUIEvent.Element)
				{ //Element dragged to an GUI element
					if (event.GUIEvent.Element->getParent())
					{ //Element dragged to an GUI element that has parent (IGUIIconTableContainer)
						if (event.GUIEvent.Element->getParent()->getID() == HotkeyBar)
						{ //Empty cell
							CGUIButton* hotkeyButton = new CGUIButton(*((CGUIButton*)event.GUIEvent.Caller));
							((IGUIIconTable::IGUIIconTableContainer*)event.GUIEvent.Element)->setButton(hotkeyButton);
						}
						else if (event.GUIEvent.Element->getParent()->getParent())
						{ //Element dragged to an GUI element that has parent (IGUIIconTable)
							if (event.GUIEvent.Element->getParent()->getParent()->getID() == HotkeyBar)
							{ //Existing cell
								CGUIButton* hotkeyButton = new CGUIButton(*((CGUIButton*)event.GUIEvent.Caller));
								((IGUIIconTable::IGUIIconTableContainer*)event.GUIEvent.Element->getParent())->setButton(hotkeyButton);
							}
						}
					}
				}
				break;
			case EGET_EDITBOX_ENTER:
				switch (eventCallerId)
				{
					case ChatInputEditBox:
						IGUIElement* eb = Universe::instance->guienv->getRootGUIElement()->getElementFromId(ChatBox)->getElementFromId(ChatInputEditBox);
						if (wcslen(eb->getText()) > 0)
						{
							char outPacket[256];
							CreatePacket(outPacket, Say, "%b%ws", Public, eb->getText());
							Universe::instance->connectSocket->Send(outPacket);
							eb->setText(NULL);
						}
						break;
				}
				break;
			case EGDT_WINDOW_CLOSE:
				switch (eventCallerId)
				{
					case InventoryWindow:
						((IGUIButton*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(InventoryToggleButton))->setPressed(false);
						break;
					case SkillsWindow:
						((IGUIButton*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(SkillsToggleButton))->setPressed(false);
						break;
				}
				break;
			case EGET_BUTTON_CLICKED:
				switch (eventCallerId)
				{
					case IconTableItemButton:
					{
						char outPacket[256];
						CreatePacket(outPacket, ItemUse, "%i", ((CGUIButton*)eventCaller)->currentGameObject->id);
						Universe::instance->connectSocket->Send(outPacket);
						break;
					}
					case IconTableSkillButton:
					{
						((IGUIIconTable*)eventCaller->getParent()->getParent())->selectedButton = (CGUIButton*)eventCaller;
						
						//rightMouseBind = eventCaller;
						/*
						char outPacket[256];
						CurrentMapObject<MapObject>* targetCurrentMapObject;
						int currentMapObjectId;
						int targetType;

						if (targetCurrentMapObject = (CurrentMapObject<MapObject>*)Universe::instance->render->GetCurrentMapObjectUnderCursor<CurrentNPC>(Universe::instance->currentLocation->currentNPCs, Universe::instance->currentLocation->currentNPCsCount))
						{
							currentMapObjectId = targetCurrentMapObject->id;
							targetType = 0;
						}
						else if (targetCurrentMapObject = (CurrentMapObject<MapObject>*)Universe::instance->render->GetCurrentMapObjectUnderCursor<CurrentCharacter>(Universe::instance->currentLocation->currentCharacters, Universe::instance->currentLocation->currentCharactersCount))
						{
							currentMapObjectId = targetCurrentMapObject->id;
							targetType = 3;
						}
						else
						{
							currentMapObjectId = 0;
							targetType = -1;
						}

						CreatePacket(outPacket, SkillUse, "%i%b%i", ((CGUIButton*)eventCaller)->currentGameObject->id, targetType, currentMapObjectId);
						Universe::instance->connectSocket->Send(outPacket);
						*/
						break;
					}
					case InventoryToggleButton:
					{
						IGUIWindow* wnd = (IGUIWindow*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(InventoryWindow);
						if (wnd)
							wnd->remove();
						else
						{
							int btnsSize = 48;

							wnd = Universe::instance->guienv->addWindow(rect< s32 >(Universe::instance->render->screenWidth - btnsSize * 6 - (6 - 1) * 2 - 20, 150, Universe::instance->render->screenWidth, 150 + 100 + btnsSize * 6 + (6 - 1) * 2 + 10), false, L"Inventory", NULL, InventoryWindow);

							IGUIIconTable* tbl = new IGUIIconTable(Universe::instance->guienv, wnd, InventoryItemsIconTable, rect< s32 >(10, 100, 10 + btnsSize * 6 + (6 - 1) * 2, 100 + btnsSize * 6 + (6 - 1) * 2), 6, 6);
							tbl->buttonSize = btnsSize;
							wnd->addChild(tbl);
							for (int i = 0; i < Universe::instance->currentCharacter->currentItemsCount; i++)
							{
								tbl->addButton((CurrentGameObject<GameObject>*)Universe::instance->currentCharacter->currentItems[i], IconTableItemButton);
							}
						}
						break;
					}
					case SkillsToggleButton:
					{
						IGUIWindow* wnd = (IGUIWindow*)Universe::instance->guienv->getRootGUIElement()->getElementFromId(SkillsWindow);
						if (wnd)
							wnd->remove();
						else
						{
							int btnsSize = 48;

							wnd = Universe::instance->guienv->addWindow(rect< s32 >(Universe::instance->render->screenWidth - btnsSize * 6 - (6 - 1) * 2 - 20 - 400, 150, Universe::instance->render->screenWidth - 400, 150 + 100 + btnsSize * 6 + (6 - 1) * 2 + 10), false, L"Skills", NULL, SkillsWindow);

							IGUIIconTable* tbl = new IGUIIconTable(Universe::instance->guienv, wnd, SkillsIconTable, rect< s32 >(10, 100, 10 + btnsSize * 6 + (6 - 1) * 2, 100 + btnsSize * 6 + (6 - 1) * 2), 6, 6);
							tbl->buttonSize = btnsSize;
							wnd->addChild(tbl);
							for (int i = 0; i < Universe::instance->currentCharacter->currentSkillsCount; i++)
							{
								tbl->addButton((CurrentGameObject<GameObject>*)Universe::instance->currentCharacter->currentSkills[i], IconTableSkillButton);
							}
						}
						break;
					}
					case ChatInputEditBox:
						Universe::instance->guienv->getRootGUIElement()->getElementFromId(ChatInputEditBox)->setText(L"");
						break;
					default:
						if (eventCallerId > DialogElement) //Dialog button
						{
							char outPacket[256];
							int currentNPCId;

							swscanf(eventCaller->getParent()->getText(), L"[%d]", &currentNPCId);
							eventCaller->getParent()->remove();
							CreatePacket(outPacket, DialogOpen, "%i%i", currentNPCId, eventCallerId - DialogElement);
							Universe::instance->connectSocket->Send(outPacket);
						}
						break;
				}
				break;
			case EGET_COMBO_BOX_CHANGED:
				break;
			case EGET_TAB_CHANGED:
				break;
			case EGET_CHECKBOX_CHANGED:
				break;
		}
	}

	return false;
}