#include "CocosGUIExamplesWeaponScene.h"
const char* shop_textures[8] =
{
"cocosgui/gui_examples/DemoShop/armour.png",
"cocosgui/gui_examples/DemoShop/helmet.png",
"cocosgui/gui_examples/DemoShop/shield.png",
"cocosgui/gui_examples/DemoShop/sword.png",
"cocosgui/gui_examples/DemoShop/gloves.png",
"cocosgui/gui_examples/DemoShop/dimensity.png",
"cocosgui/gui_examples/DemoShop/dart.png",
"cocosgui/gui_examples/DemoShop/backpack.png",
};
const char* shop_names[8] =
{
"Armour",
"Helmet",
"Shield",
"Sword",
"Gloves",
"Dimensity",
"Dart",
"Backpack",
};
const char* shop_price_units[8] =
{
"Counpon",
"Binding",
"Medal",
"Counpon",
"Binding",
"Medal",
"Counpon",
"Binding",
};
const int shop_prices[8] =
{
19,
10,
22,
20,
8,
17,
5,
4,
};
CocosGUIExamplesWeaponScene::CocosGUIExamplesWeaponScene()
: m_nIndex(-1)
, m_nCount(0)
, m_nCoupon(COUPON_MAX)
, m_nBinding(BINDING_MAX)
, m_nMedal(MEDAL_MAX)
{
CCScene::init();
}
CocosGUIExamplesWeaponScene::~CocosGUIExamplesWeaponScene()
{
}
void CocosGUIExamplesWeaponScene::onEnter()
{
CCScene::onEnter();
m_pUILayer = UILayer::create();
m_pUILayer->scheduleUpdate();
addChild(m_pUILayer);
ShopInit();
popupInit();
// BuyInit();
}
void CocosGUIExamplesWeaponScene::onExit()
{
m_pUILayer->removeFromParent();
// SceneReader::sharedSceneReader()->purgeSceneReader();
// GUIReader::shareReader()->purgeGUIReader();
//cocos2d::extension::ActionManager::shareManager()->purgeActionManager();
CCScene::onExit();
}
void CocosGUIExamplesWeaponScene::menuCloseCallback(CCObject* pSender, TouchEventType type)
{
if (type == TOUCH_EVENT_ENDED)
{
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
}
// shop
void CocosGUIExamplesWeaponScene::ShopInit()
{
// shop Layout from json
Layout* shop_root = static_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("cocosgui/gui_examples/DemoShop/DemoShop.json"));
m_pUILayer->addWidget(shop_root);
// shop scrollview
UIScrollView* shop_scrollview = static_cast<UIScrollView*>(shop_root->getChildByName("shop_ScrollView"));
// shop scrollview children
for (int i = 0; i < shop_scrollview->getChildren()->count(); ++i)
{
Layout* shop_layout = static_cast<Layout*>(shop_scrollview->getChildren()->objectAtIndex(i));
shop_layout->setTag(SHOP_ITEM_LAYOUT_TAG + i);
// buy button
UIButton* buy_button = static_cast<UIButton*>(shop_layout->getChildByName("buy_Button"));
buy_button->addTouchEventListener(this, toucheventselector(CocosGUIExamplesWeaponScene::popupLogic));
}
// ranking scrollview
UIScrollView* ranking_scrollview = static_cast<UIScrollView*>(shop_root->getChildByName("ranking_ScrollView"));
// ranking scrollview children
for (int i = 0; i < ranking_scrollview->getChildren()->count(); ++i)
{
Layout* ranking_layout = static_cast<Layout*>(ranking_scrollview->getChildren()->objectAtIndex(i));
for (int j = 0; j < shop_scrollview->getChildren()->count(); ++j)
{
Layout* shop_layout = static_cast<Layout*>(shop_scrollview->getChildren()->objectAtIndex(j));
if (strcmp(ranking_layout->getName(), shop_layout->getName()) == 0)
{
ranking_layout->setTag(RANKING_ITEM_LAYOUT_TAG + (shop_layout->getTag() - SHOP_ITEM_LAYOUT_TAG));
}
}
}
for (int i = 0; i < ranking_scrollview->getChildren()->count(); ++i)
{
Layout* ranking_layout = static_cast<Layout*>(ranking_scrollview->getChildren()->objectAtIndex(i));
// buy button
UIButton* buy_button = static_cast<UIButton*>(ranking_layout->getChildByName("buy_Button"));
buy_button->addTouchEventListener(this, toucheventselector(CocosGUIExamplesWeaponScene::popupLogic));
}
// back button
UIButton* back_button = static_cast<UIButton*>(shop_root->getChildByName("back_Button"));
back_button->addTouchEventListener(this, toucheventselector(CocosGUIExamplesWeaponScene::menuCloseCallback));
}
// popup
void CocosGUIExamplesWeaponScene::popupInit()
{
// buy layout
Layout* buy_layout = static_cast<Layout*>(m_pUILayer->getWidgetByName("buy_Panel"));
// add button
UIButton* add_button = static_cast<UIButton*>(buy_layout->getChildByName("add_Button"));
add_button->addTouchEventListener(this, toucheventselector(CocosGUIExamplesWeaponScene::popupCalculate));
// sub button
UIButton* sub_button = static_cast<UIButton*>(buy_layout->getChildByName("sub_Button"));
sub_button->addTouchEventListener(this, toucheventselector(CocosGUIExamplesWeaponScene::popupCalculate));
// number labelatlas
UILabelAtlas* number_labelAtlas = static_cast<UILabelAtlas*>(buy_layout->getChildByName("number_LabelAtlas"));
number_labelAtlas->setStringValue(CCString::createWithFormat("%d", m_nCount)->getCString());
// coupon number labelatlas
UILabelAtlas* couponNumber_labelAtlas = static_cast<UILabelAtlas*>(buy_layout->getChildByName("coupon_number_LabelAtlas"));
couponNumber_labelAtlas->setStringValue(CCString::createWithFormat("%d", m_nCoupon)->getCString());
// binding number labelatlas
UILabelAtlas* bindingNumber_labelAtlas = static_cast<UILabelAtlas*>(buy_layout->getChildByName("binding_number_LabelAtlas"));
bindingNumber_labelAtlas->setStringValue(CCString::createWithFormat("%d", m_nBinding)->getCString());
// medal number labelatlas
UILabelAtlas* medalNumber_labelAtlas = static_cast<UILabelAtlas*>(buy_layout->getChildByName("medal_number_LabelAtlas"));
medalNumber_labelAtlas->setStringValue(CCString::createWithFormat("%d", m_nMedal)->getCString());
// buy button
UIButton* buy_button = static_cast<UIButton*>(buy_layout->getChildByName("buy_Button"));
buy_button->addTouchEventListener(this, toucheventselector(CocosGUIExamplesWeaponScene::popupClose));
buy_button->setTouchEnabled(true);
// close button
UIButton* close_button = static_cast<UIButton*>(buy_layout->getChildByName("close_Button"));
close_button->addTouchEventListener(this, toucheventselector(CocosGUIExamplesWeaponScene::popupClose));
}
void CocosGUIExamplesWeaponScene::popupClose(CCObject *pSender, TouchEventType type)
{
if (type == TOUCH_EVENT_ENDED)
{
Layout* buy_layout = static_cast<Layout*>(m_pUILayer->getWidgetByName("buy_Panel"));
buy_layout->setVisible(false);
// process shop ranking touchEnabled
CCObject* obj = NULL;
// shop scrollview
UIScrollView* shop_scrollview = static_cast<UIScrollView*>(m_pUILayer->getWidgetByName("shop_ScrollView"));
// shop scrollview children
CCARRAY_FOREACH(shop_scrollview->getChildren(), obj)
{
Layout* shop_layout = static_cast<Layout*>(obj);
// buy button
UIButton* buy_button = static_cast<UIButton*>(shop_layout->getChildByName("buy_Button"));
buy_button->setTouchEnabled(true);
}
// ranking scrollview
UIScrollView* ranking_scrollview = static_cast<UIScrollView*>(m_pUILayer->getWidgetByName("ranking_ScrollView"));
// ranking scrollview children
CCARRAY_FOREACH(ranking_scrollview->getChildren(), obj)
{
Layout* ranking_layout = static_cast<Layout*>(obj);
// buy button
UIButton* buy_button = static_cast<UIButton*>(ranking_layout->getChildByName("buy_Button"));
buy_button->setTouchEnabled(true);
}
}
}
void CocosGUIExamplesWeaponScene::popupLogic(CCObject *pSender, TouchEventType type)
{
if (type == TOUCH_E
没有合适的资源?快使用搜索试试~ 我知道了~
游戏商城功能
共85个文件
png:66个
fnt:8个
json:3个
4星 · 超过85%的资源 需积分: 49 47 下载量 110 浏览量
2014-03-02
15:05:48
上传
评论 1
收藏 1.87MB RAR 举报
温馨提示
游戏商城功能: 1.商品列表显示 2.购买商品(可按数量购买)
资源推荐
资源详情
资源评论
收起资源包目录
demo.rar (85个子文件)
demo
Resources
cocosgui
gui_examples
DemoShop
backpack.png 4KB
Heiti20.fnt 9KB
Heiti8.fnt 9KB
gloves.png 4KB
buy_2.png 1KB
bg.png 19KB
Heiti14.fnt 9KB
Heiti9.fnt 9KB
Heiti8.png 22KB
buy_bg.png 7KB
sword.png 3KB
dimensity.png 3KB
Heiti20.png 58KB
button_2.png 2KB
add_1.png 779B
add_2.png 749B
buy_1.png 1KB
Heiti14.png 40KB
armour.png 5KB
close_2.png 1KB
shield.png 5KB
number.png 3KB
slot.png 2KB
button_1.png 2KB
DemoShop.json 258KB
coin.png 1KB
sub_2.png 649B
dart.png 6KB
helmet.png 3KB
Heiti9.png 26KB
sub_1.png 675B
close_1.png 1KB
hd
cocosgui
gui_examples
DemoShop
backpack.png 19KB
Heiti20.fnt 9KB
Heiti8.fnt 9KB
gloves.png 17KB
buy_2.png 6KB
bg.png 84KB
Heiti14.fnt 9KB
Heiti9.fnt 9KB
Heiti8.png 46KB
buy_bg.png 30KB
sword.png 13KB
dimensity.png 15KB
Heiti20.png 122KB
button_2.png 9KB
add_1.png 4KB
add_2.png 4KB
buy_1.png 6KB
Heiti14.png 83KB
armour.png 21KB
close_2.png 7KB
shield.png 23KB
number.png 9KB
slot.png 7KB
button_1.png 9KB
DemoShop.json 258KB
coin.png 5KB
sub_2.png 4KB
dart.png 26KB
helmet.png 15KB
Heiti9.png 52KB
sub_1.png 4KB
close_1.png 6KB
UITest
r2.png 11KB
b1.png 17KB
background.png 381KB
b2.png 17KB
r1.png 11KB
buttonBackground.png 498B
UITest.json 12KB
f2.png 17KB
f1.png 17KB
ribbon.png 2KB
fonts
Marker Felt.ttf 25KB
arial.ttf 760KB
CloseSelected.png 5KB
CloseNormal.png 6KB
HelloWorld.png 136KB
Classes
CocosGUIExamplesWeaponScene.cpp 15KB
AppDelegate.h 955B
HelloWorldScene.h 604B
CocosGUIExamplesWeaponScene.h 3KB
HelloWorldScene.cpp 3KB
AppDelegate.cpp 2KB
共 85 条
- 1
资源评论
- HandOfSorrow2014-04-12挺好的,可以参考
- linyiquan2018-07-28好资源,谢分享。
热血枫叶
- 粉丝: 388
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功