void AquariaMenuItem::onUpdate(float dt)
{	
	AquariaGuiElement::updateMovement(dt);

	if (font)
	{
		font->alpha = this->alpha;
	}
	Quad::onUpdate(dt);

	if (shareAlpha)
	{
		if (quad) quad->alphaMod = alpha.x;
		if (glow) glow->alphaMod = alpha.x;
	}

	if (this->alpha.x < 1.0) return;

	if (hasInput())
		ActionMapper::onUpdate(dt);

	if (quad)
	{
		quad->alpha.x = alpha.x;
	}

	/*
	font->position = this->position;
	font->alpha = this->alpha;
	*/
	if (hasInput())
	{
		if (alpha.x == 1)
		{
			bool on = true;
			

			if (isCursorInMenuItem())
			{
				if (!highlighted)
					toggleHighlight(true);
			}
			else
				on = false;
			
			if (!on && highlighted)
				toggleHighlight(false);	
		}
		else
		{
			if (highlighted)
				toggleHighlight(false);
		}
	}
}
Exemplo n.º 2
0
uint8 Menu::execute() {
	OSystem &system = *g_system;
	LureEngine &engine = LureEngine::getReference();
	Mouse &mouse = Mouse::getReference();
	Events &events = Events::getReference();
	Screen &screen = Screen::getReference();

	mouse.setCursorNum(CURSOR_ARROW);
	system.copyRectToScreen(_menu->data(), FULL_SCREEN_WIDTH, 0, 0,
		FULL_SCREEN_WIDTH, MENUBAR_Y_SIZE);

	_selectedMenu = NULL;
	_surfaceMenu = NULL;
	_selectedIndex = 0;

	while (mouse.lButton() || mouse.rButton()) {
		while (events.pollEvent()) {
			if (engine.shouldQuit()) return MENUITEM_NONE;

			if (mouse.y() < MENUBAR_Y_SIZE) {
				MenuRecord *p = getMenuAt(mouse.x());

				if (_selectedMenu != p) {
					// If necessary, remove prior menu
					if (_selectedMenu) {
						toggleHighlight(_selectedMenu);
						screen.updateArea(0, 0, FULL_SCREEN_WIDTH, _surfaceMenu->height() + 8);
						delete _surfaceMenu;
						_surfaceMenu = NULL;
						_selectedIndex = 0;
					}

					_selectedMenu = p;

					// If a new menu is selected, show it
					if (_selectedMenu) {
						toggleHighlight(_selectedMenu);
						_surfaceMenu = Surface::newDialog(
							_selectedMenu->width(), _selectedMenu->numEntries(),
							_selectedMenu->entries(), false, DEFAULT_TEXT_COLOUR, false);
						_surfaceMenu->copyToScreen(_selectedMenu->xstart(), MENUBAR_Y_SIZE);
					}

					system.copyRectToScreen(_menu->data(), FULL_SCREEN_WIDTH, 0, 0,
						FULL_SCREEN_WIDTH, MENUBAR_Y_SIZE);
				}
			}

			// Check for changing selected index
			uint8 index = getIndexAt(mouse.x(), mouse.y());
			if (index != _selectedIndex) {
				if (_selectedIndex != 0) toggleHighlightItem(_selectedIndex);
				_selectedIndex = index;
				if (_selectedIndex != 0) toggleHighlightItem(_selectedIndex);
			}
		}

		system.updateScreen();
		system.delayMillis(10);
	}

	delete _surfaceMenu;

	// Deselect the currently selected menu header
	if (_selectedMenu)
		toggleHighlight(_selectedMenu);

	// Restore the previous screen
	screen.update();

	if ((_selectedMenu == NULL) || (_selectedIndex == 0)) return MENUITEM_NONE;
	else if (_selectedMenu == _menus[0])
		return MENUITEM_CREDITS;
	else if (_selectedMenu == _menus[1]) {
		switch (_selectedIndex) {
		case 1:
			return MENUITEM_RESTART_GAME;
		case 2:
			return MENUITEM_SAVE_GAME;
		case 3:
			return MENUITEM_RESTORE_GAME;
		}
	} else {
		switch (_selectedIndex) {
		case 1:
			return MENUITEM_QUIT;
		case 2:
			return MENUITEM_TEXT_SPEED;
		case 3:
			return MENUITEM_SOUND;
		}
	}
	return MENUITEM_NONE;
}