//////////////////////////////////////////// // About //////////////////////////////////////////// About::About(): CUIWnd(UserString("ABOUT_WINDOW_TITLE"), GG::X(80), GG::Y(130), GG::X(600), GG::Y(500), GG::INTERACTIVE | GG::DRAGABLE | GG::MODAL), m_end_with_done(false) { m_done_btn = new CUIButton(UserString("DONE"), GG::X(400), GG::Y(440), GG::X(75)); m_license = new CUIButton(UserString("LICENSE"), GG::X(310), GG::Y(440), GG::X(75)); m_vision = new CUIButton(UserString("VISION"), GG::X(220), GG::Y(440), GG::X(75)); m_info = new CUIMultiEdit(GG::X(20), GG::Y(20), GG::X(550), GG::Y(400), UserString("FREEORION_VISION"), GG::MULTI_WORDBREAK | GG::MULTI_READ_ONLY, ClientUI::GetFont(), ClientUI::CtrlBorderColor(), ClientUI::TextColor(), ClientUI::CtrlColor(), GG::INTERACTIVE); GG::Layout* layout = new GG::Layout(GG::X0, GG::Y0, ClientWidth(), ClientHeight(), 2, 6, 5); layout->SetMinimumRowHeight(1, m_license->Height() + 5); layout->SetRowStretch(0, 1); layout->Add(m_info, 0, 0, 1, 6); layout->Add(m_vision, 1, 3); layout->Add(m_license, 1, 4); layout->Add(m_done_btn, 1, 5); AttachChild(layout); // Read in the copyright info from a file boost::filesystem::ifstream fin(GetRootDataDir() / "default" / "COPYING"); // this is not GetResourceDir() / "COPYING" because if a mod or scenario is loaded that changes the settings directory, the copyright notice should be unchanged if (!fin.is_open()) return; std::string temp_str; while (!fin.eof()) { std::getline(fin, temp_str, '\n'); m_license_str.append(temp_str); m_license_str.append("\n"); // To ensure new lines are read } fin.close(); Init(); }
fs::path GetPath(PathType path_type) { switch (path_type) { case PATH_BINARY: return GetBinDir(); case PATH_RESOURCE: return GetResourceDir(); case PATH_DATA_ROOT: return GetRootDataDir(); case PATH_DATA_USER: return GetUserDataDir(); case PATH_CONFIG: return GetUserConfigDir(); case PATH_SAVE: return GetSaveDir(); case PATH_TEMP: return fs::temp_directory_path(); case PATH_PYTHON: #if defined(FREEORION_MACOSX) || defined(FREEORION_WIN32) return GetPythonHome(); #endif case PATH_INVALID: default: ErrorLogger() << "Invalid path type " << path_type; return fs::temp_directory_path(); } }
void StartUsing() { if (m_failed_init) return; if (!m_scanline_shader) { boost::filesystem::path shader_path = GetRootDataDir() / "default" / "shaders" / "scanlines.frag"; std::string shader_text; if (!ReadFile(shader_path, shader_text)) { ErrorLogger() << "ScanlineRenderer failed to read shader at path " << shader_path.string(); m_failed_init = true; return; } m_scanline_shader = ShaderProgram::shaderProgramFactory("", shader_text); if (!m_scanline_shader) { ErrorLogger() << "ScanlineRenderer failed to initialize shader."; m_failed_init = true; return; } } float fog_scanline_spacing = static_cast<float>(GetOptionsDB().Get<double>("ui.map.system.scanlines.spacing")); m_scanline_shader->Use(); m_scanline_shader->Bind("scanline_spacing", fog_scanline_spacing); m_scanline_shader->Bind("line_color", m_color.r * (1.f / 255.f), m_color.g * (1.f / 255.f), m_color.b * (1.f / 255.f), m_color.a * (1.f / 255.f)); }
//////////////////////////////////////////// // About //////////////////////////////////////////// About::About(): CUIWnd(UserString("ABOUT_WINDOW_TITLE"), GG::X(80), GG::Y(130), GG::X(600), GG::Y(500), GG::INTERACTIVE | GG::DRAGABLE | GG::MODAL) { m_done_btn = new CUIButton(UserString("DONE")); m_license = new CUIButton(UserString("LICENSE")); m_vision = new CUIButton(UserString("VISION")); m_info = new CUIMultiEdit(GG::X0, GG::Y0, GG::X1, GG::Y1, UserString("FREEORION_VISION"), GG::MULTI_WORDBREAK | GG::MULTI_READ_ONLY); AttachChild(m_info); AttachChild(m_vision); AttachChild(m_license); AttachChild(m_done_btn); DoLayout(); // Read in the copyright info from a file boost::filesystem::ifstream fin(GetRootDataDir() / "default" / "COPYING"); // this is not GetResourceDir() / "COPYING" because if a mod or scenario is loaded that changes the settings directory, the copyright notice should be unchanged if (!fin.is_open()) return; std::string temp_str; while (!fin.eof()) { std::getline(fin, temp_str, '\n'); m_license_str.append(temp_str); m_license_str.append("\n"); // To ensure new lines are read } fin.close(); GG::Connect(m_done_btn->LeftClickedSignal, &About::OnDone, this); GG::Connect(m_license->LeftClickedSignal, &About::OnLicense, this); GG::Connect(m_vision->LeftClickedSignal, &About::OnVision, this); }
void About::CompleteConstruction() { CUIWnd::CompleteConstruction(); m_done = Wnd::Create<CUIButton>(UserString("DONE")); m_license = Wnd::Create<CUIButton>(UserString("LICENSE")); m_vision = Wnd::Create<CUIButton>(UserString("VISION")); m_info = GG::Wnd::Create<CUIMultiEdit>(UserString("FREEORION_VISION"), GG::MULTI_WORDBREAK | GG::MULTI_READ_ONLY); AttachChild(m_info); AttachChild(m_vision); AttachChild(m_license); AttachChild(m_done); DoLayout(); // Read in the copyright info from a file // this is not GetResourceDir() / "COPYING" because if a mod or scenario is loaded // that changes the settings directory, the copyright notice should be unchanged m_license_str = ReadFile(GetRootDataDir() / "default" / "COPYING").value_or(""); m_done->LeftClickedSignal.connect( boost::bind(&GG::Wnd::EndRun, this)); m_license->LeftClickedSignal.connect( boost::bind(&About::ShowLicense, this)); m_vision->LeftClickedSignal.connect( boost::bind(&About::ShowVision, this)); }
void BuildingIndicator::Refresh() { if (!s_scanline_shader && GetOptionsDB().Get<bool>("UI.system-fog-of-war")) { boost::filesystem::path shader_path = GetRootDataDir() / "default" / "shaders" / "scanlines.frag"; std::string shader_text; ReadFile(shader_path, shader_text); s_scanline_shader = boost::shared_ptr<ShaderProgram>( ShaderProgram::shaderProgramFactory("", shader_text)); } SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); TemporaryPtr<const Building> building = GetBuilding(m_building_id); if (!building) return; ClearBrowseInfoWnd(); if (m_graphic) { delete m_graphic; m_graphic = 0; } if (m_scrap_indicator) { delete m_scrap_indicator; m_scrap_indicator = 0; } if (const BuildingType* type = GetBuildingType(building->BuildingTypeName())) { boost::shared_ptr<GG::Texture> texture = ClientUI::BuildingIcon(type->Name()); m_graphic = new GG::StaticGraphic(texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); AttachChild(m_graphic); std::string desc = UserString(type->Description()); if (building->GetMeter(METER_STEALTH)) desc = UserString("METER_STEALTH") + boost::io::str(boost::format(": %3.1f\n\n") % building->GetMeter(METER_STEALTH)->Current()) + desc; if (GetOptionsDB().Get<bool>("UI.autogenerated-effects-descriptions") && !type->Effects().empty()) desc += boost::io::str(FlexibleFormat(UserString("ENC_EFFECTS_STR")) % AutoGeneratedDescription(type->Effects())); SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>( new IconTextBrowseWnd(texture, UserString(type->Name()), desc))); } if (building && building->OrderedScrapped()) { boost::shared_ptr<GG::Texture> scrap_texture = ClientUI::GetTexture(ClientUI::ArtDir() / "misc" / "scrapped.png", true); m_scrap_indicator = new GG::StaticGraphic(scrap_texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); AttachChild(m_scrap_indicator); } DoLayout(); }
void FleetButton::Init(const std::vector<int>& fleet_IDs, SizeType size_type) { if (!scanline_shader && GetOptionsDB().Get<bool>("UI.system-fog-of-war")) { boost::filesystem::path shader_path = GetRootDataDir() / "default" / "shaders" / "scanlines.frag"; std::string shader_text; ReadFile(shader_path, shader_text); scanline_shader = boost::shared_ptr<ShaderProgram>( ShaderProgram::shaderProgramFactory("", shader_text)); } // get fleets std::vector<TemporaryPtr<const Fleet> > fleets; for (std::vector<int>::const_iterator it = fleet_IDs.begin(); it != fleet_IDs.end(); ++it) { TemporaryPtr<const Fleet> fleet = GetFleet(*it); if (!fleet) { Logger().errorStream() << "FleetButton::FleetButton couldn't get fleet with id " << *it; continue; } m_fleets.push_back(*it); fleets.push_back(fleet); } // determine owner(s) of fleet(s). Only care whether or not there is more than one owner, as owner // is used to determine colouration int owner_id = ALL_EMPIRES; int multiple_owners = false; if (fleets.empty()) { // leave as ALL_EMPIRES } else if (fleets.size() == 1) { owner_id = (*fleets.begin())->Owner(); } else { owner_id = (*fleets.begin())->Owner(); // use ALL_EMPIRES if there are multiple owners (including no owner and an owner) for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) { TemporaryPtr<const Fleet> fleet = *it; if (fleet->Owner() != owner_id) { owner_id = ALL_EMPIRES; multiple_owners = true; break; } } } // get fleet colour if (multiple_owners) { SetColor(GG::CLR_WHITE); } else if (owner_id == ALL_EMPIRES) { // all ships owned by now empire bool monsters = true; // find if any ship in fleets in button is not a monster for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) { TemporaryPtr<const Fleet> fleet = *it; for (std::set<int>::const_iterator ship_it = fleet->ShipIDs().begin(); ship_it != fleet->ShipIDs().end(); ++ship_it) { if (TemporaryPtr<const Ship> ship = GetShip(*ship_it)) { if (!ship->IsMonster()) { monsters = false; break; } } } } if (monsters) SetColor(GG::CLR_RED); else SetColor(GG::CLR_WHITE); } else { // single empire owner if (const Empire* empire = Empires().Lookup(owner_id)) SetColor(empire->Color()); else SetColor(GG::CLR_GRAY); // should never be necessary... but just in case } // select icon(s) for fleet(s) int num_ships = 0; for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) { TemporaryPtr<const Fleet> fleet = *it; if (fleet) num_ships += fleet->NumShips(); } m_size_icon = FleetSizeIcon(num_ships, size_type); m_head_icons = FleetHeadIcons(fleets, size_type); // resize to fit icon by first determining necessary size, and then resizing GG::X texture_width(0); GG::Y texture_height(0); if (!m_head_icons.empty()) { texture_width = m_head_icons.front()->DefaultWidth(); texture_height = m_head_icons.front()->DefaultHeight(); } if (m_size_icon) { texture_width = std::max(texture_width, m_size_icon->DefaultWidth()); texture_height = std::max(texture_height, m_size_icon->DefaultHeight()); } // determine if fleet icon should be rotated. this should be done if the fleet is moving along // a starlane, which is the case if the fleet is not in a system and has a valid next system GG::Pt direction_vector(GG::X(0), GG::Y(1)); // default, unrotated button orientation TemporaryPtr<const Fleet> first_fleet; if (!m_fleets.empty()) first_fleet = *fleets.begin(); if (first_fleet && first_fleet->SystemID() == INVALID_OBJECT_ID) { int next_sys_id = first_fleet->NextSystemID(); if (TemporaryPtr<const UniverseObject> obj = GetUniverseObject(next_sys_id)) { // fleet is not in a system and has a valid next destination, so can orient it in that direction // fleet icons might not appear on the screen in the exact place corresponding to their // actual universe position, but if they're moving along a starlane, this code will assume // their apparent position will only be different from their true position in a direction // parallel with the starlane, so the direction from their true position to their destination // position can be used to get a direction vector to orient the icon double dest_x = obj->X(), dest_y = obj->Y(); double cur_x = first_fleet->X(), cur_y = first_fleet->Y(); const MapWnd* map_wnd = ClientUI::GetClientUI()->GetMapWnd(); GG::Pt dest = map_wnd->ScreenCoordsFromUniversePosition(dest_x, dest_y); GG::Pt cur = map_wnd->ScreenCoordsFromUniversePosition(cur_x, cur_y); direction_vector = dest - cur; } } // check for unrotated texture if (Value(direction_vector.x) == 0) { // not rotated. can do simple texture blits m_vertex_components.clear(); } else { // texture is rotated, so need some extra math // get rotated corner vetex x and y components (x1, y1, x2, y2, x3, y3, x4, y4) for texture of appropriate size m_vertex_components = VectorAlignedQuadVertices(direction_vector, Value(texture_height), Value(texture_width)); } // size icon according to texture size (average two dimensions) int diameter = static_cast<int>((Value(texture_width) + Value(texture_height)) / 2.0); Resize(GG::Pt(GG::X(diameter), GG::Y(diameter))); // get selection indicator texture m_selection_texture = ClientUI::GetTexture(ClientUI::ArtDir() / "icons" / "fleet" / "fleet_selection.png", true); }