From: <geo...@us...> - 2010-01-02 06:17:19
|
Revision: 3310 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3310&view=rev Author: geoffthemedio Date: 2010-01-02 06:17:08 +0000 (Sat, 02 Jan 2010) Log Message: ----------- -Fixed issue where fleet ordered to move to system that wasn't currently visible to player's empire would be shown as "Holding at ..." its current location in the FleetWnd (although the move lines did and still do show its ordered path). -Added check to avoid unnecessary error message in logs when selecting no system in SidePanel -Comment tweak in code that default selects a planet on production screen Modified Paths: -------------- trunk/FreeOrion/UI/BuildDesignatorWnd.cpp trunk/FreeOrion/UI/FleetWnd.cpp trunk/FreeOrion/UI/SidePanel.cpp Modified: trunk/FreeOrion/UI/BuildDesignatorWnd.cpp =================================================================== --- trunk/FreeOrion/UI/BuildDesignatorWnd.cpp 2010-01-02 01:05:45 UTC (rev 3309) +++ trunk/FreeOrion/UI/BuildDesignatorWnd.cpp 2010-01-02 06:17:08 UTC (rev 3310) @@ -1014,7 +1014,7 @@ // couldn't reselect stored default, so need to find a reasonable other // planet to select. attempt to find one owned by this client's player - const System* sys = GetObject<System>(system_id); + const System* sys = GetObject<System>(system_id); // only checking visible objects for this clients empire (and not the latest known objects) as an empire shouldn't be able to use a planet or system it can't currently see as a production location if (!sys) { Logger().errorStream() << "BuildDesignatorWnd::SelectDefaultPlanet couldn't get system with id " << system_id; return; Modified: trunk/FreeOrion/UI/FleetWnd.cpp =================================================================== --- trunk/FreeOrion/UI/FleetWnd.cpp 2010-01-02 01:05:45 UTC (rev 3309) +++ trunk/FreeOrion/UI/FleetWnd.cpp 2010-01-02 06:17:08 UTC (rev 3310) @@ -83,8 +83,10 @@ if (!fleet) return retval; - const System* dest = GetObject<System>(fleet->FinalDestinationID()); - const System* cur_sys = GetObject<System>(fleet->SystemID()); + const ObjectMap& objects = GetMainObjectMap(); + + const System* dest = objects.Object<System>(fleet->FinalDestinationID()); + const System* cur_sys = objects.Object<System>(fleet->SystemID()); if (dest && dest != cur_sys) { std::pair<int, int> eta = fleet->ETA(); // .first is turns to final destination. .second is turns to next system on route @@ -2452,10 +2454,12 @@ if (m_fleet_ids.empty()) return UserString("FW_NO_FLEET"); + const ObjectMap& objects = GetMainObjectMap(); + // at least one fleet is available, so show appropriate title this // FleetWnd's empire and system if (const Empire* empire = Empires().Lookup(m_empire_id)) { - if (const System* system = GetObject<System>(m_system_id)) { + if (const System* system = objects.Object<System>(m_system_id)) { std::string sys_name = system->Name(); if (sys_name.empty()) sys_name = UserString("SP_UNKNOWN_SYSTEM"); @@ -2466,7 +2470,7 @@ empire->Name()); } } else { - if (const System* system = GetObject<System>(m_system_id)) { + if (const System* system = objects.Object<System>(m_system_id)) { std::string sys_name = system->Name(); if (sys_name.empty()) sys_name = UserString("SP_UNKNOWN_SYSTEM"); Modified: trunk/FreeOrion/UI/SidePanel.cpp =================================================================== --- trunk/FreeOrion/UI/SidePanel.cpp 2010-01-02 01:05:45 UTC (rev 3309) +++ trunk/FreeOrion/UI/SidePanel.cpp 2010-01-02 06:17:08 UTC (rev 3310) @@ -1640,6 +1640,11 @@ (*it)->RefreshImpl(); + // early exit if no valid system object to get or connect signals to + if (s_system_id == UniverseObject::INVALID_OBJECT_ID) + return; + + // connect state changed and insertion signals for planets and fleets in system const System* system = GetObject<System>(s_system_id); if (!system) |
From: <geo...@us...> - 2010-01-02 20:58:15
|
Revision: 3312 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3312&view=rev Author: geoffthemedio Date: 2010-01-02 20:57:28 +0000 (Sat, 02 Jan 2010) Log Message: ----------- -Modified patch by wrwrwr that adds padding between StatisticIcon text and icon, minimum size to infopanel meter icons, and minimum icon size and layout tweaks to FleetWnd fleet panels. -Minor code layout tweak in FleetUIManager::SetActiveFleetWnd by me Modified Paths: -------------- trunk/FreeOrion/UI/CUIControls.cpp trunk/FreeOrion/UI/FleetWnd.cpp trunk/FreeOrion/UI/InfoPanels.cpp Modified: trunk/FreeOrion/UI/CUIControls.cpp =================================================================== --- trunk/FreeOrion/UI/CUIControls.cpp 2010-01-02 08:08:47 UTC (rev 3311) +++ trunk/FreeOrion/UI/CUIControls.cpp 2010-01-02 20:57:28 UTC (rev 3312) @@ -927,6 +927,10 @@ /////////////////////////////////////// // class StatisticIcon /////////////////////////////////////// +namespace { + const int STAT_ICON_PAD = 2; // horizontal or vertical space between icon and label +} + StatisticIcon::StatisticIcon(GG::X x, GG::Y y, GG::X w, GG::Y h, const boost::shared_ptr<GG::Texture> texture, double value, int digits, bool showsign, GG::Flags<GG::WndFlag> flags/* = GG::INTERACTIVE*/) : @@ -940,13 +944,13 @@ // arrange child controls horizontally if icon is wider than it is high, or vertically otherwise if (w >= Value(h)) { m_icon = new GG::StaticGraphic(GG::X0, GG::Y0, GG::X(Value(h)), h, texture, GG::GRAPHIC_FITGRAPHIC); - m_text = new GG::TextControl(GG::X(Value(h)), GG::Y0, w - Value(h), GG::Y(std::max(font_space, Value(h))), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_VCENTER); + m_text = new GG::TextControl(GG::X(Value(h) + STAT_ICON_PAD), GG::Y0, w - Value(h) - STAT_ICON_PAD, GG::Y(std::max(font_space, Value(h))), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_VCENTER); } else { // need vertical space for text, but don't want icon to be larger than available horizontal space - int icon_height = std::min(Value(w), std::max(Value(h - font_space), 1)); + int icon_height = std::min(Value(w), std::max(Value(h - font_space - STAT_ICON_PAD), 1)); int icon_left = Value(w - icon_height)/2; m_icon = new GG::StaticGraphic(GG::X(icon_left), GG::Y0, GG::X(icon_height), GG::Y(icon_height), texture, GG::GRAPHIC_FITGRAPHIC); - m_text = new GG::TextControl(GG::X0, GG::Y(icon_height), w, GG::Y(font_space), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_CENTER | GG::FORMAT_TOP); + m_text = new GG::TextControl(GG::X0, GG::Y(icon_height + STAT_ICON_PAD), w, GG::Y(font_space), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_CENTER | GG::FORMAT_TOP); } AttachChild(m_icon); @@ -967,10 +971,10 @@ // arrange child controls horizontally if icon is wider than it is high, or vertically otherwise if (w >= Value(h)) { m_icon = new GG::StaticGraphic(GG::X0, GG::Y0, GG::X(Value(h)), h, texture, GG::GRAPHIC_FITGRAPHIC); - m_text = new GG::TextControl(GG::X(Value(h)), GG::Y0, w - Value(h), std::max(GG::Y(ClientUI::Pts()*3/2), h), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_VCENTER); + m_text = new GG::TextControl(GG::X(Value(h) + STAT_ICON_PAD), GG::Y0, w - Value(h) - STAT_ICON_PAD, std::max(GG::Y(ClientUI::Pts()*3/2), h), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_VCENTER); } else { m_icon = new GG::StaticGraphic(GG::X0, GG::Y0, w, GG::Y(Value(w)), texture, GG::GRAPHIC_FITGRAPHIC); - m_text = new GG::TextControl(GG::X0, GG::Y(Value(w)), w, GG::Y(ClientUI::Pts()*3/2), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_CENTER | GG::FORMAT_BOTTOM); + m_text = new GG::TextControl(GG::X0, GG::Y(Value(w) + STAT_ICON_PAD), w, GG::Y(ClientUI::Pts()*3/2), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_CENTER | GG::FORMAT_BOTTOM); } m_values[0] = value0; Modified: trunk/FreeOrion/UI/FleetWnd.cpp =================================================================== --- trunk/FreeOrion/UI/FleetWnd.cpp 2010-01-02 08:08:47 UTC (rev 3311) +++ trunk/FreeOrion/UI/FleetWnd.cpp 2010-01-02 20:57:28 UTC (rev 3312) @@ -54,23 +54,20 @@ } GG::Y LabelHeight() { - return GG::Y(ClientUI::Pts() * 3/2); + return GG::Y(ClientUI::Pts()*3/2); } - GG::Y StatIconHeight() { - return GG::Y(ClientUI::Pts()*4/3); + /** + * How big fleet and ship statistics icons should be relative to the current font size. + * Icons shouldn't scale below what they are for the default, 12 pt, font size. + */ + GG::Pt StatIconSize() { + const int font_size = std::max(ClientUI::Pts(), 12); + return GG::Pt(GG::X(font_size*10/3), GG::Y(font_size*4/3)); } - GG::X StatIconWidth() { - return GG::X(Value(StatIconHeight()) * 5/2); - } - - GG::X StatIconSpacingWidth() { - return StatIconWidth(); - } - GG::Y ListRowHeight() { - return GG::Y(std::max(ICON_SIZE, Value(LabelHeight() + StatIconHeight()) + PAD)); + return GG::Y(std::max(ICON_SIZE, Value(LabelHeight() + StatIconSize().y) + PAD)); } boost::shared_ptr<GG::Texture> SpeedIcon() { @@ -392,19 +389,20 @@ } void FleetUIManager::SetActiveFleetWnd(FleetWnd* fleet_wnd) { - if (fleet_wnd != m_active_fleet_wnd) { - // disconnect old active FleetWnd signal - if (m_active_fleet_wnd) - m_ative_fleet_wnd_signal.disconnect(); + if (fleet_wnd == m_active_fleet_wnd) + return; - // set new active FleetWnd - m_active_fleet_wnd = fleet_wnd; + // disconnect old active FleetWnd signal + if (m_active_fleet_wnd) + m_ative_fleet_wnd_signal.disconnect(); - // connect new active FleetWnd selection changed signal - m_ative_fleet_wnd_signal = GG::Connect(m_active_fleet_wnd->SelectedFleetsChangedSignal, ActiveFleetWndSelectedFleetsChangedSignal); + // set new active FleetWnd + m_active_fleet_wnd = fleet_wnd; - ActiveFleetWndChangedSignal(); - } + // connect new active FleetWnd selection changed signal + m_ative_fleet_wnd_signal = GG::Connect(m_active_fleet_wnd->SelectedFleetsChangedSignal, ActiveFleetWndSelectedFleetsChangedSignal); + + ActiveFleetWndChangedSignal(); } bool FleetUIManager::CloseAll() { @@ -573,7 +571,7 @@ meters.push_back(METER_STEALTH); meters.push_back(METER_SHIELD); for (std::vector<MeterType>::const_iterator it = meters.begin(); it != meters.end(); ++it) { - StatisticIcon* icon = new StatisticIcon(GG::X0, GG::Y0, StatIconWidth(), StatIconHeight(), + StatisticIcon* icon = new StatisticIcon(GG::X0, GG::Y0, StatIconSize().x, StatIconSize().y, ClientUI::MeterIcon(*it), 0, 0, false); m_stat_icons.push_back(std::make_pair(MeterStatString(*it), icon)); AttachChild(icon); @@ -582,7 +580,7 @@ // speed stat icon - StatisticIcon* icon = new StatisticIcon(GG::X0, GG::Y0, StatIconWidth(), StatIconHeight(), + StatisticIcon* icon = new StatisticIcon(GG::X0, GG::Y0, StatIconSize().x, StatIconSize().y, SpeedIcon(), 0, 0, false); m_stat_icons.push_back(std::make_pair(SPEED_STAT_STRING, icon)); AttachChild(icon); @@ -763,31 +761,28 @@ void DoLayout() { if (m_ship_icon) { - // position icon in centre of available space - int ICON_OFFSET = std::max(0, (Value(Height()) - ICON_SIZE) / 2); - GG::Pt icon_ul = GG::Pt(GG::X(ICON_OFFSET), GG::Y(ICON_OFFSET)); - GG::Pt icon_lr = icon_ul + GG::Pt(GG::X(ICON_SIZE), GG::Y(ICON_SIZE)); - + // position ship icon in the centre of available space + const int ICON_OFFSET = std::max(0, (Value(Height()) - ICON_SIZE) / 2); + const GG::Pt icon_ul = GG::Pt(GG::X(ICON_OFFSET), GG::Y(ICON_OFFSET)); + const GG::Pt icon_lr = icon_ul + GG::Pt(GG::X(ICON_SIZE), GG::Y(ICON_SIZE)); if (m_ship_icon) m_ship_icon->SizeMove(icon_ul, icon_lr); if (m_scrap_indicator) m_scrap_indicator->SizeMove(icon_ul, icon_lr); } - - GG::Pt name_ul = GG::Pt(GG::X(ICON_SIZE + PAD), GG::Y0); - GG::Pt name_lr = GG::Pt(Width() - GG::X(PAD), LabelHeight()); + const GG::Pt name_ul = GG::Pt(GG::X(ICON_SIZE + PAD), GG::Y0); + const GG::Pt name_lr = GG::Pt(Width() - GG::X(PAD), LabelHeight()); m_ship_name_text->SizeMove(name_ul, name_lr); if (m_design_name_text) m_design_name_text->SizeMove(name_ul, name_lr); - // set stat icon positions - GG::Pt icon_ul(GG::X(ICON_SIZE) + GG::X(PAD), LabelHeight()); + // position ship statistic icons one after another horizontally and centered vertically + GG::Pt icon_ul = GG::Pt(GG::X(ICON_SIZE + PAD), LabelHeight() + std::max(GG::Y0, (Height() - LabelHeight() - StatIconSize().y) / 2)); for (std::vector<std::pair<std::string, StatisticIcon*> >::const_iterator it = m_stat_icons.begin(); it != m_stat_icons.end(); ++it) { - GG::Pt icon_lr = icon_ul + GG::Pt(StatIconWidth(), StatIconHeight()); - it->second->SizeMove(icon_ul, icon_lr); - icon_ul += GG::Pt(StatIconSpacingWidth(), GG::Y0); + it->second->SizeMove(icon_ul, icon_ul + StatIconSize()); + icon_ul.x += StatIconSize().x; } } @@ -917,7 +912,7 @@ int tooltip_delay = GetOptionsDB().Get<int>("UI.tooltip-delay"); // stat icon for fleet fuel - StatisticIcon* icon = new StatisticIcon(GG::X0, GG::Y0, StatIconWidth(), StatIconHeight(), + StatisticIcon* icon = new StatisticIcon(GG::X0, GG::Y0, StatIconSize().x, StatIconSize().y, ClientUI::MeterIcon(METER_FUEL), 0, 0, false); m_stat_icons.push_back(std::make_pair(MeterStatString(METER_FUEL), icon)); icon->SetBrowseModeTime(tooltip_delay); @@ -925,7 +920,7 @@ AttachChild(icon); // stat icon for fleet speed - icon = new StatisticIcon(GG::X0, GG::Y0, StatIconWidth(), StatIconHeight(), + icon = new StatisticIcon(GG::X0, GG::Y0, StatIconSize().x, StatIconSize().y, SpeedIcon(), 0, 0, false); m_stat_icons.push_back(std::make_pair(SPEED_STAT_STRING, icon)); icon->SetBrowseModeTime(tooltip_delay); @@ -1126,25 +1121,23 @@ void FleetDataPanel::DoLayout() { if (m_fleet_icon) { - // position icon in centre of available space - int ICON_OFFSET = std::max(0, (Value(Height()) - ICON_SIZE) / 2); - GG::Pt icon_ul = GG::Pt(GG::X(ICON_OFFSET), GG::Y(ICON_OFFSET)); - GG::Pt icon_lr = icon_ul + GG::Pt(GG::X(ICON_SIZE), GG::Y(ICON_SIZE)); - + // position fleet icon in centre of available space + const int ICON_OFFSET = std::max(0, (Value(Height()) - ICON_SIZE) / 2); + const GG::Pt icon_ul = GG::Pt(GG::X(ICON_OFFSET), GG::Y(ICON_OFFSET)); + const GG::Pt icon_lr = icon_ul + GG::Pt(GG::X(ICON_SIZE), GG::Y(ICON_SIZE)); m_fleet_icon->SizeMove(icon_ul, icon_lr); } - GG::Pt name_ul = GG::Pt(GG::X(ICON_SIZE + PAD), GG::Y0); - GG::Pt name_lr = GG::Pt(Width() - GG::X(PAD), LabelHeight()); + const GG::Pt name_ul = GG::Pt(GG::X(ICON_SIZE + PAD), GG::Y0); + const GG::Pt name_lr = GG::Pt(Width() - GG::X(PAD), LabelHeight()); m_fleet_name_text->SizeMove(name_ul, name_lr); m_fleet_destination_text->SizeMove(name_ul, name_lr); - // set stat icon positions - GG::Pt icon_ul(GG::X(ICON_SIZE + PAD), LabelHeight()); + // position stat icons, centering them vertically if there's more space than required + GG::Pt icon_ul = GG::Pt(GG::X(ICON_SIZE + PAD), LabelHeight() + std::max(GG::Y0, (Height() - LabelHeight() - StatIconSize().y) / 2)); for (std::vector<std::pair<std::string, StatisticIcon*> >::const_iterator it = m_stat_icons.begin(); it != m_stat_icons.end(); ++it) { - GG::Pt icon_lr = icon_ul + GG::Pt(StatIconWidth(), StatIconHeight()); - it->second->SizeMove(icon_ul, icon_lr); - icon_ul += GG::Pt(StatIconSpacingWidth(), GG::Y0); + it->second->SizeMove(icon_ul, icon_ul + StatIconSize()); + icon_ul.x += StatIconSize().x; } } Modified: trunk/FreeOrion/UI/InfoPanels.cpp =================================================================== --- trunk/FreeOrion/UI/InfoPanels.cpp 2010-01-02 08:08:47 UTC (rev 3311) +++ trunk/FreeOrion/UI/InfoPanels.cpp 2010-01-02 20:57:28 UTC (rev 3312) @@ -71,11 +71,12 @@ } } - /** - * How big we want meter icons with respect to the current UI font size. - */ + /** How big we want meter icons with respect to the current UI font size. + * Meters should scale along font size, but not below the size for the + * default 12 points font. */ GG::Pt MeterIconSize() { - return GG::Pt(GG::X(std::max(ClientUI::Pts()*4/3, 16)), GG::Y(std::max(ClientUI::Pts()*4/3, 16))); + const int icon_size = std::max(ClientUI::Pts(), 12) * 4/3; + return GG::Pt(GG::X(icon_size), GG::Y(icon_size)); } /** Returns how much of specified \a resource_type is being consumed by the |
From: <geo...@us...> - 2010-01-05 06:39:43
|
Revision: 3318 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3318&view=rev Author: geoffthemedio Date: 2010-01-05 06:39:36 +0000 (Tue, 05 Jan 2010) Log Message: ----------- -Added a modified CUIButton class, SettableInWindowCUIButton, that lets the user specify a replacement InWindow function at runtime -Used SettableInWindowCUIButton to make the clickable area of the menu / subscreen buttons at the top right of the map screen be different from their visible area; now the buttons appear to be in a nicer looking position (away from the edge of the screen by a padding distance) but are still easy to click since their clickable area extends to the adjacent edges of the toolbar / screen. Modified Paths: -------------- trunk/FreeOrion/UI/CUIControls.cpp trunk/FreeOrion/UI/CUIControls.h trunk/FreeOrion/UI/FleetWnd.cpp trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/UI/MapWnd.h Modified: trunk/FreeOrion/UI/CUIControls.cpp =================================================================== --- trunk/FreeOrion/UI/CUIControls.cpp 2010-01-04 03:53:45 UTC (rev 3317) +++ trunk/FreeOrion/UI/CUIControls.cpp 2010-01-05 06:39:36 UTC (rev 3318) @@ -195,6 +195,33 @@ /////////////////////////////////////// +// class SettableInWindowCUIButton +/////////////////////////////////////// +SettableInWindowCUIButton::SettableInWindowCUIButton(GG::X x, GG::Y y, GG::X w, const std::string& str, + const boost::shared_ptr<GG::Font>& font/* = boost::shared_ptr<GG::Font>()*/, + GG::Clr color/* = ClientUI::CtrlColor()*/, + GG::Clr border/* = ClientUI::CtrlBorderColor()*/, + int thick/* = 2*/, + GG::Clr text_color/* = ClientUI::TextColor()*/, + GG::Flags<GG::WndFlag> flags/* = GG::INTERACTIVE*/) : + CUIButton(x, y, w, str, font, color, border, thick, text_color, flags) +{} + +bool SettableInWindowCUIButton::InWindow(const GG::Pt& pt) const +{ + if (m_in_window_func) + return m_in_window_func(pt); + else + return CUIButton::InWindow(pt); +} + +void SettableInWindowCUIButton::SetInWindow(boost::function<bool(const GG::Pt&)> in_window_function) +{ + m_in_window_func = in_window_function; +} + + +/////////////////////////////////////// // class CUITurnButton /////////////////////////////////////// CUITurnButton::CUITurnButton(GG::X x, GG::Y y, GG::X w, const std::string& str, const boost::shared_ptr<GG::Font>& font/* = boost::shared_ptr<GG::Font>()*/, Modified: trunk/FreeOrion/UI/CUIControls.h =================================================================== --- trunk/FreeOrion/UI/CUIControls.h 2010-01-04 03:53:45 UTC (rev 3317) +++ trunk/FreeOrion/UI/CUIControls.h 2010-01-05 06:39:36 UTC (rev 3318) @@ -4,18 +4,20 @@ #define _CUIControls_h_ #include "ClientUI.h" +#include "CUIDrawUtil.h" #include <GG/Button.h> -#include "CUIDrawUtil.h" #include <GG/DropDownList.h> #include <GG/Edit.h> -#include <GG/dialogs/FileDlg.h> #include <GG/Menu.h> #include <GG/MultiEdit.h> #include <GG/Scroll.h> #include <GG/Slider.h> #include <GG/StaticGraphic.h> #include <GG/TabWnd.h> +#include <GG/dialogs/FileDlg.h> +#include <boost/function.hpp> + #include "LinkText.h" @@ -24,7 +26,6 @@ //! depend on graphics and design team specifications. They extend //! GG controls. - /** a FreeOrion Button control */ class CUIButton : public GG::Button { @@ -65,6 +66,28 @@ int m_border_thick; }; +class SettableInWindowCUIButton : public CUIButton +{ +public: + /** \name Structors */ //@{ + SettableInWindowCUIButton(GG::X x, GG::Y y, GG::X w, const std::string& str, const boost::shared_ptr<GG::Font>& font = boost::shared_ptr<GG::Font>(), + GG::Clr color = ClientUI::CtrlColor(), GG::Clr border = ClientUI::CtrlBorderColor(), int thick = 1, + GG::Clr text_color = ClientUI::TextColor(), GG::Flags<GG::WndFlag> flags = GG::INTERACTIVE); ///< basic ctor + //@} + + /** \name Accessors */ //@{ + virtual bool InWindow(const GG::Pt& pt) const; + //@} + + /** \name Mutators */ //@{ + void SetInWindow(boost::function<bool(const GG::Pt&)> in_window_function); + //@} + +private: + boost::function<bool(const GG::Pt&)> m_in_window_func; +}; + + /** a FreeOrion next-turn button control */ class CUITurnButton : public CUIButton { Modified: trunk/FreeOrion/UI/FleetWnd.cpp =================================================================== --- trunk/FreeOrion/UI/FleetWnd.cpp 2010-01-04 03:53:45 UTC (rev 3317) +++ trunk/FreeOrion/UI/FleetWnd.cpp 2010-01-05 06:39:36 UTC (rev 3318) @@ -63,10 +63,9 @@ return GG::Y(ClientUI::Pts()*3/2); } - /** - * How big fleet and ship statistics icons should be relative to the current font size. - * Icons shouldn't scale below what they are for the default, 12 pt, font size. - */ + /** How big fleet and ship statistics icons should be relative to the + * current font size. Icons shouldn't scale below what they are for the + * default, 12 pt, font size. */ GG::Pt StatIconSize() { const int font_size = std::max(ClientUI::Pts(), 12); return GG::Pt(GG::X(font_size*10/3), GG::Y(font_size*4/3)); Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2010-01-04 03:53:45 UTC (rev 3317) +++ trunk/FreeOrion/UI/MapWnd.cpp 2010-01-05 06:39:36 UTC (rev 3318) @@ -219,6 +219,14 @@ return "Building"; return "UniverseObject"; } + + GG::X WndLeft(const GG::Wnd* wnd) { return wnd ? wnd->UpperLeft().x : GG::X0; } + GG::X WndRight(const GG::Wnd* wnd) { return wnd ? wnd->LowerRight().x : GG::X0; } + GG::Y WndTop(const GG::Wnd* wnd) { return wnd ? wnd->UpperLeft().y : GG::Y0; } + GG::Y WndBottom(const GG::Wnd* wnd) { return wnd ? wnd->LowerRight().y : GG::Y0; } + bool InRect(GG::X left, GG::Y top, GG::X right, GG::Y bottom, const GG::Pt& pt) { + return pt.x >= left && pt.y >= top && pt.x < right && pt.y < bottom; //pt >= ul && pt < lr; + } } @@ -637,31 +645,81 @@ //GG::Connect(m_zoom_slider->SlidSignal, &MapWnd::ZoomSlid, this); - // Subscreen / Menu buttons + // Subscreen / Menu buttons (placed right to left) + + + // Menu button GG::X button_width = font->TextExtent(UserString("MAP_BTN_MENU")).x + BUTTON_TOTAL_MARGIN; - m_btn_menu = new CUIButton(m_toolbar->LowerRight().x-button_width, GG::Y0, button_width, UserString("MAP_BTN_MENU") ); + m_btn_menu = new SettableInWindowCUIButton(m_toolbar->LowerRight().x - button_width - GG::X(LAYOUT_MARGIN), + GG::Y(LAYOUT_MARGIN), + button_width, UserString("MAP_BTN_MENU") ); m_toolbar->AttachChild(m_btn_menu); GG::Connect(m_btn_menu->ClickedSignal, BoolToVoidAdapter(boost::bind(&MapWnd::ShowMenu, this))); + // create custom InWindow function for Menu button that extends its + // clickable area to the adjacent edges of the toolbar containing it + boost::function<bool(const GG::Pt&)> in_window_func = + boost::bind(&InRect, boost::bind(&WndLeft, m_btn_menu), boost::bind(&WndTop, m_toolbar), + boost::bind(&WndRight, m_toolbar), boost::bind(&WndBottom, m_btn_menu), + _1); + m_btn_menu->SetInWindow(in_window_func); + + // Design button button_width = font->TextExtent(UserString("MAP_BTN_DESIGN")).x + BUTTON_TOTAL_MARGIN; - m_btn_design = new CUIButton(m_btn_menu->UpperLeft().x-LAYOUT_MARGIN-button_width, GG::Y0, button_width, UserString("MAP_BTN_DESIGN") ); + m_btn_design = new SettableInWindowCUIButton(m_btn_menu->UpperLeft().x-LAYOUT_MARGIN-button_width, + GG::Y(LAYOUT_MARGIN), + button_width, UserString("MAP_BTN_DESIGN") ); m_toolbar->AttachChild(m_btn_design); GG::Connect(m_btn_design->ClickedSignal, BoolToVoidAdapter(boost::bind(&MapWnd::ToggleDesign, this))); + // custom InWindow that extends up to edge of toolbar, but NOT furhter to + // right as was done for Menu button + in_window_func = + boost::bind(&InRect, boost::bind(&WndLeft, m_btn_design), boost::bind(&WndTop, m_toolbar), + boost::bind(&WndRight, m_btn_design), boost::bind(&WndBottom, m_btn_design), + _1); + m_btn_design->SetInWindow(in_window_func); + + // Production button button_width = font->TextExtent(UserString("MAP_BTN_PRODUCTION")).x + BUTTON_TOTAL_MARGIN; - m_btn_production = new CUIButton(m_btn_design->UpperLeft().x-LAYOUT_MARGIN-button_width, GG::Y0, button_width, UserString("MAP_BTN_PRODUCTION") ); + m_btn_production = new SettableInWindowCUIButton(m_btn_design->UpperLeft().x - LAYOUT_MARGIN-button_width, + GG::Y(LAYOUT_MARGIN), + button_width, UserString("MAP_BTN_PRODUCTION") ); m_toolbar->AttachChild(m_btn_production); GG::Connect(m_btn_production->ClickedSignal, BoolToVoidAdapter(boost::bind(&MapWnd::ToggleProduction, this))); + in_window_func = + boost::bind(&InRect, boost::bind(&WndLeft, m_btn_production), boost::bind(&WndTop, m_toolbar), + boost::bind(&WndRight, m_btn_production), boost::bind(&WndBottom, m_btn_production), + _1); + m_btn_production->SetInWindow(in_window_func); + + // Research button button_width = font->TextExtent(UserString("MAP_BTN_RESEARCH")).x + BUTTON_TOTAL_MARGIN; - m_btn_research = new CUIButton(m_btn_production->UpperLeft().x-LAYOUT_MARGIN-button_width, GG::Y0, button_width, UserString("MAP_BTN_RESEARCH") ); + m_btn_research = new SettableInWindowCUIButton(m_btn_production->UpperLeft().x - LAYOUT_MARGIN - button_width, + GG::Y(LAYOUT_MARGIN), + button_width, UserString("MAP_BTN_RESEARCH") ); m_toolbar->AttachChild(m_btn_research); GG::Connect(m_btn_research->ClickedSignal, BoolToVoidAdapter(boost::bind(&MapWnd::ToggleResearch, this))); + in_window_func = + boost::bind(&InRect, boost::bind(&WndLeft, m_btn_research), boost::bind(&WndTop, m_toolbar), + boost::bind(&WndRight, m_btn_research), boost::bind(&WndBottom, m_btn_research), + _1); + m_btn_research->SetInWindow(in_window_func); + + // SitRep button button_width = font->TextExtent(UserString("MAP_BTN_SITREP")).x + BUTTON_TOTAL_MARGIN; - m_btn_siterep = new CUIButton(m_btn_research->UpperLeft().x-LAYOUT_MARGIN-button_width, GG::Y0, button_width, UserString("MAP_BTN_SITREP") ); + m_btn_siterep = new SettableInWindowCUIButton(m_btn_research->UpperLeft().x - LAYOUT_MARGIN-button_width, + GG::Y(LAYOUT_MARGIN), + button_width, UserString("MAP_BTN_SITREP") ); m_toolbar->AttachChild(m_btn_siterep); GG::Connect(m_btn_siterep->ClickedSignal, BoolToVoidAdapter(boost::bind(&MapWnd::ToggleSitRep, this))); + in_window_func = + boost::bind(&InRect, boost::bind(&WndLeft, m_btn_siterep), boost::bind(&WndTop, m_toolbar), + boost::bind(&WndRight, m_btn_siterep), boost::bind(&WndBottom, m_btn_siterep), + _1); + m_btn_siterep->SetInWindow(in_window_func); // resources @@ -726,6 +784,10 @@ RemoveAccelerators(); } +void MapWnd::DoLayout() +{ +} + GG::Pt MapWnd::ClientUpperLeft() const { return UpperLeft() + GG::Pt(GG::GUI::GetGUI()->AppWidth(), GG::GUI::GetGUI()->AppHeight()); Modified: trunk/FreeOrion/UI/MapWnd.h =================================================================== --- trunk/FreeOrion/UI/MapWnd.h 2010-01-04 03:53:45 UTC (rev 3317) +++ trunk/FreeOrion/UI/MapWnd.h 2010-01-05 06:39:36 UTC (rev 3318) @@ -10,6 +10,7 @@ #include "FleetButton.h" class CUIButton; +class SettableInWindowCUIButton; class CUIEdit; class CUITurnButton; class FleetWnd; @@ -97,19 +98,21 @@ //!@} //! \name Mutators //!@{ - virtual void Render(); - virtual void LButtonDown(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); - virtual void LDrag(const GG::Pt& pt, const GG::Pt& move, GG::Flags<GG::ModKey> mod_keys); - virtual void LButtonUp(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); - virtual void LClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); - virtual void RClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); - virtual void MouseWheel(const GG::Pt& pt, int move, GG::Flags<GG::ModKey> mod_keys); + virtual void Render(); + virtual void LButtonDown(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); + virtual void LDrag(const GG::Pt& pt, const GG::Pt& move, GG::Flags<GG::ModKey> mod_keys); + virtual void LButtonUp(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); + virtual void LClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); + virtual void RClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys); + virtual void MouseWheel(const GG::Pt& pt, int move, GG::Flags<GG::ModKey> mod_keys); - void InitTurn(int turn_number); //!< called at the start of each turn - void RestoreFromSaveData(const SaveGameUIData& data); //!< restores the UI state that was saved in an earlier call to GetSaveGameUIData(). - void ShowSystemNames(); //!< enables the system name text - void HideSystemNames(); //!< disables the system name text + void DoLayout(); + void InitTurn(int turn_number); //!< called at the start of each turn + void RestoreFromSaveData(const SaveGameUIData& data); //!< restores the UI state that was saved in an earlier call to GetSaveGameUIData(). + void ShowSystemNames(); //!< enables the system name text + void HideSystemNames(); //!< disables the system name text + mutable SystemLeftClickedSignalType SystemLeftClickedSignal; mutable SystemRightClickedSignalType SystemRightClickedSignal; mutable SystemBrowsedSignalType SystemBrowsedSignal; @@ -364,7 +367,7 @@ CUIToolBar* m_toolbar; StatisticIcon *m_food, *m_mineral, *m_trade, *m_population, *m_research, *m_industry; - CUIButton *m_btn_siterep, *m_btn_research, *m_btn_production, *m_btn_design, *m_btn_menu; + SettableInWindowCUIButton *m_btn_siterep, *m_btn_research, *m_btn_production, *m_btn_design, *m_btn_menu; FPSIndicator* m_FPS; GG::Slider* m_zoom_slider; //!< allows user to set zoom level |
From: <tz...@us...> - 2010-03-03 02:55:12
|
Revision: 3359 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3359&view=rev Author: tzlaine Date: 2010-03-03 02:55:04 +0000 (Wed, 03 Mar 2010) Log Message: ----------- Changes required by recent changes to Wnd clipping in GG. This fixes the magically invisible FleetWnd close buttons. Modified Paths: -------------- trunk/FreeOrion/UI/CUIWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/DesignWnd.cpp trunk/FreeOrion/UI/FleetWnd.cpp trunk/FreeOrion/UI/InfoPanels.cpp trunk/FreeOrion/UI/MarkupBox.cpp trunk/FreeOrion/UI/ProductionWnd.cpp trunk/FreeOrion/UI/ResearchWnd.cpp trunk/FreeOrion/UI/SidePanel.cpp trunk/FreeOrion/UI/SitRepPanel.cpp trunk/FreeOrion/UI/TechTreeWnd.cpp Modified: trunk/FreeOrion/UI/CUIWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CUIWnd.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/CUIWnd.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -146,7 +146,7 @@ // call to CUIWnd::MinimizedWidth() because MinimizedWidth is virtual SetMinSize(GG::Pt(CUIWnd::MinimizedWidth(), BORDER_TOP + INNER_BORDER_ANGLE_OFFSET + BORDER_BOTTOM + 50)); InitButtons(); - EnableChildClipping(true); + SetChildClippingMode(ClipToClientAndWindowSeparately); } CUIWnd::~CUIWnd() @@ -292,13 +292,15 @@ m_close_button = new CUI_CloseButton(button_ul.x, button_ul.y); GG::Connect(m_close_button->ClickedSignal, &CUIWnd::CloseClicked, this); AttachChild(m_close_button); + m_close_button->NonClientChild(true); } // create the minimize button if (m_minimizable) { m_minimize_button = new CUI_MinRestoreButton(button_ul.x - (m_close_button ? BUTTON_RIGHT_OFFSET : GG::X0), button_ul.y); GG::Connect(m_minimize_button->ClickedSignal, &CUIWnd::MinimizeClicked, this); - AttachChild(m_minimize_button); + AttachChild(m_minimize_button); + m_minimize_button->NonClientChild(true); } } Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -60,7 +60,7 @@ if (!m_ship) throw std::invalid_argument("ShipDataPanel::ShipDataPanel() : Attempted to construct a ShipDataPanel from a null ship pointer."); - EnableChildClipping(); + SetChildClippingMode(ClipToClient); m_ship_name_text = new GG::TextControl(GG::X(Value(h)), GG::Y0, GG::X1, LabelHeight(), m_ship->Name(), ClientUI::GetFont(), @@ -234,7 +234,7 @@ m_ship(ship) { SetName("ShipRow"); - EnableChildClipping(); + SetChildClippingMode(ClipToClient); push_back(new ShipDataPanel(w, h, m_ship)); } Modified: trunk/FreeOrion/UI/DesignWnd.cpp =================================================================== --- trunk/FreeOrion/UI/DesignWnd.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/DesignWnd.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -469,7 +469,7 @@ m_parts_list(0) { //TempUISoundDisabler sound_disabler; // should be redundant with disabler in DesignWnd::DesignWnd. uncomment if this is not the case - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); m_parts_list = new PartsListBox(GG::X0, GG::Y0, GG::X(10), GG::Y(10)); AttachChild(m_parts_list); @@ -1631,7 +1631,7 @@ m_confirm_button(0), m_clear_button(0) { - EnableChildClipping(); + SetChildClippingMode(ClipToClient); boost::shared_ptr<GG::Font> font = ClientUI::GetFont(); @@ -1935,7 +1935,7 @@ m_main_panel(0) { Sound::TempUISoundDisabler sound_disabler; - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); GG::X base_selector_width(300); GG::X most_panels_left = base_selector_width; Modified: trunk/FreeOrion/UI/FleetWnd.cpp =================================================================== --- trunk/FreeOrion/UI/FleetWnd.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/FleetWnd.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -547,7 +547,7 @@ { const Ship* ship = GetObject<Ship>(m_ship_id); - EnableChildClipping(); + SetChildClippingMode(ClipToClient); // ship name text. blank if no ship. TODO: if no ship show "No Ship" or somesuch? std::string ship_name = ""; @@ -823,7 +823,7 @@ m_ship_id(ship_id) { SetName("ShipRow"); - EnableChildClipping(); + SetChildClippingMode(ClipToClient); if (GetObject<Ship>(m_ship_id)) SetDragDropDataType(SHIP_DROP_TYPE_STRING); push_back(new ShipDataPanel(w, h, m_ship_id)); @@ -913,7 +913,7 @@ { const Fleet* fleet = GetObject<Fleet>(m_fleet_id); - EnableChildClipping(); + SetChildClippingMode(ClipToClient); m_fleet_name_text = new GG::TextControl(GG::X0, GG::Y0, GG::X1, LabelHeight(), "", ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_LEFT | GG::FORMAT_VCENTER); @@ -1179,7 +1179,7 @@ m_fleet_id(fleet_id) { SetName("FleetRow"); - EnableChildClipping(); + SetChildClippingMode(ClipToClient); push_back(new FleetDataPanel(w, h, m_fleet_id)); } @@ -1724,7 +1724,7 @@ m_ships_lb(0) { SetName("FleetDetailPanel"); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); m_ships_lb = new ShipsListBox(0, read_only); AttachChild(m_ships_lb); @@ -1922,7 +1922,7 @@ m_fleet_panel = new FleetDetailPanel(GG::X1, GG::Y1, fleet_id, read_only); AttachChild(m_fleet_panel); - EnableChildClipping(false); + SetChildClippingMode(DontClip); SetName(TitleText()); m_fleet_connection = GG::Connect(GetObject<Fleet>(fleet_id)->StateChangedSignal, &FleetDetailWnd::Refresh, this); @@ -2061,7 +2061,6 @@ void FleetWnd::Init(int selected_fleet_id) { - EnableChildClipping(); SetMinSize(GG::Pt(CUIWnd::MinimizedWidth(), BORDER_TOP + INNER_BORDER_ANGLE_OFFSET + BORDER_BOTTOM + ListRowHeight() + 2*GG::Y(PAD))); @@ -2185,7 +2184,6 @@ AddFleet(fleet->ID()); } } - } else { // check all fleets whose IDs are already in m_fleet_ids, removing any that no longer exist. std::set<int> validated_fleet_ids; Modified: trunk/FreeOrion/UI/InfoPanels.cpp =================================================================== --- trunk/FreeOrion/UI/InfoPanels.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/InfoPanels.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -470,7 +470,7 @@ if (!res) throw std::invalid_argument("Attempted to construct a ResourcePanel with an UniverseObject that is not a ResourceCenter"); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); // expand / collapse button at top right m_expand_button = new GG::Button(w - 16, GG::Y0, GG::X(16), GG::Y(16), "", ClientUI::GetFont(), GG::CLR_WHITE, GG::CLR_ZERO, GG::ONTOP | GG::INTERACTIVE); Modified: trunk/FreeOrion/UI/MarkupBox.cpp =================================================================== --- trunk/FreeOrion/UI/MarkupBox.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/MarkupBox.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -289,7 +289,7 @@ m_controls() { SetText(str); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); } MarkupBox::MarkupSurface::MarkupSurface() : @@ -297,7 +297,7 @@ GG::Control(), m_controls() { - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); } MarkupBox::MarkupSurface::~MarkupSurface() { @@ -417,7 +417,7 @@ RegisterMarkupTags(); m_surface = new MarkupSurface(GG::X0 + EDGE_PAD, GG::Y0 + EDGE_PAD, w - 2*EDGE_PAD, h - 2*EDGE_PAD, str); AttachChild(m_surface); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); Refresh(); AdjustScrolls(); VScrolled(0, 0, 0, 0); @@ -432,7 +432,7 @@ RegisterMarkupTags(); m_surface = new MarkupSurface(GG::X0, GG::Y0, GG::X0, GG::Y0, ""); AttachChild(m_surface); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); Refresh(); VScrolled(0, 0, 0, 0); // shouldn't need to adjust scrolls since text is empty Modified: trunk/FreeOrion/UI/ProductionWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ProductionWnd.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/ProductionWnd.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -231,7 +231,7 @@ m_build_designator_wnd = new BuildDesignatorWnd(buid_designator_wnd_size.x, buid_designator_wnd_size.y); m_build_designator_wnd->MoveTo(GG::Pt(m_production_info_panel->Width(), GG::Y0)); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); GG::Connect(m_build_designator_wnd->AddNamedBuildToQueueSignal, &ProductionWnd::AddBuildToQueueSlot, this); GG::Connect(m_build_designator_wnd->AddIDedBuildToQueueSignal, &ProductionWnd::AddBuildToQueueSlot, this); Modified: trunk/FreeOrion/UI/ResearchWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ResearchWnd.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/ResearchWnd.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -204,7 +204,7 @@ AttachChild(m_queue_lb); AttachChild(m_tech_tree_wnd); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); } ResearchWnd::~ResearchWnd() Modified: trunk/FreeOrion/UI/SidePanel.cpp =================================================================== --- trunk/FreeOrion/UI/SidePanel.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/SidePanel.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -1301,7 +1301,7 @@ m_vscroll(new CUIScroll(Width()-14,GG::Y0,GG::X(14),Height(),GG::VERTICAL)) { SetName("PlanetPanelContainer"); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); GG::Connect(m_vscroll->ScrolledSignal, &SidePanel::PlanetPanelContainer::VScroll, this); } Modified: trunk/FreeOrion/UI/SitRepPanel.cpp =================================================================== --- trunk/FreeOrion/UI/SitRepPanel.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/SitRepPanel.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -25,7 +25,7 @@ m_sitreps_lb->SetStyle(GG::LIST_NOSORT); AttachChild(m_sitreps_lb); - EnableChildClipping(false); + SetChildClippingMode(DontClip); Hide(); } Modified: trunk/FreeOrion/UI/TechTreeWnd.cpp =================================================================== --- trunk/FreeOrion/UI/TechTreeWnd.cpp 2010-03-02 20:25:16 UTC (rev 3358) +++ trunk/FreeOrion/UI/TechTreeWnd.cpp 2010-03-03 02:55:04 UTC (rev 3359) @@ -313,7 +313,7 @@ m_tree_view_button->MarkNotSelected(); AttachChild(m_tree_view_button); - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); DoButtonLayout(); Resize(GG::Pt(Width(), MinSize().y)); } @@ -711,7 +711,7 @@ m_tech(tech), m_selected(false) { - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); const Empire* empire = Empires().Lookup(HumanClientApp::GetApp()->EmpireID()); if (empire->TechResearched(m_tech->Name())) { SetColor(ClientUI::KnownTechFillColor()); @@ -958,7 +958,7 @@ // constrain long text that would otherwise overflow planel boundaries - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); // set text box text @@ -1107,7 +1107,7 @@ m_zoom_in_button(0), m_zoom_out_button(0) { - EnableChildClipping(true); + SetChildClippingMode(ClipToClient); m_scale = 1.0 / ZOOM_STEP_SIZE; // because fully zoomed in is too close |
From: <tz...@us...> - 2010-03-07 04:26:33
|
Revision: 3370 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3370&view=rev Author: tzlaine Date: 2010-03-07 04:26:27 +0000 (Sun, 07 Mar 2010) Log Message: ----------- Changed the prototyping-only "Done" button on the combat screen to "End Combat", and added a "Done" button to CombatSetupWnd. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h trunk/FreeOrion/UI/CombatWnd.cpp Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-03-06 20:43:40 UTC (rev 3369) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-03-07 04:26:27 UTC (rev 3370) @@ -5,10 +5,12 @@ #include "../universe/Fleet.h" #include "../universe/Ship.h" #include "../universe/ShipDesign.h" +#include "../util/MultiplayerCommon.h" #include "../util/OptionsDB.h" #include <GG/DrawUtil.h> #include <GG/GUI.h> +#include <GG/Layout.h> #include <OgreEntity.h> #include <OgreMaterialManager.h> @@ -274,6 +276,7 @@ CUIWnd("Ships", GG::X(PAD), GG::GUI::GetGUI()->AppHeight() - SETUP_WND_HEIGHT - GG::Y(PAD), GG::X(300), SETUP_WND_HEIGHT, flags), m_listbox(new CUIListBox(GG::X0, GG::Y0, GG::X1, GG::Y1)), + m_done_button(new CUIButton(GG::X0, GG::Y1, GG::X1, UserString("DONE"))), m_selected_placeable_ship(0), m_placeable_ship_node(0), m_scene_manager(scene_manager), @@ -282,9 +285,16 @@ m_add_ship_node_to_combat_wnd(add_ship_node_to_combat_wnd) { m_listbox->SetStyle(m_listbox->Style() | GG::LIST_SINGLESEL); + Connect(m_done_button->ClickedSignal, &CombatSetupWnd::DoneButtonClicked, this); + m_done_button->Disable(true); + GG::Y original_button_height = m_done_button->Height(); AttachChild(m_listbox); - GridLayout(); + AttachChild(m_done_button); + VerticalLayout(); + GetLayout()->SetRowStretch(0, Value(Height() - original_button_height)); + GetLayout()->SetRowStretch(1, Value(original_button_height)); + GetLayout()->SetCellMargin(2); ObjectMap& objects = GetUniverse().Objects(); const GG::Pt row_size = ListRowSize(); @@ -416,4 +426,12 @@ m_ship_nodes.erase(m_selected_placeable_ship->ID()); m_selected_placeable_ship = 0; m_placeable_ship_node = 0; + + m_done_button->Disable(!m_listbox->Empty()); } + +void CombatSetupWnd::DoneButtonClicked() +{ + // TODO: send a message to the server indicating the combat setup is complete + std::cerr << "Sending message to server.\n"; +} Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-03-06 20:43:40 UTC (rev 3369) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-03-07 04:26:27 UTC (rev 3370) @@ -49,8 +49,10 @@ void PlaceableShipSelected(Ship* ship); void CancelCurrentShipPlacement(); void PlaceCurrentShip(); + void DoneButtonClicked(); CUIListBox* m_listbox; + CUIButton* m_done_button; Ship* m_selected_placeable_ship; Ogre::SceneNode* m_placeable_ship_node; std::map<int, Ogre::Entity*> m_ship_entities; Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-03-06 20:43:40 UTC (rev 3369) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-03-07 04:26:27 UTC (rev 3370) @@ -290,9 +290,8 @@ } // TODO: For prototyping only. - void DoneButtonClicked() + void EndCombatButtonClicked() { - // TODO: send a message to the server indicating the combat setup is complete HumanClientApp::GetApp()->Networking().SendMessage( Message(Message::COMBAT_END, HumanClientApp::GetApp()->PlayerID(), @@ -763,11 +762,10 @@ AttachChild(m_fps_text); - ////////////////////////////////////////////////////////////////// - // NOTE: Below is temporary code for combat system prototyping! // - ////////////////////////////////////////////////////////////////// - if (GetOptionsDB().Get<bool>("tech-demo")) { + ////////////////////////////////////////////////////////////////// + // NOTE: This is temporary code for combat system prototyping! // + ////////////////////////////////////////////////////////////////// int system_id = 0; StarType star_type = STAR_BLUE; std::vector<int> planet_ids(10); @@ -903,14 +901,18 @@ InitCombat(*combat_data); } else { - GG::X width(50); + // TODO: For prototyping only. + GG::X width(150); CUIButton* done_button = - new CUIButton((GG::GUI::GetGUI()->AppWidth() - width) / 2, - GG::GUI::GetGUI()->AppHeight() - GG::Y(20), + new CUIButton(GG::GUI::GetGUI()->AppWidth() - width - GG::X(5), + GG::GUI::GetGUI()->AppHeight() - GG::Y(25), width, - "Done"); - GG::Connect(done_button->ClickedSignal, &DoneButtonClicked); + "End Combat"); + GG::Connect(done_button->ClickedSignal, &EndCombatButtonClicked); AttachChild(done_button); + + // TODO: Add permanent (i.e. not just for prototyping) button for + // combat auto-resolution. } } |
From: <tz...@us...> - 2010-03-07 05:37:49
|
Revision: 3374 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3374&view=rev Author: tzlaine Date: 2010-03-07 05:37:43 +0000 (Sun, 07 Mar 2010) Log Message: ----------- Changed CombatSetupWnd to generate placement combat orders as it places ships, and to hide itself and lock down the CombatWnd after it is done, but before the server has sent the update for the first turn. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/CombatWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-03-07 05:35:57 UTC (rev 3373) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-03-07 05:37:43 UTC (rev 3374) @@ -275,6 +275,7 @@ GG::Flags<GG::WndFlag> flags/* = GG::INTERACTIVE | GG::DRAGABLE*/) : CUIWnd("Ships", GG::X(PAD), GG::GUI::GetGUI()->AppHeight() - SETUP_WND_HEIGHT - GG::Y(PAD), GG::X(300), SETUP_WND_HEIGHT, flags), + m_setup_finished_waiting_for_server(false), m_listbox(new CUIListBox(GG::X0, GG::Y0, GG::X1, GG::Y1)), m_done_button(new CUIButton(GG::X0, GG::Y1, GG::X1, UserString("DONE"))), m_selected_placeable_ship(0), @@ -322,6 +323,10 @@ bool CombatSetupWnd::EventFilter(GG::Wnd* w, const GG::WndEvent& event) { + // Turn off all event handling to lock down CombatWnd. + if (m_setup_finished_waiting_for_server) + return true; + bool retval = false; if (event.Type() == GG::WndEvent::LButtonDown) { if (PlaceableShipNode()) @@ -422,6 +427,12 @@ assert(selections.size() == 1u); m_listbox->Erase(*selections.begin()); + Ogre::Vector3 axes[3]; + m_placeable_ship_node->getOrientation().ToAxes(axes); + m_placement_orders.push_back(CombatOrder(m_selected_placeable_ship->ID(), + ToOpenSteer(m_placeable_ship_node->getPosition()), + ToOpenSteer(axes[1]))); + m_ship_entities.erase(m_selected_placeable_ship->ID()); m_ship_nodes.erase(m_selected_placeable_ship->ID()); m_selected_placeable_ship = 0; @@ -432,6 +443,14 @@ void CombatSetupWnd::DoneButtonClicked() { - // TODO: send a message to the server indicating the combat setup is complete - std::cerr << "Sending message to server.\n"; +#if 0 // TODO + HumanClientApp::GetApp()->Networking().SendMessage( + CombatTurnOrdersMessage( + HumanClientApp::GetApp()->PlayerID(), + m_placement_orders)); +#endif + + m_setup_finished_waiting_for_server = true; + m_done_button->Disable(true); + Hide(); } Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-03-07 05:35:57 UTC (rev 3373) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-03-07 05:37:43 UTC (rev 3374) @@ -4,6 +4,7 @@ #include "CUIControls.h" #include "CUIWnd.h" +#include "../combat/CombatOrder.h" namespace Ogre { @@ -51,6 +52,9 @@ void PlaceCurrentShip(); void DoneButtonClicked(); + CombatOrderSet m_placement_orders; + bool m_setup_finished_waiting_for_server; + CUIListBox* m_listbox; CUIButton* m_done_button; Ship* m_selected_placeable_ship; Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-03-07 05:35:57 UTC (rev 3373) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-03-07 05:37:43 UTC (rev 3374) @@ -193,9 +193,6 @@ OpenSteer::Vec3 ToOpenSteer(const btVector3& vec) { return OpenSteer::Vec3(vec.x(), vec.y(), vec.z()); } - OpenSteer::Vec3 ToOpenSteer(const Ogre::Vector3& vec) - { return OpenSteer::Vec3(vec.x, vec.y, vec.z); } - struct RayIntersectionHit { RayIntersectionHit() : m_object(0) {} @@ -2149,3 +2146,6 @@ entity->setMaterialName(material->getName()); return entity; } + +OpenSteer::Vec3 ToOpenSteer(const Ogre::Vector3& vec) +{ return OpenSteer::Vec3(vec.x, vec.y, vec.z); } Modified: trunk/FreeOrion/UI/CombatWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatWnd.h 2010-03-07 05:35:57 UTC (rev 3373) +++ trunk/FreeOrion/UI/CombatWnd.h 2010-03-07 05:37:43 UTC (rev 3374) @@ -20,10 +20,15 @@ class RaySceneQuery; class SceneManager; class SceneNode; + class Vector3; class Viewport; class PlaneBoundedVolumeListSceneQuery; } +namespace OpenSteer { + class Vec3; +} + namespace GG { class Texture; } @@ -246,5 +251,6 @@ Ogre::SceneNode* CreateShipSceneNode(Ogre::SceneManager* scene_manager, const Ship& ship); Ogre::Entity* CreateShipEntity(Ogre::SceneManager* scene_manager, const Ship& ship, const Ogre::MaterialPtr& material); +OpenSteer::Vec3 ToOpenSteer(const Ogre::Vector3& vec); #endif |
From: <geo...@us...> - 2010-03-08 10:16:22
|
Revision: 3380 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3380&view=rev Author: geoffthemedio Date: 2010-03-08 10:16:16 +0000 (Mon, 08 Mar 2010) Log Message: ----------- Added (partly by uncommenting existing code) zoom slider on map, which can be dragged up and down to zoom the map, and which slides itself in response to mousewheel zooms of the map. The slider tab is double-rendered for me, however, which needs to be fixed. Modified Paths: -------------- trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/UI/MapWnd.h Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2010-03-08 08:13:51 UTC (rev 3379) +++ trunk/FreeOrion/UI/MapWnd.cpp 2010-03-08 10:16:16 UTC (rev 3380) @@ -614,19 +614,18 @@ m_scale_line = new MapScaleLine(m_turn_update->UpperLeft().x, m_turn_update->LowerRight().y + GG::Y(LAYOUT_MARGIN), SCALE_LINE_MAX_WIDTH, SCALE_LINE_HEIGHT); m_toolbar->AttachChild(m_scale_line); - GG::Connect(this->ZoomedSignal, &MapScaleLine::Update, m_scale_line); m_scale_line->Update(ZoomFactor()); // Zoom slider - //const int ZOOM_SLIDER_MIN = static_cast<int>(ZOOM_IN_MIN_STEPS), - // ZOOM_SLIDER_MAX = static_cast<int>(ZOOM_IN_MAX_STEPS); - //m_zoom_slider = new CUISlider(m_turn_update->UpperLeft().x, m_scale_line->LowerRight().y + GG::Y(LAYOUT_MARGIN), - // GG::X(ClientUI::ScrollWidth()), ZOOM_SLIDER_HEIGHT, - // ZOOM_SLIDER_MIN, ZOOM_SLIDER_MAX, GG::VERTICAL); - ////m_zoom_slider->SizeSlider(ZOOM_SLIDER_MIN, ZOOM_SLIDER_MAX); - //m_toolbar->AttachChild(m_zoom_slider); - //GG::Connect(m_zoom_slider->SlidSignal, &MapWnd::ZoomSlid, this); + const int ZOOM_SLIDER_MIN = static_cast<int>(ZOOM_IN_MIN_STEPS), + ZOOM_SLIDER_MAX = static_cast<int>(ZOOM_IN_MAX_STEPS); + m_zoom_slider = new CUISlider(m_turn_update->UpperLeft().x, m_scale_line->LowerRight().y + GG::Y(LAYOUT_MARGIN), + GG::X(ClientUI::ScrollWidth()), ZOOM_SLIDER_HEIGHT, + ZOOM_SLIDER_MIN, ZOOM_SLIDER_MAX, GG::VERTICAL); + m_zoom_slider->SlideTo(m_zoom_steps_in); + m_toolbar->AttachChild(m_zoom_slider); + GG::Connect(m_zoom_slider->SlidSignal, &MapWnd::ZoomSlid, this); // Subscreen / Menu buttons (placed right to left) @@ -2566,10 +2565,10 @@ // increment zoom steps in by delta steps double new_zoom_steps_in = m_zoom_steps_in + static_cast<double>(delta); - SetZoom(new_zoom_steps_in); + SetZoom(new_zoom_steps_in, true); } -void MapWnd::SetZoom(double steps_in) +void MapWnd::SetZoom(double steps_in, bool update_slide) { // impose range limits on zoom steps double new_steps_in = std::max(std::min(steps_in, ZOOM_IN_MAX_STEPS), ZOOM_IN_MIN_STEPS); @@ -2633,12 +2632,17 @@ MoveTo(move_to_pt - GG::Pt(GG::GUI::GetGUI()->AppWidth(), GG::GUI::GetGUI()->AppHeight())); + if (m_scale_line) + m_scale_line->Update(ZoomFactor()); + if (update_slide&& m_zoom_slider) + m_zoom_slider->SlideTo(m_zoom_steps_in); + ZoomedSignal(ZoomFactor()); } void MapWnd::ZoomSlid(int pos, int low, int high) { - SetZoom(static_cast<double>(pos)); + SetZoom(static_cast<double>(pos), false); } void MapWnd::RenderStarfields() Modified: trunk/FreeOrion/UI/MapWnd.h =================================================================== --- trunk/FreeOrion/UI/MapWnd.h 2010-03-08 08:13:51 UTC (rev 3379) +++ trunk/FreeOrion/UI/MapWnd.h 2010-03-08 10:16:16 UTC (rev 3380) @@ -189,7 +189,7 @@ void Zoom(int delta); //!< changes the zoom level of the main map by zoom step size to the power of \a delta (adds delta to the current zoom exponent) void ZoomSlid(int pos, int low, int high); - void SetZoom(double steps_in); //!< sets zoom level of the main map to zoom step size to the power of \a steps_in + void SetZoom(double steps_in, bool update_slide);//!< sets zoom level of the main map to zoom step size to the power of \a steps_in and updates zoom slider position if \a update_slide is true void RefreshFleetButtons(); //!< removes old / existing and creates new fleet buttons void RefreshFleetButtonSelectionIndicators(); //!< marks (only) selected fleets' buttons as selected |
From: <tz...@us...> - 2010-03-10 04:46:32
|
Revision: 3382 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3382&view=rev Author: tzlaine Date: 2010-03-10 04:46:25 +0000 (Wed, 10 Mar 2010) Log Message: ----------- Fixed wierd double-clicking behavior in CombatWnd. Now, the double click point must be within some small distance of the (previous, first) click point to be counted. Previously, clicking on one side of the screen and then the other inrapid succession would cause a recenter. Modified Paths: -------------- trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/CombatWnd.h Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-03-09 06:50:12 UTC (rev 3381) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-03-10 04:46:25 UTC (rev 3382) @@ -441,6 +441,13 @@ std::string ShipMeshName(const Ship& ship) { return ship.Design()->Model() + ".mesh"; } + bool CloseTo(const GG::Pt& p1, const GG::Pt& p2) + { + const int EPSILON = 5; + int delta = std::abs(Value(p1.x - p2.x)) + std::abs(Value(p1.y - p2.y)); + return delta < EPSILON; + } + void AddOptions(OptionsDB& db) { db.AddFlag("tech-demo", "OPTIONS_DB_TECH_DEMO", false); @@ -649,6 +656,7 @@ m_pitch(0.0), m_roll(0.0), m_last_pos(), + m_last_click_pos(), m_selection_drag_start(INVALID_SELECTION_DRAG_POS), m_selection_drag_stop(INVALID_SELECTION_DRAG_POS), m_mouse_dragged(false), @@ -1401,11 +1409,14 @@ DeselectAll(); } } + m_last_click_pos = pt; } void CombatWnd::LDoubleClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys) { - if (!m_mouse_dragged && !m_camera_animation->hasNodeTrack(LOOKAT_NODE_TRACK_HANDLE)) { + if (!m_mouse_dragged && + CloseTo(pt, m_last_click_pos) && + !m_camera_animation->hasNodeTrack(LOOKAT_NODE_TRACK_HANDLE)) { if (Ogre::MovableObject* movable_object = GetObjectUnderPt(pt)) { Ogre::SceneNode* clicked_scene_node = movable_object->getParentSceneNode(); assert(clicked_scene_node); @@ -1416,6 +1427,7 @@ LookAt(intersection.second); } } + m_last_click_pos = GG::Pt(); } void CombatWnd::MButtonDown(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys) Modified: trunk/FreeOrion/UI/CombatWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatWnd.h 2010-03-09 06:50:12 UTC (rev 3381) +++ trunk/FreeOrion/UI/CombatWnd.h 2010-03-10 04:46:25 UTC (rev 3382) @@ -175,6 +175,7 @@ Ogre::Radian m_pitch; Ogre::Radian m_roll; GG::Pt m_last_pos; + GG::Pt m_last_click_pos; GG::Pt m_selection_drag_start; GG::Pt m_selection_drag_stop; bool m_mouse_dragged; |
From: <tz...@us...> - 2010-03-10 05:08:55
|
Revision: 3383 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3383&view=rev Author: tzlaine Date: 2010-03-10 05:08:49 +0000 (Wed, 10 Mar 2010) Log Message: ----------- Changed the mouse handling logic in CombatSetupWnd slightly to more closely resemble that in CombatWnd. This fixes the bug in which a left button drag and release would act as a click on an object. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-03-10 04:46:25 UTC (rev 3382) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-03-10 05:08:49 UTC (rev 3383) @@ -285,6 +285,7 @@ m_dragging_placed_ship(false), m_button_press_on_placed_ship(INVALID_PRESS_POS), m_button_press_placed_ship_node(0), + m_mouse_dragged(false), m_listbox(new CUIListBox(GG::X0, GG::Y0, GG::X1, GG::Y1)), m_done_button(new CUIButton(GG::X0, GG::Y1, GG::X1, UserString("DONE"))), m_selected_placeable_ship(0), @@ -349,6 +350,7 @@ retval = true; } m_dragging_placed_ship = false; + m_mouse_dragged = false; } else if (event.Type() == GG::WndEvent::LDrag) { HandleMouseMoves(event.Point()); if (m_button_press_placed_ship_node) { @@ -369,13 +371,17 @@ } } retval = true; + m_mouse_dragged = true; } else if (event.Type() == GG::WndEvent::LButtonUp) { m_button_press_placed_ship_node = 0; + m_mouse_dragged = false; } else if (event.Type() == GG::WndEvent::LClick) { Ogre::SceneNode* placement_node = 0; if ((placement_node = PlaceableShipNode()) && IsVisible(*placement_node)) { PlaceCurrentShip(); retval = true; + } else if (m_mouse_dragged) { + retval = true; } m_button_press_placed_ship_node = 0; } else if (event.Type() == GG::WndEvent::RClick) { Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-03-10 04:46:25 UTC (rev 3382) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-03-10 05:08:49 UTC (rev 3383) @@ -62,6 +62,7 @@ bool m_dragging_placed_ship; GG::Pt m_button_press_on_placed_ship; Ogre::SceneNode* m_button_press_placed_ship_node; + bool m_mouse_dragged; CUIListBox* m_listbox; CUIButton* m_done_button; |
From: <geo...@us...> - 2010-03-22 08:22:38
|
Revision: 3396 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3396&view=rev Author: geoffthemedio Date: 2010-03-22 08:22:32 +0000 (Mon, 22 Mar 2010) Log Message: ----------- Implemented feature request 2965079 : More useful behavior when clicking on queued tech, which involved making clicking on techs on the queue show that tech in the encyclopedia panel, in addition to centring the tree on the tech. Modified Paths: -------------- trunk/FreeOrion/UI/ResearchWnd.cpp trunk/FreeOrion/UI/TechTreeWnd.cpp trunk/FreeOrion/UI/TechTreeWnd.h Modified: trunk/FreeOrion/UI/ResearchWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ResearchWnd.cpp 2010-03-22 03:46:57 UTC (rev 3395) +++ trunk/FreeOrion/UI/ResearchWnd.cpp 2010-03-22 08:22:32 UTC (rev 3396) @@ -338,7 +338,13 @@ void ResearchWnd::QueueItemClickedSlot(GG::ListBox::iterator it, const GG::Pt& pt) { - m_tech_tree_wnd->CenterOnTech(boost::polymorphic_downcast<QueueRow*>(*it)->tech); + const Tech* tech = boost::polymorphic_downcast<QueueRow*>(*it)->tech; + if (!tech) { + Logger().errorStream() << "ResearchWnd::QueueItemClickedSlot couldn't get tech from clicked row"; + return; + } + m_tech_tree_wnd->CenterOnTech(tech); + m_tech_tree_wnd->SetEncyclopediaTech(tech); } void ResearchWnd::QueueItemDoubleClickedSlot(GG::ListBox::iterator it) Modified: trunk/FreeOrion/UI/TechTreeWnd.cpp =================================================================== --- trunk/FreeOrion/UI/TechTreeWnd.cpp 2010-03-22 03:46:57 UTC (rev 3395) +++ trunk/FreeOrion/UI/TechTreeWnd.cpp 2010-03-22 08:22:32 UTC (rev 3396) @@ -2146,7 +2146,7 @@ void TechTreeWnd::Clear() { - m_tech_navigator->SetTech(0); + m_tech_navigator->SetTech(0); m_enc_detail_panel->UnsetAll(); m_layout_panel->Clear(); } @@ -2335,6 +2335,11 @@ m_layout_panel->CenterOnTech(tech); } +void TechTreeWnd::SetEncyclopediaTech(const Tech* tech) +{ + m_enc_detail_panel->SetItem(tech); +} + void TechTreeWnd::TechBrowsedSlot(const Tech* tech) { TechBrowsedSignal(tech); @@ -2343,7 +2348,7 @@ void TechTreeWnd::TechClickedSlot(const Tech* tech) { m_tech_navigator->SetTech(tech); - m_enc_detail_panel->SetItem(tech); + SetEncyclopediaTech(tech); TechSelectedSignal(tech); } Modified: trunk/FreeOrion/UI/TechTreeWnd.h =================================================================== --- trunk/FreeOrion/UI/TechTreeWnd.h 2010-03-22 03:46:57 UTC (rev 3395) +++ trunk/FreeOrion/UI/TechTreeWnd.h 2010-03-22 08:22:32 UTC (rev 3396) @@ -56,6 +56,7 @@ void ShowListView(); void CenterOnTech(const Tech* tech); + void SetEncyclopediaTech(const Tech* tech); //@} static const GG::Y NAVIGATOR_AND_DETAIL_HEIGHT; |
From: <geo...@us...> - 2010-03-29 00:19:25
|
Revision: 3409 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3409&view=rev Author: geoffthemedio Date: 2010-03-29 00:19:17 +0000 (Mon, 29 Mar 2010) Log Message: ----------- -Undid revision 3408 which switched headers to use the "lousy PNG loader" in boost from the customized one in GG. -Undid revision 3395 which removed windowed mode resolution spinners. Just because GCC says the variable is unused doesn't mean that assigning it a value didn't have important side effects. Revision Links: -------------- http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3408&view=rev http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3395&view=rev Modified Paths: -------------- trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/OptionsWnd.cpp Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-03-27 18:01:47 UTC (rev 3408) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-03-29 00:19:17 UTC (rev 3409) @@ -52,8 +52,8 @@ #include <btBulletCollisionCommon.h> #include <GG/GUI.h> -#include "boost/gil/image.hpp" -#include "boost/gil/extension/io/png_dynamic_io.hpp" +#include "../GG/src/GIL/image.hpp" +#include "../GG/src/GIL/extension/io/png_dynamic_io.hpp" #include <boost/cast.hpp> #include <boost/algorithm/string/case_conv.hpp> Modified: trunk/FreeOrion/UI/OptionsWnd.cpp =================================================================== --- trunk/FreeOrion/UI/OptionsWnd.cpp 2010-03-27 18:01:47 UTC (rev 3408) +++ trunk/FreeOrion/UI/OptionsWnd.cpp 2010-03-29 00:19:17 UTC (rev 3409) @@ -637,6 +637,9 @@ row->push_back(new RowContentsWnd(row->Width(), row->Height(), windowed_spinner_label, m_indentation_level)); m_current_option_list->Insert(row); + IntOption("app-width-windowed", UserString("OPTIONS_APP_WIDTH_WINDOWED")); + IntOption("app-height-windowed", UserString("OPTIONS_APP_HEIGHT_WINDOWED")); + // fps BoolOption("show-fps", UserString("OPTIONS_SHOW_FPS")); |
From: <tz...@us...> - 2010-04-05 21:08:44
|
Revision: 3428 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3428&view=rev Author: tzlaine Date: 2010-04-05 21:08:37 +0000 (Mon, 05 Apr 2010) Log Message: ----------- Modified CombatSetupWnd to show more info about the fleets it shows (Fleet name and system arrived from, if appropriate). This will be useful when placement regions are taken into account by CombatSetupWnd. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h trunk/FreeOrion/UI/CombatWnd.cpp Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-05 21:06:19 UTC (rev 3427) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-05 21:08:37 UTC (rev 3428) @@ -230,33 +230,55 @@ boost::signals::connection m_ship_connection; }; + // End of cut-and-pasted stuff + class ShipRow : public GG::ListBox::Row { public: - ShipRow(Ship* ship, GG::X w, GG::Y h) : + ShipRow(Ship* ship, Fleet* fleet, GG::X w, GG::Y h) : GG::ListBox::Row(w, h, ""), m_ship(ship) { SetName("ShipRow"); SetChildClippingMode(ClipToClient); - push_back(new ShipDataPanel(w, h, m_ship)); + + std::vector<GG::X> widths(3); + widths[0] = GG::X(275); + widths[1] = (w - widths[0]) / 2; + widths[2] = w - widths[0] - widths[1]; + + push_back(new ShipDataPanel(widths[0], h, m_ship)); + + const std::string& fleet_name = fleet->Name(); + push_back(new GG::TextControl(GG::X0, GG::Y0, widths[1], h, fleet_name, + ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_LEFT)); + + std::string arrival_starlane = "Present"; + if (fleet->ArrivedThisTurn()) + arrival_starlane = "From " + GetObject(fleet->ArrivalStarlane())->Name(); + push_back(new GG::TextControl(GG::X0, GG::Y0, widths[2], h, arrival_starlane, + ClientUI::GetFont(), ClientUI::TextColor(), GG::FORMAT_LEFT)); + + assert(widths[0] != ColWidth(0)); + assert(widths[1] != ColWidth(1)); + assert(widths[2] != ColWidth(2)); + SetColWidths(widths); } - void SizeMove(const GG::Pt& ul, const GG::Pt& lr) { - const GG::Pt old_size = Size(); - GG::ListBox::Row::SizeMove(ul, lr); - //std::cout << "ShipRow::SizeMove size: (" << Value(Width()) << ", " << Value(Height()) << ")" << std::endl; - if (!empty() && old_size != Size()) - at(0)->Resize(Size()); - } + void SizeMove(const GG::Pt& ul, const GG::Pt& lr) + { + const GG::Pt old_size = Size(); + GG::ListBox::Row::SizeMove(ul, lr); + if (!empty() && old_size != Size()) + at(0)->Resize(Size()); + } - int ShipID() const {return m_ship->ID();} + int ShipID() const + { return m_ship->ID(); } - Ship* const m_ship; + Ship* const m_ship; }; - // End of cut-and-pasted stuff - const GG::Y SETUP_WND_HEIGHT(250); // HACK! This must be kept in synch with CombatWnd.cpp. @@ -268,6 +290,7 @@ std::vector<Fleet*> fleets, const std::vector<CombatSetupGroup>& setup_groups, CombatWnd* combat_wnd, + CombatData* combat_data, Ogre::SceneManager* scene_manager, boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt& pt)> intersect_mouse_with_ecliptic, @@ -281,7 +304,7 @@ reposition_ship_node, GG::Flags<GG::WndFlag> flags/* = GG::INTERACTIVE | GG::DRAGABLE*/) : CUIWnd("Ships", GG::X(PAD), GG::GUI::GetGUI()->AppHeight() - SETUP_WND_HEIGHT - GG::Y(PAD), - GG::X(300), SETUP_WND_HEIGHT, flags), + GG::X(500), SETUP_WND_HEIGHT, flags), m_setup_groups(setup_groups), m_setup_finished_waiting_for_server(false), m_dragging_placed_ship(false), @@ -293,6 +316,7 @@ m_selected_placeable_ship(0), m_placeable_ship_node(0), m_scene_manager(scene_manager), + m_combat_data(combat_data), m_intersect_mouse_with_ecliptic(intersect_mouse_with_ecliptic), m_get_ship_material(get_ship_material), m_add_ship_node_to_combat_wnd(add_ship_node_to_combat_wnd), @@ -311,14 +335,15 @@ GetLayout()->SetRowStretch(1, Value(original_button_height)); GetLayout()->SetCellMargin(2); - ObjectMap& objects = GetUniverse().Objects(); const GG::Pt row_size = ListRowSize(); for (std::size_t i = 0; i < fleets.size(); ++i) { for (Fleet::const_iterator it = fleets[i]->begin(); it != fleets[i]->end(); ++it) { - ShipRow* row = new ShipRow(objects.Object<Ship>(*it), GG::X1, row_size.y); + UniverseObject* o = m_combat_data->m_combat_universe[*it]; + assert(universe_object_cast<Ship*>(o)); + Ship* ship = static_cast<Ship*>(o); + ShipRow* row = new ShipRow(ship, fleets[i], row_size.x, row_size.y); m_listbox->Insert(row); - row->Resize(row_size); } } Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-05 21:06:19 UTC (rev 3427) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-05 21:08:37 UTC (rev 3428) @@ -19,6 +19,7 @@ struct CombatSetupGroup; class CombatWnd; +struct CombatData; class Fleet; class Ship; class ShipDesign; @@ -30,6 +31,7 @@ CombatSetupWnd(std::vector<Fleet*> fleets, const std::vector<CombatSetupGroup>& setup_groups, CombatWnd* combat_wnd, + CombatData* combat_data, Ogre::SceneManager* scene_manager, boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt&)> intersect_mouse_with_ecliptic, @@ -74,6 +76,7 @@ std::map<int, Ogre::Entity*> m_ship_entities; std::map<int, Ogre::SceneNode*> m_ship_nodes; Ogre::SceneManager* m_scene_manager; + CombatData* m_combat_data; boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt& pt)> m_intersect_mouse_with_ecliptic; Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-05 21:06:19 UTC (rev 3427) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-05 21:08:37 UTC (rev 3428) @@ -1194,7 +1194,7 @@ } } m_combat_setup_wnd = - new CombatSetupWnd(fleets, setup_groups, this, m_scene_manager, + new CombatSetupWnd(fleets, setup_groups, this, m_combat_data, m_scene_manager, boost::bind(&CombatWnd::IntersectMouseWithEcliptic, this, _1), boost::bind(&CombatWnd::GetShipMaterial, this, _1), boost::bind(&CombatWnd::AddShipNode, this, _1, _2, _3, _4), |
From: <tz...@us...> - 2010-04-06 16:07:16
|
Revision: 3429 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3429&view=rev Author: tzlaine Date: 2010-04-06 16:07:10 +0000 (Tue, 06 Apr 2010) Log Message: ----------- Slightly modified the data passed to CombatSetupWnd to suit its needs a bit better. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h trunk/FreeOrion/UI/CombatWnd.cpp Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-05 21:08:37 UTC (rev 3428) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-06 16:07:10 UTC (rev 3429) @@ -287,7 +287,6 @@ } CombatSetupWnd::CombatSetupWnd( - std::vector<Fleet*> fleets, const std::vector<CombatSetupGroup>& setup_groups, CombatWnd* combat_wnd, CombatData* combat_data, @@ -316,7 +315,7 @@ m_selected_placeable_ship(0), m_placeable_ship_node(0), m_scene_manager(scene_manager), - m_combat_data(combat_data), + m_combat_universe(combat_data->m_combat_universe), m_intersect_mouse_with_ecliptic(intersect_mouse_with_ecliptic), m_get_ship_material(get_ship_material), m_add_ship_node_to_combat_wnd(add_ship_node_to_combat_wnd), @@ -337,12 +336,17 @@ const GG::Pt row_size = ListRowSize(); - for (std::size_t i = 0; i < fleets.size(); ++i) { - for (Fleet::const_iterator it = fleets[i]->begin(); it != fleets[i]->end(); ++it) { - UniverseObject* o = m_combat_data->m_combat_universe[*it]; + for (std::size_t i = 0; i < m_setup_groups.size(); ++i) { + for (std::set<int>::const_iterator it = m_setup_groups[i].m_ships.begin(); + it != m_setup_groups[i].m_ships.end(); + ++it) { + UniverseObject* o = m_combat_universe[*it]; assert(universe_object_cast<Ship*>(o)); Ship* ship = static_cast<Ship*>(o); - ShipRow* row = new ShipRow(ship, fleets[i], row_size.x, row_size.y); + o = m_combat_universe[ship->FleetID()]; + assert(universe_object_cast<Fleet*>(o)); + Fleet* fleet = static_cast<Fleet*>(o); + ShipRow* row = new ShipRow(ship, fleet, row_size.x, row_size.y); m_listbox->Insert(row); } } Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-05 21:08:37 UTC (rev 3428) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-06 16:07:10 UTC (rev 3429) @@ -23,13 +23,13 @@ class Fleet; class Ship; class ShipDesign; +class UniverseObject; class CombatSetupWnd : public CUIWnd { public: - CombatSetupWnd(std::vector<Fleet*> fleets, - const std::vector<CombatSetupGroup>& setup_groups, + CombatSetupWnd(const std::vector<CombatSetupGroup>& setup_groups, CombatWnd* combat_wnd, CombatData* combat_data, Ogre::SceneManager* scene_manager, @@ -76,7 +76,7 @@ std::map<int, Ogre::Entity*> m_ship_entities; std::map<int, Ogre::SceneNode*> m_ship_nodes; Ogre::SceneManager* m_scene_manager; - CombatData* m_combat_data; + std::map<int, UniverseObject*> m_combat_universe; boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt& pt)> m_intersect_mouse_with_ecliptic; Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-05 21:08:37 UTC (rev 3428) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-06 16:07:10 UTC (rev 3429) @@ -1181,20 +1181,8 @@ // TODO } - // TODO: For prototyping only! - std::vector<Fleet*> fleets; - for (std::map<int, UniverseObject*>::iterator it = - m_combat_data->m_combat_universe.begin(); - it != m_combat_data->m_combat_universe.end(); - ++it) { - if (Fleet* fleet = universe_object_cast<Fleet*>(it->second)) { - if (fleet->Owners().size() == 1u && - *fleet->Owners().begin() == HumanClientApp::GetApp()->PlayerID()) - fleets.push_back(fleet); - } - } m_combat_setup_wnd = - new CombatSetupWnd(fleets, setup_groups, this, m_combat_data, m_scene_manager, + new CombatSetupWnd(setup_groups, this, m_combat_data, m_scene_manager, boost::bind(&CombatWnd::IntersectMouseWithEcliptic, this, _1), boost::bind(&CombatWnd::GetShipMaterial, this, _1), boost::bind(&CombatWnd::AddShipNode, this, _1, _2, _3, _4), |
From: <tz...@us...> - 2010-04-06 18:38:19
|
Revision: 3430 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3430&view=rev Author: tzlaine Date: 2010-04-06 18:38:13 +0000 (Tue, 06 Apr 2010) Log Message: ----------- First pass at CombatSetupWnd placement region indicators. Only ELLIPSE regions are currently implemented. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-06 16:07:10 UTC (rev 3429) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-06 18:38:13 UTC (rev 3430) @@ -14,6 +14,7 @@ #include <OgreEntity.h> #include <OgreMaterialManager.h> +#include <OgreMeshManager.h> #include <OgreSceneManager.h> #include <boost/cast.hpp> @@ -21,6 +22,11 @@ namespace { + const GG::Y SETUP_WND_HEIGHT(250); + + // HACK! This must be kept in synch with CombatWnd.cpp. + const Ogre::uint32 REGULAR_OBJECTS_MASK = 1 << 0; + // HACK! These functions and classes were cut-and-pasted from FleetWnd. // If they continue to be used without modification, move them into a // common location. @@ -279,11 +285,88 @@ Ship* const m_ship; }; - const GG::Y SETUP_WND_HEIGHT(250); + Ogre::SceneNode* CreatePlacementRegionNode(Ogre::SceneManager* scene_manager, + const CombatSetupRegion& region, + bool allow, + std::size_t group_index, + std::size_t region_index) + { + Ogre::SceneNode* retval = 0; - // HACK! This must be kept in synch with CombatWnd.cpp. - const Ogre::uint32 REGULAR_OBJECTS_MASK = 1 << 0; + const int SLICES = 100; + static std::vector<Ogre::Vector3> unit_circle_vertices; + if (unit_circle_vertices.empty()) { + unit_circle_vertices.resize(SLICES); + const double INCR = 2.0 * Ogre::Math::PI / SLICES; + for (std::size_t i = 0; i < unit_circle_vertices.size(); ++i) { + double theta = i * INCR; + unit_circle_vertices[i].x = std::cos(theta); + unit_circle_vertices[i].y = std::sin(theta); + unit_circle_vertices[i].z = 0.0; + } + } + const std::string UNIT_CIRCLE_MESH_NAME = std::string(allow ? "allow" : "deny") + "_unit_circle_mesh"; + const Ogre::ColourValue COLOR(allow ? 0.0 : 1.0, allow ? 1.0 : 0.0, 0.0, 0.5); + + Ogre::MeshPtr unit_circle_mesh = Ogre::MeshManager::getSingleton().getByName("unit_circle_mesh"); + //Ogre::ManualObject* manual_object = new Ogre::ManualObject(); + + std::string base_name = + boost::lexical_cast<std::string>(group_index) + "_" + + boost::lexical_cast<std::string>(region_index) + "_"; + retval = scene_manager->getRootSceneNode()->createChildSceneNode(base_name + "node"); + + switch (region.m_type) { + case CombatSetupRegion::RING: { + break; + } + + case CombatSetupRegion::ELLIPSE: { + if (unit_circle_mesh.isNull()) { + Ogre::ManualObject manual_object(""); + manual_object.estimateVertexCount(unit_circle_vertices.size()); + manual_object.begin("", Ogre::RenderOperation::OT_TRIANGLE_FAN); + manual_object.position(0.0, 0.0, 0.0); + manual_object.colour(COLOR); + for (std::size_t i = 0; i < unit_circle_vertices.size(); ++i) { + manual_object.position(unit_circle_vertices[i]); + manual_object.colour(COLOR); + } + manual_object.position(unit_circle_vertices[0]); + manual_object.colour(COLOR); + manual_object.end(); + unit_circle_mesh = manual_object.convertToMesh(UNIT_CIRCLE_MESH_NAME); + } + Ogre::Entity* entity = scene_manager->createEntity(base_name + "entity", UNIT_CIRCLE_MESH_NAME); + entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); + entity->setMaterialName("effects/area"); + retval->attachObject(entity); + retval->setPosition(region.m_centroid[0], region.m_centroid[1], 0.0); + retval->setScale(region.m_radial_axis, region.m_tangent_axis, 1.0); + // if non-circular, rotate + if (region.m_radial_axis != region.m_tangent_axis) { + retval->setOrientation( + Ogre::Quaternion(Ogre::Radian(std::atan2(region.m_centroid[1], region.m_centroid[0])), + Ogre::Vector3(0.0, 0.0, 1.0))); + } + break; + } + + case CombatSetupRegion::PARTIAL_ELLIPSE: { + break; + } + } + + return retval; + } + + void SetRegionNodesVisibility(const std::vector<Ogre::SceneNode*>& nodes, bool visible) + { + for (std::size_t i = 0; i < nodes.size(); ++i) { + nodes[i]->setVisible(visible); + } + } } CombatSetupWnd::CombatSetupWnd( @@ -305,6 +388,7 @@ CUIWnd("Ships", GG::X(PAD), GG::GUI::GetGUI()->AppHeight() - SETUP_WND_HEIGHT - GG::Y(PAD), GG::X(500), SETUP_WND_HEIGHT, flags), m_setup_groups(setup_groups), + m_current_setup_group(m_setup_groups.size()), m_setup_finished_waiting_for_server(false), m_dragging_placed_ship(false), m_button_press_on_placed_ship(INVALID_PRESS_POS), @@ -463,10 +547,12 @@ assert(sels.size() <= 1u); if (sels.empty()) { PlaceableShipSelected(0); + UpdatePlacementIndicators(0); } else { GG::ListBox::Row* row = **sels.begin(); ShipRow* ship_row = boost::polymorphic_downcast<ShipRow*>(row); PlaceableShipSelected(const_cast<Ship*>(ship_row->m_ship)); + UpdatePlacementIndicators(ship_row->m_ship); } } @@ -493,6 +579,37 @@ } } +void CombatSetupWnd::UpdatePlacementIndicators(const Ship* ship) +{ + if (m_selected_placeable_ship) { + for (std::size_t i = 0; i < m_setup_groups.size(); ++i) { + if (m_setup_groups[i].m_ships.find(m_selected_placeable_ship->ID()) != + m_setup_groups[i].m_ships.end()) { + if (m_current_setup_group != i) { + if (m_current_setup_group < m_setup_groups.size()) + SetRegionNodesVisibility(m_region_nodes_by_setup_group[m_current_setup_group], false); + if (m_region_nodes_by_setup_group.find(i) != m_region_nodes_by_setup_group.end()) { + SetRegionNodesVisibility(m_region_nodes_by_setup_group[i], true); + } else { + CombatSetupGroup& group = m_setup_groups[i]; + for (std::size_t j = 0; j < group.m_regions.size(); ++j) { + Ogre::SceneNode* node = + CreatePlacementRegionNode(m_scene_manager, group.m_regions[j], + group.m_allow, i, j); + m_region_nodes_by_setup_group[i].push_back(node); + } + } + m_current_setup_group = i; + } + break; + } + } + } else { + if (m_current_setup_group < m_setup_groups.size()) + SetRegionNodesVisibility(m_region_nodes_by_setup_group[m_current_setup_group], false); + } +} + void CombatSetupWnd::CancelCurrentShipPlacement() { m_selected_placeable_ship = 0; Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-06 16:07:10 UTC (rev 3429) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-06 18:38:13 UTC (rev 3430) @@ -57,11 +57,14 @@ void CreateCombatOrder(int ship_id, Ogre::SceneNode* node); void PlaceableShipSelected_(const GG::ListBox::SelectionSet& sels); void PlaceableShipSelected(Ship* ship); + void UpdatePlacementIndicators(const Ship* ship); void CancelCurrentShipPlacement(); void PlaceCurrentShip(); void DoneButtonClicked(); std::vector<CombatSetupGroup> m_setup_groups; + std::map<std::size_t, std::vector<Ogre::SceneNode*> > m_region_nodes_by_setup_group; + std::size_t m_current_setup_group; std::map<int, CombatOrder> m_placement_orders; bool m_setup_finished_waiting_for_server; bool m_dragging_placed_ship; |
From: <tz...@us...> - 2010-04-06 20:41:16
|
Revision: 3434 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3434&view=rev Author: tzlaine Date: 2010-04-06 20:41:06 +0000 (Tue, 06 Apr 2010) Log Message: ----------- Added code to move the view position to the place a ship can be placed, when that ship is clicked in CombatSetupWnd. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/CombatWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-06 20:12:59 UTC (rev 3433) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-06 20:41:06 UTC (rev 3434) @@ -430,6 +430,8 @@ get_object_under_pt, boost::function<void (int, const Ogre::Vector3&)> reposition_ship_node, + boost::function<void (const Ogre::Vector3&)> + look_at, GG::Flags<GG::WndFlag> flags/* = GG::INTERACTIVE | GG::DRAGABLE*/) : CUIWnd("Ships", GG::X(PAD), GG::GUI::GetGUI()->AppHeight() - SETUP_WND_HEIGHT - GG::Y(PAD), GG::X(500), SETUP_WND_HEIGHT, flags), @@ -450,7 +452,8 @@ m_get_ship_material(get_ship_material), m_add_ship_node_to_combat_wnd(add_ship_node_to_combat_wnd), m_get_object_under_pt(get_object_under_pt), - m_reposition_ship_node(reposition_ship_node) + m_reposition_ship_node(reposition_ship_node), + m_look_at(look_at) { m_listbox->SetStyle(m_listbox->Style() | GG::LIST_SINGLESEL); Connect(m_done_button->ClickedSignal, &CombatSetupWnd::DoneButtonClicked, this); @@ -646,6 +649,10 @@ } } m_current_setup_group = i; + if (m_setup_groups[m_current_setup_group].m_allow && + m_region_nodes_by_setup_group[m_current_setup_group].size() == 1u) { + m_look_at(m_region_nodes_by_setup_group[m_current_setup_group].back()->getPosition()); + } } break; } Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-06 20:12:59 UTC (rev 3433) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-06 20:41:06 UTC (rev 3434) @@ -43,6 +43,8 @@ get_object_under_pt, boost::function<void (int, const Ogre::Vector3&)> reposition_ship_node, + boost::function<void (const Ogre::Vector3&)> + look_at, GG::Flags<GG::WndFlag> flags = GG::INTERACTIVE | GG::DRAGABLE); ~CombatSetupWnd(); @@ -91,6 +93,8 @@ m_get_object_under_pt; boost::function<void (int, const Ogre::Vector3&)> m_reposition_ship_node; + boost::function<void (const Ogre::Vector3&)> + m_look_at; }; #endif // _CombatSetupWnd_h_ Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-06 20:12:59 UTC (rev 3433) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-06 20:41:06 UTC (rev 3434) @@ -1187,7 +1187,8 @@ boost::bind(&CombatWnd::GetShipMaterial, this, _1), boost::bind(&CombatWnd::AddShipNode, this, _1, _2, _3, _4), boost::bind(&CombatWnd::GetObjectUnderPt, this, _1), - boost::bind(&CombatWnd::RepositionShipNode, this, _1, _2)); + boost::bind(&CombatWnd::RepositionShipNode, this, _1, _2), + boost::bind(&CombatWnd::LookAtPosition, this, _1)); AttachChild(m_combat_setup_wnd); } @@ -1312,13 +1313,13 @@ EndSelectionDrag(); } -void CombatWnd::LookAt(Ogre::SceneNode* look_at_node) +void CombatWnd::LookAtNode(Ogre::SceneNode* look_at_node) { m_look_at_scene_node = look_at_node; - LookAt(m_look_at_scene_node->_getDerivedPosition()); + LookAtPosition(m_look_at_scene_node->_getDerivedPosition()); } -void CombatWnd::LookAt(const Ogre::Vector3& look_at_point) +void CombatWnd::LookAtPosition(const Ogre::Vector3& look_at_point) { const Ogre::Vector3 DISTANCE = look_at_point - m_look_at_point; m_look_at_point = look_at_point; @@ -1408,11 +1409,11 @@ if (Ogre::MovableObject* movable_object = GetObjectUnderPt(pt)) { Ogre::SceneNode* clicked_scene_node = movable_object->getParentSceneNode(); assert(clicked_scene_node); - LookAt(clicked_scene_node); + LookAtNode(clicked_scene_node); } else { std::pair<bool, Ogre::Vector3> intersection = IntersectMouseWithEcliptic(pt); if (intersection.first) - LookAt(intersection.second); + LookAtPosition(intersection.second); } } } else { Modified: trunk/FreeOrion/UI/CombatWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatWnd.h 2010-04-06 20:12:59 UTC (rev 3433) +++ trunk/FreeOrion/UI/CombatWnd.h 2010-04-06 20:41:06 UTC (rev 3434) @@ -125,8 +125,8 @@ void RenderLensFlare(); - void LookAt(Ogre::SceneNode* look_at_node); - void LookAt(const Ogre::Vector3& look_at_point); + void LookAtNode(Ogre::SceneNode* look_at_node); + void LookAtPosition(const Ogre::Vector3& look_at_point); void Zoom(int move, GG::Flags<GG::ModKey> mod_keys); void HandleRotation(const GG::Pt& delta); void UpdateCameraPosition(); |
From: <tz...@us...> - 2010-04-06 21:27:51
|
Revision: 3435 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3435&view=rev Author: tzlaine Date: 2010-04-06 21:27:45 +0000 (Tue, 06 Apr 2010) Log Message: ----------- Changed the behavior of the CombatSetupWnd ship-placement and -dragging code to point the placed ships towards the system's star. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/CombatWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-06 20:41:06 UTC (rev 3434) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-06 21:27:45 UTC (rev 3435) @@ -294,7 +294,7 @@ Ogre::SceneNode* retval = 0; const int SLICES = 100; - const double INCR = 2.0 * Ogre::Math::PI / SLICES; + const double INCR = Ogre::Math::TWO_PI / SLICES; static std::vector<Ogre::Vector3> unit_circle_vertices; if (unit_circle_vertices.empty()) { unit_circle_vertices.resize(SLICES); @@ -428,7 +428,7 @@ add_ship_node_to_combat_wnd, boost::function<Ogre::MovableObject* (const GG::Pt&)> get_object_under_pt, - boost::function<void (int, const Ogre::Vector3&)> + boost::function<void (int, const Ogre::Vector3&, const Ogre::Quaternion&)> reposition_ship_node, boost::function<void (const Ogre::Vector3&)> look_at, @@ -533,7 +533,12 @@ const Ship* const * ship = Ogre::any_cast<Ship*>(&m_button_press_placed_ship_node->getUserAny()); assert(ship); - m_reposition_ship_node((*ship)->ID(), intersection.second); + m_reposition_ship_node( + (*ship)->ID(), + intersection.second, + Ogre::Quaternion(Ogre::Radian(Ogre::Math::HALF_PI + + std::atan2(-intersection.second.y, -intersection.second.x)), + Ogre::Vector3(0.0, 0.0, 1.0))); CreateCombatOrder((*ship)->ID(), m_button_press_placed_ship_node); } } @@ -576,6 +581,10 @@ if (intersection.first) { node->setVisible(true); node->setPosition(intersection.second); + node->setOrientation( + Ogre::Quaternion(Ogre::Radian(Ogre::Math::HALF_PI + + std::atan2(-intersection.second.y, -intersection.second.x)), + Ogre::Vector3(0.0, 0.0, 1.0))); } else { node->setVisible(false); } Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-06 20:41:06 UTC (rev 3434) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-06 21:27:45 UTC (rev 3435) @@ -12,6 +12,7 @@ class Material; class MaterialPtr; class MovableObject; + class Quaternion; class SceneManager; class SceneNode; class Vector3; @@ -41,7 +42,7 @@ add_ship_node_to_combat_wnd, boost::function<Ogre::MovableObject* (const GG::Pt&)> get_object_under_pt, - boost::function<void (int, const Ogre::Vector3&)> + boost::function<void (int, const Ogre::Vector3&, const Ogre::Quaternion&)> reposition_ship_node, boost::function<void (const Ogre::Vector3&)> look_at, @@ -91,7 +92,7 @@ m_add_ship_node_to_combat_wnd; boost::function<Ogre::MovableObject* (const GG::Pt&)> m_get_object_under_pt; - boost::function<void (int, const Ogre::Vector3&)> + boost::function<void (int, const Ogre::Vector3&, const Ogre::Quaternion&)> m_reposition_ship_node; boost::function<void (const Ogre::Vector3&)> m_look_at; Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-06 20:41:06 UTC (rev 3434) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-06 21:27:45 UTC (rev 3435) @@ -181,6 +181,9 @@ btVector3 ToCollision(const Ogre::Vector3& vec) { return btVector3(vec.x, vec.y, vec.z); } + btQuaternion ToCollision(const Ogre::Quaternion& q) + { return btQuaternion(q.x, q.y, q.z, q.w); } + btVector3 ToCollision(const OpenSteer::Vec3& vec) { return btVector3(vec.x, vec.y, vec.z); } @@ -1137,11 +1140,11 @@ std::string planet_name = "orbit " + boost::lexical_cast<std::string>(it->first) + " planet"; - const Ogre::Real DELTA_THETA = 2.0 * Ogre::Math::PI / ASTEROIDS; + const Ogre::Real DELTA_THETA = Ogre::Math::TWO_PI / ASTEROIDS; Ogre::Real theta = 0.0; for (int i = 0; i < ASTEROIDS; ++i, theta += DELTA_THETA) { const Ogre::Real THICKNESS = AsteroidBeltRadius() * 2.0; - Ogre::Radian yaw(2.0 * Ogre::Math::PI * RandZeroToOne()); + Ogre::Radian yaw(Ogre::Math::TWO_PI * RandZeroToOne()); Ogre::Vector3 position; position.z = THICKNESS * (RandZeroToOne() - 0.5); position.y = @@ -1187,7 +1190,7 @@ boost::bind(&CombatWnd::GetShipMaterial, this, _1), boost::bind(&CombatWnd::AddShipNode, this, _1, _2, _3, _4), boost::bind(&CombatWnd::GetObjectUnderPt, this, _1), - boost::bind(&CombatWnd::RepositionShipNode, this, _1, _2), + boost::bind(&CombatWnd::RepositionShipNode, this, _1, _2, _3), boost::bind(&CombatWnd::LookAtPosition, this, _1)); AttachChild(m_combat_setup_wnd); } @@ -1890,6 +1893,7 @@ collision_object->getWorldTransform().setBasis(scaled); #endif collision_object->getWorldTransform().setOrigin(ToCollision(node->getPosition())); + collision_object->getWorldTransform().setRotation(ToCollision(node->getOrientation())); collision_object->setCollisionShape(collision_shape); m_collision_world->addCollisionObject(collision_object); collision_object->setUserPointer(static_cast<Ogre::MovableObject*>(entity)); @@ -1898,13 +1902,17 @@ ShipData(node, material, collision_mesh, collision_shape, collision_object); } -void CombatWnd::RepositionShipNode(int ship_id, const Ogre::Vector3& position) +void CombatWnd::RepositionShipNode(int ship_id, + const Ogre::Vector3& position, + const Ogre::Quaternion& orientation) { assert(m_ship_assets.find(ship_id) != m_ship_assets.end()); ShipData& ship_data = m_ship_assets[ship_id]; ship_data.m_node->setPosition(position); + ship_data.m_node->setOrientation(orientation); ship_data.m_bt_object->getWorldTransform().setOrigin(ToCollision(position)); m_collision_world->removeCollisionObject(ship_data.m_bt_object); + ship_data.m_bt_object->getWorldTransform().setRotation(ToCollision(orientation)); m_collision_world->addCollisionObject(ship_data.m_bt_object); } Modified: trunk/FreeOrion/UI/CombatWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatWnd.h 2010-04-06 20:41:06 UTC (rev 3434) +++ trunk/FreeOrion/UI/CombatWnd.h 2010-04-06 21:27:45 UTC (rev 3435) @@ -139,7 +139,9 @@ const Ogre::MaterialPtr& GetShipMaterial(const ShipDesign& ship_design); void AddShipNode(int ship_id, Ogre::SceneNode* node, Ogre::Entity* entity, const Ogre::MaterialPtr& material); - void RepositionShipNode(int ship_id, const Ogre::Vector3& position); + void RepositionShipNode(int ship_id, + const Ogre::Vector3& position, + const Ogre::Quaternion& orientation); void AddCombatShip(const CombatShipPtr& combat_ship); void RemoveCombatShip(const CombatShipPtr& combat_ship); |
From: <tz...@us...> - 2010-04-07 04:38:49
|
Revision: 3439 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3439&view=rev Author: tzlaine Date: 2010-04-07 04:38:43 +0000 (Wed, 07 Apr 2010) Log Message: ----------- Added logic to CombatSetupWnd to prohibit the placement of ships outside the indicated placement regions. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-07 04:38:03 UTC (rev 3438) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-07 04:38:43 UTC (rev 3439) @@ -5,6 +5,7 @@ #include "../universe/Fleet.h" #include "../universe/Ship.h" #include "../universe/ShipDesign.h" +#include "../util/Math.h" #include "../util/MultiplayerCommon.h" #include "../util/OptionsDB.h" @@ -413,6 +414,48 @@ nodes[i]->setVisible(visible); } } + + std::size_t GroupIndexOfShip(const std::vector<CombatSetupGroup>& setup_groups, const Ship* ship) + { + std::size_t retval = setup_groups.size(); + for (std::size_t i = 0; i < setup_groups.size(); ++i) { + if (setup_groups[i].m_ships.find(ship->ID()) != setup_groups[i].m_ships.end()) { + retval = i; + break; + } + } + return retval; + } + + bool PointInRegion(const Ogre::Vector3& point, const CombatSetupRegion& region) + { + bool retval = false; + switch (region.m_type) { + case CombatSetupRegion::RING: { + Ogre::Real range = point.length(); + retval = region.m_radius_begin < range && range < region.m_radius_end; + break; + } + case CombatSetupRegion::ELLIPSE: { + double theta_major = std::atan2(region.m_centroid[1], region.m_centroid[0]); + retval = PointInEllipse(point.x, point.y, + region.m_centroid[0], region.m_centroid[1], + region.m_radial_axis, region.m_tangent_axis, + theta_major); + break; + } + case CombatSetupRegion::PARTIAL_ELLIPSE: { + double theta_major = std::atan2(region.m_centroid[1], region.m_centroid[0]); + retval = PointInPartialEllipse(point.x, point.y, + region.m_centroid[0], region.m_centroid[1], + region.m_radial_axis, region.m_tangent_axis, + theta_major, + region.m_theta_begin, region.m_theta_end); + break; + } + } + return retval; + } } CombatSetupWnd::CombatSetupWnd( @@ -529,17 +572,16 @@ } if (m_dragging_placed_ship) { std::pair<bool, Ogre::Vector3> intersection = m_intersect_mouse_with_ecliptic(event.Point()); - if (intersection.first) { - const Ship* const * ship = - Ogre::any_cast<Ship*>(&m_button_press_placed_ship_node->getUserAny()); - assert(ship); + Ship* ship = *Ogre::any_cast<Ship*>(&m_button_press_placed_ship_node->getUserAny()); + bool valid_location = intersection.first && ValidPlacement(ship, intersection.second); + if (valid_location) { m_reposition_ship_node( - (*ship)->ID(), + ship->ID(), intersection.second, Ogre::Quaternion(Ogre::Radian(Ogre::Math::HALF_PI + std::atan2(-intersection.second.y, -intersection.second.x)), Ogre::Vector3(0.0, 0.0, 1.0))); - CreateCombatOrder((*ship)->ID(), m_button_press_placed_ship_node); + CreateCombatOrder(ship->ID(), m_button_press_placed_ship_node); } } } @@ -574,11 +616,31 @@ Ogre::SceneNode* CombatSetupWnd::PlaceableShipNode() const { return m_selected_placeable_ship ? m_placeable_ship_node : 0; } +bool CombatSetupWnd::ValidPlacement(Ship* ship, const Ogre::Vector3& point) +{ + bool retval = false; + std::size_t i = GroupIndexOfShip(m_setup_groups, ship); + if (i != m_setup_groups.size()) { + CombatSetupGroup& group = m_setup_groups[i]; + retval = !group.m_allow; + for (std::size_t j = 0; j < group.m_regions.size(); ++j) { + if (PointInRegion(point, group.m_regions[j])) { + retval = !retval; + break; + } + } + } + return retval; +} + void CombatSetupWnd::HandleMouseMoves(const GG::Pt& pt) { if (Ogre::SceneNode* node = PlaceableShipNode()) { std::pair<bool, Ogre::Vector3> intersection = m_intersect_mouse_with_ecliptic(pt); - if (intersection.first) { + bool valid_location = + intersection.first && + ValidPlacement(*Ogre::any_cast<Ship*>(&node->getUserAny()), intersection.second); + if (valid_location) { node->setVisible(true); node->setPosition(intersection.second); node->setOrientation( @@ -633,37 +695,35 @@ node->attachObject(entity); } m_placeable_ship_node = node; + m_placeable_ship_node->setVisible(false); } } } void CombatSetupWnd::UpdatePlacementIndicators(const Ship* ship) { - if (m_selected_placeable_ship) { - for (std::size_t i = 0; i < m_setup_groups.size(); ++i) { - if (m_setup_groups[i].m_ships.find(m_selected_placeable_ship->ID()) != - m_setup_groups[i].m_ships.end()) { - if (m_current_setup_group != i) { - if (m_current_setup_group < m_setup_groups.size()) - SetRegionNodesVisibility(m_region_nodes_by_setup_group[m_current_setup_group], false); - if (m_region_nodes_by_setup_group.find(i) != m_region_nodes_by_setup_group.end()) { - SetRegionNodesVisibility(m_region_nodes_by_setup_group[i], true); - } else { - CombatSetupGroup& group = m_setup_groups[i]; - for (std::size_t j = 0; j < group.m_regions.size(); ++j) { - Ogre::SceneNode* node = - CreatePlacementRegionNode(m_scene_manager, group.m_regions[j], - group.m_allow, i, j); - m_region_nodes_by_setup_group[i].push_back(node); - } + if (ship) { + std::size_t i = GroupIndexOfShip(m_setup_groups, ship); + if (i != m_setup_groups.size()) { + if (m_current_setup_group != i) { + if (m_current_setup_group < m_setup_groups.size()) + SetRegionNodesVisibility(m_region_nodes_by_setup_group[m_current_setup_group], false); + if (m_region_nodes_by_setup_group.find(i) != m_region_nodes_by_setup_group.end()) { + SetRegionNodesVisibility(m_region_nodes_by_setup_group[i], true); + } else { + CombatSetupGroup& group = m_setup_groups[i]; + for (std::size_t j = 0; j < group.m_regions.size(); ++j) { + Ogre::SceneNode* node = + CreatePlacementRegionNode(m_scene_manager, group.m_regions[j], + group.m_allow, i, j); + m_region_nodes_by_setup_group[i].push_back(node); } - m_current_setup_group = i; - if (m_setup_groups[m_current_setup_group].m_allow && - m_region_nodes_by_setup_group[m_current_setup_group].size() == 1u) { - m_look_at(m_region_nodes_by_setup_group[m_current_setup_group].back()->getPosition()); - } } - break; + m_current_setup_group = i; + if (m_setup_groups[m_current_setup_group].m_allow && + m_region_nodes_by_setup_group[m_current_setup_group].size() == 1u) { + m_look_at(m_region_nodes_by_setup_group[m_current_setup_group].back()->getPosition()); + } } } } else { Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-07 04:38:03 UTC (rev 3438) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-07 04:38:43 UTC (rev 3439) @@ -56,6 +56,7 @@ private: Ogre::SceneNode* PlaceableShipNode() const; + bool ValidPlacement(Ship* ship, const Ogre::Vector3& point); void HandleMouseMoves(const GG::Pt& pt); void CreateCombatOrder(int ship_id, Ogre::SceneNode* node); void PlaceableShipSelected_(const GG::ListBox::SelectionSet& sels); |
From: <tz...@us...> - 2010-04-09 00:00:30
|
Revision: 3447 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3447&view=rev Author: tzlaine Date: 2010-04-09 00:00:23 +0000 (Fri, 09 Apr 2010) Log Message: ----------- Added code to CombatSetupWnd to check that ships are not placed too close to each other. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-08 22:07:56 UTC (rev 3446) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-09 00:00:23 UTC (rev 3447) @@ -624,12 +624,12 @@ Ogre::SceneNode* CombatSetupWnd::PlaceableShipNode() const { return m_selected_placeable_ship ? m_placeable_ship_node : 0; } -bool CombatSetupWnd::ValidPlacement(Ship* ship, const Ogre::Vector3& point) +bool CombatSetupWnd::ValidPlacement(Ship* ship, const Ogre::Vector3& point) const { bool retval = false; std::size_t i = GroupIndexOfShip(m_setup_groups, ship); if (i != m_setup_groups.size()) { - CombatSetupGroup& group = m_setup_groups[i]; + const CombatSetupGroup& group = m_setup_groups[i]; retval = !group.m_allow; for (std::size_t j = 0; j < group.m_regions.size(); ++j) { if (PointInRegion(point, group.m_regions[j])) { @@ -638,6 +638,21 @@ } } } + if (retval) { + // verify that this placement is not too near to other ships + for (std::map<int, Ogre::SceneNode*>::const_iterator it = m_placed_nodes.begin(); + it != m_placed_nodes.end(); + ++it) { + Ogre::SceneNode::ObjectIterator iterator = it->second->getAttachedObjectIterator(); + assert(iterator.hasMoreElements()); + const Ogre::Sphere& sphere = + boost::polymorphic_downcast<Ogre::Entity*>(iterator.getNext())->getWorldBoundingSphere(); + if (sphere.intersects(point)) { + retval = false; + break; + } + } + } return retval; } @@ -790,6 +805,8 @@ assert(m_placement_orders.find(ship_id) == m_placement_orders.end()); CreateCombatOrder(ship_id, m_placeable_ship_node); + m_placed_nodes[ship_id] = m_ship_nodes[ship_id]; + m_ship_entities.erase(ship_id); m_ship_nodes.erase(ship_id); m_selected_placeable_ship = 0; Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-08 22:07:56 UTC (rev 3446) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-09 00:00:23 UTC (rev 3447) @@ -56,7 +56,8 @@ private: Ogre::SceneNode* PlaceableShipNode() const; - bool ValidPlacement(Ship* ship, const Ogre::Vector3& point); + bool ValidPlacement(Ship* ship, const Ogre::Vector3& point) const; + void HandleMouseMoves(const GG::Pt& pt); void CreateCombatOrder(int ship_id, Ogre::SceneNode* node); void PlaceableShipSelected_(const GG::ListBox::SelectionSet& sels); @@ -82,6 +83,7 @@ Ogre::SceneNode* m_placeable_ship_node; std::map<int, Ogre::Entity*> m_ship_entities; std::map<int, Ogre::SceneNode*> m_ship_nodes; + std::map<int, Ogre::SceneNode*> m_placed_nodes; Ogre::SceneManager* m_scene_manager; std::map<int, UniverseObject*> m_combat_universe; |
From: <tz...@us...> - 2010-04-10 04:09:05
|
Revision: 3458 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3458&view=rev Author: tzlaine Date: 2010-04-10 04:08:58 +0000 (Sat, 10 Apr 2010) Log Message: ----------- Fixed a bug introduced with the new redo-placement functionality in r3455. Ships (re-)placed multiple times are clickable/draggable now. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h trunk/FreeOrion/UI/CombatWnd.cpp Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-10 03:36:41 UTC (rev 3457) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-10 04:08:58 UTC (rev 3458) @@ -428,6 +428,13 @@ } return retval; } + + Ogre::Quaternion OrientationForPosition(const Ogre::Vector3& position) + { + return Ogre::Quaternion(Ogre::Radian(std::atan2(-position.y, -position.x) - + Ogre::Math::HALF_PI), + Ogre::Vector3(0.0, 0.0, 1.0)); + } } CombatSetupWnd::CombatSetupWnd( @@ -577,15 +584,8 @@ std::pair<bool, Ogre::Vector3> intersection = m_intersect_mouse_with_ecliptic(event.Point()); Ship* ship = *Ogre::any_cast<Ship*>(&m_button_press_placed_ship_node->getUserAny()); bool valid_location = intersection.first && ValidPlacement(ship, intersection.second); - if (valid_location) { - m_reposition_ship_node( - ship->ID(), - intersection.second, - Ogre::Quaternion(Ogre::Radian(Ogre::Math::HALF_PI + - std::atan2(-intersection.second.y, -intersection.second.x)), - Ogre::Vector3(0.0, 0.0, 1.0))); - CreateCombatOrder(ship->ID(), m_button_press_placed_ship_node); - } + if (valid_location) + RepositionShip(ship, m_button_press_placed_ship_node, intersection.second); } } retval = true; @@ -667,10 +667,7 @@ bool valid_location = ValidPlacement(ship, intersection.second); node->setVisible(true); node->setPosition(intersection.second); - node->setOrientation( - Ogre::Quaternion(Ogre::Radian(std::atan2(-intersection.second.y, -intersection.second.x) - - Ogre::Math::HALF_PI), - Ogre::Vector3(0.0, 0.0, 1.0))); + node->setOrientation(OrientationForPosition(intersection.second)); if (valid_location) { Ogre::SceneNode::ObjectIterator iterator = node->getAttachedObjectIterator(); assert(iterator.hasMoreElements()); @@ -797,7 +794,7 @@ assert(m_selected_placeable_ship); assert(m_placeable_ship_node); - PlaceShip(m_selected_placeable_ship, m_placeable_ship_node); + RepositionShip(m_selected_placeable_ship, m_placeable_ship_node, m_placeable_ship_node->getPosition()); const CUIListBox::SelectionSet& selections = m_listbox->Selections(); assert(selections.size() == 1u); @@ -820,6 +817,14 @@ m_placed_nodes[ship_id] = node; } +void CombatSetupWnd::RepositionShip(Ship* ship, Ogre::SceneNode* node, const Ogre::Vector3& position) +{ + int ship_id = ship->ID(); + m_reposition_ship_node(ship_id, position, OrientationForPosition(position)); + CreateCombatOrder(ship_id, node); + m_placed_nodes[ship_id] = node; +} + void CombatSetupWnd::RedoPlacementsButtonClicked() { const GG::Pt row_size = ListRowSize(); Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-10 03:36:41 UTC (rev 3457) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-10 04:08:58 UTC (rev 3458) @@ -69,6 +69,7 @@ void CancelCurrentShipPlacement(); void PlaceCurrentShip(); void PlaceShip(Ship* ship, Ogre::SceneNode* node); + void RepositionShip(Ship* ship, Ogre::SceneNode* node, const Ogre::Vector3& position); void RedoPlacementsButtonClicked(); void AutoPlaceButtonClicked(); void DoneButtonClicked(); Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-10 03:36:41 UTC (rev 3457) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-10 04:08:58 UTC (rev 3458) @@ -1954,9 +1954,6 @@ void CombatWnd::AddShipNode(int ship_id, Ogre::SceneNode* node, Ogre::Entity* entity, const Ogre::MaterialPtr& material) { - if (m_ship_assets.find(ship_id) != m_ship_assets.end()) - return; - CollisionMeshConverter collision_mesh_converter(entity); btTriangleMesh* collision_mesh = 0; btBvhTriangleMeshShape* collision_shape = 0; |
From: <tz...@us...> - 2010-04-13 21:17:31
|
Revision: 3480 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3480&view=rev Author: tzlaine Date: 2010-04-13 21:17:25 +0000 (Tue, 13 Apr 2010) Log Message: ----------- Fixed the double-rendering of CUISlider's tab. Modified Paths: -------------- trunk/FreeOrion/UI/CUIControls.cpp trunk/FreeOrion/UI/MapWnd.cpp Modified: trunk/FreeOrion/UI/CUIControls.cpp =================================================================== --- trunk/FreeOrion/UI/CUIControls.cpp 2010-04-13 20:13:15 UTC (rev 3479) +++ trunk/FreeOrion/UI/CUIControls.cpp 2010-04-13 21:17:25 UTC (rev 3480) @@ -917,9 +917,6 @@ lr.y = ul.y + static_cast<int>(LineWidth()); } GG::FlatRectangle(ul, lr, GG::CLR_ZERO, border_color_to_use, 1); - Tab()->OffsetMove(UpperLeft()); - Tab()->Render(); - Tab()->OffsetMove(-UpperLeft()); } void CUISlider::SizeMove(const GG::Pt& ul, const GG::Pt& lr) Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2010-04-13 20:13:15 UTC (rev 3479) +++ trunk/FreeOrion/UI/MapWnd.cpp 2010-04-13 21:17:25 UTC (rev 3480) @@ -634,7 +634,6 @@ GG::X(ClientUI::ScrollWidth()), ZOOM_SLIDER_HEIGHT, ZOOM_SLIDER_MIN, ZOOM_SLIDER_MAX, GG::VERTICAL); m_zoom_slider->SlideTo(static_cast<int>(m_zoom_steps_in)); - GG::Connect(m_zoom_slider->SlidSignal, &MapWnd::ZoomSlid, this); // stealth threshold slider m_stealth_threshold_slider = new CUISlider(m_zoom_slider->UpperLeft().x + GG::X(ClientUI::ScrollWidth()*3), m_zoom_slider->UpperLeft().y, |
From: <tz...@us...> - 2010-04-14 16:47:06
|
Revision: 3489 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3489&view=rev Author: tzlaine Date: 2010-04-14 16:47:00 +0000 (Wed, 14 Apr 2010) Log Message: ----------- Added code to CombatWnd to set the decal color of all ships to be the ship's owner's empire color. Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatSetupWnd.h trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/CombatWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-14 16:34:28 UTC (rev 3488) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-14 16:47:00 UTC (rev 3489) @@ -437,7 +437,7 @@ Ogre::SceneManager* scene_manager, boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt& pt)> intersect_mouse_with_ecliptic, - boost::function<const Ogre::MaterialPtr& (const ShipDesign&)> + boost::function<const Ogre::MaterialPtr& (const Ship&)> get_ship_material, boost::function<void (int, Ogre::SceneNode*, Ogre::Entity*, const Ogre::MaterialPtr&)> add_ship_node_to_combat_wnd, @@ -707,7 +707,7 @@ if (!retval) { retval = CreateShipSceneNode(m_scene_manager, ship); retval->setUserAny(Ogre::Any(&ship)); - const Ogre::MaterialPtr& material = m_get_ship_material(*ship.Design()); + const Ogre::MaterialPtr& material = m_get_ship_material(ship); Ogre::Entity*& entity = m_ship_entities[ship.ID()]; entity = CreateShipEntity(m_scene_manager, ship, material); retval->attachObject(entity); @@ -808,7 +808,7 @@ m_add_ship_node_to_combat_wnd(ship_id, node, m_ship_entities[ship_id], - m_get_ship_material(*ship->Design())); + m_get_ship_material(*ship)); CreateCombatOrder(ship_id, node); m_placed_nodes[ship_id] = node; } Modified: trunk/FreeOrion/UI/CombatSetupWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-14 16:34:28 UTC (rev 3488) +++ trunk/FreeOrion/UI/CombatSetupWnd.h 2010-04-14 16:47:00 UTC (rev 3489) @@ -36,7 +36,7 @@ Ogre::SceneManager* scene_manager, boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt&)> intersect_mouse_with_ecliptic, - boost::function<const Ogre::MaterialPtr& (const ShipDesign&)> + boost::function<const Ogre::MaterialPtr& (const Ship&)> get_ship_material, boost::function<void (int, Ogre::SceneNode*, Ogre::Entity*, const Ogre::MaterialPtr&)> add_ship_node_to_combat_wnd, @@ -98,7 +98,7 @@ boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt& pt)> m_intersect_mouse_with_ecliptic; - boost::function<const Ogre::MaterialPtr& (const ShipDesign&)> + boost::function<const Ogre::MaterialPtr& (const Ship&)> m_get_ship_material; boost::function<void (int, Ogre::SceneNode*, Ogre::Entity*, const Ogre::MaterialPtr&)> m_add_ship_node_to_combat_wnd; Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-14 16:34:28 UTC (rev 3488) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-14 16:47:00 UTC (rev 3489) @@ -10,6 +10,7 @@ #include "../combat/OpenSteer/CombatShip.h" #include "../combat/OpenSteer/Missile.h" #include "../combat/OpenSteer/PathingEngine.h" +#include "../Empire/Empire.h" #include "../universe/System.h" #include "../universe/Planet.h" #include "../universe/Predicates.h" @@ -1944,8 +1945,11 @@ void CombatWnd::DeselectAll() { m_current_selections.clear(); } -const Ogre::MaterialPtr& CombatWnd::GetShipMaterial(const ShipDesign& ship_design) +const Ogre::MaterialPtr& CombatWnd::GetShipMaterial(const Ship& ship) { + assert(ship.Design()); + const ShipDesign& ship_design = *ship.Design(); + Ogre::MaterialPtr ship_material = Ogre::MaterialManager::getSingleton().getByName("ship"); std::string modified_material_name = ShipMaterialName(ship_design); @@ -1958,14 +1962,19 @@ setTextureName(ship_design.Model() + "_Glow.png"); modified_material->getTechnique(0)->getPass(1)->getTextureUnitState(2)-> setTextureName(ship_design.Model() + "_Normal.png"); - modified_material->getTechnique(0)->getPass(1)->getTextureUnitState(3)-> - setTextureName(ship_design.Model() + "_Specular.png"); } + modified_material->getTechnique(0)->getPass(1)->getFragmentProgramParameters()-> setNamedConstant("star_light_color", GetSystemColor(StarBaseName())); + // TODO: Use the current skybox, once we have more than one. modified_material->getTechnique(0)->getPass(1)->getFragmentProgramParameters()-> setNamedConstant("skybox_light_color", GetSystemColor("sky_box_1")); + + GG::Clr color = Empires().Lookup(ClientApp::GetApp()->PlayerID())->Color(); + modified_material->getTechnique(0)->getPass(1)->getFragmentProgramParameters()-> + setNamedConstant("decal_color", Ogre::Vector3(color.r / 255.0, color.g / 255.0, color.b / 255.0)); + return modified_material; } @@ -2024,7 +2033,7 @@ const Ship& ship = combat_ship->GetShip(); std::string mesh_name = ship.Design()->Model() + ".mesh"; - const Ogre::MaterialPtr& material = GetShipMaterial(*ship.Design()); + const Ogre::MaterialPtr& material = GetShipMaterial(ship); Ogre::Entity* entity = CreateShipEntity(m_scene_manager, ship, material); Ogre::SceneNode* node = CreateShipSceneNode(m_scene_manager, ship); node->attachObject(entity); Modified: trunk/FreeOrion/UI/CombatWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatWnd.h 2010-04-14 16:34:28 UTC (rev 3488) +++ trunk/FreeOrion/UI/CombatWnd.h 2010-04-14 16:47:00 UTC (rev 3489) @@ -137,7 +137,7 @@ void SelectObjectsInVolume(bool toggle_selected_items); Ogre::MovableObject* GetObjectUnderPt(const GG::Pt& pt); void DeselectAll(); - const Ogre::MaterialPtr& GetShipMaterial(const ShipDesign& ship_design); + const Ogre::MaterialPtr& GetShipMaterial(const Ship& ship); void AddShipNode(int ship_id, Ogre::SceneNode* node, Ogre::Entity* entity, const Ogre::MaterialPtr& material); void RepositionShipNode(int ship_id, |
From: <tz...@us...> - 2010-04-15 18:24:59
|
Revision: 3507 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3507&view=rev Author: tzlaine Date: 2010-04-15 18:24:53 +0000 (Thu, 15 Apr 2010) Log Message: ----------- Fixed problem with empire colors getting erroneously replaced when a material is used to represent an entire design (now, it represents a design in a particular empire color). Modified Paths: -------------- trunk/FreeOrion/UI/CombatSetupWnd.cpp trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/CombatWnd.h Modified: trunk/FreeOrion/UI/CombatSetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-15 18:23:10 UTC (rev 3506) +++ trunk/FreeOrion/UI/CombatSetupWnd.cpp 2010-04-15 18:24:53 UTC (rev 3507) @@ -675,10 +675,10 @@ Ogre::SceneNode::ObjectIterator iterator = node->getAttachedObjectIterator(); assert(iterator.hasMoreElements()); Ogre::Entity* entity = boost::polymorphic_downcast<Ogre::Entity*>(iterator.getNext()); - entity->setMaterialName(ShipMaterialName(*ship->Design())); + entity->setMaterialName(ShipMaterialName(*ship->Design(), *ship->Owners().begin())); entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN); } else { - std::string base_material_name = ShipMaterialName(*ship->Design()); + std::string base_material_name = ShipMaterialName(*ship->Design(), *ship->Owners().begin()); std::string material_name = UNPLACEABLE_MATERIAL_PREFIX + base_material_name; if (!Ogre::MaterialManager::getSingleton().resourceExists(material_name)) { Ogre::MaterialPtr unmodified_material = Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-15 18:23:10 UTC (rev 3506) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-15 18:24:53 UTC (rev 3507) @@ -1945,7 +1945,7 @@ Ogre::MaterialPtr ship_material = Ogre::MaterialManager::getSingleton().getByName("ship"); - std::string modified_material_name = ShipMaterialName(ship_design); + std::string modified_material_name = ShipMaterialName(ship_design, *ship.Owners().begin()); Ogre::MaterialPtr& modified_material = m_ship_materials[modified_material_name]; if (!modified_material.get()) { modified_material = ship_material->clone(modified_material_name); @@ -2283,8 +2283,8 @@ OpenSteer::Vec3 ToOpenSteer(const Ogre::Vector3& vec) { return OpenSteer::Vec3(vec.x, vec.y, vec.z); } -std::string ShipMaterialName(const ShipDesign& ship_design) -{ return "ship material " + ship_design.Model(); } +std::string ShipMaterialName(const ShipDesign& ship_design, int empire_id) +{ return "ship material " + ship_design.Model() + " empire " + boost::lexical_cast<std::string>(empire_id); } Ogre::Quaternion StarwardOrientationForPosition(const Ogre::Vector3& position) { Modified: trunk/FreeOrion/UI/CombatWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatWnd.h 2010-04-15 18:23:10 UTC (rev 3506) +++ trunk/FreeOrion/UI/CombatWnd.h 2010-04-15 18:24:53 UTC (rev 3507) @@ -259,7 +259,7 @@ const Ogre::MaterialPtr& material); Ogre::Vector3 ToOgre(const OpenSteer::Vec3& vec); OpenSteer::Vec3 ToOpenSteer(const Ogre::Vector3& vec); -std::string ShipMaterialName(const ShipDesign& ship_design); +std::string ShipMaterialName(const ShipDesign& ship_design, int empire_id); Ogre::Quaternion StarwardOrientationForPosition(const Ogre::Vector3& position); extern const int PAGED_GEOMETRY_IMPOSTOR_QUEUE; |
From: <tz...@us...> - 2010-04-22 21:35:45
|
Revision: 3521 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3521&view=rev Author: tzlaine Date: 2010-04-22 21:35:39 +0000 (Thu, 22 Apr 2010) Log Message: ----------- Added an initial implementation of "zoom-panning", a la Supreme Commander. The motion when zooming in (and out, come to think of it) is currently discrete. A smooth transition like happens when you double-click to recenter may yet be implemented. Modified Paths: -------------- trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/CombatWnd.h Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-22 03:45:25 UTC (rev 3520) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-22 21:35:39 UTC (rev 3521) @@ -95,6 +95,7 @@ }; const GG::Pt INVALID_SELECTION_DRAG_POS(-GG::X1, -GG::Y1); + const Ogre::Vector3 INVALID_MAP_LOCATION(FLT_MAX, FLT_MAX, FLT_MAX); const Ogre::Real NEAR_CLIP = 0.01; const Ogre::Real FAR_CLIP = 4.0 * SystemRadius(); @@ -184,6 +185,16 @@ std::copy(ray_direction.data().begin(), ray_direction.data().end(), out_ray_direction); } + Ogre::Real ZoomFactor(GG::Flags<GG::ModKey> mod_keys) + { + Ogre::Real retval = 1.0; + if (mod_keys & GG::MOD_KEY_SHIFT) + retval *= 2.0; + if (mod_keys & GG::MOD_KEY_CTRL) + retval /= 4.0; + return retval; + } + std::string PlanetNodeMaterial(PlanetType type) { assert(INVALID_PLANET_TYPE < type && type < NUM_PLANET_TYPES); @@ -687,6 +698,8 @@ m_look_at_scene_node(0), m_selection_rect(), m_look_at_point(0, 0, 0), + m_initial_zoom_in_position(INVALID_MAP_LOCATION), + m_previous_zoom_in_time(0), m_star_back_billboard(0), m_collision_configuration(0), m_collision_dispatcher(0), @@ -1425,19 +1438,20 @@ void CombatWnd::Zoom(int move, GG::Flags<GG::ModKey> mod_keys) { + Ogre::Real move_incr = m_distance_to_look_at_point * 0.25; + Ogre::Real scale_factor = ZoomFactor(mod_keys); + Ogre::Real total_move = move_incr * scale_factor * -move; + ZoomImpl(total_move); +} + +void CombatWnd::ZoomImpl(Ogre::Real total_move) +{ Ogre::Sphere bounding_sphere(Ogre::Vector3(), 0.0); if (m_look_at_scene_node) bounding_sphere = m_look_at_scene_node->getAttachedObject(0)->getWorldBoundingSphere(); const Ogre::Real EFFECTIVE_MIN_DISTANCE = std::max(bounding_sphere.getRadius() * Ogre::Real(1.05), MIN_ZOOM_IN_DISTANCE); - Ogre::Real move_incr = m_distance_to_look_at_point * 0.25; - Ogre::Real scale_factor = 1.0; - if (mod_keys & GG::MOD_KEY_SHIFT) - scale_factor *= 2.0; - if (mod_keys & GG::MOD_KEY_CTRL) - scale_factor /= 4.0; - Ogre::Real total_move = move_incr * scale_factor * -move; if (m_distance_to_look_at_point + total_move < EFFECTIVE_MIN_DISTANCE) total_move += EFFECTIVE_MIN_DISTANCE - (m_distance_to_look_at_point + total_move); else if (MAX_ZOOM_OUT_DISTANCE < m_distance_to_look_at_point + total_move) @@ -1667,8 +1681,45 @@ void CombatWnd::MouseWheel(const GG::Pt& pt, int move, GG::Flags<GG::ModKey> mod_keys) { - if (move) - Zoom(move, mod_keys); + if (move) { + Ogre::Real move_incr = m_distance_to_look_at_point * 0.2; + Ogre::Real scale_factor = ZoomFactor(mod_keys); + Ogre::Real total_move = move_incr * scale_factor * -move; + if (0 < move) + { + const unsigned int TICKS = GG::GUI::GetGUI()->Ticks(); + + const unsigned int ZOOM_IN_TIMEOUT = 750u; + if (m_initial_zoom_in_position == INVALID_MAP_LOCATION || + ZOOM_IN_TIMEOUT < TICKS - m_previous_zoom_in_time) + { + std::pair<bool, Ogre::Vector3> intersection = IntersectMouseWithEcliptic(pt); + m_initial_zoom_in_position = intersection.first ? intersection.second : INVALID_MAP_LOCATION; + } + + if (m_initial_zoom_in_position != INVALID_MAP_LOCATION) { + const double CLOSE_FACTOR = move * 0.25; + Ogre::Vector3 delta = m_initial_zoom_in_position - m_look_at_point; + double delta_length = delta.length(); + double distance = std::min(std::max(1.0, delta_length * CLOSE_FACTOR), delta_length); + delta.normalise(); + Ogre::Vector3 new_center = m_look_at_point + delta * distance; + if (new_center.length() < SystemRadius()) { + m_look_at_scene_node = 0; +#if 0 + // TODO: Integrate with LookAtPosition(), if possible/convenient. + LookAtPosition(new_center); +#else + m_look_at_point = new_center; + UpdateCameraPosition(); +#endif + } + } + + m_previous_zoom_in_time = TICKS; + } + ZoomImpl(total_move); + } } void CombatWnd::KeyPress(GG::Key key, boost::uint32_t key_code_point, GG::Flags<GG::ModKey> mod_keys) Modified: trunk/FreeOrion/UI/CombatWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatWnd.h 2010-04-22 03:45:25 UTC (rev 3520) +++ trunk/FreeOrion/UI/CombatWnd.h 2010-04-22 21:35:39 UTC (rev 3521) @@ -133,6 +133,7 @@ void LookAtNode(Ogre::SceneNode* look_at_node); void LookAtPosition(const Ogre::Vector3& look_at_point); void Zoom(int move, GG::Flags<GG::ModKey> mod_keys); + void ZoomImpl(Ogre::Real total_move); void HandleRotation(const GG::Pt& delta); void UpdateCameraPosition(); void UpdateStarFromCameraPosition(); @@ -191,6 +192,8 @@ Ogre::SceneNode* m_look_at_scene_node; GG::Rect m_selection_rect; Ogre::Vector3 m_look_at_point; + Ogre::Vector3 m_initial_zoom_in_position; + unsigned int m_previous_zoom_in_time; std::map<Ogre::MovableObject*, SelectedObject> m_current_selections; Ogre::Billboard* m_star_back_billboard; Ogre::Real m_star_brightness_factor; |
From: <tz...@us...> - 2010-04-23 18:33:40
|
Revision: 3529 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3529&view=rev Author: tzlaine Date: 2010-04-23 18:33:33 +0000 (Fri, 23 Apr 2010) Log Message: ----------- Added animated transitions to the zoom-panning code. Now, zooming in while panning is smooth, just like recentering. Still needs tweaking -- frequent moves of the mousewheel cause different behavior than infrequent moves, due to interruption of the current transition animation. Smooth zoom-out is still to come. Modified Paths: -------------- trunk/FreeOrion/UI/CombatWnd.cpp trunk/FreeOrion/UI/CombatWnd.h Modified: trunk/FreeOrion/UI/CombatWnd.cpp =================================================================== --- trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-23 11:16:32 UTC (rev 3528) +++ trunk/FreeOrion/UI/CombatWnd.cpp 2010-04-23 18:33:33 UTC (rev 3529) @@ -123,8 +123,12 @@ const unsigned int NO_CITY_LIGHTS = std::numeric_limits<unsigned int>::max(); - const unsigned short LOOKAT_NODE_TRACK_HANDLE = 0; + const Ogre::Real IGNORE_DISTANCE = FLT_MAX; + const unsigned short CAMERA_NODE_TRACK_HANDLE = 0; + const unsigned short DISTANCE_TRACK_HANDLE = 1; + const unsigned short CAMERA_TRACK_HANDLE = 2; + // HACK! The currently-used star cores only cover part of the texture. // Here, we adjust for this, so that the edge of the star as it appears // onscreen is actually what we use for the star radius below. @@ -195,6 +199,9 @@ return retval; } + Ogre::Real TotalMove(int move, GG::Flags<GG::ModKey> mod_keys, Ogre::Real current_distance) + { return current_distance * 0.25 * ZoomFactor(mod_keys) * -move; } + std::string PlanetNodeMaterial(PlanetType type) { assert(INVALID_PLANET_TYPE < type && type < NUM_PLANET_TYPES); @@ -483,6 +490,53 @@ return colors[star_or_skybox_base_name]; } + class AnimableReal : + public Ogre::AnimableValue + { + public: + AnimableReal(Ogre::Real& value) : + AnimableValue(REAL), + m_value(value) + { mBaseValueReal[0] = m_value; } + + virtual void setValue(Ogre::Real v) + { m_value = mBaseValueReal[0] = v; } + + virtual void setCurrentStateAsBaseValue() + {} + + virtual void applyDeltaValue(Ogre::Real v) + { m_value = mBaseValueReal[0] = v; } + + private: + Ogre::Real& m_value; + }; + + class AnimableCamera : + public Ogre::AnimableValue + { + public: + AnimableCamera(Ogre::Camera& camera, const Ogre::Vector3& v) : + AnimableValue(VECTOR3), + m_camera(camera) + { std::memcpy(mBaseValueReal, v.ptr(), sizeof(Ogre::Real) * 3); } + + virtual void setValue(const Ogre::Vector3& v) + { setAsBaseValue(v); } + + virtual void setCurrentStateAsBaseValue() + {} + + virtual void applyDeltaValue(const Ogre::Vector3& v) + { + setAsBaseValue(v); + m_camera.setPosition(v); + } + + private: + Ogre::Camera& m_camera; + }; + void AddOptions(OptionsDB& db) { db.AddFlag("tech-demo", "OPTIONS_DB_TECH_DEMO", false); @@ -1418,33 +1472,69 @@ } void CombatWnd::LookAtPosition(const Ogre::Vector3& look_at_point) +{ LookAtPositionImpl(look_at_point, IGNORE_DISTANCE); } + +void CombatWnd::LookAtPositionImpl(const Ogre::Vector3& look_at_point, Ogre::Real distance) { - const Ogre::Vector3 DISTANCE = look_at_point - m_look_at_point; + if (distance == IGNORE_DISTANCE) + distance = m_distance_to_look_at_point; + else + m_camera_animation->destroyAllTracks(); + + Ogre::Vector3 node_start = m_look_at_point; + Ogre::Vector3 node_stop = look_at_point; + + Ogre::Vector3 camera_start = CameraPositionAndOrientation(m_distance_to_look_at_point).first; + Ogre::Vector3 camera_stop = CameraPositionAndOrientation(distance).first; + + const Ogre::Vector3 NODE_POS_DELTA = node_stop - node_start; + const Ogre::Real DISTANCE_DELTA = distance - m_distance_to_look_at_point; + const Ogre::Vector3 CAMERA_DELTA = camera_stop - camera_start; + m_look_at_point = look_at_point; - UpdateCameraPosition(); + + // We interpolate three things in our animation: the position of + // m_camera_node, which always stays on the ecliptic; the value of + // m_distance_to_look_at_point, which determines how far back m_camera is + // from its parent m_camera_node; and the parent-relative position of + // m_camera (which includes the interpolated value of + // m_distance_to_look_at_point). It is necessary to track + // m_distance_to_look_at_point separately, so that we can maintain its + // value during animated camera moves, even if we interrupt an animation + // in the middle to start a new one (as we do when the user rapidly rolls + // the mouse wheel). m_camera_animation_state->setTimePosition(0.0); - Ogre::NodeAnimationTrack* track = - m_camera_animation->createNodeTrack(LOOKAT_NODE_TRACK_HANDLE, m_camera_node); + Ogre::NodeAnimationTrack* node_track = + m_camera_animation->createNodeTrack(CAMERA_NODE_TRACK_HANDLE, m_camera_node); + Ogre::AnimableValuePtr animable_distance(new AnimableReal(m_distance_to_look_at_point)); + Ogre::NumericAnimationTrack* distance_track = + m_camera_animation->createNumericTrack(DISTANCE_TRACK_HANDLE, animable_distance); + Ogre::AnimableValuePtr animable_camera_pos(new AnimableCamera(*m_camera, camera_start)); + Ogre::NumericAnimationTrack* camera_track = + m_camera_animation->createNumericTrack(CAMERA_TRACK_HANDLE, animable_camera_pos); + const int STEPS = 8; const Ogre::Real TIME_INCREMENT = CAMERA_RECENTER_TIME / STEPS; - const Ogre::Vector3 DISTANCE_INCREMENT = DISTANCE / STEPS; + const Ogre::Vector3 NODE_POS_INCREMENT = NODE_POS_DELTA / STEPS; + const Ogre::Real DISTANCE_INCREMENT = DISTANCE_DELTA / STEPS; + const Ogre::Vector3 CAMERA_INCREMENT = CAMERA_DELTA / STEPS; + // the loop extends an extra 2 steps in either direction, to // ensure smoothness (since splines are being used) for (int i = -2; i < STEPS + 2; ++i) { - Ogre::TransformKeyFrame* key = track->createNodeKeyFrame(i * TIME_INCREMENT); - key->setTranslate(look_at_point - DISTANCE + i * DISTANCE_INCREMENT); + Ogre::TransformKeyFrame* node_key = node_track->createNodeKeyFrame(i * TIME_INCREMENT); + node_key->setTranslate(node_stop - NODE_POS_DELTA + i * NODE_POS_INCREMENT); + Ogre::NumericKeyFrame* distance_key = distance_track->createNumericKeyFrame(i * TIME_INCREMENT); + distance_key->setValue(distance - DISTANCE_DELTA + i * DISTANCE_INCREMENT); + Ogre::NumericKeyFrame* camera_key = camera_track->createNumericKeyFrame(i * TIME_INCREMENT); + camera_key->setValue(camera_stop - CAMERA_DELTA + i * CAMERA_INCREMENT); } } void CombatWnd::Zoom(int move, GG::Flags<GG::ModKey> mod_keys) -{ - Ogre::Real move_incr = m_distance_to_look_at_point * 0.25; - Ogre::Real scale_factor = ZoomFactor(mod_keys); - Ogre::Real total_move = move_incr * scale_factor * -move; - ZoomImpl(total_move); -} +{ ZoomImpl(TotalMove(move, mod_keys, m_distance_to_look_at_point)); } -void CombatWnd::ZoomImpl(Ogre::Real total_move) +Ogre::Real CombatWnd::ZoomResult(Ogre::Real total_move) { Ogre::Sphere bounding_sphere(Ogre::Vector3(), 0.0); if (m_look_at_scene_node) @@ -1456,7 +1546,12 @@ total_move += EFFECTIVE_MIN_DISTANCE - (m_distance_to_look_at_point + total_move); else if (MAX_ZOOM_OUT_DISTANCE < m_distance_to_look_at_point + total_move) total_move -= (m_distance_to_look_at_point + total_move) - MAX_ZOOM_OUT_DISTANCE; - m_distance_to_look_at_point += total_move; + return m_distance_to_look_at_point + total_move; +} + +void CombatWnd::ZoomImpl(Ogre::Real total_move) +{ + m_distance_to_look_at_point = ZoomResult(total_move); UpdateCameraPosition(); } @@ -1504,7 +1599,7 @@ void CombatWnd::LDoubleClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys) { if (CloseTo(pt, m_last_click_pos)) { - if (!m_mouse_dragged && !m_camera_animation->hasNodeTrack(LOOKAT_NODE_TRACK_HANDLE)) { + if (!m_mouse_dragged && !m_camera_animation->hasNodeTrack(CAMERA_NODE_TRACK_HANDLE)) { if (Ogre::MovableObject* movable_object = GetObjectUnderPt(pt)) { Ogre::SceneNode* clicked_scene_node = movable_object->getParentSceneNode(); assert(clicked_scene_node); @@ -1681,43 +1776,34 @@ void CombatWnd::MouseWheel(const GG::Pt& pt, int move, GG::Flags<GG::ModKey> mod_keys) { - if (move) { - Ogre::Real move_incr = m_distance_to_look_at_point * 0.2; - Ogre::Real scale_factor = ZoomFactor(mod_keys); - Ogre::Real total_move = move_incr * scale_factor * -move; - if (0 < move) + Ogre::Real total_move = TotalMove(move, mod_keys, m_distance_to_look_at_point); + if (0 < move) + { + const unsigned int TICKS = GG::GUI::GetGUI()->Ticks(); + + const unsigned int ZOOM_IN_TIMEOUT = 750u; + if (m_initial_zoom_in_position == INVALID_MAP_LOCATION || + ZOOM_IN_TIMEOUT < TICKS - m_previous_zoom_in_time) { - const unsigned int TICKS = GG::GUI::GetGUI()->Ticks(); + std::pair<bool, Ogre::Vector3> intersection = IntersectMouseWithEcliptic(pt); + m_initial_zoom_in_position = intersection.first ? intersection.second : INVALID_MAP_LOCATION; + } - const unsigned int ZOOM_IN_TIMEOUT = 750u; - if (m_initial_zoom_in_position == INVALID_MAP_LOCATION || - ZOOM_IN_TIMEOUT < TICKS - m_previous_zoom_in_time) - { - std::pair<bool, Ogre::Vector3> intersection = IntersectMouseWithEcliptic(pt); - m_initial_zoom_in_position = intersection.first ? intersection.second : INVALID_MAP_LOCATION; + if (m_initial_zoom_in_position != INVALID_MAP_LOCATION) { + const double CLOSE_FACTOR = move * 0.25; + Ogre::Vector3 delta = m_initial_zoom_in_position - m_look_at_point; + double delta_length = delta.length(); + double distance = std::min(std::max(1.0, delta_length * CLOSE_FACTOR), delta_length); + delta.normalise(); + Ogre::Vector3 new_center = m_look_at_point + delta * distance; + if (new_center.length() < SystemRadius()) { + m_look_at_scene_node = 0; + LookAtPositionImpl(new_center, ZoomResult(total_move)); } + } - if (m_initial_zoom_in_position != INVALID_MAP_LOCATION) { - const double CLOSE_FACTOR = move * 0.25; - Ogre::Vector3 delta = m_initial_zoom_in_position - m_look_at_point; - double delta_length = delta.length(); - double distance = std::min(std::max(1.0, delta_length * CLOSE_FACTOR), delta_length); - delta.normalise(); - Ogre::Vector3 new_center = m_look_at_point + delta * distance; - if (new_center.length() < SystemRadius()) { - m_look_at_scene_node = 0; -#if 0 - // TODO: Integrate with LookAtPosition(), if possible/convenient. - LookAtPosition(new_center); -#else - m_look_at_point = new_center; - UpdateCameraPosition(); -#endif - } - } - - m_previous_zoom_in_time = TICKS; - } + m_previous_zoom_in_time = TICKS; + } else if (move < 0) { ZoomImpl(total_move); } } @@ -1870,6 +1956,57 @@ return *boost::next(star_textures.begin(), m_combat_data->m_system->ID() % star_textures.size()); } +std::pair<Ogre::Vector3, Ogre::Quaternion> CombatWnd::CameraPositionAndOrientation(Ogre::Real distance) const +{ + // Here, we calculate where m_camera should be relative to its parent + // m_camera_node. m_camera_node always stays on the ecliptic, and the + // camera moves away from it a bit to look at the position it occupies. + // This code was originally written using the high-level Ogre::Camera API, + // but now the camera position sometimes needs to be known without + // actually moving the camera. The original lines of code are preserved + // here as comments, and under each one is the equivalent code cut from + // OgreCamera.cpp. + + std::pair<Ogre::Vector3, Ogre::Quaternion> retval; + + // Ogre::Camera::setPosition(Ogre::Vector3::ZERO); + retval.first = Ogre::Vector3::ZERO; + + // Ogre::Camera::setDirection(Ogre::Vector3::NEGATIVE_UNIT_Z); + { + Ogre::Vector3 zAdjustVec = -Ogre::Vector3::NEGATIVE_UNIT_Z; + Ogre::Vector3 xVec = Ogre::Vector3::UNIT_Y.crossProduct( zAdjustVec ); + xVec.normalise(); + Ogre::Vector3 yVec = zAdjustVec.crossProduct( xVec ); + yVec.normalise(); + retval.second.FromAxes( xVec, yVec, zAdjustVec ); + } + + // Ogre::Camera::roll(m_roll); + { + Ogre::Vector3 zAxis = retval.second * Ogre::Vector3::UNIT_Z; + Ogre::Quaternion roll_q(m_roll, zAxis); + roll_q.normalise(); + retval.second = roll_q * retval.second; + } + + // Ogre::Camera::pitch(m_pitch); + { + Ogre::Vector3 xAxis = retval.second * Ogre::Vector3::UNIT_X; + Ogre::Quaternion pitch_q(m_pitch, xAxis); + pitch_q.normalise(); + retval.second = pitch_q * retval.second; + } + + // Ogre::Camera::moveRelative(Ogre::Vector3(0, 0, distance)); + { + Ogre::Vector3 trans = retval.second * Ogre::Vector3(0, 0, distance); + retval.first += trans; + } + + return retval; +} + bool CombatWnd::frameStarted(const Ogre::FrameEvent& event) { Ogre::RenderTarget::FrameStats stats = @@ -1906,11 +2043,10 @@ void CombatWnd::UpdateCameraPosition() { m_camera_node->setPosition(m_look_at_point); - m_camera->setPosition(Ogre::Vector3::ZERO); - m_camera->setDirection(Ogre::Vector3::NEGATIVE_UNIT_Z); - m_camera->roll(m_roll); - m_camera->pitch(m_pitch); - m_camera->moveRelative(Ogre::Vector3(0, 0, m_distance_to_look_at_point)); + std::pair<Ogre::Vector3, Ogre::Quaternion> position_and_orientation = + CameraPositionAndOrientation(m_distance_to_look_at_point); + m_camera->setPosition(position_and_orientation.first); + m_camera->setOrientation(position_and_orientation.second); UpdateStarFromCameraPosition(); #if TEST_STATIC_OPENSTEER_OBSTACLES std::cout << "testing...\n"; Modified: trunk/FreeOrion/UI/CombatWnd.h =================================================================== --- trunk/FreeOrion/UI/CombatWnd.h 2010-04-23 11:16:32 UTC (rev 3528) +++ trunk/FreeOrion/UI/CombatWnd.h 2010-04-23 18:33:33 UTC (rev 3529) @@ -124,6 +124,7 @@ std::pair<bool, Ogre::Vector3> IntersectMouseWithEcliptic(const GG::Pt& pt) const; const std::string& StarBaseName() const; + std::pair<Ogre::Vector3, Ogre::Quaternion> CameraPositionAndOrientation(Ogre::Real distance) const; virtual bool frameStarted(const Ogre::FrameEvent& event); virtual bool frameEnded(const Ogre::FrameEvent& event); @@ -132,7 +133,9 @@ void LookAtNode(Ogre::SceneNode* look_at_node); void LookAtPosition(const Ogre::Vector3& look_at_point); + void LookAtPositionImpl(const Ogre::Vector3& look_at_point, Ogre::Real zoom); void Zoom(int move, GG::Flags<GG::ModKey> mod_keys); + Ogre::Real ZoomResult(Ogre::Real total_move); void ZoomImpl(Ogre::Real total_move); void HandleRotation(const GG::Pt& delta); void UpdateCameraPosition(); |
From: <tz...@us...> - 2010-04-24 03:56:37
|
Revision: 3538 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3538&view=rev Author: tzlaine Date: 2010-04-24 03:56:30 +0000 (Sat, 24 Apr 2010) Log Message: ----------- Removed CombatCamera::m_distance_to_look_at_point, in favor of using the value directly out of the Ogre::Camera position. Modified Paths: -------------- trunk/FreeOrion/UI/CombatCamera.cpp trunk/FreeOrion/UI/CombatCamera.h Modified: trunk/FreeOrion/UI/CombatCamera.cpp =================================================================== --- trunk/FreeOrion/UI/CombatCamera.cpp 2010-04-24 03:11:27 UTC (rev 3537) +++ trunk/FreeOrion/UI/CombatCamera.cpp 2010-04-24 03:56:30 UTC (rev 3538) @@ -21,7 +21,6 @@ const Ogre::Real TIME_INCREMENT = CAMERA_MOVE_TIME / CAMERA_ANIMATION_STEPS; const unsigned short CAMERA_NODE_TRACK_HANDLE = 0; - const unsigned short DISTANCE_TRACK_HANDLE = 1; const unsigned short CAMERA_TRACK_HANDLE = 2; const Ogre::Real IGNORE_DISTANCE = FLT_MAX; @@ -47,28 +46,6 @@ Ogre::Real TotalMove(int move, GG::Flags<GG::ModKey> mod_keys, Ogre::Real current_distance) { return current_distance * 0.25 * ZoomFactor(mod_keys) * -move; } - class AnimableReal : - public Ogre::AnimableValue - { - public: - AnimableReal(Ogre::Real& value) : - AnimableValue(REAL), - m_value(value) - { mBaseValueReal[0] = m_value; } - - virtual void setValue(Ogre::Real v) - { m_value = mBaseValueReal[0] = v; } - - virtual void setCurrentStateAsBaseValue() - {} - - virtual void applyDeltaValue(Ogre::Real v) - { m_value = mBaseValueReal[0] = v; } - - private: - Ogre::Real& m_value; - }; - class AnimableCamera : public Ogre::AnimableValue { @@ -102,7 +79,6 @@ m_camera_node(scene_manager->getRootSceneNode()->createChildSceneNode()), m_camera_animation(scene_manager->createAnimation("CameraTrack", CAMERA_MOVE_TIME)), m_camera_animation_state(scene_manager->createAnimationState("CameraTrack")), - m_distance_to_look_at_point(SystemRadius() / 2.0), m_pitch(0.0), m_roll(0.0), m_look_at_scene_node(look_at_node), @@ -219,11 +195,11 @@ } void CombatCamera::Zoom(int move, GG::Flags<GG::ModKey> mod_keys) -{ ZoomImpl(TotalMove(move, mod_keys, m_distance_to_look_at_point)); } +{ ZoomImpl(TotalMove(move, mod_keys, DistanceToLookAtPoint())); } void CombatCamera::MouseWheel(const GG::Pt& pt, int move, GG::Flags<GG::ModKey> mod_keys) { - Ogre::Real total_move = TotalMove(move, mod_keys, m_distance_to_look_at_point); + Ogre::Real total_move = TotalMove(move, mod_keys, DistanceToLookAtPoint()); if (0 < move) { const unsigned int TICKS = GG::GUI::GetGUI()->Ticks(); @@ -367,30 +343,27 @@ const Ogre::Real EFFECTIVE_MIN_DISTANCE = std::max(bounding_sphere.getRadius() * Ogre::Real(1.05), MIN_ZOOM_IN_DISTANCE); - if (m_distance_to_look_at_point + total_move < EFFECTIVE_MIN_DISTANCE) - total_move += EFFECTIVE_MIN_DISTANCE - (m_distance_to_look_at_point + total_move); - else if (MAX_ZOOM_OUT_DISTANCE < m_distance_to_look_at_point + total_move) - total_move -= (m_distance_to_look_at_point + total_move) - MAX_ZOOM_OUT_DISTANCE; - return m_distance_to_look_at_point + total_move; + if (DistanceToLookAtPoint() + total_move < EFFECTIVE_MIN_DISTANCE) + total_move += EFFECTIVE_MIN_DISTANCE - (DistanceToLookAtPoint() + total_move); + else if (MAX_ZOOM_OUT_DISTANCE < DistanceToLookAtPoint() + total_move) + total_move -= (DistanceToLookAtPoint() + total_move) - MAX_ZOOM_OUT_DISTANCE; + return DistanceToLookAtPoint() + total_move; } +Ogre::Real CombatCamera::DistanceToLookAtPoint() const +{ return m_camera.getPosition().z; } + void CombatCamera::LookAtPositionImpl(const Ogre::Vector3& look_at_point, Ogre::Real distance) { if (distance == IGNORE_DISTANCE) - distance = m_distance_to_look_at_point; + distance = DistanceToLookAtPoint(); - // We interpolate three things in our animation: the position of - // m_camera_node, which always stays on the ecliptic; the value of - // m_distance_to_look_at_point, which determines how far back m_camera is - // from its parent m_camera_node; and the parent-relative position of - // m_camera (which includes the interpolated value of - // m_distance_to_look_at_point). The latter two are interpolated in - // ZoomImpl(). It is necessary to track m_distance_to_look_at_point - // separately, so that we can maintain its value during animated camera - // moves, even if we interrupt an animation in the middle to start a new - // one (as we do when the user rapidly rolls the mouse wheel). + // We interpolate two things in our animation: the position of + // m_camera_node, which always stays on the ecliptic, and the + // parent-relative position of m_camera. The latter is interpolated in + // ZoomImpl(). - ZoomImpl(distance - m_distance_to_look_at_point); + ZoomImpl(distance - DistanceToLookAtPoint()); Ogre::Vector3 node_start = m_look_at_point; Ogre::Vector3 node_stop = look_at_point; @@ -418,28 +391,21 @@ Ogre::Real distance = ZoomResult(total_move); - Ogre::Vector3 camera_start = CameraPositionAndOrientation(m_distance_to_look_at_point).first; + Ogre::Vector3 camera_start = CameraPositionAndOrientation(DistanceToLookAtPoint()).first; Ogre::Vector3 camera_stop = CameraPositionAndOrientation(distance).first; - const Ogre::Real DISTANCE_DELTA = distance - m_distance_to_look_at_point; const Ogre::Vector3 CAMERA_DELTA = camera_stop - camera_start; m_camera_animation_state->setTimePosition(0.0); - Ogre::AnimableValuePtr animable_distance(new AnimableReal(m_distance_to_look_at_point)); - Ogre::NumericAnimationTrack* distance_track = - m_camera_animation->createNumericTrack(DISTANCE_TRACK_HANDLE, animable_distance); Ogre::AnimableValuePtr animable_camera_pos(new AnimableCamera(m_camera, camera_start)); Ogre::NumericAnimationTrack* camera_track = m_camera_animation->createNumericTrack(CAMERA_TRACK_HANDLE, animable_camera_pos); - const Ogre::Real DISTANCE_INCREMENT = DISTANCE_DELTA / CAMERA_ANIMATION_STEPS; const Ogre::Vector3 CAMERA_INCREMENT = CAMERA_DELTA / CAMERA_ANIMATION_STEPS; // the loop extends an extra 2 steps in either direction, to // ensure smoothness (since splines are being used) for (int i = -2; i < CAMERA_ANIMATION_STEPS + 2; ++i) { - Ogre::NumericKeyFrame* distance_key = distance_track->createNumericKeyFrame(i * TIME_INCREMENT); - distance_key->setValue(distance - DISTANCE_DELTA + i * DISTANCE_INCREMENT); Ogre::NumericKeyFrame* camera_key = camera_track->createNumericKeyFrame(i * TIME_INCREMENT); camera_key->setValue(camera_stop - CAMERA_DELTA + i * CAMERA_INCREMENT); } @@ -449,7 +415,7 @@ { m_camera_node->setPosition(m_look_at_point); std::pair<Ogre::Vector3, Ogre::Quaternion> position_and_orientation = - CameraPositionAndOrientation(m_distance_to_look_at_point); + CameraPositionAndOrientation(DistanceToLookAtPoint()); m_camera.setPosition(position_and_orientation.first); m_camera.setOrientation(position_and_orientation.second); CameraChangedSignal(); Modified: trunk/FreeOrion/UI/CombatCamera.h =================================================================== --- trunk/FreeOrion/UI/CombatCamera.h 2010-04-24 03:11:27 UTC (rev 3537) +++ trunk/FreeOrion/UI/CombatCamera.h 2010-04-24 03:56:30 UTC (rev 3538) @@ -45,6 +45,7 @@ double out_ray_origin[3], double out_ray_direction[3]) const; std::pair<Ogre::Vector3, Ogre::Quaternion> CameraPositionAndOrientation(Ogre::Real distance) const; Ogre::Real ZoomResult(Ogre::Real total_move) const; + Ogre::Real DistanceToLookAtPoint() const; void LookAtPositionImpl(const Ogre::Vector3& look_at_point, Ogre::Real zoom); void ZoomImpl(Ogre::Real total_move); @@ -56,7 +57,6 @@ Ogre::Animation* m_camera_animation; Ogre::AnimationState* m_camera_animation_state; - Ogre::Real m_distance_to_look_at_point; Ogre::Radian m_pitch; Ogre::Radian m_roll; Ogre::SceneNode* m_look_at_scene_node; |