Ejemplo n.º 1
0
StarPhysicsNode::StarPhysicsNode(const char* f, CCPoint p, AroundMeLayer* layer)
        : PhysicsNode(layer) {
    m_image = QString(f);
    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.position.Set(p.x / PTM_RATIO, p.y / PTM_RATIO);
    bd.userData = this;
    b2Body *body = m_world->CreateBody(&bd);
    b2Vec2 vertices[3];

    {
        b2PolygonShape triangle;
        vertices[0] = b2Vec2(-3.0f, 0.78f);
        vertices[1] = b2Vec2(-1.98f, -0.84f);
        vertices[2] = b2Vec2(-1.2f, 1.56f);
        triangle.Set(vertices, 3);
        b2FixtureDef fixtureDef;
        fixtureDef.shape = ▵
        fixtureDef.density = 1.0f;
        fixtureDef.restitution = 0.5;
        fixtureDef.friction = 0.3f;
        fixtureDef.filter.categoryBits = CHEERIOS;
        body->CreateFixture(&fixtureDef);
    }
    {
        b2PolygonShape triangle;
        vertices[0] = b2Vec2(-1.2f, 1.56f);
        vertices[1] = b2Vec2(1.2f, 1.56f);
        vertices[2] = b2Vec2(0.0f, 3.0f);
        triangle.Set(vertices, 3);
        b2FixtureDef fixtureDef;
        fixtureDef.shape = ▵
        fixtureDef.density = 1.0f;
        fixtureDef.restitution = 0.5;
        fixtureDef.friction = 0.3f;
        fixtureDef.filter.categoryBits = CHEERIOS;
        body->CreateFixture(&fixtureDef);
    }
    {
        b2PolygonShape triangle;
        vertices[0] = b2Vec2(1.2f, 1.56f);
        vertices[1] = b2Vec2(1.98f, -0.84f);
        vertices[2] = b2Vec2(3.0f, 0.78f);
        triangle.Set(vertices, 3);
        b2FixtureDef fixtureDef;
        fixtureDef.shape = ▵
        fixtureDef.density = 1.0f;
        fixtureDef.restitution = 0.5;
        fixtureDef.friction = 0.3f;
        fixtureDef.filter.categoryBits = CHEERIOS;
        body->CreateFixture(&fixtureDef);
    }
    {
        b2PolygonShape triangle;
        vertices[0] = b2Vec2(1.98f, -0.84f);
        vertices[1] = b2Vec2(0.0f, -2.22f);
        vertices[2] = b2Vec2(1.8f, -3.0f);
        triangle.Set(vertices, 3);
        b2FixtureDef fixtureDef;
        fixtureDef.shape = ▵
        fixtureDef.density = 1.0f;
        fixtureDef.restitution = 0.5;
        fixtureDef.friction = 0.3f;
        fixtureDef.filter.categoryBits = CHEERIOS;
        body->CreateFixture(&fixtureDef);
    }
    {
        b2PolygonShape triangle;
        vertices[0] = b2Vec2(0.0f, -2.22f);
        vertices[1] = b2Vec2(-1.98f, -0.84f);
        vertices[2] = b2Vec2(-1.8f, -3.0f);
        triangle.Set(vertices, 3);
        b2FixtureDef fixtureDef;
        fixtureDef.shape = ▵
        fixtureDef.density = 1.0f;
        fixtureDef.restitution = 0.5;
        fixtureDef.friction = 0.3f;
        fixtureDef.filter.categoryBits = CHEERIOS;
        body->CreateFixture(&fixtureDef);
    }
    {
        b2Vec2 vertices[5];
        b2PolygonShape pentagon;
        vertices[0] = b2Vec2(-1.98f, -0.84f);
        vertices[1] = b2Vec2(0.0f, -2.22f);
        vertices[2] = b2Vec2(1.98f, -0.84f);
        vertices[3] = b2Vec2(1.2f, 1.56f);
        vertices[4] = b2Vec2(-1.2f, 1.56f);
        pentagon.Set(vertices, 5);
        b2FixtureDef fixtureDef;
        fixtureDef.shape = &pentagon;
        fixtureDef.density = 1.0f;
        fixtureDef.restitution = 0.5;
        fixtureDef.friction = 0.3f;
        fixtureDef.filter.categoryBits = CHEERIOS;
        body->CreateFixture(&fixtureDef);
    }

    setContentSize(CCSize(WORLD_TO_SCREEN(3*2), WORLD_TO_SCREEN(3*2)));
    setScale(WORLD_TO_SCREEN(3) / 100);
    setPosition(ccp(p.x, p.y));
    setB2Body(body);

    m_sprite = CCSprite::create(f);
    addChild(m_sprite);
}
Ejemplo n.º 2
0
bool RepayView::init(){
    if (!PopupBaseView::init()) {
        return false;
    }
    setIsHDPanel(true);
    CCLoadSprite::doResourceByCommonIndex(8, true);
    CCLoadSprite::doResourceByCommonIndex(11, true);
    CCLoadSprite::doResourceByCommonIndex(101, true);
    CCLoadSprite::doResourceByCommonIndex(305, true);
    CCLoadSprite::doResourceByCommonIndex(502, true);
    setCleanFunction([](){
        CCLoadSprite::doResourceByCommonIndex(8, false);
        CCLoadSprite::doResourceByCommonIndex(11, false);
        CCLoadSprite::doResourceByCommonIndex(101, false);
        CCLoadSprite::doResourceByCommonIndex(305, false);
        CCLoadSprite::doResourceByCommonIndex(502, false);
        CCLoadSprite::releaseDynamicResourceByType(CCLoadSpriteType_GOODS);
    });
    m_dataCount = RepayController::getInstance()->repayRewards.size();
    setTitleName("");
    auto tmpCCB = CCBLoadFile("RepayView",this,this);
    setContentSize(tmpCCB->getContentSize());
    auto size = CCDirector::sharedDirector()->getWinSize();
    float extH = getExtendHeight();
    float add =  size.height - 852;
    if (CCCommonUtils::isIosAndroidPad()) {
        add = size.height - 2048;
        add = add / 2.4;
    }
    m_bgNode->setPositionY(m_bgNode->getPositionY()-extH);
    auto tbg = CCLoadSprite::loadResource("Bottom frame04.png");
    auto tBatchNode = CCSpriteBatchNode::createWithTexture(tbg->getTexture());
    int maxHight = ceil(size.height*1.0/90);
    for (int j = 0; j<maxHight; j++)
    {
        for (int i=0; i<8; i++) {
            auto bg = CCLoadSprite::createSprite("Bottom frame04.png");
            bg->setAnchorPoint(ccp(0, 0));
            bg->setPosition(ccp(i*90, j*90));
            tBatchNode->addChild(bg);
        }
    }
    m_bgNode->addChild(tBatchNode);
    CCSize nodeRewardSize = m_nodeRewards->getContentSize();
    nodeRewardSize.height += extH;
    m_nodeRewards->setContentSize(nodeRewardSize);
    m_nodeRewards->setPositionY(m_nodeRewards->getPositionY()-extH);
    m_tabRewards = CCTableView::create(this, nodeRewardSize);
    m_tabRewards->setDirection(kCCScrollViewDirectionVertical);
    m_tabRewards->setVerticalFillOrder(kCCTableViewFillTopDown);
    m_tabRewards->setTouchPriority(Touch_Default);
    m_tabRewards->setDelegate(this);
    m_nodeRewards->addChild(m_tabRewards);
    
//    m_scrollPoints = CCScrollView::create(m_nodePoints->getContentSize());
//    m_scrollPoints->setDirection(kCCScrollViewDirectionHorizontal);
//    m_scrollPoints->setTouchEnabled(false);
//    m_nodePoints->addChild(m_scrollPoints);
//    m_scrollPoints->setPosition(ccp(0, 0));
    auto clipNode = CCClipNode::create(m_nodePoints->getContentSize().width, m_nodePoints->getContentSize().height);
    clipNode->setAnchorPoint(CCPointZero);
    m_nodePoints->addChild(clipNode);
    clipNode->setTag(REPAY_CLIP_NODE_TAG);
    CCNode *node = CCNode::create();
    clipNode->addChild(node);
    node->setTag(REPAY_CLIP_NODE_TAG);
    
    auto clipNode1 = CCClipNode::create(m_nodePoints->getContentSize().width - 45, m_nodePoints->getContentSize().height);
    m_nodePoints->addChild(clipNode1);
    clipNode1->setPosition(ccp(23,0));
    clipNode1->setTag(REPAY_CLIP_NODE_BAR_TAG);
    auto progress = CCLoadSprite::createScale9Sprite("01_03.png");
    progress->setAnchorPoint(ccp(0, 0.5));
    progress->setTag(REPAY_CLIP_NODE_BAR_TAG);
    clipNode1->addChild(progress);
    progress->setPreferredSize(CCSize(1, 26));
    progress->setPosition(ccp(2.5, 60));
//    setTitleName(_lang("133246"));
    m_lblTitle->setString(_lang("101100"));//距离累计充值大反馈结束还有
//    setButtonTitle(m_btnGoBuy, _lang("101221").c_str());
    m_lblPointTitle->setString(_lang("133247"));
    m_lblRewardTitle->setString(_lang("105848"));
    m_lblPointOrgW = m_lblPointTitle->getContentSize().width * m_lblPointTitle->getOriginScaleX();
    m_lblPointOrgX = m_lblPointTitle->getPositionX();
    onTimer(0);
    this->schedule(schedule_selector(RepayView::onTimer),1.0);
    initPointNode(true);
    
    CCPoint offset = m_tabRewards->getContentOffset();
    int newPoint = RepayController::getInstance()->getNewPayPoint();
    int lv = RepayController::getInstance()->getLVIndexByPoint(newPoint) - 3;
    float changeH = 0;
    while (lv>-1) {
        changeH += tableCellSizeForIndex(m_tabRewards, lv).height;
        lv--;
    }
    offset.y += changeH;
    m_tabRewards->setContentOffset(offset);
    return true;
}
Ejemplo n.º 3
0
EditServerDialog::EditServerDialog(ServerDialog *parent, ServerInfo server,
                                   int index) :
    Window(_("Edit Server"), true, parent),
    mServerDialog(parent),
    mServer(server),
    mIndex(index)
{
    setWindowName("EditServerDialog");

    Label *nameLabel = new Label(_("Name:"));
    Label *serverAdressLabel = new Label(_("Address:"));
    Label *portLabel = new Label(_("Port:"));
    Label *typeLabel = new Label(_("Server type:"));
    Label *descriptionLabel = new Label(_("Description:"));
    mServerAddressField = new TextField(std::string());
    mPortField = new TextField(std::string());
    mPortField->setNumeric(true);
    mPortField->setRange(1, 65535);

    mTypeListModel = new TypeListModel();
    mTypeField = new DropDown(mTypeListModel);
    mTypeField->setSelected(0); // TmwAthena by default for now.

    mNameField = new TextField(std::string());
    mDescriptionField = new TextField(std::string());

    mOkButton = new Button(_("OK"), "addServer", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);

    mServerAddressField->addActionListener(this);
    mPortField->addActionListener(this);

    place(0, 0, nameLabel);
    place(1, 0, mNameField, 4).setPadding(3);
    place(0, 1, serverAdressLabel);
    place(1, 1, mServerAddressField, 4).setPadding(3);
    place(0, 2, portLabel);
    place(1, 2, mPortField, 4).setPadding(3);
    place(0, 3, typeLabel);
    place(1, 3, mTypeField).setPadding(3);
    place(0, 4, descriptionLabel);
    place(1, 4, mDescriptionField, 4).setPadding(3);
    place(4, 5, mOkButton);
    place(3, 5, mCancelButton);

    // Do this manually instead of calling reflowLayout so we can enforce a
    // minimum width.
    int width = 0, height = 0;
    getLayout().reflow(width, height);
    if (width < 300)
    {
        width = 300;
        getLayout().reflow(width, height);
    }
    if (height < 120)
    {
        height = 120;
        getLayout().reflow(width, height);
    }

    setContentSize(width, height);

    setMinWidth(getWidth());
    setMinHeight(getHeight());
    setDefaultSize(getWidth(), getHeight(), ImageRect::CENTER);

    setResizable(false);
    addKeyListener(this);

    loadWindowState();

    mNameField->setText(mServer.name);
    mDescriptionField->setText(mServer.description);
    mServerAddressField->setText(mServer.hostname);
    mPortField->setText(toString(mServer.port));

    switch (mServer.type)
    {
#ifdef EATHENA_SUPPORT
        case ServerInfo::EATHENA:
            mTypeField->setSelected(2);
            break;
        case ServerInfo::MANASERV:
#ifdef MANASERV_SUPPORT
            mTypeField->setSelected(3);
            break;
#endif
#else
        case ServerInfo::MANASERV:
#ifdef MANASERV_SUPPORT
            mTypeField->setSelected(2);
            break;
#endif
#endif
        default:
        case ServerInfo::UNKNOWN:
        case ServerInfo::TMWATHENA:
            mTypeField->setSelected(0);
            break;
        case ServerInfo::EVOL:
            mTypeField->setSelected(1);
            break;
    }

    setLocationRelativeTo(getParentWindow());
    setVisible(true);

    mNameField->requestFocus();
}
Ejemplo n.º 4
0
bool TestController::init() {
    Layer::init();
    
    Sprite *hello = Sprite::create("HelloWorld.png");
    hello->setPosition(Vec2(240, 160));
    this->addChild(hello);
    
    std::string text = std::string() +
                                   "Police have said they plan" +
                                   "to dismantle the camp of colorful" +
                                   "tents and art installations Thursday" +
                                   "morning, urging protesters to leave" +
                                   "peacefully."+ "On Thursday morning," +
                                   "bailiffs read out the court injunction," +
                                   "telling demonstrators to pack up and" +
                                   "leave on their own accord. They then"
                                   "began dismantling and removing barricades"
                                   "at the far western end of the protest area." +
                                   "The bailiffs carried off metal and plastic" +
                                   "barriers that had been lashed together, as" +
                                   "well as broken umbrellas -- wilted versions" +
                                   "of the protest movement's symbol.";
    
    textLabel = Label::createWithTTF(text,
                                    "fonts/Skranji-Regular.ttf",
                                    24);
    textLabel->setAnchorPoint(Vec2(0, 1));
    textLabel->setPosition(Vec2(0, 300));
    textLabel->setDimensions(300, 500);
    textLabel->setAlignment(TextHAlignment::LEFT, TextVAlignment::TOP);
//    textLabel->enableOutline(Color4B(52, 26, 7, 255), 1);
    textLabel->enableShadow(Color4B(52, 26, 7, 255), Size(-0.5f, -0.5f));
//    this->addChild(textLabel);


    CCLOG("content size = (%f, %f)", textLabel->getContentSize().width,
          textLabel->getContentSize().height);
    
    auto clipper = ClippingNode::create();
    clipper->setTag( 98 );
    clipper->setContentSize(  Size(300, 300) );
    clipper->setAnchorPoint(  Vec2(0.5, 0.5) );
    clipper->setPosition(this->getContentSize().width / 2, this->getContentSize().height / 2);
//    clipper->runAction(RepeatForever::create(RotateBy::create(1, 45)));
    this->addChild(clipper);
    
    auto stencil = DrawNode::create();
    Vec2 rectangle[4];
    rectangle[0] = Vec2(0, 0);
    rectangle[1] = Vec2(clipper->getContentSize().width, 0);
    rectangle[2] = Vec2(clipper->getContentSize().width, clipper->getContentSize().height);
    rectangle[3] = Vec2(0, clipper->getContentSize().height);
    
    Color4F white(1, 1, 1, 1);
    stencil->drawPolygon(rectangle, 4, white, 1, white);
    clipper->setStencil(stencil);
    
//    auto content = Sprite::create();
//    content->setContentSize(Size(300, 300));
//    content->setTag( 97 );
//    content->setAnchorPoint(  Vec2(0.5, 0.5) );
//    content->setPosition(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2);
    clipper->addChild(textLabel);
//    content->addChild(textLabel);
    
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    
    listener->onTouchBegan = CC_CALLBACK_2(TestController::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(TestController::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(TestController::onTouchEnded, this);
    
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    return true;
}
void CCClippingRegionNode::setClippingRegion(const CCRect &clippingRegion)
{
    m_clippingRegion = clippingRegion;
    setContentSize(clippingRegion.size);
}
Ejemplo n.º 6
0
void SportsLayer::Shieldtouched(){

	//事件
	auto listen=EventListenerTouchOneByOne::create();
	listen->setSwallowTouches(true);//设置不想向下传递触摸  true是不想 默认为false   
    listen->onTouchBegan = [this](Touch* touch, Event* event){    

		m_touchPoint = Director::getInstance()->convertToGL(touch->getLocationInView()); 
        return true;  
    };     
    listen->onTouchMoved = [this](Touch* touch, Event* event){       
    };     
     
    listen->onTouchEnded = [this](Touch* touch, Event* event){     

		

		Vec2 endPoint = Director::getInstance()->convertToGL(touch->getLocationInView());  

		if(endPoint.x>=this->getPositionX()-getContentSize().width/2&&endPoint.x<=this->getPositionX()+getContentSize().width/2){

        float distance = endPoint.x - m_touchPoint.x;  
		if (fabs(distance) > 50){  

			float width=Actual_x*0.8f;
	        float hight=Actual_y*0.8f;

			if(vsion==1){
			   width=Actual_x*0.8f;
	           hight=Actual_y*0.8f;
			}else if(vsion==2){
			   width=525;
	           hight=450;
			}
			Size visibaleSize = Size(width,hight);
				

				 if (distance < 0)  
			   {  
				   m_curPage++;  
				}else{  
					m_curPage--;  
				}  
  
 
  
			    if (m_curPage < 1)  
				{  
					m_curPage = 1;  
				}  
  
				if (m_curPage > 2)  
				{  
					m_curPage = 2;  
				}   
				
				Vec2 origin = Director::getInstance()->getVisibleOrigin();  
				Vec2 adjustPos =Vec2(origin.x - (m_curPage - 1) * visibaleSize.width,0);  
				scrollView->setContentOffset(adjustPos,true);

				if(m_curPage>1){
					jt1->setVisible(true);
					jt2->setVisible(false);
					
					if(vsion==2)
					  b_label->setString(FX::StringsMap::getValue("dfljing"));
					  
				}else if(m_curPage<2){
					jt1->setVisible(false);
					jt2->setVisible(true);
					
					if(vsion==2)
					  b_label->setString(FX::StringsMap::getValue("wdfzsm"));
					  
				}
	           
         }
		}
    };  


	EventDispatcher* dispatch=Director::getInstance()->getEventDispatcher();
	dispatch->addEventListenerWithSceneGraphPriority(listen,this);

	//
	ignoreAnchorPointForPosition(false);
	setAnchorPoint(Vec2(0.5,0.5));
	setPosition(Vec2(Actual_x/2,Actual_y/2));
	setContentSize(Size(Actual_x,Actual_y));
}
Ejemplo n.º 7
0
// on "init" you need to initialize your instance
bool LearnScene::init()
{
    if ( !LayerColor::initWithColor(Constants::BACKGROUND_COLOR) )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    // Home btn
    auto btn = ui::Button::create("HomeBtn", "HomeBtn", "", ui::Widget::TextureResType::PLIST);
    btn->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
    btn->setPosition(Vec2(origin.x + visibleSize.width, origin.y + visibleSize.height));
    btn->addTouchEventListener(CC_CALLBACK_2(LearnScene::touchEvent, this));
    this->addChild(btn, 1, 1);
    
    // Learn progress txt
    float retainedPercent = round(Constants::getRetainedWordCount() * 100 / Constants::getTotalWordCount());
    std::stringstream stm;
    stm << "Learning progress: " << retainedPercent << "%";
    auto label = Label::createWithBMFont(Constants::FONT_BOLD12, stm.str());
    label->setColor(Color3B::BLACK);
    label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
    label->setPosition(origin.x + 14, origin.y + visibleSize.height - 28);
    this->addChild(label, 2, 2);
    
    // Learn progress bar
    auto sprite9 = ui::Scale9Sprite::createWithSpriteFrameName("PbBg", Rect(2, 2, 2, 2));
    sprite9->setContentSize(Size(visibleSize.width - 28, 18));
    sprite9->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 60));
    this->addChild(sprite9, 3, 3);
    
    auto pb = ui::Scale9Sprite::createWithSpriteFrameName("PbProgress", Rect(2, 2, 2, 2));
    Size pbSize = sprite9->getContentSize();
    pbSize.width *= retainedPercent / 100;
    if(pbSize.width < 6) pbSize.width = 6;
    pb->setContentSize(pbSize);
    pb->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
    sprite9->addChild(pb, 1, 1);
    
    // Text area
    sprite9 = ui::Scale9Sprite::createWithSpriteFrameName("TextArea", Rect(12, 12, 12, 12));
    sprite9->setContentSize(Size(visibleSize.width-28, visibleSize.height - 264));
    sprite9->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 86 - sprite9->getContentSize().height / 2));
    this->addChild(sprite9, 4, 4);
    
    // choices
    btn = ui::Button::create("ChoiceBg", "ChoiceSelectedBg", "", ui::Widget::TextureResType::PLIST);
    btn->setScale9Enabled(true);
    btn->setCapInsets(Rect(5, 5, 5, 5));
    btn->setSize(Size(visibleSize.width-28, 30));
    btn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + 148));
    btn->getTitleRenderer()->setBMFontFilePath(Constants::FONT_REGULAR12);
    btn->getTitleRenderer()->setColor(Color3B::BLACK);
    btn->setTitleText("I know this word.");
    btn->addTouchEventListener(CC_CALLBACK_2(LearnScene::touchEvent, this));
    this->addChild(btn, 5, 5);
    btn = ui::Button::create("ChoiceBg", "ChoiceSelectedBg", "", ui::Widget::TextureResType::PLIST);
    btn->setScale9Enabled(true);
    btn->setCapInsets(Rect(5, 5, 5, 5));
    btn->setSize(Size(visibleSize.width-28, 30));
    btn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + 103));
    btn->getTitleRenderer()->setBMFontFilePath(Constants::FONT_REGULAR12);
    btn->getTitleRenderer()->setColor(Color3B::BLACK);
    btn->setTitleText("Not yet!");
    btn->addTouchEventListener(CC_CALLBACK_2(LearnScene::touchEvent, this));
    this->addChild(btn, 6, 6);
    
    // check btn
    btn = ui::Button::create("BtnNormal", "BtnPressed", "BtnDisabled", ui::Widget::TextureResType::PLIST);
    btn->setScale9Enabled(true);
    btn->setCapInsets(Rect(12, 12, 12, 12));
    btn->setSize(Size(visibleSize.width-28, 58));
    btn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + 45));
    btn->getTitleRenderer()->setBMFontFilePath(Constants::FONT_BOLD30);
    btn->setTitleText("Check");
    btn->addTouchEventListener(CC_CALLBACK_2(LearnScene::touchEvent, this));
    this->addChild(btn, 7, 7);
    btn->setEnabled(false);
    btn->setBright(false);
    
    // term
    std::string nextWord = Constants::getNextWordToLearn();
    label = Label::createWithBMFont(Constants::FONT_BOLD30, nextWord);
    label->setColor(Color3B::BLACK);
    label->setPosition(sprite9->getContentSize().width/2, sprite9->getContentSize().height/2);
    sprite9->addChild(label, 1, 1);
    
    // definition
    const ValueMap& wInfo = Configuration::getInstance()->getValue("words").asValueMap().at(nextWord).asValueMap();
    auto it = wInfo.find("ldef");
    std::string ldef = it != wInfo.end() ? it->second.asString() : "Missing definition";
    label = Label::createWithBMFont(Constants::FONT_REGULAR14, ldef);
    label->setColor(Color3B::BLACK);
    label->setWidth(sprite9->getContentSize().width - 28);
    label->setAlignment(TextHAlignment::LEFT);
    label->setPosition(sprite9->getContentSize().width/2, sprite9->getContentSize().height/2);
    sprite9->addChild(label, 2, 2);
    label->setOpacity(0);
    label->setVisible(false);
    
    // play sound
    Constants::playText(nextWord);
    
    // init vars
    this->startTime = time(0);
    this->showNext = false;
    this->answerChoice = -1;
    
    return true;
}
Ejemplo n.º 8
0
bool HelloWorld::init()
{

	if ( !Layer::init() )
	{
		return false;
	}

	CReadFile::getInstance()->init();

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto closeItem = MenuItemImage::create(
		"picture/blue1_menu.png",
		"picture/blue2_menu.png" 
		, CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
	closeItem->setScale(0.3f);
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2-310 ,
		origin.y + closeItem->getContentSize().height/2+160));

	auto closeItem1 = MenuItemImage::create(
		"picture/blue1_menu.png",
		"picture/blue2_menu.png",
		CC_CALLBACK_1(HelloWorld::menuCloseCallback1, this));

	closeItem1->setScale(0.5f);

	closeItem1->setPosition(Vec2(origin.x + visibleSize.width - closeItem1->getContentSize().width/2-310 ,
		origin.y + closeItem1->getContentSize().height/2+330));

	auto SetMenu = MenuItemImage::create(
		"picture/shezhi2_cover.png",
		"picture/shezhi1_cover.png",
		CC_CALLBACK_1(HelloWorld::menuCloseCallback3, this));
	SetMenu->setScale(0.8f);

	SetMenu->setPosition(Vec2(origin.x + visibleSize.width - SetMenu->getContentSize().width/2-390 ,
		origin.y + SetMenu->getContentSize().height/2+260));

	auto menu = Menu::create(closeItem,closeItem1,SetMenu, NULL);
	menu->setPosition(Vec2::ZERO);		
	this->addChild(menu, 1);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
	auto label = Label::createWithTTF(Tools::Unicode2Utf8(L"开始游戏"), "fonts/msyh.ttc", 24);
#else
	auto label = Label::createWithTTF("开始游戏", "fonts/msyh.ttc", 24);
#endif
	label->setPosition(Vec2(closeItem1->getPositionX(), closeItem1->getPositionY()));
	label->setScale(0.8f);
	this->addChild(label, 1);
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
	auto label1 = Label::createWithTTF(Tools::Unicode2Utf8(L"退出"), "fonts/msyh.ttc", 24);
#else
	auto label1 = Label::createWithTTF("退出", "fonts/msyh.ttc", 24);
#endif
	label1->setPosition(Vec2(closeItem->getPositionX(), closeItem->getPositionY()));
	label1->setScale(0.8f);
	this->addChild(label1,1);

	auto sprite = Sprite::create("picture/shumabaobei.jpg");

	Size sprSize = sprite->getContentSize();

	sprite->setScaleX(visibleSize.width/sprSize.width);
	sprite->setScaleY(visibleSize.height/sprSize.height);
	sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
	this->addChild(sprite, 0);	

	auto logo = Sprite::create("picture/logo.png");
	Size logoSize = logo->getContentSize();

	auto spark = Sprite::create("picture/spark.png");
	spark->setPosition(-logoSize.width,0);
	auto clippingNode = ClippingNode::create();
	clippingNode->setPosition(500,560);
	this->addChild(clippingNode);
	clippingNode->setAlphaThreshold(0.05f);
	clippingNode->setContentSize(logoSize);

	clippingNode->setStencil(logo);
	clippingNode->addChild(logo,1);
	clippingNode->addChild(spark,2);

	auto moveAction = MoveTo::create(2.0f,Vec2(logoSize.width,0));
	auto moveBackAction = MoveTo::create(2.0f,Vec2(-logoSize.width,0));
	spark->runAction(RepeatForever::create(Sequence::create(moveAction,moveBackAction,NULL)));
	if (CReadFile::getInstance()->getshuomingkg())
	{
		CReadFile::getInstance()->setshuomingkg(false);
		CSound::getInstance()->playBG("Butter-Fly.mp3",CSound::getInstance()->getIsPlay());
		CSound::getInstance()->setIsPlay(true);


		auto shuominglayer = LayerColor::create(Color4B(120,120,120,200));
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
		auto wenzi = Label::createWithTTF(Tools::Unicode2Utf8(L"欢迎来到宝库设计的数码宝贝记忆消除游戏"),"fonts/msyh.ttc", 28);
#else
		auto wenzi = Label::createWithTTF("欢迎来到宝库设计的数码宝贝记忆消除游戏","fonts/msyh.ttc", 28);
#endif
		wenzi->setMaxLineWidth(460);
		wenzi->setLineBreakWithoutSpace(true);
		wenzi->setPosition(480,520);
		wenzi->setColor(ccc3(0,0,0));
		shuominglayer->runAction(FadeOut::create(5));
		wenzi->runAction(FadeOut::create(3));
		shuominglayer->addChild(wenzi,2);
		this->addChild(shuominglayer,2);
	}
	return true;
}
Ejemplo n.º 9
0
	bool CCTMXTiledMap::initWithTMXFile(const char *tmxFile)
	{
		CCAssert(tmxFile != NULL && strlen(tmxFile)>0, "TMXTiledMap: tmx file should not bi nil");
		
		setContentSize(CCSizeZero);

		CCTMXMapInfo *mapInfo = CCTMXMapInfo::formatWithTMXFile(tmxFile);
    
        if (! mapInfo)
        {
            return false;
        }
		CCAssert( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");

		m_tMapSize = mapInfo->getMapSize();
		m_tTileSize = mapInfo->getTileSize();
		m_nMapOrientation = mapInfo->getOrientation();
		setObjectGroups(mapInfo->getObjectGroups());
		setProperties(mapInfo->getProperties());
		CC_SAFE_RELEASE(m_pTileProperties);
		m_pTileProperties = mapInfo->getTileProperties();
		CC_SAFE_RETAIN(m_pTileProperties);

		int idx = 0;

		CCMutableArray<CCTMXLayerInfo*>* layers = mapInfo->getLayers();
		if (layers && layers->count()>0)
		{
            if (NULL == m_pTMXLayers)
            {
                m_pTMXLayers = new CCDictionary<std::string, CCTMXLayer*>();
                CCAssert(m_pTMXLayers, "Allocate memory failed!");
            }

			CCTMXLayerInfo *layerInfo = NULL;
			CCMutableArray<CCTMXLayerInfo*>::CCMutableArrayIterator it;
			for (it = layers->begin(); it != layers->end(); ++it)
			{
				layerInfo = *it;
				if (layerInfo && layerInfo->m_bVisible)
				{
					CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
					addChild((CCNode*)child, idx, idx);

                    // record the CCTMXLayer object by it's name
                    std::string layerName = child->getLayerName();
                    m_pTMXLayers->setObject(child, layerName);

					// update content size with the max size
					const CCSize& childSize = child->getContentSize();
					CCSize currentSize = this->getContentSize();
					currentSize.width = MAX( currentSize.width, childSize.width );
					currentSize.height = MAX( currentSize.height, childSize.height );
					this->setContentSize(currentSize);

					idx++;
				}
			}
		}
		return true;
	}
Ejemplo n.º 10
0
void CCSlot::_updateFrame()
{
    const auto frameDisplay = (DBCCSprite*)(this->_rawDisplay);

    if (this->_display && this->_displayIndex >= 0)
    {
        const unsigned displayIndex = this->_displayIndex;
        const auto rawDisplayData = displayIndex < this->_displayDataSet->displays.size() ? this->_displayDataSet->displays[displayIndex] : nullptr;
        const auto replacedDisplayData = displayIndex < this->_replacedDisplayDataSet.size() ? this->_replacedDisplayDataSet[displayIndex] : nullptr;
        const auto currentDisplayData = replacedDisplayData ? replacedDisplayData : rawDisplayData;
        const auto currentTextureData = static_cast<CCTextureData*>(currentDisplayData->textureData);

        if (currentTextureData)
        {
            if (!currentTextureData->texture)
            {
                const auto textureAtlasTexture = static_cast<CCTextureAtlasData*>(currentTextureData->parent)->texture;
                if (textureAtlasTexture)
                {
                    cocos2d::Rect rect(currentTextureData->region.x, currentTextureData->region.y, currentTextureData->region.width, currentTextureData->region.height);
                    cocos2d::Vec2 offset(0.f, 0.f);
                    cocos2d::Size originSize(currentTextureData->region.width, currentTextureData->region.height);

                    /*if (currentTextureData->frame) 
                    {
                        offset.setPoint(-currentTextureData->frame->x, -currentTextureData->frame->y);
                        originSize.setSize(currentTextureData->frame->width, currentTextureData->frame->height);
                    }*/

                    currentTextureData->texture = cocos2d::SpriteFrame::createWithTexture(textureAtlasTexture, rect, currentTextureData->rotated, offset, originSize); // TODO multiply textureAtlas
                    currentTextureData->texture->retain();
                }
            }

            const auto currentTexture = this->_armature->_replacedTexture ? static_cast<cocos2d::Texture2D*>(this->_armature->_replacedTexture) : (currentTextureData->texture ? currentTextureData->texture->getTexture() : nullptr);

            if (currentTexture)
            {
                if (this->_meshData && this->_display == this->_meshDisplay)
                {
                    const auto& region = currentTextureData->region;
                    const auto& textureAtlasSize = currentTextureData->texture->getTexture()->getContentSizeInPixels();
                    auto displayVertices = new cocos2d::V3F_C4B_T2F[(unsigned)(this->_meshData->uvs.size() / 2)]; // does cocos2dx release it?
                    auto vertexIndices = new unsigned short[this->_meshData->vertexIndices.size()]; // does cocos2dx release it?
                    cocos2d::Rect boundsRect(999999.f, 999999.f, -999999.f, -999999.f);

                    for (std::size_t i = 0, l = this->_meshData->uvs.size(); i < l; i += 2)
                    {
                        const auto iH = (unsigned)(i / 2);
                        const auto x = this->_meshData->vertices[i];
                        const auto y = this->_meshData->vertices[i + 1];
                        cocos2d::V3F_C4B_T2F vertexData;
                        vertexData.vertices.set(x, -y, 0.f);
                        vertexData.texCoords.u = (region.x + this->_meshData->uvs[i] * region.width) / textureAtlasSize.width;
                        vertexData.texCoords.v = (region.y + this->_meshData->uvs[i + 1] * region.height) / textureAtlasSize.height;
                        vertexData.colors = cocos2d::Color4B::WHITE;
                        displayVertices[iH] = vertexData;

                        if (boundsRect.origin.x > x)
                        {
                            boundsRect.origin.x = x;
                        }

                        if (boundsRect.size.width < x) 
                        {
                            boundsRect.size.width = x;
                        }

                        if (boundsRect.origin.y > -y)
                        {
                            boundsRect.origin.y = -y;
                        }

                        if (boundsRect.size.height < -y)
                        {
                            boundsRect.size.height = -y;
                        }
                    }

                    boundsRect.size.width -= boundsRect.origin.x;
                    boundsRect.size.height -= boundsRect.origin.y;

                    for (std::size_t i = 0, l = this->_meshData->vertexIndices.size(); i < l; ++i)
                    {
                        vertexIndices[i] = this->_meshData->vertexIndices[i];
                    }

                    // In cocos2dx render meshDisplay and frameDisplay are the same display
                    frameDisplay->setSpriteFrame(currentTextureData->texture); // polygonInfo will be override
                    if (currentTexture != currentTextureData->texture->getTexture())
                    {
                        frameDisplay->setTexture(currentTexture); // Relpace texture // polygonInfo will be override
                    }

                    //
                    cocos2d::PolygonInfo polygonInfo;
                    auto& triangles = polygonInfo.triangles;
                    triangles.verts = displayVertices;
                    triangles.indices = vertexIndices;
                    triangles.vertCount = (unsigned)(this->_meshData->uvs.size() / 2);
                    triangles.indexCount = (unsigned)(this->_meshData->vertexIndices.size());
                    polygonInfo.rect = boundsRect; // Copy
                    frameDisplay->setPolygonInfo(polygonInfo);
                    frameDisplay->setContentSize(boundsRect.size);

                    if (this->_meshData->skinned)
                    {
                        frameDisplay->setScale(1.f, 1.f);
                        frameDisplay->setRotationSkewX(0.f);
                        frameDisplay->setRotationSkewY(0.f);
                        frameDisplay->setPosition(0.f, 0.f);
                    }

                    frameDisplay->setAnchorPoint(cocos2d::Vec2::ZERO);
                }
                else
                {
                    cocos2d::Vec2 pivot(currentDisplayData->pivot.x, currentDisplayData->pivot.y);

                    const auto& rectData = currentTextureData->frame ? *currentTextureData->frame : currentTextureData->region;
                    auto width = rectData.width;
                    auto height = rectData.height;
                    if (!currentTextureData->frame && currentTextureData->rotated)
                    {
                        width = rectData.height;
                        height = rectData.width;
                    }

                    if (currentDisplayData->isRelativePivot)
                    {
                        pivot.x *= width;
                        pivot.y *= height;
                    }

                    if (currentTextureData->frame)
                    {
                        pivot.x += currentTextureData->frame->x;
                        pivot.y += currentTextureData->frame->y;
                    }

                    if (rawDisplayData && rawDisplayData != currentDisplayData)
                    {
                        pivot.x += rawDisplayData->transform.x - currentDisplayData->transform.x;
                        pivot.y += rawDisplayData->transform.y - currentDisplayData->transform.y;
                    }

                    pivot.x = pivot.x / currentTextureData->region.width;
                    pivot.y = 1.f - pivot.y / currentTextureData->region.height;

                    frameDisplay->setSpriteFrame(currentTextureData->texture); // polygonInfo will be override

                    if (currentTexture != currentTextureData->texture->getTexture())
                    {
                        frameDisplay->setTexture(currentTexture); // Relpace texture // polygonInfo will be override
                    }

                    frameDisplay->setAnchorPoint(pivot);
                }

                this->_updateVisible();

                return;
            }
        }
    }

    frameDisplay->setTexture(nullptr);
    frameDisplay->setTextureRect(cocos2d::Rect::ZERO);
    frameDisplay->setAnchorPoint(cocos2d::Vec2::ZERO);
    frameDisplay->setVisible(false);
}
Ejemplo n.º 11
0
void CCSlot::_updateMesh() 
{
    const auto meshDisplay = static_cast<DBCCSprite*>(this->_meshDisplay);
    const auto hasFFD = !this->_ffdVertices.empty();

    const auto displayVertices = meshDisplay->getPolygonInfoModify().triangles.verts;
    cocos2d::Rect boundsRect(999999.f, 999999.f, -999999.f, -999999.f);

    if (this->_meshData->skinned)
    {
        std::size_t iF = 0;
        for (std::size_t i = 0, l = this->_meshData->vertices.size(); i < l; i += 2)
        {
            const auto iH = unsigned(i / 2);

            const auto& boneIndices = this->_meshData->boneIndices[iH];
            const auto& boneVertices = this->_meshData->boneVertices[iH];
            const auto& weights = this->_meshData->weights[iH];

            float xG = 0.f, yG = 0.f;
            for (std::size_t iB = 0, lB = boneIndices.size(); iB < lB; ++iB)
            {
                const auto bone = this->_meshBones[boneIndices[iB]];
                const auto matrix = bone->globalTransformMatrix;
                const auto weight = weights[iB];

                float xL = 0.f, yL = 0.f;
                if (hasFFD)
                {
                    xL = boneVertices[iB * 2] + this->_ffdVertices[iF];
                    yL = boneVertices[iB * 2 + 1] + this->_ffdVertices[iF + 1];
                }
                else
                {
                    xL = boneVertices[iB * 2];
                    yL = boneVertices[iB * 2 + 1];
                }

                xG += (matrix->a * xL + matrix->c * yL + matrix->tx) * weight;
                yG += (matrix->b * xL + matrix->d * yL + matrix->ty) * weight;

                iF += 2;
            }

            auto& vertices = displayVertices[iH];
            auto& vertex = vertices.vertices;

            vertex.set(xG, -yG, 0.f);

            if (boundsRect.origin.x > xG)
            {
                boundsRect.origin.x = xG;
            }

            if (boundsRect.size.width < xG)
            {
                boundsRect.size.width = xG;
            }

            if (boundsRect.origin.y > -yG)
            {
                boundsRect.origin.y = -yG;
            }

            if (boundsRect.size.height < -yG)
            {
                boundsRect.size.height = -yG;
            }
        }
    }
    else if (hasFFD)
    {
        const auto& vertices = _meshData->vertices;
        for (std::size_t i = 0, l = this->_meshData->vertices.size(); i < l; i += 2)
        {
            const auto iH = unsigned(i / 2);
            const auto xG = vertices[i] + _ffdVertices[i];
            const auto yG = vertices[i + 1] + _ffdVertices[i + 1];

            auto& vertices = displayVertices[iH];
            auto& vertex = vertices.vertices;

            vertex.set(xG, -yG, 0.f);

            if (boundsRect.origin.x > xG)
            {
                boundsRect.origin.x = xG;
            }

            if (boundsRect.size.width < xG)
            {
                boundsRect.size.width = xG;
            }

            if (boundsRect.origin.y > -yG)
            {
                boundsRect.origin.y = -yG;
            }

            if (boundsRect.size.height < -yG)
            {
                boundsRect.size.height = -yG;
            }
        }
    }

    boundsRect.size.width -= boundsRect.origin.x;
    boundsRect.size.height -= boundsRect.origin.y;
    
    cocos2d::Rect* rect = (cocos2d::Rect*)&meshDisplay->getPolygonInfo().rect;
    rect->origin = boundsRect.origin; // copy
    rect->size = boundsRect.size; // copy
    meshDisplay->setContentSize(boundsRect.size);
}
Ejemplo n.º 12
0
bool FloorMapLayer::init(int floor)
{
    _floor = floor;
    // 由于直接继承自node,需要做一些处理,现在layer的功能全被废弃了,无意义
    setContentSize(Director::getInstance()->getWinSize());

    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan = CC_CALLBACK_2(FloorMapLayer::onTouchBegan, this);
    listener->onTouchEnded = CC_CALLBACK_2(FloorMapLayer::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

    // 加载地图编辑器文件
    auto res = "TileMaps/floor00" + String::createWithFormat("%d", floor)->_string + ".tmx";
    _tiled_map = cocos2d::experimental::TMXTiledMap::create(res);
    if (nullptr != _tiled_map)
    {
        _tiled_map->setPosition(Vec2(-50.0f, -50.0f));
        this->addChild(_tiled_map);
    }

    // 路径节点
    _road_node = Node::create();
    if (nullptr != _road_node)
    {
        _road_node->setPosition(Vec2::ZERO);
        this->addChild(_road_node);
    }

    // 勇士骨骼动画节点
    _warrior = WarriorNode::create();
    /*cocostudio::CCBone* bone = _warrior->getBone("sheild1");
    int index = bone->getDisplayManager()->getCurrentDisplayIndex();
    bone->removeDisplay(1);
    bone->changeDisplayByIndex(-1, true);
    cocostudio::CCBone* bone2 = _warrior->getBone("sheild2");
    index = bone2->getDisplayManager()->getCurrentDisplayIndex();
    bone2->removeDisplay(1);
    bone2->changeDisplayByIndex(-1, true);*/
    _warrior->setPosition(Vec2(62.5f, 62.5f));
    this->addChild(_warrior);

    // 上方背景
    auto inside_bg = Sprite::create("Images/bg_top2.png");
    auto outside_bg = Sprite::create("Images/bg_top_1.png");
    if (nullptr != outside_bg && nullptr != inside_bg)
    {
        auto win_size = Director::getInstance()->getWinSize();
        outside_bg->setScale(inside_bg->getContentSize().width / outside_bg->getContentSize().width);
        outside_bg->setPosition(Vec2(win_size.width / 2, 1092.0f));
        this->addChild(outside_bg);

        inside_bg->setPosition(Vec2(win_size.width / 2, 1076.0f));
        this->addChild(inside_bg);
    }

    // 点击箭头节点
    _arrow_node = ArrowNode::create();
    if (nullptr != _arrow_node)
    {
        _arrow_node->setPosition(Vec2::ZERO);
        _arrow_node->setVisible(false);
        this->addChild(_arrow_node);
    }

    // 勇士属性面板
    _info_panel = WarriorInfoPanel::create();
    if (nullptr != _info_panel)
    {
        _info_panel->setPosition(Vec2(-10.0f, 825.0f));
        this->addChild(_info_panel);
    }
    
    return true;
}
Ejemplo n.º 13
0
ServerDialog::ServerDialog(ServerInfo *const serverInfo,
                           const std::string &dir) :
    // TRANSLATORS: servers dialog name
    Window(_("Choose Your Server"), Modal_false, nullptr, "server.xml"),
    ActionListener(),
    KeyListener(),
    SelectionListener(),
    mMutex(),
    mServers(ServerInfos()),
    mDir(dir),
    mDescription(new Label(this, std::string())),
    // TRANSLATORS: servers dialog button
    mQuitButton(new Button(this, _("Quit"), "quit", this)),
    // TRANSLATORS: servers dialog button
    mConnectButton(new Button(this, _("Connect"), "connect", this)),
    // TRANSLATORS: servers dialog button
    mAddEntryButton(new Button(this, _("Add"), "addEntry", this)),
    // TRANSLATORS: servers dialog button
    mEditEntryButton(new Button(this, _("Edit"), "editEntry", this)),
    // TRANSLATORS: servers dialog button
    mDeleteButton(new Button(this, _("Delete"), "remove", this)),
    // TRANSLATORS: servers dialog button
    mLoadButton(new Button(this, _("Load"), "load", this)),
    mServersListModel(new ServersListModel(&mServers, this)),
    mServersList(new ServersListBox(this, mServersListModel)),
    mDownload(nullptr),
    mServerInfo(serverInfo),
    mPersistentIPCheckBox(nullptr),
    mDownloadProgress(-1.0F),
    mDownloadStatus(DOWNLOADING_UNKNOWN)
{
    mServersList->postInit();

    if (isSafeMode)
    {
        // TRANSLATORS: servers dialog name
        setCaption(_("Choose Your Server  *** SAFE MODE ***"));
    }

    setWindowName("ServerDialog");

    setCloseButton(true);

    mPersistentIPCheckBox = new CheckBox(this,
        // TRANSLATORS: servers dialog checkbox
        _("Use same ip for game sub servers"),
        config.getBoolValue("usePersistentIP"),
        this, "persitent ip");

    loadCustomServers();

    mServersList->addMouseListener(this);

    ScrollArea *const usedScroll = new ScrollArea(this, mServersList,
        getOptionBool("showbackground"), "server_background.xml");
    usedScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);

    mServersList->addSelectionListener(this);
    usedScroll->setVerticalScrollAmount(0);

    place(0, 0, usedScroll, 7, 5).setPadding(3);
    place(0, 5, mDescription, 7);
    place(0, 6, mPersistentIPCheckBox, 7);
    place(0, 7, mAddEntryButton);
    place(1, 7, mEditEntryButton);
    place(2, 7, mLoadButton);
    place(3, 7, mDeleteButton);
    place(5, 7, mQuitButton);
    place(6, 7, mConnectButton);

    // Make sure the list has enough height
    getLayout().setRowHeight(0, 80);

    // Do this manually instead of calling reflowLayout so we can enforce a
    // minimum width.
    int width = 500;
    int height = 350;

    getLayout().reflow(width, height);
    setContentSize(width, height);

    setMinWidth(310);
    setMinHeight(220);
    setDefaultSize(getWidth(), getHeight(), ImageRect::CENTER);

    setResizable(true);
    addKeyListener(this);

    loadWindowState();
}
Ejemplo n.º 14
0
bool Layer::init()
{
    Director * director = Director::getInstance();
    setContentSize(director->getWinSize());
    return true;
}
Ejemplo n.º 15
0
bool PropSpeedupView::init(int type,int bid, int qid){
    if (!PopupBaseView::init()) {
        return false;
    }
    setIsHDPanel(true);
    bool bRet=false;
//    CCLoadSprite::doResourceByCommonIndex(11, true);
    CCLoadSprite::doResourceByWorldIndex(2, true);
    setCleanFunction([](){
//        CCLoadSprite::doResourceByCommonIndex(11, false);
        CCLoadSprite::doResourceByWorldIndex(2, false);
        CCLoadSprite::releaseDynamicResourceByType(CCLoadSpriteType_GOODS);
    });
    if (CCBLoadFile("PropSpeedupView.ccbi", this, this)) {
        this->getAnimationManager()->runAnimationsForSequenceNamed("stop");
        CCSize size=CCDirector::sharedDirector()->getWinSize();
        setContentSize(size);
        m_proptype = type,
        m_qID = qid;
        m_buildingID = bid;
        CCSize nodeSize = m_nodeProp1->getContentSize();
        m_scrollView = CCScrollView::create(nodeSize);
        m_scrollView->setDirection(kCCScrollViewDirectionHorizontal);
        m_scrollView->setTouchEnabled(false);
        //m_scrollView->setDelegate(this);
        m_nodeProp1->addChild(m_scrollView);
        m_lblInfo->setString(_lang("102358").c_str());
        switch (m_proptype) {
            case ItemSpdMenu_Soldier:{ //造兵
                m_lblTitle->setString(_lang("102356").c_str());
                break;
            }
            case ItemSpdMenu_Heal:{//治疗
                m_lblTitle->setString(_lang("102354").c_str());
                break;
            }
            case ItemSpdMenu_Trap:{//造陷阱
                m_lblTitle->setString(_lang("102357").c_str());
                break;
            }
            case ItemSpdMenu_Science:{//科技
                m_lblTitle->setString(_lang("102355").c_str());
                break;
            }
            case ItemSpdMenu_City:{//城建
                if (FunBuildController::getInstance()->curBuildsInfo->find(m_buildingID) != FunBuildController::getInstance()->curBuildsInfo->end()) {
                    auto m_info = &((*FunBuildController::getInstance()->curBuildsInfo)[m_buildingID]);
                    bool isUpgrading = (m_info->state == FUN_BUILD_UPING)?true:false ;
                    if(isUpgrading){
                        m_lblTitle->setString(_lang("102352").c_str());
                    }else{
                        m_lblTitle->setString(_lang("102352").c_str());
                    }

                }
//                else if (DragonBuildingController::getInstance()->curDragonBuildsInfo->find(m_buildingID) != DragonBuildingController::getInstance()->curDragonBuildsInfo->end()) {
//                    auto m_info = &((*DragonBuildingController::getInstance()->curDragonBuildsInfo)[m_buildingID]);
//                    bool isUpgrading = (m_info->state == FUN_BUILD_UPING)?true:false ;
//                    if(isUpgrading){
//                        m_lblTitle->setString(_lang("102352").c_str());
//                    }else{
//                        m_lblTitle->setString(_lang("102352").c_str());
//                    }
//                }
                break;
            }
            case ItemSpdMenu_DuanZao:{ //锻造
                m_lblTitle->setString(_lang("102373").c_str());
                break;
            }
            case ItemSpdMenu_Mate:{ //材料
                m_lblTitle->setString(_lang("111756").c_str());
                break;
            }
            default:
                break;
        }
        //auto& qInfo = GlobalData::shared()->allQueuesInfo[m_qID];
        auto& qInfo = GlobalData::shared()->allQueuesInfo[m_qID];
        m_buildTime = qInfo.finishTime - GlobalData::shared()->getWorldTime();
        
        initDataList();
        updateProgressBar(0);
        initSliderBar();
        m_clickIndex=0;
        refreshEditBox();
        m_sprSelect=CCLoadSprite::createScale9Sprite("sel_general.png");
        m_sprSelect->setInsetBottom(10);
        m_sprSelect->setInsetTop(10);
        m_sprSelect->setInsetLeft(10);
        m_sprSelect->setInsetRight(10);
        m_sprSelect->setPreferredSize(CCSize(PROP_SPEEDUP_CELL_W, PROP_SPEEDUP_CELL_W));
        m_partileNode = Node::create();
        m_sprSelect->addChild(m_partileNode);
        auto particle = ParticleController::createParticle("Speedupicon_1");
        particle->setPosition(m_sprSelect->getContentSize() / 2);
        m_partileNode->addChild(particle);
        m_scrollView->addChild(m_sprSelect);
        m_sprSelect->setZOrder(-1);
        setSelectSpritePosition();
        this->schedule(schedule_selector(PropSpeedupView::updateProgressBar), 1);
        m_lastClickIndex = m_clickIndex;
//        m_useBtn->setTouchPriority(0);
        
        
        this->setModelLayerTouchCallback([&](cocos2d::CCTouch *pTouch){
            if(!isTouchInside(m_sprBG, pTouch) ){
                this->closeSelf();
            }/*else{
                this->ccTouchBegan(pTouch, NULL);
            }*/
        });

        bRet=true;
    }
    return bRet;
}
Ejemplo n.º 16
0
EditServerDialog::EditServerDialog(ServerDialog *const parent,
                                   ServerInfo server,
                                   const int index) :
    // TRANSLATORS: edit server dialog name
    Window(_("Edit Server"), Modal_true, parent),
    ActionListener(),
    KeyListener(),
    mServerAddressField(new TextField(this, std::string())),
    mPortField(new TextField(this, std::string())),
    mNameField(new TextField(this, std::string())),
    mDescriptionField(new TextField(this, std::string())),
    mOnlineListUrlField(new TextField(this, std::string())),
    mPacketVersionField(new IntTextField(this, 0, 0, maxPacketVersion)),
    // TRANSLATORS: edit server dialog button
    mConnectButton(new Button(this, _("Connect"), "connect", this)),
    // TRANSLATORS: edit server dialog button
    mOkButton(new Button(this, _("OK"), "addServer", this)),
    // TRANSLATORS: edit server dialog button
    mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
    // TRANSLATORS: edit server dialog label
    mPersistentIp(new CheckBox(this, _("Use same ip"),
                  true, this, "persistentIp")),
    mTypeListModel(new TypeListModel),
    mTypeField(new DropDown(this, mTypeListModel, false, Modal_true)),
    mServerDialog(parent),
    mServer(server),
    mIndex(index)
{
    setWindowName("EditServerDialog");

    // TRANSLATORS: edit server dialog label
    Label *const nameLabel = new Label(this, _("Name:"));
    // TRANSLATORS: edit server dialog label
    Label *const serverAdressLabel = new Label(this, _("Address:"));
    // TRANSLATORS: edit server dialog label
    Label *const portLabel = new Label(this, _("Port:"));
    // TRANSLATORS: edit server dialog label
    Label *const typeLabel = new Label(this, _("Server type:"));
    // TRANSLATORS: edit server dialog label
    Label *const descriptionLabel = new Label(this, _("Description:"));
    // TRANSLATORS: edit server dialog label
    Label *const onlineListUrlLabel = new Label(this, _("Online list url:"));
    // TRANSLATORS: edit server dialog label
    Label *const packetVersionLabel = new Label(this, _("Packet version:"));
    mPortField->setNumeric(true);
    mPortField->setRange(1, 65535);

    mTypeField->setSelected(0);  // TmwAthena by default

    mServerAddressField->addActionListener(this);
    mPortField->addActionListener(this);

    place(0, 0, nameLabel);
    place(1, 0, mNameField, 4).setPadding(3);
    place(0, 1, serverAdressLabel);
    place(1, 1, mServerAddressField, 4).setPadding(3);
    place(0, 2, portLabel);
    place(1, 2, mPortField, 4).setPadding(3);
    place(0, 3, typeLabel);
    place(1, 3, mTypeField).setPadding(3);
    place(0, 4, descriptionLabel);
    place(1, 4, mDescriptionField, 4).setPadding(3);
    place(0, 5, onlineListUrlLabel);
    place(1, 5, mOnlineListUrlField, 4).setPadding(3);
    place(0, 6, packetVersionLabel);
    place(1, 6, mPacketVersionField, 4).setPadding(3);
    place(0, 7, mPersistentIp, 4).setPadding(3);
    place(0, 8, mConnectButton);
    place(4, 8, mOkButton);
    place(3, 8, mCancelButton);

    // Do this manually instead of calling reflowLayout so we can enforce a
    // minimum width.
    int width = 0;
    int height = 0;
    getLayout().reflow(width, height);
    if (width < 300)
    {
        width = 300;
        getLayout().reflow(width, height);
    }
    if (height < 120)
    {
        height = 120;
        getLayout().reflow(width, height);
    }

    setContentSize(width, height);

    setMinWidth(getWidth());
    setMinHeight(getHeight());
    setDefaultSize(getWidth(), getHeight(), ImagePosition::CENTER);

    setResizable(false);
    addKeyListener(this);

    loadWindowState();

    mNameField->setText(mServer.name);
    mDescriptionField->setText(mServer.description);
    mOnlineListUrlField->setText(mServer.onlineListUrl);
    mServerAddressField->setText(mServer.hostname);
    mPacketVersionField->setValue(mServer.packetVersion);
    mPortField->setText(toString(mServer.port));
    mPersistentIp->setSelected(mServer.persistentIp);

    switch (mServer.type)
    {
        case ServerType::EATHENA:
#ifdef TMWA_SUPPORT
            mTypeField->setSelected(1);
#else   // TMWA_SUPPORT
            mTypeField->setSelected(0);
#endif  // TMWA_SUPPORT
            break;
        default:
        case ServerType::UNKNOWN:
        case ServerType::TMWATHENA:
            mTypeField->setSelected(0);
            break;
        case ServerType::EVOL2:
#ifdef TMWA_SUPPORT
            mTypeField->setSelected(2);
#else   // TMWA_SUPPORT
            mTypeField->setSelected(1);
#endif  // TMWA_SUPPORT
            break;
    }

    setLocationRelativeTo(getParentWindow());
}
Ejemplo n.º 17
0
void SportsLayer::loadNet(){

	mark=0;
	float width=525;
	float hight=450;

	
	this->setContentSize(Size(width,hight));
    
	auto scal8=Scale9Sprite::create("ui_zhuye_daojukuang.png");
	scal8->setContentSize(Size(width,hight));

	
	scal8->setPosition(Vec2(getContentSize().width/2,getContentSize().height/2));
	addChild(scal8,100);


	jt1=Sprite::create("ui_zhuye_guanqiamoshi_guanqia_anniu_fanye.png");
	jt1->setPosition(Vec2(scal8->getPositionX()-scal8->getContentSize().width/2+jt1->getContentSize().width/2,scal8->getPositionY()));
	
	jt1->setRotationSkewY(180.0f);
	jt1->setVisible(false);
	scal8->addChild(jt1,100);

	jt2=Sprite::create("ui_zhuye_guanqiamoshi_guanqia_anniu_fanye.png");
	jt2->setPosition(Vec2(scal8->getPositionX()+scal8->getContentSize().width/2-jt1->getContentSize().width/2,scal8->getPositionY()));;
	jt2->setVisible(true);
	scal8->addChild(jt2,100);


	scroll_layer = Layer::create();//创建scrollView中的容器层   
	scroll_layer->setPosition(Vec2(0,0));  
	scroll_layer->setAnchorPoint(Vec2(0.0f,0.0f));  
	scroll_layer->setContentSize(Size(width*2,hight));//设置容器层大小为(600,300)   


  
	scrollView = ScrollView::create(Size(width,hight),scroll_layer);//创建scrollView,显示窗口大小为(400,300)   
    scrollView->setDelegate(this);//设置委托  
	scrollView->setContentOffset(Vec2::ZERO);//充当了锚点的作用  
	scrollView->setTouchEnabled(false);
    scrollView->setDirection(ScrollView::Direction::HORIZONTAL);//设置滚动方向为水平   

	scrollView->ignoreAnchorPointForPosition(false);
	scrollView->setAnchorPoint(Vec2(0.5,0.5));
    scrollView->setPosition(scal8->getPosition());  
	scal8->addChild(scrollView,20);  

	
	auto biti2=Sprite::create(Biti_imgstr2);
	biti2->setPosition(Vec2(scal8->getContentSize().width/2,0));
	scal8->addChild(biti2,1025);

    b_label=Label::createWithSystemFont(FX::StringsMap::getValue("wdfzsm"),"Arial",24);
	b_label->setPosition(Vec2(biti2->getContentSize().width/2,biti2->getContentSize().height/2));
	b_label->setColor(Color3B(0,0,0));
	biti2->addChild(b_label);
	
	auto jj_bg=Sprite::create(Biti_imgstr);
	jj_bg->setPosition(Vec2(width/2,hight));
	addChild(jj_bg,1025);

	auto jjgz=Label::createWithSystemFont(FX::StringsMap::getValue("jinjiguizhe"),"Arial",30);
	jjgz->setColor(Color3B(0,0,0));
	jjgz->setPosition(Vec2(jj_bg->getContentSize().width/2,jj_bg->getContentSize().height/2));
	jj_bg->addChild(jjgz,100);

	for(int i=0;i<2;i++){
		if(i==0){
			    
				drowFisrt(scroll_layer,Vec2(width*i+width/2,hight/2));
		 }else{
                drowSecond(scroll_layer,Vec2(width*i+width/2,hight/2));
				
		 }
	 }

}
Ejemplo n.º 18
0
void GiftListView::setListSize(float itemw,float itemh)
{
	int colsize = ceil((double)mPageSize/mPageRowSize);
	setContentSize(CCSizeMake((itemw+mItemIntervalH)*mPageRowSize - mItemIntervalH,
		colsize*(itemh+mItemIntervalV)-mItemIntervalV));
}
Ejemplo n.º 19
0
void SportsLayer::loadbasic(){

	float width=Actual_x*0.8f;
	float hight=Actual_y*0.8f;

	Color4B color =Color4B(0,0,0,100);
	LayerColor *colorLayer1 = LayerColor::create(color);
	
	colorLayer1->setContentSize(Size(Actual_x,Actual_y));
	addChild(colorLayer1,1);
	this->setContentSize(colorLayer1->getContentSize());


	auto scal8=Scale9Sprite::create("ui_zhuye_daojukuang.png");
	scal8->setContentSize(Size(width,hight));

	
	scal8->setPosition(Vec2(getContentSize().width/2,getContentSize().height/2));
	colorLayer1->addChild(scal8);


	jt1=Sprite::create("ui_zhuye_guanqiamoshi_guanqia_anniu_fanye.png");
	jt1->setPosition(Vec2(scal8->getPositionX()-scal8->getContentSize().width/2+jt1->getContentSize().width/2,scal8->getPositionY()));
	
	jt1->setRotationSkewY(180.0f);
	jt1->setVisible(false);
	colorLayer1->addChild(jt1,100);

	jt2=Sprite::create("ui_zhuye_guanqiamoshi_guanqia_anniu_fanye.png");
	jt2->setPosition(Vec2(scal8->getPositionX()+scal8->getContentSize().width/2-jt1->getContentSize().width/2,scal8->getPositionY()));
	//jt2->setFlippedY(180);
	jt2->setVisible(true);
	colorLayer1->addChild(jt2,100);


	scroll_layer = Layer::create();//创建scrollView中的容器层   
	scroll_layer->setPosition(Vec2(0,0));  
	scroll_layer->setAnchorPoint(Vec2(0.0f,0.0f));  
	scroll_layer->setContentSize(Size(width*2,hight));//设置容器层大小为(600,300)   


  
	scrollView = ScrollView::create(Size(width,hight),scroll_layer);//创建scrollView,显示窗口大小为(400,300)   
    scrollView->setDelegate(this);//设置委托  
	scrollView->setContentOffset(Vec2::ZERO);//充当了锚点的作用  
	scrollView->setTouchEnabled(false);
    scrollView->setDirection(ScrollView::Direction::HORIZONTAL);//设置滚动方向为水平   

	scrollView->ignoreAnchorPointForPosition(false);
	scrollView->setAnchorPoint(Vec2(0.5,0.5));
    scrollView->setPosition(scal8->getPosition());  
	colorLayer1->addChild(scrollView,20);  



	
	

	/*
	text_ts=Label::createWithSystemFont(FX::StringsMap::getValue("shujujiazz"),"Arial",30);
	text_ts->setColor(Color3B(0,0,0));
	text_ts->setPosition(Vec2(getContentSize().width/2,getContentSize().height/2));
	colorLayer1->addChild(text_ts,1000);
	*/
	
	auto close=MenuItemImage::create("ui_shangcheng_guanbi.png","ui_shangcheng_guanbi.png",CC_CALLBACK_1(SportsLayer::returnPa,this));
	close->setPosition(Vec2(scal8->getPositionX()+scal8->getContentSize().width/2-close->getContentSize().width/2,
		                    scal8->getPositionY()+scal8->getContentSize().height/2-close->getContentSize().height/2));


	auto menu = Menu::create(close,nullptr);
    menu->setPosition(Vec2::ZERO);
	colorLayer1->addChild(menu);
     

	for(int i=0;i<2;i++){
		if(i==0){
				drowSecond(scroll_layer,Vec2(width*i+width/2,hight/2));
		 }else{
				drowFisrt(scroll_layer,Vec2(width*i+width/2,hight/2));
		 }
	 }
}
Ejemplo n.º 20
0
void UpgradeUILayer::createStoneMaxUI()
{
    std::string fontFile = "DS-Digital.ttf";//"arial.ttf";
    int fontSize = 25;
    auto infoColor = DIY_COLOR_BLUE5;
    
    auto bk = Scale9Sprite::create("helpCellBG.png");
    auto bkSize = panelSize - Size(30,150);
    bk->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
    bk->setPosition(Point(panelSize.width/2,panelSize.height-70));
    bk->setContentSize(bkSize);
    _panel->addChild(bk);
    
    Point pos1(60,bkSize.height/2+80);
    Point pos2(260,bkSize.height/2+80);
    Point pos3(360,bkSize.height/2+80);
    Point pos4(400,bkSize.height/2+80);
    Point offset(0,-70);
    
    auto level_text = TextSprite::create(s_gameStrings.base->upgradeLevel,GameConfig::defaultFontName,fontSize);
    level_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_text->setPosition(pos1);
    bk->addChild(level_text);
    
    auto level_before = TextSprite::create(Value(s_playerConfig.stonecapacitylevel+1).asString(),GameConfig::defaultFontName,fontSize);
    level_before->setColor(infoColor);
    level_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_before->setPosition(pos2);
    bk->addChild(level_before);
    
    auto arrow_upgrade_0 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_0->setPosition(pos3);
    bk->addChild(arrow_upgrade_0);
    
    auto level_after = TextSprite::create(Value(s_playerConfig.stonecapacitylevel+2).asString(),GameConfig::defaultFontName,fontSize);
    level_after->setColor(infoColor);
    level_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_after->setPosition(pos4);
    bk->addChild(level_after);
    
    auto init_text = TextSprite::create(s_gameStrings.base->stoneinit,GameConfig::defaultFontName,fontSize);
    init_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    init_text->setPosition(pos1+offset);
    bk->addChild(init_text);
    
    auto init_before = TextSprite::create(Value(s_stoneCapacity[s_playerConfig.stonecapacitylevel].initstone).asString(),GameConfig::defaultFontName,fontSize);
    init_before->setColor(infoColor);
    init_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    init_before->setPosition(pos2+offset);
    bk->addChild(init_before);
    
    auto arrow_upgrade_1 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_1->setPosition(pos3+offset);
    bk->addChild(arrow_upgrade_1);
    
    auto init_after = TextSprite::create(Value(s_stoneCapacity[s_playerConfig.stonecapacitylevel+1].initstone).asString(),GameConfig::defaultFontName,fontSize);
    init_after->setColor(infoColor);
    init_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    init_after->setPosition(pos4+offset);
    bk->addChild(init_after);
    
    auto max_text = TextSprite::create(s_gameStrings.base->stonemax,GameConfig::defaultFontName,fontSize);
    max_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    max_text->setPosition(pos1+offset*2);
    bk->addChild(max_text);
    
    auto max_before = TextSprite::create(Value(s_stoneCapacity[s_playerConfig.stonecapacitylevel].maxstone).asString(),GameConfig::defaultFontName,fontSize);
    max_before->setColor(infoColor);
    max_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    max_before->setPosition(pos2+offset*2);
    bk->addChild(max_before);
    
    auto arrow_upgrade_2 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_2->setPosition(pos3+offset*2);
    bk->addChild(arrow_upgrade_2);
    
    auto max_after = TextSprite::create(Value(s_stoneCapacity[s_playerConfig.stonecapacitylevel+1].maxstone).asString(),GameConfig::defaultFontName,fontSize);
    max_after->setColor(infoColor);
    max_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    max_after->setPosition(pos4+offset*2);
    bk->addChild(max_after);

}
Ejemplo n.º 21
0
void BeingPopup::show(const int x, const int y, Being *const b)
{
    if (!b)
    {
        setVisible(false);
        return;
    }

    Label *label1 = mBeingParty;
    Label *label2 = mBeingGuild;
    Label *label3 = mBeingRank;
    Label *label4 = mBeingBuyBoard;
    Label *label5 = mBeingSellBoard;
    Label *label6 = mBeingComment;
    Label *label7 = mBeingRoom;

    b->updateComment();

    if (b->getType() == ActorType::Npc && b->getComment().empty())
    {
        setVisible(false);
        return;
    }

    mBeingName->setCaption(b->getName() + b->getGenderSignWithSpace());
    if (gui)
    {
        if (player_relations.isGoodName(b))
            mBeingName->setFont(boldFont);
        else
            mBeingName->setFont(gui->getSecureFont());
    }
    if (b->isAdvanced())
    {
        mBeingName->setForegroundColorAll(getThemeColor(
            Theme::PLAYER_ADVANCED), getThemeColor(
            Theme::PLAYER_ADVANCED_OUTLINE));
    }
    else
    {
        mBeingName->setForegroundColorAll(getThemeColor(Theme::POPUP),
            getThemeColor(Theme::POPUP_OUTLINE));
    }

    mBeingName->adjustSize();
    label1->setCaption("");
    label2->setCaption("");
    label3->setCaption("");
    label4->setCaption("");
    label5->setCaption("");
    label6->setCaption("");
    label7->setCaption("");

#ifdef EATHENA_SUPPORT
    const ActorType::Type type = b->getType();
    if (type == ActorType::Pet)
    {
        PetInfo *const info = PlayerInfo::getPet();
        if (info)
        {
            // TRANSLATORS: being popup label
            label1->setCaption(strprintf(_("Hungry: %d"),
                info->hungry));
            label1->adjustSize();
            // TRANSLATORS: being popup label
            label2->setCaption(strprintf(_("Intimacy: %d"),
                info->intimacy));
            label2->adjustSize();
            label3 = nullptr;
            label4 = nullptr;
            label5 = nullptr;
            label6 = nullptr;
            label7 = nullptr;
        }
    }
    else if (type == ActorType::Homunculus)
    {
        HomunculusInfo *const info = PlayerInfo::getHomunculus();
        if (info)
        {
            // TRANSLATORS: being popup label
            label1->setCaption(strprintf(_("Hungry: %d"),
                info->hungry));
            label1->adjustSize();
            // TRANSLATORS: being popup label
            label2->setCaption(strprintf(_("Intimacy: %d"),
                info->intimacy));
            label2->adjustSize();
            label3 = nullptr;
            label4 = nullptr;
            label5 = nullptr;
            label6 = nullptr;
            label7 = nullptr;
        }
    }
    else
#endif
    {
        if (!(b->getPartyName().empty()))
        {
            // TRANSLATORS: being popup label
            label1->setCaption(strprintf(_("Party: %s"),
                b->getPartyName().c_str()));
            label1->adjustSize();
        }
        else
        {
            label7 = label6;
            label6 = label5;
            label5 = label4;
            label4 = label3;
            label3 = label2;
            label2 = label1;
            label1 = nullptr;
        }

        if (!(b->getGuildName().empty()))
        {
            // TRANSLATORS: being popup label
            label2->setCaption(strprintf(_("Guild: %s"),
                b->getGuildName().c_str()));
            label2->adjustSize();
        }
        else
        {
            label7 = label6;
            label6 = label5;
            label5 = label4;
            label4 = label3;
            label3 = label2;
            label2 = nullptr;
        }

        if (b->getPvpRank() > 0)
        {
            // TRANSLATORS: being popup label
            label3->setCaption(strprintf(_("Pvp rank: %u"),
                b->getPvpRank()));
            label3->adjustSize();
        }
        else
        {
            label7 = label6;
            label6 = label5;
            label5 = label4;
            label4 = label3;
            label3 = nullptr;
        }

        if (!b->getBuyBoard().empty())
        {
            // TRANSLATORS: being popup label
            label4->setCaption(strprintf(_("Buy shop: %s"),
                b->getBuyBoard().c_str()));
            label4->adjustSize();
        }
        else
        {
            label7 = label6;
            label6 = label5;
            label5 = label4;
            label4 = nullptr;
        }

        if (!b->getSellBoard().empty())
        {
            // TRANSLATORS: being popup label
            label5->setCaption(strprintf(_("Sell shop: %s"),
                b->getSellBoard().c_str()));
            label5->adjustSize();
        }
        else
        {
            label7 = label6;
            label6 = label5;
            label5 = nullptr;
        }

        if (!b->getComment().empty())
        {
            // TRANSLATORS: being popup label
            label6->setCaption(strprintf(_("Comment: %s"),
                b->getComment().c_str()));
            label6->adjustSize();
        }
        else
        {
            label7 = label6;
            label6 = nullptr;
        }
#ifdef EATHENA_SUPPORT
        const ChatObject *const chat = b->getChat();
        if (chat)
        {
            // TRANSLATORS: being popup label
            label7->setCaption(strprintf(_("Chat room: %s"),
                chat->title.c_str()));
            label7->adjustSize();
        }
        else
        {
            label7 = nullptr;
        }
#endif
    }

    int minWidth = mBeingName->getWidth();
    if (label1 && label1->getWidth() > minWidth)
        minWidth = label1->getWidth();
    if (label2 && label2->getWidth() > minWidth)
        minWidth = label2->getWidth();
    if (label3 && label3->getWidth() > minWidth)
        minWidth = label3->getWidth();
    if (label4 && label4->getWidth() > minWidth)
        minWidth = label4->getWidth();
    if (label5 && label5->getWidth() > minWidth)
        minWidth = label5->getWidth();
    if (label6 && label6->getWidth() > minWidth)
        minWidth = label6->getWidth();
    if (label7 && label7->getWidth() > minWidth)
        minWidth = label7->getWidth();

    const int height1 = getFont()->getHeight();
    int height = height1;
    if (label1)
        height += height1;
    if (label2)
        height += height1;
    if (label3)
        height += height1;
    if (label4)
        height += height1;
    if (label5)
        height += height1;
    if (label6)
        height += height1;
    if (label7)
        height += height1;

    setContentSize(minWidth, height);
    position(x, y);
    return;
}
Ejemplo n.º 22
0
void UpgradeUILayer::createFlightUI()
{
    std::string fontFile = "DS-Digital.ttf";//"arial.ttf";
    int fontSize = 25;
    auto infoColor = DIY_COLOR_BLUE5;
    
    auto bk = Scale9Sprite::create("helpCellBG.png");
    auto bkSize = panelSize - Size(30,150);
    bk->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
    bk->setPosition(Point(panelSize.width/2,panelSize.height-70));
    bk->setContentSize(bkSize);
    _panel->addChild(bk);
    
    Point pos1(80,bkSize.height/2+120);
    Point pos2(260,bkSize.height/2+120);
    Point pos3(360,bkSize.height/2+120);
    Point pos4(400,bkSize.height/2+120);
    Point offset(0,-40);
    
    auto level_text = TextSprite::create(s_gameStrings.base->upgradeLevel,GameConfig::defaultFontName,fontSize);
    level_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_text->setPosition(pos1);
    bk->addChild(level_text);
    
    auto level_before = TextSprite::create(Value(s_playerConfig.fighterslevel[_index]+1).asString(),GameConfig::defaultFontName,fontSize);
    level_before->setColor(infoColor);
    level_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_before->setPosition(pos2);
    bk->addChild(level_before);
    
    auto arrow_upgrade_0 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_0->setPosition(pos3);
    bk->addChild(arrow_upgrade_0);
    
    auto level_after = TextSprite::create(Value(s_playerConfig.fighterslevel[_index]+2).asString(),GameConfig::defaultFontName,fontSize);
    level_after->setColor(infoColor);
    level_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_after->setPosition(pos4);
    bk->addChild(level_after);
    
    auto life_text = TextSprite::create(s_gameStrings.base->upgradeLife,GameConfig::defaultFontName,fontSize);
    life_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    life_text->setPosition(pos1+offset);
    bk->addChild(life_text);
    
    auto life_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].life).asString(),GameConfig::defaultFontName,fontSize);
    life_before->setColor(infoColor);
    life_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    life_before->setPosition(pos2+offset);
    bk->addChild(life_before);
    
    auto arrow_upgrade_1 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_1->setPosition(pos3+offset);
    bk->addChild(arrow_upgrade_1);
    
    auto life_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].life).asString(),GameConfig::defaultFontName,fontSize);
    life_after->setColor(infoColor);
    life_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    life_after->setPosition(pos4+offset);
    bk->addChild(life_after);
    
    auto attack_text = TextSprite::create(s_gameStrings.base->upgradeAtt,GameConfig::defaultFontName,fontSize);
    attack_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_text->setPosition(pos1+offset*2);
    bk->addChild(attack_text);
    
    auto attack_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].attack).asString(),GameConfig::defaultFontName,fontSize);
    attack_before->setColor(infoColor);
    attack_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_before->setPosition(pos2+offset*2);
    bk->addChild(attack_before);
    
    auto arrow_upgrade_2 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_2->setPosition(pos3+offset*2);
    bk->addChild(arrow_upgrade_2);
    
    auto attack_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].attack).asString(),GameConfig::defaultFontName,fontSize);
    attack_after->setColor(infoColor);
    attack_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_after->setPosition(pos4+offset*2);
    bk->addChild(attack_after);
    
    auto defense_text = TextSprite::create(s_gameStrings.base->upgradeDef,GameConfig::defaultFontName,fontSize);
    defense_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    defense_text->setPosition(pos1+offset*3);
    bk->addChild(defense_text);
    
    auto defense_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].defense).asString(),GameConfig::defaultFontName,fontSize);
    defense_before->setColor(infoColor);
    defense_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    defense_before->setPosition(pos2+offset*3);
    bk->addChild(defense_before);
    
    auto arrow_upgrade_3 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_3->setPosition(pos3+offset*3);
    bk->addChild(arrow_upgrade_3);
    
    auto defense_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].defense).asString(),GameConfig::defaultFontName,fontSize);
    defense_after->setColor(infoColor);
    defense_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    defense_after->setPosition(pos4+offset*3);
    bk->addChild(defense_after);
    
    auto speed_text = TextSprite::create(s_gameStrings.base->upgradeSpd,GameConfig::defaultFontName,fontSize);
    speed_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    speed_text->setPosition(pos1+offset*4);
    bk->addChild(speed_text);
    
    auto speed_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].speed).asString(),GameConfig::defaultFontName,fontSize);
    speed_before->setColor(infoColor);
    speed_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    speed_before->setPosition(pos2+offset*4);
    bk->addChild(speed_before);
    
    auto arrow_upgrade_4 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_4->setPosition(pos3+offset*4);
    bk->addChild(arrow_upgrade_4);
    
    auto speed_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].speed).asString(),GameConfig::defaultFontName,fontSize);
    speed_after->setColor(infoColor);
    speed_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    speed_after->setPosition(pos4+offset*4);
    bk->addChild(speed_after);

    auto range_text = TextSprite::create(s_gameStrings.base->upgradeRange,GameConfig::defaultFontName,fontSize);
    range_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    range_text->setPosition(pos1+offset*5);
    bk->addChild(range_text);
    
    auto range_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].range).asString(),GameConfig::defaultFontName,fontSize);
    range_before->setColor(infoColor);
    range_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    range_before->setPosition(pos2+offset*5);
    bk->addChild(range_before);
    
    auto arrow_upgrade_5 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_5->setPosition(pos3+offset*5);
    bk->addChild(arrow_upgrade_5);
    
    auto range_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].range).asString(),GameConfig::defaultFontName,fontSize);
    range_after->setColor(infoColor);
    range_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    range_after->setPosition(pos4+offset*5);
    bk->addChild(range_after);
    
    auto usestone_text = TextSprite::create(s_gameStrings.base->useStone,GameConfig::defaultFontName,fontSize);
    usestone_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    usestone_text->setPosition(pos1+offset*6);
    bk->addChild(usestone_text);
    
    auto usestone_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].sparForMake).asString(),GameConfig::defaultFontName,fontSize);
    usestone_before->setColor(infoColor);
    usestone_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    usestone_before->setPosition(pos2+offset*6);
    bk->addChild(usestone_before);
    
    auto arrow_upgrade_6 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_6->setPosition(pos3+offset*6);
    bk->addChild(arrow_upgrade_6);
    
    auto usestone_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].sparForMake).asString(),GameConfig::defaultFontName,fontSize);
    usestone_after->setColor(infoColor);
    usestone_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    usestone_after->setPosition(pos4+offset*6);
    bk->addChild(usestone_after);
}
Ejemplo n.º 23
0
ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
    Window(_("Choose Your Server")),
    mDir(dir),
    mDownloadStatus(DOWNLOADING_PREPARING),
    mDownloadProgress(-1.0f),
    mServers(ServerInfos()),
    mServerInfo(serverInfo)
{
    setWindowName("ServerDialog");

    Label *serverLabel = new Label(_("Server:"));
    Label *portLabel = new Label(_("Port:"));
    Label *typeLabel = new Label(_("Server type:"));
    mServerNameField = new TextField(mServerInfo->hostname);
    mPortField = new TextField(toString(mServerInfo->port));

    loadCustomServers();

    mServersListModel = new ServersListModel(&mServers, this);

    mServersList = new ServersListBox(mServersListModel);

    ScrollArea *usedScroll = new ScrollArea(mServersList);
    usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);

    mTypeListModel = new TypeListModel();
    mTypeField = new DropDown(mTypeListModel);
    mTypeField->setSelected((serverInfo->type == ServerInfo::MANASERV) ?
                            1 : 0);

    mDescription = new Label(std::string());

    mQuitButton = new Button(_("Quit"), "quit", this);
    mConnectButton = new Button(_("Connect"), "connect", this);
    mManualEntryButton = new Button(_("Custom Server"), "addEntry", this);
    mDeleteButton = new Button(_("Delete"), "remove", this);

    mServerNameField->setActionEventId("connect");
    mPortField->setActionEventId("connect");

    mServerNameField->addActionListener(this);
    mPortField->addActionListener(this);
    mManualEntryButton->addActionListener(this);
    mServersList->addSelectionListener(this);
    usedScroll->setVerticalScrollAmount(0);

    place(0, 0, serverLabel);
    place(1, 0, mServerNameField, 4).setPadding(3);
    place(0, 1, portLabel);
    place(1, 1, mPortField, 4).setPadding(3);
    place(0, 2, typeLabel);
    place(1, 2, mTypeField, 4).setPadding(3);
    place(0, 3, usedScroll, 5, 5).setPadding(3);
    place(0, 8, mDescription, 5);
    place(0, 9, mManualEntryButton);
    place(1, 9, mDeleteButton);
    place(3, 9, mQuitButton);
    place(4, 9, mConnectButton);

    // Make sure the list has enough height
    getLayout().setRowHeight(3, 80);

    // Do this manually instead of calling reflowLayout so we can enforce a
    // minimum width.
    int width = 0, height = 0;
    getLayout().reflow(width, height);
    if (width < 400)
    {
        width = 400;
        getLayout().reflow(width, height);
    }

    setContentSize(width, height);

    setMinWidth(getWidth());
    setMinHeight(getHeight());
    setDefaultSize(getWidth(), getHeight(), ImageRect::CENTER);

    setResizable(true);
    addKeyListener(this);

    loadWindowState();

    setFieldsReadOnly(true);
    mServersList->setSelected(0); // Do this after for the Delete button
    setVisible(true);

    if (mServerNameField->getText().empty())
    {
        mServerNameField->requestFocus();
    }
    else
    {
        if (mPortField->getText().empty())
            mPortField->requestFocus();
        else
            mConnectButton->requestFocus();
    }

    downloadServerList();
}
Ejemplo n.º 24
0
void UpgradeUILayer::createWeaponUI()
{
    std::string fontFile = "DS-Digital.ttf";//"arial.ttf";
    int fontSize = 25;
    auto infoColor = DIY_COLOR_BLUE5;
    
    auto bk = Scale9Sprite::create("helpCellBG.png");
    auto bkSize = panelSize - Size(30,150);
    bk->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
    bk->setPosition(Point(panelSize.width/2,panelSize.height-70));
    bk->setContentSize(bkSize);
    _panel->addChild(bk);
    
    Point pos1(60,bkSize.height/2+95);
    Point pos2(220,bkSize.height/2+95);
    Point pos3(350,bkSize.height/2+95);
    Point pos4(400,bkSize.height/2+95);
    Point offset(0,-50);
    
    auto level_text = TextSprite::create(s_gameStrings.base->upgradeLevel,GameConfig::defaultFontName,fontSize);
    level_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_text->setPosition(pos1);
    bk->addChild(level_text);
    
    auto level_before = TextSprite::create(Value(s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1).asString(),GameConfig::defaultFontName,fontSize);
    level_before->setColor(infoColor);
    level_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_before->setPosition(pos2);
    bk->addChild(level_before);
    
    auto arrow_upgrade_0 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_0->setPosition(pos3);
    bk->addChild(arrow_upgrade_0);
    
    auto level_after = TextSprite::create(Value(s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+2).asString(),GameConfig::defaultFontName,fontSize);
    level_after->setColor(infoColor);
    level_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_after->setPosition(pos4);
    bk->addChild(level_after);
    
    auto attack_text = TextSprite::create(s_gameStrings.base->upgradeAtt,GameConfig::defaultFontName,fontSize);
    attack_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_text->setPosition(pos1+offset);
    bk->addChild(attack_text);
    
    auto attack_before = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]].attack).asString(),GameConfig::defaultFontName,fontSize);
    attack_before->setColor(infoColor);
    attack_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_before->setPosition(pos2+offset);
    bk->addChild(attack_before);
    
    auto arrow_upgrade_1 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_1->setPosition(pos3+offset*1);
    bk->addChild(arrow_upgrade_1);
    
    auto attack_after = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1].attack).asString(),GameConfig::defaultFontName,fontSize);
    attack_after->setColor(infoColor);
    attack_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_after->setPosition(pos4+offset);
    bk->addChild(attack_after);
    
    auto duration_text = TextSprite::create(s_gameStrings.base->upgradeDuration,GameConfig::defaultFontName,fontSize);
    duration_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    duration_text->setPosition(pos1+offset*2);
    bk->addChild(duration_text);
    
    char p[30];
    float duration_before_data = s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]].duration;
    sprintf(p, "%.2f",duration_before_data);
    auto duration_before = TextSprite::create(p,GameConfig::defaultFontName,fontSize);
    duration_before->setColor(infoColor);
    duration_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    duration_before->setPosition(pos2+offset*2);
    bk->addChild(duration_before);
    
    auto arrow_upgrade_2 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_2->setPosition(pos3+offset*2);
    bk->addChild(arrow_upgrade_2);
    
    float duration_after_data = s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1].duration;
    sprintf(p, "%.2f",duration_after_data);
    auto duration_after = TextSprite::create(p,GameConfig::defaultFontName,fontSize);
    duration_after->setColor(infoColor);
    duration_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    duration_after->setPosition(pos4+offset*2);
    bk->addChild(duration_after);
    
    auto buyusegem_text = TextSprite::create(s_gameStrings.base->buyusegem,GameConfig::defaultFontName,fontSize);
    buyusegem_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buyusegem_text->setPosition(pos1+offset*3);
    bk->addChild(buyusegem_text);
    
    auto buyusegem_before = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]].costGem).asString(),GameConfig::defaultFontName,fontSize);
    buyusegem_before->setColor(infoColor);
    buyusegem_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buyusegem_before->setPosition(pos2+offset*3);
    bk->addChild(buyusegem_before);
    
    auto arrow_upgrade_3 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_3->setPosition(pos3+offset*3);
    bk->addChild(arrow_upgrade_3);
    
    auto buyusegem_after = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1].costGem).asString(),GameConfig::defaultFontName,fontSize);
    buyusegem_after->setColor(infoColor);
    buyusegem_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buyusegem_after->setPosition(pos4+offset*3);
    bk->addChild(buyusegem_after);
    
    auto buymax_text = TextSprite::create(s_gameStrings.base->buymax,GameConfig::defaultFontName,fontSize);
    buymax_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buymax_text->setPosition(pos1+offset*4);
    bk->addChild(buymax_text);
    
    auto buymax_before = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]].capacity).asString(),GameConfig::defaultFontName,fontSize);
    buymax_before->setColor(infoColor);
    buymax_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buymax_before->setPosition(pos2+offset*4);
    bk->addChild(buymax_before);
    
    auto arrow_upgrade_4 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_4->setPosition(pos3+offset*4);
    bk->addChild(arrow_upgrade_4);
    
    auto buymax_after = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1].capacity).asString(),GameConfig::defaultFontName,fontSize);
    buymax_after->setColor(infoColor);
    buymax_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buymax_after->setPosition(pos4+offset*4);
    bk->addChild(buymax_after);

}
Ejemplo n.º 25
0
void CCScrollBar::attachToScrollView(ScrollView* scrollView, ccInsets insets, bool horizontal) {
	// save flag
	m_horizontal = horizontal;
	
	// add to scroll view
	float thumbLength = 0;
	Widget* svParent = dynamic_cast<Widget*>(scrollView->getParent());
	CCSize svSize = scrollView->getSize();
	CCPoint svOrigin = CCUtils::getOrigin(scrollView);
	CCSize innerSize = scrollView->getInnerContainerSize();
	CCSize sbSize;
	if(horizontal) {
		sbSize = CCSizeMake(m_track->getContentSize().width,
							svSize.width - insets.left - insets.right);
		setContentSize(sbSize);
		setAnchorPoint(ccp(0, 0.5f));
		setPosition(ccp(svOrigin.x + svSize.width / 2,
						svOrigin.y + insets.bottom));
		setRotation(-90);
		svParent->addNode(this, MAX_INT);
		
		// thumb length
		if(m_fixedThumb)
			thumbLength = m_fixedThumb->getContentSize().height;
		else
			thumbLength = MIN(1, svSize.width / innerSize.width) * sbSize.height;
	} else {
		sbSize = CCSizeMake(m_track->getContentSize().width,
							svSize.height - insets.top - insets.bottom);
		setContentSize(sbSize);
		setAnchorPoint(ccp(1, 0.5f));
		setPosition(ccp(svOrigin.x + svSize.width - insets.right,
						svOrigin.y + svSize.height / 2));
		svParent->addNode(this, MAX_INT);
		
		// thumb length
		if(m_fixedThumb)
			thumbLength = m_fixedThumb->getContentSize().height;
		else
			thumbLength = MIN(1, svSize.height / innerSize.height) * sbSize.height;
	}
	
	// add track
	m_track->setPreferredSize(sbSize);
	m_track->setPosition(CCUtils::getLocalCenter(this));
	addChild(m_track);
	
	// clipping node to hold thumb
	CCClippingNode* thumbClipping = CCClippingNode::create(m_track);
	thumbClipping->ignoreAnchorPointForPosition(false);
	thumbClipping->setAnchorPoint(ccp(0.5f, 0.5f));
	thumbClipping->setContentSize(sbSize);
	thumbClipping->setPosition(CCUtils::getLocalCenter(this));
	thumbClipping->setAlphaThreshold(0.5f);
	thumbClipping->setScaleX((sbSize.width - 4) / sbSize.width);
	thumbClipping->setScaleY((sbSize.height - 4) / sbSize.height);
	addChild(thumbClipping);
	
	// thumb or fixed thumb
	if(m_thumb) {
		m_thumb->setPreferredSize(CCSizeMake(sbSize.width, thumbLength));
		m_thumb->setPosition(ccp(sbSize.width / 2,
								 sbSize.height - thumbLength / 2));
		thumbClipping->addChild(m_thumb);
	} else {
		m_fixedThumb->setPosition(ccp(sbSize.width / 2,
									  sbSize.height - thumbLength / 2));
		thumbClipping->addChild(m_fixedThumb);
	}
	
	// sync thumb position
	syncThumbPositionSizeForScrollView(scrollView);
	
	// listen to scrollview scrolling event
	scrollView->addEventListenerScrollView(this, scrollvieweventselector(CCScrollBar::onScrollViewEvent));
    
    // init fade out
    if(m_initFadeOut) {
        m_fadingOut = true;
        CCUtils::setOpacityRecursively(this, 0);
    }
}
Ejemplo n.º 26
0
bool LayerMenu::init(Point posWorld, cocos2d::Size sizeElement, const msg::Property& property)
{
    if(!Layer::init()) {
        return false;
    }
    
    posWorld_ = posWorld;
    sizeElement_ = sizeElement;
    property_ = property;
    
    auto layout = Layout::create();
    layout->setContentSize(Director::getInstance()->getWinSize());
    layout->setTouchEnabled(true);
    layout->addClickEventListener([this](Ref*) {
        this->removeFromParentAndCleanup(true);
    });
    this->addChild(layout, -1);
    
    this->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
    this->setSwallowsTouches(true);
    LayerColor * layer = LayerColor::create(Color4B(200, 200, 200, 100));
    this->addChild(layer);

    switch (property_.type())
    {
        case msg::PropertyType::ENUM:
        {
            for (int i =0; i < property_.enumvalue().items().size() ; i++)
            {
                auto item = property_.enumvalue().items(i);
//                Menu *menu = Menu::create();
//                menu->setPosition(Vec2(0, 0));
//                
//                Sprite *sprite = Sprite::create("login_res/creategameroom_res/btn_enum_normal.png");
//                MenuItemSprite *menuItemSprite = MenuItemSprite::create(sprite, sprite, this, menu_selector(LayerMenu::click_menu));
//                //menu->addChild(menuItemSprite);
//                //this->addChild(menu);
//                menuItemSprite->setTag(property_.enumvalue().items(i).value());
//                menuItemSprite->setPosition(Vec2(posWorld.x, posWorld.y - sizeElement.height * (i)));
                //                this->addChild(menuItemSprite);
                Button *cell = Button::create();

                cell->loadTextures("login_res/creategameroom_res/btn_enum_normal.png", "login_res/creategameroom_res/btn_enum_normal.png");
                                cell->setTitleFontSize(28);
                                cell->setContentSize(sizeElement);
//                menuItemSprite->setAnchorPoint(cell->getAnchorPoint());
                cell->setTitleText(item.text());

                cell->setTitleColor(cocos2d::Color3B(151, 151, 151));
                cell->setPosition(Vec2(posWorld.x,posWorld.y - sizeElement.height * (i) -1 ));
                cell->setTag(property_.enumvalue().items(i).value());
                cell->addClickEventListener(std::bind(&LayerMenu::click_menu, this,std::placeholders::_1));
                this->addChild(cell);
            }
            
        }
            break;
            
        default:
            break;
    }
    
    return true;
}
Ejemplo n.º 27
0
void Sensors::showSensorList() {
    // get http response
    auto http_response_data =
        lib::network::DataStoreSingleton::getInstance()->getResponseData(
            lib::network::DataStoreSingleton::Request_Pointcast_Home_e);

    const char* json = http_response_data.c_str();

    // JSON解析
    rapidjson::Document document;
    document.Parse<0>(json);
    if (document.HasParseError()) {
        // 解析エラー
        assert(false);
        return;
    }

    // read list view
    auto p_panel =
        this->_p_contents->getChildByName<ui::Layout*>("panelBackground");

    auto p_list_view = p_panel->getChildByName<ui::ListView*>("listSensors");
    p_list_view->setInnerContainerSize(p_list_view->getContentSize());
    p_list_view->setBounceEnabled(true);
    p_list_view->setTouchEnabled(true);

    p_list_view->addEventListener(
        [this](Ref* ref, ui::ListView::EventType eventType) {
            if (eventType == ui::ListView::EventType::ON_SELECTED_ITEM_END) {
                auto listView = static_cast<ui::ListView*>(ref);
                auto selectedIndex = listView->getCurSelectedIndex();

                // revert color all record
                for (auto widget : listView->getItems()) {
                    auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record);
                    p_record->getChildByName<ui::Layout*>("panelRecord")
                        ->setColor(Color3B::WHITE);
                }
                // change color selected record
                auto widget = listView->getItem(selectedIndex);
                auto p_record = widget->getChildByTag(Tag_Id_Sensor_Record);
                p_record->getChildByName<ui::Layout*>("panelRecord")
                    ->setColor(Color3B(250, 219, 218));
                CCLOG("selected index %ld", selectedIndex);

                this->showAnalyticsDialog(widget->getTag());
            } else {
                CCLOG("touch list event type %d", eventType);
            }
        });

    std::map<int, lib::object::LocationItem> m_sensors =
        lib::network::DataStoreSingleton::getInstance()->getLocationItemAll();

    for (auto item : m_sensors) {
        auto p_record =
            CSLoader::getInstance()->createNode("res/sensors_record.csb");

        this->setMesurementData(p_record, item.second);

        auto widget = ui::Widget::create();
        p_record->setTag(Tag_Id_Sensor_Record);
        widget->addChild(p_record);
        widget->setTag(item.second.m_sensor_main_id);

        widget->setContentSize(p_record->getContentSize());
        p_list_view->pushBackCustomItem(widget);

        widget->setTouchEnabled(true);  // enable listview touch event
    }
}
Ejemplo n.º 28
0
CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
                                   const int slot) :
    // TRANSLATORS: char create dialog name
    Window(_("New Character"), Modal_true, parent, "charcreate.xml"),
    ActionListener(),
    KeyListener(),
    mCharSelectDialog(parent),
    mNameField(new TextField(this, "")),
    // TRANSLATORS: char create dialog label
    mNameLabel(new Label(this, _("Name:"))),
    // TRANSLATORS: This is a narrow symbol used to denote 'next'.
    // You may change this symbol if your language uses another.
    // TRANSLATORS: char create dialog button
    mNextHairColorButton(new Button(this, _(">"), "nextcolor", this)),
    // TRANSLATORS: This is a narrow symbol used to denote 'previous'.
    // You may change this symbol if your language uses another.
    // TRANSLATORS: char create dialog button
    mPrevHairColorButton(new Button(this, _("<"), "prevcolor", this)),
    // TRANSLATORS: char create dialog label
    mHairColorLabel(new Label(this, _("Hair color:"))),
    mHairColorNameLabel(new Label(this, "")),
    // TRANSLATORS: char create dialog button
    mNextHairStyleButton(new Button(this, _(">"), "nextstyle", this)),
    // TRANSLATORS: char create dialog button
    mPrevHairStyleButton(new Button(this, _("<"), "prevstyle", this)),
    // TRANSLATORS: char create dialog label
    mHairStyleLabel(new Label(this, _("Hair style:"))),
    mHairStyleNameLabel(new Label(this, "")),
    mNextRaceButton(nullptr),
    mPrevRaceButton(nullptr),
    mRaceLabel(nullptr),
    mRaceNameLabel(nullptr),
    mNextLookButton(nullptr),
    mPrevLookButton(nullptr),
    mLookLabel(nullptr),
    mLookNameLabel(nullptr),
    // TRANSLATORS: char create dialog button
    mActionButton(new Button(this, _("^"), "action", this)),
    // TRANSLATORS: char create dialog button
    mRotateButton(new Button(this, _(">"), "rotate", this)),
    mAttributeSlider(),
    mAttributeLabel(),
    mAttributeValue(),
    mAttributesLeft(new Label(this,
        // TRANSLATORS: char create dialog label
        strprintf(_("Please distribute %d points"), 99))),
    // TRANSLATORS: char create dialog button
    mCreateButton(new Button(this, _("Create"), "create", this)),
    // TRANSLATORS: char create dialog button
    mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
    mPlayer(new Being(BeingId_zero,
            ActorType::Player,
            BeingTypeId_zero,
            nullptr)),
    mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml",
        "charcreate_selectedplayerbox.xml")),
    mGenderStrip(nullptr),
    mMaxPoints(0),
    mUsedPoints(0),
    mRace(CharDB::getMinRace()),
    mLook(0),
    mMinLook(CharDB::getMinLook()),
    mMaxLook(CharDB::getMaxLook()),
    mMinRace(CharDB::getMinRace()),
    mMaxRace(CharDB::getMaxRace()),
    mHairStyle(0),
    mHairColor(0),
    mSlot(slot),
    mDefaultGender(Gender::FEMALE),
    mGender(Gender::UNSPECIFIED),
    maxHairColor(CharDB::getMaxHairColor()),
    minHairColor(CharDB::getMinHairColor()),
    maxHairStyle(CharDB::getMaxHairStyle()),
    minHairStyle(CharDB::getMinHairStyle()),
    mAction(0),
    mDirection(0)
{
    setStickyButtonLock(true);
    setSticky(true);
    setWindowName("NewCharacter");

    const int w = 480;
    const int h = 350;
    setContentSize(w, h);

    mPlayer->setGender(Gender::MALE);
    const std::vector<int> &items = CharDB::getDefaultItems();
    int i = 1;
    for (std::vector<int>::const_iterator it = items.begin(),
         it_end = items.end();
         it != it_end; ++ it, i ++)
    {
        mPlayer->setSprite(i, *it);
    }

    if (!maxHairColor)
        maxHairColor = ColorDB::getHairSize();
    if (!maxHairStyle)
        maxHairStyle = mPlayer->getNumOfHairstyles();

    if (maxHairStyle)
    {
        mHairStyle = (static_cast<unsigned int>(rand())
            % maxHairStyle) + minHairStyle;
    }
    else
    {
        mHairStyle = 0;
    }
    if (maxHairColor)
    {
        mHairColor = (static_cast<unsigned int>(rand())
            % maxHairColor) + minHairColor;
    }
    else
    {
        mHairColor = 0;
    }

    mNameField->setMaximum(24);

    if (serverFeatures->haveRaceSelection())
    {
        // TRANSLATORS: char create dialog button
        mNextRaceButton = new Button(this, _(">"), "nextrace", this);
        // TRANSLATORS: char create dialog button
        mPrevRaceButton = new Button(this, _("<"), "prevrace", this);
        // TRANSLATORS: char create dialog label
        mRaceLabel = new Label(this, _("Race:"));
        mRaceNameLabel = new Label(this, "");
    }
    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        // TRANSLATORS: char create dialog button
        mNextLookButton = new Button(this, _(">"), "nextlook", this);
        // TRANSLATORS: char create dialog button
        mPrevLookButton = new Button(this, _("<"), "prevlook", this);
        // TRANSLATORS: char create dialog label
        mLookLabel = new Label(this, _("Look:"));
        mLookNameLabel = new Label(this, "");
    }

    if (serverFeatures->haveCreateCharGender())
    {
        const int size = config.getIntValue("fontSize");
        mGenderStrip = new TabStrip(this,
            "gender_" + getWindowName(),
            size + 16);
        mGenderStrip->setPressFirst(false);
        mGenderStrip->addActionListener(this);
        mGenderStrip->setActionEventId("gender_");
        // TRANSLATORS: one char size female character gender
        mGenderStrip->addButton(_("F"), "f", false);
        // TRANSLATORS: one char size male character gender
        mGenderStrip->addButton(_("M"), "m", false);
        // TRANSLATORS: one char size unknown character gender
        mGenderStrip->addButton(_("U"), "u", true);
        mGenderStrip->setVisible(Visible_true);
        add(mGenderStrip);

        mGenderStrip->setPosition(385, 130);
        mGenderStrip->setWidth(500);
        mGenderStrip->setHeight(50);
    }

    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mPlayerBox->setDimension(Rect(360, 0, 110, 90));
    mActionButton->setPosition(385, 100);
    mRotateButton->setPosition(415, 100);

    mNameLabel->setPosition(5, 2);
    mNameField->setDimension(
            Rect(60, 2, 300, mNameField->getHeight()));

    const int leftX = 120;
    const int rightX = 300;
    const int labelX = 5;
    const int nameX = 145;
    int y = 30;

    mPrevHairColorButton->setPosition(leftX, y);
    mNextHairColorButton->setPosition(rightX, y);
    y += 5;
    mHairColorLabel->setPosition(labelX, y);
    mHairColorNameLabel->setPosition(nameX, y);
    y += 24;
    mPrevHairStyleButton->setPosition(leftX, y);
    mNextHairStyleButton->setPosition(rightX, y);
    y += 5;
    mHairStyleLabel->setPosition(labelX, y);
    mHairStyleNameLabel->setPosition(nameX, y);

    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        y += 24;
        if (mPrevLookButton)
            mPrevLookButton->setPosition(leftX, y);
        if (mNextLookButton)
            mNextLookButton->setPosition(rightX, y);
        y += 5;
        if (mLookLabel)
            mLookLabel->setPosition(labelX, y);
        if (mLookNameLabel)
            mLookNameLabel->setPosition(nameX, y);  // 93
    }
    if (serverFeatures->haveRaceSelection())
    {
        y += 24;
        if (mPrevRaceButton)
            mPrevRaceButton->setPosition(leftX, y);
        if (mNextRaceButton)
            mNextRaceButton->setPosition(rightX, y);
        y += 5;
        if (mRaceLabel)
            mRaceLabel->setPosition(labelX, y);
        if (mRaceNameLabel)
            mRaceNameLabel->setPosition(nameX, y);
    }

    updateSliders();
    setButtonsPosition(w, h);

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mHairColorNameLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mHairStyleNameLabel);
    add(mActionButton);
    add(mRotateButton);

    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        add(mNextLookButton);
        add(mPrevLookButton);
        add(mLookLabel);
        add(mLookNameLabel);
    }

    if (serverFeatures->haveRaceSelection())
    {
        add(mNextRaceButton);
        add(mPrevRaceButton);
        add(mRaceLabel);
        add(mRaceNameLabel);
    }

    add(mAttributesLeft);
    add(mCreateButton);
    add(mCancelButton);

    center();
    setVisible(Visible_true);
    mNameField->requestFocus();

    updateHair();
    if (serverFeatures->haveRaceSelection())
        updateRace();
    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
        updateLook();
    updatePlayer();

    addKeyListener(this);
}
bool LuaTouchEventManager::initWithSize(const Size& size)
{
    setContentSize(size);
    return true;
}
Ejemplo n.º 30
0
CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
    Window(_("Create Character"), true, parent),
    mCharSelectDialog(parent),
    mSlot(slot)
{
    mPlayer = new Being(0, ActorSprite::PLAYER, 0, NULL);
    mPlayer->setGender(GENDER_MALE);

    mHairStylesIds = hairDB.getHairStyleIds(
        Net::getCharHandler()->getCharCreateMaxHairStyleId());
    mHairStyleId = rand() * mHairStylesIds.size() / RAND_MAX;

    mHairColorsIds = hairDB.getHairColorIds(
        Net::getCharHandler()->getCharCreateMaxHairColorId());
    mHairColorId = rand() * mHairColorsIds.size() / RAND_MAX;

    updateHair();

    mNameField = new TextField("");
    mNameLabel = new Label(_("Name:"));

    mNextHairColorButton = new Button("", "nextcolor", this);
    mPrevHairColorButton = new Button("", "prevcolor", this);
    mPrevHairColorButton->setButtonIcon("tab_arrows_left.png");
    mNextHairColorButton->setButtonIcon("tab_arrows_right.png");

    mHairColorLabel = new Label(_("Hair color:"));
    mNextHairStyleButton = new Button("", "nextstyle", this);
    mPrevHairStyleButton = new Button("", "prevstyle", this);
    mPrevHairStyleButton->setButtonIcon("tab_arrows_left.png");
    mNextHairStyleButton->setButtonIcon("tab_arrows_right.png");

    mHairStyleLabel = new Label(_("Hair style:"));
    mCreateButton = new Button(_("Create"), "create", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);
    mMale = new RadioButton(_("Male"), "gender");
    mFemale = new RadioButton(_("Female"), "gender");

    // Default to a Male character
    mMale->setSelected(true);

    mMale->setActionEventId("gender");
    mFemale->setActionEventId("gender");

    mMale->addActionListener(this);
    mFemale->addActionListener(this);

    mPlayerBox = new PlayerBox(mPlayer);
    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mAttributesLeft = new Label(
            strprintf(_("Please distribute %d points"), 99));

    int w = 200;
    int h = 330;
    setContentSize(w, h);
    mPlayerBox->setDimension(gcn::Rectangle(80, 30, 110, 85));
    mNameLabel->setPosition(5, 5);
    mNameField->setDimension(
            gcn::Rectangle(45, 5, w - 45 - 7, mNameField->getHeight()));
    mPrevHairColorButton->setPosition(90, 35);
    mNextHairColorButton->setPosition(165, 35);
    mHairColorLabel->setPosition(5, 40);
    mPrevHairStyleButton->setPosition(90, 64);
    mNextHairStyleButton->setPosition(165, 64);
    mHairStyleLabel->setPosition(5, 70);
    mAttributesLeft->setPosition(15, 280);
    updateSliders();
    mCancelButton->setPosition(
            w - 5 - mCancelButton->getWidth(),
            h - 5 - mCancelButton->getHeight());
    mCreateButton->setPosition(
            mCancelButton->getX() - 5 - mCreateButton->getWidth(),
            h - 5 - mCancelButton->getHeight());

    mMale->setPosition(30, 120);
    mFemale->setPosition(100, 120);

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mAttributesLeft);
    add(mCreateButton);
    add(mCancelButton);

    add(mMale);
    add(mFemale);

    center();
    setVisible(true);
    mNameField->requestFocus();
}