void ProfileAddGui::createSignals()
{
    connect(ui.radioButton_unregistered_nick, SIGNAL(clicked()), this, SLOT(hidePass()));
    connect(ui.radioButton_registered_nick, SIGNAL(clicked()), this, SLOT(showPass()));
    connect(ui.pushButton_register_nick, SIGNAL(clicked()), this, SLOT(buttonRegisterNick()));
    connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(buttonOk()));
    connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
}
Example #2
0
Skill::Primary::skill_t Dialog::SelectSkillFromArena(void)
{
    Display & display = Display::Get();
    const ICN::icn_t system = Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM;

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

    TextBox textbox(_("You enter the arena and face a pack of vicious lions. You handily defeat them, to the wild cheers of the crowd.  Impressed by your skill, the aged trainer of gladiators agrees to train you in a skill of your choice."), Font::BIG, BOXAREA_WIDTH);
    const Sprite & sprite = AGG::GetICN(ICN::XPRIMARY, 0);
    const u8 spacer = Settings::Get().QVGA() ? 5 : 10;

    Dialog::FrameBox box(textbox.h() + spacer + sprite.h() + 15, true);

    const Rect & box_rt = box.GetArea();
    Point dst_pt = box_rt;

    textbox.Blit(dst_pt);
    dst_pt.y += textbox.h() + spacer;

    Skill::Primary::skill_t  res = Skill::Primary::ATTACK;
    Rect rect1, rect2, rect3, rect4;

    if(Settings::Get().ExtHeroArenaCanChoiseAnySkills())
    {
	rect1 = Rect(dst_pt.x + box_rt.w / 2 - 2 * sprite.w() - 30, dst_pt.y, sprite.w(), sprite.h());
	rect2 = Rect(dst_pt.x + box_rt.w / 2 - sprite.w() - 10, dst_pt.y, sprite.w(), sprite.h());
	rect3 = Rect(dst_pt.x + box_rt.w / 2 + 10, dst_pt.y, sprite.w(), sprite.h());
	rect4 = Rect(dst_pt.x + box_rt.w / 2 + sprite.w() + 30, dst_pt.y, sprite.w(), sprite.h());
    }
    else
    {
	rect1 = Rect(dst_pt.x + box_rt.w / 2 - 2 * sprite.w() - 10, dst_pt.y, sprite.w(), sprite.h());
	rect2 = Rect(dst_pt.x + box_rt.w / 2 - sprite.w() + 15, dst_pt.y, sprite.w(), sprite.h());
	rect3 = Rect(dst_pt.x + box_rt.w / 2 + 40, dst_pt.y, sprite.w(), sprite.h());
    }

    InfoSkillClear(rect1, rect2, rect3, rect4);
    InfoSkillSelect(res, rect1, rect2, rect3, rect4);

    // info texts
    Text text(Skill::Primary::String(Skill::Primary::ATTACK), Font::SMALL);
    dst_pt.x = rect1.x + (rect1.w - text.w()) / 2;
    dst_pt.y = rect1.y + rect1.h + 5;
    text.Blit(dst_pt);

    text.Set(Skill::Primary::String(Skill::Primary::DEFENSE));
    dst_pt.x = rect2.x + (rect2.w - text.w()) / 2;
    dst_pt.y = rect2.y + rect2.h + 5;
    text.Blit(dst_pt);

    text.Set(Skill::Primary::String(Skill::Primary::POWER));
    dst_pt.x = rect3.x + (rect3.w - text.w()) / 2;
    dst_pt.y = rect3.y + rect3.h + 5;
    text.Blit(dst_pt);

    if(Settings::Get().ExtHeroArenaCanChoiseAnySkills())
    {
	text.Set(Skill::Primary::String(Skill::Primary::KNOWLEDGE));
	dst_pt.x = rect4.x + (rect4.w - text.w()) / 2;
	dst_pt.y = rect4.y + rect4.h + 5;
	text.Blit(dst_pt);
    }

    // buttons
    dst_pt.x = box_rt.x + (box_rt.w - AGG::GetICN(system, 1).w()) / 2;
    dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h();
    Button buttonOk(dst_pt.x, dst_pt.y, system, 1, 2);

    LocalEvent & le = LocalEvent::Get();
    bool redraw = false;

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

    // message loop
    while(le.HandleEvents())
    {
	le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw();

	if(Game::HotKeyPress(Game::EVENT_DEFAULT_LEFT) && Skill::Primary::UNKNOWN != InfoSkillPrev(res))
	{
	    res = InfoSkillPrev(res);
	    redraw = true;
	}
	else
	if(Game::HotKeyPress(Game::EVENT_DEFAULT_RIGHT) && Skill::Primary::UNKNOWN != InfoSkillNext(res))
	{
	    res = InfoSkillNext(res);
	    redraw = true;
	}
	else
	if(le.MouseClickLeft(rect1))
	{
	    res = Skill::Primary::ATTACK;
	    redraw = true;
	}
	else
	if(le.MouseClickLeft(rect2))
	{
	    res = Skill::Primary::DEFENSE;
	    redraw = true;
	}
	else
	if(le.MouseClickLeft(rect3))
	{
	    res = Skill::Primary::POWER;
	    redraw = true;
	}
	else
	if(Settings::Get().ExtHeroArenaCanChoiseAnySkills() && le.MouseClickLeft(rect4))
	{
	    res = Skill::Primary::KNOWLEDGE;
	    redraw = true;
	}

	if(redraw)
	{
	    cursor.Hide();
	    InfoSkillClear(rect1, rect2, rect3, rect4);
	    InfoSkillSelect(res, rect1, rect2, rect3, rect4);
	    cursor.Show();
	    display.Flip();
	    redraw = false;
	}

        if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || le.MouseClickLeft(buttonOk)) break;
    }

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

    return res;
}
bool Dialog::SelectCount(const std::string &header, u32 min, u32 max, u32 & cur, u8 step)
{
    Display & display = Display::Get();

    if(min >= max) min = 0;
    if(cur > max || cur < min) cur = min;

    const ICN::icn_t system = Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM;

    // preload
    AGG::Cache::PreloadObject(system);

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

    Text text(header, Font::BIG);
    const u8 spacer = Settings::Get().QVGA() ? 5 : 10;

    Box box(text.h() + spacer + 30, true);

    const Rect & pos = box.GetArea();
    Point pt;

    // text
    pt.x = pos.x + (pos.w - text.w()) / 2;
    pt.y = pos.y;
    text.Blit(pt);

    // sprite edit
    const Surface & sprite_edit = AGG::GetICN(ICN::TOWNWIND, 4);
    pt.x = pos.x + 80;
    pt.y = pos.y + 35;
    sprite_edit.Blit(pt, display);

    text.Set(GetString(cur));
    pt.x = pos.x + 80 + (sprite_edit.w() - text.w()) / 2;
    pt.y = pos.y + 36;
    text.Blit(pt);

    // buttons
    pt.x = pos.x + 150;
    pt.y = pos.y + 31;
    Button buttonUp(pt, ICN::TOWNWIND, 5, 6);

    pt.x = pos.x + 150;
    pt.y = pos.y + 47;
    Button buttonDn(pt, ICN::TOWNWIND, 7, 8);

    pt.x = pos.x;
    pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 1).h();
    Button buttonOk(pt, system, 1, 2);

    pt.x = pos.x + pos.w - AGG::GetICN(system, 3).w();
    pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 3).h();
    Button buttonCancel(pt, system, 3, 4);

    text.Set("MAX", Font::SMALL);
    const Rect rectMax(pos.x + 173, pos.y + 38, text.w(), text.h());
    text.Blit(rectMax.x, rectMax.y);

    LocalEvent & le = LocalEvent::Get();

    buttonUp.Draw();
    buttonDn.Draw();
    buttonOk.Draw();
    buttonCancel.Draw();

    bool redraw_count = false;
    cursor.Show();
    display.Flip();

    // message loop
    while(le.HandleEvents())
    {
	le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw();
        le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw();
	le.MousePressLeft(buttonUp) ? buttonUp.PressDraw() : buttonUp.ReleaseDraw();
	le.MousePressLeft(buttonDn) ? buttonDn.PressDraw() : buttonDn.ReleaseDraw();

	if(PressIntKey(min, max, cur))
	    redraw_count = true;

        // max
        if(le.MouseClickLeft(rectMax))
        {
    	    cur = max;
    	    redraw_count = true;
        }
	else
	// up
	if((le.MouseWheelUp(pos) ||
            le.MouseClickLeft(buttonUp)) && cur < max)
	{
	    cur += cur + step <= max ? step : max - cur;
    	    redraw_count = true;
	}
	else
	// down
	if((le.MouseWheelDn(pos) ||
            le.MouseClickLeft(buttonDn)) && min < cur)
	{
	    cur -= min + cur >= step ? step : cur;
    	    redraw_count = true;
	}

	if(redraw_count)
	{
	    cursor.Hide();
	    pt.x = pos.x + 80;
	    pt.y = pos.y + 35;
	    sprite_edit.Blit(pt, display);

	    text.Set(GetString(cur), Font::BIG);
	    pt.x = pos.x + 80 + (sprite_edit.w() - text.w()) / 2;
	    pt.y = pos.y + 36;
	    text.Blit(pt);
	    cursor.Show();
	    display.Flip();

	    redraw_count = false;
	}

        if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || le.MouseClickLeft(buttonOk)){ return true; }
	else
	if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancel)){ cur = 0;  break; }
    }

    return false;
}
bool Dialog::InputString(const std::string &header, std::string &res)
{
    const ICN::icn_t system = Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM;

    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();
    cursor.Hide();
    Cursor::themes_t oldcursor = cursor.Themes();
    cursor.SetThemes(cursor.POINTER);

    //const bool pda = Settings::Get().PocketPC();
    if(res.size()) res.clear();
    res.reserve(48);
    size_t charInsertPos = 0;

    TextBox textbox(header, Font::BIG, BOXAREA_WIDTH);
    Point dst_pt;
    const Surface & sprite = AGG::GetICN((Settings::Get().ExtGameEvilInterface() ? ICN::BUYBUILD : ICN::BUYBUILE), 3);

    Box box(10 + textbox.h() + 10 + sprite.h(), OK|CANCEL);
    const Rect & box_rt = box.GetArea();

    // text
    dst_pt.x = box_rt.x + (box_rt.w - textbox.w()) / 2;
    dst_pt.y = box_rt.y + 10;
    textbox.Blit(dst_pt);

    dst_pt.y = box_rt.y + 10 + textbox.h() + 10;
    dst_pt.x = box_rt.x + (box_rt.w - sprite.w()) / 2;
    sprite.Blit(dst_pt, display);
    const Rect text_rt(dst_pt.x, dst_pt.y, sprite.w(), sprite.h());

    Text text("_", Font::BIG);
    sprite.Blit(text_rt, display);
    text.Blit(dst_pt.x + (sprite.w() - text.w()) / 2, dst_pt.y - 1);

    dst_pt.x = box_rt.x;
    dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h();
    Button buttonOk(dst_pt, system, 1, 2);

    dst_pt.x = box_rt.x + box_rt.w - AGG::GetICN(system, 3).w();
    dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 3).h();
    Button buttonCancel(dst_pt, system, 3, 4);

    buttonOk.SetDisable(res.empty());
    buttonOk.Draw();
    buttonCancel.Draw();

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

    LocalEvent & le = LocalEvent::Get();
    bool redraw = true;

    // message loop
    while(le.HandleEvents())
    {
	buttonOk.isEnable() && le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw();
        le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw();

	if(Settings::Get().PocketPC() && le.MousePressLeft(text_rt))
	{
	    PocketPC::KeyboardDialog(res);
	    redraw = true;
	}

        if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || (buttonOk.isEnable() && le.MouseClickLeft(buttonOk))) break;
	else
	if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancel)){ res.clear(); break; }
	else
	if(le.KeyPress())
	{
	    charInsertPos = String::InsertKeySym(res, charInsertPos, le.KeyValue(), le.KeyMod());
	    redraw = true;
	}

	if(redraw)
	{
	    buttonOk.SetDisable(res.empty());
	    buttonOk.Draw();

	    text.Set(String::InsertString(res, charInsertPos, "_"));

	    if(text.w() < sprite.w() - 24)
	    {
		cursor.Hide();
		sprite.Blit(text_rt, display);
		text.Blit(text_rt.x + (text_rt.w - text.w()) / 2, text_rt.y - 1);
		cursor.Show();
		display.Flip();
	    }
	    redraw = false;
	}
    }

    cursor.SetThemes(oldcursor);
    cursor.Hide();

    return res.size();
}
void ChannelKeyGui::createSignals()
{
    connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(buttonOk()));
    connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
}
const Maps::FileInfo* Dialog::SelectScenario(const MapsFileInfoList & all)
{
    Cursor & cursor = Cursor::Get();
    Display & display = Display::Get();
    LocalEvent & le = LocalEvent::Get();

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

    const Maps::FileInfo* result = NULL;
    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::const_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 Sprite & panel = AGG::GetICN(ICN::REQSBKG, 0);
    Background back((display.w() - panel.w()) / 2, (display.h() - panel.h()) / 2, panel.w(), panel.h());
    back.Save();

    const Rect & rt = back.GetRect();

    const Rect countPlayers(rt.x + 45, rt.y + 55, 20, 175);
    const Rect sizeMaps(rt.x + 62, rt.y + 55, 20, 175);
    const Rect victoryConds(rt.x + 267, rt.y + 55, 20, 175);
    const Rect lossConds(rt.x + 287, rt.y + 55, 20, 175);

    const Rect curCountPlayer(rt.x + 66, rt.y + 264, 18, 18);
    const Rect curMapSize(rt.x + 85, rt.y + 264, 18, 18);
    const Rect curMapName(rt.x + 107, rt.y + 264, 166, 18);
    const Rect curVictoryCond(rt.x + 277, rt.y + 264, 18, 18);
    const Rect curLossCond(rt.x + 295, rt.y + 264, 18, 18);
    const Rect curDifficulty(rt.x + 220, rt.y + 292, 114, 20);
    const Rect curDescription(rt.x + 42, rt.y + 316, 292, 90);

    Button buttonOk(rt.x + 140, rt.y + 410, ICN::REQUESTS, 1, 2);

    Button buttonSelectSmall(rt.x + 37, rt.y + 22, ICN::REQUESTS, 9, 10);
    Button buttonSelectMedium(rt.x + 99, rt.y + 22, ICN::REQUESTS, 11, 12);
    Button buttonSelectLarge(rt.x + 161, rt.y + 22, ICN::REQUESTS, 13, 14);
    Button buttonSelectXLarge(rt.x + 223, rt.y + 22, ICN::REQUESTS, 15, 16);
    Button buttonSelectAll(rt.x + 285, rt.y + 22, ICN::REQUESTS, 17, 18);

    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 + 327, rt.y + 55));
    listbox.SetScrollButtonDn(ICN::REQUESTS, 7, 8, Point(rt.x + 327, rt.y + 217));
    listbox.SetScrollSplitter(AGG::GetICN(ICN::ESCROLL, 3), Rect(rt.x + 330, rt.y + 73, 12, 141));
    listbox.SetAreaMaxItems(9);
    listbox.SetAreaItems(Rect(rt.x + 55, rt.y + 55, 270, 175));
    listbox.SetListContent(const_cast<MapsFileInfoList &>(all));
    listbox.Redraw();

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

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

    while(le.HandleEvents())
    {
        if(buttonOk.isEnable()) le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw();
	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();

        if((buttonOk.isEnable() && le.MouseClickLeft(buttonOk)) ||
	    Game::HotKeyPress(Game::EVENT_DEFAULT_READY) ||
	    listbox.selectOk)
	{
	    MapsFileInfoList::const_iterator it = std::find(all.begin(), all.end(), listbox.GetCurrent());
	    result = it != all.end() ? &(*it) : NULL;
	    break;
	}
	else
        if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT))
	{
	    result = NULL;
	    break;
	}
	else
	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(const_cast<MapsFileInfoList &>(all));
	    cursor.Hide();
	}

	listbox.QueueEventProcessing();

	// right info
	if(le.MousePressRight(buttonSelectSmall)) Dialog::Message(_("Small Maps"), _("View only maps of size small (36x36)."), Font::BIG);
	else
	if(le.MousePressRight(buttonSelectMedium)) Dialog::Message(_("Medium Maps"), _("View only maps of size medium (72x72)."), Font::BIG);
	else
	if(le.MousePressRight(buttonSelectLarge)) Dialog::Message(_("Large Maps"), _("View only maps of size large (108x108)."), Font::BIG);
	else
	if(le.MousePressRight(buttonSelectXLarge)) Dialog::Message(_("Extra Large Maps"), _("View only maps of size extra large (144x144)."), Font::BIG);
	else
	if(le.MousePressRight(buttonSelectAll)) Dialog::Message(_("All Maps"), _("View all maps, regardless of size."), Font::BIG);
	else
	if(le.MousePressRight(countPlayers) || le.MousePressRight(curCountPlayer)) Dialog::Message(_("Players Icon"), _("Indicates how many players total are in the EditScenario. Any positions not occupied by humans will be occupied by computer players."), Font::BIG);
	else
	if(le.MousePressRight(sizeMaps) || le.MousePressRight(curMapSize)) Dialog::Message(_("Size Icon"), _("Indicates whether the maps is small (36x36), medium (72x72), large (108x108), or extra large (144x144)."), Font::BIG);
	else
	if(le.MousePressRight(curMapName)) Dialog::Message(_("Selected Name"), _("The name of the currently selected map."), Font::BIG);
	else
	if(le.MousePressRight(victoryConds))
	{
	    const Maps::FileInfo* item = listbox.GetFromPosition(le.GetMouseCursor());
	    if(item) VictoryConditionInfo(*item);
	}
	else
	if(le.MousePressRight(lossConds))
	{
	    const Maps::FileInfo* item = listbox.GetFromPosition(le.GetMouseCursor());
	    if(item) LossConditionInfo(*item);
	}
	else
	if(le.MousePressRight(curVictoryCond)) VictoryConditionInfo(listbox.GetCurrent());
	else
	if(le.MousePressRight(curLossCond)) LossConditionInfo(listbox.GetCurrent());
	else
	if(le.MousePressRight(curDifficulty)) Dialog::Message(_("Selected Map Difficulty"), _("The map difficulty of the currently selected map.  The map difficulty is determined by the EditScenario designer. More difficult maps might include more or stronger enemies, fewer resources, or other special conditions making things tougher for the human player."), Font::BIG);
	else
	if(le.MousePressRight(curDescription)) Dialog::Message(_("Selected Description"), _("The description of the currently selected map."), Font::BIG);
	else
	if(le.MousePressRight(buttonOk)) Dialog::Message(_("OK"), _("Accept the choice made."), Font::BIG);

	if(!cursor.isVisible())
	{
	    listbox.Redraw();
	    buttonOk.Draw();
    	    buttonSelectSmall.Draw();
    	    buttonSelectMedium.Draw();
    	    buttonSelectLarge.Draw();
    	    buttonSelectXLarge.Draw();
    	    buttonSelectAll.Draw();
	    cursor.Show();
	    display.Flip();
	}
    }

    cursor.Hide();
    back.Restore();

    return result;
}
Example #7
0
bool FH2LocalClient::ScenarioInfoDialog(void)
{
    Settings & conf = Settings::Get();
    Cursor & cursor = Cursor::Get();
    Display & display = Display::Get();
    LocalEvent & le = LocalEvent::Get();

    if(!GetCurrentMapInfo() ||
	!GetPlayersInfo()) return false;

    const Sprite & panel = AGG::GetICN(ICN::NGHSBKG, 0);
    const Rect  rectPanel(204, 32, panel.w(), panel.h());
    const Point pointOpponentInfo(rectPanel.x + 24, rectPanel.y + 202);
    const Point pointClassInfo(rectPanel.x + 24, rectPanel.y + 282);
    const Rect  box(pointOpponentInfo, 360, 180);

    Rects::const_iterator itr;

    Interface::PlayersInfo playersInfo(true, false, false);

    playersInfo.UpdateInfo(conf.GetPlayers(), pointOpponentInfo, pointClassInfo);

    RedrawScenarioStaticInfo(rectPanel);
    playersInfo.RedrawInfo();

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

    SpriteCursor sp;
    sp.SetSprite(AGG::GetICN(ICN::NGEXTRA, 80));

    if(! Modes(ST_ADMIN))
    {
	buttonOk.SetDisable(true);
	buttonSelectMaps.SetDisable(true);
    }

    buttonSelectMaps.Draw();
    buttonOk.Draw();
    buttonCancel.Draw();
    cursor.Show();
    display.Flip();

    bool exit = false;
    bool update_info = false;
    u8 change_color = Color::NONE;
    DEBUG(DBG_NETWORK, DBG_INFO, "start queue");

    while(!exit && le.HandleEvents())
    {
        if(Ready())
	{
	    QueueMessage packet;

	    if(!Recv(packet)) return false;
	    DEBUG(DBG_NETWORK, DBG_INFO, "recv: " << Network::GetMsgString(packet.GetID()));

	    switch(packet.GetID())
    	    {
		case MSG_READY:
		    break;

		case MSG_CHANGE_RACE:
		    Network::UnpackRaceColors(packet);
		    update_info = true;
		    break;

		case MSG_UPDATE_PLAYERS:
		{
		    MsgUpdatePlayers(packet);
		    if(Modes(ST_ADMIN))
		    {
			buttonOk.Release();
			buttonOk.SetDisable(false);
			buttonSelectMaps.Release();
			buttonSelectMaps.SetDisable(false);
		    }
		    else
		    {
			buttonOk.Press();
			buttonOk.SetDisable(true);
			buttonSelectMaps.Press();
			buttonSelectMaps.SetDisable(true);
		    }
		    update_info = true;
		    break;
		}

		case MSG_SET_CURRENT_MAP:
		    Network::PacketPopMapsFileInfo(packet, conf.CurrentFileInfo());
		    playersInfo.UpdateInfo(conf.GetPlayers(), pointOpponentInfo, pointClassInfo);
		    update_info = true;
		    break;

		case MSG_MESSAGE:
		    break;

		case MSG_SHUTDOWN:
		    exit = true;
		    break;


		default: break;
	    }
	}

	if(update_info)
	{
	    cursor.Hide();
	    RedrawScenarioStaticInfo(rectPanel);
	    playersInfo.RedrawInfo();
	    buttonSelectMaps.Draw();
	    buttonOk.Draw();
	    buttonCancel.Draw();
	    cursor.Show();
	    display.Flip();
	    update_info = false;
	}

	// press button
        if(buttonSelectMaps.isEnable()) le.MousePressLeft(buttonSelectMaps) ? buttonSelectMaps.PressDraw() : buttonSelectMaps.ReleaseDraw();
        if(buttonOk.isEnable()) le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw();
        le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw();

	// click select
	if(Game::HotKeyPress(Game::EVENT_BUTTON_SELECT) ||
	    (buttonSelectMaps.isEnable() && le.MouseClickLeft(buttonSelectMaps)))
	{
	    cursor.Hide();
	    sp.Hide();
	    cursor.Show();

	    // recv maps_info_list
	    QueueMessage packet(MSG_GET_MAPS_LIST);
	    if(SendWait(packet, MSG_GET_MAPS_LIST, "ScenarioInfoDialog: "))
	    {
		MapsFileInfoList lists;
		Network::PacketPopMapsFileInfoList(packet, lists);
		if(const Maps::FileInfo *fi = Dialog::SelectScenario(lists))
        	{
		    // send set_maps_info
	    	    packet.Reset();
		    packet.SetID(MSG_SET_CURRENT_MAP);
	    	    packet.Push(fi->file);
		    DEBUG(DBG_NETWORK, DBG_INFO, "send: " << Network::GetMsgString(packet.GetID()));
	    	    if(!Send(packet)) return false;
		}
		update_info = true;
	    }
	}
	else
	// click cancel
        if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT))
    	    return false;
        else
        // click ok
        if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || (buttonOk.isEnable() && le.MouseClickLeft(buttonOk)))
    	{
/*
	    packet.Reset();
	    packet.SetID(MSG_START_GAME);
	    DEBUG(DBG_NETWORK, DBG_INFO, "send: " << Network::GetMsgString(packet.GetID()));
	    if(!Send(packet)) return false;
	    cursor.Hide();
	    return true;
*/
	}
	else
	if(Modes(ST_ADMIN) && le.MouseClickLeft(box))
	{
	    // click colors
	    if(Player* player = playersInfo.GetFromOpponentClick(le.GetMouseCursor()))
	    {
		u8 humans = conf.GetPlayers().GetColors(CONTROL_HUMAN);

		if((humans & player->color) && Color::NONE == change_color)
		{
		    cursor.Hide();
		    sp.Move((*itr).x - 3, (*itr).y - 3);
		    cursor.Show();
		    display.Flip();
		    change_color = player->color;
		}
		else
		if(conf.CurrentFileInfo().AllowHumanColors() & player->color)
		{
		    cursor.Hide();
		    sp.Hide();
		    cursor.Show();
		    display.Flip();
		    if(Color::NONE != change_color)
		    {
			QueueMessage packet(MSG_CHANGE_COLORS);
			packet.Push(change_color);
			packet.Push(player->color);
		        DEBUG(DBG_NETWORK, DBG_INFO, "send: " << Network::GetMsgString(packet.GetID()));
			if(!Send(packet)) return false;
			change_color = Color::NONE;
		    }
		}
	    }
	    else
	    // click races
	    if(Player* player = playersInfo.GetFromClassClick(le.GetMouseCursor()))
	    {
		if(conf.AllowChangeRace(player->color))
		{
                    switch(player->race)
                    {
                        case Race::KNGT: player->race = Race::BARB; break;
                        case Race::BARB: player->race = Race::SORC; break;
                        case Race::SORC: player->race = Race::WRLK; break;
                        case Race::WRLK: player->race = Race::WZRD; break;
                        case Race::WZRD: player->race = Race::NECR; break;
                        case Race::NECR: player->race = Race::RAND; break;
                        case Race::RAND: player->race = Race::KNGT; break;
                        default: break;
                    }
		    if(change_color)
		    {
			cursor.Hide();
			sp.Hide();
			cursor.Show();
			display.Flip();
			change_color = Color::NONE;
		    }
		    if((player->race & Race::ALL) || player->race == Race::RAND)
		    {
			QueueMessage packet(MSG_CHANGE_RACE);
			packet.Push(player->color);
			packet.Push(player->race);
		        DEBUG(DBG_NETWORK, DBG_INFO, "send: " << Network::GetMsgString(packet.GetID()));
			if(!Send(packet)) return false;
		    }
		}
	    }
	}

        DELAY(10);
    }

    return false;
}
void ProfileEditGui::createSignals()
{
    connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(buttonOk()));
    connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
}
u16 Dialog::RecruitMonster(const Monster & monster, u16 available)
{
    Display & display = Display::Get();
    LocalEvent & le = LocalEvent::Get();

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

    // calculate max count
    u32 max = 0;
    const payment_t paymentMonster = monster.GetCost();
    const Kingdom & kingdom = world.GetKingdom(Settings::Get().CurrentColor());

    while(kingdom.AllowPayment(paymentMonster * max) && max < available) ++max;

    u32 result = max;

    payment_t paymentCosts(paymentMonster * result);

    const Sprite & box = AGG::GetICN(ICN::RECRBKG, 0);
    const Rect pos((display.w() - box.w()) / 2, Settings::Get().QVGA() ? (display.h() - box.h()) / 2 - 15 : (display.h() - box.h()) / 2, box.w(), box.h());

    Background back(pos);
    back.Save();

    box.Blit(pos.x, pos.y);

    Point dst_pt;
    std::string str;
    Text text;

    // smear hardcore text "Cost per troop:"
    const Sprite & smear = AGG::GetICN(ICN::TOWNNAME, 0);
    dst_pt.x = pos.x + 144;
    dst_pt.y = pos.y + 55;
    smear.Blit(Rect(8, 1, 120, 12), dst_pt);

    text.Set(_("Cost per troop:"), Font::SMALL);
    dst_pt.x = pos.x + 206 - text.w() / 2;
    dst_pt.y = pos.y + 55;
    text.Blit(dst_pt);

    // text recruit monster
    str = _("Recruit %{name}");
    String::Replace(str, "%{name}", monster.GetMultiName());
    text.Set(str, Font::BIG);
    dst_pt.x = pos.x + (pos.w - text.w()) / 2;
    dst_pt.y = pos.y + 25;
    text.Blit(dst_pt);

    // sprite monster
    const Sprite & smon = AGG::GetICN(monster.ICNMonh(), 0);
    dst_pt.x = pos.x + 70 - smon.w() / 2;
    dst_pt.y = pos.y + 130 - smon.h();
    smon.Blit(dst_pt);

    bool extres = 2 == paymentMonster.GetValidItems();

    // info resource
    // gold
    const Sprite & sgold = AGG::GetICN(ICN::RESOURCE, 6);
    dst_pt.x = pos.x + (extres ? 150 : 175);
    dst_pt.y = pos.y + 75;
    sgold.Blit(dst_pt);

    dst_pt.x = pos.x + (extres ? 105 : 130);
    dst_pt.y = pos.y + 200;
    sgold.Blit(dst_pt);

    text.Set(GetString(paymentMonster.gold), Font::SMALL);
    dst_pt.x = pos.x + (extres ? 183 : 205) - text.w() / 2;
    dst_pt.y = pos.y + 103;
    text.Blit(dst_pt);

    // crystal
    if(paymentMonster.crystal)
    {
        const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 4);
	RedrawResourceInfo(sres, pos, paymentMonster.crystal,
				225, 75, 240, 103);
	dst_pt.x = pos.x + 180;
	dst_pt.y = pos.y + 200;
	sres.Blit(dst_pt);
    }
    else
    // mercury
    if(paymentMonster.mercury)
    {
        const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 1);
	RedrawResourceInfo(sres, pos, paymentMonster.mercury,
				225, 72, 240, 103);
	dst_pt.x = pos.x + 180;
	dst_pt.y = pos.y + 197;
	sres.Blit(dst_pt);
    }
    else
    // wood
    if(paymentMonster.wood)
    {
        const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 0);
	RedrawResourceInfo(sres, pos, paymentMonster.wood,
				225, 72, 240, 103);
	dst_pt.x = pos.x + 180;
	dst_pt.y = pos.y + 197;
	sres.Blit(dst_pt);
    }
    else
    // ore
    if(paymentMonster.ore)
    {
        const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 2);
	RedrawResourceInfo(sres, pos, paymentMonster.ore,
				225, 72, 240, 103);
	dst_pt.x = pos.x + 180;
	dst_pt.y = pos.y + 197;
	sres.Blit(dst_pt);
    }
    else
    // sulfur
    if(paymentMonster.sulfur)
    {
        const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 3);
	RedrawResourceInfo(sres, pos, paymentMonster.sulfur,
				225, 75, 240, 103);
	dst_pt.x = pos.x + 180;
	dst_pt.y = pos.y + 200;
	sres.Blit(dst_pt);
    }
    else
    // gems
    if(paymentMonster.gems)
    {
        const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 5);
	RedrawResourceInfo(sres, pos, paymentMonster.gems,
				225, 75, 240, 103);
	dst_pt.x = pos.x + 180;
	dst_pt.y = pos.y + 200;
	sres.Blit(dst_pt);
    }

    // text number buy
    text.Set(_("Number to buy:"));
    dst_pt.x = pos.x + 30;
    dst_pt.y = pos.y + 163;
    text.Blit(dst_pt);

    Background static_info(Rect(pos.x + 16, pos.y + 125, pos.w - 32, 122));
    static_info.Save();

    RedrawCurrentInfo(pos, available, result, paymentMonster, paymentCosts);

    // buttons
    dst_pt.x = pos.x + 34;
    dst_pt.y = pos.y + 249;
    Button buttonOk(dst_pt, ICN::RECRUIT, 8, 9);

    dst_pt.x = pos.x + 187;
    dst_pt.y = pos.y + 249;
    Button buttonCancel(dst_pt, ICN::RECRUIT, 6, 7);

    dst_pt.x = pos.x + 230;
    dst_pt.y = pos.y + 155;
    Button buttonMax(dst_pt, ICN::RECRUIT, 4, 5);
    dst_pt.x = pos.x + 208;
    dst_pt.y = pos.y + 156;
    Button buttonUp(dst_pt, ICN::RECRUIT, 0, 1);

    dst_pt.x = pos.x + 208;
    dst_pt.y = pos.y + 171;
    Button buttonDn(dst_pt, ICN::RECRUIT, 2, 3);

    buttonOk.Draw();
    buttonCancel.Draw();
    buttonMax.Draw();
    buttonUp.Draw();
    buttonDn.Draw();

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

    bool redraw = false;

    // str loop
    while(le.HandleEvents())
    {
	le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw();
	le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw();
	le.MousePressLeft(buttonMax) ? buttonMax.PressDraw() : buttonMax.ReleaseDraw();
	le.MousePressLeft(buttonUp) ? buttonUp.PressDraw() : buttonUp.ReleaseDraw();
	le.MousePressLeft(buttonDn) ? buttonDn.PressDraw() : buttonDn.ReleaseDraw();

	if(PressIntKey(0, max, result))
	{
	    paymentCosts = paymentMonster * result;
	    redraw = true;
	}

	if(le.MouseClickLeft(buttonUp) && result < max)
	{
	    ++result;
	    paymentCosts += paymentMonster;
	    redraw = true;
	}
	else
	if(le.MouseClickLeft(buttonDn) && result)
	{
	    --result;
	    paymentCosts -= paymentMonster;
	    redraw = true;
	}
	else
	if(le.MouseClickLeft(buttonMax) && result != max)
	{
	    result = max;
	    paymentCosts = paymentMonster * max;
	    redraw = true;
	}

	if(redraw)
	{
	    cursor.Hide();
	    static_info.Restore();
	    RedrawCurrentInfo(pos, available, result, paymentMonster, paymentCosts);
	    cursor.Show();
	    display.Flip();
	    redraw = false;
	}

	if(le.MouseClickLeft(buttonOk) || Game::HotKeyPress(Game::EVENT_DEFAULT_READY)) break;

	if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)){ result = 0; break; }
    }

    cursor.Hide();

    back.Restore();
    cursor.SetThemes(oldcursor);

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

    return result;
}