diff --git a/README.md b/README.md index f97c43300..a7e08cedf 100644 --- a/README.md +++ b/README.md @@ -116,4 +116,6 @@ Install all the APKs, then start the Kitkit Launcher to explorer. - Please make sure there is enough storage on the device. - Most of the APKs will not show up in the android (default) launcher. +# Questions? +Do you have questions about the code, content or data? Please reach out to the [Global Learning XPRIZE Community](http://community.xprize.org/learning). diff --git a/bookviewer/Classes/BookPage.cpp b/bookviewer/Classes/BookPage.cpp index d33d9a7bb..b1ce9be26 100644 --- a/bookviewer/Classes/BookPage.cpp +++ b/bookviewer/Classes/BookPage.cpp @@ -8,121 +8,121 @@ #include "BookPage.hpp" -#include "Managers/GameSoundManager.h" #include "Utils/TodoUtil.h" #include "Common/Controls/SignLanguageVideoPlayer.hpp" - +#include "Managers/VoiceMoldManager.h" using namespace ui; +namespace BookPageSpace +{ +const auto textColor = Color3B(79, 61, 24); +const Size defaultSize = Size(2560, 1800); +const Size halfSize = Size(1280, 1800); -namespace BookPageSpace { - const auto textColor = Color3B(79, 61, 24); - const Size defaultSize = Size(2560, 1800); - const Size halfSize = Size(1280, 1800); - - const Size bigSize = Size(2480, 1800); - const Size smallSize = Size(80, 1800); - - const Size squareSize = Size(1520, 1520); - const Size squareImageSize = Size(909, 909); - - - const float squareMiddle = defaultSize.width/2 - squareSize.width/2; - - const float skewY = 10; - const float turnDuration = 0.25; - const float turnEase = 1.4; - - const string titleFont = "fonts/Seshat.otf"; - const string bodyFont = "fonts/Andika-R.ttf"; - - const bool DebugLayout = false; - - -} +const Size bigSize = Size(2480, 1800); +const Size smallSize = Size(80, 1800); -using namespace BookPageSpace; +const Size squareSize = Size(1520, 1520); +const Size squareImageSize = Size(909, 909); + +const float squareMiddle = defaultSize.width / 2 - squareSize.width / 2; + +const float skewY = 10; +const float turnDuration = 0.25; +const float turnEase = 1.4; + +const string titleFont = "fonts/Seshat.otf"; +const string bodyFont = "fonts/Andika-R.ttf"; +const bool DebugLayout = false; -BookPage* BookPage::create() +} // namespace BookPageSpace + +using namespace BookPageSpace; + +BookPage *BookPage::create() { - BookPage *pRet = new(std::nothrow) BookPage(); - if (pRet && pRet->init()) { + BookPage *pRet = new (std::nothrow) BookPage(); + if (pRet && pRet->init()) + { pRet->autorelease(); return pRet; - } else { + } + else + { delete pRet; - pRet= nullptr; + pRet = nullptr; return nullptr; } } - bool BookPage::init() { - if (!Node::init()) return false; - + if (!Node::init()) + return false; + setColor(Color3B::WHITE); - + setContentSize(defaultSize); _contentsView = Node::create(); _contentsView->setContentSize(defaultSize); addChild(_contentsView); - + _isReading = false; - + return true; - } void BookPage::onExit() { Node::onExit(); - - } - - - +int buttonIndex = 0; +int tag = -1; void BookPage::update(float delta) { - if (_pauseReading) { - + if (_pauseReading) + { + _pauseLength -= delta; - if (_pauseLength<0) { + if (_pauseLength < 0) + { _pauseLength = 0; _pauseReading = false; - - //GameSoundManager::getInstance()->resumeEffect(_readingAudioID); - GameSoundManager::getInstance()->resumeBGM(); - - } else { + } + else + { return; } - } else { - _timePage+=delta; - _timeSentence+=delta; - + } + else + { + _timePage += delta; + _timeSentence += delta; + auto page = _page; - + int newReadingSentenceIndex = _readingSentenceIndex; TodoSentence newReadingSentence; - - int i=-1; - - for (auto p : page->paragraphs) { - for (auto s : p.sentences) { + + int i = -1; + + for (auto p : page->paragraphs) + { + for (auto s : p.sentences) + { i++; - if (s.startTimingInPage <= _timePage) { + if (s.startTimingInPage <= _timePage) + { newReadingSentenceIndex = i; newReadingSentence = s; } } } - + /* for (int i=_readingSentence+1; iparagraphs[0].sentences.size(); i++) { auto sentence= page->paragraphs[0].sentences[i]; @@ -132,40 +132,71 @@ void BookPage::update(float delta) } } */ - - - if (newReadingSentenceIndex!=_readingSentenceIndex) { - _readingSentenceIndex = newReadingSentenceIndex; - //auto sentence= page->paragraphs[0].sentences[_readingSentenceIndex]; - - GameSoundManager::getInstance()->stopAllEffects(); - - //auto audioPath = _book->filePrefix+_book->pagePrefix+sentence.sentenceAudioFilename; - auto audioPath = _book->filePrefix + "page/"+newReadingSentence.sentenceAudioFilename; - //_readingAudioID = GameSoundManager::getInstance()->playEffectSound(audioPath); - GameSoundManager::getInstance()->playBGM(audioPath); - - _timeSentence = 0.0; - + auto b1 = ui::Button::create(); + b1->setTag(-1); + if (newReadingSentenceIndex != _readingSentenceIndex) + { + if (buttonIndex == _words.size()) + { + _readingSentenceIndex = newReadingSentenceIndex; + buttonIndex = -1; + } + for (auto b : _wordButtons) + { + if (buttonIndex > b->getTag()) + { + continue; + } + if (buttonIndex >= 0) + { + b1 = b; + if (b->getTag() > 0) + { + VoiceMoldManager::shared()->speak(_words[b->getTag() - 1].word); + } + } + else + { + VoiceMoldManager::shared()->speak(_words[_words.size() - 1].word); + _timeSentence = 0.0; + } + buttonIndex++; + break; + } } - - } - - - for (auto b : _wordButtons) { - auto wordObj = _words[b->getTag()]; - bool highlight = wordObj.startTimingInPage<=_timePage && _timePage<=wordObj.endTimingInPage; - highlightWordButton(b, highlight); + + for (auto b : _wordButtons) + { + if (b->getTag() == b1->getTag()) + { + highlightWordButton(b, true); + } + else + { + if (tag >= 0) + { + if (tag == b->getTag()) + { + VoiceMoldManager::shared()->speak(_words[b->getTag()].word); + } + } + highlightWordButton(b, b->getTag() == tag); + } + } + tag = -1; } } void BookPage::highlightWordButton(ui::Button *btn, bool highlight) { - if (highlight) { + if (highlight) + { btn->resetNormalRender(); btn->loadTextureNormal("Common/lightblue.png"); btn->setTitleColor(Color3B::BLACK); - } else { + } + else + { btn->resetNormalRender(); btn->loadTextureNormal("Common/transparent.png"); btn->setTitleColor(textColor); @@ -177,690 +208,625 @@ void BookPage::startReading() _timePage = -0.5; _timeSentence = -0.5; _readingSentenceIndex = -1; - if (_withAudio ) { + if (_withAudio) + { _isReading = true; scheduleUpdate(); } - - + SHOW_SL_VIDEO_IF_ENABLED("common/temp_video_short.mp4"); } void BookPage::stopReading() { - if (_withAudio) { + if (_withAudio) + { _isReading = false; unscheduleUpdate(); } - - GameSoundManager::getInstance()->stopAllEffects(); - GameSoundManager::getInstance()->stopBGM(); - - for (auto b : _wordButtons) { + + for (auto b : _wordButtons) + { highlightWordButton(b, false); } - - } void BookPage::setTitle(string title, string titleImagePath, string audioPath, TDBookLayout layout, float delay) { Size size = getContentSize(); - + _isTitle = true; - + unscheduleUpdate(); - - - //_isPortrait = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; - _hasBackCover = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; - - if (layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional) { - - - + + // _isPortrait = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; + _hasBackCover = layout == TDBookLayout::Portrait || layout == TDBookLayout::Portrait_Traditional; + + if (layout == TDBookLayout::Portrait || layout == TDBookLayout::Portrait_Traditional) + { + _leftView = Node::create(); _leftView->setContentSize(halfSize); _contentsView->addChild(_leftView); - - - + _leftCover = Node::create(); _leftCover->setContentSize(halfSize); - + Sprite *sp; - if (layout==TDBookLayout::Portrait_Traditional) { + if (layout == TDBookLayout::Portrait_Traditional) + { sp = Sprite::create("Books/portrait_traditional/koreanbook_cover.jpg", Rect(0, 0, 20, 1800)); - } else { + } + else + { sp = Sprite::create("Books/portrait/xprize_vertical_layout_cover.jpg", Rect(0, 0, 20, 1800)); } sp->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sp->setPosition(Vec2(halfSize.width, 0)); _leftCover->addChild(sp); _leftView->addChild(_leftCover); - - + _rightView = Node::create(); _rightView->setContentSize(halfSize); _rightView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_rightView); - - if (layout==TDBookLayout::Portrait_Traditional) { + + if (layout == TDBookLayout::Portrait_Traditional) + { _rightCover = Sprite::create("Books/portrait_traditional/koreanbook_cover.jpg", Rect(20, 0, 1280, 1800)); - } else { + } + else + { _rightCover = Sprite::create("Books/portrait/xprize_vertical_layout_cover.jpg", Rect(20, 0, 1280, 1800)); } _rightCover->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->setPosition(Vec2(0, 0)); _rightView->addChild(_rightCover); - - - Vec2 imagePos = Vec2(halfSize.width-610, 720); - + + Vec2 imagePos = Vec2(halfSize.width - 610, 720); + Sprite *cover; - if (layout==TDBookLayout::Portrait_Traditional) { + if (layout == TDBookLayout::Portrait_Traditional) + { cover = Sprite::create("Books/portrait_traditional/koreanbook_cover_illustration_blank.png"); - } else { + } + else + { cover = Sprite::create("Books/portrait/book_vertical_cover_illustration.png"); } - + cover->setPosition(imagePos); _rightView->addChild(cover); - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(Size(1020, 1170)); _imageView->setPosition(imagePos); _rightView->addChild(_imageView); - - if (layout==TDBookLayout::Portrait) { + + if (layout == TDBookLayout::Portrait) + { auto texture = Sprite::create("Books/portrait/book_vertical_cover_illustration_texture.png"); texture->setScale(2.0); texture->setPosition(imagePos); _rightView->addChild(texture); } - + Sprite *frame; - if (layout==TDBookLayout::Portrait_Traditional) { + if (layout == TDBookLayout::Portrait_Traditional) + { frame = Sprite::create("Books/portrait_traditional/koreanbook_cover_illustration_frame.png"); - } else { + } + else + { frame = Sprite::create("Books/portrait/xprize_vertical_cover_illustration_frame.png"); } frame->setPosition(imagePos); _rightView->addChild(frame); - - + auto textViewSize = Size(1038, 360); - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(textViewSize); - _textView->setPosition(Vec2(halfSize.width-610, 1800-250)); + _textView->setPosition(Vec2(halfSize.width - 610, 1800 - 250)); _rightView->addChild(_textView); - + float fontSize = 150; - - auto labelFunc = [&](Color4B color, string fontName, Size offset){ - + + auto labelFunc = [&](Color4B color, string fontName, Size offset) { auto l = Label::createWithTTF(title, fontName, fontSize, Size(textViewSize.width, 0), TextHAlignment::CENTER); auto lSize = l->getContentSize(); - if (lSize.height > textViewSize.height) { + if (lSize.height > textViewSize.height) + { l->setScale(textViewSize.height / lSize.height); } - l->setPosition(textViewSize/2 + offset); + l->setPosition(textViewSize / 2 + offset); l->setTextColor(color); return l; }; - - - if (layout==TDBookLayout::Portrait_Traditional) { - _textView->addChild(labelFunc(Color4B(77, 35, 20, 255),bodyFont, Size(0, 0))); - } else { + + if (layout == TDBookLayout::Portrait_Traditional) + { + _textView->addChild(labelFunc(Color4B(77, 35, 20, 255), bodyFont, Size(0, 0))); + } + else + { _textView->addChild(labelFunc(Color4B(148, 94, 48, 255), titleFont, Size(5, -5))); _textView->addChild(labelFunc(Color4B(255, 250, 227, 255), titleFont, Size(0, 0))); } - - - } else if (layout==TDBookLayout::Landscape) { - + } + else if (layout == TDBookLayout::Landscape) + { + _leftView = Node::create(); _leftView->setContentSize(smallSize); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftCover->setContentSize(smallSize); _leftView->addChild(_leftCover); - - - auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(0, 0, 80/2, 1800/2)); + + auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(0, 0, 80 / 2, 1800 / 2)); sp->setScale(2.0); sp->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sp->setPosition(Vec2(smallSize.width, 0)); _leftCover->addChild(sp); - auto bindingLeft = Sprite::create("Books/book_horizontal_cover_binding.png", Rect(0, 0, 85, 1800)); bindingLeft->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); bindingLeft->setPosition(Vec2(smallSize.width, 0)); _leftCover->addChild(bindingLeft); - - - - + _rightView = Node::create(); _rightView->setContentSize(bigSize); _rightView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_rightView); - - _rightCover = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80/2, 0, (2560-80)/2, 1800/2)); + + _rightCover = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); _rightCover->setScale(2); _rightCover->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->setPosition(Vec2(0, 0)); _rightView->addChild(_rightCover); - - auto bindingRight = Sprite::create("Books/book_horizontal_cover_binding.png", Rect(85, 0, 150-85, 1800)); + + auto bindingRight = Sprite::create("Books/book_horizontal_cover_binding.png", Rect(85, 0, 150 - 85, 1800)); bindingRight->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); bindingRight->setPosition(Vec2(0, 0)); _rightCover->addChild(bindingRight); - - - Vec2 imagePos = Vec2(bigSize.width/2, 750); - + + Vec2 imagePos = Vec2(bigSize.width / 2, 750); + auto cover = Sprite::create("Books/xprize_horizontal_cover_illustration.png"); cover->setPosition(imagePos); _rightView->addChild(cover); - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(Size(1560, 1090)); _imageView->setPosition(imagePos); _rightView->addChild(_imageView); - - - + auto texture = Sprite::create("Books/xprize_horizontal_cover_illustration_texture.png"); texture->setScale(2.0); texture->setPosition(imagePos); _rightView->addChild(texture); - + auto frame = Sprite::create("Books/xprize_horizontal_cover_frame.png"); frame->setPosition(imagePos); _rightView->addChild(frame); - - + auto textViewSize = Size(1560, 360); - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); _textView->setContentSize(textViewSize); - _textView->setPosition(Vec2(bigSize.width/2, 1800-380-100)); + _textView->setPosition(Vec2(bigSize.width / 2, 1800 - 380 - 100)); _rightView->addChild(_textView); - + float fontSize = 150; - - - - auto labelFunc = [&](Color4B color, Size offset){ - + + auto labelFunc = [&](Color4B color, Size offset) { auto l = Label::createWithTTF(title, titleFont, fontSize, Size(textViewSize.width, 0), TextHAlignment::CENTER, TextVAlignment::CENTER); auto lSize = l->getContentSize(); - if (lSize.height > textViewSize.height) { + if (lSize.height > textViewSize.height) + { l->setScale(textViewSize.height / lSize.height); } - l->setPosition(Size(textViewSize.width/2, lSize.height/2) + offset); + l->setPosition(Size(textViewSize.width / 2, lSize.height / 2) + offset); l->setTextColor(color); return l; }; - - + _textView->addChild(labelFunc(Color4B(84, 37, 11, 255), Size(5, -5))); _textView->addChild(labelFunc(Color4B(255, 248, 227, 255), Size(0, 0))); - - - - - - - - } else if (layout==TDBookLayout::Square) { - - + } + else if (layout == TDBookLayout::Square) + { + _leftView = Node::create(); _leftView->setContentSize(squareSize); _contentsView->addChild(_leftView); - - - + _leftCover = Node::create(); _leftCover->setContentSize(squareSize); _leftView->addChild(_leftCover); - - + _rightView = Node::create(); _rightView->setContentSize(squareSize); - _rightView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _rightView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_rightView); - + _rightCover = Node::create(); _rightCover->setContentSize(squareSize); - + auto coverBG = Sprite::create("Books/square/_alphabet_book_border.jpg"); - coverBG->setPosition(squareSize/2); + coverBG->setPosition(squareSize / 2); _rightCover->addChild(coverBG); _rightCover->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->setPosition(Vec2(0, 0)); _rightView->addChild(_rightCover); - - - Vec2 imagePos = Vec2(squareSize.width/2, squareSize.height/2); - - + + Vec2 imagePos = Vec2(squareSize.width / 2, squareSize.height / 2); + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(squareImageSize); _imageView->setPosition(imagePos); _rightView->addChild(_imageView); - - - auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171/2, 0, 171/2, 1520)); + + auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171 / 2, 0, 171 / 2, 1520)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightView->addChild(rightBinding); - -// Sprite *frame; -// if (layout==TDBookLayout::Portrait_Traditional) { -// frame = Sprite::create("Books/portrait_traditional/koreanbook_cover_illustration_frame.png"); -// } else { -// frame = Sprite::create("Books/portrait/xprize_vertical_cover_illustration_frame.png"); -// } -// -// frame->setPosition(imagePos); -// _rightView->addChild(frame); - - - - + + // Sprite *frame; + // if (layout==TDBookLayout::Portrait_Traditional) { + // frame = Sprite::create("Books/portrait_traditional/koreanbook_cover_illustration_frame.png"); + // } else { + // frame = Sprite::create("Books/portrait/xprize_vertical_cover_illustration_frame.png"); + // } + + // frame->setPosition(imagePos); + // _rightView->addChild(frame); } - - - - - - - + auto image = Sprite::create(titleImagePath); - if (!image) image = Sprite::create(titleImagePath+".jpg"); - if (!image) image = Sprite::create(titleImagePath+".png"); - if (image) { + if (!image) + image = Sprite::create(titleImagePath + ".jpg"); + if (!image) + image = Sprite::create(titleImagePath + ".png"); + if (image) + { auto imageSize = image->getContentSize(); auto viewSize = _imageView->getContentSize(); - auto scale = MIN(viewSize.width/imageSize.width, viewSize.height/imageSize.height); + auto scale = MIN(viewSize.width / imageSize.width, viewSize.height / imageSize.height); image->setScale(scale); - image->setPosition(viewSize/2); + image->setPosition(viewSize / 2); _imageView->addChild(image); } - - - - - GameSoundManager::getInstance()->stopAllEffects(); - if (audioPath.length() > 0) { + + if (audioPath.length() > 0) + { auto titleAudioPath = audioPath; - scheduleOnce([titleAudioPath](float){ // Sound delay - GameSoundManager::getInstance()->playBGM(titleAudioPath); - }, delay, "titleAudio"); + scheduleOnce([title](float) { // Sound delay + VoiceMoldManager::shared()->speak(title); + }, + delay, "titleAudio"); SHOW_SL_VIDEO_IF_ENABLED("common/temp_video_short.mp4"); } } - -void BookPage::setPage(TodoBook *book, TodoPage *page, TDBookLayout layout, bool withAudio) +void BookPage::setPage(TodoBook *book, TodoPage *page, TDBookLayout layout, bool withAudio) { _isTitle = false; - + _page = page; _book = book; auto folder = _book->filePrefix; _bookLayout = layout; _withAudio = withAudio; - //_isPortrait = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; - _hasBackCover = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; + // _isPortrait = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; + _hasBackCover = layout == TDBookLayout::Portrait || layout == TDBookLayout::Portrait_Traditional; int pageNum = _page->pageNum; - if (page->creditPage) { + if (page->creditPage) + { setCreditPage(); return; - } Size size = getContentSize(); + if (layout == TDBookLayout::Portrait || layout == TDBookLayout::Portrait_Traditional) + { - - - if (layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional) { - - - _leftView = Node::create(); _leftView->setContentSize(halfSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_leftView); - - if (layout==TDBookLayout::Portrait_Traditional) { + + if (layout == TDBookLayout::Portrait_Traditional) + { _leftCover = Sprite::create("Books/portrait_traditional/koreanbook_coverplain.jpg", Rect(0, 0, 1280, 1800)); - } else { + } + else + { _leftCover = Sprite::create("Books/portrait/book_vertical_yellowcover_bg.jpg", Rect(0, 0, 1280, 1800)); } - _leftCover->setPosition(halfSize/2); + _leftCover->setPosition(halfSize / 2); _leftView->addChild(_leftCover); - - auto leftBinding = Sprite::create("Books/book_vertical_yellowcover_bg_binding.png", Rect(0, 0, 472/2, 1800)); + + auto leftBinding = Sprite::create("Books/book_vertical_yellowcover_bg_binding.png", Rect(0, 0, 472 / 2, 1800)); leftBinding->setPosition(Vec2(halfSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftCover->addChild(leftBinding); - - + auto wp1 = Scale9Sprite::create("Books/book_vertical_pagespread_1.png"); wp1->setPreferredSize(Size(1280, 1718)); wp1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); wp1->setPosition(Vec2(halfSize.width, 30)); _leftView->addChild(wp1); - + auto sd1 = Scale9Sprite::create("Books/book_vertical_middleshadow_left_1.png"); sd1->setPreferredSize(Size(85, 1698)); sd1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sd1->setPosition(Vec2(halfSize.width, 50)); _leftView->addChild(sd1); - - - + _rightView = Node::create(); _rightView->setContentSize(halfSize); _rightView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_rightView); - - - if (layout==TDBookLayout::Portrait_Traditional) { + + if (layout == TDBookLayout::Portrait_Traditional) + { _rightCover = Sprite::create("Books/portrait_traditional/koreanbook_coverplain.jpg", Rect(0, 0, 1280, 1800)); - } else { + } + else + { _rightCover = Sprite::create("Books/portrait/book_vertical_yellowcover_bg.jpg", Rect(1280, 0, 1280, 1800)); } - - _rightCover->setPosition(halfSize/2); + + _rightCover->setPosition(halfSize / 2); _rightView->addChild(_rightCover); - - auto rightBinding = Sprite::create("Books/book_vertical_yellowcover_bg_binding.png", Rect(472/2, 0, 472/2, 1800)); + + auto rightBinding = Sprite::create("Books/book_vertical_yellowcover_bg_binding.png", Rect(472 / 2, 0, 472 / 2, 1800)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->addChild(rightBinding); - - + auto wp2 = Scale9Sprite::create("Books/book_vertical_pagespread_1.png"); wp2->setPreferredSize(Size(1280, 1718)); wp2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); wp2->setPosition(Vec2(0, 30)); _rightView->addChild(wp2); - - - if (layout==TDBookLayout::Portrait) { + + if (layout == TDBookLayout::Portrait) + { auto wp3 = Sprite::create("Books/book_vertical_toppage.png"); wp3->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); wp3->setPosition(Vec2(0, 30)); _rightView->addChild(wp3); } - + auto sd2 = Scale9Sprite::create("Books/book_vertical_middleshadow_right_1.png"); sd2->setPreferredSize(Size(85, 1698)); sd2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); sd2->setPosition(Vec2(0, 50)); _rightView->addChild(sd2); - - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(Size(1110, 1500)); - _imageView->setPosition(halfSize/2); + _imageView->setPosition(halfSize / 2); _leftView->addChild(_imageView); - - auto leftTexture = Sprite::create("Books/book_vertical_pagespread_texture.png", Rect(0, 0, 1280/2, 1718/2)); + + auto leftTexture = Sprite::create("Books/book_vertical_pagespread_texture.png", Rect(0, 0, 1280 / 2, 1718 / 2)); leftTexture->setScale(2); leftTexture->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); leftTexture->setPosition(wp1->getPosition()); _leftView->addChild(leftTexture); - - setPageNum((pageNum * 2 - 1), _leftView, Vec2(_leftView->getContentSize().width/2, 100)); - + + setPageNum((pageNum * 2 - 1), _leftView, Vec2(_leftView->getContentSize().width / 2, 100)); + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(Size(1000, 1500)); - _textView->setPosition(halfSize/2); + _textView->setPosition(halfSize / 2); _rightView->addChild(_textView); - - auto rightTexture = Sprite::create("Books/book_vertical_pagespread_texture.png", Rect(1280/2, 0, 1280/2, 1718/2)); + + auto rightTexture = Sprite::create("Books/book_vertical_pagespread_texture.png", Rect(1280 / 2, 0, 1280 / 2, 1718 / 2)); rightTexture->setScale(2); rightTexture->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); rightTexture->setPosition(wp2->getPosition()); _rightView->addChild(rightTexture); - - setPageNum(( pageNum * 2), _rightView, Vec2(_rightView->getContentSize().width/2, 100)); - - } else if (layout==TDBookLayout::Landscape) { + + setPageNum((pageNum * 2), _rightView, Vec2(_rightView->getContentSize().width / 2, 100)); + } + else if (layout == TDBookLayout::Landscape) + { _leftView = Node::create(); _leftView->setContentSize(bigSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftCover->setContentSize(bigSize); _leftView->addChild(_leftCover); - + auto winsize = Director::getInstance()->getWinSize(); - - - auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80/2, 0, (2560-80)/2, 1800/2)); + + auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); sp->setScale(2); sp->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sp->setPosition(Vec2(bigSize.width, 0)); _leftCover->addChild(sp); - - - auto leftBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(0, 0, 476/2, 1800)); - + auto leftBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(0, 0, 476 / 2, 1800)); + leftBinding->setPosition(Vec2(bigSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftCover->addChild(leftBinding); - - + auto wp1 = Scale9Sprite::create("Books/book_horizontal_inside_pagespread_1.png"); wp1->setPreferredSize(Size(bigSize.width, 1712)); wp1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); wp1->setPosition(Vec2(bigSize.width, 30)); _leftView->addChild(wp1); - + auto sd1 = Scale9Sprite::create("Books/book_vertical_middleshadow_left_1.png"); sd1->setPreferredSize(Size(85, 1692)); sd1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sd1->setPosition(Vec2(bigSize.width, 50)); _leftView->addChild(sd1); - - - - + _rightView = Node::create(); _rightView->setContentSize(bigSize); _rightView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_rightView); - - + _rightCover = Node::create(); _rightCover->setContentSize(bigSize); _rightView->addChild(_rightCover); - - - auto rsp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80/2, 0, (2560-80)/2, 1800/2)); + + auto rsp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); rsp->setScale(2); - rsp->setPosition(bigSize/2); + rsp->setPosition(bigSize / 2); _rightCover->addChild(rsp); - - auto rightBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(476/2, 0, 476/2, 1800)); + auto rightBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(476 / 2, 0, 476 / 2, 1800)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->addChild(rightBinding); - - auto wp2 = Scale9Sprite::create("Books/book_horizontal_inside_pagespread_1.png"); wp2->setPreferredSize(Size(bigSize.width, 1712)); wp2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); wp2->setPosition(Vec2(0, 30)); _rightView->addChild(wp2); - - + auto sd2 = Scale9Sprite::create("Books/book_vertical_middleshadow_right_1.png"); sd2->setPreferredSize(Size(85, 1692)); sd2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); sd2->setPosition(Vec2(0, 50)); _rightView->addChild(sd2); - - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); _imageView->setContentSize(Size(1820, 1274)); - _imageView->setPosition(Vec2(bigSize.width/2, 390)); + _imageView->setPosition(Vec2(bigSize.width / 2, 390)); _rightView->addChild(_imageView); - - + auto leftTexture = Sprite::create("Books/book_horizontal_inside_pagespread_texture.png"); leftTexture->setScale(2); leftTexture->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); leftTexture->setPosition(wp1->getPosition()); _leftView->addChild(leftTexture); - - - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(Size(2000, 300)); - + // what is the rationale behind doing this? this does not fix the issue... - _textView->setPosition(Vec2(_rightView->getContentSize().width/2, 280)); + _textView->setPosition(Vec2(_rightView->getContentSize().width / 2, 280)); _rightView->addChild(_textView); - + // adding pagespread texture after the textview is intentional - to give a feeling of embossing ; hard to notice though auto rightTexture = Sprite::create("Books/book_horizontal_inside_pagespread_texture.png"); rightTexture->setScale(2); rightTexture->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); rightTexture->setPosition(wp2->getPosition()); _rightView->addChild(rightTexture); - - - setPageNum(pageNum, _rightView, Vec2(_rightView->getContentSize().width/2,100)); - - - } else if (layout==TDBookLayout::Square) { - - - + + setPageNum(pageNum, _rightView, Vec2(_rightView->getContentSize().width / 2, 100)); + } + else if (layout == TDBookLayout::Square) + { + _leftView = Node::create(); _leftView->setContentSize(squareSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); - _leftView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _leftView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftView->addChild(_leftCover); - + auto cl = LayerColor::create(Color4B::WHITE, squareSize.width, squareSize.height); _leftView->addChild(cl); - - auto leftBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(0, 0, 171/2, 1520)); + + auto leftBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(0, 0, 171 / 2, 1520)); leftBinding->setPosition(Vec2(squareSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->addChild(leftBinding); - - - - + _rightView = Node::create(); _rightView->setContentSize(squareSize); - _rightView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _rightView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_rightView); - + _rightCover = Node::create(); _rightView->addChild(_rightCover); - - auto cr = LayerColor::create(Color4B::WHITE, squareSize.width, squareSize.height); _rightView->addChild(cr); - - auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171/2, 0, 171/2, 1520)); + + auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171 / 2, 0, 171 / 2, 1520)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightView->addChild(rightBinding); - - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(Size(1200, 1000)); - _imageView->setPosition(Vec2(squareSize.width/2, squareSize.height/2 + 120)); + _imageView->setPosition(Vec2(squareSize.width / 2, squareSize.height / 2 + 120)); _rightView->addChild(_imageView); - - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(Size(1200, 300)); - _textView->setPosition(Vec2(squareSize.width/2, 240)); + _textView->setPosition(Vec2(squareSize.width / 2, 240)); _rightView->addChild(_textView); - - setPageNum(pageNum, _rightView, Vec2(_contentsView->getContentSize().width/2, 100)); - - + setPageNum(pageNum, _rightView, Vec2(_contentsView->getContentSize().width / 2, 100)); } - - - - - //auto image = Sprite::create(_book->imagePrefix+pageObj.pageImageFilename); - auto image = Sprite::create(folder+"page/"+page->pageImageFilename); - if (!image) image = Sprite::create(folder+"page/"+page->pageImageFilename+".jpg"); - if (!image) image = Sprite::create(folder+"page/"+page->pageImageFilename+".png"); - if (image) { + // auto image = Sprite::create(_book->imagePrefix+pageObj.pageImageFilename); + auto image = Sprite::create(folder + "page/" + page->pageImageFilename); + if (!image) + image = Sprite::create(folder + "page/" + page->pageImageFilename + ".jpg"); + if (!image) + image = Sprite::create(folder + "page/" + page->pageImageFilename + ".png"); + if (image) + { auto imageSize = image->getContentSize(); auto viewSize = _imageView->getContentSize(); - auto scale = MIN(viewSize.width/imageSize.width, viewSize.height/imageSize.height); + auto scale = MIN(viewSize.width / imageSize.width, viewSize.height / imageSize.height); image->setScale(scale); - image->setPosition(viewSize/2); + image->setPosition(viewSize / 2); _imageView->addChild(image); } - - GameSoundManager::getInstance()->stopAllEffects(); - - - + _wordButtons.clear(); - + auto textViewSize = _textView->getContentSize(); - - + _words.clear(); - for (auto p : page->paragraphs) { - for (auto s : p.sentences) { - for (auto w : s.words) { + for (auto p : page->paragraphs) + { + for (auto s : p.sentences) + { + for (auto w : s.words) + { _words.push_back(w); } } } - + /* for (int i=0; iparagraphs[0].sentences.size(); i++) { TodoSentence s = page->paragraphs[0].sentences[i]; @@ -872,565 +838,517 @@ void BookPage::setPage(TodoBook *book, TodoPage *page, TDBookLayout layout, boo } } */ - - if (true) { + + if (true) + { auto text = createTextViewMultiLine(textViewSize, page->fontSize); _textView->addChild(text); - } else { + } + else + { auto text = createTextViewOneLine(textViewSize, page->fontSize); _textView->addChild(text); } - - - - - - - } void BookPage::setCreditPage() { - - auto getSentence = [this](int index){ + + auto getSentence = [this](int index) { string str; - - if (_page->paragraphs.size()>index) { + + if (_page->paragraphs.size() > index) + { auto p = _page->paragraphs.at(index); - - for (auto s : p.sentences) { - if (s.words.size()==0) continue; + + for (auto s : p.sentences) + { + if (s.words.size() == 0) + continue; auto w = s.words[0]; str += w.word + "\n"; } } return str; }; - - if (_bookLayout==TDBookLayout::Portrait || _bookLayout==TDBookLayout::Portrait_Traditional) { + if (_bookLayout == TDBookLayout::Portrait || _bookLayout == TDBookLayout::Portrait_Traditional) + { _leftView = Node::create(); _leftView->setContentSize(halfSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_leftView); - - if (_bookLayout==TDBookLayout::Portrait_Traditional) { + + if (_bookLayout == TDBookLayout::Portrait_Traditional) + { _leftCover = Node::create(); _leftCover->setContentSize(halfSize); _leftCover->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - + auto cv = Sprite::create("Books/portrait_traditional/koreanbook_cover.jpg", Rect(20, 00, 1280, 1800)); cv->setScale(-1, 1); - cv->setPosition(halfSize/2); + cv->setPosition(halfSize / 2); _leftCover->addChild(cv); - - } else { + } + else + { _leftCover = Sprite::create("Books/portrait/xprize_vertical_layout_cover_back.jpg", Rect(0, 0, 1280, 1800)); } - _leftCover->setPosition(halfSize/2); + _leftCover->setPosition(halfSize / 2); _leftView->addChild(_leftCover); - - - + _rightView = Node::create(); _rightView->setContentSize(halfSize); _rightView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_rightView); - - if (_bookLayout==TDBookLayout::Portrait_Traditional) { + + if (_bookLayout == TDBookLayout::Portrait_Traditional) + { _rightCover = Node::create(); _rightCover->setContentSize(Size(20, 1800)); _rightCover->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - + auto cv = Sprite::create("Books/portrait_traditional/koreanbook_cover.jpg", Rect(0, 0, 20, 1800)); cv->setScale(-1, 1); - cv->setPosition(_rightCover->getContentSize()/2); + cv->setPosition(_rightCover->getContentSize() / 2); _rightCover->addChild(cv); - - } else { + } + else + { _rightCover = Sprite::create("Books/portrait/xprize_vertical_layout_cover_back.jpg", Rect(1280, 0, 20, 1800)); } - + _rightCover->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightView->addChild(_rightCover); - - - - - _imageView = Node::create(); _leftView->addChild(_imageView); - - + auto centerOffset = -30; - + auto textViewSize = Size(1110, 1500); _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(textViewSize); - _textView->setPosition(halfSize/2 + Size(centerOffset, 100)); - _leftView->addChild(_textView); - - - - + _textView->setPosition(halfSize / 2 + Size(centerOffset, 100)); + _leftView->addChild(_textView); + { string titleTxt = getSentence(0); - Label* label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); - if (_bookLayout==TDBookLayout::Portrait_Traditional) { + Label *label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); + if (_bookLayout == TDBookLayout::Portrait_Traditional) + { label->setTextColor(Color4B(77, 35, 20, 255)); - } else { + } + else + { label->setTextColor(Color4B(255, 249, 225, 255)); } label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - label->setPosition(textViewSize/2 + Size(0, 50)); + label->setPosition(textViewSize / 2 + Size(0, 50)); _textView->addChild(label); } - - + { string creditTxt = getSentence(1); - - Label* label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); + + Label *label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); label->setTextColor(Color4B(98, 61, 29, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(textViewSize/2); + label->setPosition(textViewSize / 2); _textView->addChild(label); } - + { string licenseTxt = getSentence(2); - + auto bottom = Label::createWithTTF(licenseTxt, titleFont, 25, Size(0, 0), TextHAlignment::CENTER, TextVAlignment::CENTER); bottom->setTextColor(Color4B(98, 61, 29, 255)); bottom->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - bottom->setPosition(Size(halfSize.width/2+centerOffset, 50)); + bottom->setPosition(Size(halfSize.width / 2 + centerOffset, 50)); _leftView->addChild(bottom); - + auto cc = Sprite::create("Books/cc_logo.png"); - cc->setPosition(Vec2(halfSize.width/2+centerOffset, bottom->getContentSize().height + 120)); + cc->setPosition(Vec2(halfSize.width / 2 + centerOffset, bottom->getContentSize().height + 120)); _leftView->addChild(cc); - + auto enuma = Label::createWithTTF("(c) 2015 Enuma, Inc.", titleFont, 30); enuma->setTextColor(Color4B(98, 61, 29, 255)); - enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height/2 + 40)); + enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height / 2 + 40)); _leftView->addChild(enuma); - } + } + else if (_bookLayout == TDBookLayout::Landscape) + { - - } else if (_bookLayout==TDBookLayout::Landscape) { - - _leftView = Node::create(); _leftView->setContentSize(bigSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftCover->setContentSize(bigSize); _leftView->addChild(_leftCover); - - - auto sp = Sprite::create("Books/book_horizontal_bg.jpg" , Rect(80/2, 0, (2560-80)/2, 1800/2)); + + auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); sp->setScale(2); sp->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sp->setPosition(Vec2(bigSize.width, 0)); _leftCover->addChild(sp); - - - - auto leftBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(0, 0, 476/2, 1800)); + + auto leftBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(0, 0, 476 / 2, 1800)); leftBinding->setPosition(Vec2(bigSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftCover->addChild(leftBinding); - - + auto wp1 = Scale9Sprite::create("Books/book_horizontal_inside_pagespread_1.png"); wp1->setPreferredSize(Size(bigSize.width, 1712)); wp1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); wp1->setPosition(Vec2(bigSize.width, 30)); _leftView->addChild(wp1); - + auto sd1 = Scale9Sprite::create("Books/book_vertical_middleshadow_left_1.png"); sd1->setPreferredSize(Size(85, 1692)); sd1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sd1->setPosition(Vec2(bigSize.width, 50)); _leftView->addChild(sd1); - - - + _rightView = Node::create(); _rightView->setContentSize(bigSize); _rightView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_rightView); - + _rightCover = Node::create(); _rightView->addChild(_rightCover); - - auto rsp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80/2, 0, (2560-80)/2, 1800/2)); + + auto rsp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); rsp->setScale(2); - rsp->setPosition(bigSize/2); + rsp->setPosition(bigSize / 2); _rightCover->addChild(rsp); - - - auto rightBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(476/2, 0, 476/2, 1800)); + + auto rightBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(476 / 2, 0, 476 / 2, 1800)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->addChild(rightBinding); - + auto textViewSize = Size(2000, 1200); - - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(textViewSize); - _textView->setPosition(defaultSize/2 + Size(0, 400)); + _textView->setPosition(defaultSize / 2 + Size(0, 400)); _rightView->addChild(_textView); - - - - { string titleTxt = getSentence(0); - Label* label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); + Label *label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); label->setTextColor(Color4B(255, 249, 225, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(Vec2(textViewSize.width/2, textViewSize.height - 450)); + label->setPosition(Vec2(textViewSize.width / 2, textViewSize.height - 450)); _textView->addChild(label); } - - + { string creditTxt = getSentence(1); - - Label* label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); + + Label *label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); label->setTextColor(Color4B(54, 28, 14, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(Vec2(textViewSize.width/2, textViewSize.height - 600)); + label->setPosition(Vec2(textViewSize.width / 2, textViewSize.height - 600)); _textView->addChild(label); } - + { string licenseTxt = getSentence(2); - + auto bottom = Label::createWithTTF(licenseTxt, titleFont, 25, Size(0, 0), TextHAlignment::CENTER, TextVAlignment::CENTER); bottom->setTextColor(Color4B(255, 249, 225, 255)); bottom->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - bottom->setPosition(Size(defaultSize.width/2, 50)); + bottom->setPosition(Size(defaultSize.width / 2, 50)); _rightView->addChild(bottom); - + auto cc = Sprite::create("Books/cc_logo.png"); - cc->setPosition(Vec2(defaultSize.width/2, bottom->getContentSize().height + 120)); + cc->setPosition(Vec2(defaultSize.width / 2, bottom->getContentSize().height + 120)); _rightView->addChild(cc); - + auto enuma = Label::createWithTTF("(c) 2015 Enuma, Inc.", titleFont, 30); enuma->setTextColor(Color4B(255, 249, 225, 255)); - enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height/2 + 40)); + enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height / 2 + 40)); _rightView->addChild(enuma); - } - - + } + else if (_bookLayout == TDBookLayout::Square) + { - } else if (_bookLayout==TDBookLayout::Square) { - - _leftView = Node::create(); _leftView->setContentSize(squareSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); - _leftView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _leftView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftView->addChild(_leftCover); - + auto cl = LayerColor::create(Color4B::WHITE, squareSize.width, squareSize.height); _leftView->addChild(cl); - - auto leftBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(0, 0, 171/2, 1520)); + + auto leftBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(0, 0, 171 / 2, 1520)); leftBinding->setPosition(Vec2(squareSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->addChild(leftBinding); - - - _rightView = Node::create(); _rightView->setContentSize(squareSize); - _rightView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _rightView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_rightView); - + _rightCover = Node::create(); _rightView->addChild(_rightCover); - - - + auto cr = LayerColor::create(Color4B::WHITE, squareSize.width, squareSize.height); _rightView->addChild(cr); - - auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171/2, 0, 171/2, 1520)); + + auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171 / 2, 0, 171 / 2, 1520)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightView->addChild(rightBinding); - - auto textViewSize = Size(1200, 1200); - - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(textViewSize); - _textView->setPosition(squareSize/2); + _textView->setPosition(squareSize / 2); _rightView->addChild(_textView); - - - - - + { string titleTxt = getSentence(0); - Label* label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); + Label *label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); label->setTextColor(Color4B(255, 249, 225, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(Vec2(textViewSize.width/2, textViewSize.height - 450)); + label->setPosition(Vec2(textViewSize.width / 2, textViewSize.height - 450)); _textView->addChild(label); } - - + { string creditTxt = getSentence(1); - - Label* label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); + + Label *label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); label->setTextColor(Color4B(54, 28, 14, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(Vec2(textViewSize.width/2, textViewSize.height - 600)); + label->setPosition(Vec2(textViewSize.width / 2, textViewSize.height - 600)); _textView->addChild(label); } - + { string licenseTxt = getSentence(2); - + auto bottom = Label::createWithTTF(licenseTxt, titleFont, 25, Size(0, 0), TextHAlignment::CENTER, TextVAlignment::CENTER); bottom->setTextColor(Color4B(54, 28, 14, 255)); bottom->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - bottom->setPosition(Size(squareSize.width/2, 50)); + bottom->setPosition(Size(squareSize.width / 2, 50)); _rightView->addChild(bottom); - + auto cc = Sprite::create("Books/cc_logo.png"); - cc->setPosition(Vec2(squareSize.width/2, bottom->getContentSize().height + 120)); + cc->setPosition(Vec2(squareSize.width / 2, bottom->getContentSize().height + 120)); _rightView->addChild(cc); - + auto enuma = Label::createWithTTF("(c) 2015 Enuma, Inc.", titleFont, 30); enuma->setTextColor(Color4B(54, 28, 14, 255)); - enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height/2 + 40)); + enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height / 2 + 40)); _rightView->addChild(enuma); - } - - - } - - - - - } void BookPage::showRightHalf(bool animate) { - if (!animate) { + if (!animate) + { _rightView->setVisible(true); _rightCover->setVisible(true); - } else { + } + else + { _rightView->setVisible(true); _rightView->setScale(0, 1); _rightView->setSkewY(skewY); - if (!isTitlePage() && !isLastPage()) _rightCover->setVisible(false); - - - if (!isTitlePage() && !_hasBackCover && isLastPage()) _rightCover->setVisible(false); + if (!isTitlePage() && !isLastPage()) + _rightCover->setVisible(false); + + if (!isTitlePage() && !_hasBackCover && isLastPage()) + _rightCover->setVisible(false); auto ani = Spawn::create(EaseIn::create(ScaleTo::create(turnDuration, 1, 1), turnEase), EaseIn::create(SkewTo::create(turnDuration, 0, 0), turnEase), nullptr); _rightView->runAction(Sequence::create(ani, - CallFunc::create([this](){ _rightCover->setVisible(true); }), nullptr)); + CallFunc::create([this]() { _rightCover->setVisible(true); }), nullptr)); } } void BookPage::showLeftHalf(bool animate) { - if (!animate) { + if (!animate) + { _leftView->setVisible(true); _leftCover->setVisible(true); - } else { + } + else + { _leftView->setVisible(true); _leftView->setScale(0, 1); _leftView->setSkewY(-skewY); - - if (!isFirstPage() && !isCreditPage()) _leftCover->setVisible(false); - if (!_hasBackCover && isCreditPage()) _leftCover->setVisible(false); + + if (!isFirstPage() && !isCreditPage()) + _leftCover->setVisible(false); + if (!_hasBackCover && isCreditPage()) + _leftCover->setVisible(false); auto ani = Spawn::create(EaseIn::create(ScaleTo::create(turnDuration, 1, 1), turnEase), EaseIn::create(SkewTo::create(turnDuration, 0, 0), turnEase), nullptr); _leftView->runAction(Sequence::create(ani, - CallFunc::create([this](){ _leftCover->setVisible(true); }), nullptr)); - + CallFunc::create([this]() { _leftCover->setVisible(true); }), nullptr)); } - } void BookPage::hideRightHalf(bool animate) { - if (!animate) { + if (!animate) + { _rightView->setVisible(false); - } else { + } + else + { _rightView->setScale(1, 1); - if (!isTitlePage() && !isLastPage()) _rightCover->setVisible(false); - if (!isTitlePage() && !_hasBackCover && isLastPage()) _rightCover->setVisible(false); + if (!isTitlePage() && !isLastPage()) + _rightCover->setVisible(false); + if (!isTitlePage() && !_hasBackCover && isLastPage()) + _rightCover->setVisible(false); auto ani = Spawn::create(EaseOut::create(ScaleTo::create(turnDuration, 0, 1), turnEase), EaseOut::create(SkewTo::create(turnDuration, 0, skewY), turnEase), nullptr); _rightView->runAction(Sequence::create(ani, - CallFunc::create([this](){_rightView->setVisible(false);}), - nullptr)); + CallFunc::create([this]() { _rightView->setVisible(false); }), + nullptr)); } } void BookPage::hideLeftHalf(bool animate) { - if (!animate) { + if (!animate) + { _leftView->setVisible(false); - } else { + } + else + { _leftView->setScale(1, 1); - if (!isFirstPage() && !isCreditPage()) _leftCover->setVisible(false); - if (!_hasBackCover && isCreditPage()) _leftCover->setVisible(false); + if (!isFirstPage() && !isCreditPage()) + _leftCover->setVisible(false); + if (!_hasBackCover && isCreditPage()) + _leftCover->setVisible(false); auto ani = Spawn::create(EaseOut::create(ScaleTo::create(turnDuration, 0, 1), turnEase), EaseOut::create(SkewTo::create(turnDuration, 0, -skewY), turnEase), nullptr); _leftView->runAction(Sequence::create(ani, - CallFunc::create([this](){_leftView->setVisible(false);}), + CallFunc::create([this]() { _leftView->setVisible(false); }), nullptr)); } } -void BookPage::playWordSound(ui::Button *button, string path, float length) +void BookPage::playWordSound(ui::Button *button) { - //GameSoundManager::getInstance()->pauseEffect(_readingAudioID); - GameSoundManager::getInstance()->pauseBGM(); - - - GameSoundManager::getInstance()->playEffectSound(path); - - if (_isReading) { - + tag = button->getTag(); + if (_isReading) + { button->resetNormalRender(); button->loadTextureNormal("Common/lightblue.png"); SHOW_SL_VIDEO_IF_ENABLED("common/temp_video_short.mp4"); - _pauseReading = true; - _pauseLength = length; } - } - -Node* BookPage::createTextViewOneLine(Size size, float fontSize) +Node *BookPage::createTextViewOneLine(Size size, float fontSize) { - + auto tempTextView = Node::create(); tempTextView->setContentSize(size); - - float pageFontSize = (fontSize>0) ? fontSize : size.height-5; + + float pageFontSize = (fontSize > 0) ? fontSize : size.height - 5; float currentX = 0.0; - - for (int i=0; i<_words.size(); i++) { + + for (int i = 0; i < _words.size(); i++) + { auto word = _words[i]; auto wordButton = Button::create(); - wordButton->setAnchorPoint(Vec2::ANCHOR_MIDDLE); wordButton->setTag(i); wordButton->setTitleFontSize(pageFontSize); wordButton->setTitleFontName(bodyFont); wordButton->setTitleText(word.word); wordButton->setTitleColor(textColor); - - + auto buttonSize = wordButton->getContentSize(); - - wordButton->setPosition(Vec2(currentX+buttonSize.width/2, size.height/2)); - currentX += buttonSize.width + pageFontSize/2; - - if (_withAudio) { + + wordButton->setPosition(Vec2(currentX + buttonSize.width / 2, size.height / 2)); + currentX += buttonSize.width + pageFontSize / 2; + + if (_withAudio) + { auto wordAudioPath = _book->getWordAudioPath(word.wordAudioFilename); - GameSoundManager::getInstance()->preloadEffect(wordAudioPath); - wordButton->addClickEventListener([this, word, wordAudioPath, wordButton](Ref*){ - this->playWordSound(wordButton, wordAudioPath, word.wordAudioLength); + VoiceMoldManager::shared()->speak(word.word); + wordButton->addClickEventListener([this, word, wordAudioPath, wordButton](Ref *) { + this->playWordSound(wordButton); }); } - - + tempTextView->addChild(wordButton); _wordButtons.push_back(wordButton); } - - - Size tempTextViewSize = Size(currentX-pageFontSize, size.height); + + Size tempTextViewSize = Size(currentX - pageFontSize, size.height); tempTextView->setContentSize(tempTextViewSize); tempTextView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - tempTextView->setPosition(size/2); - - float textScale = MIN(1.0, size.width/tempTextViewSize.width); + tempTextView->setPosition(size / 2); + + float textScale = MIN(1.0, size.width / tempTextViewSize.width); tempTextView->setScale(textScale); - + return tempTextView; } - -Node* BookPage::createTextViewMultiLine(Size size, float fontSize) +Node *BookPage::createTextViewMultiLine(Size size, float fontSize) { - auto innerTextView = Node::create(); - - auto pageFontSize = (fontSize>0) ? fontSize : 80; - + + auto pageFontSize = (fontSize > 0) ? fontSize : 80; + // (s) one-pass Size viewSize = size; - + float maxWidth = 0.f; float minBottom = 0.f; - + float currentLeft = 0.f; float currentTop = 0.f; - + int wordIndex = 0; - + float paragraphSpace = pageFontSize; - float lineSpace = pageFontSize*1.5; - float indentSpace = pageFontSize*0.5; - float wordSpace = pageFontSize*0.5; - - + float lineSpace = pageFontSize * 1.5; + float indentSpace = pageFontSize * 0.5; + float wordSpace = pageFontSize * 0.5; + bool wordWrap = _page->wordwrap; - - - - bool indentation = wordWrap || (_page->paragraphs.size()>1); + + bool indentation = wordWrap || (_page->paragraphs.size() > 1); bool finalPass = !wordWrap; - + bool firstInLine; - - - + auto createWordButton = [&](string word) { - auto wordButton = Button::create(); wordButton->setTag(wordIndex++); wordButton->setTouchEnabled(_withAudio); @@ -1440,235 +1358,226 @@ Node* BookPage::createTextViewMultiLine(Size size, float fontSize) wordButton->setTitleText(word); wordButton->setTitleColor(textColor); return wordButton; - }; - - auto addAudioHandler = [&](Button* button, string path, float length) { - GameSoundManager::getInstance()->preloadEffect(path); - button->addClickEventListener([this, path, button, length](Ref*){ - - playWordSound(button, path, length); - + + auto addAudioHandler = [&](Button *button) { + button->addClickEventListener([this, button](Ref *) { + playWordSound(button); }); }; - + bool singleLine = true; - - + for (int i = 0; i < _page->paragraphs.size(); i++) { auto paragraph = _page->paragraphs[i]; - + // it appears that the auto identation causes the skewing problem when the sentence is short, but we can't just disable it currentLeft = indentation ? indentSpace : 0; // auto indentation - if (i > 0) currentTop -= paragraphSpace; // paragraph spacing - + if (i > 0) + currentTop -= paragraphSpace; // paragraph spacing + firstInLine = true; - for (int j = 0; j < paragraph.sentences.size(); j++) { auto sentence = paragraph.sentences[j]; - + for (int k = 0; k < sentence.words.size(); k++) { auto word = sentence.words[k]; auto wordButton = createWordButton(word.word); auto buttonSize = wordButton->getContentSize(); - if (wordWrap && (currentLeft + wordSpace + buttonSize.width > viewSize.width)) { // do wordwrapping + if (wordWrap && (currentLeft + wordSpace + buttonSize.width > viewSize.width)) + { // do wordwrapping currentLeft = 0; currentTop -= lineSpace; firstInLine = true; singleLine = false; - } else { + } + else + { currentLeft += firstInLine ? 0 : wordSpace; } - - if (finalPass) { + + if (finalPass) + { wordButton->setPosition(Vec2(currentLeft, currentTop)); innerTextView->addChild(wordButton); - - if (_withAudio) { + + if (_withAudio) + { auto wordAudioPath = _book->getWordAudioPath(word.wordAudioFilename); - addAudioHandler(wordButton, wordAudioPath, word.wordAudioLength); + addAudioHandler(wordButton); _wordButtons.push_back(wordButton); } } - + firstInLine = false; currentLeft += buttonSize.width; - minBottom = MIN(minBottom, (currentTop-buttonSize.height)); + minBottom = MIN(minBottom, (currentTop - buttonSize.height)); maxWidth = MAX(maxWidth, currentLeft); - } - - if (!wordWrap) { // force next line if no wordwrap + + if (!wordWrap) + { // force next line if no wordwrap currentLeft = 0; currentTop -= lineSpace; firstInLine = true; } } - - if (wordWrap) { + + if (wordWrap) + { currentLeft = 0; currentTop -= lineSpace; firstInLine = true; } } // (e) one-pass - - - if (finalPass) { + + if (finalPass) + { auto textView = Node::create(); textView->setContentSize(Size(maxWidth, -minBottom)); innerTextView->setPosition(Vec2(0, -minBottom)); textView->addChild(innerTextView); textView->setScale(MIN(1.f, size.width / maxWidth)); textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - textView->setPosition(size/2); + textView->setPosition(size / 2); return textView; } - - - + // (s) two-pass - + auto sampleHeight = -minBottom; - - auto pageScale = MAX(1.f, sqrt(sampleHeight/size.height)); - viewSize = Size(size.width*pageScale, sampleHeight); + auto pageScale = MAX(1.f, sqrt(sampleHeight / size.height)); + + viewSize = Size(size.width * pageScale, sampleHeight); finalPass = true; - + currentLeft = 0.f; currentTop = viewSize.height; - + maxWidth = 0.f; minBottom = currentTop; - - wordIndex = 0; - - for (int i = 0; i < _page->paragraphs.size(); i++) { auto paragraph = _page->paragraphs[i]; - + currentLeft = indentation ? indentSpace : 0; // auto indentation - if (singleLine) currentLeft = 0; - if (i > 0) currentTop -= paragraphSpace; // paragraph spacing - + if (singleLine) + currentLeft = 0; + if (i > 0) + currentTop -= paragraphSpace; // paragraph spacing + firstInLine = true; - - + for (int j = 0; j < paragraph.sentences.size(); j++) { auto sentence = paragraph.sentences[j]; - + for (int k = 0; k < sentence.words.size(); k++) { - + auto word = sentence.words[k]; - + auto wordButton = createWordButton(word.word); - - + auto buttonSize = wordButton->getContentSize(); - if (wordWrap && (currentLeft + wordSpace + buttonSize.width > viewSize.width)) { // do wordwrapping - + if (wordWrap && (currentLeft + wordSpace + buttonSize.width > viewSize.width)) + { // do wordwrapping + currentLeft = 0; currentTop -= lineSpace; firstInLine = true; - - - } else { + } + else + { currentLeft += firstInLine ? 0 : wordSpace; } - - if (finalPass) { + + if (finalPass) + { wordButton->setPosition(Vec2(currentLeft, currentTop)); innerTextView->addChild(wordButton); - - if (_withAudio) { + + if (_withAudio) + { auto wordAudioPath = _book->getWordAudioPath(word.wordAudioFilename); - GameSoundManager::getInstance()->preloadEffect(wordAudioPath); - addAudioHandler(wordButton, wordAudioPath, word.wordAudioLength); - - _wordButtons.push_back(wordButton); + addAudioHandler(wordButton); - + _wordButtons.push_back(wordButton); } - } - + firstInLine = false; currentLeft += buttonSize.width; - minBottom = MIN(minBottom, (currentTop-buttonSize.height)); + minBottom = MIN(minBottom, (currentTop - buttonSize.height)); maxWidth = MAX(maxWidth, currentLeft); - } - - if (!wordWrap) { // force next line if no wordwrap + + if (!wordWrap) + { // force next line if no wordwrap currentLeft = 0; currentTop -= lineSpace; firstInLine = true; } } - - if (wordWrap) { + + if (wordWrap) + { currentLeft = 0; currentTop -= lineSpace; firstInLine = true; } } - + { auto textView = Node::create(); - viewSize = Size(maxWidth, viewSize.height-minBottom); + viewSize = Size(maxWidth, viewSize.height - minBottom); textView->setContentSize(viewSize); - + // to check textview size - if (DebugLayout) { + if (DebugLayout) + { auto lc = LayerColor::create(Color4B::YELLOW, viewSize.width, viewSize.height); textView->addChild(lc); } - + innerTextView->setPosition(Vec2(0, -minBottom)); textView->addChild(innerTextView); textView->setScale(MIN(1.f, MIN(size.width / viewSize.width, size.height / viewSize.height))); textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - textView->setPosition(size/2); + textView->setPosition(size / 2); return textView; } - } void BookPage::setPageNum(int page, Node *_pageView, Vec2 pos) { - Label* pagelabel = Label::create(); + Label *pagelabel = Label::create(); pagelabel->setSystemFontSize(40); pagelabel->setTextColor(Color4B::BLACK); pagelabel->setString(TodoUtil::itos(page)); pagelabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); pagelabel->setPosition(pos); - - if (DebugLayout) { + + if (DebugLayout) + { auto line = DrawNode::create(); auto pageSize = _pageView->getContentSize(); line->setContentSize(pageSize); _pageView->addChild(line); - - line->drawLine(Vec2(0, pos.y+10), Vec2(pageSize.width, pos.y+10), Color4F::BLUE); - line->drawLine(Vec2(pageSize.width/2, pos.y), Vec2(pageSize.width/2, pos.y+20), Color4F::BLUE); - - - - - + + line->drawLine(Vec2(0, pos.y + 10), Vec2(pageSize.width, pos.y + 10), Color4F::BLUE); + line->drawLine(Vec2(pageSize.width / 2, pos.y), Vec2(pageSize.width / 2, pos.y + 20), Color4F::BLUE); } - + _pageView->addChild(pagelabel); } diff --git a/bookviewer/Classes/BookPage.hpp b/bookviewer/Classes/BookPage.hpp index e33e4880f..b04966757 100644 --- a/bookviewer/Classes/BookPage.hpp +++ b/bookviewer/Classes/BookPage.hpp @@ -15,91 +15,69 @@ #include "ui/CocosGUI.h" #include "TodoBook.hpp" - USING_NS_CC; - - class BookPage : public Node { public: - - static BookPage* create(); + static BookPage *create(); virtual bool init() override; virtual void onExit() override; virtual void update(float delta) override; void highlightWordButton(ui::Button *btn, bool highlight); void startReading(); void stopReading(); - + void setTitle(string title, string titleImagePath, string audioPath, TDBookLayout layout, float delay); void setPage(TodoBook *book, TodoPage *page, TDBookLayout layout, bool withAudio); void setCreditPage(); void setPageNum(int page, Node *_pageView, Vec2 pos); - - - + void showRightHalf(bool animate); void showLeftHalf(bool animate); - + void hideRightHalf(bool animate); void hideLeftHalf(bool animate); - - - - - -protected: - +protected: bool isFirstPage() { return _page->pageNum == 1; } bool isLastPage() { return _page->lastPage; } bool isCreditPage() { return _page->creditPage; } bool isTitlePage() { return _isTitle; } - void playWordSound(ui::Button *button, string path, float length); - Node* createTextViewOneLine(Size size, float fontSize); - Node* createTextViewMultiLine(Size size, float fontSize); - - + void playWordSound(ui::Button *button); + Node *createTextViewOneLine(Size size, float fontSize); + Node *createTextViewMultiLine(Size size, float fontSize); + Node *_leftView, *_rightView; Node *_leftCover, *_rightCover; - + Node *_contentsView; - Node *_imageView; Node *_textView; - - - - std::vector _wordButtons; + std::vector _wordButtons; std::vector _words; - + TodoBook *_book; TodoPage *_page; - + //string _resourceFolder; int _readingSentenceIndex; //int _readingAudioID; -> change as BGM - + bool _isTitle; string _titleAudioPath; - - + bool _hasBackCover; TDBookLayout _bookLayout; bool _withAudio; float _timePage, _timeSentence; bool _isReading; - + bool _pauseReading; float _pauseLength; - - - }; - #endif /* BookPage_hpp */ diff --git a/bookviewer/Classes/Managers/VoiceMoldManager.cpp b/bookviewer/Classes/Managers/VoiceMoldManager.cpp new file mode 100644 index 000000000..46ce3827c --- /dev/null +++ b/bookviewer/Classes/Managers/VoiceMoldManager.cpp @@ -0,0 +1,184 @@ +// +// Created by Taihyun Hwang on 16-Mar-2018. +// + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + +#include "VoiceMoldManager.h" + +#include +#include "platform/android/jni/JniHelper.h" +#include "cocos2d.h" +#include +#include + +using namespace cocos2d; +using namespace std; + +std::string VoiceMoldManager::getDefaultLocale(std::string locale) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticGetDefaultLocale", + "()Ljava/lang/String;")) + { + jstring jLocale = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID); + string locale = JniHelper::jstring2string(jLocale); + + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(jLocale); + + return locale; + } + + return ""; +} + +void VoiceMoldManager::setDefaultLocale(std::string locale) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticSetDefaultLocale", + "(Ljava/lang/String;)V")) + { + jstring jLocale = t.env->NewStringUTF(locale.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, jLocale); + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(jLocale); + } +} + +void VoiceMoldManager::secureVoiceData() +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticSecureVoiceData", "()V")) + { + t.env->CallStaticVoidMethod(t.classID, t.methodID); + t.env->DeleteLocalRef(t.classID); + } +} + +void VoiceMoldManager::secureVoiceData(std::string locale) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticSecureVoiceData", "(Ljava/lang/String;)V")) + { + jstring jLocale = t.env->NewStringUTF(locale.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, jLocale); + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(jLocale); + } +} + +void VoiceMoldManager::warmup() +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticWarmup", "()V")) + { + t.env->CallStaticVoidMethod(t.classID, t.methodID); + t.env->DeleteLocalRef(t.classID); + } +} + +void VoiceMoldManager::warmup(std::string locale) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticWarmup", "(Ljava/lang/String;)V")) + { + jstring jLocale = t.env->NewStringUTF(locale.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, jLocale); + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(jLocale); + } +} + +void VoiceMoldManager::speak(std::string text) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticSpeak", "(Ljava/lang/String;)V")) + { + jstring jText = t.env->NewStringUTF(text.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, jText); + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(jText); + } +} + +void VoiceMoldManager::speak(std::string text, std::string locale) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticSpeak", "(Ljava/lang/String;Ljava/lang/String;)V")) + { + jstring jText = t.env->NewStringUTF(text.c_str()); + jstring jLocale = t.env->NewStringUTF(locale.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, jText, jLocale); + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(jText); + t.env->DeleteLocalRef(jLocale); + } +} + +float VoiceMoldManager::guessSpeakDuration(std::string text) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticGuessSpeakDuration", "(Ljava/lang/String;)F")) + { + jstring jText = t.env->NewStringUTF(text.c_str()); + float rv = t.env->CallStaticFloatMethod(t.classID, t.methodID, jText); + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(jText); + + return rv; + } + + return std::numeric_limits::quiet_NaN(); +} + +float VoiceMoldManager::guessSpeakDuration(std::string text, std::string locale) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, + "org/cocos2dx/cpp/VoiceMoldManager", + "staticGuessSpeakDuration", "(Ljava/lang/String;Ljava/lang/String;)F")) + { + jstring jText = t.env->NewStringUTF(text.c_str()); + jstring jLocale = t.env->NewStringUTF(locale.c_str()); + float rv = t.env->CallStaticFloatMethod(t.classID, t.methodID, jText, jLocale); + t.env->DeleteLocalRef(t.classID); + t.env->DeleteLocalRef(jText); + t.env->DeleteLocalRef(jLocale); + + return rv; + } + + return std::numeric_limits::quiet_NaN(); +} + +VoiceMoldManager *VoiceMoldManager::shared() +{ + static VoiceMoldManager *_shared = nullptr; + if (!_shared) + { + _shared = new VoiceMoldManager(); + } + return _shared; +} + +#endif +//EOF diff --git a/bookviewer/Classes/Managers/VoiceMoldManager.h b/bookviewer/Classes/Managers/VoiceMoldManager.h new file mode 100644 index 000000000..0756ba42e --- /dev/null +++ b/bookviewer/Classes/Managers/VoiceMoldManager.h @@ -0,0 +1,40 @@ +// +// Created by Taihyun Hwang on 26/02/2018. +// + +#pragma once + +#include + +class VoiceMoldManager +{ +public: + // NB(xenosoz, 2018): To copy these std::string prevent crash + // on some device. I'm very sad I don't know why, but it works. + + std::string getDefaultLocale(std::string locale); + void setDefaultLocale(std::string locale); + + // NB(xenosoz, 2018): Issue an (android) intent to install voice data. + void secureVoiceData(); + void secureVoiceData(std::string locale); + + void warmup(); + void warmup(std::string locale); + + void speak(std::string text); + void speak(std::string text, std::string locale); + + float guessSpeakDuration(std::string text); + float guessSpeakDuration(std::string text, std::string locale); + +public: + static VoiceMoldManager *shared(); + +#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) +private: + std::string _internalLocaleForMock; +#endif +}; + +//EOF diff --git a/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java b/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java index de7574445..2bae64e69 100644 --- a/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java +++ b/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java @@ -48,6 +48,7 @@ public class AppActivity extends Cocos2dxActivity { public static AppActivity _activity; public static String _launchString; private static String TAG = "BookTestActivity"; + public static AppActivity instance() { return _activity; } private Cocos2dxGLSurfaceView _glSurfaceView; public static String getDocumentsPath() { diff --git a/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/TextToSpeechWrapper.java b/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/TextToSpeechWrapper.java new file mode 100644 index 000000000..18894f422 --- /dev/null +++ b/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/TextToSpeechWrapper.java @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// NB(xenosoz, 2018): from https://android.googlesource.com/platform/cts/+/70ebda42367ada13ff1500bf7d985714055c4cdc/tests/tests/speech/src/android/speech/tts/cts/TextToSpeechWrapper.java +// NB(xenosoz, 2018): Modified to always pick a license-free TTS engine. + +package org.cocos2dx.cpp; + +import android.content.Context; +import android.media.MediaPlayer; +import android.speech.tts.TextToSpeech; +import android.speech.tts.TextToSpeech.OnInitListener; +import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; +import android.util.Log; +import java.util.HashSet; +import java.util.Locale; +import java.util.StringTokenizer; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +/** + * Wrapper for {@link TextToSpeech} with some handy test functionality. + */ +public class TextToSpeechWrapper { + private static final String LOG_TAG = "TextToSpeechServiceTest"; + public static final String MOCK_TTS_ENGINE = "com.android.cts.stub"; + //public static final String FREE_TO_USE_TTS_ENGINE = "com.svox.pico"; + //public static final String FREE_TO_USE_TTS_ENGINE = "com.example.android.ttsengine"; + public static final String FREE_TO_USE_TTS_ENGINE = "com.enuma.voice_engine_a"; + private boolean _goodEngine = false; + private boolean _energetic = false; + + private final Context mContext; + private final String mLocale; + private TextToSpeech mTts; + private final InitWaitListener mInitListener; + private final UtteranceWaitListener mUtteranceListener; + /** maximum time to wait for tts to be initialized */ + private static final int TTS_INIT_MAX_WAIT_TIME = 30 * 1000; + /** maximum time to wait for speech call to be complete */ + private static final int TTS_SPEECH_MAX_WAIT_TIME = 5 * 1000; + + private TextToSpeechWrapper(Context context, String locale) { + mContext = context; + mLocale = locale; + mInitListener = new InitWaitListener(); + mUtteranceListener = new UtteranceWaitListener(); + } + + private boolean initTts() throws InterruptedException { + return initTts(new TextToSpeech(mContext, mInitListener)); + } + + private boolean initTts(String engine) throws InterruptedException { + return initTts(new TextToSpeech(mContext, mInitListener, engine)); + } + + private boolean initTts(TextToSpeech tts) throws InterruptedException { + _goodEngine = false; + mTts = tts; + if (!mInitListener.waitForInit()) { + return false; + } + mTts.setOnUtteranceCompletedListener(mUtteranceListener); + updateEngineStatus(); + updateVitalStatus(); + + return true; + } + + private void updateEngineStatus() { + if (mTts != null) { + for (TextToSpeech.EngineInfo info : mTts.getEngines()) { + Log.d("Info!", info.name); + if (FREE_TO_USE_TTS_ENGINE.equals(info.name)) { + _goodEngine = true; + return; + } + } + } + + _goodEngine = false; + } + + private void updateVitalStatus() { + if (mTts != null) { + // NB(xenosoz, 2018): I don't have Locale.forLanguageTag here. + + String lang = "hi"; + String country = "IN"; + + StringTokenizer st = new StringTokenizer(mLocale, "-"); + if (st.hasMoreTokens()) { + lang = st.nextElement().toString(); + } + if (st.hasMoreTokens()) { + country = st.nextElement().toString(); + } + + Locale loc = new Locale(lang, country); + int status = mTts.setLanguage(loc); + if (status >= TextToSpeech.LANG_AVAILABLE) { + _energetic = true; + } + } + } + + public boolean waitForComplete(String utteranceId) throws InterruptedException { + return mUtteranceListener.waitForComplete(utteranceId); + } + + public TextToSpeech getTts() { + return mTts; + } + public boolean isGood() { return _goodEngine; } + public boolean isEnergetic() { return _energetic; } + public void shutdown() { + mTts.shutdown(); + } + public static TextToSpeechWrapper createTextToSpeechWrapper(Context context, String locale) + throws InterruptedException { + TextToSpeechWrapper wrapper = new TextToSpeechWrapper(context, locale); + if (wrapper.initTts(FREE_TO_USE_TTS_ENGINE)) { + return wrapper; + } else { + return null; + } + } + + public static TextToSpeechWrapper createTextToSpeechMockWrapper(Context context, String locale) + throws InterruptedException + { + TextToSpeechWrapper wrapper = new TextToSpeechWrapper(context, locale); + if (wrapper.initTts(MOCK_TTS_ENGINE)) { + return wrapper; + } else { + return null; + } + } + /** + * Listener for waiting for TTS engine initialization completion. + */ + private static class InitWaitListener implements OnInitListener { + private final Lock mLock = new ReentrantLock(); + private final Condition mDone = mLock.newCondition(); + private Integer mStatus = null; + public void onInit(int status) { + mLock.lock(); + try { + mStatus = new Integer(status); + mDone.signal(); + } finally { + mLock.unlock(); + } + } + public boolean waitForInit() throws InterruptedException { + long timeOutNanos = TimeUnit.MILLISECONDS.toNanos(TTS_INIT_MAX_WAIT_TIME); + mLock.lock(); + try { + while (mStatus == null) { + if (timeOutNanos <= 0) { + return false; + } + timeOutNanos = mDone.awaitNanos(timeOutNanos); + } + return mStatus == TextToSpeech.SUCCESS; + } finally { + mLock.unlock(); + } + } + } + /** + * Listener for waiting for utterance completion. + */ + private static class UtteranceWaitListener implements OnUtteranceCompletedListener { + private final Lock mLock = new ReentrantLock(); + private final Condition mDone = mLock.newCondition(); + private final HashSet mCompletedUtterances = new HashSet(); + + public void onUtteranceCompleted(String utteranceId) { + mLock.lock(); + try { + mCompletedUtterances.add(utteranceId); + mDone.signal(); + } finally { + mLock.unlock(); + } + } + + public boolean waitForComplete(String utteranceId) + throws InterruptedException { + long timeOutNanos = TimeUnit.MILLISECONDS.toNanos(TTS_INIT_MAX_WAIT_TIME); + mLock.lock(); + try { + while (!mCompletedUtterances.remove(utteranceId)) { + if (timeOutNanos <= 0) { + return false; + } + timeOutNanos = mDone.awaitNanos(timeOutNanos); + } + return true; + } finally { + mLock.unlock(); + } + } + } + /** + * Determines if given file path is a valid, playable music file. + */ + public static boolean isSoundFile(String filePath) { + // use media player to play the file. If it succeeds with no exceptions, assume file is + //valid + MediaPlayer mp = null; + try { + mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.prepare(); + mp.start(); + mp.stop(); + return true; + } catch (Exception e) { + Log.e(LOG_TAG, "Exception while attempting to play music file", e); + return false; + } finally { + if (mp != null) { + mp.release(); + } + } + } +} \ No newline at end of file diff --git a/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMold.java b/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMold.java new file mode 100644 index 000000000..91e30329f --- /dev/null +++ b/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMold.java @@ -0,0 +1,143 @@ +/** + * VoiceMold.java -- Wrap[TextToSpeechWrapper] (=tts-wrapper-wrapper). + * + * NB(xenosoz, 2018): Date created: 26 Feb, 2018 + */ + +package org.cocos2dx.cpp; + +import java.io.File; +import java.lang.String; +import java.util.HashMap; +import java.util.List; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.media.MediaMetadataRetriever; +import android.speech.tts.TextToSpeech; +import android.util.Log; + + +public class VoiceMold { + private static final String SPEAK_UTTERANCE_ID = "com.enuma.voice_engine_a.speak"; + private static final String SYNTH_UTTERANCE_ID = "com.enuma.voice_engine_a.synth"; + + public TextToSpeechWrapper wrapper; + public String locale; + + + VoiceMold(String locale) { + Context context = AppActivity.instance(); + try { + this.locale = locale; + wrapper = TextToSpeechWrapper.createTextToSpeechWrapper(context, locale); + + Intent ttsIntent = new Intent(); + ttsIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); + + PackageManager pm = context.getPackageManager(); + List list = pm.queryIntentActivities(ttsIntent, + PackageManager.GET_META_DATA); + + for (ResolveInfo info : list) { + Log.d("Info", info.toString()); + } + } + catch (InterruptedException e) { + Log.d("Error", e.toString()); + } + } + + public boolean isEnergetic() { + return wrapper != null && wrapper.isEnergetic(); + } + + public void speak(String text) { + if (wrapper == null) { + Log.d("Warn", "SpeechWrapper wrapper is null in VoiceMold::speak()."); + return; + } + + if (!wrapper.isGood()) { + String header = " "; + text = header + text; + } + + wrapper.getTts().speak(text, TextToSpeech.QUEUE_FLUSH, createParamsForSpeak()); + while (wrapper.getTts().isSpeaking()) { + } + } + + public void warmup() { + if (wrapper == null) { + Log.d("Warn", "SpeechWrapper wrapper is null in VoiceMold::speak()."); + return; + } + + String text = ""; + wrapper.getTts().setPitch(0.80f); + wrapper.getTts().setSpeechRate(0.75f); + wrapper.getTts().speak(text, TextToSpeech.QUEUE_FLUSH, createParamsForSpeak()); + } + + public float guessSpeakDuration(String text) { + if (wrapper == null) { + Log.d("Warn", "SpeechWrapper wrapper is null in VoiceMold::speak()."); + return Float.NaN; + } + + if (!wrapper.isGood()) { + String header = " "; + text = header + text; + } + + try { + // NB(xenosoz, 2018): I'm sad we need android-21 to get it done this in-memory. + String filename; + + Context context = AppActivity.instance(); + File dummyFile = File.createTempFile("voice-engine-a.", "", context.getExternalCacheDir()); + + filename = dummyFile.getAbsolutePath() + ".mp3"; + dummyFile.delete(); + + + if (0 == wrapper.getTts().synthesizeToFile(text, createParamsForSynth(), filename)) { + wrapper.waitForComplete(SYNTH_UTTERANCE_ID); + + MediaMetadataRetriever mm = new MediaMetadataRetriever(); + mm.setDataSource(filename); + + String duration = mm.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + Log.v("time", duration); + float dur = Float.parseFloat(duration); + String seconds = String.valueOf((dur % 60000) / 1000); + Log.v("seconds", seconds); + String minutes = String.valueOf(dur / 60000); + return dur / 1000; + } + else { + Log.e("voice-engine-a", "synthesizeToFile failed"); + } + } + catch (Exception e) { // XXX + Log.e("voice-engine-a", e.toString()); + } + + return Float.NaN; + } + + private HashMap createParamsForSpeak() { + HashMap params = new HashMap(); + params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, SPEAK_UTTERANCE_ID); + return params; + } + + private HashMap createParamsForSynth() { + HashMap params = new HashMap(); + params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, SYNTH_UTTERANCE_ID); + return params; + } +} diff --git a/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMoldManager.java b/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMoldManager.java new file mode 100644 index 000000000..4ec22a477 --- /dev/null +++ b/bookviewer/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMoldManager.java @@ -0,0 +1,118 @@ +/** + * VoiceMoldManager.java -- Thin wrapper for locale-to-tts mapping + * + * NB(xenosoz, 2018): Date created: 26 Feb, 2018 + */ + + +package org.cocos2dx.cpp; +import android.content.Context; +import android.content.Intent; + +import java.lang.String; +import java.util.HashMap; + + +public class VoiceMoldManager +{ + public String defaultLocale = "en-IN"; + public HashMap moldForLocaleCache; + + public String getDefaultLocale() { return defaultLocale; } + public void setDefaultLocale(String locale) { defaultLocale = locale; } + + public VoiceMoldManager() { + moldForLocaleCache = new HashMap(); + } + + public VoiceMold moldForLocale(String locale) { + VoiceMold cache = moldForLocaleCache.get(locale); + if (cache != null) { + return cache; + } + + VoiceMold mold = new VoiceMold(locale); + moldForLocaleCache.put(locale, mold); + return mold; + } + + public void secureVoiceData() { + secureVoiceData(defaultLocale); + } + + public void secureVoiceData(String locale) { + VoiceMold mold = moldForLocale(locale); + + if (mold != null && mold.isEnergetic()) { + return; + } + + Intent intent = new Intent(); + intent.setAction("com.enuma.voice_engine_a.installer.CALL_BY_KITKIT_SCHOOL"); + + Context context = AppActivity.instance(); + context.startActivity(intent); + } + + public void warmup() { + warmup(defaultLocale); + } + + public void warmup(String locale) { + VoiceMold mold = moldForLocale(locale); + mold.warmup(); + } + + public void speak(String text) { + speak(text, defaultLocale); + } + + public void speak(String text, String locale) { + VoiceMold mold = moldForLocale(locale); + mold.speak(text); + } + + public float guessSpeakDuration(String text) { + return guessSpeakDuration(text, defaultLocale); + } + + public float guessSpeakDuration(String text, String locale) { + VoiceMold mold = moldForLocale(locale); + return mold.guessSpeakDuration(text); + } + + + // ---- + private static VoiceMoldManager _shared; + + public static VoiceMoldManager shared() { + if (_shared == null) { + _shared = new VoiceMoldManager(); + } + return _shared; + } + + + // NB(xenosoz, 2018): Sugers for simplifying exposure to c++ world. + + public static String staticGetDefaultLocale() { + return shared().getDefaultLocale(); + } + public static void staticSetDefaultLocale(String locale) { + shared().setDefaultLocale(locale); + } + + public static void staticSecureVoiceData() { shared().secureVoiceData(); } + public static void staticSecureVoiceData(String locale) { shared().secureVoiceData(locale); } + + public static void staticWarmup() { shared().warmup(); } + public static void staticWarmup(String locale) { shared().warmup(locale); } + + public static void staticSpeak(String text) { shared().speak(text); } + public static void staticSpeak(String text, String locale) { + shared().speak(text, locale); + } + + public static float staticGuessSpeakDuration(String text) { return shared().guessSpeakDuration(text); } + public static float staticGuessSpeakDuration(String text, String locale) { return shared().guessSpeakDuration(text); } +} diff --git a/mainapp/Classes/Games/Books/BookPage.cpp b/mainapp/Classes/Games/Books/BookPage.cpp index 561b5978b..4459aadd0 100644 --- a/mainapp/Classes/Games/Books/BookPage.cpp +++ b/mainapp/Classes/Games/Books/BookPage.cpp @@ -8,121 +8,121 @@ #include "BookPage.hpp" -#include "Managers/GameSoundManager.h" #include "Utils/TodoUtil.h" #include "Common/Controls/SignLanguageVideoPlayer.hpp" - +#include "Managers/VoiceMoldManager.h" using namespace ui; +namespace BookPageSpace +{ +const auto textColor = Color3B(79, 61, 24); +const Size defaultSize = Size(2560, 1800); +const Size halfSize = Size(1280, 1800); -namespace BookPageSpace { - const auto textColor = Color3B(79, 61, 24); - const Size defaultSize = Size(2560, 1800); - const Size halfSize = Size(1280, 1800); - - const Size bigSize = Size(2480, 1800); - const Size smallSize = Size(80, 1800); - - const Size squareSize = Size(1520, 1520); - const Size squareImageSize = Size(909, 909); - - - const float squareMiddle = defaultSize.width/2 - squareSize.width/2; - - const float skewY = 10; - const float turnDuration = 0.25; - const float turnEase = 1.4; - - const string titleFont = "fonts/Seshat.otf"; - const string bodyFont = "fonts/mukta-bold.ttf"; - - const bool DebugLayout = false; - - -} +const Size bigSize = Size(2480, 1800); +const Size smallSize = Size(80, 1800); -using namespace BookPageSpace; +const Size squareSize = Size(1520, 1520); +const Size squareImageSize = Size(909, 909); + +const float squareMiddle = defaultSize.width / 2 - squareSize.width / 2; + +const float skewY = 10; +const float turnDuration = 0.25; +const float turnEase = 1.4; + +const string titleFont = "fonts/Seshat.otf"; +const string bodyFont = "fonts/mukta-bold.ttf"; +const bool DebugLayout = false; -BookPage* BookPage::create() +} // namespace BookPageSpace + +using namespace BookPageSpace; + +BookPage *BookPage::create() { - BookPage *pRet = new(std::nothrow) BookPage(); - if (pRet && pRet->init()) { + BookPage *pRet = new (std::nothrow) BookPage(); + if (pRet && pRet->init()) + { pRet->autorelease(); return pRet; - } else { + } + else + { delete pRet; - pRet= nullptr; + pRet = nullptr; return nullptr; } } - bool BookPage::init() { - if (!Node::init()) return false; - + if (!Node::init()) + return false; + setColor(Color3B::WHITE); - + setContentSize(defaultSize); _contentsView = Node::create(); _contentsView->setContentSize(defaultSize); addChild(_contentsView); - + _isReading = false; - + return true; - } void BookPage::onExit() { Node::onExit(); - - } - - - +int buttonIndex = 0; +int tag = -1; void BookPage::update(float delta) { - if (_pauseReading) { - + if (_pauseReading) + { + _pauseLength -= delta; - if (_pauseLength<0) { + if (_pauseLength < 0) + { _pauseLength = 0; _pauseReading = false; - - //GameSoundManager::getInstance()->resumeEffect(_readingAudioID); - GameSoundManager::getInstance()->resumeBGM(); - - } else { + } + else + { return; } - } else { - _timePage+=delta; - _timeSentence+=delta; - + } + else + { + _timePage += delta; + _timeSentence += delta; + auto page = _page; - + int newReadingSentenceIndex = _readingSentenceIndex; TodoSentence newReadingSentence; - - int i=-1; - - for (auto p : page->paragraphs) { - for (auto s : p.sentences) { + + int i = -1; + + for (auto p : page->paragraphs) + { + for (auto s : p.sentences) + { i++; - if (s.startTimingInPage <= _timePage) { + if (s.startTimingInPage <= _timePage) + { newReadingSentenceIndex = i; newReadingSentence = s; } } } - + /* for (int i=_readingSentence+1; iparagraphs[0].sentences.size(); i++) { auto sentence= page->paragraphs[0].sentences[i]; @@ -132,40 +132,71 @@ void BookPage::update(float delta) } } */ - - - if (newReadingSentenceIndex!=_readingSentenceIndex) { - _readingSentenceIndex = newReadingSentenceIndex; - //auto sentence= page->paragraphs[0].sentences[_readingSentenceIndex]; - - GameSoundManager::getInstance()->stopAllEffects(); - - //auto audioPath = _book->filePrefix+_book->pagePrefix+sentence.sentenceAudioFilename; - auto audioPath = _book->filePrefix + "page/"+newReadingSentence.sentenceAudioFilename; - //_readingAudioID = GameSoundManager::getInstance()->playEffectSound(audioPath); - GameSoundManager::getInstance()->playBGM(audioPath); - - _timeSentence = 0.0; - + auto b1 = ui::Button::create(); + b1->setTag(-1); + if (newReadingSentenceIndex != _readingSentenceIndex) + { + if (buttonIndex == _words.size()) + { + _readingSentenceIndex = newReadingSentenceIndex; + buttonIndex = -1; + } + for (auto b : _wordButtons) + { + if (buttonIndex > b->getTag()) + { + continue; + } + if (buttonIndex >= 0) + { + b1 = b; + if (b->getTag() > 0) + { + VoiceMoldManager::shared()->speak(_words[b->getTag() - 1].word); + } + } + else + { + VoiceMoldManager::shared()->speak(_words[_words.size() - 1].word); + _timeSentence = 0.0; + } + buttonIndex++; + break; + } } - - } - - - for (auto b : _wordButtons) { - auto wordObj = _words[b->getTag()]; - bool highlight = wordObj.startTimingInPage<=_timePage && _timePage<=wordObj.endTimingInPage; - highlightWordButton(b, highlight); + + for (auto b : _wordButtons) + { + if (b->getTag() == b1->getTag()) + { + highlightWordButton(b, true); + } + else + { + if (tag >= 0) + { + if (tag == b->getTag()) + { + VoiceMoldManager::shared()->speak(_words[b->getTag()].word); + } + } + highlightWordButton(b, b->getTag() == tag); + } + } + tag = -1; } } void BookPage::highlightWordButton(ui::Button *btn, bool highlight) { - if (highlight) { + if (highlight) + { btn->resetNormalRender(); btn->loadTextureNormal("Common/lightblue.png"); btn->setTitleColor(Color3B::BLACK); - } else { + } + else + { btn->resetNormalRender(); btn->loadTextureNormal("Common/transparent.png"); btn->setTitleColor(textColor); @@ -177,690 +208,625 @@ void BookPage::startReading() _timePage = -0.5; _timeSentence = -0.5; _readingSentenceIndex = -1; - if (_withAudio ) { + if (_withAudio) + { _isReading = true; scheduleUpdate(); } - - + SHOW_SL_VIDEO_IF_ENABLED("common/temp_video_short.mp4"); } void BookPage::stopReading() { - if (_withAudio) { + if (_withAudio) + { _isReading = false; unscheduleUpdate(); } - - GameSoundManager::getInstance()->stopAllEffects(); - GameSoundManager::getInstance()->stopBGM(); - - for (auto b : _wordButtons) { + + for (auto b : _wordButtons) + { highlightWordButton(b, false); } - - } void BookPage::setTitle(string title, string titleImagePath, string audioPath, TDBookLayout layout, float delay) { Size size = getContentSize(); - + _isTitle = true; - + unscheduleUpdate(); - - - //_isPortrait = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; - _hasBackCover = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; - - if (layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional) { - - - + + // _isPortrait = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; + _hasBackCover = layout == TDBookLayout::Portrait || layout == TDBookLayout::Portrait_Traditional; + + if (layout == TDBookLayout::Portrait || layout == TDBookLayout::Portrait_Traditional) + { + _leftView = Node::create(); _leftView->setContentSize(halfSize); _contentsView->addChild(_leftView); - - - + _leftCover = Node::create(); _leftCover->setContentSize(halfSize); - + Sprite *sp; - if (layout==TDBookLayout::Portrait_Traditional) { + if (layout == TDBookLayout::Portrait_Traditional) + { sp = Sprite::create("Books/portrait_traditional/koreanbook_cover.jpg", Rect(0, 0, 20, 1800)); - } else { + } + else + { sp = Sprite::create("Books/portrait/xprize_vertical_layout_cover.jpg", Rect(0, 0, 20, 1800)); } sp->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sp->setPosition(Vec2(halfSize.width, 0)); _leftCover->addChild(sp); _leftView->addChild(_leftCover); - - + _rightView = Node::create(); _rightView->setContentSize(halfSize); _rightView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_rightView); - - if (layout==TDBookLayout::Portrait_Traditional) { + + if (layout == TDBookLayout::Portrait_Traditional) + { _rightCover = Sprite::create("Books/portrait_traditional/koreanbook_cover.jpg", Rect(20, 0, 1280, 1800)); - } else { + } + else + { _rightCover = Sprite::create("Books/portrait/xprize_vertical_layout_cover.jpg", Rect(20, 0, 1280, 1800)); } _rightCover->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->setPosition(Vec2(0, 0)); _rightView->addChild(_rightCover); - - - Vec2 imagePos = Vec2(halfSize.width-610, 720); - + + Vec2 imagePos = Vec2(halfSize.width - 610, 720); + Sprite *cover; - if (layout==TDBookLayout::Portrait_Traditional) { + if (layout == TDBookLayout::Portrait_Traditional) + { cover = Sprite::create("Books/portrait_traditional/koreanbook_cover_illustration_blank.png"); - } else { + } + else + { cover = Sprite::create("Books/portrait/book_vertical_cover_illustration.png"); } - + cover->setPosition(imagePos); _rightView->addChild(cover); - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(Size(1020, 1170)); _imageView->setPosition(imagePos); _rightView->addChild(_imageView); - - if (layout==TDBookLayout::Portrait) { + + if (layout == TDBookLayout::Portrait) + { auto texture = Sprite::create("Books/portrait/book_vertical_cover_illustration_texture.png"); texture->setScale(2.0); texture->setPosition(imagePos); _rightView->addChild(texture); } - + Sprite *frame; - if (layout==TDBookLayout::Portrait_Traditional) { + if (layout == TDBookLayout::Portrait_Traditional) + { frame = Sprite::create("Books/portrait_traditional/koreanbook_cover_illustration_frame.png"); - } else { + } + else + { frame = Sprite::create("Books/portrait/xprize_vertical_cover_illustration_frame.png"); } frame->setPosition(imagePos); _rightView->addChild(frame); - - + auto textViewSize = Size(1038, 360); - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(textViewSize); - _textView->setPosition(Vec2(halfSize.width-610, 1800-250)); + _textView->setPosition(Vec2(halfSize.width - 610, 1800 - 250)); _rightView->addChild(_textView); - + float fontSize = 150; - - auto labelFunc = [&](Color4B color, string fontName, Size offset){ - + + auto labelFunc = [&](Color4B color, string fontName, Size offset) { auto l = Label::createWithTTF(title, fontName, fontSize, Size(textViewSize.width, 0), TextHAlignment::CENTER); auto lSize = l->getContentSize(); - if (lSize.height > textViewSize.height) { + if (lSize.height > textViewSize.height) + { l->setScale(textViewSize.height / lSize.height); } - l->setPosition(textViewSize/2 + offset); + l->setPosition(textViewSize / 2 + offset); l->setTextColor(color); return l; }; - - - if (layout==TDBookLayout::Portrait_Traditional) { - _textView->addChild(labelFunc(Color4B(77, 35, 20, 255),bodyFont, Size(0, 0))); - } else { + + if (layout == TDBookLayout::Portrait_Traditional) + { + _textView->addChild(labelFunc(Color4B(77, 35, 20, 255), bodyFont, Size(0, 0))); + } + else + { _textView->addChild(labelFunc(Color4B(148, 94, 48, 255), titleFont, Size(5, -5))); _textView->addChild(labelFunc(Color4B(255, 250, 227, 255), titleFont, Size(0, 0))); } - - - } else if (layout==TDBookLayout::Landscape) { - + } + else if (layout == TDBookLayout::Landscape) + { + _leftView = Node::create(); _leftView->setContentSize(smallSize); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftCover->setContentSize(smallSize); _leftView->addChild(_leftCover); - - - auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(0, 0, 80/2, 1800/2)); + + auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(0, 0, 80 / 2, 1800 / 2)); sp->setScale(2.0); sp->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sp->setPosition(Vec2(smallSize.width, 0)); _leftCover->addChild(sp); - auto bindingLeft = Sprite::create("Books/book_horizontal_cover_binding.png", Rect(0, 0, 85, 1800)); bindingLeft->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); bindingLeft->setPosition(Vec2(smallSize.width, 0)); _leftCover->addChild(bindingLeft); - - - - + _rightView = Node::create(); _rightView->setContentSize(bigSize); _rightView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_rightView); - - _rightCover = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80/2, 0, (2560-80)/2, 1800/2)); + + _rightCover = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); _rightCover->setScale(2); _rightCover->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->setPosition(Vec2(0, 0)); _rightView->addChild(_rightCover); - - auto bindingRight = Sprite::create("Books/book_horizontal_cover_binding.png", Rect(85, 0, 150-85, 1800)); + + auto bindingRight = Sprite::create("Books/book_horizontal_cover_binding.png", Rect(85, 0, 150 - 85, 1800)); bindingRight->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); bindingRight->setPosition(Vec2(0, 0)); _rightCover->addChild(bindingRight); - - - Vec2 imagePos = Vec2(bigSize.width/2, 750); - + + Vec2 imagePos = Vec2(bigSize.width / 2, 750); + auto cover = Sprite::create("Books/xprize_horizontal_cover_illustration.png"); cover->setPosition(imagePos); _rightView->addChild(cover); - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(Size(1560, 1090)); _imageView->setPosition(imagePos); _rightView->addChild(_imageView); - - - + auto texture = Sprite::create("Books/xprize_horizontal_cover_illustration_texture.png"); texture->setScale(2.0); texture->setPosition(imagePos); _rightView->addChild(texture); - + auto frame = Sprite::create("Books/xprize_horizontal_cover_frame.png"); frame->setPosition(imagePos); _rightView->addChild(frame); - - + auto textViewSize = Size(1560, 360); - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); _textView->setContentSize(textViewSize); - _textView->setPosition(Vec2(bigSize.width/2, 1800-380-100)); + _textView->setPosition(Vec2(bigSize.width / 2, 1800 - 380 - 100)); _rightView->addChild(_textView); - + float fontSize = 150; - - - - auto labelFunc = [&](Color4B color, Size offset){ - + + auto labelFunc = [&](Color4B color, Size offset) { auto l = Label::createWithTTF(title, titleFont, fontSize, Size(textViewSize.width, 0), TextHAlignment::CENTER, TextVAlignment::CENTER); auto lSize = l->getContentSize(); - if (lSize.height > textViewSize.height) { + if (lSize.height > textViewSize.height) + { l->setScale(textViewSize.height / lSize.height); } - l->setPosition(Size(textViewSize.width/2, lSize.height/2) + offset); + l->setPosition(Size(textViewSize.width / 2, lSize.height / 2) + offset); l->setTextColor(color); return l; }; - - + _textView->addChild(labelFunc(Color4B(84, 37, 11, 255), Size(5, -5))); _textView->addChild(labelFunc(Color4B(255, 248, 227, 255), Size(0, 0))); - - - - - - - - } else if (layout==TDBookLayout::Square) { - - + } + else if (layout == TDBookLayout::Square) + { + _leftView = Node::create(); _leftView->setContentSize(squareSize); _contentsView->addChild(_leftView); - - - + _leftCover = Node::create(); _leftCover->setContentSize(squareSize); _leftView->addChild(_leftCover); - - + _rightView = Node::create(); _rightView->setContentSize(squareSize); - _rightView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _rightView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_rightView); - + _rightCover = Node::create(); _rightCover->setContentSize(squareSize); - + auto coverBG = Sprite::create("Books/square/_alphabet_book_border.jpg"); - coverBG->setPosition(squareSize/2); + coverBG->setPosition(squareSize / 2); _rightCover->addChild(coverBG); _rightCover->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->setPosition(Vec2(0, 0)); _rightView->addChild(_rightCover); - - - Vec2 imagePos = Vec2(squareSize.width/2, squareSize.height/2); - - + + Vec2 imagePos = Vec2(squareSize.width / 2, squareSize.height / 2); + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(squareImageSize); _imageView->setPosition(imagePos); _rightView->addChild(_imageView); - - - auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171/2, 0, 171/2, 1520)); + + auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171 / 2, 0, 171 / 2, 1520)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightView->addChild(rightBinding); - -// Sprite *frame; -// if (layout==TDBookLayout::Portrait_Traditional) { -// frame = Sprite::create("Books/portrait_traditional/koreanbook_cover_illustration_frame.png"); -// } else { -// frame = Sprite::create("Books/portrait/xprize_vertical_cover_illustration_frame.png"); -// } -// -// frame->setPosition(imagePos); -// _rightView->addChild(frame); - - - - + + // Sprite *frame; + // if (layout==TDBookLayout::Portrait_Traditional) { + // frame = Sprite::create("Books/portrait_traditional/koreanbook_cover_illustration_frame.png"); + // } else { + // frame = Sprite::create("Books/portrait/xprize_vertical_cover_illustration_frame.png"); + // } + + // frame->setPosition(imagePos); + // _rightView->addChild(frame); } - - - - - - - + auto image = Sprite::create(titleImagePath); - if (!image) image = Sprite::create(titleImagePath+".jpg"); - if (!image) image = Sprite::create(titleImagePath+".png"); - if (image) { + if (!image) + image = Sprite::create(titleImagePath + ".jpg"); + if (!image) + image = Sprite::create(titleImagePath + ".png"); + if (image) + { auto imageSize = image->getContentSize(); auto viewSize = _imageView->getContentSize(); - auto scale = MIN(viewSize.width/imageSize.width, viewSize.height/imageSize.height); + auto scale = MIN(viewSize.width / imageSize.width, viewSize.height / imageSize.height); image->setScale(scale); - image->setPosition(viewSize/2); + image->setPosition(viewSize / 2); _imageView->addChild(image); } - - - - - GameSoundManager::getInstance()->stopAllEffects(); - if (audioPath.length() > 0) { + + if (audioPath.length() > 0) + { auto titleAudioPath = audioPath; - scheduleOnce([titleAudioPath](float){ // Sound delay - GameSoundManager::getInstance()->playBGM(titleAudioPath); - }, delay, "titleAudio"); + scheduleOnce([title](float) { // Sound delay + VoiceMoldManager::shared()->speak(title); + }, + delay, "titleAudio"); SHOW_SL_VIDEO_IF_ENABLED("common/temp_video_short.mp4"); } } - -void BookPage::setPage(TodoBook *book, TodoPage *page, TDBookLayout layout, bool withAudio) +void BookPage::setPage(TodoBook *book, TodoPage *page, TDBookLayout layout, bool withAudio) { _isTitle = false; - + _page = page; _book = book; auto folder = _book->filePrefix; _bookLayout = layout; _withAudio = withAudio; - //_isPortrait = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; - _hasBackCover = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; + // _isPortrait = layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional; + _hasBackCover = layout == TDBookLayout::Portrait || layout == TDBookLayout::Portrait_Traditional; int pageNum = _page->pageNum; - if (page->creditPage) { + if (page->creditPage) + { setCreditPage(); return; - } Size size = getContentSize(); + if (layout == TDBookLayout::Portrait || layout == TDBookLayout::Portrait_Traditional) + { - - - if (layout==TDBookLayout::Portrait || layout==TDBookLayout::Portrait_Traditional) { - - - _leftView = Node::create(); _leftView->setContentSize(halfSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_leftView); - - if (layout==TDBookLayout::Portrait_Traditional) { + + if (layout == TDBookLayout::Portrait_Traditional) + { _leftCover = Sprite::create("Books/portrait_traditional/koreanbook_coverplain.jpg", Rect(0, 0, 1280, 1800)); - } else { + } + else + { _leftCover = Sprite::create("Books/portrait/book_vertical_yellowcover_bg.jpg", Rect(0, 0, 1280, 1800)); } - _leftCover->setPosition(halfSize/2); + _leftCover->setPosition(halfSize / 2); _leftView->addChild(_leftCover); - - auto leftBinding = Sprite::create("Books/book_vertical_yellowcover_bg_binding.png", Rect(0, 0, 472/2, 1800)); + + auto leftBinding = Sprite::create("Books/book_vertical_yellowcover_bg_binding.png", Rect(0, 0, 472 / 2, 1800)); leftBinding->setPosition(Vec2(halfSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftCover->addChild(leftBinding); - - + auto wp1 = Scale9Sprite::create("Books/book_vertical_pagespread_1.png"); wp1->setPreferredSize(Size(1280, 1718)); wp1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); wp1->setPosition(Vec2(halfSize.width, 30)); _leftView->addChild(wp1); - + auto sd1 = Scale9Sprite::create("Books/book_vertical_middleshadow_left_1.png"); sd1->setPreferredSize(Size(85, 1698)); sd1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sd1->setPosition(Vec2(halfSize.width, 50)); _leftView->addChild(sd1); - - - + _rightView = Node::create(); _rightView->setContentSize(halfSize); _rightView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_rightView); - - - if (layout==TDBookLayout::Portrait_Traditional) { + + if (layout == TDBookLayout::Portrait_Traditional) + { _rightCover = Sprite::create("Books/portrait_traditional/koreanbook_coverplain.jpg", Rect(0, 0, 1280, 1800)); - } else { + } + else + { _rightCover = Sprite::create("Books/portrait/book_vertical_yellowcover_bg.jpg", Rect(1280, 0, 1280, 1800)); } - - _rightCover->setPosition(halfSize/2); + + _rightCover->setPosition(halfSize / 2); _rightView->addChild(_rightCover); - - auto rightBinding = Sprite::create("Books/book_vertical_yellowcover_bg_binding.png", Rect(472/2, 0, 472/2, 1800)); + + auto rightBinding = Sprite::create("Books/book_vertical_yellowcover_bg_binding.png", Rect(472 / 2, 0, 472 / 2, 1800)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->addChild(rightBinding); - - + auto wp2 = Scale9Sprite::create("Books/book_vertical_pagespread_1.png"); wp2->setPreferredSize(Size(1280, 1718)); wp2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); wp2->setPosition(Vec2(0, 30)); _rightView->addChild(wp2); - - - if (layout==TDBookLayout::Portrait) { + + if (layout == TDBookLayout::Portrait) + { auto wp3 = Sprite::create("Books/book_vertical_toppage.png"); wp3->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); wp3->setPosition(Vec2(0, 30)); _rightView->addChild(wp3); } - + auto sd2 = Scale9Sprite::create("Books/book_vertical_middleshadow_right_1.png"); sd2->setPreferredSize(Size(85, 1698)); sd2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); sd2->setPosition(Vec2(0, 50)); _rightView->addChild(sd2); - - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(Size(1110, 1500)); - _imageView->setPosition(halfSize/2); + _imageView->setPosition(halfSize / 2); _leftView->addChild(_imageView); - - auto leftTexture = Sprite::create("Books/book_vertical_pagespread_texture.png", Rect(0, 0, 1280/2, 1718/2)); + + auto leftTexture = Sprite::create("Books/book_vertical_pagespread_texture.png", Rect(0, 0, 1280 / 2, 1718 / 2)); leftTexture->setScale(2); leftTexture->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); leftTexture->setPosition(wp1->getPosition()); _leftView->addChild(leftTexture); - - setPageNum((pageNum * 2 - 1), _leftView, Vec2(_leftView->getContentSize().width/2, 100)); - + + setPageNum((pageNum * 2 - 1), _leftView, Vec2(_leftView->getContentSize().width / 2, 100)); + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(Size(1000, 1500)); - _textView->setPosition(halfSize/2); + _textView->setPosition(halfSize / 2); _rightView->addChild(_textView); - - auto rightTexture = Sprite::create("Books/book_vertical_pagespread_texture.png", Rect(1280/2, 0, 1280/2, 1718/2)); + + auto rightTexture = Sprite::create("Books/book_vertical_pagespread_texture.png", Rect(1280 / 2, 0, 1280 / 2, 1718 / 2)); rightTexture->setScale(2); rightTexture->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); rightTexture->setPosition(wp2->getPosition()); _rightView->addChild(rightTexture); - - setPageNum(( pageNum * 2), _rightView, Vec2(_rightView->getContentSize().width/2, 100)); - - } else if (layout==TDBookLayout::Landscape) { + + setPageNum((pageNum * 2), _rightView, Vec2(_rightView->getContentSize().width / 2, 100)); + } + else if (layout == TDBookLayout::Landscape) + { _leftView = Node::create(); _leftView->setContentSize(bigSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftCover->setContentSize(bigSize); _leftView->addChild(_leftCover); - + auto winsize = Director::getInstance()->getWinSize(); - - - auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80/2, 0, (2560-80)/2, 1800/2)); + + auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); sp->setScale(2); sp->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sp->setPosition(Vec2(bigSize.width, 0)); _leftCover->addChild(sp); - - - auto leftBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(0, 0, 476/2, 1800)); - + auto leftBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(0, 0, 476 / 2, 1800)); + leftBinding->setPosition(Vec2(bigSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftCover->addChild(leftBinding); - - + auto wp1 = Scale9Sprite::create("Books/book_horizontal_inside_pagespread_1.png"); wp1->setPreferredSize(Size(bigSize.width, 1712)); wp1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); wp1->setPosition(Vec2(bigSize.width, 30)); _leftView->addChild(wp1); - + auto sd1 = Scale9Sprite::create("Books/book_vertical_middleshadow_left_1.png"); sd1->setPreferredSize(Size(85, 1692)); sd1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sd1->setPosition(Vec2(bigSize.width, 50)); _leftView->addChild(sd1); - - - - + _rightView = Node::create(); _rightView->setContentSize(bigSize); _rightView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_rightView); - - + _rightCover = Node::create(); _rightCover->setContentSize(bigSize); _rightView->addChild(_rightCover); - - - auto rsp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80/2, 0, (2560-80)/2, 1800/2)); + + auto rsp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); rsp->setScale(2); - rsp->setPosition(bigSize/2); + rsp->setPosition(bigSize / 2); _rightCover->addChild(rsp); - - auto rightBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(476/2, 0, 476/2, 1800)); + auto rightBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(476 / 2, 0, 476 / 2, 1800)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->addChild(rightBinding); - - auto wp2 = Scale9Sprite::create("Books/book_horizontal_inside_pagespread_1.png"); wp2->setPreferredSize(Size(bigSize.width, 1712)); wp2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); wp2->setPosition(Vec2(0, 30)); _rightView->addChild(wp2); - - + auto sd2 = Scale9Sprite::create("Books/book_vertical_middleshadow_right_1.png"); sd2->setPreferredSize(Size(85, 1692)); sd2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); sd2->setPosition(Vec2(0, 50)); _rightView->addChild(sd2); - - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); _imageView->setContentSize(Size(1820, 1274)); - _imageView->setPosition(Vec2(bigSize.width/2, 390)); + _imageView->setPosition(Vec2(bigSize.width / 2, 390)); _rightView->addChild(_imageView); - - + auto leftTexture = Sprite::create("Books/book_horizontal_inside_pagespread_texture.png"); leftTexture->setScale(2); leftTexture->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); leftTexture->setPosition(wp1->getPosition()); _leftView->addChild(leftTexture); - - - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(Size(2000, 300)); - + // what is the rationale behind doing this? this does not fix the issue... - _textView->setPosition(Vec2(_rightView->getContentSize().width/2, 280)); + _textView->setPosition(Vec2(_rightView->getContentSize().width / 2, 280)); _rightView->addChild(_textView); - + // adding pagespread texture after the textview is intentional - to give a feeling of embossing ; hard to notice though auto rightTexture = Sprite::create("Books/book_horizontal_inside_pagespread_texture.png"); rightTexture->setScale(2); rightTexture->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); rightTexture->setPosition(wp2->getPosition()); _rightView->addChild(rightTexture); - - - setPageNum(pageNum, _rightView, Vec2(_rightView->getContentSize().width/2,100)); - - - } else if (layout==TDBookLayout::Square) { - - - + + setPageNum(pageNum, _rightView, Vec2(_rightView->getContentSize().width / 2, 100)); + } + else if (layout == TDBookLayout::Square) + { + _leftView = Node::create(); _leftView->setContentSize(squareSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); - _leftView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _leftView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftView->addChild(_leftCover); - + auto cl = LayerColor::create(Color4B::WHITE, squareSize.width, squareSize.height); _leftView->addChild(cl); - - auto leftBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(0, 0, 171/2, 1520)); + + auto leftBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(0, 0, 171 / 2, 1520)); leftBinding->setPosition(Vec2(squareSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->addChild(leftBinding); - - - - + _rightView = Node::create(); _rightView->setContentSize(squareSize); - _rightView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _rightView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_rightView); - + _rightCover = Node::create(); _rightView->addChild(_rightCover); - - auto cr = LayerColor::create(Color4B::WHITE, squareSize.width, squareSize.height); _rightView->addChild(cr); - - auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171/2, 0, 171/2, 1520)); + + auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171 / 2, 0, 171 / 2, 1520)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightView->addChild(rightBinding); - - + _imageView = Node::create(); _imageView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _imageView->setContentSize(Size(1200, 1000)); - _imageView->setPosition(Vec2(squareSize.width/2, squareSize.height/2 + 120)); + _imageView->setPosition(Vec2(squareSize.width / 2, squareSize.height / 2 + 120)); _rightView->addChild(_imageView); - - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(Size(1200, 300)); - _textView->setPosition(Vec2(squareSize.width/2, 240)); + _textView->setPosition(Vec2(squareSize.width / 2, 240)); _rightView->addChild(_textView); - - setPageNum(pageNum, _rightView, Vec2(_contentsView->getContentSize().width/2, 100)); - - + setPageNum(pageNum, _rightView, Vec2(_contentsView->getContentSize().width / 2, 100)); } - - - - - //auto image = Sprite::create(_book->imagePrefix+pageObj.pageImageFilename); - auto image = Sprite::create(folder+"page/"+page->pageImageFilename); - if (!image) image = Sprite::create(folder+"page/"+page->pageImageFilename+".jpg"); - if (!image) image = Sprite::create(folder+"page/"+page->pageImageFilename+".png"); - if (image) { + // auto image = Sprite::create(_book->imagePrefix+pageObj.pageImageFilename); + auto image = Sprite::create(folder + "page/" + page->pageImageFilename); + if (!image) + image = Sprite::create(folder + "page/" + page->pageImageFilename + ".jpg"); + if (!image) + image = Sprite::create(folder + "page/" + page->pageImageFilename + ".png"); + if (image) + { auto imageSize = image->getContentSize(); auto viewSize = _imageView->getContentSize(); - auto scale = MIN(viewSize.width/imageSize.width, viewSize.height/imageSize.height); + auto scale = MIN(viewSize.width / imageSize.width, viewSize.height / imageSize.height); image->setScale(scale); - image->setPosition(viewSize/2); + image->setPosition(viewSize / 2); _imageView->addChild(image); } - - GameSoundManager::getInstance()->stopAllEffects(); - - - + _wordButtons.clear(); - + auto textViewSize = _textView->getContentSize(); - - + _words.clear(); - for (auto p : page->paragraphs) { - for (auto s : p.sentences) { - for (auto w : s.words) { + for (auto p : page->paragraphs) + { + for (auto s : p.sentences) + { + for (auto w : s.words) + { _words.push_back(w); } } } - + /* for (int i=0; iparagraphs[0].sentences.size(); i++) { TodoSentence s = page->paragraphs[0].sentences[i]; @@ -872,565 +838,517 @@ void BookPage::setPage(TodoBook *book, TodoPage *page, TDBookLayout layout, boo } } */ - - if (true) { + + if (true) + { auto text = createTextViewMultiLine(textViewSize, page->fontSize); _textView->addChild(text); - } else { + } + else + { auto text = createTextViewOneLine(textViewSize, page->fontSize); _textView->addChild(text); } - - - - - - - } void BookPage::setCreditPage() { - - auto getSentence = [this](int index){ + + auto getSentence = [this](int index) { string str; - - if (_page->paragraphs.size()>index) { + + if (_page->paragraphs.size() > index) + { auto p = _page->paragraphs.at(index); - - for (auto s : p.sentences) { - if (s.words.size()==0) continue; + + for (auto s : p.sentences) + { + if (s.words.size() == 0) + continue; auto w = s.words[0]; str += w.word + "\n"; } } return str; }; - - if (_bookLayout==TDBookLayout::Portrait || _bookLayout==TDBookLayout::Portrait_Traditional) { + if (_bookLayout == TDBookLayout::Portrait || _bookLayout == TDBookLayout::Portrait_Traditional) + { _leftView = Node::create(); _leftView->setContentSize(halfSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_leftView); - - if (_bookLayout==TDBookLayout::Portrait_Traditional) { + + if (_bookLayout == TDBookLayout::Portrait_Traditional) + { _leftCover = Node::create(); _leftCover->setContentSize(halfSize); _leftCover->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - + auto cv = Sprite::create("Books/portrait_traditional/koreanbook_cover.jpg", Rect(20, 00, 1280, 1800)); cv->setScale(-1, 1); - cv->setPosition(halfSize/2); + cv->setPosition(halfSize / 2); _leftCover->addChild(cv); - - } else { + } + else + { _leftCover = Sprite::create("Books/portrait/xprize_vertical_layout_cover_back.jpg", Rect(0, 0, 1280, 1800)); } - _leftCover->setPosition(halfSize/2); + _leftCover->setPosition(halfSize / 2); _leftView->addChild(_leftCover); - - - + _rightView = Node::create(); _rightView->setContentSize(halfSize); _rightView->setPosition(Vec2(halfSize.width, 0)); _contentsView->addChild(_rightView); - - if (_bookLayout==TDBookLayout::Portrait_Traditional) { + + if (_bookLayout == TDBookLayout::Portrait_Traditional) + { _rightCover = Node::create(); _rightCover->setContentSize(Size(20, 1800)); _rightCover->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - + auto cv = Sprite::create("Books/portrait_traditional/koreanbook_cover.jpg", Rect(0, 0, 20, 1800)); cv->setScale(-1, 1); - cv->setPosition(_rightCover->getContentSize()/2); + cv->setPosition(_rightCover->getContentSize() / 2); _rightCover->addChild(cv); - - } else { + } + else + { _rightCover = Sprite::create("Books/portrait/xprize_vertical_layout_cover_back.jpg", Rect(1280, 0, 20, 1800)); } - + _rightCover->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightView->addChild(_rightCover); - - - - - _imageView = Node::create(); _leftView->addChild(_imageView); - - + auto centerOffset = -30; - + auto textViewSize = Size(1110, 1500); _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(textViewSize); - _textView->setPosition(halfSize/2 + Size(centerOffset, 100)); - _leftView->addChild(_textView); - - - - + _textView->setPosition(halfSize / 2 + Size(centerOffset, 100)); + _leftView->addChild(_textView); + { string titleTxt = getSentence(0); - Label* label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); - if (_bookLayout==TDBookLayout::Portrait_Traditional) { + Label *label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); + if (_bookLayout == TDBookLayout::Portrait_Traditional) + { label->setTextColor(Color4B(77, 35, 20, 255)); - } else { + } + else + { label->setTextColor(Color4B(255, 249, 225, 255)); } label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - label->setPosition(textViewSize/2 + Size(0, 50)); + label->setPosition(textViewSize / 2 + Size(0, 50)); _textView->addChild(label); } - - + { string creditTxt = getSentence(1); - - Label* label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); + + Label *label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); label->setTextColor(Color4B(98, 61, 29, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(textViewSize/2); + label->setPosition(textViewSize / 2); _textView->addChild(label); } - + { string licenseTxt = getSentence(2); - + auto bottom = Label::createWithTTF(licenseTxt, titleFont, 25, Size(0, 0), TextHAlignment::CENTER, TextVAlignment::CENTER); bottom->setTextColor(Color4B(98, 61, 29, 255)); bottom->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - bottom->setPosition(Size(halfSize.width/2+centerOffset, 50)); + bottom->setPosition(Size(halfSize.width / 2 + centerOffset, 50)); _leftView->addChild(bottom); - + auto cc = Sprite::create("Books/cc_logo.png"); - cc->setPosition(Vec2(halfSize.width/2+centerOffset, bottom->getContentSize().height + 120)); + cc->setPosition(Vec2(halfSize.width / 2 + centerOffset, bottom->getContentSize().height + 120)); _leftView->addChild(cc); - + auto enuma = Label::createWithTTF("(c) 2015 Enuma, Inc.", titleFont, 30); enuma->setTextColor(Color4B(98, 61, 29, 255)); - enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height/2 + 40)); + enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height / 2 + 40)); _leftView->addChild(enuma); - } + } + else if (_bookLayout == TDBookLayout::Landscape) + { - - } else if (_bookLayout==TDBookLayout::Landscape) { - - _leftView = Node::create(); _leftView->setContentSize(bigSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftCover->setContentSize(bigSize); _leftView->addChild(_leftCover); - - - auto sp = Sprite::create("Books/book_horizontal_bg.jpg" , Rect(80/2, 0, (2560-80)/2, 1800/2)); + + auto sp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); sp->setScale(2); sp->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sp->setPosition(Vec2(bigSize.width, 0)); _leftCover->addChild(sp); - - - - auto leftBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(0, 0, 476/2, 1800)); + + auto leftBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(0, 0, 476 / 2, 1800)); leftBinding->setPosition(Vec2(bigSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftCover->addChild(leftBinding); - - + auto wp1 = Scale9Sprite::create("Books/book_horizontal_inside_pagespread_1.png"); wp1->setPreferredSize(Size(bigSize.width, 1712)); wp1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); wp1->setPosition(Vec2(bigSize.width, 30)); _leftView->addChild(wp1); - + auto sd1 = Scale9Sprite::create("Books/book_vertical_middleshadow_left_1.png"); sd1->setPreferredSize(Size(85, 1692)); sd1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); sd1->setPosition(Vec2(bigSize.width, 50)); _leftView->addChild(sd1); - - - + _rightView = Node::create(); _rightView->setContentSize(bigSize); _rightView->setPosition(Vec2(smallSize.width, 0)); _contentsView->addChild(_rightView); - + _rightCover = Node::create(); _rightView->addChild(_rightCover); - - auto rsp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80/2, 0, (2560-80)/2, 1800/2)); + + auto rsp = Sprite::create("Books/book_horizontal_bg.jpg", Rect(80 / 2, 0, (2560 - 80) / 2, 1800 / 2)); rsp->setScale(2); - rsp->setPosition(bigSize/2); + rsp->setPosition(bigSize / 2); _rightCover->addChild(rsp); - - - auto rightBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(476/2, 0, 476/2, 1800)); + + auto rightBinding = Sprite::create("Books/book_horizontal_inside_bookbinding.png", Rect(476 / 2, 0, 476 / 2, 1800)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightCover->addChild(rightBinding); - + auto textViewSize = Size(2000, 1200); - - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(textViewSize); - _textView->setPosition(defaultSize/2 + Size(0, 400)); + _textView->setPosition(defaultSize / 2 + Size(0, 400)); _rightView->addChild(_textView); - - - - { string titleTxt = getSentence(0); - Label* label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); + Label *label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); label->setTextColor(Color4B(255, 249, 225, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(Vec2(textViewSize.width/2, textViewSize.height - 450)); + label->setPosition(Vec2(textViewSize.width / 2, textViewSize.height - 450)); _textView->addChild(label); } - - + { string creditTxt = getSentence(1); - - Label* label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); + + Label *label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); label->setTextColor(Color4B(54, 28, 14, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(Vec2(textViewSize.width/2, textViewSize.height - 600)); + label->setPosition(Vec2(textViewSize.width / 2, textViewSize.height - 600)); _textView->addChild(label); } - + { string licenseTxt = getSentence(2); - + auto bottom = Label::createWithTTF(licenseTxt, titleFont, 25, Size(0, 0), TextHAlignment::CENTER, TextVAlignment::CENTER); bottom->setTextColor(Color4B(255, 249, 225, 255)); bottom->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - bottom->setPosition(Size(defaultSize.width/2, 50)); + bottom->setPosition(Size(defaultSize.width / 2, 50)); _rightView->addChild(bottom); - + auto cc = Sprite::create("Books/cc_logo.png"); - cc->setPosition(Vec2(defaultSize.width/2, bottom->getContentSize().height + 120)); + cc->setPosition(Vec2(defaultSize.width / 2, bottom->getContentSize().height + 120)); _rightView->addChild(cc); - + auto enuma = Label::createWithTTF("(c) 2015 Enuma, Inc.", titleFont, 30); enuma->setTextColor(Color4B(255, 249, 225, 255)); - enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height/2 + 40)); + enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height / 2 + 40)); _rightView->addChild(enuma); - } - - + } + else if (_bookLayout == TDBookLayout::Square) + { - } else if (_bookLayout==TDBookLayout::Square) { - - _leftView = Node::create(); _leftView->setContentSize(squareSize); _leftView->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); - _leftView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _leftView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_leftView); - + _leftCover = Node::create(); _leftView->addChild(_leftCover); - + auto cl = LayerColor::create(Color4B::WHITE, squareSize.width, squareSize.height); _leftView->addChild(cl); - - auto leftBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(0, 0, 171/2, 1520)); + + auto leftBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(0, 0, 171 / 2, 1520)); leftBinding->setPosition(Vec2(squareSize.width, 0)); leftBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT); _leftView->addChild(leftBinding); - - - _rightView = Node::create(); _rightView->setContentSize(squareSize); - _rightView->setPosition(Vec2(squareMiddle, defaultSize.height/2 - squareSize.height/2)); + _rightView->setPosition(Vec2(squareMiddle, defaultSize.height / 2 - squareSize.height / 2)); _contentsView->addChild(_rightView); - + _rightCover = Node::create(); _rightView->addChild(_rightCover); - - - + auto cr = LayerColor::create(Color4B::WHITE, squareSize.width, squareSize.height); _rightView->addChild(cr); - - auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171/2, 0, 171/2, 1520)); + + auto rightBinding = Sprite::create("Books/square/book_abc_insidespread_binding.png", Rect(171 / 2, 0, 171 / 2, 1520)); rightBinding->setPosition(Vec2(0, 0)); rightBinding->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _rightView->addChild(rightBinding); - - auto textViewSize = Size(1200, 1200); - - + _textView = Node::create(); _textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _textView->setContentSize(textViewSize); - _textView->setPosition(squareSize/2); + _textView->setPosition(squareSize / 2); _rightView->addChild(_textView); - - - - - + { string titleTxt = getSentence(0); - Label* label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); + Label *label = Label::createWithTTF(titleTxt, titleFont, 75, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); label->setTextColor(Color4B(255, 249, 225, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(Vec2(textViewSize.width/2, textViewSize.height - 450)); + label->setPosition(Vec2(textViewSize.width / 2, textViewSize.height - 450)); _textView->addChild(label); } - - + { string creditTxt = getSentence(1); - - Label* label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); + + Label *label = Label::createWithTTF(creditTxt, titleFont, 50, textViewSize, TextHAlignment::CENTER, TextVAlignment::TOP); label->setTextColor(Color4B(54, 28, 14, 255)); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); - label->setPosition(Vec2(textViewSize.width/2, textViewSize.height - 600)); + label->setPosition(Vec2(textViewSize.width / 2, textViewSize.height - 600)); _textView->addChild(label); } - + { string licenseTxt = getSentence(2); - + auto bottom = Label::createWithTTF(licenseTxt, titleFont, 25, Size(0, 0), TextHAlignment::CENTER, TextVAlignment::CENTER); bottom->setTextColor(Color4B(54, 28, 14, 255)); bottom->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - bottom->setPosition(Size(squareSize.width/2, 50)); + bottom->setPosition(Size(squareSize.width / 2, 50)); _rightView->addChild(bottom); - + auto cc = Sprite::create("Books/cc_logo.png"); - cc->setPosition(Vec2(squareSize.width/2, bottom->getContentSize().height + 120)); + cc->setPosition(Vec2(squareSize.width / 2, bottom->getContentSize().height + 120)); _rightView->addChild(cc); - + auto enuma = Label::createWithTTF("(c) 2015 Enuma, Inc.", titleFont, 30); enuma->setTextColor(Color4B(54, 28, 14, 255)); - enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height/2 + 40)); + enuma->setPosition(cc->getPosition() + Vec2(0, cc->getContentSize().height / 2 + 40)); _rightView->addChild(enuma); - } - - - } - - - - - } void BookPage::showRightHalf(bool animate) { - if (!animate) { + if (!animate) + { _rightView->setVisible(true); _rightCover->setVisible(true); - } else { + } + else + { _rightView->setVisible(true); _rightView->setScale(0, 1); _rightView->setSkewY(skewY); - if (!isTitlePage() && !isLastPage()) _rightCover->setVisible(false); - - - if (!isTitlePage() && !_hasBackCover && isLastPage()) _rightCover->setVisible(false); + if (!isTitlePage() && !isLastPage()) + _rightCover->setVisible(false); + + if (!isTitlePage() && !_hasBackCover && isLastPage()) + _rightCover->setVisible(false); auto ani = Spawn::create(EaseIn::create(ScaleTo::create(turnDuration, 1, 1), turnEase), EaseIn::create(SkewTo::create(turnDuration, 0, 0), turnEase), nullptr); _rightView->runAction(Sequence::create(ani, - CallFunc::create([this](){ _rightCover->setVisible(true); }), nullptr)); + CallFunc::create([this]() { _rightCover->setVisible(true); }), nullptr)); } } void BookPage::showLeftHalf(bool animate) { - if (!animate) { + if (!animate) + { _leftView->setVisible(true); _leftCover->setVisible(true); - } else { + } + else + { _leftView->setVisible(true); _leftView->setScale(0, 1); _leftView->setSkewY(-skewY); - - if (!isFirstPage() && !isCreditPage()) _leftCover->setVisible(false); - if (!_hasBackCover && isCreditPage()) _leftCover->setVisible(false); + + if (!isFirstPage() && !isCreditPage()) + _leftCover->setVisible(false); + if (!_hasBackCover && isCreditPage()) + _leftCover->setVisible(false); auto ani = Spawn::create(EaseIn::create(ScaleTo::create(turnDuration, 1, 1), turnEase), EaseIn::create(SkewTo::create(turnDuration, 0, 0), turnEase), nullptr); _leftView->runAction(Sequence::create(ani, - CallFunc::create([this](){ _leftCover->setVisible(true); }), nullptr)); - + CallFunc::create([this]() { _leftCover->setVisible(true); }), nullptr)); } - } void BookPage::hideRightHalf(bool animate) { - if (!animate) { + if (!animate) + { _rightView->setVisible(false); - } else { + } + else + { _rightView->setScale(1, 1); - if (!isTitlePage() && !isLastPage()) _rightCover->setVisible(false); - if (!isTitlePage() && !_hasBackCover && isLastPage()) _rightCover->setVisible(false); + if (!isTitlePage() && !isLastPage()) + _rightCover->setVisible(false); + if (!isTitlePage() && !_hasBackCover && isLastPage()) + _rightCover->setVisible(false); auto ani = Spawn::create(EaseOut::create(ScaleTo::create(turnDuration, 0, 1), turnEase), EaseOut::create(SkewTo::create(turnDuration, 0, skewY), turnEase), nullptr); _rightView->runAction(Sequence::create(ani, - CallFunc::create([this](){_rightView->setVisible(false);}), - nullptr)); + CallFunc::create([this]() { _rightView->setVisible(false); }), + nullptr)); } } void BookPage::hideLeftHalf(bool animate) { - if (!animate) { + if (!animate) + { _leftView->setVisible(false); - } else { + } + else + { _leftView->setScale(1, 1); - if (!isFirstPage() && !isCreditPage()) _leftCover->setVisible(false); - if (!_hasBackCover && isCreditPage()) _leftCover->setVisible(false); + if (!isFirstPage() && !isCreditPage()) + _leftCover->setVisible(false); + if (!_hasBackCover && isCreditPage()) + _leftCover->setVisible(false); auto ani = Spawn::create(EaseOut::create(ScaleTo::create(turnDuration, 0, 1), turnEase), EaseOut::create(SkewTo::create(turnDuration, 0, -skewY), turnEase), nullptr); _leftView->runAction(Sequence::create(ani, - CallFunc::create([this](){_leftView->setVisible(false);}), + CallFunc::create([this]() { _leftView->setVisible(false); }), nullptr)); } } -void BookPage::playWordSound(ui::Button *button, string path, float length) +void BookPage::playWordSound(ui::Button *button) { - //GameSoundManager::getInstance()->pauseEffect(_readingAudioID); - GameSoundManager::getInstance()->pauseBGM(); - - - GameSoundManager::getInstance()->playEffectSound(path); - - if (_isReading) { - + tag = button->getTag(); + if (_isReading) + { button->resetNormalRender(); button->loadTextureNormal("Common/lightblue.png"); SHOW_SL_VIDEO_IF_ENABLED("common/temp_video_short.mp4"); - _pauseReading = true; - _pauseLength = length; } - } - -Node* BookPage::createTextViewOneLine(Size size, float fontSize) +Node *BookPage::createTextViewOneLine(Size size, float fontSize) { - + auto tempTextView = Node::create(); tempTextView->setContentSize(size); - - float pageFontSize = (fontSize>0) ? fontSize : size.height-5; + + float pageFontSize = (fontSize > 0) ? fontSize : size.height - 5; float currentX = 0.0; - - for (int i=0; i<_words.size(); i++) { + + for (int i = 0; i < _words.size(); i++) + { auto word = _words[i]; auto wordButton = Button::create(); - wordButton->setAnchorPoint(Vec2::ANCHOR_MIDDLE); wordButton->setTag(i); wordButton->setTitleFontSize(pageFontSize); wordButton->setTitleFontName(bodyFont); wordButton->setTitleText(word.word); wordButton->setTitleColor(textColor); - - + auto buttonSize = wordButton->getContentSize(); - - wordButton->setPosition(Vec2(currentX+buttonSize.width/2, size.height/2)); - currentX += buttonSize.width + pageFontSize/2; - - if (_withAudio) { + + wordButton->setPosition(Vec2(currentX + buttonSize.width / 2, size.height / 2)); + currentX += buttonSize.width + pageFontSize / 2; + + if (_withAudio) + { auto wordAudioPath = _book->getWordAudioPath(word.wordAudioFilename); - GameSoundManager::getInstance()->preloadEffect(wordAudioPath); - wordButton->addClickEventListener([this, word, wordAudioPath, wordButton](Ref*){ - this->playWordSound(wordButton, wordAudioPath, word.wordAudioLength); + VoiceMoldManager::shared()->speak(word.word); + wordButton->addClickEventListener([this, word, wordAudioPath, wordButton](Ref *) { + this->playWordSound(wordButton); }); } - - + tempTextView->addChild(wordButton); _wordButtons.push_back(wordButton); } - - - Size tempTextViewSize = Size(currentX-pageFontSize, size.height); + + Size tempTextViewSize = Size(currentX - pageFontSize, size.height); tempTextView->setContentSize(tempTextViewSize); tempTextView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - tempTextView->setPosition(size/2); - - float textScale = MIN(1.0, size.width/tempTextViewSize.width); + tempTextView->setPosition(size / 2); + + float textScale = MIN(1.0, size.width / tempTextViewSize.width); tempTextView->setScale(textScale); - + return tempTextView; } - -Node* BookPage::createTextViewMultiLine(Size size, float fontSize) +Node *BookPage::createTextViewMultiLine(Size size, float fontSize) { - auto innerTextView = Node::create(); - - auto pageFontSize = (fontSize>0) ? fontSize : 80; - + + auto pageFontSize = (fontSize > 0) ? fontSize : 80; + // (s) one-pass Size viewSize = size; - + float maxWidth = 0.f; float minBottom = 0.f; - + float currentLeft = 0.f; float currentTop = 0.f; - + int wordIndex = 0; - + float paragraphSpace = pageFontSize; - float lineSpace = pageFontSize*1.5; - float indentSpace = pageFontSize*0.5; - float wordSpace = pageFontSize*0.5; - - + float lineSpace = pageFontSize * 1.5; + float indentSpace = pageFontSize * 0.5; + float wordSpace = pageFontSize * 0.5; + bool wordWrap = _page->wordwrap; - - - - bool indentation = wordWrap || (_page->paragraphs.size()>1); + + bool indentation = wordWrap || (_page->paragraphs.size() > 1); bool finalPass = !wordWrap; - + bool firstInLine; - - - + auto createWordButton = [&](string word) { - auto wordButton = Button::create(); wordButton->setTag(wordIndex++); wordButton->setTouchEnabled(_withAudio); @@ -1440,235 +1358,226 @@ Node* BookPage::createTextViewMultiLine(Size size, float fontSize) wordButton->setTitleText(word); wordButton->setTitleColor(textColor); return wordButton; - }; - - auto addAudioHandler = [&](Button* button, string path, float length) { - GameSoundManager::getInstance()->preloadEffect(path); - button->addClickEventListener([this, path, button, length](Ref*){ - - playWordSound(button, path, length); - + + auto addAudioHandler = [&](Button *button) { + button->addClickEventListener([this, button](Ref *) { + playWordSound(button); }); }; - + bool singleLine = true; - - + for (int i = 0; i < _page->paragraphs.size(); i++) { auto paragraph = _page->paragraphs[i]; - + // it appears that the auto identation causes the skewing problem when the sentence is short, but we can't just disable it currentLeft = indentation ? indentSpace : 0; // auto indentation - if (i > 0) currentTop -= paragraphSpace; // paragraph spacing - + if (i > 0) + currentTop -= paragraphSpace; // paragraph spacing + firstInLine = true; - for (int j = 0; j < paragraph.sentences.size(); j++) { auto sentence = paragraph.sentences[j]; - + for (int k = 0; k < sentence.words.size(); k++) { auto word = sentence.words[k]; auto wordButton = createWordButton(word.word); auto buttonSize = wordButton->getContentSize(); - if (wordWrap && (currentLeft + wordSpace + buttonSize.width > viewSize.width)) { // do wordwrapping + if (wordWrap && (currentLeft + wordSpace + buttonSize.width > viewSize.width)) + { // do wordwrapping currentLeft = 0; currentTop -= lineSpace; firstInLine = true; singleLine = false; - } else { + } + else + { currentLeft += firstInLine ? 0 : wordSpace; } - - if (finalPass) { + + if (finalPass) + { wordButton->setPosition(Vec2(currentLeft, currentTop)); innerTextView->addChild(wordButton); - - if (_withAudio) { + + if (_withAudio) + { auto wordAudioPath = _book->getWordAudioPath(word.wordAudioFilename); - addAudioHandler(wordButton, wordAudioPath, word.wordAudioLength); + addAudioHandler(wordButton); _wordButtons.push_back(wordButton); } } - + firstInLine = false; currentLeft += buttonSize.width; - minBottom = MIN(minBottom, (currentTop-buttonSize.height)); + minBottom = MIN(minBottom, (currentTop - buttonSize.height)); maxWidth = MAX(maxWidth, currentLeft); - } - - if (!wordWrap) { // force next line if no wordwrap + + if (!wordWrap) + { // force next line if no wordwrap currentLeft = 0; currentTop -= lineSpace; firstInLine = true; } } - - if (wordWrap) { + + if (wordWrap) + { currentLeft = 0; currentTop -= lineSpace; firstInLine = true; } } // (e) one-pass - - - if (finalPass) { + + if (finalPass) + { auto textView = Node::create(); textView->setContentSize(Size(maxWidth, -minBottom)); innerTextView->setPosition(Vec2(0, -minBottom)); textView->addChild(innerTextView); textView->setScale(MIN(1.f, size.width / maxWidth)); textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - textView->setPosition(size/2); + textView->setPosition(size / 2); return textView; } - - - + // (s) two-pass - + auto sampleHeight = -minBottom; - - auto pageScale = MAX(1.f, sqrt(sampleHeight/size.height)); - viewSize = Size(size.width*pageScale, sampleHeight); + auto pageScale = MAX(1.f, sqrt(sampleHeight / size.height)); + + viewSize = Size(size.width * pageScale, sampleHeight); finalPass = true; - + currentLeft = 0.f; currentTop = viewSize.height; - + maxWidth = 0.f; minBottom = currentTop; - - wordIndex = 0; - - for (int i = 0; i < _page->paragraphs.size(); i++) { auto paragraph = _page->paragraphs[i]; - + currentLeft = indentation ? indentSpace : 0; // auto indentation - if (singleLine) currentLeft = 0; - if (i > 0) currentTop -= paragraphSpace; // paragraph spacing - + if (singleLine) + currentLeft = 0; + if (i > 0) + currentTop -= paragraphSpace; // paragraph spacing + firstInLine = true; - - + for (int j = 0; j < paragraph.sentences.size(); j++) { auto sentence = paragraph.sentences[j]; - + for (int k = 0; k < sentence.words.size(); k++) { - + auto word = sentence.words[k]; - + auto wordButton = createWordButton(word.word); - - + auto buttonSize = wordButton->getContentSize(); - if (wordWrap && (currentLeft + wordSpace + buttonSize.width > viewSize.width)) { // do wordwrapping - + if (wordWrap && (currentLeft + wordSpace + buttonSize.width > viewSize.width)) + { // do wordwrapping + currentLeft = 0; currentTop -= lineSpace; firstInLine = true; - - - } else { + } + else + { currentLeft += firstInLine ? 0 : wordSpace; } - - if (finalPass) { + + if (finalPass) + { wordButton->setPosition(Vec2(currentLeft, currentTop)); innerTextView->addChild(wordButton); - - if (_withAudio) { + + if (_withAudio) + { auto wordAudioPath = _book->getWordAudioPath(word.wordAudioFilename); - GameSoundManager::getInstance()->preloadEffect(wordAudioPath); - addAudioHandler(wordButton, wordAudioPath, word.wordAudioLength); - - _wordButtons.push_back(wordButton); + addAudioHandler(wordButton); - + _wordButtons.push_back(wordButton); } - } - + firstInLine = false; currentLeft += buttonSize.width; - minBottom = MIN(minBottom, (currentTop-buttonSize.height)); + minBottom = MIN(minBottom, (currentTop - buttonSize.height)); maxWidth = MAX(maxWidth, currentLeft); - } - - if (!wordWrap) { // force next line if no wordwrap + + if (!wordWrap) + { // force next line if no wordwrap currentLeft = 0; currentTop -= lineSpace; firstInLine = true; } } - - if (wordWrap) { + + if (wordWrap) + { currentLeft = 0; currentTop -= lineSpace; firstInLine = true; } } - + { auto textView = Node::create(); - viewSize = Size(maxWidth, viewSize.height-minBottom); + viewSize = Size(maxWidth, viewSize.height - minBottom); textView->setContentSize(viewSize); - + // to check textview size - if (DebugLayout) { + if (DebugLayout) + { auto lc = LayerColor::create(Color4B::YELLOW, viewSize.width, viewSize.height); textView->addChild(lc); } - + innerTextView->setPosition(Vec2(0, -minBottom)); textView->addChild(innerTextView); textView->setScale(MIN(1.f, MIN(size.width / viewSize.width, size.height / viewSize.height))); textView->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - textView->setPosition(size/2); + textView->setPosition(size / 2); return textView; } - } void BookPage::setPageNum(int page, Node *_pageView, Vec2 pos) { - Label* pagelabel = Label::create(); + Label *pagelabel = Label::create(); pagelabel->setSystemFontSize(40); pagelabel->setTextColor(Color4B::BLACK); pagelabel->setString(TodoUtil::itos(page)); pagelabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); pagelabel->setPosition(pos); - - if (DebugLayout) { + + if (DebugLayout) + { auto line = DrawNode::create(); auto pageSize = _pageView->getContentSize(); line->setContentSize(pageSize); _pageView->addChild(line); - - line->drawLine(Vec2(0, pos.y+10), Vec2(pageSize.width, pos.y+10), Color4F::BLUE); - line->drawLine(Vec2(pageSize.width/2, pos.y), Vec2(pageSize.width/2, pos.y+20), Color4F::BLUE); - - - - - + + line->drawLine(Vec2(0, pos.y + 10), Vec2(pageSize.width, pos.y + 10), Color4F::BLUE); + line->drawLine(Vec2(pageSize.width / 2, pos.y), Vec2(pageSize.width / 2, pos.y + 20), Color4F::BLUE); } - + _pageView->addChild(pagelabel); } diff --git a/mainapp/Classes/Games/Books/BookPage.hpp b/mainapp/Classes/Games/Books/BookPage.hpp index e33e4880f..b04966757 100644 --- a/mainapp/Classes/Games/Books/BookPage.hpp +++ b/mainapp/Classes/Games/Books/BookPage.hpp @@ -15,91 +15,69 @@ #include "ui/CocosGUI.h" #include "TodoBook.hpp" - USING_NS_CC; - - class BookPage : public Node { public: - - static BookPage* create(); + static BookPage *create(); virtual bool init() override; virtual void onExit() override; virtual void update(float delta) override; void highlightWordButton(ui::Button *btn, bool highlight); void startReading(); void stopReading(); - + void setTitle(string title, string titleImagePath, string audioPath, TDBookLayout layout, float delay); void setPage(TodoBook *book, TodoPage *page, TDBookLayout layout, bool withAudio); void setCreditPage(); void setPageNum(int page, Node *_pageView, Vec2 pos); - - - + void showRightHalf(bool animate); void showLeftHalf(bool animate); - + void hideRightHalf(bool animate); void hideLeftHalf(bool animate); - - - - - -protected: - +protected: bool isFirstPage() { return _page->pageNum == 1; } bool isLastPage() { return _page->lastPage; } bool isCreditPage() { return _page->creditPage; } bool isTitlePage() { return _isTitle; } - void playWordSound(ui::Button *button, string path, float length); - Node* createTextViewOneLine(Size size, float fontSize); - Node* createTextViewMultiLine(Size size, float fontSize); - - + void playWordSound(ui::Button *button); + Node *createTextViewOneLine(Size size, float fontSize); + Node *createTextViewMultiLine(Size size, float fontSize); + Node *_leftView, *_rightView; Node *_leftCover, *_rightCover; - + Node *_contentsView; - Node *_imageView; Node *_textView; - - - - std::vector _wordButtons; + std::vector _wordButtons; std::vector _words; - + TodoBook *_book; TodoPage *_page; - + //string _resourceFolder; int _readingSentenceIndex; //int _readingAudioID; -> change as BGM - + bool _isTitle; string _titleAudioPath; - - + bool _hasBackCover; TDBookLayout _bookLayout; bool _withAudio; float _timePage, _timeSentence; bool _isReading; - + bool _pauseReading; float _pauseLength; - - - }; - #endif /* BookPage_hpp */ diff --git a/mainapp/Classes/Games/Books/TodoBook.cpp b/mainapp/Classes/Games/Books/TodoBook.cpp index e5abd684d..e1b4033de 100644 --- a/mainapp/Classes/Games/Books/TodoBook.cpp +++ b/mainapp/Classes/Games/Books/TodoBook.cpp @@ -114,7 +114,7 @@ void TodoBook::readData(string &filedata) sentence.sentenceAudioFilename = row[1]; sentence.startTimingInPage = TodoUtil::stod(row[2]); } - + currentParagraph.sentences.push_back(sentence); } else if (type == "word") diff --git a/mainapp/Classes/Games/Books/TodoBook.hpp b/mainapp/Classes/Games/Books/TodoBook.hpp index e47240379..50d0296dd 100644 --- a/mainapp/Classes/Games/Books/TodoBook.hpp +++ b/mainapp/Classes/Games/Books/TodoBook.hpp @@ -68,7 +68,6 @@ class TodoPage bool wordwrap; bool creditPage; bool lastPage; - float fontSize; }; diff --git a/mainapp/Classes/Managers/VoiceMoldManager.cpp b/mainapp/Classes/Managers/VoiceMoldManager.cpp index 99ba873a0..46ce3827c 100644 --- a/mainapp/Classes/Managers/VoiceMoldManager.cpp +++ b/mainapp/Classes/Managers/VoiceMoldManager.cpp @@ -28,10 +28,10 @@ std::string VoiceMoldManager::getDefaultLocale(std::string locale) t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(jLocale); - + return locale; } - + return ""; } @@ -143,10 +143,10 @@ float VoiceMoldManager::guessSpeakDuration(std::string text) float rv = t.env->CallStaticFloatMethod(t.classID, t.methodID, jText); t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(jText); - + return rv; } - + return std::numeric_limits::quiet_NaN(); } @@ -163,21 +163,21 @@ float VoiceMoldManager::guessSpeakDuration(std::string text, std::string locale) t.env->DeleteLocalRef(t.classID); t.env->DeleteLocalRef(jText); t.env->DeleteLocalRef(jLocale); - + return rv; } - + return std::numeric_limits::quiet_NaN(); } -VoiceMoldManager* VoiceMoldManager::shared() +VoiceMoldManager *VoiceMoldManager::shared() { - static VoiceMoldManager* _shared = nullptr; - if (!_shared) { + static VoiceMoldManager *_shared = nullptr; + if (!_shared) + { _shared = new VoiceMoldManager(); } return _shared; - } #endif diff --git a/mainapp/Classes/Managers/VoiceMoldManager.h b/mainapp/Classes/Managers/VoiceMoldManager.h index 2c6f0eb05..0756ba42e 100644 --- a/mainapp/Classes/Managers/VoiceMoldManager.h +++ b/mainapp/Classes/Managers/VoiceMoldManager.h @@ -6,7 +6,6 @@ #include - class VoiceMoldManager { public: @@ -30,8 +29,8 @@ class VoiceMoldManager float guessSpeakDuration(std::string text, std::string locale); public: - static VoiceMoldManager* shared(); - + static VoiceMoldManager *shared(); + #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) private: std::string _internalLocaleForMock; diff --git a/mainapp/proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java b/mainapp/proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java index c3011c151..cfad76485 100644 --- a/mainapp/proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java +++ b/mainapp/proj.android-studio/app/src/org/cocos2dx/cpp/AppActivity.java @@ -24,6 +24,7 @@ of this software and associated documentation files (the "Software"), to deal package org.cocos2dx.cpp; import android.Manifest; +import android.app.Activity; import android.app.ActivityManager; import android.app.AlarmManager; import android.app.PendingIntent; diff --git a/mainapp/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMold.java b/mainapp/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMold.java old mode 100755 new mode 100644 index 4e4b21982..279eaa2a9 --- a/mainapp/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMold.java +++ b/mainapp/proj.android-studio/app/src/org/cocos2dx/cpp/VoiceMold.java @@ -64,6 +64,8 @@ public void speak(String text) { } wrapper.getTts().speak(text, TextToSpeech.QUEUE_FLUSH, createParamsForSpeak()); + while (wrapper.getTts().isSpeaking()) { + } } public void warmup() {