std::wstring TrimFilename(const std::wstring &filename) { wstring song_title = filename; wstring song_lower = StringLower(song_title); // Strip off known file extensions set<wstring> extensions; extensions.insert(L".mid"); extensions.insert(L".midi"); for (set<wstring>::const_iterator i = extensions.begin(); i != extensions.end(); ++i) { wstring extension = StringLower(*i); wstring::size_type len = extension.length(); wstring song_end = song_lower.substr(std::max((unsigned long)0, (unsigned long)(song_lower.length() - len)), song_lower.length()); if (song_end == extension) song_title = song_title.substr(0, song_title.length() - len); song_lower = StringLower(song_title); } // Strip off path for (wstring::size_type i = song_title.length(); i != 0; --i) { if (song_title[i-1] == PathDelimiter) { song_title = song_title.substr(i, song_title.length()); break; } } return song_title; }
BuildingInfo::BuildingInfo(const Castle & c, building_t b) : castle(c), building(b), area(0, 0, 135, 57), bcond(ALLOW_BUILD) { if(IsDwelling()) building = castle.GetActualDwelling(b); building = castle.isBuild(b) ? castle.GetUpgradeBuilding(b) : b; if(BUILD_TAVERN == building && Race::NECR == castle.GetRace()) building = Settings::Get().PriceLoyaltyVersion() ? BUILD_SHRINE : BUILD_TAVERN; bcond = castle.CheckBuyBuilding(building); // generate description if(BUILD_DISABLE == bcond) description = GetConditionDescription(); else if(IsDwelling()) { description = _("The %{building} produces %{monster}."); StringReplace(description, "%{building}", Castle::GetStringBuilding(building, castle.GetRace())); StringReplace(description, "%{monster}", StringLower(Monster(castle.GetRace(), building).GetMultiName())); } else description = Castle::GetDescriptionBuilding(building, castle.GetRace()); switch(building) { case BUILD_WELL: StringReplace(description, "%{count}", Castle::GetGrownWell()); break; case BUILD_WEL2: StringReplace(description, "%{count}", Castle::GetGrownWel2()); break; case BUILD_CASTLE: case BUILD_STATUE: case BUILD_SPEC: { const payment_t profit = ProfitConditions::FromBuilding(building, castle.GetRace()); StringReplace(description, "%{count}", profit.gold); break; } default: break; } // fix area for capratin if(b == BUILD_CAPTAIN) { const Sprite & sprite = AGG::GetICN(ICN::Get4Captain(castle.GetRace()), (building & BUILD_CAPTAIN ? 1 : 0)); area.w = sprite.w(); area.h = sprite.h(); } }
std::string ModifyKey(const std::string & str) { std::string key = StringTrim(StringLower(str)); // remove multiple space std::string::iterator it = std::unique(key.begin(), key.end(), SpaceCompare); key.resize(it - key.begin()); // change space std::replace_if(key.begin(), key.end(), ::isspace, 0x20); return key; }
void ListFiles::ReadDir(const std::string &path, const std::string &filter, bool sensitive) { // read directory DIR *dp; struct dirent *ep; dp = opendir(path.c_str()); DEBUG(DBG_ENGINE, DBG_INFO, (filter.size() ? path + " (" + filter + ")" : path)); if(dp) { while(NULL != (ep = readdir(dp))) { const std::string fullname = System::ConcatePath(path, ep->d_name); // if not regular file if(! System::IsFile(fullname)) continue; if(filter.size()) { std::string filename(ep->d_name); if(sensitive) { if(std::string::npos == filename.find(filter)) continue; } else { if(std::string::npos == StringLower(filename).find(StringLower(filter))) continue; } } push_back(fullname); } closedir(dp); } }
CEventActionBase * CEventInfo::ParseActionCloseApplication(CMarkup & xml) { // Declare variables CString sTitle, sFilename, sTemp, sLowerTemp;; CEventActionBase * pAction; bool bAskUser; // Jump into element xml.IntoElem(); // Get title xml.FindElem(_T("TITLE")); sTitle = xml.GetElemContent(); // Reset pointer xml.ResetMainPos(); // Get filename xml.FindElem(_T("FILENAME")); sFilename = xml.GetElemContent(); // Reset pointer xml.ResetMainPos(); // Get ask user if (xml.FindElem(_T("ASKUSER"))) { // Get data sTemp = xml.GetElemContent(); // Make lowercase sTemp = StringLower(sTemp); bAskUser = (sTemp == _T("false")) ? false : true; } else { // Use default value (true) bAskUser = true; } // Create object pAction = new CEventActionCloseApplication(sTitle, sFilename, bAskUser); // Jump out of element xml.OutOfElem(); // Return the object return pAction; }
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; }
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; }