#include "HelloWorldScene.h"
#include "CunDangScene.h"
#include "AppDelegate.h"
#include "cocos/ui/CocosGUI.h"
#include "cocos2d.h" 
#include "first.h" 
using namespace cocos2d;
using namespace ui;
USING_NS_CC;
int y, k;
Scene* CunDangScene::createScene(){
	return CunDangScene::create();
}
bool CunDangScene::init(){
	if (!Scene::init()){
		return false;
	}
	Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
	////////////////////////////////////////////////////
	auto node8 = Sprite::create("zhujiemian.png");
	node8->setPosition(Vec2(1920, 1280));
	this->addChild(node8, 4);

	auto btn1 = Button::create("exit.png", "exit.png");
	btn1->setScale9Enabled(true);
	btn1->setTitleFontSize(35);
	btn1->setContentSize(Size(1000, 400));
	btn1->setPosition(Vec2(3340, 500));
	btn1->addTouchEventListener([this, visibleSize](Ref* senderButton, ui::Widget::TouchEventType eventType) {
		auto button = static_cast<ui::Button*>(senderButton);
		switch (eventType) {
		case ui::Widget::TouchEventType::BEGAN: { CCLOG("Button Touch Began"); break; }
		case ui::Widget::TouchEventType::MOVED: { CCLOG("Button Touch Moved"); break; }
		case ui::Widget::TouchEventType::CANCELED: { CCLOG("Button Touch Cancelled"); break; }
		case ui::Widget::TouchEventType::ENDED: {
			CCLOG("Button Touch Ended");
			CCLOG("do action:");
			auto actionGrow = ScaleTo::create(.1f, 2.0f);
			auto actionShrink = ScaleTo::create(.1f, 1.0f);
			button->runAction(Sequence::createWithTwoActions(actionGrow, actionShrink));
			Scene* pScene = HelloWorld::createScene();
			Director::getInstance()->replaceScene(pScene);
			break;
		}
		}
	});
	this->addChild(btn1, 5);

	if (k == 1) {
		auto btn1 = Button::create("first.png", "first.png");
		btn1->setScale9Enabled(true);
		//btn->setTitleText("Jump");
		btn1->setTitleFontSize(35);
		btn1->setContentSize(Size(400, 133));
		btn1->setPosition(Vec2(500, 2000));
		btn1->addTouchEventListener([this, visibleSize](Ref* senderButton, ui::Widget::TouchEventType eventType) {
			auto button = static_cast<ui::Button*>(senderButton);
			switch (eventType) {
			case ui::Widget::TouchEventType::BEGAN: { CCLOG("Button Touch Began"); break; }
			case ui::Widget::TouchEventType::MOVED: { CCLOG("Button Touch Moved"); break; }
			case ui::Widget::TouchEventType::CANCELED: { CCLOG("Button Touch Cancelled"); break; }
			case ui::Widget::TouchEventType::ENDED: {
				CCLOG("Button Touch Ended");
				CCLOG("do action:");
				auto actionGrow = ScaleTo::create(.1f, 2.0f);
				auto actionShrink = ScaleTo::create(.1f, 1.0f);
				button->runAction(Sequence::createWithTwoActions(actionGrow, actionShrink));
				Scene* pScene = first::createScene();
				Director::getInstance()->replaceScene(pScene);
				//this->removeFromParentAndCleanup(true);
				break;
				}
			}
		});
		this->addChild(btn1, 5);
	}

    return true;
}


void CunDangScene::ttt1(int i) {
	if (i == 1) {
		UserDefault::getInstance()->setIntegerForKey("int1", i);
	}
	int intVar1 = UserDefault::getInstance()->getIntegerForKey("int1");
	k = intVar1;
}

