add play ui

This commit is contained in:
chuanweizhang2013 2014-05-22 11:51:56 +08:00
parent 1aa92bdef0
commit 111840f37b
10 changed files with 2750 additions and 2652 deletions

File diff suppressed because it is too large Load Diff

View File

@ -51,6 +51,13 @@ void ConfigParser::readConfig()
{ {
_initViewSize.width = objectInitView["width"].GetUint(); _initViewSize.width = objectInitView["width"].GetUint();
_initViewSize.height = objectInitView["height"].GetUint(); _initViewSize.height = objectInitView["height"].GetUint();
if (_initViewSize.height>_initViewSize.width)
{
float tmpvalue =_initViewSize.height;
_initViewSize.height = _initViewSize.width;
_initViewSize.width = tmpvalue;
}
} }
if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) if (objectInitView.HasMember("name") && objectInitView["name"].IsString())
{ {

View File

@ -99,50 +99,113 @@ bool reloadScript(const string& modulefile)
class ConnectWaitLayer: public Layer class ConnectWaitLayer: public Layer
{ {
private: private:
LabelTTF* pLabelUploadFile; Label* _labelUploadFile;
public: public:
ConnectWaitLayer() ConnectWaitLayer()
{ {
int designWidth = 1280;
int designHeight = 800;
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designWidth,designHeight,ResolutionPolicy::EXACT_FIT);
string playEnbleFile = "res/debug/Play1.png";
string shineFile = "res/debug/shine.png";
string backgroundFile = "res/debug/landscape.png";
if (!ConfigParser::getInstance()->isLanscape())
{
backgroundFile = "res/debug/portrait.png";
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designHeight,designWidth,ResolutionPolicy::EXACT_FIT);
}
auto background = Sprite::create(backgroundFile.c_str());
if (background)
{
background->setAnchorPoint(Vec2(0,0));
addChild(background,9999);
}
auto playSprite = Sprite::create(playEnbleFile.c_str());
if (playSprite)
{
playSprite->setPosition(Vec2(902,400));
addChild(playSprite,9999);
}else
{
auto labelPlay = LabelTTF::create("play", "Arial", 108);
auto menuItem = MenuItemLabel::create(labelPlay, CC_CALLBACK_1(ConnectWaitLayer::playerCallback, this));
auto menu = Menu::create(menuItem, NULL);
menu->setPosition( Point::ZERO );
menuItem->setPosition(Vec2(902,400));
if (!ConfigParser::getInstance()->isLanscape()) menuItem->setPosition(Vec2(400,500));
addChild(menu, 1);
}
auto shineSprite = Sprite::create(shineFile.c_str());
if (shineSprite)
{
shineSprite->setPosition(Vec2(902,400));
shineSprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(ScaleBy::create(1.0f, 1.08f),ScaleTo::create(1.0f, 1))));
addChild(shineSprite,9999);
}
string strip = getIPAddress(); string strip = getIPAddress();
char szIPAddress[512]={0}; char szIPAddress[512]={0};
sprintf(szIPAddress, "LocalIP: %s",strip.c_str()); sprintf(szIPAddress, "LocalIP: %s",strip.c_str());
auto label = LabelTTF::create(szIPAddress, "Arial", 24); auto IPlabel = Label::create(szIPAddress, "Arial", 36);
addChild(label, 9999); IPlabel->setAnchorPoint(Vec2(0,0));
label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) ); int spaceSize = 72;
IPlabel->setPosition( Point(VisibleRect::leftTop().x+spaceSize, VisibleRect::top().y -spaceSize) );
string strShowMsg =""; addChild(IPlabel, 9999);
string strShowMsg = "waiting for file transfer ...";
if (CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM || CC_PLATFORM_MAC == CC_TARGET_PLATFORM) if (CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM || CC_PLATFORM_MAC == CC_TARGET_PLATFORM)
{ {
strShowMsg = "waiting for debugger to connect ..."; strShowMsg = "waiting for debugger to connect ...";
}else }
_labelUploadFile = Label::create(strShowMsg.c_str(), "Arial", 24);
_labelUploadFile->setAnchorPoint(Vec2(0,0));
_labelUploadFile->setPosition( Point(VisibleRect::leftTop().x+spaceSize, IPlabel->getPositionY()-spaceSize) );
_labelUploadFile->setAlignment(TextHAlignment::LEFT);
addChild(_labelUploadFile, 10000);
if (!ConfigParser::getInstance()->isLanscape())
{ {
strShowMsg = "waiting for file transfer ..."; if (playSprite) playSprite->setPosition(400,500);
} if (shineSprite) shineSprite->setPosition(400,500);
auto labelwait = LabelTTF::create(strShowMsg.c_str(), "Arial", 22); _labelUploadFile->setAlignment(TextHAlignment::LEFT);
addChild(labelwait, 10000); }
labelwait->setPosition( Point(VisibleRect::center().x, VisibleRect::center().y) );
pLabelUploadFile = LabelTTF::create("", "Arial", 22); if (playSprite)
addChild(pLabelUploadFile, 10000); {
pLabelUploadFile->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 60) ); auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch* touch, Event *event)->bool{
auto labelPlay = LabelTTF::create("play", "Arial", 36); auto target = static_cast<Sprite*>(event->getCurrentTarget());
auto menuItem = MenuItemLabel::create(labelPlay, CC_CALLBACK_1(ConnectWaitLayer::playerCallback, this)); Vec2 point = target->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView()));
auto menu = Menu::create(menuItem, NULL); auto rect = Rect(0, 0, target->getContentSize().width, target->getContentSize().height);
if (!rect.containsPoint(point)) return false;
target->stopAllActions();
target->runAction(Sequence::createWithTwoActions(ScaleBy::create(0.05f, 0.9f),ScaleTo::create(0.125f, 1)));
return true;
};
listener->onTouchEnded = [](Touch* touch, Event *event){
auto target = static_cast<Sprite*>(event->getCurrentTarget());
Vec2 point = target->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView()));
auto rect = Rect(0, 0, target->getContentSize().width, target->getContentSize().height);
if (!rect.containsPoint(point)) return;
startScript("");
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, playSprite);
}
menu->setPosition( Point::ZERO );
menuItem->setPosition( Point( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) );
addChild(menu, 1);
} }
void playerCallback(Object* sender) void playerCallback(Object* sender)
{ {
startScript(""); startScript("");
} }
void showCurRcvFile(string fileName) { void showCurRcvFile(string fileName) {
pLabelUploadFile->setString(fileName); _labelUploadFile->setString(fileName);
} }
}; };

View File

@ -98,16 +98,16 @@ std::string getCurAppPath(void)
return; return;
} }
if(!g_landscape)
{
float tmpvalue =width;
width = height;
height = tmpvalue;
}
g_eglView = GLView::createWithRect([viewName cStringUsingEncoding:NSUTF8StringEncoding],cocos2d::Rect(0.0f,0.0f,width,height),frameZoomFactor); g_eglView = GLView::createWithRect([viewName cStringUsingEncoding:NSUTF8StringEncoding],cocos2d::Rect(0.0f,0.0f,width,height),frameZoomFactor);
auto director = Director::getInstance(); auto director = Director::getInstance();
director->setOpenGLView(g_eglView); director->setOpenGLView(g_eglView);
g_landscape = false;
g_screenSize.width = width;
g_screenSize.height = height;
if (width > height)
{
g_landscape = true;
}
window = glfwGetCocoaWindow(g_eglView->getWindow()); window = glfwGetCocoaWindow(g_eglView->getWindow());
[NSApp setDelegate: self]; [NSApp setDelegate: self];
@ -124,12 +124,15 @@ void createSimulator(const char* viewName, float width, float height,bool isLand
{ {
if(g_nsAppDelegate) if(g_nsAppDelegate)
{ {
if((isLandscape && height > width) || (!isLandscape && width > height)) g_landscape = isLandscape;
if(height > width)
{ {
float tmpvalue =width; float tmpvalue =width;
width = height; width = height;
height = tmpvalue; height = tmpvalue;
} }
g_screenSize.width = width;
g_screenSize.height = height;
[g_nsAppDelegate createSimulator:[NSString stringWithUTF8String:viewName] viewWidth:width viewHeight:height factor:frameZoomFactor]; [g_nsAppDelegate createSimulator:[NSString stringWithUTF8String:viewName] viewWidth:width viewHeight:height factor:frameZoomFactor];
} }

View File

@ -308,23 +308,26 @@ void createSimulator(const char* viewName, float width, float height, bool isLan
return; return;
} }
if((isLandscape && height > width) || (!isLandscape && width > height)) g_landscape = isLandscape;
if(height > width)
{ {
float tmpvalue =width; float tmpvalue =width;
width = height; width = height;
height = tmpvalue; height = tmpvalue;
} }
g_screenSize.width = width;
g_screenSize.height = height;
if(!g_landscape)
{
float tmpvalue =width;
width = height;
height = tmpvalue;
}
g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor); g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor);
auto director = Director::getInstance(); auto director = Director::getInstance();
director->setOpenGLView(g_eglView); director->setOpenGLView(g_eglView);
g_landscape = false;
g_screenSize.width = width;
g_screenSize.height = height;
if (width > height)
{
g_landscape = true;
}
HWND hWnd=glfwGetWin32Window(g_eglView->getWindow()); HWND hWnd=glfwGetWin32Window(g_eglView->getWindow());
HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU_COCOS)); HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU_COCOS));

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB