CShopDialog类

#ifndef SHOP_H
#define SHOP_H

#include "XWidget.h"
#include "GameConfig.h"

class CXStatic;
class CXImage;
class CXButton;
class CXTimer;
class CXCommon;

#define SHOP_NOCHECKED_INIT_ID    1060
#define    SHOP_CHECKED_INIT_ID    1050
#define SHOP_GOODS_NUM            6
#define SHOP_GOODS_BTN_INIT_ID    1070
#define SHOP_PRICE_FRAME        1033
#define SHOP_STA_PRICE            1040
#define SHOP_TIME                0.3
#define SHOP_STATIC_NUM            8
#define SHOP_INTRODUCTION        "shop_"




class CShopDialog : public CXWidget
{
public:
    enum ShopDialogId
    {
        _IDD_ShopDialog = 131,
        _IDC_BtnBuy = 1003,
        _IDC_BtnBack = 1010,
        _IDC_ImgBoss = 1001,
        _IDC_ImgStore = 1002,
        _IDC_Decoration1 = 1004,
        _IDC_Decoration2 = 1005,
        _IDC_ImgSparFrame = 1030,
        _IDC_ImgSectExp    = 1031,
        _IDC_StaIntroduction = 1048,
    };
public:
    CShopDialog(void);
    ~CShopDialog(void);
    bool init();
    void btnMsgCallback(CCObject* pSender);
    virtual void setVisible(bool visible);
    void refreshDlg();
    void onTimerEnd(CCObject* obj);
private:
    CXImage*        m_pImgBoss;
    CXImage*        m_pImgStore;
    CXImage*        m_pImgDecoration1;
    CXImage*        m_pImgDecoration2;
    CXImage*        m_pImgChecked[SHOP_GOODS_NUM];
    CXButton*        m_pBtnBuy;
    CXButton*        m_pBtnBack;
    CXStatic*        m_pStaIntroduction;
    CXTimer*        m_pTimer;
    CCNode*            m_pStorePad;
    int                m_nCheckedIndex;
};

#endif
#include "ShopDialog.h"
#include "WidgetMgr.h"
#include "XButton.h"
#include "XImage.h"
#include "XStatic.h"
#include "XCommon.h"
#include "EncyclopediaDialog.h"
#include "GameConfig.h"
#include "GameLogic.h"
#include "hero.h"
#include "Config.h"
#include "WorldmapDialog.h"
#include "XTimer.h"
#include "XCommon.h"

CShopDialog::CShopDialog(void)
{
    m_pImgBoss = NULL;
    m_pImgStore = NULL;
    m_pBtnBuy = NULL;
    m_pBtnBack = NULL;
    m_pImgDecoration1 = NULL;
    m_pImgDecoration2 = NULL;
    m_pStorePad = NULL;
    m_pTimer = NULL;
    m_pStaIntroduction = NULL;
    m_nCheckedIndex = 0;

    for (int i = 0; i < SHOP_GOODS_NUM; i++)
    {
        m_pImgChecked[i] = NULL;
    }
}


CShopDialog::~CShopDialog(void)
{
}

bool CShopDialog::init()
{
    CWidgetMgr::getInstance()->loadWidget(this, _IDD_ShopDialog);
    CWidgetMgr::getInstance()->addWnd(this);
    for (deque<CXWindow*>::const_iterator it = this->getDequeWnd().begin(); it != this->getDequeWnd().end(); it++)
    {
        if (UI_BUTTON == (*it)->getUIType())
        {
            (*it)->setClickListener(this, callfuncO_selector(CShopDialog::btnMsgCallback));
        }
    }

    m_pStorePad = CCNode::create();
    this->addChild(m_pStorePad);
    m_pStorePad->setPosition(0,0);

    CXWindow* pWnd = NULL;
    
    pWnd = this->getCtrl(_IDC_ImgSparFrame);
    pWnd->getParent()->removeChild(pWnd, false);
    m_pStorePad->addChild(pWnd);

    pWnd = this->getCtrl(_IDC_ImgSectExp);
    pWnd->getParent()->removeChild(pWnd, false);
    m_pStorePad->addChild(pWnd);

    pWnd = this->getCtrl(_IDC_ImgStore);
    pWnd->getParent()->removeChild(pWnd, false);
    m_pStorePad->addChild(pWnd);

    for (int i = 0; i < SHOP_GOODS_NUM; i++)
    {
        m_pImgChecked[i] = (CXImage*)this->getCtrl(SHOP_CHECKED_INIT_ID + i);
        ASSERT(m_pImgChecked[i]);
        m_pImgChecked[i]->setVisible(false);

        pWnd = this->getCtrl(SHOP_NOCHECKED_INIT_ID + i);
        pWnd->getParent()->removeChild(pWnd, false);
        m_pStorePad->addChild(pWnd);

        pWnd = this->getCtrl(SHOP_CHECKED_INIT_ID + i);
        pWnd->getParent()->removeChild(pWnd, false);
        m_pStorePad->addChild(pWnd);

        pWnd = this->getCtrl(SHOP_PRICE_FRAME + i);
        pWnd->getParent()->removeChild(pWnd, false);
        m_pStorePad->addChild(pWnd);

    }

    for (int i = 0; i < SHOP_STATIC_NUM; i++)
    {
        pWnd = this->getCtrl(SHOP_STA_PRICE + i);
        pWnd->getParent()->removeChild(pWnd, false);
        m_pStorePad->addChild(pWnd);
    }
    
    pWnd = this->getCtrl(_IDC_StaIntroduction);
    pWnd->getParent()->removeChild(pWnd, false);
    m_pStorePad->addChild(pWnd);

    m_pStaIntroduction = (CXStatic*)this->getCtrl(_IDC_StaIntroduction);
    ASSERT(m_pStaIntroduction);
    m_pStaIntroduction->reorderChild(m_pStaIntroduction,5);

    m_pImgBoss = (CXImage*)this->getCtrl(_IDC_ImgBoss);
    ASSERT(m_pImgBoss);
    m_pImgBoss->setVisible(false);
    this->reorderChild(m_pImgBoss, 5);

    m_pImgStore = (CXImage*)this->getCtrl(_IDC_ImgStore);
    ASSERT(m_pImgStore);
    m_pImgStore->setVisible(false);

    m_pBtnBuy = (CXButton*)this->getCtrl(_IDC_BtnBuy);
    ASSERT(m_pBtnBuy);
    m_pBtnBuy->setVisible(false);
    this->reorderChild(m_pBtnBuy, 5);

    m_pBtnBack = (CXButton*)this->getCtrl(_IDC_BtnBack);
    ASSERT(m_pBtnBack);
    m_pBtnBack->setVisible(false);

    m_pImgDecoration1 = (CXImage*)this->getCtrl(_IDC_Decoration1);
    ASSERT(m_pImgDecoration1);
    m_pImgDecoration1->setVisible(false);
    this->reorderChild(m_pImgDecoration1, 5);

    m_pImgDecoration2 = (CXImage*)this->getCtrl(_IDC_Decoration2);
    ASSERT(m_pImgDecoration2);
    m_pImgDecoration2->setVisible(false);
    this->reorderChild(m_pImgDecoration2, 5);
    
    m_pTimer = new CXTimer();
    m_pTimer->init(2, 0.2f);
    m_pTimer->autorelease();
    this->addChild(m_pTimer);
    m_pTimer->setTimerEndListener(this, callfuncO_selector(CShopDialog::onTimerEnd));
    

    this->setVisible(false);
    return true;
}

void CShopDialog::onTimerEnd(CCObject* obj)
{
    m_pStorePad->setPosition(m_pStorePad->getPosition().x,m_pStorePad->getPosition().y - 768);
    m_pImgBoss->setPosition(m_pImgBoss->getPosition().x + 1024,m_pImgBoss->getPosition().y);
    m_pBtnBuy->setPosition(m_pBtnBuy->getPosition().x,m_pBtnBuy->getPosition().y + 768);
    m_pBtnBack->setPosition(m_pBtnBack->getPosition().x,m_pBtnBack->getPosition().y - 768);
    m_pImgDecoration1->setPosition(m_pImgDecoration1->getPosition().x,m_pImgDecoration1->getPosition().y + 768);
    m_pImgDecoration2->setPosition(m_pImgDecoration2->getPosition().x,m_pImgDecoration2->getPosition().y + 768);
    this->setVisible(false);
    m_pStorePad->stopAllActions();
    m_pImgBoss->stopAllActions();
    m_pBtnBuy->stopAllActions();
    m_pBtnBack->stopAllActions();
    m_pImgDecoration1->stopAllActions();
    m_pImgDecoration2->stopAllActions();

    ((CWorldmapDialog*)CWidgetMgr::getInstance()->getWnd(CWorldmapDialog::_IDD_ChooseMenuDialog))->entrance();
}

void CShopDialog::btnMsgCallback(CCObject* pSender)
{
    CXButton* pButton = (CXButton*)pSender;

    switch(pButton->getId())
    {
    case _IDC_BtnBack:
        {
            //这里写退出特效
            m_pStorePad->runAction(CCMoveTo::create(SHOP_TIME,
                CCPoint(m_pStorePad->getPosition().x,m_pStorePad->getPosition().y + 768)));
            m_pImgBoss->runAction(CCMoveTo::create(SHOP_TIME,
                CCPoint(m_pImgBoss->getPosition().x - 1024,m_pImgBoss->getPosition().y)));
            m_pBtnBuy->runAction(CCMoveTo::create(SHOP_TIME,
                CCPoint(m_pBtnBuy->getPosition().x,m_pBtnBuy->getPosition().y - 768)));
            m_pBtnBack->runAction(CCMoveTo::create(SHOP_TIME,
                CCPoint(m_pBtnBack->getPosition().x,m_pBtnBack->getPosition().y + 768)));
            m_pImgDecoration1->runAction(CCMoveTo::create(SHOP_TIME,
                CCPoint(m_pImgDecoration1->getPosition().x,m_pImgDecoration1->getPosition().y - 768)));
            m_pImgDecoration2->runAction(CCMoveTo::create(SHOP_TIME,
                CCPoint(m_pImgDecoration2->getPosition().x,m_pImgDecoration2->getPosition().y - 768)));
            if (m_pTimer)
            {
                m_pTimer->setCount(3);
                m_pTimer->start();
            }
        }
        break;
    default:
        break;
    }

    if (pButton->getId() >= SHOP_GOODS_BTN_INIT_ID && pButton->getId() < SHOP_GOODS_BTN_INIT_ID + SHOP_GOODS_NUM)
    {
        m_nCheckedIndex = pButton->getId() - SHOP_GOODS_BTN_INIT_ID;
    }

    if (this->isVisible())
    {
        this->refreshDlg();
    }
}

void CShopDialog::setVisible(bool visible)
{
    CXWidget::setVisible(visible);
    if (visible)
    {
        //这里做效果
        CCPoint tPos = m_pStorePad->getPosition();
        m_pStorePad->setPosition(m_pStorePad->getPosition().x ,m_pStorePad->getPosition().y + CConfig::getInstance()->getNumberByKey("shop_store_startpos_y"));
        m_pImgStore->setVisible(true);
        m_pStorePad->runAction(CCSequence::create(
            CCMoveTo::create(CConfig::getInstance()->getNumberByKey("shop_store_showtime"),CCPoint(tPos.x ,tPos.y + CConfig::getInstance()->getNumberByKey("shop_boss01_y"))),
            CCMoveTo::create(CConfig::getInstance()->getNumberByKey("shop_store_showtime"),CCPoint(tPos.x ,tPos.y + CConfig::getInstance()->getNumberByKey("shop_boss02_y"))),
            CCMoveTo::create(CConfig::getInstance()->getNumberByKey("shop_store_showtime"),CCPoint(tPos.x ,tPos.y + CConfig::getInstance()->getNumberByKey("shop_boss03_y"))),
            CCMoveTo::create(CConfig::getInstance()->getNumberByKey("shop_store_showtime"),CCPoint(tPos.x ,tPos.y + CConfig::getInstance()->getNumberByKey("shop_boss04_y"))),
            CCMoveTo::create(CConfig::getInstance()->getNumberByKey("shop_store_showtime"),CCPoint(tPos.x ,tPos.y)),NULL));

        tPos = m_pImgBoss->getPosition();
        m_pImgBoss->setPosition(m_pImgBoss->getPosition().x - CConfig::getInstance()->getNumberByKey("shop_screen_width"), m_pImgBoss->getPosition().y);
        m_pImgBoss->setVisible(true);
        m_pImgBoss->runAction(CCMoveTo::create(CConfig::getInstance()->getNumberByKey("shop_boss_movetime"),tPos));

        CCActionInterval* pFloatUp = CCMoveBy::create(CConfig::getInstance()->getNumberByKey("shop_boss_floattime"),
            CCPoint(CConfig::getInstance()->getNumberByKey("shop_boss_moveby_x"),
                    CConfig::getInstance()->getNumberByKey("shop_boss_moveby_y")));
        CCActionInterval* pReFloat = CCRepeatForever::create(static_cast<CCSequence *>(CCSequence::create(pFloatUp,pFloatUp->reverse(),NULL)));
        m_pImgBoss->runAction(pReFloat);

        tPos = m_pBtnBuy->getPosition();
        m_pBtnBuy->setPosition(m_pBtnBuy->getPosition().x, 
                m_pBtnBuy->getPosition().y - CConfig::getInstance()->getNumberByKey("shop_screen_heigh"));
        m_pBtnBuy->setVisible(true);
        m_pBtnBuy->runAction(CCMoveTo::create(
            CConfig::getInstance()->getNumberByKey("shop_btnbuy_time"),tPos));

        tPos = m_pBtnBack->getPosition();
        m_pBtnBack->setPosition(m_pBtnBack->getPosition().x , m_pBtnBack->getPosition().y + 768);
        m_pBtnBack->setVisible(true);
        m_pBtnBack->runAction(CCMoveTo::create(
            CConfig::getInstance()->getNumberByKey("shop_btnback_time"),tPos));

        pFloatUp = CCMoveBy::create(
            CConfig::getInstance()->getNumberByKey("shop_btnback_moveby_time"),
            CCPoint(CConfig::getInstance()->getNumberByKey("shop_btnback_moveby_x"),
                    CConfig::getInstance()->getNumberByKey("shop_btnback_moveby_y")));
        pReFloat = CCRepeatForever::create(static_cast<CCSequence *>(CCSequence::create(pFloatUp,pFloatUp->reverse(),NULL)));
        m_pBtnBack->runAction(pReFloat);

        tPos = m_pImgDecoration1->getPosition();
        m_pImgDecoration1->setPosition(tPos.x,tPos.y - CConfig::getInstance()->getNumberByKey("shop_screen_heigh"));
        m_pImgDecoration1->setVisible(true);
        m_pImgDecoration1->runAction(CCMoveTo::create(CConfig::getInstance()->getNumberByKey("shop_decoration1_movetime"),tPos));
        pFloatUp = CCMoveBy::create(CConfig::getInstance()->getNumberByKey("shop_decoration1_floatime"),
                                    CCPoint(CConfig::getInstance()->getNumberByKey("shop_decoration1_moveby_x"),
                                            CConfig::getInstance()->getNumberByKey("shop_decoration1_moveby_y")));
        pReFloat = CCRepeatForever::create(static_cast<CCSequence *>(CCSequence::create(pFloatUp,pFloatUp->reverse(),NULL)));
        m_pImgDecoration1->runAction(pReFloat);

        tPos = m_pImgDecoration2->getPosition();
        m_pImgDecoration2->setPosition(tPos.x,tPos.y - CConfig::getInstance()->getNumberByKey("shop_screen_heigh"));
        m_pImgDecoration2->setVisible(true);
        m_pImgDecoration2->runAction(CCMoveTo::create(CConfig::getInstance()->getNumberByKey("shop_decoration2_movetime"),tPos));
        m_pImgDecoration2->setVisible(true);
        pFloatUp = CCMoveBy::create(CConfig::getInstance()->getNumberByKey("shop_decoration2_floatime"),
                                    CCPoint(CConfig::getInstance()->getNumberByKey("shop_decoration2_moveby_x"),
                                            CConfig::getInstance()->getNumberByKey("shop_decoration2_moveby_y")));
        pReFloat = CCRepeatForever::create(static_cast<CCSequence *>(CCSequence::create(pFloatUp,pFloatUp->reverse(),NULL)));
        m_pImgDecoration2->runAction(pReFloat);

        m_nCheckedIndex = 0;
        this->refreshDlg();
    }
}

void CShopDialog::refreshDlg()
{
    for (int i = 0; i < SHOP_GOODS_NUM; i++)
    {
        m_pImgChecked[i]->setVisible(false);
    }
    m_pImgChecked[m_nCheckedIndex]->setVisible(true);
    m_pStaIntroduction->setText(CConfig::getInstance()->getWordBykey((string(SHOP_INTRODUCTION) + CXCommon::toString(m_nCheckedIndex)).c_str()).c_str());
}

 

你可能感兴趣的:(dialog)