Beispiel #1
0
void main(void){

	init();

	stop();

	int delayms = (int)((random() / 32767.0) * MAX_START_DELAY);  //Get random number between 0 and 5000

	
	if(SWITCH_ON){
		delay_ms(delayms);
	}

	while (1){

		if(SWITCH_ON){
			goOut();
 		} else {
			goIn();
		}
	}

}
bool OptionScene::init()
{
	if (!Scene::init())
		return false;
	Size visibleSize = Director::getInstance()->getVisibleSize();
	//--·µ»Ø°´Å¥--//
	auto exitScene = [](Ref* pSender) {
		Director::getInstance()->replaceScene(TransitionFlipX::create(0.5f, MainScene::create(), TransitionScene::Orientation::LEFT_OVER));
	};
	auto backItem = MenuItemImage::create("UI/BackNormal.png", "UI/BackSelected.png", exitScene);
	backItem->setPosition(Vec2(backItem->getContentSize().width / 2 + 10, visibleSize.height - backItem->getContentSize().height / 2 - 10));
	auto backMenu = Menu::create(backItem, NULL);
	backMenu->setPosition(Vec2::ZERO);
	this->addChild(backMenu);
	//--¸ù²Ëµ¥--//
	auto rootLayout = createLayout(Lang::get("optionTitle"), this->getContentSize());
	this->addChild(rootLayout);

	auto list = ListView::create();
	list->setDirection(ScrollView::Direction::VERTICAL);
	list->setGravity(ListView::Gravity::CENTER_HORIZONTAL);
	list->setBounceEnabled(true);
	list->setItemsMargin(10);
	list->setContentSize(Size(700, 480));
	list->setAnchorPoint(Vec2(0.5f, 0.5f));
	list->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2 - 20));
	rootLayout->addChild(list);
	//--ÓïÑÔ°´Å¥--//
	auto langButton = createButton(Lang::get("selectLang"), Size(600, 60), [=](Ref* pSender) {
		auto button = (Button*)pSender;
		auto langLayout = createLayout(Lang::get("selectLang"), Size(600, 600));
		auto langList = ListView::create();
		langList->setDirection(ScrollView::Direction::VERTICAL);
		langList->setItemsMargin(10);
		langList->setGravity(ListView::Gravity::CENTER_HORIZONTAL);
		langList->setBounceEnabled(true);
		langList->setContentSize(Size(600, 480));
		langList->setAnchorPoint(Vec2(0.5f, 0.5f));
		langList->setPosition(Vec2(langLayout->getContentSize().width / 2, langLayout->getContentSize().height / 2 - 20));
		langLayout->addChild(langList);
		auto langs = Lang::getAllLangs();

		auto autoLangButton = createButton(Lang::get("autoLang"), Size(500, 60), [this](Ref* pSender) {
			auto button = static_cast<Button*> (pSender);
			highlightingButton->loadTextureNormal("UI/ButtonNormal.png");
			highlightingButton->setContentSize(Size(500, 60));
			highlightingButton = button;
			button->loadTextureNormal("UI/ButtonActive.png");
			button->setContentSize(Size(500, 60));
			Lang::setAutoLang(true);
			Lang::loadAutoLang();
		});
		if (Lang::isAutoLang()) {
			autoLangButton->loadTextureNormal("UI/ButtonActive.png");
			autoLangButton->setContentSize(Size(500, 60));
			highlightingButton = autoLangButton;
		}
		langList->addChild(autoLangButton);
		for (auto i : langs) {
			auto langButton = createButton(i.first, Size(500, 60), [i, this](Ref* pSender) {
				auto button = static_cast<Button*> (pSender);
				highlightingButton->loadTextureNormal("UI/ButtonNormal.png");
				highlightingButton->setContentSize(Size(500, 60));
				highlightingButton = button;
				button->loadTextureNormal("UI/ButtonActive.png");
				button->setContentSize(Size(500, 60));
				Lang::setAutoLang(false);
				Lang::loadLang(i.second);
			});
			if (!Lang::isAutoLang() && i.second == Lang::getCurrentLang()) {
				langButton->loadTextureNormal("UI/ButtonActive.png");
				langButton->setContentSize(Size(500, 60));
				highlightingButton = langButton;
			}
			langList->addChild(langButton);
		}
		goInto(rootLayout, button, langLayout);
		backItem->setCallback([=](Ref* pSender) {
			goOut(rootLayout, button, langLayout);
			backItem->setCallback(exitScene);
		});

	});
	list->addChild(langButton);
	return true;
}