From: <tz...@us...> - 2007-07-04 22:33:46
|
Revision: 2116 http://svn.sourceforge.net/freeorion/revision/?rev=2116&view=rev Author: tzlaine Date: 2007-07-04 15:33:48 -0700 (Wed, 04 Jul 2007) Log Message: ----------- Mainly, this commit fixes the nonclickablility of the StaticGraphics used as Specials icons under planets in the SidePanel, and the general buggy behavior of the InWindow() functions of all the classes in the SidePanel. Everything works pretty well now -- opaque things are clickable, and transparent places (i.e. the space between the planets in the left side of the SidePanel) are not. Also did some minor grooming. Modified Paths: -------------- trunk/FreeOrion/UI/InfoPanels.cpp trunk/FreeOrion/UI/SidePanel.cpp Modified: trunk/FreeOrion/UI/InfoPanels.cpp =================================================================== --- trunk/FreeOrion/UI/InfoPanels.cpp 2007-07-04 20:17:47 UTC (rev 2115) +++ trunk/FreeOrion/UI/InfoPanels.cpp 2007-07-04 22:33:48 UTC (rev 2116) @@ -36,6 +36,8 @@ m_health_meter_bar(0), m_expand_button(new GG::Button(w - 16, 0, 16, 16, "", GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()), GG::CLR_WHITE)) { + SetText("PopulationPanel"); + const PopCenter* pop = dynamic_cast<const PopCenter*>(&obj); if (!pop) throw std::invalid_argument("Attempted to construct a PopulationPanel with an UniverseObject that is not a PopCenter"); @@ -296,6 +298,8 @@ m_primary_focus_drop(0), m_secondary_focus_drop(0), m_expand_button(new GG::Button(w - 16, 0, 16, 16, "", GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()), GG::CLR_WHITE)) { + SetText("ResourcePanel"); + const ResourceCenter* res = dynamic_cast<const ResourceCenter*>(&obj); if (!res) throw std::invalid_argument("Attempted to construct a ResourcePanel with an UniverseObject that is not a ResourceCenter"); @@ -832,7 +836,9 @@ m_initial_current(m_meter.Current()), m_projected_max(m_meter.Max()), m_projected_current(m_meter.Current()) -{} +{ + SetText("MeterStatusBar2"); +} void MeterStatusBar2::SetProjectedCurrent(double current) { @@ -903,6 +909,8 @@ m_building_indicators(), m_expand_button(new GG::Button(w - 16, 0, 16, 16, "", GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()), GG::CLR_WHITE)) { + SetText("BuildingsPanel"); + if (m_columns < 1) throw std::invalid_argument("Attempted to create a BuidingsPanel with less than 1 column"); // expand / collapse button at top right @@ -1171,6 +1179,8 @@ m_graphic(0), m_progress_bar(0) { + SetText("BuildingIndicator"); + boost::shared_ptr<GG::Texture> texture = ClientUI::GetTexture(ClientUI::ArtDir() / type.Graphic()); m_graphic = new GG::StaticGraphic(0, 0, w, w, texture, GG::GR_FITGRAPHIC | GG::GR_PROPSCALE); AttachChild(m_graphic); @@ -1183,6 +1193,8 @@ m_graphic(0), m_progress_bar(0) { + SetText("BuildingIndicator"); + boost::shared_ptr<GG::Texture> texture = ClientUI::GetTexture(ClientUI::ArtDir() / type.Graphic()); m_graphic = new GG::StaticGraphic(0, 0, w, w, texture, GG::GR_FITGRAPHIC | GG::GR_PROPSCALE); AttachChild(m_graphic); @@ -1258,12 +1270,13 @@ ///////////////////////////////////// // SpecialsPanel // ///////////////////////////////////// - SpecialsPanel::SpecialsPanel(int w, const UniverseObject &obj) : Wnd(0, 0, w, ClientUI::Pts()*4/3, GG::CLICKABLE), m_object_id(obj.ID()), m_icons() { + SetText("SpecialsPanel"); + Update(); SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); SetBrowseText("??????????"); @@ -1280,16 +1293,16 @@ bool SpecialsPanel::InWindow(const GG::Pt& pt) const { - for (std::vector<GG::StaticGraphic*>::const_iterator it = m_icons.begin(); it != m_icons.end(); ++it) + bool retval = false; + for (std::vector<GG::StaticGraphic*>::const_iterator it = m_icons.begin(); it != m_icons.end(); ++it) { if ((*it)->InWindow(pt)) - return true; - - return false; + retval = true; + } + return retval; } void SpecialsPanel::Render() -{ -} +{} void SpecialsPanel::MouseWheel(const GG::Pt& pt, int move, Uint32 keys) { @@ -1316,9 +1329,10 @@ const Special* special = GetSpecial(*it); boost::shared_ptr<GG::Texture> texture = ClientUI::GetTexture(ClientUI::ArtDir() / special->Graphic()); - GG::StaticGraphic* graphic = new GG::StaticGraphic(0, 0, icon_size, icon_size, texture, GG::GR_FITGRAPHIC | GG::GR_PROPSCALE | GG::CLICKABLE); + GG::StaticGraphic* graphic = new GG::StaticGraphic(0, 0, icon_size, icon_size, texture, GG::GR_FITGRAPHIC | GG::GR_PROPSCALE, GG::CLICKABLE); graphic->SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); graphic->SetBrowseText("!!!!!!!!!!"); + graphic->SetText(UserString(special->Name()) + " Special graphic"); m_icons.push_back(graphic); } @@ -1335,6 +1349,7 @@ icon->MoveTo(GG::Pt(x, 0)); AttachChild(icon); + GG::Pt icon_ul = icon->UpperLeft(); } } Modified: trunk/FreeOrion/UI/SidePanel.cpp =================================================================== --- trunk/FreeOrion/UI/SidePanel.cpp 2007-07-04 20:17:47 UTC (rev 2115) +++ trunk/FreeOrion/UI/SidePanel.cpp 2007-07-04 22:33:48 UTC (rev 2116) @@ -352,7 +352,7 @@ case SZ_HUGE : scale = 4.0/5.0; break; case SZ_GASGIANT : scale = 5.0/5.0; break; case SZ_ASTEROIDS : scale = 5.0/5.0; break; - default : scale = 2.0/5.0; break; + default : scale = 2.0/5.0; break; } return static_cast<int>(SidePanel::MIN_PLANET_DIAMETER + (SidePanel::MAX_PLANET_DIAMETER - SidePanel::MIN_PLANET_DIAMETER) * scale); @@ -609,7 +609,7 @@ { int index; - if(-1 == (index=child_path.find_first_of('.'))) + if (-1 == (index=child_path.find_first_of('.'))) return node.ContainsChild(child_path)?node.Child(child_path):XMLElement(); else return node.ContainsChild(child_path.substr(0,index)) ? @@ -811,7 +811,7 @@ const Planet* SidePanel::PlanetPanel::GetPlanet() const { const Planet *planet = GetUniverse().Object<const Planet>(m_planet_id); - if(!planet) throw std::runtime_error("SidePanel::PlanetPanel::GetPlanet: planet not found!"); + if (!planet) throw std::runtime_error("SidePanel::PlanetPanel::GetPlanet: planet not found!"); return planet; } @@ -851,10 +851,10 @@ enum OWNERSHIP {OS_NONE, OS_FOREIGN, OS_SELF} owner = OS_NONE; - if(planet->Owners().empty() || planet->IsAboutToBeColonized()) { + if (planet->Owners().empty() || planet->IsAboutToBeColonized()) { owner = OS_NONE; } else { - if(!planet->OwnedBy(HumanClientApp::GetApp()->EmpireID())) + if (!planet->OwnedBy(HumanClientApp::GetApp()->EmpireID())) owner = OS_FOREIGN; else owner = OS_SELF; @@ -910,15 +910,18 @@ void SidePanel::PlanetPanel::MouseWheel(const GG::Pt& pt, int move, Uint32 keys) { GG::Wnd *parent; - if((parent=Parent())) + if ((parent=Parent())) parent->MouseWheel(pt,move,keys); } bool SidePanel::PlanetPanel::InWindow(const GG::Pt& pt) const { + // The mouse is in this window if it is in the rightmost Width() - MAX_PLANET_DIAMETER portion, or if it is over the + // planet graphic, or if it is over the specials panel. That is, it falls through to the MapWnd if it is over the + // empty space around the planet on the left side of the panel. GG::Pt ul = UpperLeft(), lr = LowerRight(); - ul.x += MAX_PLANET_DIAMETER / 2; - return ((ul <= pt && pt < lr) || InPlanet(pt)); + ul.x += MAX_PLANET_DIAMETER; + return (ul <= pt && pt < lr || m_specials_panel->InWindow(pt) || InPlanet(pt)); } SidePanel::PlanetPanel::HilitingType SidePanel::PlanetPanel:: Hiliting() const @@ -928,15 +931,14 @@ void SidePanel::PlanetPanel::LClick(const GG::Pt& pt, Uint32 keys) { - if(InPlanet(pt)) + if (InPlanet(pt)) { - if(GetOptionsDB().Get<bool>("UI.sound.enabled")) + if (GetOptionsDB().Get<bool>("UI.sound.enabled")) HumanClientApp::GetApp()->PlaySound(ClientUI::SoundDir() / GetOptionsDB().Get<std::string>("UI.sound.planet-button-click")); PlanetImageLClickedSignal(m_planet_id); } } - void SidePanel::PlanetPanel::Render() { const Planet *planet = GetPlanet(); @@ -973,20 +975,20 @@ int empire_id = HumanClientApp::GetApp()->EmpireID(); std::map<int, int> pending_colonization_orders = HumanClientApp::GetApp()->PendingColonizationOrders(); std::map<int, int>::const_iterator it = pending_colonization_orders.find(planet->ID()); - if(it == pending_colonization_orders.end()) // colonize + if (it == pending_colonization_orders.end()) // colonize { Ship *ship=FindColonyShip(planet->SystemID()); - if(ship==0) + if (ship==0) throw std::runtime_error("SidePanel::PlanetPanel::ClickColonize ship not found!"); - if(!ship->GetFleet()->Accept(StationaryFleetVisitor(*ship->GetFleet()->Owners().begin()))) + if (!ship->GetFleet()->Accept(StationaryFleetVisitor(*ship->GetFleet()->Owners().begin()))) { GG::ThreeButtonDlg dlg(320,200,UserString("SP_USE_DEPARTING_COLONY_SHIPS_QUESTION"), GG::GUI::GetGUI()->GetFont(ClientUI::Font(),ClientUI::Pts()),ClientUI::WndColor(),ClientUI::CtrlBorderColor(),ClientUI::CtrlColor(),ClientUI::TextColor(),2, UserString("YES"),UserString("NO")); dlg.Run(); - if(dlg.Result()!=0) + if (dlg.Result()!=0) return; } @@ -1004,11 +1006,11 @@ Ship* ship = GetUniverse().Object<Ship>(ship_id); Fleet* fleet= ship ? GetUniverse().Object<Fleet>(ship->FleetID()) : NULL; MapWnd* map_wnd = ClientUI::GetClientUI()->GetMapWnd(); - if(fleet) - for( MapWnd::FleetWndIter it = map_wnd->FleetWndBegin();it != map_wnd->FleetWndEnd();++it) + if (fleet) + for ( MapWnd::FleetWndIter it = map_wnd->FleetWndBegin();it != map_wnd->FleetWndEnd();++it) { FleetWnd *fleet_wnd = *it; - if(fleet->SystemID() == fleet_wnd->SystemID() + if (fleet->SystemID() == fleet_wnd->SystemID() && !fleet_wnd->ContainsFleet(fleet->ID())) { fleet_wnd->AddFleet(GetUniverse().Object<Fleet>(fleet->ID())); @@ -1022,7 +1024,7 @@ { const Planet *planet = GetPlanet(); - if(!planet->OwnedBy(HumanClientApp::GetApp()->EmpireID())) + if (!planet->OwnedBy(HumanClientApp::GetApp()->EmpireID())) return; @@ -1030,7 +1032,7 @@ menu_contents.next_level.push_back(GG::MenuItem(UserString("SP_RENAME_PLANET"), 1, false, false)); GG::PopupMenu popup(pt.x, pt.y, GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()), menu_contents, ClientUI::TextColor()); - if(popup.Run()) + if (popup.Run()) switch (popup.MenuID()) { case 1: @@ -1038,7 +1040,7 @@ std::string plt_name = planet->Name(); CUIEditWnd edit_wnd(350, UserString("SP_ENTER_NEW_PLANET_NAME"), plt_name); edit_wnd.Run(); - if(edit_wnd.Result() != "") + if (edit_wnd.Result() != "") { HumanClientApp::GetApp()->Orders().IssueOrder(new RenameOrder(HumanClientApp::GetApp()->EmpireID(), planet->ID(), edit_wnd.Result())); m_planet_name->SetText(planet->Name()); @@ -1066,20 +1068,23 @@ bool SidePanel::PlanetPanelContainer::InWindow(const GG::Pt& pt) const { - if(pt.y < UpperLeft().y) - return false; - - bool retval = UpperLeft() <= pt && pt < LowerRight(); - for(unsigned int i = 0; i < m_planet_panels.size() && !retval; ++i) - if(m_planet_panels[i]->InWindow(pt)) - retval = true; - + // The pt is in the container if it is in the vertical extent of the container and at least one of the container's + // panels. + bool retval = false; + GG::Pt ul = UpperLeft(), lr = LowerRight(); + if (ul.y <= pt.y || pt.y < lr.y) + { + for (unsigned int i = 0; i < m_planet_panels.size() && !retval; ++i) { + if (m_planet_panels[i]->InWindow(pt)) + retval = true; + } + } return retval; } void SidePanel::PlanetPanelContainer::MouseWheel(const GG::Pt& pt, int move, Uint32 keys) { - if(m_vscroll) + if (m_vscroll) move < 0 ? m_vscroll->ScrollLineIncr() : m_vscroll->ScrollLineDecr(); } @@ -1350,7 +1355,13 @@ bool SidePanel::InWindow(const GG::Pt& pt) const { - return (UpperLeft() + GG::Pt(MAX_PLANET_DIAMETER, 0) <= pt && pt < LowerRight()) || m_planet_panel_container->InWindow(pt); + // The pt is in the panel if it is in the normal bounds of the panel and above the PlanetPanelContainer, OR if it is + // either within the rightmost Width() - MAX_PLANET_DIAMETER portion of the panel, or within the + // PlanetPanelContainer. Note that this allows clicks, etc., to fall through the spaces between the planets to the + // MapWnd. + return pt.y < m_planet_panel_container->UpperLeft().y ? + Wnd::InWindow(pt) : + UpperLeft() + GG::Pt(MAX_PLANET_DIAMETER, 0) <= pt && pt < LowerRight() || m_planet_panel_container->InWindow(pt); } void SidePanel::Render() @@ -1367,10 +1378,8 @@ void SidePanel::RefreshImpl() { UpdateSystemResourceSummary(); - // update individual PlanetPanels in PlanetPanelContainer, then redo layout of panel container m_planet_panel_container->RefreshAllPlanetPanels(); - } void SidePanel::SetSystemImpl() { @@ -1419,7 +1428,7 @@ m_system_name->Insert(row); ++system_names_in_droplist; - if(sys_vec[i] == s_system) + if (sys_vec[i] == s_system) select_row = row; } const int TEXT_ROW_HEIGHT = CUISimpleDropDownListRow::DEFAULT_ROW_HEIGHT; @@ -1429,7 +1438,7 @@ m_system_name->SetDropHeight(drop_height); for (int i = 0; i < m_system_name->NumRows(); i++) { - if(select_row == &m_system_name->GetRow(i)) + if (select_row == &m_system_name->GetRow(i)) { m_system_name->Select(i); break; @@ -1449,14 +1458,14 @@ // TODO: add fleet icons std::pair<System::const_orbit_iterator, System::const_orbit_iterator> range = s_system->non_orbit_range(); std::vector<const Fleet*> flt_vec = s_system->FindObjects<Fleet>(); - for(unsigned int i = 0; i < flt_vec.size(); i++) + for (unsigned int i = 0; i < flt_vec.size(); i++) m_fleet_connections.insert(std::pair<int, boost::signals::connection>(flt_vec[i]->ID(), GG::Connect(flt_vec[i]->StateChangedSignal, &SidePanel::FleetsChanged, this))); // add planets std::vector<const Planet*> plt_vec = s_system->FindObjects<Planet>(); m_planet_panel_container->SetPlanets(plt_vec, s_system->Star()); - for(unsigned int i = 0; i < plt_vec.size(); i++) { + for (unsigned int i = 0; i < plt_vec.size(); i++) { m_system_connections.insert(GG::Connect(plt_vec[i]->StateChangedSignal, &SidePanel::UpdateSystemResourceSummary, this)); m_system_connections.insert(GG::Connect(plt_vec[i]->ResourceCenterChangedSignal, SidePanel::ResourceCenterChangedSignal)); } @@ -1558,13 +1567,13 @@ void SidePanel::UpdateSystemResourceSummary() { - if(s_system) + if (s_system) { std::vector<const Planet*> plt_vec = s_system->FindObjects<Planet>(); int farming = 0, mining = 0, trade = 0, research = 0, industry = 0, defense = 0, num_empire_planets = 0; - for(unsigned int i = 0; i < plt_vec.size(); i++) - if(plt_vec[i]->Owners().find(HumanClientApp::GetApp()->EmpireID()) != plt_vec[i]->Owners().end()) + for (unsigned int i = 0; i < plt_vec.size(); i++) { + if (plt_vec[i]->Owners().find(HumanClientApp::GetApp()->EmpireID()) != plt_vec[i]->Owners().end()) { farming +=static_cast<int>(plt_vec[i]->FarmingPoints()); mining +=static_cast<int>(plt_vec[i]->MiningPoints()); @@ -1575,6 +1584,7 @@ num_empire_planets++; } + } m_system_resource_summary->SetFarming (farming ); m_system_resource_summary->SetMining (mining ); @@ -1583,7 +1593,7 @@ m_system_resource_summary->SetIndustry(industry); m_system_resource_summary->SetDefense (defense ); - if(num_empire_planets==0) + if (num_empire_planets==0) { m_system_resource_summary->Hide(); m_static_text_systemproduction->Hide(); |