Пример #1
0
void FontAtlas::purgeTexturesAtlas()
{
    FontFreeType* fontTTf = dynamic_cast<FontFreeType*>(_font);
    if (fontTTf && _atlasTextures.size() > 1)
    {
        for( auto &item: _atlasTextures)
        {
            if (item.first != 0)
            {
                item.second->release();
            }
        }
        auto temp = _atlasTextures[0];
        _atlasTextures.clear();
        _atlasTextures[0] = temp;

        _fontLetterDefinitions.clear();
        memset(_currentPageData,0,_currentPageDataSize);
        _currentPage = 0;
        _currentPageOrigX = 0;
        _currentPageOrigY = 0;

        auto eventDispatcher = Director::getInstance()->getEventDispatcher();
        eventDispatcher->dispatchCustomEvent(EVENT_PURGE_TEXTURES,this);
    }
}
void DungeonLayer::_handleRoomsPlacements(EventCustom* event) {
  auto placementsData = (RoomsPlacementsData*) event->getUserData();
  auto placements = placementsData->getPlacements();
  
  int zOrder = placements.size();
  
  if (placements.size() > 0) {
    float delayTime = 0;
    auto lastPlacement = placements.at(placements.size() - 1);
    
    for (auto placement : placements) {
      auto room = placement->getRoom();
      auto coordinate = placement->getCoordinate();
      
      auto roomSprite = DungeonRoomSprite::createWithRoom(room);
      roomSprite->setCoordinate(coordinate);
      
      auto size = Director::getInstance()->getVisibleSize();
      auto origin = Director::getInstance()->getVisibleOrigin() - this->getParent()->getPosition();
      
      auto initialSize = TILE_DIMENSION * TILE_PLACEMENT_SCALE;
      
      auto deckPosition = Vec2(origin.x + size.width - initialSize / 2 - 10,
                               origin.y + size.height - initialSize / 2 - 10);
      roomSprite->setScale(TILE_PLACEMENT_SCALE, TILE_PLACEMENT_SCALE);
      roomSprite->setPosition(deckPosition);
      
      this->addChild(roomSprite, zOrder + 1);
      
      auto position = PositionUtil::positionForCoordinate(coordinate);
      
      auto delay = DelayTime::create(delayTime);
      auto animationStarted = CallFunc::create([=]() {
        roomSprite->setLocalZOrder(DUNGEON_ROOM_Z_ORDER + 10);
      });
      auto moveAndScale = Spawn::create(MoveTo::create(PLACE_ROOM_DURATION, position),
                                        ScaleTo::create(PLACE_ROOM_DURATION, 1),
                                        NULL);
      auto easeMove = EaseBackIn::create(moveAndScale);
      auto animationEnded = CallFunc::create([=]() {
        roomSprite->setLocalZOrder(DUNGEON_ROOM_Z_ORDER);
        
        if (placement == lastPlacement) {
          auto dispatcher = Director::getInstance()->getEventDispatcher();
          dispatcher->dispatchCustomEvent(EVT_LAST_TILE_HAS_BEEN_PLACED, placement);
          
          if (Game::getInstance()->isInitialTurn()) {
            Game::getInstance()->finishCurrentTurn();
          }
        }
      });
      
      roomSprite->runAction(Sequence::create(delay, animationStarted, easeMove,
                                             animationEnded, NULL));
      
      delayTime += PLACE_ROOM_DURATION;
      zOrder--;
    }
  }
}
Пример #3
0
void FontAtlas::listenRendererRecreated(EventCustom *event)
{
    if (_fontFreeType)
    {
        auto eventDispatcher = Director::getInstance()->getEventDispatcher();
        eventDispatcher->dispatchCustomEvent(CMD_PURGE_FONTATLAS,this);
        eventDispatcher->dispatchCustomEvent(CMD_RESET_FONTATLAS,this);
    }
}
Пример #4
0
void FontAtlas::purgeTexturesAtlas()
{
    if (_fontFreeType && _atlasTextures.size() > 1)
    {
        auto eventDispatcher = Director::getInstance()->getEventDispatcher();
        eventDispatcher->dispatchCustomEvent(CMD_PURGE_FONTATLAS,this);
        eventDispatcher->dispatchCustomEvent(CMD_RESET_FONTATLAS,this);
    }
}
void GameplayLayer::dockActionDice(ActionDiceSprite *actionDiceSprite) {
  Node* dockableNode;
  
  auto dockableNodes = this->_getDockableContainer()->getDockableNodes();
  dockableNodes.reverse();
  for (auto node : dockableNodes) {
    if (node->getChildren().size() == 0) {
      dockableNode = node;
      break;
    }
  }
  
  auto dispatcher = Director::getInstance()->getEventDispatcher();
  
  actionDiceSprite->dockOnNode(dockableNode);
  dispatcher->dispatchCustomEvent(EVT_ACTION_DICE_SPENT,
                                  actionDiceSprite->getDice());
}
Пример #6
0
void FontAtlas::listenToForeground(EventCustom *event)
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
    FontFreeType* fontTTf = dynamic_cast<FontFreeType*>(_font);
    if (fontTTf)
    {
        if (_currentPageOrigX == 0 && _currentPageOrigY == 0)
        {
            auto eventDispatcher = Director::getInstance()->getEventDispatcher();
            eventDispatcher->dispatchCustomEvent(EVENT_PURGE_TEXTURES,this);
        }
        else
        {
            auto contentSize = Size(CacheTextureWidth,CacheTextureHeight);
            auto  pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8;

            _atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, CacheTextureWidth, CacheTextureHeight, contentSize );
        }
    }
#endif
}
Пример #7
0
bool GameScene::init()
{
    if (!Layer::init()) {
        return false;
    }

    _deviceOrientation = DeviceOrientation::Portrait;

    auto visibleSize = Director::getInstance()->getVisibleSize();

    //setContentSize(Size(visibleSize.width * 2, visibleSize.height));

    // 背景レイヤーの上にメインシーン、レポートシーンを含めるコンテナシーンを重ねて、コンテナシーンを移動させ、背景は固定されるようにする

    // 背景レイヤー
    auto bkgLayer = Layer::create();
    bkgLayer->setName(name::scene::game::BACKGROUND_LAYER);
    addChild(bkgLayer);

    auto cache = Director::getInstance()->getTextureCache();
    auto tex = cache->getTextureForKey(name::resource::GAME_BACKGROUND);
    auto spr = Sprite::createWithTexture(tex);
    cache->removeTexture(tex);
    //spr->setName(name::GAME_BACKGROUND);
    spr->setAnchorPoint(Vec2::ZERO);
    spr->setPosition(Vec2::ZERO);
    bkgLayer->addChild(spr);

    // コンテナレイヤー(メインシーンとレポートシーンを含める)
    auto containerLayer = Layer::create();
    containerLayer->setName(name::scene::game::CONTAINER_LAYER);
    addChild(containerLayer);

    auto mainScene = MainScene::create();
    mainScene->setName(name::scene::MAIN);
    mainScene->setAnchorPoint(Vec2::ZERO);
    mainScene->setPosition(Vec2::ZERO);
    containerLayer->addChild(mainScene);

    auto reportScene = ReportScene::create();
    reportScene->setName(name::scene::REPORT);
    reportScene->setAnchorPoint(Vec2::ZERO);
    reportScene->setPosition(Vec2(720, 0));
    containerLayer->addChild(reportScene);

    // 左スクロールイベント
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(config::event::ScrollToLeftNotification, [this](EventCustom* evt) {
        auto vec = Vec2::ZERO;
        if (DeviceOrientation::Portrait == _deviceOrientation) {
            vec = Vec2(-720, 0);
        }
        else if (DeviceOrientation::Landscape == _deviceOrientation) {
            vec = Vec2(-1280, 0);
        }
        getChildByName(name::scene::game::CONTAINER_LAYER)->runAction(MoveBy::create(0.3f, vec));
    });
    // 右スクロールイベント
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(config::event::ScrollToRightNotification, [this](EventCustom* evt) {
        auto vec = Vec2::ZERO;
        if (DeviceOrientation::Portrait == _deviceOrientation) {
            vec = Vec2(720, 0);
        }
        else if (DeviceOrientation::Landscape == _deviceOrientation) {
            vec = Vec2(1280, 0);
        }
        // スクロールしてスクロール完了を通知
        auto action = Sequence::createWithTwoActions(MoveBy::create(0.3f, vec), CallFunc::create([this]() {
            Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(config::event::ScrollToRightCompletionNotification);
        }));
        getChildByName(name::scene::game::CONTAINER_LAYER)->runAction(action);
    });
    // 端末の向き変更イベント
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(config::event::OrientationChangedNotification, [this](EventCustom* evt) {
        auto data = static_cast<ValueMap*>(evt->getUserData());
        auto w = data->at("w").asInt();
        auto h = data->at("h").asInt();

        auto glview = Director::getInstance()->getOpenGLView();
        // フレームサイズをセットしてから、デザイン解像度をセット
        glview->setFrameSize(w, h);
        if (w > h) {
            //CCLOG("(landscape) w: %d, h: %d", w, h);
            glview->setDesignResolutionSize(config::resolution::DESIGN_RESOLUTION_LONG_SPAN, config::resolution::DESIGN_RESOLUTION_SHORT_SPAN, config::resolution::DESIGN_POLICY);
            _deviceOrientation = DeviceOrientation::Landscape;
        }
        else {
            //CCLOG("(portrait) w: %d, h: %d", w, h);
            glview->setDesignResolutionSize(config::resolution::DESIGN_RESOLUTION_SHORT_SPAN, config::resolution::DESIGN_RESOLUTION_LONG_SPAN, config::resolution::DESIGN_POLICY);
            _deviceOrientation = DeviceOrientation::Portrait;
        }
        reArrangeChildrens();
    });

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    auto keyboardListener = EventListenerKeyboard::create();
    keyboardListener->onKeyPressed = [this](EventKeyboard::KeyCode keyCode, Event* event) {};
    keyboardListener->onKeyReleased = [this](EventKeyboard::KeyCode keyCode, Event* event) {
        if (EventKeyboard::KeyCode::KEY_V != keyCode && EventKeyboard::KeyCode::KEY_H != keyCode)
            return;

        auto data = ValueMap();
        if (EventKeyboard::KeyCode::KEY_V == keyCode) {
            data["w"] = 540;
            data["h"] = 960;
        }
        else if (EventKeyboard::KeyCode::KEY_H == keyCode) {
            data["w"] = 960;
            data["h"] = 540;
        }
        auto evtDispatcher = Director::getInstance()->getEventDispatcher();
        evtDispatcher->dispatchCustomEvent(config::event::OrientationChangedNotification, &data);
    };
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(keyboardListener, this);
#endif

    return true;
}