bool PrepareMapsFileInfoList(MapsFileInfoList & lists, bool multi) { const Settings & conf = Settings::Get(); ListFiles maps = conf.GetListFiles("maps", ".mp2"); // check loyality version if(conf.PriceLoyaltyVersion()) maps.Append(conf.GetListFiles("maps", ".mx2")); const ListDirs & list = conf.GetMapsParams(); if(! list.empty()) { for(ListDirs::const_iterator it = list.begin(); it != list.end(); ++it) if(*it != "maps") { maps.Append(conf.GetListFiles(*it, ".mp2")); if(conf.PriceLoyaltyVersion()) maps.Append(conf.GetListFiles(*it, ".mx2")); } } if(maps.empty()) return false; lists.reserve(maps.size()); for(ListFiles::const_iterator it = maps.begin(); it != maps.end(); ++it) { Maps::FileInfo fi; if(fi.ReadMP2(*it)) lists.push_back(fi); } std::sort(lists.begin(), lists.end(), Maps::FileInfo::NameSorting); lists.resize(std::unique(lists.begin(), lists.end(), Maps::FileInfo::NameCompare) - lists.begin()); if(multi == false) { MapsFileInfoList::iterator it = std::remove_if(lists.begin(), lists.end(), std::mem_fun_ref(&Maps::FileInfo::isMultiPlayerMap)); if(it != lists.begin()) lists.resize(std::distance(lists.begin(), it)); } // set preferably count filter if(conf.PreferablyCountPlayers()) { MapsFileInfoList::iterator it = std::remove_if(lists.begin(), lists.end(), std::not1(std::bind2nd(std::mem_fun_ref(&Maps::FileInfo::isAllowCountPlayers), conf.PreferablyCountPlayers()))); if(it != lists.begin()) lists.resize(std::distance(lists.begin(), it)); } return lists.size(); }
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; }