void ViewmdaWidget1D::mousePressEvent ( QMouseEvent * event ) { if (!m_model) return; if ((event->button()&Qt::LeftButton)||(event->button()&Qt::RightButton)) { m_model->setSelectedRect(QRect(-1,-1,1,1),false); long index=pointToIndex(event->pos()); m_model->setC1(index); } }
void QMFieldView::mouseDoubleClickEvent(QMouseEvent *pEvent) { bool bValid = false; UInt32 uiIndex = pointToIndex(pEvent->pos(), bValid); if(bValid && (uiIndex < getFieldPtr()->getSize())) { emit doubleClicked(getFieldContainer(), getFieldId(), uiIndex, pEvent->button()); } }
AngleMap::AngleMap(const deg tth) { size_ = gSession->imageSize(); arrAngles_.resize(size_.count()); const Detector& geo = gSession->params.detector; // compute angles: // detector center is at vec{d} = (d_x, 0, ) // detector pixel (i,j) is at vec{b} const double t = tth.toRad(); const double c = cos(t); const double s = sin(t); const double d_z = geo.detectorDistance.val(); const double b_x1 = d_z * s; const double b_z1 = d_z * c; int midPixX = size_.w/2 + geo.pixOffset[0].val(); int midPixY = size_.h/2 + geo.pixOffset[1].val(); for (int i=0; i<size_.w; ++i) { const double d_x = (i - midPixX) * geo.pixSize.val(); const double b_x = b_x1 + d_x * c; const double b_z = b_z1 - d_x * s; const double b_x2 = b_x * b_x; for (int j=0; j<size_.h; ++j) { const double b_y = (midPixY - j) * geo.pixSize.val(); // == d_y const double b_r = sqrt(b_x2 + b_y * b_y); const rad gma = atan2(b_y, b_x); const rad tth = atan2(b_r, b_z); arrAngles_[pointToIndex(i, j)] = {tth.toDeg(), gma.toDeg()}; } } const ImageCut& cut = gSession->params.imageCut; ASSERT(size_.w > cut.horiz()); ASSERT(size_.h > cut.vertical()); const int countAfterCut = (size_.w - cut.horiz()) * (size_.h - cut.vertical()); ASSERT(countAfterCut > 0); // compute ranges rgeTth_, rgeGma_, rgeGmaFull_, and arrays gmas_, gmaIndexes_: rgeTth_.invalidate(); rgeGma_.invalidate(); rgeGmaFull_.invalidate(); gmas_.resize(countAfterCut); gmaIndexes_.resize(countAfterCut); int gi = 0; for (int j = cut.top.val(), jEnd = size_.h - cut.bottom.val(); j < jEnd; ++j) { for (int i = cut.left.val(), iEnd = size_.w - cut.right.val(); i < iEnd; ++i) { // (loop order j-i results in faster stable_sort than order i-j) const ScatterDirection& dir = arrAngles_[pointToIndex(i, j)]; gmas_[gi] = dir.gma; gmaIndexes_[gi] = pointToIndex(i, j); ++gi; rgeTth_.extendBy(dir.tth); rgeGmaFull_.extendBy(dir.gma); // TODO URGENT: THIS IS WRONG: seems correct only for tth<=90deg if (dir.tth >= tth) rgeGma_.extendBy(dir.gma); // gma range at mid tth } } //qDebug() << "AngleMap: found gamma range " << rgeGma_.to_s(); //qDebug() << "AngleMap: found full range " << rgeGmaFull_.to_s(); //qDebug() << "AngleMap: found theta range " << rgeTth_.to_s(); // compute indices of sorted gmas_: std::vector<int> is(countAfterCut); for (int i=0; i<is.size(); ++i) is[i] = i; //qDebug() << "AngleMap: sort"; // empirically, stable_sort seems to be faster than sort std::stable_sort(is.begin(), is.end(), [this](int i1, int i2) { return gmas_.at(i1) < gmas_.at(i2); }); //qDebug() << "AngleMap: sort/"; // sort gmas_: std::vector<deg> gv(countAfterCut); for (int i=0; i<countAfterCut; ++i) gv[i] = gmas_.at(is.at(i)); gmas_ = std::move(gv); // sort gmaIndexes_: std::vector<int> uv(countAfterCut); for (int i=0; i<countAfterCut; ++i) uv[i] = gmaIndexes_.at(is.at(i)); gmaIndexes_ = std::move(uv); //qDebug() << "AngleMap/"; }
bool RogueScene::init() { // 1. super init first if ( !Layer::init() ) { return false; } // 乱数 srand((unsigned int)time(NULL)); // TouchEvent settings auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = CC_CALLBACK_2(RogueScene::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(RogueScene::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(RogueScene::onTouchEnded, this); // this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); this->getEventDispatcher()->addEventListenerWithFixedPriority(listener, 1); auto winSize = Director::getInstance()->getWinSize(); // --------------------- // タイルマップを生成 // --------------------- auto pTiledMap = TMXTiledMap::create("tmx/desert.tmx"); pTiledMap->setPosition(Point::ZERO); this->addChild(pTiledMap, RogueScene::zTiledMapIndex, RogueScene::kTiledMapTag); m_baseMapSize = pTiledMap->getMapSize(); m_baseTileSize = pTiledMap->getTileSize(); m_baseContentSize = pTiledMap->getContentSize(); m_mapManager.init(0, (int)m_baseMapSize.height, 0, (int)m_baseMapSize.width); // 使ってなかった // // フロントレイヤー // auto pFrontLayer = Layer::create(); // pTiledMap->addChild(pFrontLayer, // RogueScene::TiledMapIndex::zTiledMapFrontIndex, // RogueScene::TiledMapTag::kTiledMapFrontTag); // エネミーレイヤー auto pEnemyLayer = Layer::create(); pTiledMap->addChild(pEnemyLayer, RogueScene::TiledMapIndex::zTiledMapEnemyBaseIndex, RogueScene::TiledMapTag::kTiledMapEnemyBaseTag); // ドロップアイテムレイヤー auto pDropItemLayer = Layer::create(); pTiledMap->addChild(pDropItemLayer, RogueScene::TiledMapIndex::zTiledMapDropItemBaseIndex, RogueScene::TiledMapTag::kTiledMapDropItemBaseTag); // 障害物をmapManagerに適応する auto pColisionLayer = pTiledMap->getLayer("colision"); for (int x = 0; x < m_baseMapSize.width; x++) { for (int y = 0; y < m_baseMapSize.height; y++) { if (pColisionLayer->getTileAt(Point(x, y))) { MapIndex mapIndex = {x, y, MoveDirectionType::MOVE_NONE}; auto tileMapIndex = mapIndexToTileIndex(mapIndex); m_mapManager.addObstacle(&tileMapIndex); } } } // --------------------- // グリッド線を生成 // --------------------- auto draw = DrawNode::create(); draw->setPosition(Point::ZERO); // 線の太さと色 float lineSize = 1 * 0.5; Color4F color = Color4F::MAGENTA; // 縦線を引く for (int x = 1; x < m_baseMapSize.width; x++) { float xPoint = x * m_baseTileSize.width; draw->drawSegment(Point(xPoint, 0), Point(xPoint, m_baseContentSize.height), lineSize, color); } // 横線を引く for (int y = 1; y < m_baseMapSize.height; y++) { float yPoint = y * m_baseTileSize.height; draw->drawSegment(Point(0, yPoint), Point(m_baseContentSize.width, yPoint), lineSize, color); } // マップに追加 pTiledMap->addChild(draw, RogueScene::TiledMapIndex::zGridLineIndex, RogueScene::TiledMapTag::kGridLineTag); //------------------------- // ステータスバー? //------------------------- auto statusLayer = LayerColor::create(Color4B::BLACK); statusLayer->setContentSize(Size(winSize.width, m_baseTileSize.height * 0.8)); statusLayer->setPosition(Point(0, winSize.height - statusLayer->getContentSize().height)); // TODO: あとで更新する auto sampleText = LabelTTF::create(" --F Lv-- HP ---/--- 満腹度 ---/--- - G", GAME_FONT(16), 16); sampleText->setPosition(Point(sampleText->getContentSize().width / 2, statusLayer->getContentSize().height / 2)); statusLayer->addChild(sampleText); this->addChild(statusLayer, RogueScene::zStatusBarIndex, RogueScene::kStatusBarTag); // // 下のステータスバー2 // auto pStatusLayer2 = LayerColor::create(Color4B::BLACK); // pStatusLayer2->setContentSize(Size(m_baseTileSize.width, m_baseTileSize.height)); // pStatusLayer2->setPosition(Point(0, 0)); // // // TODO: アイコン表示するかな(ステータスバー2?) // auto pFaceSprite = Sprite::createWithSpriteFrame(SpriteFrame::create("actor_4_f.png", Rect(0, 0, 96, 96))); // float scale = 1.0f / 3.0f; // pFaceSprite->setScale(scale, scale); // // pFaceSprite->setContentSize(pFaceSprite->getContentSize() * scale); // // CCLOG("getContentSize (%f, %f) ", pFaceSprite->getContentSize().width, pFaceSprite->getContentSize().height); // // pFaceSprite->setPosition(Point(pFaceSprite->getContentSize().width / 2, pFaceSprite->getContentSize().height / 2)); // pFaceSprite->setPosition(Point(pFaceSprite->getContentSize().width * pFaceSprite->getScaleX() / 2, pFaceSprite->getContentSize().height * pFaceSprite->getScaleY() / 2)); // pStatusLayer2->addChild(pFaceSprite); // // this->addChild(pStatusLayer2, RogueScene::zStatusBar2Index, RogueScene::kStatusBar2Tag); //------------------------- // ゲームログ表示 //------------------------- // float startWidth = pFaceSprite->getContentSize().width * pFaceSprite->getScaleX(); auto pGameLogLayer = LayerColor::create(Color4B(0, 0, 0, 192)); pGameLogLayer->setContentSize(Size(winSize.width * 0.8, m_baseTileSize.height * 1.5)); pGameLogLayer->setPosition(winSize.width / 2 - pGameLogLayer->getContentSize().width / 2, 0); int baseFontSize = 10; auto pLogTextLabel = LabelTTF::create("", GAME_FONT(baseFontSize), baseFontSize, Size::ZERO, TextHAlignment::LEFT, TextVAlignment::TOP); pLogTextLabel->setPosition(Point(pLogTextLabel->getContentSize().width / 2 + pLogTextLabel->getFontSize() / 4, pGameLogLayer->getContentSize().height - pLogTextLabel->getContentSize().height / 2 - pLogTextLabel->getFontSize() / 4)); pGameLogLayer->addChild(pLogTextLabel); this->addChild(pGameLogLayer, RogueScene::zGameLogIndex, RogueScene::kGameLogTag); // ------------------------ // ミニマップ // ------------------------ // 青で半透明 auto miniMapLayer = LayerColor::create(Color4B(0, 0, 196, 128)); // 1/8サイズ miniMapLayer->setContentSize(Size(m_baseMapSize.width * m_baseTileSize.width / 8, m_baseMapSize.height * m_baseTileSize.height / 8)); // ステータスバーの下くらい miniMapLayer->setPosition(0, miniMapLayer->getPositionY() + winSize.height - miniMapLayer->getContentSize().height - statusLayer->getContentSize().height); this->addChild(miniMapLayer, RogueScene::zMiniMapIndex, RogueScene::kMiniMapTag); // ------------------------ // イベントリ作成 // ------------------------ showItemList(1); hideItemList(); // --------------------- // プレイヤー生成 // --------------------- ActorSprite::ActorDto actorDto; actorDto.name = "ジニー"; actorDto.faceImgId = 0; actorDto.imageResId = 1015; // 基本 actorDto.attackRange = 1; actorDto.movePoint = 5; actorDto.playerId = 4; // 攻守 actorDto.attackPoint = 5; actorDto.defencePoint = 1; // 経験値 actorDto.exp = 0; actorDto.nextExp = 10; // HP actorDto.hitPoint = 15; actorDto.hitPointLimit = 15; actorDto.lv = 1; // 満腹度?精神力? actorDto.magicPoint = 100; actorDto.magicPointLimit = 100; ActorMapItem actorMapItem; actorMapItem.mapDataType = MapDataType::PLAYER; // 画面の中心(固定) actorMapItem.mapIndex = pointToIndex(Point(winSize.width/2, winSize.height/2)); actorMapItem.seqNo = 1; actorMapItem.moveDist = actorDto.movePoint; actorMapItem.attackDist = actorDto.attackRange; actorMapItem.moveDone = false; actorMapItem.attackDone = false; auto actorSprite = ActorSprite::createWithActorDto(actorDto); actorSprite->setPosition(indexToPoint(actorMapItem.mapIndex)); // 画面の中心 actorSprite->setActorMapItem(actorMapItem); actorSprite->runBottomAction(); // プレイヤーは画面中心にくるのでmapLayerに追加しない this->addChild(actorSprite, RogueScene::zActorBaseIndex, (RogueScene::kActorBaseTag + actorMapItem.seqNo)); // マップに追加 m_mapManager.addActor(actorSprite->getActorMapItem()); refreshStatus(); // プレイヤーの位置表示用(同じく1/8サイズ) auto miniMapActorLayer = LayerColor::create(Color4B::YELLOW); // タイルの1/8サイズ miniMapActorLayer->setContentSize(m_baseTileSize / 8); // 現在位置からPositionを取得して1/8にする miniMapActorLayer->setPosition(indexToPointNotTileSize(actorSprite->getActorMapItem()->mapIndex) / 8); // 移動時に更新できるようにplayerIdをtag管理 miniMapActorLayer->setTag(actorSprite->getTag()); // add miniMapLayer->addChild(miniMapActorLayer); // --------------------- // 敵キャラ生成 // --------------------- ActorSprite::ActorDto enemyDto; enemyDto.name = "スライム"; enemyDto.faceImgId = 0; enemyDto.imageResId = 1011; // 基本 enemyDto.attackRange = 1; // TODO: 未使用 enemyDto.movePoint = 10; // 索敵範囲 enemyDto.playerId = 901; // 攻守 enemyDto.attackPoint = 2; enemyDto.defencePoint = 0; // 経験値 enemyDto.exp = 0; enemyDto.nextExp = 10; // HP enemyDto.hitPoint = 10; enemyDto.hitPointLimit = 10; enemyDto.lv = 1; // 満腹度?精神力? enemyDto.magicPoint = 100; enemyDto.magicPointLimit = 100; MapIndex enemyMapIndex1 = {4, 4, MoveDirectionType::MOVE_DOWN}; tileSetEnemyActorMapItem(enemyDto, enemyMapIndex1); ActorSprite::ActorDto enemyDto2 = enemyDto; MapIndex enemyMapIndex2 = {14,12, MoveDirectionType::MOVE_DOWN}; tileSetEnemyActorMapItem(enemyDto2, enemyMapIndex2); ActorSprite::ActorDto enemyDto3 = enemyDto; MapIndex enemyMapIndex3 = {20,4, MoveDirectionType::MOVE_DOWN}; tileSetEnemyActorMapItem(enemyDto3, enemyMapIndex3); //------------------------- // アイテム配置 //------------------------- DropItemSprite::DropItemDto dropItemDto; dropItemDto.itemId = 1; dropItemDto.imageResId = 64; // imageId 10064 dropItemDto.name = "ポーション"; MapIndex mapIndex = {7, 5, MoveDirectionType::MOVE_NONE}; tileSetDropMapItem(dropItemDto, mapIndex); DropItemSprite::DropItemDto dropItemDto2; dropItemDto2.itemId = 2; dropItemDto2.imageResId = 168; // imageId 10168 dropItemDto2.name = "ぶどう"; MapIndex mapIndex2 = {10, 9, MoveDirectionType::MOVE_NONE}; tileSetDropMapItem(dropItemDto2, mapIndex2); // ------------------------------- // メニュー // ------------------------------- auto rect = Rect(0, 0, 300, 30); auto capRect = Rect(0, 0, 300, 30); auto pScale9Sprite1 = extension::Scale9Sprite::create("menu_button.png", rect, capRect); pScale9Sprite1->setContentSize(Size(40, 20)); pScale9Sprite1->setOpacity(192); auto pScale9Sprite2 = extension::Scale9Sprite::create("menu_button.png", rect, capRect); pScale9Sprite2->setContentSize(Size(40, 20)); pScale9Sprite2->setOpacity(128); auto pMenuItem1 = MenuItemSprite::create(pScale9Sprite1, pScale9Sprite2, [this](Object *pSender) { CCLOG("menuItem1が押された!"); showItemList(1); }); pMenuItem1->setColor(Color3B::GREEN); pMenuItem1->setPosition(Point(winSize.width - pMenuItem1->getContentSize().width / 2, pMenuItem1->getContentSize().height / 2)); auto pMenu = Menu::create(pMenuItem1, NULL); pMenu->setPosition(Point::ZERO); this->addChild(pMenu, RogueScene::zMenuIndex, RogueScene::kMenuTag); // --------------------------------- // プレイヤーの先行 changeGameStatus(GameStatus::PLAYER_TURN); return true; }