bool GUI::Load( const std::list <std::string> & pagelist, const std::map<std::string, std::list <std::pair <std::string, std::string> > > & valuelists, const std::string & datapath, const std::string & optionsfile, const std::string & skinname, const std::string & language, const std::string & texsize, const float screenhwratio, std::map <std::string, Slot0*> actionmap, ContentManager & content, std::ostream & info_output, std::ostream & error_output) { Unload(); // serious mess here, needs cleanup const std::string fonttexpath = "skins/" + skinname + "/fonts"; const std::string texpath = "skins/" + skinname + "/textures"; const std::string skinpath = datapath + "/skins/" + skinname; const std::string fontpath = skinpath + "/fonts"; const std::string langpath = skinpath + "/languages"; const std::string menupath = skinpath + "/menus"; // setup language lang.Init(langpath); lang.Set(language, error_output); // load font (hardcoded for now) const std::string fontcp = lang.GetCodePageId(language); const std::string fonttex = "robotobold_" + fontcp + "_sdf.png"; const std::string fontinfo = fontpath + "/robotobold_" + fontcp + ".txt"; if (!font.Load(fontinfo, fonttexpath, fonttex, content, error_output)) return false; // load options if (!LoadOptions(optionsfile, valuelists, error_output)) return false; VSIGNALMAP vsignalmap; VNACTIONMAP vnactionmap; VACTIONMAP vactionmap; RegisterOptions(vsignalmap, vnactionmap, vactionmap, actionmap); // init pages size_t pagecount = 0; for (std::list <std::string>::const_iterator i = pagelist.begin(); i != pagelist.end(); ++i) { pages.insert(std::make_pair(*i, GUIPAGE())); pagecount++; } // register pages page_activate.reserve(pagecount); for (PAGEMAP::iterator i = pages.begin(); i != pages.end(); ++i) { page_activate.push_back(PAGECB()); page_activate.back().gui = this; page_activate.back().page = i->first; actionmap[i->first] = &page_activate.back().action; } // load pages for (PAGEMAP::iterator i = pages.begin(); i != pages.end(); ++i) { const std::string pagepath = menupath + "/" + i->first; if (!i->second.Load( pagepath, texpath, screenhwratio, lang, font, vsignalmap, vnactionmap, vactionmap, actionmap, node, content, error_output)) { error_output << "Error loading GUI page: " << pagepath << std::endl; return false; } } if (pages.find("Main") == pages.end()) { error_output << "Couldn't find GUI Main menu in: " << menupath << std::endl; return false; } info_output << "Loaded GUI successfully" << std::endl; // start out with everything invisible Deactivate(); return true; }
bool Gui::Load( const std::list <std::string> & pagelist, const std::map<std::string, GuiOption::List> & valuelists, const std::string & datapath, const std::string & optionsfile, const std::string & skinname, const std::string & language, const float screenhwratio, StrSignalMap vsignalmap, SlotMap actionmap, ContentManager & content, std::ostream & info_output, std::ostream & error_output) { Unload(); // serious mess here, needs cleanup const std::string fonttexpath = "skins/" + skinname + "/fonts"; const std::string texpath = "skins/" + skinname + "/textures"; const std::string skinpath = datapath + "/skins/" + skinname; const std::string fontpath = skinpath + "/fonts"; const std::string langpath = skinpath + "/languages"; const std::string menupath = skinpath + "/menus"; // setup language lang.Set(language, info_output, error_output); // load font (hardcoded for now) const std::string fontcp = lang.GetCodePage(); const std::string fonttex = "robotobold_" + fontcp + "_sdf.png"; const std::string fontinfo = fontpath + "/robotobold_" + fontcp + ".txt"; if (!font.Load(fontinfo, fonttexpath, fonttex, content, error_output)) return false; // load options Config opt; if (!opt.load(optionsfile)) { error_output << "Failed to load options file: " << optionsfile << std::endl; return false; } if (!LoadOptions(opt, lang, options, error_output)) { error_output << "Failed to load options." << std::endl; return false; } // register options StrVecSlotMap vnactionmap; IntSlotMap nactionmap; StrSlotMap vactionmap; RegisterOptions(vsignalmap, vnactionmap, vactionmap, nactionmap, actionmap); // register page activation callbacks vactionmap["gui.page"] = &activate_page; actionmap["gui.page.prev"] = &activate_prev_page; // init pages size_t pagecount = 0; for (const auto & page : pagelist) { pages.insert(std::make_pair(page, GuiPage())); pagecount++; } // load pages for (auto & page : pages) { const std::string pagepath = menupath + "/" + page.first; if (!page.second.Load( pagepath, texpath, screenhwratio, lang, font, vsignalmap, vnactionmap, vactionmap, nactionmap, actionmap, content, error_output)) { error_output << "Error loading GUI page: " << pagepath << std::endl; return false; } } if (pages.find("Main") == pages.end()) { error_output << "Couldn't find GUI Main menu in: " << menupath << std::endl; return false; } // populate option values // has to happen after page loading to sync gui with options if (!LoadOptionValues(opt, lang, valuelists, options, error_output)) { error_output << "Failed to load option values." << std::endl; return false; } info_output << "Loaded GUI successfully" << std::endl; // start out with everything invisible Deactivate(); return true; }
int mainSetupAndRun() { try { RegisterOptions(&HumanClientApp::AddWindowSizeOptionsAfterMainStart); int colour_depth = GetOptionsDB().Get<int>("color-depth"); bool fullscreen = GetOptionsDB().Get<bool>("fullscreen"); bool fake_mode_change = GetOptionsDB().Get<bool>("fake-mode-change"); std::pair<int, int> width_height = HumanClientApp::GetWindowWidthHeight(); int width(width_height.first), height(width_height.second); std::pair<int, int> left_top = HumanClientApp::GetWindowLeftTop(); int left(left_top.first), top(left_top.second); int fullscreen_monitor_id = GetOptionsDB().Get<int>("fullscreen-monitor-id"); #ifdef FREEORION_WIN32 # ifdef IDI_ICON1 // set window icon to embedded application icon HWND hwnd; window->getCustomAttribute("WINDOW", &hwnd); HINSTANCE hInst = (HINSTANCE)GetModuleHandle(NULL); SetClassLong (hwnd, GCL_HICON, (LONG)LoadIcon (hInst, MAKEINTRESOURCE (IDI_ICON1))); # endif #endif parse::init(); HumanClientApp app(width, height, true, "FreeOrion " + FreeOrionVersionString(), left, top, fullscreen, fake_mode_change); if (GetOptionsDB().Get<bool>("quickstart")) { // immediately start the server, establish network connections, and // go into a single player game, using default universe options (a // standard quickstart, without requiring the user to click the // quickstart button). app.NewSinglePlayerGame(true); // acceptable to call before app() } std::string load_filename = GetOptionsDB().Get<std::string>("load"); if (!load_filename.empty()) { // immediately start the server, establish network connections, and // go into a single player game, loading the indicated file // (without requiring the user to click the load button). app.LoadSinglePlayerGame(load_filename); // acceptable to call before app() } // run rendering loop app(); // calls GUI::operator() which calls SDLGUI::Run() which starts rendering loop } catch (const HumanClientApp::CleanQuit&) { // do nothing std::cout << "mainSetupAndRun caught CleanQuit" << std::endl; } #ifndef FREEORION_CHMAIN_KEEP_STACKTRACE catch (const std::invalid_argument& e) { ErrorLogger() << "main() caught exception(std::invalid_argument): " << e.what(); std::cerr << "main() caught exception(std::invalid_arg): " << e.what() << std::endl; return 1; } catch (const std::runtime_error& e) { ErrorLogger() << "main() caught exception(std::runtime_error): " << e.what(); std::cerr << "main() caught exception(std::runtime_error): " << e.what() << std::endl; return 1; } catch (const boost::io::format_error& e) { ErrorLogger() << "main() caught exception(boost::io::format_error): " << e.what(); std::cerr << "main() caught exception(boost::io::format_error): " << e.what() << std::endl; return 1; } catch (const std::exception& e) { ErrorLogger() << "main() caught exception(std::exception): " << e.what(); std::cerr << "main() caught exception(std::exception): " << e.what() << std::endl; return 1; } #endif return 0; }