Exemplo n.º 1
0
void RedrawRatingInfo(TextSprite & sprite)
{
    sprite.Hide();
    std::string str(_("Rating %{rating}%"));
    StringReplace(str, "%{rating}", Game::GetRating());
    sprite.SetText(str);
    sprite.Show();
}
Exemplo n.º 2
0
void LabeledSprite(GameManager *mgr, uint32 marker_handle, uint32 width, uint32 height)
{
    Sprite *image = new Sprite(mgr);
    image->SetImage(mgr->GetResourceManager()->GetImage(ARROW_HANDLE));
    image->AddTransformation(new AnchorTransformation());
    image->SetBaseLocation(CIwVec2(mgr->GetSurfaceWidth() / 2, mgr->GetSurfaceHeight() / 2));
    OrbitTransformation *orbiter = new OrbitTransformation(150, 5000, 0, CounterClockwise);
    image->AddTransformation(orbiter);
    mgr->RegisterGameObject(image);

    TextSprite *text = new TextSprite(mgr, (char *)"Normal");
    text->AddTransformation(new AnchorTransformation());
    text->AddTransformation(new AnchorToTransformation(image, image, (float)(text->GetHeight() / 2 + image->GetHeight() / 2 + 10), 0, RelativeToNormal));
    text->AddTransformation(new OrientToTransformation((IDirectional*)image, OrientAlongOrientation));
    mgr->RegisterGameObject(text);
}
Exemplo n.º 3
0
void TradeWindowGUI::RedrawInfoBuySell(u32 count_sell, u32 count_buy)
{
    Point dst_pt;
    std::string message;

    String::AddInt(message, count_sell);
    textSell.Hide();
    textSell.SetText(message);
    dst_pt.x = pos_rt.x + pos_rt.w / 2 - 70 - textSell.w() / 2;
    dst_pt.y = pos_rt.y + 116;
    textSell.SetPos(dst_pt);
    textSell.Show();

    message.clear();
    String::AddInt(message, count_buy);
    textBuy.Hide();
    textBuy.SetText(message);
    dst_pt.x = pos_rt.x + pos_rt.w / 2 + 70 - textBuy.w() / 2;
    dst_pt.y = pos_rt.y + 116;
    textBuy.SetPos(dst_pt);
    textBuy.Show();
}
Exemplo n.º 4
0
void WallLevel::SummarizeWallLevel(EventCallback *eventData)
{
    StateVariable finalPoints = mgr->GetStateManager()->GetVar(VAR_POINTS);

    char stateSummary[1024];

    sprintf(stateSummary, "You got %d points.\nHave some stars!\nTouch to continue.", finalPoints.intValue);

    mgr->RemoveAllGameObjects();

    Sprite *sprite = new Sprite(mgr);
    sprite->SetImage(mgr->GetResourceManager()->GetImage(IMAGE_WALL_BACKGROUND));
    sprite->SetBaseLocation(CIwVec2(0, 0));
    sprite->SetZIndex(-999);
    mgr->RegisterGameObject(sprite);
    strcpy(sprite->debugId, "WallLevelBackground");
    sprite->SetTouchEndCallback(this, (EventCallbackPtr)&WallLevel::GoToLevelSelect, (void*)(mgr->GetCurrentClockTime() + 2000));

    for(int y = 0; y < NUM_COURSES; y++)
    {
        for(int x = -1; x<= NUM_POSITIONS; x++)
        {
            new Brick(mgr, this, x, y);
        }
    }

    TextSprite *summary = new TextSprite(mgr, stateSummary);
    summary->SetAlign(IW_2D_FONT_ALIGN_CENTRE);
    summary->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]);
    summary->SetFont(mgr->GetResourceManager()->GetFont(FONT_COOPER_24));
    summary->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_BLACK]);
    summary->SetBorderThickness(CIwVec2(4, 4));
    summary->SetPadding(CIwVec2(7, 7));
    summary->AddTransformation(new AnchorTransformation());
    summary->SetBaseLocation(CIwVec2(mgr->GetSurfaceWidth() / 2, mgr->GetSurfaceHeight() / 2));
    summary->SetZIndex(999);
    mgr->RegisterGameObject(summary);
}
Exemplo n.º 5
0
void MapShowScene::render()
{
	curMap->draw();

	//SDL_RenderDrawRect(renderer, &bomberman.pos);
	bomberman.draw();

	enemies.draw();
	statusString.draw();
	if (bomb != nullptr)bomb->draw();
	switch (mapShowState)
	{
	case MapShowState::GAME_RUNNING:
		break;
	case MapShowState::GAME_SUCCESS:
	{
		TextSprite ts;
		fontColor.b = 250;
		ts.init(renderer, fontColor, "You Win", gFont);
		int w, h;
		SDL_GetWindowSize(window, &w, &h);
		int smaller = 100;
		ts.pos = { smaller, smaller, w - smaller * 2, h - smaller * 2 };
		ts.draw();
	}
		break;
	case MapShowState::GAME_OVER:
	{
		TextSprite ts;
		fontColor.b = 250;
		ts.init(renderer, fontColor, "You Lost", gFont);
		int w, h;
		SDL_GetWindowSize(window, &w, &h);
		int smaller = 100;
		ts.pos = { smaller, smaller, w - smaller * 2, h - smaller * 2 };
		ts.draw();
	}
		break;
	}
	
}
Exemplo n.º 6
0
bool GameOverLayer::init(bool win, int stage, int time, int kill, int loss, int newFlight)
{
    if(!Layer::init())
    {
        return false;
    }
    
    //init
    _stage = stage;
    
    std::string fontFile = "DS-Digital.ttf";//"arial.ttf";
    int fontSize = 25;
    auto infoColor = DIY_COLOR_BLUE5;
    
    //swallow touches
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan = [](Touch* touch, Event* event){
        return true;
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    //panel
    Size panelSize;
    if(win)
        panelSize = Size(s_visibleRect.visibleWidth-60,s_visibleRect.visibleHeight-280);
    else
        panelSize = Size(s_visibleRect.visibleWidth-60,s_visibleRect.visibleHeight-450);
    
    
    auto _panel = Scale9Sprite::create("windowBox.png");
    _panel->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
    _panel->setPosition(Point(s_visibleRect.center.x,s_visibleRect.top.y + panelSize.height));
    _panel->setContentSize(panelSize);
    this->addChild(_panel);
    _panel->runAction(MoveTo::create(0.15f,s_visibleRect.top-Point(0,80)));
    
    //title
    TextSprite* title;
    if(win)
    {
        title = TextSprite::create(s_gameStrings.battleInfo->gameovertitle_win.c_str(),s_gameConfig.defaultFontName,32);
        title->setColor(Color3B::YELLOW);
    }
    else
    {   title = TextSprite::create(s_gameStrings.battleInfo->gameovertitle_loss.c_str(),s_gameConfig.defaultFontName,32);
        title->setColor(Color3B::RED);
    }
    title->setAnchorPoint(Point::ANCHOR_MIDDLE);
    title->setPosition(Point(panelSize.width/2,panelSize.height-90));
    _panel->addChild(title,1);
    
    //info
    auto time_label = TextSprite::create(s_gameStrings.battleInfo->gameovertime, "Arial", fontSize);
    time_label->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    time_label->setPosition(Point(150,panelSize.height-150));
    _panel->addChild(time_label);
    
    time = time > 36000?3599:(time/10);
    int min = time/60;
    int sec = time - min*60;
    char p[10];
    sprintf(p,"%02d\'%02d\"",min,sec);
    
    auto time_content = TextSprite::create(p,fontFile, fontSize);
    time_content->setColor(infoColor);
    time_content->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    time_content->setPosition(Point(320,panelSize.height-150));
    _panel->addChild(time_content);
    
    auto kill_label = TextSprite::create(s_gameStrings.battleInfo->gameoverkill, "Arial", fontSize);
    kill_label->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    kill_label->setPosition(Point(150,panelSize.height-200));
    _panel->addChild(kill_label);
    
    auto kill_content = TextSprite::create(Value(kill).asString(),fontFile, fontSize);
    kill_content->setColor(infoColor);
    kill_content->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    kill_content->setPosition(Point(320,panelSize.height-200));
    _panel->addChild(kill_content);
    
    auto loss_label = TextSprite::create(s_gameStrings.battleInfo->gameoverloss, "Arial", fontSize);
    loss_label->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    loss_label->setPosition(Point(150,panelSize.height-250));
    _panel->addChild(loss_label);
    
    auto loss_content = TextSprite::create(Value(loss).asString(), fontFile, fontSize);
    loss_content->setColor(infoColor);
    loss_content->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    loss_content->setPosition(Point(320,panelSize.height-250));
    _panel->addChild(loss_content);
    
    //rewards
    if (win)
    {
        //init rewards
        int _gem = s_stageRewards[_stage][0];
        int _starboom = s_stageRewards[_stage][1];
        int _laser = s_stageRewards[_stage][2];
        int _blackhole = s_stageRewards[_stage][3];
        
        auto rewards_label = TextSprite::create(s_gameStrings.battleInfo->gameoverreward, "Arial", fontSize);
        rewards_label->setColor(Color3B::GRAY);
        rewards_label->setAnchorPoint(Point::ANCHOR_MIDDLE);
        rewards_label->setPosition(Point(panelSize.width/2,panelSize.height-300));
        _panel->addChild(rewards_label);
        
        if(_starboom == 0 && _laser == 0 && _blackhole == 0)
        {
            auto icon = Sprite::createWithSpriteFrameName("icon_gem.png");
            icon->setPosition(panelSize.width/2-50, panelSize.height/2-10);
            _panel->addChild(icon);
            
            auto label = Label::createWithTTF(Value(_gem).asString().c_str(), s_gameConfig.defaultFontName, fontSize);
            label->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
            label->setPosition(Point(icon->getPositionX()+icon->getContentSize().width, icon->getPositionY()));
            label->setColor(Color3B::YELLOW);
            _panel->addChild(label);
        }
        else
        {
            auto icon1 = Sprite::createWithSpriteFrameName("icon_gem.png");
            icon1->setPosition(panelSize.width/2-130, panelSize.height/2-10);
            _panel->addChild(icon1);
            
            auto label1 = Label::createWithTTF(Value(_gem).asString().c_str(), s_gameConfig.defaultFontName, fontSize);
            label1->setPosition(icon1->getPositionX()+icon1->getContentSize().width+20, icon1->getPositionY());
            label1->setColor(Color3B::YELLOW);
            _panel->addChild(label1);
            if (_starboom > 0) {
                auto icon2 = Sprite::createWithSpriteFrameName("bomb_1_1.png");
                icon2->setScale(0.5f);icon2->setRotation(90);
                icon2->setPosition(panelSize.width/2+50, panelSize.height/2-10);
                _panel->addChild(icon2);
                
                std::string str = "x" + Value(_starboom).asString();
                auto label2 = Label::createWithTTF(str.c_str(), s_gameConfig.defaultFontName, fontSize);
                label2->setPosition(icon2->getPositionX()+icon2->getContentSize().width, icon2->getPositionY());
                label2->setColor(infoColor);
                _panel->addChild(label2);
            }
            else if (_laser > 0) {
                
                auto icon2 = Sprite::createWithSpriteFrameName("bomb_2_1.png");
                icon2->setScale(0.8f);icon2->setRotation(90);
                icon2->setPosition(panelSize.width/2+50, panelSize.height/2-10);
                _panel->addChild(icon2);
                
                std::string str = "x" + Value(_laser).asString();
                auto label2 = Label::createWithTTF(str.c_str(), s_gameConfig.defaultFontName, fontSize);
                label2->setPosition(icon2->getPositionX()+icon2->getContentSize().width, icon2->getPositionY());
                label2->setColor(infoColor);
                _panel->addChild(label2);
            }
            else if (_blackhole > 0) {
                
                auto icon2 = Sprite::createWithSpriteFrameName("bomb_3_1.png");
                icon2->setScale(0.6f);
                icon2->setPosition(panelSize.width/2+50, panelSize.height/2);
                _panel->addChild(icon2);
                
                std::string str = "x" + Value(_blackhole).asString();
                auto label2 = Label::createWithTTF(str.c_str(), s_gameConfig.defaultFontName, fontSize);
                label2->setPosition(icon2->getPositionX()+icon2->getContentSize().width, icon2->getPositionY());
                label2->setColor(infoColor);
                _panel->addChild(label2);
            }
        }
        
        if(newFlight)
        {
            auto newflight_label = TextSprite::create(s_gameStrings.battleInfo->gameovernewflight, "Arial", fontSize);
            newflight_label->setColor(Color3B::GRAY);
            newflight_label->setAnchorPoint(Point::ANCHOR_MIDDLE);
            newflight_label->setPosition(Point(panelSize.width/2,panelSize.height-400));
            _panel->addChild(newflight_label);
            
            char name[30];
            sprintf(name,"plain_%d_lv_%d.png",newFlight,1);
            auto newflight = Sprite::createWithSpriteFrameName(name);
            newflight->setScale(1.3f);
            newflight->setAnchorPoint(Point::ANCHOR_MIDDLE);
            newflight->setPosition(Point(panelSize.width/2,panelSize.height-480));
            _panel->addChild(newflight);
            
            auto newicon = Sprite::createWithSpriteFrameName("icon_new.png");
            newicon->setAnchorPoint(Point::ANCHOR_MIDDLE);
            newicon->setPosition(newflight->getPosition()+Point(0,-60));
            _panel->addChild(newicon);
            
        }
    }
    
    if(newFlight)
    {
        auto gotosee_menu = MenuItemImageLabel::createWithFrameName("bt_main_0.png", "bt_main_1.png", CC_CALLBACK_1(GameOverLayer::returnBase_callback, this), s_gameStrings.battleInfo->gotosee);
        gotosee_menu->setAnchorPoint(Point::ANCHOR_MIDDLE);
        gotosee_menu->setPosition(Point(panelSize.width/2, 60));
        
        auto menu = Menu::create(gotosee_menu, nullptr);
        menu->setPosition(Point::ZERO);
        _panel->addChild(menu);
        return true;
    }
    
    //menu
    auto returnBase_menu = MenuItemImageLabel::createWithFrameName("bt_main_0.png", "bt_main_1.png", CC_CALLBACK_1(GameOverLayer::returnBase_callback, this), s_gameStrings.battleInfo->returnbase);
    returnBase_menu->setAnchorPoint(Point::ANCHOR_MIDDLE);
    returnBase_menu->setPosition(Point(panelSize.width/2, 150));
    
    if (win && s_playerConfig.overstage<50) {
        auto nextStage_menu = MenuItemImageLabel::createWithFrameName("bt_main_0.png", "bt_main_1.png", CC_CALLBACK_1(GameOverLayer::nextStage_callback, this), s_gameStrings.battleInfo->nextstage);
        nextStage_menu->setAnchorPoint(Point::ANCHOR_MIDDLE);
        nextStage_menu->setPosition(Point(panelSize.width/2, 70));
        nextStage_menu->setColor(DIY_COLOR_BLUE5);
        
        auto menu = Menu::create(returnBase_menu, nextStage_menu, nullptr);
        menu->setPosition(Point::ZERO);
        _panel->addChild(menu);
    }
    else{
        auto restartStage_menu = MenuItemImageLabel::createWithFrameName("bt_main_0.png", "bt_main_1.png", CC_CALLBACK_1(GameOverLayer::restartStage_callback, this), s_gameStrings.battleInfo->restartstage);
        restartStage_menu->setAnchorPoint(Point::ANCHOR_MIDDLE);
        restartStage_menu->setPosition(Point(panelSize.width/2, 70));
        
        auto menu = Menu::create(returnBase_menu, restartStage_menu, nullptr);
        menu->setPosition(Point::ZERO);
        _panel->addChild(menu);
    }
    
    //this->scheduleOnce(schedule_selector(GameOverLayer::pausegame), 0.5f);

    return true;
}
Exemplo n.º 7
0
int Game::ScenarioInfo(void)
{
    Settings & conf = Settings::Get();

    AGG::PlayMusic(MUS::MAINMENU);

    MapsFileInfoList lists;
    if(!PrepareMapsFileInfoList(lists, (conf.GameType(Game::TYPE_MULTI))))
    {
	Dialog::Message(_("Warning"), _("No maps available!"), Font::BIG, Dialog::OK);
        return MAINMENU;
    }

    int result = QUITGAME;
    LocalEvent & le = LocalEvent::Get();

    // cursor
    Cursor & cursor = Cursor::Get();
    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    Display & display = Display::Get();

    Point top, pointDifficultyInfo, pointOpponentInfo, pointClassInfo;
    Rect rectPanel;
    Button* buttonSelectMaps = NULL;
    Button* buttonOk = NULL;
    Button* buttonCancel = NULL;

    // vector coord difficulty
    Rects coordDifficulty;
    coordDifficulty.reserve(5);

    const Sprite & ngextra = AGG::GetICN(ICN::NGEXTRA, 62);
    Dialog::FrameBorder* frameborder = NULL;

    // image background
    if(conf.QVGA())
    {
	frameborder = new Dialog::FrameBorder(Size(380, 224));
	rectPanel = frameborder->GetArea();

	pointDifficultyInfo = Point(rectPanel.x + 4, rectPanel.y + 24);
	pointOpponentInfo = Point(rectPanel.x + 4, rectPanel.y + 94);
	pointClassInfo = Point(rectPanel.x + 4, rectPanel.y + 148);

	coordDifficulty.push_back(Rect(rectPanel.x + 1, rectPanel.y + 21,   ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 78, rectPanel.y + 21,  ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 154, rectPanel.y + 21, ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 231, rectPanel.y + 21, ngextra.w(), ngextra.h()));
        coordDifficulty.push_back(Rect(rectPanel.x + 308, rectPanel.y + 21, ngextra.w(), ngextra.h()));

	buttonOk = new Button(rectPanel.x + rectPanel.w / 2 - 160, rectPanel.y + rectPanel.h - 30, ICN::NGEXTRA, 66, 67);
	buttonCancel = new Button(rectPanel.x + rectPanel.w / 2 + 60, rectPanel.y + rectPanel.h - 30, ICN::NGEXTRA, 68, 69);

	Text text;
	text.Set(conf.CurrentFileInfo().name, Font::BIG);
	text.Blit(rectPanel.x + (rectPanel.w - text.w()) / 2, rectPanel.y + 5);
    }
    else
    {
	const Sprite &panel = AGG::GetICN(ICN::NGHSBKG, 0);
	const Sprite &back = AGG::GetICN(ICN::HEROES, 0);
	const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2);

	rectPanel = Rect(top.x + 204, top.y + 32, panel.w(), panel.h());
	pointDifficultyInfo = Point(rectPanel.x + 24, rectPanel.y + 93);
	pointOpponentInfo = Point(rectPanel.x + 24, rectPanel.y + 202);
	pointClassInfo = Point(rectPanel.x + 24, rectPanel.y + 282);

	coordDifficulty.push_back(Rect(rectPanel.x + 21, rectPanel.y + 91,  ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 98, rectPanel.y + 91,  ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 174, rectPanel.y + 91, ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 251, rectPanel.y + 91, ngextra.w(), ngextra.h()));
	coordDifficulty.push_back(Rect(rectPanel.x + 328, rectPanel.y + 91, ngextra.w(), ngextra.h()));

	buttonSelectMaps = new Button(rectPanel.x + 309, rectPanel.y + 45, ICN::NGEXTRA, 64, 65);
	buttonOk = new Button(rectPanel.x + 31, rectPanel.y + 380, ICN::NGEXTRA, 66, 67);
	buttonCancel = new Button(rectPanel.x + 287, rectPanel.y + 380, ICN::NGEXTRA, 68, 69);

	back.Blit(top);
    }

    const bool reset_starting_settings = conf.MapsFile().empty() || ! System::IsFile(conf.MapsFile());
    Players & players = conf.GetPlayers();
    Interface::PlayersInfo playersInfo(true, !conf.QVGA(), !conf.QVGA());

    // set first maps settings
    if(reset_starting_settings)
	conf.SetCurrentFileInfo(lists.front());

    playersInfo.UpdateInfo(players, pointOpponentInfo, pointClassInfo);

    RedrawScenarioStaticInfo(rectPanel);
    RedrawDifficultyInfo(pointDifficultyInfo, !conf.QVGA());

    playersInfo.RedrawInfo();

    TextSprite* rating = conf.QVGA() ? NULL : new TextSprite();
    if(rating)
    {
	rating->SetFont(Font::BIG);
	rating->SetPos(rectPanel.x + 166, rectPanel.y + 383);
	RedrawRatingInfo(*rating);
    }

    SpriteMove levelCursor(ngextra);

    switch(conf.GameDifficulty())
    {
	case Difficulty::EASY:		levelCursor.Move(coordDifficulty[0]); break;
	case Difficulty::NORMAL:	levelCursor.Move(coordDifficulty[1]); break;
	case Difficulty::HARD:		levelCursor.Move(coordDifficulty[2]); break;
	case Difficulty::EXPERT:	levelCursor.Move(coordDifficulty[3]); break;
	case Difficulty::IMPOSSIBLE:	levelCursor.Move(coordDifficulty[4]); break;
    }

    if(buttonSelectMaps) buttonSelectMaps->Draw();
    buttonOk->Draw();
    buttonCancel->Draw();

    cursor.Show();
    display.Flip();

    while(le.HandleEvents())
    {
	// press button
	if(buttonSelectMaps)
	le.MousePressLeft(*buttonSelectMaps) ? buttonSelectMaps->PressDraw() : buttonSelectMaps->ReleaseDraw();
	le.MousePressLeft(*buttonOk) ? buttonOk->PressDraw() : buttonOk->ReleaseDraw();
	le.MousePressLeft(*buttonCancel) ? buttonCancel->PressDraw() : buttonCancel->ReleaseDraw();

	// click select
	if(buttonSelectMaps &&
	  (HotKeyPressEvent(Game::EVENT_BUTTON_SELECT) || le.MouseClickLeft(*buttonSelectMaps)))
	{
	    levelCursor.Hide();
	    const Maps::FileInfo* fi = Dialog::SelectScenario(lists);
	    if(fi)
	    {
		conf.SetCurrentFileInfo(*fi);
		playersInfo.UpdateInfo(players, pointOpponentInfo, pointClassInfo);

		cursor.Hide();
		RedrawScenarioStaticInfo(rectPanel);
		RedrawDifficultyInfo(pointDifficultyInfo, !conf.QVGA());
		playersInfo.RedrawInfo();
		if(rating) RedrawRatingInfo(*rating);
		// default difficulty normal
		levelCursor.Move(coordDifficulty[1]);
    		conf.SetGameDifficulty(Difficulty::NORMAL);
		buttonOk->Draw();
		buttonCancel->Draw();
	    }
	    cursor.Show();
	    display.Flip();
	}
	else
	// click cancel
	if(HotKeyPressEvent(EVENT_DEFAULT_EXIT) || le.MouseClickLeft(*buttonCancel))
	{
	    result = MAINMENU;
	    break;
	}
	else
	// click ok
	if(HotKeyPressEvent(EVENT_DEFAULT_READY) || le.MouseClickLeft(*buttonOk))
	{
	    DEBUG(DBG_GAME, DBG_INFO, "select maps: " << conf.MapsFile() << \
		    ", difficulty: " << Difficulty::String(conf.GameDifficulty()));
	    result = STARTGAME;
	    break;
	}
	else
	if(le.MouseClickLeft(rectPanel))
	{
	    const s32 index = coordDifficulty.GetIndex(le.GetMouseCursor());

	    // select difficulty
	    if(0 <= index)
	    {
		cursor.Hide();
		levelCursor.Move(coordDifficulty[index]);
		conf.SetGameDifficulty(index);
		if(rating) RedrawRatingInfo(*rating);
		cursor.Show();
		display.Flip();
	    }
	    else
	    // playersInfo
	    if(playersInfo.QueueEventProcessing())
	    {
		cursor.Hide();
		RedrawScenarioStaticInfo(rectPanel);
		levelCursor.Redraw();
		RedrawDifficultyInfo(pointDifficultyInfo, !conf.QVGA());

		playersInfo.RedrawInfo();
		if(rating) RedrawRatingInfo(*rating);
		buttonOk->Draw();
		buttonCancel->Draw();
		cursor.Show();
		display.Flip();
	    }
	}

	if(le.MousePressRight(rectPanel))
	{
	    if(buttonSelectMaps && le.MousePressRight(*buttonSelectMaps))
		Dialog::Message(_("Scenario"), _("Click here to select which scenario to play."), Font::BIG);
	    else
	    if(0 <= coordDifficulty.GetIndex(le.GetMouseCursor()))
		Dialog::Message(_("Game Difficulty"), _("This lets you change the starting difficulty at which you will play. Higher difficulty levels start you of with fewer resources, and at the higher settings, give extra resources to the computer."), Font::BIG);
	    else
	    if(rating && le.MousePressRight(rating->GetRect()))
		Dialog::Message(_("Difficulty Rating"), _("The difficulty rating reflects a combination of various settings for your game. This number will be applied to your final score."), Font::BIG);
	    else
	    if(le.MousePressRight(*buttonOk))
		Dialog::Message(_("OK"), _("Click to accept these settings and start a new game."), Font::BIG);
	    else
	    if(le.MousePressRight(*buttonCancel))
		Dialog::Message(_("Cancel"), _("Click to return to the main menu."), Font::BIG);
	    else
		playersInfo.QueueEventProcessing();
	}
    }

    cursor.Hide();

    if(result == STARTGAME)
    {
	players.SetStartGame();
	if(conf.ExtGameUseFade()) display.Fade();
	Game::ShowLoadMapsText();
	// Load maps
	std::string lower = StringLower(conf.MapsFile());

	if(lower.size() > 3)
	{
	    std::string ext = lower.substr(lower.size() - 3);

	    if(ext == "mp2" || ext == "mx2")
		result = world.LoadMapMP2(conf.MapsFile()) ? STARTGAME : MAINMENU;
	    else
	    if(ext == "map")
		result = world.LoadMapMAP(conf.MapsFile()) ? STARTGAME : MAINMENU;
	}
	else
	{
	    result = MAINMENU;
	    DEBUG(DBG_GAME, DBG_WARN, conf.MapsFile() << ", " << "unknown map format");
	}
    }

    if(frameborder) delete frameborder;
    if(rating) delete rating;
    if(buttonSelectMaps) delete buttonSelectMaps;
    delete buttonOk;
    delete buttonCancel;

    return result;
}
Exemplo n.º 8
0
int Dialog::ArmyJoinWithCost(const Troop & troop, u32 join, u32 gold, Heroes & hero)
{
    Display & display = Display::Get();
    const Settings & conf = Settings::Get();

    // cursor
    Cursor & cursor = Cursor::Get();
    int oldthemes = cursor.Themes();
    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    std::string message;

    if(troop.GetCount() == 1)
	message = _("The creature is swayed by your diplomatic tongue, and offers to join your army for the sum of %{gold} gold.\nDo you accept?");
    else
    {
        message = _("The creatures are swayed by your diplomatic\ntongue, and make you an offer:\n \n");

        if(join != troop.GetCount())
    	    message += _("%{offer} of the %{total} %{monster} will join your army, and the rest will leave you alone, for the sum of %{gold} gold.\nDo you accept?");
        else
    	    message += _("All %{offer} of the %{monster} will join your army for the sum of %{gold} gold.\nDo you accept?");
    }

    StringReplace(message, "%{offer}", join);
    StringReplace(message, "%{total}", troop.GetCount());
    StringReplace(message, "%{monster}", StringLower(troop.GetPluralName(join)));
    StringReplace(message, "%{gold}", gold);

    TextBox textbox(message, Font::BIG, BOXAREA_WIDTH);
    const int buttons = Dialog::YES | Dialog::NO;
    const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 6);
    int posy = 0;
    Text text;

    message = _("(Rate: %{percent})");
    StringReplace(message, "%{percent}", troop.GetMonster().GetCost().gold * join * 100 / gold);
    text.Set(message, Font::BIG);

    FrameBox box(10 + textbox.h() + 10 + text.h() + 40 + sprite.h() + 10, buttons);
    const Rect & pos = box.GetArea();

    posy = pos.y + 10;
    textbox.Blit(pos.x, posy);

    posy += textbox.h() + 10;
    text.Blit(pos.x + (pos.w - text.w()) / 2, posy);


    posy += text.h() + 40;
    sprite.Blit(pos.x + (pos.w - sprite.w()) / 2, posy);

    TextSprite tsTotal(GetString(gold) + " " + "(" + "total: " + GetString(world.GetKingdom(hero.GetColor()).GetFunds().Get(Resource::GOLD)) + ")", Font::SMALL,
	    pos.x + (pos.w - text.w()) / 2, posy + sprite.h() + 5);
    tsTotal.Show();

    ButtonGroups btnGroups(pos, buttons);
    Button btnMarket(pos.x + pos.w / 2 - 60 - 36, posy, (conf.ExtGameEvilInterface() ? ICN::ADVEBTNS : ICN::ADVBTNS), 4, 5);
    Button btnHeroes(pos.x + pos.w / 2 + 60, posy, (conf.ExtGameEvilInterface() ? ICN::ADVEBTNS : ICN::ADVBTNS), 0, 1);
    const Kingdom & kingdom = hero.GetKingdom();

    if(! kingdom.AllowPayment(payment_t(Resource::GOLD, gold)))
	btnGroups.DisableButton1(true);

    TextSprite tsEnough;

    if(kingdom.GetCountMarketplace())
    {
	if(kingdom.AllowPayment(payment_t(Resource::GOLD, gold)))
	    btnMarket.SetDisable(true);
	else
	{
	    std::string msg = _("Not enough gold (%{gold})");
	    StringReplace(msg, "%{gold}", gold - kingdom.GetFunds().Get(Resource::GOLD));
	    tsEnough.SetText(msg, Font::YELLOW_SMALL);
	    tsEnough.SetPos(btnMarket.x - 25, btnMarket.y - 17);
	    tsEnough.Show();
	    btnMarket.Draw();
	}
    }

    if(hero.GetArmy().GetCount() < hero.GetArmy().Size() || hero.GetArmy().HasMonster(troop))
	btnHeroes.SetDisable(true);
    else
    {
	TextBox textbox2(_("Not room in\nthe garrison"), Font::SMALL, 100);
	textbox2.Blit(btnHeroes.x - 35, btnHeroes.y - 30);
	btnHeroes.Draw();

	btnGroups.DisableButton1(true);
    }

    btnGroups.Draw();
    cursor.Show();
    display.Flip();

    LocalEvent & le = LocalEvent::Get();

    // message loop
    int result = Dialog::ZERO;

    while(result == Dialog::ZERO && le.HandleEvents())
    {
	if(btnMarket.isEnable())
    	    le.MousePressLeft(btnMarket) ? btnMarket.PressDraw() : btnMarket.ReleaseDraw();

	if(btnHeroes.isEnable())
    	    le.MousePressLeft(btnHeroes) ? btnHeroes.PressDraw() : btnHeroes.ReleaseDraw();

        if(!buttons && !le.MousePressRight()) break;

        result = btnGroups.QueueEventProcessing();

	if(btnMarket.isEnable() && le.MouseClickLeft(btnMarket))
	{
	    Marketplace(false);

	    cursor.Hide();
	    tsTotal.Hide();
	    tsTotal.SetText(GetString(gold) + " " + "(" + "total: " + GetString(world.GetKingdom(hero.GetColor()).GetFunds().Get(Resource::GOLD)) + ")");
	    tsTotal.Show();

	    if(kingdom.AllowPayment(payment_t(Resource::GOLD, gold)))
	    {
		tsEnough.Hide();
    		btnGroups.DisableButton1(false);
		btnGroups.Draw();
	    }
	    else
	    {
		tsEnough.Hide();
		std::string msg = _("Not enough gold (%{gold})");
		StringReplace(msg, "%{gold}", gold - kingdom.GetFunds().Get(Resource::GOLD));
		tsEnough.SetText(msg, Font::SMALL);
		tsEnough.Show();
	    }

	    cursor.Show();
	    display.Flip();
	}
	else
	if(btnHeroes.isEnable() && le.MouseClickLeft(btnHeroes))
	{
	    hero.OpenDialog(false, false);

	    if(hero.GetArmy().GetCount() < hero.GetArmy().Size())
	    {
    		btnGroups.DisableButton1(false);
		btnGroups.Draw();
	    }

	    cursor.Show();
	    display.Flip();
	}
    }

    cursor.Hide();
    cursor.SetThemes(oldthemes);
    cursor.Show();

    return result;
}