void PDUGameNumber::execute(GameState*) { CChatView* pChat = CChatView::Instance(); CTableView* pTable = CTableView::Instance(); if (pTable) pTable->setGameNumber(gamenumber_); if (pChat) { CString s; s.Format("+--- New game #%d ---+", gamenumber_); pChat->addDealerMessage(s, CChatView::CF_Fatal); // XXX i testing: /* for (int i = 0; i < 10; i++) { Player* p = pTable->getPlayer(i); if (p) { s.Format("Player %s $%i", p->getName(), p->getChips()); pChat->addDealerMessage(s, CChatView::CF_Fatal); } } */ } if (!Global::IsObserver()) CActionBar::UncheckActionButtons(); GameLogic::NewHand(); }
CTableView* CTableView::create(const Size& tViewSize) { CTableView * pRet = new CTableView(); if( pRet && pRet->initWithSize(tViewSize) ) { pRet->autorelease(); return pRet; } CC_SAFE_DELETE(pRet); return NULL; }
CTableView* CTableView::create(const Size& tViewSize, const Size& tCellSize, unsigned int uCellCount, Ref* pListener, SEL_DataSoucreAdapterHandler pHandler) { CTableView* pRet = new CTableView(); if( pRet && pRet->initWithParams(tViewSize, tCellSize, uCellCount, pListener, pHandler) ) { pRet->autorelease(); return pRet; } CC_SAFE_DELETE(pRet); return NULL; }
///静态构造函数,通过数据回调接口和size构建 CTableView* CTableView::create(CCTableViewDataSource *pDataSource, CCSize tSize) { CTableView *table = new CTableView(); if(table && table->initWithViewSize(tSize, NULL)) { table->autorelease(); table->setDataSource(pDataSource); return table; } CC_SAFE_DELETE(table); return NULL; }
bool CTableViewBindingDataAndVertical::init() { CTableViewTestSceneBase::init(); setTitle("CTableViewBindingDataAndVertical"); setDescription("binding data with vector<string>"); m_vDatas.push_back("A"); m_vDatas.push_back("B"); m_vDatas.push_back("C"); m_vDatas.push_back("D"); m_vDatas.push_back("E"); m_vDatas.push_back("F"); m_vDatas.push_back("G"); m_vDatas.push_back("H"); m_vDatas.push_back("I"); m_vDatas.push_back("J"); m_vDatas.push_back("K"); m_vDatas.push_back("L"); m_vDatas.push_back("M"); m_vDatas.push_back("N"); m_vDatas.push_back("O"); m_vDatas.push_back("P"); m_vDatas.push_back("Q"); m_vDatas.push_back("R"); m_vDatas.push_back("S"); m_vDatas.push_back("T"); m_vDatas.push_back("U"); m_vDatas.push_back("V"); m_vDatas.push_back("W"); m_vDatas.push_back("X"); m_vDatas.push_back("Y"); m_vDatas.push_back("Z"); CTableView* pTable = CTableView::create( CCSize(150.0f, 54.0f * 5), CCSize(150.0f, 54.0f), m_vDatas.size(), this, ccw_datasource_adapter_selector(CTableViewBindingDataAndVertical::tableviewDataSource)); pTable->setDirection(eScrollViewDirectionVertical); pTable->setPosition(CCPoint(480, 320)); m_pWindow->addChild(pTable); pTable->reloadData(); pText = CLabel::create(); pText->setAnchorPoint(CCPoint(0, 0.5)); pText->setPosition(CCPoint(200, 320)); pText->setFontSize(35.0f); pText->setString("click button"); m_pWindow->addChild(pText); return true; }
CTableView* TuiManager::createTableView(float tag, Color4B color, int dir, int num, int cellWidth, int cellHeight, float x, float y, float w, float h, float rotation){ CTableView *pView = CTableView::create(Size(w,h)); if (color.a != 0) pView->setBackgroundColor(color); pView->setAutoRelocate(true); pView->setRotation(rotation); pView->setDirection((CScrollViewDirection)dir); pView->setCountOfCell(num); pView->setSizeOfCell(Size(cellWidth, cellHeight)); pView->setRotation(rotation); pView->setPosition(x,-y); pView->setTag(tag); return pView; }
bool CTableViewBasicTest::init() { CTableViewTestSceneBase::init(); setTitle("CTableViewBasicTest"); setDescription("TableView basic test"); CTableView* pTable = CTableView::create( Size(74.0f * 5, 70.0f), Size(74.0f, 70.0f), 50, this, ccw_datasource_adapter_selector(CTableViewBasicTest::tableviewDataSource)); pTable->setPosition(Vec2(480, 320)); pTable->setBackgroundColor(Color4B::GRAY); m_pWindow->addChild(pTable); pTable->reloadData(); return true; }
void PDUCommunityCard::execute(Base::GameState*) { // Note: the StateDealCommunity is not used since // if a new community card pdu is received while a // StateDealCommunity is active then the previous // community card is lost. Instead, this PDU puts // the card directly to the community player. CTableView* pView = CTableView::Instance(); ASSERT_VALID(pView); if (pView) { // Tell the current state to quit animations if any GameState* state = GameLogic::Instance().currentState(); if (state) state->onCommand(MAKEWPARAM(ID_STOPANIMATION, 0), 0); pView->endBettingRound(); // Update the screen now to make sure whatever we // were doing becomes visible pView->UpdateWindow(); Player* pCommunity = pView->getCommunity(); ASSERT(pCommunity); if (pCommunity) { // Add card directly to community's deck Card card(suit_, card_); pCommunity->addCard(card); SndMan::Instance()->playSound(SndMan::SM_Card2); if (msecs_ > 0) { // Do the "flip" animation to show the card CPoint pos = pCommunity->getCardPos(Player::LastCard); Cards::Instance().startFlip(card, pos); CDC* pDC = pView->GetDC(); if (pDC) { Cards::Instance().flip(pDC, card, pos); pView->ReleaseDC(pDC); } } else { // Just repaint it once pView->InvalidateRect(pCommunity->getCardPaintArea(Player::LastCard)); } ShowCommunityCardMessage(pCommunity); } } }
void ChipsAnimate::startAnimate(int from, int to, const CChips& chips, int sound) { stopAnimate(); sound_ = sound; CTableView* pV = CTableView::Instance(); pView_ = pV; ASSERT(pView_); chips_ = chips; Player* pFrom = pV->getPlayer(from); Player* pTo = pV->getPlayer(to); if (pFrom && pTo) { player_ = from; msecs_ = Global::GetAnimationTime() / 2; ticks_ = 0; // Animation does not go to the pot right away, // chips move to the pot only after betting round // ends. start_ = pFrom->getChipStartPos(); end_ = pFrom->getChipBetPos(); //end_ = pTo->getChipPos(); pos_ = start_; CDC* pDC = pView_->GetDC(); if (pDC) { Chips::Instance().startAnimate(pDC, chips_, start_); pView_->ReleaseDC(pDC); } // Fix up the 'end' position so the bottom left corner // of the rectangle will hit there CSize s = Chips::Instance().getAnimationBufferSize(); end_.y -= (s.cy - Chips::Height_); } }
NS_BAG_BEGIN void Bagui::onLoadScene() { SpriteFrameCache::getInstance()->addSpriteFramesWithFile("bag/bagui.plist"); TuiManager::getInstance()->parseScene(this, "panel_bag", PATH_BAG); CGridView* pGridView = (CGridView*)this->getControl(PANEL_BAG, GV_BAG); pGridView->setDataSourceAdapter(this, ccw_datasource_adapter_selector(Bagui::event_adapt_gvBag)); pGridView->reloadData(); CTableView* pTblView = (CTableView*)this->getControl(PANEL_BAG, TBL_BAG); pTblView->setDataSourceAdapter(this, ccw_datasource_adapter_selector(Bagui::event_adapt_tblBag)); pTblView->reloadData(); CPageView* pPageView = (CPageView*)this->getControl(PANEL_BAG, PV_BAG); pPageView->setDataSourceAdapter(this, ccw_datasource_adapter_selector(Bagui::event_adapt_pageBag)); pPageView->reloadData(); CButton* pBtnView = (CButton*)this->getControl(PANEL_BAG, BTN_BACK); pBtnView->setOnClickListener(this, ccw_click_selector(Bagui::event_btn_back)); }
void PDUNetworkError::execute(Base::GameState*) { #ifdef PSPOT_TABLE_MODULE_ Base::GameLogic::Instance().setNextState(0); Global::Instance().closeConnections(); CTableView* pView = CTableView::Instance(); if (pView) { pView->setCaption(); pView->resetCards(); pView->announce(""); for (int i = 0; i < 10; i++) pView->removePlayer(i); pView->Invalidate(); } // CONNRESET means server closed connection - it's ok if (!Global::CloseConnection())//errorCode_ != WSAECONNRESET) { CString msg; msg.Format(g_szErrFmt, errorCode_); if (AfxGetMainWnd()) AfxGetMainWnd()->MessageBox(msg, NULL, MB_OK|MB_ICONEXCLAMATION); } #else Global::Instance().closeConnections(); CFloorMap* pFM = CFloorMap::Instance(); if (pFM) pFM->disconnect(); if (!Global::CloseConnection()) { CString msg; msg.Format(g_szErrFmt, errorCode_); if (AfxGetMainWnd()) AfxGetMainWnd()->MessageBox(msg, NULL, MB_OK|MB_ICONEXCLAMATION); } #endif }
void PDUShowdown::execute(Base::GameState*) { CTableView* pView = CTableView::Instance(); if (pView) { Player* pPlayer = pView->getPlayer(player_); if (pPlayer) { if (num_cards_ == 0) { // // Player mucks hand - do muck hand animation // unless its the local player // if (!pView->isLocalPlayer(player_)) { pView->InvalidateRect(pPlayer->getCardPaintArea(Player::AllCards)); pPlayer->empty(); GameLogic::Instance().setNextState( new StateShowdown(player_, pPlayer->numCards())); } } else { // // Show player's cards // pView->InvalidateRect(pPlayer->getCardPaintArea(Player::AllCards)); CardEntry* pC = pCards_; for (int i = 0; i < num_cards_; i++, pC++) pPlayer->setCard(i, Card((Base::Suit)pC->suit_, pC->value_)); pPlayer->setShowAll(TRUE); } pView->InvalidateRect( pPlayer->getCardPaintArea(Player::AllCards)); if (message_) pPlayer->setActionText(message_); else pPlayer->setActionText(""); } } }
// // This PDU is always sent at the start of hand. // // The dealer is set twice to make sure the old // blind positions are erased and new positions // painted correctly. // // The player states are reset to sit-in. // void PDUButton::execute(Base::GameState* pState) { CTableView* pView = CTableView::Instance(); if (pView) { pView->resetCards(true); pView->setDealer(dealerslot_, true); static bool is_first_button = true; if (!is_first_button) { for (int i = 0; i < 10; i++) { Player* pP = pView->getPlayer(i); if (pP) { if (pP->getChips() > 0 && pP->getState() != Base::AllIn) { pP->setState(Base::SitIn); pP->setActionText("", true); } else { pP->setState(Base::SitOut); } } } } else is_first_button = true; pView->setDealer(dealerslot_, true); pView->Invalidate(); } if (GameLogic::Instance().currentState() == NULL) { // Set the next state already! GameLogic::Instance().setNextState(new StatePromptPostBlind(10, 0, 0)); } }
CTableView* TuiManager::createTableView(float tag, const char* img, int dir, int num, int cellWidth, int cellHeight, float x, float y, float w, float h, float rotation){ CTableView *pView = CTableView::create(Size(w, h)); m_isUseSpriteFrame ? pView->setBackgroundSpriteFrameName(img) : pView->setBackgroundImage(img); pView->setAutoRelocate(true); pView->setRotation(rotation); pView->setDirection((CScrollViewDirection)dir); pView->setCountOfCell(num); pView->setSizeOfCell(Size(cellWidth, cellHeight)); pView->setRotation(rotation); pView->setPosition(x, -y); pView->setTag(tag); return pView; }
void PDUPlayerInfo::execute(GameState*) { CString msg; CTableView* pTable = CTableView::Instance(); ASSERT(pTable); CChatView* pChat = CChatView::Instance(); int num_players_b4_pdu = pTable->numPlayers(); if (pTable) { int num_players = num_players_b4_pdu; PlayerInfo* pP = pPlayers_; if (pP != NULL) { for (int i = 0; i < num_players_; i++) { CString namesz = MakeString(pP->username_); Player* p = pTable->getPlayer(pP->slot_); bool wasThere = false; if (p && p->getName() == namesz) wasThere = true; pTable->addPlayer(namesz, CChips_n(pP->chips_).ntohl(), pP->slot_); // Set initial player state if (pP->state_ & PLAYER_STATE_ACTIVE) pTable->setState(pP->slot_, Base::SitIn); else pTable->setState(pP->slot_, Base::SitOut); Player* pPlayer = pTable->getPlayer(pP->slot_); ASSERT(pPlayer); if (pPlayer) { if (pP->state_ & PLAYER_STATE_ZOMBIE) pPlayer->setState(Base::Zombie); CString citysz = MakeString(pP->city_); pPlayer->setHomeCity(citysz); pTable->InvalidateRect(&pPlayer->getArea()); } if (pChat && !wasThere) { CString msg; msg.Format(g_szPlayerJoined, (LPCSTR)namesz, pP->slot_ + 1); pChat->addDealerMessage(msg, CChatView::CF_GameNormal); } pP++; } } // make a full redraw if original player // count was 0 if (num_players == 0) pTable->Invalidate(); } if (num_players_b4_pdu == 0) { // Send initial sit in status BOOL b = GameLogic::SitOut(); if (Global::TableServer()) { if (b) Global::TableServer()->sendPlaySitOutPDU(); else Global::TableServer()->sendPlaySitInPDU(); } // Send initial muck hand status b = GameLogic::HideHand(); if (Global::TableServer()) { if (b) Global::TableServer()->sendPlayHideCardsPDU(); else Global::TableServer()->sendPlayShowCardsPDU(); } // Done, start waiting for new hand to start GameLogic::Instance().setNextState(new StateWait()); } }
void PDUTournamentParams::execute(GameState* pS) { #ifdef PSPOT_TABLE_MODULE_ if (!Global::IsTournament()) { // Set tournament flag Global::SetIsTournament(true); if (CActionBar::Instance()) CActionBar::Instance()->setTournament(); } GameState* state = GameLogic::Instance().currentState(); if (state) { // Tell the current state to quit animations if any state->onCommand(MAKEWPARAM(ID_FINISH_DEAL, 0), 0); } if (flag_ == TF_Start) { GameLogic::Instance().setNextState(new StateWait("The tournament starts!")); SndMan::Instance()->playSound(SndMan::SM_Tournament); } else if (flag_ == TF_GameType) { // Map server enumerated values to client if (p1_ == Game_Type_Holdem) p1_ = GT_Holdem; else if (p1_ == Game_Type_Omaha) p1_ = GT_Omaha; else if (p1_ == Game_Type_SevenStud) p1_ = GT_SevenStud; else p1_ = GT_Holdem; CTableView* table = CTableView::Instance(); bool typeChanged = p1_ != Global::GetGameType(); bool wasHiLo = table ? table->getIsHiLo() : false; bool isHiLo = (p2_ != 0) ? true : false; bool hiloChanged = (wasHiLo != isHiLo); Global::SetGameType((GameType)p1_); CString s; s.Format("The game is %s", Global::GetGameName()); if (isHiLo) s += " Hi/Lo 8 or better"; if ((typeChanged || hiloChanged) && table) { if (typeChanged) table->reloadConfiguration(); table->setIsHiLo(isHiLo); table->setCaption(); GameLogic::Instance().setNextState(new StateWait(s)); } } else if (flag_ == TF_Limit) { bool changed = false; CTableView* table = CTableView::Instance(); if (table) { CChips lo, hi; lo.setRep(p1_); hi.setRep(p2_); changed = table->lolimit() != lo || table->hilimit() != hi; if (changed) { table->lolimit(lo); table->hilimit(hi); table->resetCaption(); } } if (changed) { CStrOut s; BetStructure bs = Global::GetBetting(); if (bs == BS_NoLimit) { CChips lolimit, sb, bb; lolimit.setRep(p1_); GetBlinds(lolimit, sb, bb); s << "The blinds are " << sb << '/' << bb << ". Betting is no-limit."; } else if (bs == BS_PotLimit) { CChips lolimit, sb, bb; lolimit.setRep(p1_); GetBlinds(lolimit, sb, bb); s << "The blinds are " << sb << '/' << bb << ". Betting is pot limit."; } else // (bs == BS_Limit) { CChips sb, bb; sb.setRep(p1_); bb.setRep(p2_); s << "The limits are " << sb << '/' << bb << '.'; } GameLogic::Instance().setNextState(new StateWait(s.str())); } } else if (flag_ == TF_BetStructure) { BetStructure bs = BS_Limit; if (p1_ == BS_PotLimit) bs = BS_PotLimit; else if (p1_ == BS_NoLimit) bs = BS_NoLimit; Global::SetBetting(bs); if (bs == BS_Limit) GameLogic::Instance().setNextState(new StateWait("Betting is limit based.")); else if (bs == BS_PotLimit) GameLogic::Instance().setNextState(new StateWait("Betting is pot limit.")); else if (bs == BS_NoLimit) GameLogic::Instance().setNextState(new StateWait("Betting is no limit.")); } else if (flag_ == TF_Freeze) { GameLogic::Instance().setNextState(new StateWait("The tournament is closed from new players.")); } else if (flag_ == TF_Dissolve) { GameLogic::Instance().setNextState(new StateWait("You will be seated to another table - please wait.")); } else if (flag_ == TF_Pause) { if (p1_ != 0) { CString s; if (p1_ > 60) { int mins = p1_ / 60; if (mins > 1) { s.Format("The tournament is paused %i minutes %i seconds for break.", mins, p1_ - 60 * (p1_ / 60)); } else { s.Format("The tournament is paused %i minute %i seconds for break.", mins, p1_ - 60 * (p1_ / 60)); } } else { s.Format("The tournament is paused %i seconds for break.", p1_); } GameLogic::Instance().setNextState(new StateWait(s)); } else GameLogic::Instance().setNextState(new StateWait("The tournament is paused -- please wait")); } #endif }
void PDUActionEcho::execute(GameState* pS) { // Call the corresponding routine to // visualize the action. CTableView* pView = CTableView::Instance(); if (!pView) return; Player* pPlayer = pView->getPlayer(slot_); if (!pPlayer) return; if (pS) { // Let the current state know of the action pS->onCommand(MAKEWPARAM(ID_PDU_ACTIONECHO, 0), reinterpret_cast<LPARAM>(this)); } // Get the state anew because actionecho handling might // have destroyed it pS = GameLogic::Instance().currentState(); if (action_ == PDUAction::Call) { Base::ImplementCall(pPlayer, slot_, amount_); } else if (action_ == PDUAction::Raise) { CChips bet; if (pS) { // Ask state the current bet pS->onCommand(MAKEWPARAM(ID_PDU_GETBET, 0), reinterpret_cast<LPARAM>(&bet)); } Base::ImplementRaise(pPlayer, slot_, bet, amount_); } else if (action_ == PDUAction::Fold) { Base::ImplementFold(pPlayer, slot_); if (pView->isLocalPlayer(slot_) && Base::GameLogic::LeaveTable()) { // User has clicked the Leave Table button // - send logout now Base::SetStatusText(pView, _T("Leaving table...")); if (Global::TableServer()) Global::TableServer()->sendSetupTableLogout(); } } else if (action_ == PDUAction::Ante) { Base::ImplementAnte(pPlayer, slot_, amount_); } else if (action_ == PDUAction::SitOut) { Base::ImplementSitOut(slot_, pPlayer); if (pView->isLocalPlayer(slot_) && Base::GameLogic::LeaveTable()) { // User has clicked the Leave Table button // - send logout now Base::SetStatusText(pView, _T("Leaving table...")); if (Global::TableServer()) Global::TableServer()->sendSetupTableLogout(); } } else { CString s; s.Format("*** Action Echo PDU: unrecognized action: %d", action_); PDU_DEBUG(s); } }
void PDUAnnounce::execute(GameState*) { CTableView* pTable = CTableView::Instance(); bool msgOnly = (winner_ == ANNOUNCE_FLAG_MSG); if (!msgOnly && pTable) { // Tell the current state to quit animations if any GameState* state = GameLogic::Instance().currentState(); if (state) state->onCommand(MAKEWPARAM(ID_STOPANIMATION, 0), 0); pTable->endBettingRound(true); } CChatView* pChat = CChatView::Instance(); if (pChat && pTable) { CString name("unknown"); Base::Player* p = pTable->getPlayer(winner_); if (p) { name = p->getName(); pTable->showWinner(winner_, 3000); // animate 3 secs } // Replace newlines with spaces CString s(message_); for (int i = 0; i < s.GetLength(); i++) { if (s[i] == '\n' || s[i] == '\r') s.SetAt(i, ' '); } if (msgOnly) pChat->addDealerMessage(s, CChatView::CF_GameNormal); else pChat->addDealerMessage(s, CChatView::CF_Fatal); if (!msgOnly) { CChips chipsInPot = pTable->resetPot(); if (pTable->isLocalPlayer(winner_)) { if (chipsInPot > 100) SndMan::Instance()->playSound(SndMan::SM_RakeInLarge); else SndMan::Instance()->playSound(SndMan::SM_RakeInSmall); } else { SndMan::Instance()->playSound(SndMan::SM_Show); } } #ifdef SHOW_ANNOUNCEMENT_RECT_ // The announcement rectangle is not currently used. pTable->announce(message_); #endif } if (!msgOnly && GameLogic::LeaveTable()) { // User has clicked the Leave Table button // - send logout now if (pTable) Base::SetStatusText(pTable, _T("Leaving table...")); if (Global::TableServer()) Global::TableServer()->sendSetupTableLogout(); } }