bool BuildingInfo::DialogBuyBuilding(bool buttons) const { Display & display = Display::Get(); const int system = (Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM); Cursor & cursor = Cursor::Get(); cursor.Hide(); std::string box1str = description; if(ALLOW_BUILD != bcond) { const std::string & ext = GetConditionDescription(); if(! ext.empty()) { box1str.append("\n \n"); box1str.append(ext); } } TextBox box1(box1str, Font::BIG, BOXAREA_WIDTH); // prepare requires build string std::string str; const u32 requires = castle.GetBuildingRequires(building); const char* sep = ", "; for(u32 itr = 0x00000001; itr; itr <<= 1) if((requires & itr) && ! castle.isBuild(itr)) { str.append(Castle::GetStringBuilding(itr, castle.GetRace())); str.append(sep); } // replace end sep if(str.size()) str.replace(str.size() - strlen(sep), strlen(sep), "."); bool requires_true = str.size(); Text requires_text(_("Requires:"), Font::BIG); TextBox box2(str, Font::BIG, BOXAREA_WIDTH); Resource::BoxSprite rbs(PaymentConditions::BuyBuilding(castle.GetRace(), building), BOXAREA_WIDTH); const Sprite & window_icons = AGG::GetICN(ICN::BLDGXTRA, 0); const int space = Settings::Get().QVGA() ? 5 : 10; Dialog::FrameBox box(space + window_icons.h() + space + box1.h() + space + (requires_true ? requires_text.h() + box2.h() + space : 0) + rbs.GetArea().h, buttons); const Rect & box_rt = box.GetArea(); LocalEvent & le = LocalEvent::Get(); Point dst_pt; dst_pt.x = box_rt.x; dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h(); Button button1(dst_pt.x, dst_pt.y, 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 button2(dst_pt.x, dst_pt.y, system, 3, 4); dst_pt.x = box_rt.x + (box_rt.w - window_icons.w()) / 2; dst_pt.y = box_rt.y + space; window_icons.Blit(dst_pt); const Sprite & building_icons = AGG::GetICN(ICN::Get4Building(castle.GetRace()), GetIndexBuildingSprite(building)); dst_pt.x = box_rt.x + (box_rt.w - building_icons.w()) / 2; dst_pt.y += 1; building_icons.Blit(dst_pt); Text text(GetName(), Font::SMALL); dst_pt.x = box_rt.x + (box_rt.w - text.w()) / 2; dst_pt.y += 57; text.Blit(dst_pt); dst_pt.x = box_rt.x; dst_pt.y = box_rt.y + space + window_icons.h() + space; box1.Blit(dst_pt); dst_pt.y += box1.h() + space; if(requires_true) { dst_pt.x = box_rt.x + (box_rt.w - requires_text.w()) / 2; requires_text.Blit(dst_pt); dst_pt.x = box_rt.x; dst_pt.y += requires_text.h(); box2.Blit(dst_pt); dst_pt.y += box2.h() + space; } rbs.SetPos(dst_pt.x, dst_pt.y); rbs.Redraw(); if(buttons) { if(ALLOW_BUILD != castle.CheckBuyBuilding(building)) button1.SetDisable(true); button1.Draw(); button2.Draw(); } cursor.Show(); display.Flip(); // message loop while(le.HandleEvents()) { if(!buttons && !le.MousePressRight()) break; le.MousePressLeft(button1) ? button1.PressDraw() : button1.ReleaseDraw(); le.MousePressLeft(button2) ? button2.PressDraw() : button2.ReleaseDraw(); if(button1.isEnable() && (Game::HotKeyPressEvent(Game::EVENT_DEFAULT_READY) || le.MouseClickLeft(button1))) return true; if(Game::HotKeyPressEvent(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(button2)) break; } return false; }
Dialog::answer_t Dialog::BuyBoat(bool enable) { Display & display = Display::Get(); const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; Cursor & cursor = Cursor::Get(); cursor.Hide(); Resource::BoxSprite rbs(PaymentConditions::BuyBoat(), BOXAREA_WIDTH); const Sprite & sprite = AGG::GetICN(ICN::BOATWIND, 0); Text text(_("Build a new ship:"), Font::BIG); const u8 spacer = Settings::Get().QVGA() ? 5 : 10; Dialog::Box box(text.h() + spacer + sprite.h() + spacer + text.h() + spacer + rbs.GetArea().h - 20, true); const Rect & box_rt = box.GetArea(); Point dst_pt; dst_pt.x = box_rt.x + (box_rt.w - text.w()) / 2; dst_pt.y = box_rt.y; text.Blit(dst_pt); dst_pt.x = box_rt.x + (box_rt.w - sprite.w()) / 2; dst_pt.y = box_rt.y + text.h() + spacer; display.Blit(sprite, dst_pt); text.Set(_("Resource cost:"), Font::BIG); dst_pt.x = box_rt.x + (box_rt.w - text.w()) / 2; dst_pt.y = dst_pt.y + sprite.h() + spacer; text.Blit(dst_pt); rbs.SetPos(box_rt.x, dst_pt.y + spacer); rbs.Redraw(); // buttons dst_pt.x = box_rt.x; dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h(); Button button1(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 button2(dst_pt, system, 3, 4); if(!enable) { button1.Press(); button1.SetDisable(true); } button1.Draw(); button2.Draw(); cursor.Show(); display.Flip(); LocalEvent & le = LocalEvent::Get(); // message loop while(le.HandleEvents()) { if(button1.isEnable()) le.MousePressLeft(button1) ? button1.PressDraw() : button1.ReleaseDraw(); le.MousePressLeft(button2) ? button2.PressDraw() : button2.ReleaseDraw(); if(le.KeyPress(KEY_RETURN) || (button1.isEnable() && le.MouseClickLeft(button1))) return Dialog::OK; if(le.KeyPress(KEY_ESCAPE) || le.MouseClickLeft(button2)) return Dialog::CANCEL; } return Dialog::ZERO; }