示例#1
0
/*************************************************************************
Perform actual update processing for this Window.
*************************************************************************/
void MenuItem::updateSelf(float elapsed)
{
    ItemEntry::updateSelf(elapsed);

    //handle delayed popup closing/opening when hovering with the mouse
    if (d_autoPopupTimeout != 0.0f && (d_popupOpening || d_popupClosing))
    {
        // stop timer if the hovering state isn't set appropriately anymore
        if (d_hovering)
        {
            d_popupClosing = false;
        }
        else
        {
            d_popupOpening = false;
        }

        //check if the timer elapsed and take action appropriately
        d_autoPopupTimeElapsed += elapsed;

        if (d_autoPopupTimeElapsed > d_autoPopupTimeout)
        {
            if (d_popupOpening)
            {
                d_popupOpening = false;
                openPopupMenu(true);
            }
            else if (d_popupClosing)
            {
                d_popupClosing = false;
                closePopupMenu(true);
            }
        }
    }
}
示例#2
0
/*************************************************************************
    Recursive function that closes all popups down the hierarchy starting
    with this one.
*************************************************************************/
void MenuItem::closeAllMenuItemPopups()
{
    // are we attached to a PopupMenu?
    if (!d_ownerList)
        return;

    if (dynamic_cast<Menubar*>(d_ownerList))
    {
        closePopupMenu();
        return;
    }

    PopupMenu* pop = dynamic_cast<PopupMenu*>(d_ownerList);
    if (pop)
    {
        // is this parent popup attached to a menu item?
        Window* popParent = pop->getParent();
        MenuItem* mi = dynamic_cast<MenuItem*>(popParent);

        if (mi)
        {
            // recurse
            mi->closeAllMenuItemPopups();
        }
        // otherwise we just hide the parent popup
        else
        {
            pop->closePopupMenu(false);
        }
    }
}
示例#3
0
/*************************************************************************
    Toggles the PopupMenu.
*************************************************************************/
bool MenuItem::togglePopupMenu(void)
{
    if (d_opened)
    {
        closePopupMenu();
        return false;
    }

    openPopupMenu();
    return true;
}
示例#4
0
bool Viewport::changeMap(const std::string &path)
{
    // Clean up floor items, beings and particles
    floorItemManager->clear();
    beingManager->clear();

    // Close the popup menu on map change so that invalid options can't be
    // executed.
    closePopupMenu();

    // Unset the map of the player so that its particles are cleared before
    // being deleted in the next step
    if (player_node)
        player_node->setMap(NULL);

    particleEngine->clear();

    mMapName = path.substr(0, path.rfind("."));

    // Store full map path in global var
    std::string mapPath = "maps/" + mMapName + ".tmx";
    ResourceManager *resman = ResourceManager::getInstance();
    if (!resman->exists(mapPath))
        mapPath += ".gz";

    // Attempt to load the new map
    Map *newMap = MapReader::readMap(mapPath);

    if (!newMap)
    {
        logger->log("Error while loading %s", mapPath.c_str());
        new OkDialog(_("Could not load map"),
                     strprintf(_("Error while loading %s"), mapPath.c_str()));
    }

    // Notify the minimap and beingManager about the map change
    minimap->setMap(newMap);
    beingManager->setMap(newMap);
    particleEngine->setMap(newMap);

    keyboard.refreshActiveKeys();

    // Initialize map-based particle effects
    if (newMap)
        newMap->initializeParticleEffects(particleEngine);

    // Start playing new music file when necessary
    std::string oldMusic = mCurrentMap ? mCurrentMap->getMusicFile() : "";
    std::string newMusic = newMap ? newMap->getMusicFile() : "";

    if (newMusic != oldMusic)
        sound.playMusic(newMusic);

    if (mCurrentMap)
        destroy(mCurrentMap);

    setMap(newMap);
    MessageOut outMsg(CMSG_MAP_LOADED);

    return true;
}