示例#1
0
float ITools::getTextSpriteScale(Text* text, Sprite* sprite)            //获取字体与底下背景图片所要拉伸的比例
{
    float f;
    f = (text->getContentSize().width + 50) / (sprite->getContentSize().width);
    GAMELOG("ffff==%f",f);
    return f;
}
示例#2
0
void UI_Friend::setFriendsList()
{
    Text* t;
    
    t = (Text*)rootNode->getChildByTag(T_FRIENDS_TOTALGOLDS);
    t->setString(StringUtils::format("%d", _player->friendsTotalGolds));
    GAMELOG("friendsTotalGolds = %d", _player->friendsTotalGolds);
    t = (Text*)rootNode->getChildByTag(T_FRIENDS_TOTALPOINTS);
    t->setString(StringUtils::format("%d", _player->friendsTotalPoints));
    GAMELOG("friendsTotalPoints = %d", _player->friendsTotalPoints);
    IPlayerData *ipayerData = M_GET_PLAYER;
//    ipayerData->golds+=_player->friendsTotalGolds;
//    ipayerData->totalpoints+=_player->friendsTotalPoints;
    t = (Text*)rootNode->getChildByTag(T_TOTALGOLDS);
    t->setString(StringUtils::format("%d",_player->friendsgolds));// _player->friendsTotalGolds));
    
    t = (Text*)rootNode->getChildByTag(T_TOTALPOINTS);
    t->setString(StringUtils::format("%d", _player->friendspoints));//_player->friendsTotalPoints));
    
    l_friends->removeAllItems();
    
    for(uint i = 0; i < _player->v_friends.size(); i ++)
    {
        Text* t;
        l_friends->pushBackDefaultItem();
        Widget* cell = l_friends->getItem(i);
        ImageView* head = (ImageView*)cell->getChildByTag(41);//头像
        head->loadTexture(StringUtils::format("CSres/Setup/Head/%s", _player->v_friends[i].uHeadIndex.c_str()));
        t = (Text*)cell->getChildByTag(42);//昵称
        t->setString(_player->v_friends[i].nickname);
        t = (Text*)cell->getChildByTag(43);//被邀请人等级
        t->setString(_player->v_friends[i].rankname);
//        t = (Text*)cell->getChildByTag(45);//等级记录
//        t->setString(_player->v_friends[i].recordgrade);
        t = (Text*)cell->getChildByTag(47);//总金币
        t->setString(StringUtils::format("%d", _player->v_friends[i].totalgolds));
        t = (Text*)cell->getChildByTag(49);//今日贡献金币
        t->setString(StringUtils::format("%d", _player->v_friends[i].todaygolds));
    }
    l_friends->jumpToPercentVertical(0);
}
示例#3
0
LPDIRECT3DSURFACE9 Game::createSurfaceFromFile(LPDIRECT3DDEVICE9 device, LPWSTR filePath)
{
    D3DXIMAGE_INFO info;

    HRESULT result = D3DXGetImageInfoFromFile(filePath, &info);

    if (result != D3D_OK)
    {
        GAMELOG("[Error] Failed to get image info %s", filePath);
        return NULL;
    }
    LPDIRECT3DSURFACE9 surface;
    GameGlobal::GetCurrentDevice()->CreateOffscreenPlainSurface(info.Width, info.Height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);

    result = D3DXLoadSurfaceFromFile(surface, NULL, NULL, filePath, NULL, D3DX_DEFAULT, 0, NULL);
    if (result != D3D_OK)
    {
        GAMELOG("[Error] Failed to load image from %s", filePath);
        return NULL;
    }

    return surface;
}
示例#4
0
void GameIni::afterCapture(bool succeed, const string& outputFile)
{
    if(succeed)
    {
        Args args;
        args.content = outputFile;
        GAMELOG("outfile == %s", outputFile.c_str());
        IMessageManager::getInstance()->postNotification(MES_GAMEINI_SCREENSHOOT_SUCCEED, &args);
    }
    else
    {
        IMessageManager::getInstance()->postNotification(MES_GAMEINI_SCREENSHOOT_FAILED);
    }
}
示例#5
0
Msg_Layer* Msg_Layer::create(const Color4B& color, int type)
{
    Msg_Layer * pLayer = Msg_Layer::create();
    
    GAMELOG("create _LayerStack.size() = %ld", _LayerStack.size());
    
    if(pLayer)
    {
        pLayer->setMsgType(type);
        Msg_Layer* last = getTopLayer();

        if(type & MsgType::Normal)
        {
            if((int)type & (int)MsgType::Hide)
            {
                if(last)
                    last->setVisible(false);
            }
        }
        else
        {
            if(_LayerStack.size() > 0)
                _LayerStack.pop();
            if(last)
                last->removeFromParent();
        }
        
        if(type & MsgType::Msgbox)
        {
            pLayer->setZOrder(10000);
        }
        else if(type & MsgType::Warnning)
        {
            pLayer->setZOrder(20000);
        }
        
        pLayer->setColor(Color3B(color.r, color.g, color.b));
        pLayer->setOpacity(color.a);
        
        _LayerStack.push(pLayer);
    }
    return pLayer;
}
示例#6
0
bool UI_Friend::Notify(const string& name, Args& args)
{
    if(IUILayer::Notify(name, args))
        return true;
    
//    Notify_Compare(MES_PLAYER_SETINVITECODE)
//    {
//        p_invite->setVisible(NO);
//        setInviteCode(_player->invitecode);
//        UIMessage::createMesBox("提交完成");
//        return YES;
//    }
    Notify_Compare(MES_PLAYER_GETFRIENDREWARD)
    {
        setFriendsList();
        UIMessage::createMesBox("领取成功");
        return YES;
    }
    
    Notify_Compare(SYSTEM_KEYBACK)
    {
//        if(p_invite->isVisible())
//        {
//            p_invite->setVisible(NO);
//            return YES;
//        }
        Ref* sender = rootNode->getChildByTag(B_BACK);
        if(sender)
            eventCallback(sender, Widget::TouchEventType::ENDED);
        return YES;
    }
    
    Notify_Compare(MES_GAMEINI_SCREENSHOOT_SUCCEED)
    {
        GAMELOG("---%s",args.content.c_str());
        ShareSDKHelper::getInstance()->sendImage(GameIni::getInstance()->shareSdkInfo.title,
                                                 GameIni::getInstance()->shareSdkInfo.description,
                                                 args.content);
        return YES;
    }
    
    return true;
}
示例#7
0
void Msg_Layer::close()
{
    if(_LayerStack.size() > 0)
        _LayerStack.pop();
    if(getParent())
        removeFromParent();
    GAMELOG("close _LayerStack.size() = %ld", _LayerStack.size());

    if(_msgType & MsgType::Normal )
    {
        if(_msgType & MsgType::Hide)
        {
            Msg_Layer* last = getTopLayer();
            if(last)
            {
                last->setVisible(true);
                last->setEnterType(last->getEnterType());
            }
        }
    }
}
示例#8
0
bool IsPhoneNumber(string str)
{
    GAMELOG("IsPhoneNumber %s", str.c_str());
    if(str.empty() || str.length() < 11)
        return false;
    
    
    for(int i = 0; i < str.size(); i ++)
    {
        if(i == 0 && str[i] == '0')
        {
            return false;
        }
        
        if ( (str[i] > '9') || (str[i] < '0') )
        {
            return false;
        }
    }
    return true;
}
示例#9
0
void PokedexData::insert(Advertise* a)
{
    if(!a)
        return;
    
//    deleteItem(a->adid);
    deleteItemByImgUrl(a->imgurl);
    
    if(v_pokedex.empty())
    {
        v_pokedex.push_back(a);
    }
    else
    {
        uint i = 0;
        for(; i < v_pokedex.size(); i ++)
        {
            if(a->datetime > v_pokedex[i]->datetime)
                break;
        }
        v_pokedex.insert(v_pokedex.begin() + i, a);
        if(v_pokedex.size() >= POKEDEX_MAX)
        {
            vector<Advertise*>::iterator it = v_pokedex.begin() + POKEDEX_MAX;
            while(it != v_pokedex.end())
            {
                //----删除多余图片-----
                string filename = ITools::Intercept_string((*it)->imgurl, "/");//截取图片名
                string path = FileUtils::getInstance()->getWritablePath() + IMAGE_ROOT_FINDER + "/" + IMAGE_AD_FINDER + "/" + filename;
                bool del = IFile::removeFile(path);
                GAMELOG("PokedexData::insert del = %d", del);
                //----删除存储节点-----
                SAFE_DELETE(*it);
                it = v_pokedex.erase(it);  
            }
        }
//        GAMELOG("PokedexData::insert time = %llu, v_pokedexsize = %lu", a->datetime, v_pokedex.size());
    }
    savefile();
}
示例#10
0
void GameIni::getDeviceInfo()
{
    string deviceInfo = "";
    
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    {
        
    }
    #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    {
        JniMethodInfo t;
        if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/cpp/NgsteamPhoneInfo",
                                           "getRegPhoneInfoString", "()Ljava/lang/String;"))
        {
            jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID);
            deviceInfo = JniHelper::jstring2string(str);
            t.env->DeleteLocalRef(t.classID);
        }
    }
    #endif
    
    GAMELOG("----gameini---getdeviceInfo-----\n%s", deviceInfo.c_str());
}
示例#11
0
void Msg_Layer::onTouchMoved(Touch *touch, Event *unused_event)
{
    GAMELOG("------------Msg_Layer::onTouchMoved-------------");
}
示例#12
0
bool Msg_Layer::onTouchBegan(Touch *touch, Event *unused_event)
{
    GAMELOG("------------Msg_Layer::onTouchBegan-------------");
    return true;
}
示例#13
0
void UI_Friend::eventCallback(Ref * pSender,Widget::TouchEventType type)
{
    if (type != Widget::TouchEventType::ENDED)
        return;
    
    IAudio::getInstance()->playEffect(music_ef_ok);
    
    Widget* widget = (Widget*)pSender;
    int tag = widget->getTag();
    GAMELOG("widget->getTag = %d", tag);
    switch (tag)
    {
        case B_BACK:
        {
            UICtrl::getInstance()->gotoScene(UI_OPTION);
        }break;
//        case B_INVITE:
//        {
//            p_invite->setVisible(YES);
//        }break;
//        case B_INVITE_SAVE:
//        {
//            TextField* tf = (TextField*)p_invite->getChildByTag(TF_INVITE_PHONE);
//            if(!isVauled(tf) || !IsPhoneNumber(tf->getString()))
//            {
//                UIMessage::createMesBox(GameIni::getInstance()->getTips(tips_error_phone));
//            }
//            else if(tf->getString().compare(_player->userid) == 0)
//            {
//                UIMessage::createMesBox(GameIni::getInstance()->getTips(tips_error_invitenotself));
//            }
//            else
//            {
//                _player->http_request_setInviteCode(tf->getString());
//            }
//        }break;
//        case B_INVITE_BACK:
//        {
//            p_invite->setVisible(NO);
//        }break;
//        case I_INVITE_AUTOCLOSE:
//        {
//            p_invite->setVisible(NO);
//        }break;
        case B_GETGOLDS:
        {
            //if(_player->friendsTotalGolds <= 0 || _player->friendsTotalPoints <= 0)
            if(_player->friendspoints <= 0 && _player->friendsgolds <= 0)
            {
                UIMessage::createMesBox("没有可领取的奖励");
            }
            else
            {
                _player->http_request_getFriendsReward();
            }
        }break;
        case B_YQHY:        //邀请好友  分享
        {
//            分享 链接+内容+本地图片
            ShareSDKHelper::getInstance()->sendLink(GameIni::getInstance()->shareSdkInfo.title,
                                                     GameIni::getInstance()->shareSdkInfo.description,
                                                    GameIni::getInstance()->shareSdkInfo.webpageUrl,
                                                    GameIni::getInstance()->getShareLocalPath("res/Share/share_phone.png"));
            CCLOG("分享 %s 12 %s 23 %s ",GameIni::getInstance()->shareSdkInfo.title.c_str(),GameIni::getInstance()->shareSdkInfo.description.c_str(),GameIni::getInstance()->shareSdkInfo.webpageUrl.c_str());
//            break;
            //分享截屏
//            GameIni::getInstance()->screenShoot();      //截屏发送分享流程    不可删除 IMAGE_SCREENSHOOT_FILENAME
            //分享本地图片
//            ShareSDKHelper::getInstance()->sendImage(GameIni::getInstance()->shareSdkInfo.title,
//                                                     GameIni::getInstance()->shareSdkInfo.description,
//                                                     GameIni::getInstance()->getShareLocalPath("res/Share/share_phone.png"));
        }break;
        case B_INVITE_YQSM:
        {
            inviteNode->setVisible(true);
            inviteList->jumpToTop();
        }break;
        case B_YQHYSM_BACK:
        {
            inviteNode->setVisible(false);
        }break;
        default:
            break;
    }
}
示例#14
0
void getLocationInfo(double x, double y)
{
    GAMELOG("----gameini---getLocationInfo----x = %f-y = %f", x, y);
}
示例#15
0
void Msg_Layer::onTouchEnded(Touch *touch, Event *unused_event)
{
    GAMELOG("------------Msg_Layer::onTouchMoved-------------");
    if(_outsideClose)
        close();
}
示例#16
0
void TestScene::OnKeyDown(int keyCode)
{
    if (!isContentLoaded)
        return;

    if (keyCode == DIK_SPACE)
        isPause = !isPause;

    if (keyCode == DIK_D)
        isDebugDraw = !isDebugDraw;

    if (keyCode == DIK_H)
        isHideAll = !isHideAll;

    if (keyCode == DIK_B)
    {
        isDrawBezier = !isDrawBezier;
    }
        
    if (keyCode == DIK_C)
    {
        points.clear();
        savePoints.clear();
    }

    //chay bezier bac 2
    if (keyCode == DIK_NUMPAD1)
    {
        points.clear();
        savePoints.clear();
        t = 0;

        points.push_back(D3DXVECTOR2(100, 100));
        points.push_back(D3DXVECTOR2(400, 300));
        points.push_back(D3DXVECTOR2(200, 600));

        updateFullPoints();
    }

    //chay bezier bac 3
    if (keyCode == DIK_NUMPAD2)
    {
        points.clear();
        savePoints.clear();
        t = 0;

        points.push_back(D3DXVECTOR2(100, 100));
        points.push_back(D3DXVECTOR2(400, 200));
        points.push_back(D3DXVECTOR2(200, 400));
        points.push_back(D3DXVECTOR2(500, 600));

        updateFullPoints();
    }

    //chay bezier bac 4
    if (keyCode == DIK_NUMPAD3)
    {
        points.clear();
        savePoints.clear();
        t = 0;

        points.push_back(D3DXVECTOR2(100, 100));
        points.push_back(D3DXVECTOR2(400, 200));
        points.push_back(D3DXVECTOR2(200, 400));
        points.push_back(D3DXVECTOR2(400, 600));
        points.push_back(D3DXVECTOR2(650, 250));

        updateFullPoints();
    }

    //bac 12
    if (keyCode == DIK_NUMPAD4)
    {
        points.clear();
        savePoints.clear();
        t = 0;

        points.push_back(D3DXVECTOR2(0, 0));
        points.push_back(D3DXVECTOR2(300, 80));
        points.push_back(D3DXVECTOR2(450, 150));
        points.push_back(D3DXVECTOR2(200, 200));
        points.push_back(D3DXVECTOR2(10, 250));
        points.push_back(D3DXVECTOR2(50, 350));
        points.push_back(D3DXVECTOR2(300, 450));
        points.push_back(D3DXVECTOR2(350, 250));
        points.push_back(D3DXVECTOR2(850, 150));
        points.push_back(D3DXVECTOR2(600, 350));
        points.push_back(D3DXVECTOR2(400, 450));
        points.push_back(D3DXVECTOR2(150, 650));
        points.push_back(D3DXVECTOR2(900, 680));

        updateFullPoints();
    }

    if (keyCode == DIK_ADD)
    {
        speed += 0.1f;         
        
    }

    if (keyCode == DIK_SUBTRACT)
    {
        speed -= 0.1f;

        if (speed <= 0)
            speed = 0.1f;
    }

    GAMELOG("speed: %f", speed);
}
示例#17
0
void Shader::Init()
{
    unsigned int indexDataSize = 6 * sizeof(unsigned int);

    D3DXMatrixIdentity(&mMatrixWorld);
    D3DXMatrixIdentity(&mMatrixView);
    D3DXMatrixIdentity(&mMatrixProject);

    D3DXMatrixTranslation(&mMatrixView, 0, 0, 2);
    D3DXMatrixPerspectiveFovLH(&mMatrixProject, D3DXToRadian(75), 800.0f / 600.0f, 0.01f, 100.0f);

    if (GameGlobal::GetCurrentDevice()->CreateIndexBuffer(indexDataSize, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &mIndexBuffer, 0))
    {
        GAMELOG("Create Index Buffer Successed!");
    }

    //Create Vertex Data
    VertexData vertexData[]
    {
        {D3DXVECTOR3(-0.5f, -0.5f, 0), D3DCOLOR_XRGB(255, 0, 0)},
        { D3DXVECTOR3(0.0f, 0.5f, 0), D3DCOLOR_XRGB(0, 255, 0) },
        { D3DXVECTOR3(0.5f, 0.5f, 0), D3DCOLOR_XRGB(0, 0, 255) }
    };

    unsigned int vertexDataSize = 3 * sizeof(unsigned int);

    //Create Vertex Buffer
    HRESULT rs = GameGlobal::GetCurrentDevice()->CreateVertexBuffer(vertexDataSize, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &mVertexBuffer, 0);

    switch (rs)
    {
    case D3DERR_INVALIDCALL:
        GAMELOG("D3DERR_INVALIDCALL");
        break;

    case D3DERR_OUTOFVIDEOMEMORY:
        GAMELOG("D3DERR_OUTOFVIDEOMEMORY");
        break;

    case E_OUTOFMEMORY:
        GAMELOG("E_OUTOFMEMORY");
        break;

    default:
        break;
    }

    void *tempVertexBuffer;
    mVertexBuffer->Lock(0, vertexDataSize, &tempVertexBuffer, 0);
    {
        memcpy(tempVertexBuffer, vertexData, vertexDataSize);
    }
    mVertexBuffer->Unlock();

    unsigned int indexData[]
    {
        0, 1, 2,
        0, 2, 1
    };

    //Create Index Buffer
    GameGlobal::GetCurrentDevice()->CreateIndexBuffer(indexDataSize, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &mIndexBuffer, 0);
    
    void *tempIndexBuffer;
    mIndexBuffer->Lock(0, indexDataSize, &tempIndexBuffer, 0);
    {
        memcpy(tempIndexBuffer, mIndexBuffer, indexDataSize);
    }
    mIndexBuffer->Unlock();

    //Create Vertex Declaration
    D3DVERTEXELEMENT9 declaration[]
    {
        {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
        { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
        D3DDECL_END(),
    };

    GameGlobal::GetCurrentDevice()->CreateVertexDeclaration(declaration, &mVertexDeclaration);

    //Create Shader
    D3DXCreateEffectFromFileA(GameGlobal::GetCurrentDevice(), "shader.fx", 0, 0, 0, 0, &mShader, 0);
}