Пример #1
0
Skill::Secondary Dialog::SelectSecondarySkill(void)
{
    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    LocalEvent & le = LocalEvent::Get();

    std::vector<int> skills(MAXSECONDARYSKILL * 3, 0);

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    for(size_t ii = 0; ii < MAXSECONDARYSKILL * 3; ++ii) skills[ii] = ii;

    const u16 window_w = 310;
    const u16 window_h = 280;

    Dialog::FrameBorder frameborder;
    frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH,
			    (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h);
    frameborder.Redraw(AGG::GetICN(ICN::TEXTBAK2, 0));

    const Rect & area = frameborder.GetArea();

    SelectEnumSecSkill listbox(area);

    listbox.SetListContent(skills);
    listbox.Redraw();

    ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL);
    btnGroups.Draw();

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

    u16 result = Dialog::ZERO;

    while(result == Dialog::ZERO && ! listbox.ok && le.HandleEvents())
    {
        result = btnGroups.QueueEventProcessing();
        listbox.QueueEventProcessing();

        if(!cursor.isVisible())
        {
            listbox.Redraw();
            cursor.Show();
            display.Flip();
        }
    }

    Skill::Secondary skill;

    if(result == Dialog::OK || listbox.ok)
    {
	skill.SetSkill(1 + (listbox.GetCurrent() / 3));
	skill.SetLevel(1 + (listbox.GetCurrent() % 3));
    }

    return skill;
}
Пример #2
0
Heroes::heroes_t Dialog::SelectHeroes(Heroes::heroes_t cur)
{
    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    LocalEvent & le = LocalEvent::Get();

    std::vector<int> heroes(static_cast<int>(Heroes::SANDYSANDY), Heroes::UNKNOWN);

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);


    for(size_t ii = 0; ii < heroes.size(); ++ii) heroes[ii] = Heroes::ConvertID(ii);

    const u16 window_w = 240;
    const u16 window_h = 280;

    Dialog::FrameBorder frameborder;
    frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH,
			    (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h);
    frameborder.Redraw(AGG::GetICN(ICN::TEXTBAK2, 0));

    const Rect & area = frameborder.GetArea();

    SelectEnumHeroes listbox(area);

    listbox.SetListContent(heroes);
    if(cur != Heroes::UNKNOWN)
	listbox.SetCurrent(static_cast<int>(cur));
    listbox.Redraw();

    ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL);
    btnGroups.Draw();

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

    u16 result = Dialog::ZERO;

    while(result == Dialog::ZERO && ! listbox.ok && le.HandleEvents())
    {
        result = btnGroups.QueueEventProcessing();
        listbox.QueueEventProcessing();

        if(!cursor.isVisible())
        {
            listbox.Redraw();
            cursor.Show();
            display.Flip();
        }
    }

    return result == Dialog::OK || listbox.ok ?
	Heroes::ConvertID(listbox.GetCurrent()) : Heroes::UNKNOWN;
}
Пример #3
0
Monster Dialog::SelectMonster(u8 id)
{
    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    LocalEvent & le = LocalEvent::Get();

    std::vector<int> monsters(static_cast<int>(Monster::WATER_ELEMENT), Monster::UNKNOWN);

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);


    for(size_t ii = 0; ii < monsters.size(); ++ii) monsters[ii] = ii + 1; // skip Monser::UNKNOWN

    const u16 window_w = 260;
    const u16 window_h = 280;

    Dialog::FrameBorder frameborder;
    frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH,
			    (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h);
    frameborder.Redraw(AGG::GetICN(ICN::TEXTBAK2, 0));

    const Rect & area = frameborder.GetArea();

    SelectEnumMonster listbox(area);

    listbox.SetListContent(monsters);
    if(id != Monster::UNKNOWN)
	listbox.SetCurrent(static_cast<int>(id));
    listbox.Redraw();

    ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL);
    btnGroups.Draw();

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

    u16 result = Dialog::ZERO;

    while(result == Dialog::ZERO && ! listbox.ok && le.HandleEvents())
    {
        result = btnGroups.QueueEventProcessing();
        listbox.QueueEventProcessing();

        if(!cursor.isVisible())
        {
            listbox.Redraw();
            cursor.Show();
            display.Flip();
        }
    }

    return result == Dialog::OK || listbox.ok ?
	Monster(listbox.GetCurrent()) : Monster(Monster::UNKNOWN);
}
Пример #4
0
Spell Dialog::SelectSpell(u8 cur)
{
    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    LocalEvent & le = LocalEvent::Get();

    std::vector<int> spells(static_cast<int>(Spell::STONE - 1), Spell::NONE);

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    for(size_t ii = 0; ii < spells.size(); ++ii) spells[ii] = ii + 1;

    const u16 window_w = 340;
    const u16 window_h = 280;

    Dialog::FrameBorder frameborder;
    frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH,
			    (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h);
    frameborder.Redraw(AGG::GetICN(ICN::TEXTBAK2, 0));

    const Rect & area = frameborder.GetArea();

    SelectEnumSpell listbox(area);

    listbox.SetListContent(spells);
    if(cur != Spell::NONE)
	listbox.SetCurrent(static_cast<int>(cur));
    listbox.Redraw();

    ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL);
    btnGroups.Draw();

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

    u16 result = Dialog::ZERO;

    while(result == Dialog::ZERO && ! listbox.ok && le.HandleEvents())
    {
        result = btnGroups.QueueEventProcessing();
        listbox.QueueEventProcessing();

        if(!cursor.isVisible())
        {
            listbox.Redraw();
            cursor.Show();
            display.Flip();
        }
    }

    return result == Dialog::OK || listbox.ok ?
	Spell(listbox.GetCurrent()) : Spell(Spell::NONE);
}
Пример #5
0
bool FH2LocalClient::Prepare4BattleOnly(void)
{
    // get color
    if(! GetPlayersInfo()) return false;

    if(2 > players.size())
    {
	GetLoadMaps(true, false);

	LocalEvent & le = LocalEvent::Get();
	Cursor & cursor = Cursor::Get();
	Display & display = Display::Get();

	cursor.Hide();
	TextBox textbox("wait other player", Font::BIG, BOXAREA_WIDTH);
	Dialog::Box box(10 + textbox.h(), Dialog::CANCEL);
	const Rect & pos = box.GetArea();                                                                                          
	textbox.Blit(pos.x, pos.y + 20);

	ButtonGroups btnGroups(box.GetArea(), Dialog::CANCEL);
	btnGroups.Draw();

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

	QueueMessage packet;

	DEBUG(DBG_NETWORK, DBG_INFO, "wait: " << Network::GetMsgString(MSG_UPDATE_PLAYERS));

	while(le.HandleEvents())
	{
	    if(Dialog::ZERO != btnGroups.QueueEventProcessing())
		return false;

	    if(Ready())
    	    {
        	if(!Network::RecvMessage(*this, packet))
            	    return false;

        	if(MSG_UPDATE_PLAYERS == packet.GetID())
		    break;
    	    }
    	    DELAY(10);
	}

	MsgUpdatePlayers(packet);
    }

    return true;
}
Пример #6
0
u16 Dialog::Message(const std::string &header, const std::string &message, Font::type_t ft, u16 buttons)
{
    Display & display = Display::Get();
    const ICN::icn_t system = Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM;

    // preload
    AGG::PreloadObject(system);

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

    TextBox textbox1(header, Font::YELLOW_BIG, BOXAREA_WIDTH);
    TextBox textbox2(message, ft, BOXAREA_WIDTH);

    Box box(10 + (header.size() ? textbox1.h() + 10 : 0) + textbox2.h(), buttons);
    const Rect & pos = box.GetArea();

    if(header.size()) textbox1.Blit(pos.x, pos.y + 10);
    if(message.size()) textbox2.Blit(pos.x, pos.y + 10 + (header.size() ? textbox1.h() : 0) + 10);

    LocalEvent & le = LocalEvent::Get();

    ButtonGroups btnGroups(box.GetArea(), buttons);
    btnGroups.Draw();
    
    cursor.Show();
    display.Flip();

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

    while(result == Dialog::ZERO && le.HandleEvents())
    {
        if(!buttons && !le.MousePressRight()) break;

	result = btnGroups.QueueEventProcessing();
    }

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

    return result;
}
Пример #7
0
int Dialog::SelectHeroes(int cur)
{
    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    LocalEvent & le = LocalEvent::Get();

    std::vector<int> heroes(static_cast<int>(Heroes::SANDYSANDY), Heroes::UNKNOWN);

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);


    for(size_t ii = 0; ii < heroes.size(); ++ii) heroes[ii] = ii;

    Dialog::FrameBorder frameborder(Size(240, 280), AGG::GetICN(ICN::TEXTBAK2, 0));
    const Rect & area = frameborder.GetArea();

    SelectEnumHeroes listbox(area);

    listbox.SetListContent(heroes);
    if(cur != Heroes::UNKNOWN)
	listbox.SetCurrent(cur);
    listbox.Redraw();

    ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL);
    btnGroups.Draw();

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

    int result = Dialog::ZERO;
    while(result == Dialog::ZERO && ! listbox.ok && le.HandleEvents())
    {
        result = btnGroups.QueueEventProcessing();
        listbox.QueueEventProcessing();

        if(!cursor.isVisible())
        {
            listbox.Redraw();
            cursor.Show();
            display.Flip();
        }
    }

    return result == Dialog::OK || listbox.ok ?
	listbox.GetCurrent() : Heroes::UNKNOWN;
}
Пример #8
0
void Dialog::ExtSettings(bool readonly)
{
    Display & display = Display::Get();
    const Settings & conf = Settings::Get();

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

    const int window_h = conf.QVGA() ? 224 : 400;
    Dialog::FrameBorder frameborder(Size(320, window_h));
    const Rect & area = frameborder.GetArea();

    Text text("FHeroes2 Settings", Font::YELLOW_BIG);
    text.Blit(area.x + (area.w - text.w()) / 2, area.y + 6);

    std::vector<u32> states;
    states.reserve(64);

    states.push_back(Settings::GAME_SAVE_REWRITE_CONFIRM);
    states.push_back(Settings::GAME_ALSO_CONFIRM_AUTOSAVE);
    states.push_back(Settings::GAME_REMEMBER_LAST_FOCUS);
    states.push_back(Settings::GAME_SHOW_SYSTEM_INFO);
    states.push_back(Settings::GAME_EVIL_INTERFACE);
    states.push_back(Settings::GAME_BATTLE_SHOW_GRID);
    states.push_back(Settings::GAME_BATTLE_SHOW_MOUSE_SHADOW);
    states.push_back(Settings::GAME_BATTLE_SHOW_MOVE_SHADOW);
    states.push_back(Settings::GAME_BATTLE_SHOW_DAMAGE);

    if(! conf.QVGA())
    {
	states.push_back(Settings::GAME_CASTLE_FLASH_BUILDING);
	states.push_back(Settings::GAME_HIDE_INTERFACE);
    }

    if(!conf.PocketPC())
	states.push_back(Settings::GAME_DYNAMIC_INTERFACE);

    states.push_back(Settings::GAME_AUTOSAVE_ON);
    states.push_back(Settings::GAME_AUTOSAVE_BEGIN_DAY);

    if(conf.VideoMode().w == 640 && conf.VideoMode().h == 480)
	states.push_back(Settings::GAME_USE_FADE);

#ifdef BUILD_RELEASE
    states.push_back(Settings::GAME_SHOW_SDL_LOGO);
#endif
    states.push_back(Settings::GAME_CONTINUE_AFTER_VICTORY);
    states.push_back(Settings::WORLD_SHOW_VISITED_CONTENT);
    states.push_back(Settings::WORLD_ABANDONED_MINE_RANDOM);
    states.push_back(Settings::WORLD_SAVE_MONSTER_BATTLE);
    states.push_back(Settings::WORLD_ALLOW_SET_GUARDIAN);
    states.push_back(Settings::WORLD_GUARDIAN_TWO_DEFENSE);
    states.push_back(Settings::WORLD_EXT_OBJECTS_CAPTURED);
    states.push_back(Settings::WORLD_NOREQ_FOR_ARTIFACTS);
    states.push_back(Settings::WORLD_SCOUTING_EXTENDED);
    states.push_back(Settings::WORLD_ARTSPRING_SEPARATELY_VISIT);
    states.push_back(Settings::WORLD_ARTIFACT_CRYSTAL_BALL);
    states.push_back(Settings::WORLD_ONLY_FIRST_MONSTER_ATTACK);
    states.push_back(Settings::WORLD_EYE_EAGLE_AS_SCHOLAR);
    states.push_back(Settings::WORLD_BAN_WEEKOF);
    states.push_back(Settings::WORLD_NEW_VERSION_WEEKOF);
    states.push_back(Settings::WORLD_BAN_PLAGUES);
    states.push_back(Settings::WORLD_BAN_MONTHOF_MONSTERS);
    states.push_back(Settings::WORLD_STARTHERO_LOSSCOND4HUMANS);
    states.push_back(Settings::WORLD_1HERO_HIRED_EVERY_WEEK);
    states.push_back(Settings::CASTLE_1HERO_HIRED_EVERY_WEEK);
    states.push_back(Settings::WORLD_DWELLING_ACCUMULATE_UNITS);
    states.push_back(Settings::WORLD_USE_UNIQUE_ARTIFACTS_ML);
    states.push_back(Settings::WORLD_USE_UNIQUE_ARTIFACTS_RS);
    states.push_back(Settings::WORLD_USE_UNIQUE_ARTIFACTS_PS);
    states.push_back(Settings::WORLD_USE_UNIQUE_ARTIFACTS_SS);
    states.push_back(Settings::WORLD_DISABLE_BARROW_MOUNDS);
    states.push_back(Settings::HEROES_BUY_BOOK_FROM_SHRINES);
    states.push_back(Settings::HEROES_LEARN_SPELLS_WITH_DAY);
    states.push_back(Settings::HEROES_COST_DEPENDED_FROM_LEVEL);
    states.push_back(Settings::HEROES_REMEMBER_POINTS_RETREAT);
    states.push_back(Settings::HEROES_SURRENDERING_GIVE_EXP);
    states.push_back(Settings::HEROES_RECALCULATE_MOVEMENT);
    states.push_back(Settings::HEROES_PATROL_ALLOW_PICKUP);
    states.push_back(Settings::HEROES_AUTO_MOVE_BATTLE_DST);
    states.push_back(Settings::HEROES_TRANSCRIBING_SCROLLS);
    states.push_back(Settings::HEROES_ALLOW_BANNED_SECSKILLS);
    states.push_back(Settings::HEROES_ARENA_ANY_SKILLS);

    if(! conf.QVGA())
	states.push_back(Settings::CASTLE_ALLOW_BUY_FROM_WELL);

    states.push_back(Settings::CASTLE_ALLOW_GUARDIANS);
    states.push_back(Settings::CASTLE_MAGEGUILD_POINTS_TURN);
    states.push_back(Settings::CASTLE_ALLOW_RECRUITS_SPECIAL);

    states.push_back(Settings::UNIONS_ALLOW_HERO_MEETINGS);
    states.push_back(Settings::UNIONS_ALLOW_CASTLE_VISITING);

    states.push_back(Settings::BATTLE_SOFT_WAITING);
    states.push_back(Settings::BATTLE_OBJECTS_ARCHERS_PENALTY);
    states.push_back(Settings::BATTLE_MERGE_ARMIES);
    states.push_back(Settings::BATTLE_ARCHMAGE_RESIST_BAD_SPELL);
    states.push_back(Settings::BATTLE_MAGIC_TROOP_RESIST);
    states.push_back(Settings::BATTLE_SKIP_INCREASE_DEFENSE);
    states.push_back(Settings::BATTLE_REVERSE_WAIT_ORDER);

    if(conf.PocketPC())
    {
	states.push_back(Settings::POCKETPC_HIDE_CURSOR);
	states.push_back(Settings::POCKETPC_TAP_MODE);
	states.push_back(Settings::POCKETPC_LOW_MEMORY);
	states.push_back(Settings::POCKETPC_DRAG_DROP_SCROLL);
#ifdef ANDROID
	states.push_back(Settings::POCKETPC_LOW_RESOLUTION);
#endif
    }

    SettingsListBox listbox(area, readonly);

    const int ah = window_h - 60;

    listbox.RedrawBackground(area);
    listbox.SetScrollButtonUp(ICN::DROPLISL, 6, 7, Point(area.x + 295, area.y + 25));
    listbox.SetScrollButtonDn(ICN::DROPLISL, 8, 9, Point(area.x + 295, area.y + ah + 5));
    listbox.SetScrollSplitter(AGG::GetICN(ICN::DROPLISL, 13), Rect(area.x + 300, area.y + 49, 12, ah - 43));
    listbox.SetAreaMaxItems(ah / 40);
    listbox.SetAreaItems(Rect(area.x + 10, area.y + 30, 290, ah + 5));
    listbox.SetListContent(states);
    listbox.Redraw();

    LocalEvent & le = LocalEvent::Get();

    ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL);
    btnGroups.Draw();

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

    // message loop
    int result = Dialog::ZERO;
    while(result == Dialog::ZERO && le.HandleEvents())
    {
	result = btnGroups.QueueEventProcessing();

	listbox.QueueEventProcessing();

	if(!cursor.isVisible())
	{
	    listbox.Redraw();
	    cursor.Show();
	    display.Flip();
	}
    }

    // store
    if(result == Dialog::OK)
    {
	le.SetTapMode(conf.ExtPocketTapMode());
	Settings::Get().BinarySave();
    }
}
Game::menu_t PocketPC::SelectScenario(void)
{
    Settings & conf = Settings::Get();
    Cursor & cursor = Cursor::Get();
    Display & display = Display::Get();
    LocalEvent & le = LocalEvent::Get();

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    const Sprite &sprite = AGG::GetICN(ICN::HEROES, 0);
    Rect src_rt((sprite.w() - display.w()) / 2, 0, display.w(), display.h());
    sprite.Blit(src_rt, 0, 0);

    MapsFileInfoList all;
    if(!PrepareMapsFileInfoList(all, false))
    {
        Dialog::Message(_("Warning"), _("No maps available!"), Font::BIG, Dialog::OK);
        return Game::MAINMENU;
    }

    MapsFileInfoList small;
    MapsFileInfoList medium;
    MapsFileInfoList large;
    MapsFileInfoList xlarge;

    small.reserve(all.size());
    medium.reserve(all.size());
    large.reserve(all.size());
    xlarge.reserve(all.size());

    for(MapsFileInfoList::iterator cur = all.begin(); cur != all.end(); ++ cur)
    {
	switch((*cur).size_w)
	{
    	    case Maps::SMALL:	small.push_back(*cur); break;
    	    case Maps::MEDIUM:	medium.push_back(*cur); break;
    	    case Maps::LARGE:	large.push_back(*cur); break;
    	    case Maps::XLARGE:	xlarge.push_back(*cur); break;
	    default: continue;
	}
    }

    const u16 window_w = 320;
    const u16 window_h = 224;

    Dialog::FrameBorder frameborder;
    frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h);
    frameborder.Redraw();

    const Rect & rt = frameborder.GetArea();
    const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0);
    background.Blit(Rect(0, 0, window_w, window_h), rt);

    ButtonGroups btnGroups(rt, Dialog::OK|Dialog::CANCEL);

    Button buttonSelectSmall(rt.x + 7, rt.y + 12, ICN::REQUESTS, 9, 10);
    Button buttonSelectMedium(rt.x + 69, rt.y + 12, ICN::REQUESTS, 11, 12);
    Button buttonSelectLarge(rt.x + 131, rt.y + 12, ICN::REQUESTS, 13, 14);
    Button buttonSelectXLarge(rt.x + 193, rt.y + 12, ICN::REQUESTS, 15, 16);
    Button buttonSelectAll(rt.x + 255, rt.y + 12, ICN::REQUESTS, 17, 18);

    if(all.empty()) btnGroups.DisableButton1(true);
    if(small.empty()) buttonSelectSmall.SetDisable(true);
    if(medium.empty()) buttonSelectMedium.SetDisable(true);
    if(large.empty()) buttonSelectLarge.SetDisable(true);
    if(xlarge.empty()) buttonSelectXLarge.SetDisable(true);

    ScenarioListBox listbox(rt);

    listbox.RedrawBackground(rt);
    listbox.SetScrollButtonUp(ICN::REQUESTS, 5, 6, Point(rt.x + 285, rt.y + 40));
    listbox.SetScrollButtonDn(ICN::REQUESTS, 7, 8, Point(rt.x + 285, rt.y + 175));
    listbox.SetScrollSplitter(AGG::GetICN(ICN::ESCROLL, 3), Rect(rt.x + 288, rt.y + 58, 12, 114));
    listbox.SetAreaMaxItems(8);
    listbox.SetAreaItems(Rect(rt.x + 17, rt.y + 37, 266, 156));
    listbox.SetListContent(all);

    listbox.Redraw();

    btnGroups.Draw();

    buttonSelectSmall.Draw();
    buttonSelectMedium.Draw();
    buttonSelectLarge.Draw();
    buttonSelectXLarge.Draw();
    buttonSelectAll.Draw();

    u16 result = Dialog::ZERO;

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

    while(result == Dialog::ZERO && le.HandleEvents())
    {
	le.MousePressLeft(buttonSelectSmall) && buttonSelectSmall.isEnable() ? buttonSelectSmall.PressDraw() : buttonSelectSmall.ReleaseDraw();
	le.MousePressLeft(buttonSelectMedium) && buttonSelectMedium.isEnable() ? buttonSelectMedium.PressDraw() : buttonSelectMedium.ReleaseDraw();
	le.MousePressLeft(buttonSelectLarge) && buttonSelectLarge.isEnable() ? buttonSelectLarge.PressDraw() : buttonSelectLarge.ReleaseDraw();
	le.MousePressLeft(buttonSelectXLarge) && buttonSelectXLarge.isEnable() ? buttonSelectXLarge.PressDraw() : buttonSelectXLarge.ReleaseDraw();
	le.MousePressLeft(buttonSelectAll) ? buttonSelectAll.PressDraw() : buttonSelectAll.ReleaseDraw();

	result = btnGroups.QueueEventProcessing();

	if(((le.MouseClickLeft(buttonSelectSmall) || le.KeyPress(KEY_s)) && buttonSelectSmall.isEnable()) && buttonSelectSmall.isEnable())
	{
	    listbox.SetListContent(small);
	    cursor.Hide();
	}
	else
	if(((le.MouseClickLeft(buttonSelectMedium) || le.KeyPress(KEY_m)) && buttonSelectMedium.isEnable()) && buttonSelectMedium.isEnable())
	{
	    listbox.SetListContent(medium);
	    cursor.Hide();
	}
	else
	if(((le.MouseClickLeft(buttonSelectLarge) || le.KeyPress(KEY_l)) && buttonSelectLarge.isEnable()) && buttonSelectLarge.isEnable())
	{
	    listbox.SetListContent(large);
	    cursor.Hide();
	}
	else
	if(((le.MouseClickLeft(buttonSelectXLarge) || le.KeyPress(KEY_x)) && buttonSelectXLarge.isEnable()) && buttonSelectXLarge.isEnable())
	{
	    listbox.SetListContent(xlarge);
	    cursor.Hide();
	}
	else
	if(le.MouseClickLeft(buttonSelectAll) || le.KeyPress(KEY_a))
	{
	    listbox.SetListContent(all);
	    cursor.Hide();
	}

	listbox.QueueEventProcessing();

	if(!cursor.isVisible())
	{
	    listbox.Redraw();
	    cursor.Show();
	    display.Flip();
	}
    }

    if(Dialog::OK == result)
    {
	conf.SetCurrentFileInfo(listbox.GetCurrent());
    	conf.SetGameDifficulty(Difficulty::NORMAL);

	return Game::SCENARIOINFO;
    }

    return Game::MAINMENU;
}
Пример #10
0
void Dialog::MakeGiftResource(void)
{
    Cursor & cursor = Cursor::Get();
    Display & display = Display::Get();
    LocalEvent & le = LocalEvent::Get();
    const Settings & conf = Settings::Get();

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    const u16 window_w = 320;
    const u16 window_h = 224;

    Dialog::FrameBorder frameborder;
    frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h);
    frameborder.Redraw();

    const Rect & box = frameborder.GetArea();
    const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0);
    background.Blit(Rect(0, 0, window_w, window_h), box);

    Kingdom & myKingdom = world.GetKingdom(conf.CurrentColor());

    Funds funds1(myKingdom.GetFunds());
    Funds funds2;
    Text text;

    text.Set("Select Recipients");
    text.Blit(box.x + (box.w - text.w()) / 2, box.y + 5);

    SelectRecipientsColors selector(Point(box.x + 65, box.y + 28));
    selector.Redraw();

    text.Set("Your Funds");
    text.Blit(box.x + (box.w - text.w()) / 2, box.y + 55);

    ResourceBar info1(funds1, box.x + 25, box.y + 80);
    info1.Redraw();

    text.Set("Planned Gift");
    text.Blit(box.x + (box.w - text.w()) / 2, box.y + 125);

    ResourceBar info2(funds2, box.x + 25, box.y + 150);
    info2.Redraw();


    ButtonGroups btnGroups(box, Dialog::OK|Dialog::CANCEL);
    btnGroups.DisableButton1(true);
    btnGroups.Draw();


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

    u8 count = Color::Count(selector.recipients);

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

    while(result == Dialog::ZERO && le.HandleEvents())
    {
	if(selector.QueueEventProcessing())
	{
	    u8 new_count = Color::Count(selector.recipients);
	    cursor.Hide();
	    btnGroups.DisableButton1(0 == new_count || 0 == funds2.GetValidItems());
	    if(count != new_count)
	    {
		funds1 = myKingdom.GetFunds();
		funds2.Reset();
		info1.Redraw();
		info2.Redraw();
		count = new_count;
	    }
	    btnGroups.Draw();
	    selector.Redraw();
	    cursor.Show();
	    display.Flip();
	}
	else
	if(info2.QueueEventProcessing(funds1, count))
	{
	    cursor.Hide();
	    btnGroups.DisableButton1(0 == Color::Count(selector.recipients) || 0 == funds2.GetValidItems());
	    info1.Redraw();
	    info2.Redraw();
	    btnGroups.Draw();
	    cursor.Show();
	    display.Flip();
	}

        result = btnGroups.QueueEventProcessing();
    }

    if(Dialog::OK == result)
    {
	EventDate event;

	event.resource = funds2;
	event.computer = true;
	event.first = world.CountDay() + 1;
	event.subsequent = 0;
	event.colors = selector.recipients;
	event.message = "Gift from %{name}";
	const Player* player = Settings::Get().GetPlayers().GetCurrent();
	if(player)
	    String::Replace(event.message, "%{name}", player->name);

	world.AddEventDate(event);

	if(1 < count) funds2 *= count;
	myKingdom.OddFundsResource(funds2);
    }
}
Пример #11
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;
}
Пример #12
0
bool ActionSpellTownPortal(Heroes & hero)
{
    const Kingdom & kingdom = world.GetKingdom(hero.GetColor());
    std::vector<s32> castles;

    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    LocalEvent & le = LocalEvent::Get();

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    for(KingdomCastles::const_iterator it = kingdom.GetCastles().begin(); it != kingdom.GetCastles().end(); ++it)
        if(*it && !(*it)->GetHeroes().Guest()) castles.push_back((**it).GetIndex());

    if(castles.empty())
    {
        Dialog::Message("", _("No avaialble town. Spell Failed!!!"), Font::BIG, Dialog::OK);
        return false;
    }

    const u16 window_w = 280;
    const u16 window_h = 200;

    Dialog::FrameBorder* frameborder = new Dialog::FrameBorder();
    frameborder->SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h);
    frameborder->Redraw();

    const Rect & area = frameborder->GetArea();
    const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0);
    background.Blit(Rect(0, 0, window_w, window_h), area);

    u16 result = Dialog::ZERO;

    CastleIndexListBox listbox(area, result);

    listbox.RedrawBackground(area);
    listbox.SetScrollButtonUp(ICN::LISTBOX, 3, 4, Point(area.x + 256, area.y + 55));
    listbox.SetScrollButtonDn(ICN::LISTBOX, 5, 6, Point(area.x + 256, area.y + 145));
    listbox.SetScrollSplitter(AGG::GetICN(ICN::LISTBOX, 10), Rect(area.x + 261, area.y + 78, 14, 64));
    listbox.SetAreaMaxItems(5);
    listbox.SetAreaItems(Rect(area.x + 10, area.y + 60, 250, 100));
    listbox.SetListContent(castles);
    listbox.Redraw();

    ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL);
    btnGroups.Draw();

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

    while(result == Dialog::ZERO && le.HandleEvents())
    {
        result = btnGroups.QueueEventProcessing();

        listbox.QueueEventProcessing();

        if(!cursor.isVisible())
        {
            listbox.Redraw();
            cursor.Show();
            display.Flip();
        }
    }

    delete frameborder;

    // store
    if(result == Dialog::OK)
        return HeroesTownGate(hero, world.GetCastle(listbox.GetCurrent()));

    return false;
}