From: <tz...@us...> - 2006-02-13 03:43:57
|
Revision: 1751 Author: tzlaine Date: 2006-02-12 19:43:43 -0800 (Sun, 12 Feb 2006) ViewCVS: http://svn.sourceforge.net/freeorion?rev=1751&view=rev Log Message: ----------- Fixed drag-rearrangement of ProductionWnd and ResearchWnd items broken by recent GG changes. Modified Paths: -------------- trunk/FreeOrion/UI/ProductionWnd.cpp trunk/FreeOrion/UI/ProductionWnd.h trunk/FreeOrion/UI/ResearchWnd.cpp trunk/FreeOrion/UI/ResearchWnd.h Modified: trunk/FreeOrion/UI/ProductionWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ProductionWnd.cpp 2006-02-13 02:17:43 UTC (rev 1750) +++ trunk/FreeOrion/UI/ProductionWnd.cpp 2006-02-13 03:43:43 UTC (rev 1751) @@ -30,6 +30,45 @@ }; ////////////////////////////////////////////////// + // QueueListBox + ////////////////////////////////////////////////// + class QueueListBox : public CUIListBox + { + public: + QueueListBox(int x, int y, int w, int h, ProductionWnd* production_wnd) : + CUIListBox(x, y, w, h), + m_production_wnd(production_wnd) + {} + // HACK! This is sort of a dirty trick, but we return false here in all cases, even when we accept the dropped + // item. This keeps things simpler than if we handled ListBox::DroppedRow signals, since we are explicitly + // updating everything on drops anyway. + virtual void AcceptDrops(std::list<Wnd*>& wnds, const GG::Pt& pt) + { + assert(wnds.size() == 1); + if ((*wnds.begin())->DragDropDataType() == "PRODUCTION_QUEUE_ROW") { + GG::ListBox::Row* row = static_cast<GG::ListBox::Row*>(*wnds.begin()); + int original_row_idx = -1; + for (int i = 0; i < NumRows(); ++i) { + if (&GetRow(i) == row) { + original_row_idx = i; + break; + } + } + assert(original_row_idx != -1); + int row_idx = RowUnderPt(pt); + if (original_row_idx < row_idx) + ++row_idx; + if (row_idx < 0 || row_idx > NumRows()) + row_idx = NumRows(); + m_production_wnd->QueueItemMoved(row_idx, row); + } + wnds.clear(); + } + private: + ProductionWnd* m_production_wnd; + }; + + ////////////////////////////////////////////////// // QueueBuildPanel ////////////////////////////////////////////////// class QueueBuildPanel : public GG::Control @@ -153,16 +192,14 @@ { m_production_info_panel = new ProductionInfoPanel(PRODUCTION_INFO_AND_QUEUE_WIDTH, 200, UserString("PRODUCTION_INFO_PANEL_TITLE"), UserString("PRODUCTION_INFO_PP"), OUTER_LINE_THICKNESS, ClientUI::KNOWN_TECH_FILL_COLOR, ClientUI::KNOWN_TECH_TEXT_AND_BORDER_COLOR); - m_queue_lb = new CUIListBox(2, m_production_info_panel->LowerRight().y, m_production_info_panel->Width() - 4, ClientSize().y - 4 - m_production_info_panel->Height()); + m_queue_lb = new QueueListBox(2, m_production_info_panel->LowerRight().y, m_production_info_panel->Width() - 4, ClientSize().y - 4 - m_production_info_panel->Height(), this); m_queue_lb->SetStyle(GG::LB_NOSORT | GG::LB_NOSEL | GG::LB_USERDELETE); - m_queue_lb->AllowDropType("PRODUCTION_QUEUE_ROW"); GG::Pt buid_designator_wnd_size = ClientSize() - GG::Pt(m_production_info_panel->Width() + 6, 6); 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() + 3, 3)); GG::Connect(m_build_designator_wnd->AddBuildToQueueSignal, &ProductionWnd::AddBuildToQueueSlot, this); GG::Connect(m_build_designator_wnd->BuildQuantityChangedSignal, &ProductionWnd::ChangeBuildQuantitySlot, this); - GG::Connect(m_queue_lb->DroppedSignal, &ProductionWnd::QueueItemMovedSlot, this); GG::Connect(m_queue_lb->ErasedSignal, &ProductionWnd::QueueItemDeletedSlot, this); GG::Connect(m_queue_lb->LeftClickedSignal, &ProductionWnd::QueueItemClickedSlot, this); GG::Connect(m_queue_lb->DoubleClickedSignal, &ProductionWnd::QueueItemDoubleClickedSlot, this); @@ -299,6 +336,13 @@ m_build_designator_wnd->SelectSystem(system); } +void ProductionWnd::QueueItemMoved(int row_idx, GG::ListBox::Row* row) +{ + HumanClientApp::Orders().IssueOrder(new ProductionQueueOrder(HumanClientApp::GetApp()->EmpireID(), static_cast<QueueRow*>(row)->queue_index, row_idx)); + UpdateQueue(); + ResetInfoPanel(); +} + void ProductionWnd::Sanitize() { m_build_designator_wnd->Clear(); @@ -359,13 +403,6 @@ } } -void ProductionWnd::QueueItemMovedSlot(int row_idx, GG::ListBox::Row* row) -{ - HumanClientApp::Orders().IssueOrder(new ProductionQueueOrder(HumanClientApp::GetApp()->EmpireID(), static_cast<QueueRow*>(row)->queue_index, row_idx)); - UpdateQueue(); - ResetInfoPanel(); -} - void ProductionWnd::QueueItemClickedSlot(int row_idx, GG::ListBox::Row* row, const GG::Pt& pt) { m_build_designator_wnd->CenterOnBuild(row_idx); Modified: trunk/FreeOrion/UI/ProductionWnd.h =================================================================== --- trunk/FreeOrion/UI/ProductionWnd.h 2006-02-13 02:17:43 UTC (rev 1750) +++ trunk/FreeOrion/UI/ProductionWnd.h 2006-02-13 03:43:43 UTC (rev 1751) @@ -29,6 +29,7 @@ void Reset(); void CenterOnBuild(int queue_idx); void SelectSystem(int system); + void QueueItemMoved(int row_idx, GG::ListBox::Row* row); void Sanitize(); //@} @@ -38,7 +39,6 @@ void AddBuildToQueueSlot(BuildType build_type, const std::string& name, int number, int location); void ChangeBuildQuantitySlot(int queue_idx, int quantity); void QueueItemDeletedSlot(int row_idx, GG::ListBox::Row* row); - void QueueItemMovedSlot(int row_idx, GG::ListBox::Row* row); void QueueItemClickedSlot(int row_idx, GG::ListBox::Row* row, const GG::Pt& pt); void QueueItemDoubleClickedSlot(int row_idx, GG::ListBox::Row* row); Modified: trunk/FreeOrion/UI/ResearchWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ResearchWnd.cpp 2006-02-13 02:17:43 UTC (rev 1750) +++ trunk/FreeOrion/UI/ResearchWnd.cpp 2006-02-13 03:43:43 UTC (rev 1751) @@ -30,6 +30,45 @@ }; ////////////////////////////////////////////////// + // QueueListBox + ////////////////////////////////////////////////// + class QueueListBox : public CUIListBox + { + public: + QueueListBox(int x, int y, int w, int h, ResearchWnd* research_wnd) : + CUIListBox(x, y, w, h), + m_research_wnd(research_wnd) + {} + // HACK! This is sort of a dirty trick, but we return false here in all cases, even when we accept the dropped + // item. This keeps things simpler than if we handled ListBox::DroppedRow signals, since we are explicitly + // updating everything on drops anyway. + virtual void AcceptDrops(std::list<Wnd*>& wnds, const GG::Pt& pt) + { + assert(wnds.size() == 1); + if ((*wnds.begin())->DragDropDataType() == "RESEARCH_QUEUE_ROW") { + GG::ListBox::Row* row = static_cast<GG::ListBox::Row*>(*wnds.begin()); + int original_row_idx = -1; + for (int i = 0; i < NumRows(); ++i) { + if (&GetRow(i) == row) { + original_row_idx = i; + break; + } + } + assert(original_row_idx != -1); + int row_idx = RowUnderPt(pt); + if (original_row_idx < row_idx) + ++row_idx; + if (row_idx < 0 || row_idx > NumRows()) + row_idx = NumRows(); + m_research_wnd->QueueItemMoved(row_idx, row); + } + wnds.clear(); + } + private: + ResearchWnd* m_research_wnd; + }; + + ////////////////////////////////////////////////// // QueueTechPanel ////////////////////////////////////////////////// class QueueTechPanel : public GG::Control @@ -144,15 +183,13 @@ { m_research_info_panel = new ProductionInfoPanel(RESEARCH_INFO_AND_QUEUE_WIDTH, 200, UserString("RESEARCH_INFO_PANEL_TITLE"), UserString("RESEARCH_INFO_RP"), OUTER_LINE_THICKNESS, ClientUI::KNOWN_TECH_FILL_COLOR, ClientUI::KNOWN_TECH_TEXT_AND_BORDER_COLOR); - m_queue_lb = new CUIListBox(2, m_research_info_panel->LowerRight().y, m_research_info_panel->Width() - 4, ClientSize().y - 4 - m_research_info_panel->Height()); + m_queue_lb = new QueueListBox(2, m_research_info_panel->LowerRight().y, m_research_info_panel->Width() - 4, ClientSize().y - 4 - m_research_info_panel->Height(), this); m_queue_lb->SetStyle(GG::LB_NOSORT | GG::LB_NOSEL | GG::LB_USERDELETE); - m_queue_lb->AllowDropType("RESEARCH_QUEUE_ROW"); GG::Pt tech_tree_wnd_size = ClientSize() - GG::Pt(m_research_info_panel->Width() + 6, 6); m_tech_tree_wnd = new TechTreeWnd(tech_tree_wnd_size.x, tech_tree_wnd_size.y); m_tech_tree_wnd->MoveTo(GG::Pt(m_research_info_panel->Width() + 3, 3)); GG::Connect(m_tech_tree_wnd->AddTechToQueueSignal, &ResearchWnd::AddTechToQueueSlot, this); - GG::Connect(m_queue_lb->DroppedSignal, &ResearchWnd::QueueItemMovedSlot, this); GG::Connect(m_queue_lb->ErasedSignal, &ResearchWnd::QueueItemDeletedSlot, this); GG::Connect(m_queue_lb->LeftClickedSignal, &ResearchWnd::QueueItemClickedSlot, this); GG::Connect(m_queue_lb->DoubleClickedSignal, &ResearchWnd::QueueItemDoubleClickedSlot, this); @@ -185,6 +222,13 @@ m_tech_tree_wnd->CenterOnTech(GetTech(tech_name)); } +void ResearchWnd::QueueItemMoved(int row_idx, GG::ListBox::Row* row) +{ + HumanClientApp::Orders().IssueOrder(new ResearchQueueOrder(HumanClientApp::GetApp()->EmpireID(), dynamic_cast<QueueRow*>(row)->tech->Name(), row_idx)); + UpdateQueue(); + ResetInfoPanel(); +} + void ResearchWnd::Sanitize() { m_tech_tree_wnd->Clear(); @@ -238,13 +282,6 @@ m_tech_tree_wnd->Update(); } -void ResearchWnd::QueueItemMovedSlot(int row_idx, GG::ListBox::Row* row) -{ - HumanClientApp::Orders().IssueOrder(new ResearchQueueOrder(HumanClientApp::GetApp()->EmpireID(), dynamic_cast<QueueRow*>(row)->tech->Name(), row_idx)); - UpdateQueue(); - ResetInfoPanel(); -} - void ResearchWnd::QueueItemClickedSlot(int row_idx, GG::ListBox::Row* row, const GG::Pt& pt) { m_tech_tree_wnd->CenterOnTech(dynamic_cast<QueueRow*>(row)->tech); Modified: trunk/FreeOrion/UI/ResearchWnd.h =================================================================== --- trunk/FreeOrion/UI/ResearchWnd.h 2006-02-13 02:17:43 UTC (rev 1750) +++ trunk/FreeOrion/UI/ResearchWnd.h 2006-02-13 03:43:43 UTC (rev 1751) @@ -25,6 +25,7 @@ void Reset(); void CenterOnTech(const std::string& tech_name); + void QueueItemMoved(int row_idx, GG::ListBox::Row* row); void Sanitize(); //@} @@ -33,7 +34,6 @@ void ResetInfoPanel(); void AddTechToQueueSlot(const Tech* tech); void QueueItemDeletedSlot(int row_idx, GG::ListBox::Row* row); - void QueueItemMovedSlot(int row_idx, GG::ListBox::Row* row); void QueueItemClickedSlot(int row_idx, GG::ListBox::Row* row, const GG::Pt& pt); void QueueItemDoubleClickedSlot(int row_idx, GG::ListBox::Row* row); |