// \83\8d\81[\83J\83\8b\95Ï\90\94
-static LPCWSTR const k_appName = L"GVONavi\81i\82Á\82Û\82¢\89½\82©\81j"; // \83A\83v\83\8a\83P\81[\83V\83\87\83\93\96¼
-static LPCWSTR const k_version = L"ver 1.2"; // \83o\81[\83W\83\87\83\93\94Ô\8d\86
+static LPCWSTR const k_appName = L"GVONavish"; // \83A\83v\83\8a\83P\81[\83V\83\87\83\93\96¼
+static LPCWSTR const k_version = L"ver 1.2"; // \83o\81[\83W\83\87\83\93\94Ô\8d\86
static LPCWSTR const k_copyright = L"copyright(c) @MandhelingFreak"; // \92\98\8dì\8c \95\\8e¦\81i\82¢\82¿\82¨\81[\81j
static LPCWSTR const k_windowClassName = L"GVONavish"; // \83\81\83C\83\93 \83E\83B\83\93\83h\83E \83N\83\89\83X\96¼
::glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
}
- for ( const GVOShipRoute *route : shipRouteList->getList() ) {
+ for ( const GVOShipRoutePtr route : shipRouteList->getList() ) {
// \8dÅ\90V\8dq\98H\82¾\82¯\82ð\95s\93§\96¾\82Å\95`\89æ
if ( shipRouteList->getList().back() == route ) {
::glLineWidth( lineWidth );
void GVOShipRoute::addRoutePoint( const GVONormalizedPoint & point )
{
+ _ASSERT( !isFixed() );
+
if ( m_lines.empty() ) {
m_lines.push_back( Line() );
}
Lines m_lines;
bool m_favorite = false;
bool m_hilight = false;
+ bool m_fixed = false; //!<@brief \8dq\98H\8cÅ\92è\83t\83\89\83O
public:
GVOShipRoute();
~GVOShipRoute();
+ //!@attention \8cÅ\92è\82³\82ê\82½\8dq\98H\82É\8dÀ\95W\82ð\92Ç\89Á\82µ\82Ä\82Í\82È\82ç\82È\82¢\81B\83\8d\83W\83b\83N\83G\83\89\81[\82È\82Ì\82ÅDebug\8e\9e\82Ì\82Ý\83G\83\89\81[\82Æ\82µ\82Ä\82¢\82é\81B
void addRoutePoint( const GVONormalizedPoint & point );
const Lines & getLines() const
}
return true;
}
+
+ bool isFixed() const
+ {
+ return m_fixed;
+ }
+
+ void setFix( bool isFixed)
+ {
+ m_fixed = isFixed;
+ }
private:
};
+
+typedef std::shared_ptr<GVOShipRoute> GVOShipRoutePtr;
+typedef std::weak_ptr<GVOShipRoute> GVOShipRouteWeakPtr;
-#include "stdafx.h"
+#include "stdafx.h"
#include "GVOShipRouteList.h"
-GVOShipRouteList::~GVOShipRouteList()
-{
- for ( GVOShipRoute *route : m_shipRouteList ) {
- delete route;
- }
- m_shipRouteList.clear();
-}
-
void GVOShipRouteList::closeRoute()
{
- addRoute();
+ if ( !m_shipRouteList.empty() ) {
+ m_shipRouteList.back()->setFix( true );
+ }
}
void GVOShipRouteList::addRoutePoint( const GVONormalizedPoint point )
{
- if ( m_shipRouteList.empty() ) {
+ if ( m_shipRouteList.empty() || m_shipRouteList.back()->isFixed() ) {
addRoute();
}
m_shipRouteList.back()->addRoutePoint( point );
if ( m_observer ) {
- m_observer->onShipRouteListUpdateRoute( *m_shipRouteList.back() );
+ m_observer->onShipRouteListUpdateRoute( m_shipRouteList.back() );
}
}
-void GVOShipRouteList::removeShipRouteAtReverseIndex( int reverseIndex )
+void GVOShipRouteList::removeShipRoute( GVOShipRoutePtr shipRoute )
{
- _ASSERT( 0 <= reverseIndex );
- _ASSERT( reverseIndex < (int)m_shipRouteList.size() );
-
- std::unique_ptr<GVOShipRoute> route;
- RouteList::iterator it;
- it = m_shipRouteList.begin();
- std::advance( it, indexFromReverseIndex( reverseIndex ) );
- route.reset( std::move( *it ) );
+ _ASSERT( shipRoute != nullptr );
+ auto it = std::find( m_shipRouteList.begin(), m_shipRouteList.end(), shipRoute );
+ if ( it == m_shipRouteList.end() ) {
+ return;
+ }
+ GVOShipRoutePtr removeTarget = shipRoute;
m_shipRouteList.erase( it );
if ( m_observer ) {
- m_observer->onShipRouteListRemoveItem( *route );
- }
- if ( reverseIndex == 0 ) {
- // \8dÅ\90V\8dX\90V\92\86\8dq\98H\82ð\92P\8f\83\8dí\8f\9c\82·\82é\82Æ\92¼\91O\82Ì\8dq\98H\82ª\8dX\90V\82³\82ê\91±\82¯\82é\88×\81A\90V\8bK\8dq\98H\82ð\8dì\90¬\82·\82é\81B
- addRoute();
+ m_observer->onShipRouteListRemoveItem( removeTarget );
}
}
void GVOShipRouteList::addRoute()
{
// \92Ç\89Á\82Æ\92Ê\92m
- m_shipRouteList.push_back( new GVOShipRoute() );
+ m_shipRouteList.push_back( GVOShipRoutePtr( new GVOShipRoute() ) );
if ( m_observer ) {
- m_observer->onShipRouteListAddRoute( *m_shipRouteList.back() );
+ m_observer->onShipRouteListAddRoute( m_shipRouteList.back() );
}
// \88ì\82ê\82½\95ª\82ð\8dí\8f\9c
int removeCount = 0;
auto it = m_shipRouteList.begin();
while ( it != m_shipRouteList.end() && removeCount < overCount) {
- auto route = *it;
- if ( route->isFavorite() ) {
+ if ( (*it)->isFavorite() ) {
++it;
continue;
}
auto itNext = std::next( it, 1 );
- delete route;
m_shipRouteList.erase( it );
++removeCount;
it = itNext;
std::advance( itBase, indexFromReverseIndex( reverseIndex ) );
RouteList::iterator itPrev = std::prev( itBase );
_ASSERT( itPrev != m_shipRouteList.end() );
- GVOShipRoute *baseRoute = *itBase;
- std::unique_ptr<GVOShipRoute> prevRoute( std::move( *itPrev ) );
+ GVOShipRoutePtr baseRoute = *itBase;
+ GVOShipRoutePtr prevRoute = *itPrev;
m_shipRouteList.erase( itPrev );
if ( m_observer ) {
- m_observer->onShipRouteListRemoveItem( *prevRoute );
+ m_observer->onShipRouteListRemoveItem( prevRoute );
}
baseRoute->jointPreviousLinesWithRoute( *prevRoute );
// \92Ê\92m
if ( m_observer ) {
- m_observer->onShipRouteListUpdateRoute( *baseRoute );
+ m_observer->onShipRouteListUpdateRoute( baseRoute );
}
}
//!@brief \8dq\98H\83\8a\83X\83g\8aÇ\97\9d\83N\83\89\83X
class GVOShipRouteList {
private:
- typedef std::list<GVOShipRoute *> RouteList;
+ typedef std::list<GVOShipRoutePtr> RouteList;
RouteList m_shipRouteList;
IGVOShipRouteListObserver * m_observer = nullptr;
size_t m_maxRouteCountWithoutFavorits = 30; //!<@brief \82¨\8bC\82É\93ü\82è\82ð\8f\9c\8aO\82µ\82½\8dq\98H\95Û\91¶\90\94
public:
GVOShipRouteList() = default;
- ~GVOShipRouteList();
+ ~GVOShipRouteList() = default;
void setObserver( IGVOShipRouteListObserver * observer )
{
return m_shipRouteList;
}
- //GVOShipRoute * getRouteAtIndex( int index )
- //{
- // if ( m_shipRouteList.size() <= (size_t)index ) {
- // return NULL;
- // }
- // RouteList::iterator it;
- // it = m_shipRouteList.begin();
- // std::advance( it, index );
- // return *it;
- //}
-
- GVOShipRoute * getRouteAtReverseIndex( int reverseIndex )
+ GVOShipRoutePtr getRouteAtReverseIndex( int reverseIndex )
{
if ( m_shipRouteList.size() <= (size_t)reverseIndex ) {
return nullptr;
return *it;
}
- int indexFromShipRoute( GVOShipRoute & shipRoute )
+ int reverseIndexFromShipRoute( GVOShipRoutePtr shipRoute ) const
{
- RouteList::iterator it;
- it = std::find( m_shipRouteList.begin(), m_shipRouteList.end(), &shipRoute );
- if ( it == m_shipRouteList.end() ) {
+ auto it = std::find( m_shipRouteList.crbegin(), m_shipRouteList.crend(), shipRoute );
+ if ( it == m_shipRouteList.crend() ) {
return -1;
}
- return std::distance( m_shipRouteList.begin(), it );
+ const int reverseIndex = std::distance( m_shipRouteList.crbegin(), it );
+ return reverseIndex;
}
- void removeShipRouteAtReverseIndex( int reverseIndex );
+ //void removeShipRouteAtReverseIndex( int reverseIndex );
+
+ void removeShipRoute( GVOShipRoutePtr shipRoute );
void clearAllItems();
IGVOShipRouteListObserver() = default;
virtual ~IGVOShipRouteListObserver() = default;
- virtual void onShipRouteListAddRoute( GVOShipRoute & shipRoute ) = 0;
- virtual void onShipRouteListUpdateRoute( GVOShipRoute & shipRoute ) = 0;
- virtual void onShipRouteListRemoveItem( GVOShipRoute & shipRoute ) = 0;
+ virtual void onShipRouteListAddRoute( GVOShipRoutePtr shipRoute ) = 0;
+ virtual void onShipRouteListUpdateRoute( GVOShipRoutePtr shipRoute ) = 0;
+ virtual void onShipRouteListRemoveItem( GVOShipRoutePtr shipRoute ) = 0;
virtual void onShipRouteListRemoveAllItems() = 0;
};
}
-void GVOShipRouteManageView::onShipRouteListAddRoute( GVOShipRoute & shipRoute )
+void GVOShipRouteManageView::onShipRouteListAddRoute( GVOShipRoutePtr shipRoute )
{
updateVisibleListItemCount();
- if ( m_selectedRoute ) {
- const int prevLineIndex = m_selectionIndex;
- const int nextLineIndex = m_selectionIndex + 1;
- ListView_SetItemState( m_listViewCtrl, prevLineIndex, 0, LVIS_SELECTED );
- ListView_SetItemState( m_listViewCtrl, nextLineIndex, LVIS_SELECTED, LVIS_SELECTED );
+ if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) {
+ const int reverseIndex = m_routeList->reverseIndexFromShipRoute( selectedRoute );
+ selectRow( m_selectionIndex, false );
+ selectRow( reverseIndex, true );
}
}
-void GVOShipRouteManageView::onShipRouteListUpdateRoute( GVOShipRoute & shipRoute )
+void GVOShipRouteManageView::onShipRouteListUpdateRoute( GVOShipRoutePtr shipRoute )
{
- int index = ((int)m_routeList->getList().size() - 1) - m_routeList->indexFromShipRoute( shipRoute );
- ListView_RedrawItems( m_listViewCtrl, index, index );
+ int reverseIndex = m_routeList->reverseIndexFromShipRoute( shipRoute );
+ if ( 0 <= reverseIndex ) {
+ ListView_RedrawItems( m_listViewCtrl, reverseIndex, reverseIndex );
+ }
}
-void GVOShipRouteManageView::onShipRouteListRemoveItem( GVOShipRoute & shipRoute )
+void GVOShipRouteManageView::onShipRouteListRemoveItem( GVOShipRoutePtr shipRoute )
{
- if ( m_selectedRoute == &shipRoute ) {
- const int selectionIndex = m_selectionIndex;
- if ( shipRoute.isHilight() ) {
- ListView_SetItemState( m_listViewCtrl, selectionIndex, 0, LVIS_SELECTED );
- ListView_RedrawItems( m_listViewCtrl, selectionIndex, selectionIndex );
+ if ( m_selectedRoute.lock() == shipRoute ) {
+ if ( 0 <= m_selectionIndex ) {
+ selectRow( m_selectionIndex, false );
}
}
updateVisibleListItemCount();
::ShowWindow( m_hwnd, SW_HIDE );
break;
case IDM_DESELECT_ROUTE:
- if ( m_selectedRoute ) {
- ListView_SetItemState( m_listViewCtrl, m_selectionIndex, 0, LVIS_SELECTED );
+ if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) {
+ selectRow( m_selectionIndex, false );
}
break;
case IDM_DELETE_SHIP_ROUTE:
- if ( m_selectedRoute ) {
- const int index = m_selectionIndex;
- ListView_SetItemState( m_listViewCtrl, index, 0, LVIS_SELECTED );
- m_routeList->removeShipRouteAtReverseIndex( index );
+ if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) {
+ selectRow( m_selectionIndex, false );
+ m_routeList->removeShipRoute( selectedRoute );
}
break;
case IDM_JOINT_SHIP_ROUTE:
- if ( m_selectedRoute ) {
+ if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) {
m_routeList->joinPreviousRouteAtReverseIndex( m_selectionIndex );
}
break;
case IDM_TOGGLE_FAVORITE:
- if ( m_selectedRoute ) {
- m_selectedRoute->setFavorite( !m_selectedRoute->isFavorite() );
+ if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) {
+ selectedRoute->setFavorite( !selectedRoute->isFavorite() );
ListView_RedrawItems( m_listViewCtrl, m_selectionIndex, m_selectionIndex );
}
break;
LV_DISPINFO * dispInfo = reinterpret_cast<LV_DISPINFO *>(nmh);
LVITEM & item = dispInfo->item;
dispInfo->hdr.idFrom;
- GVOShipRoute *route = m_routeList->getRouteAtReverseIndex( item.iItem );
+ GVOShipRoutePtr route = m_routeList->getRouteAtReverseIndex( item.iItem );
// \8dí\8f\9c\8f\88\97\9d\82Æ\95`\89æ\8f\88\97\9d\82Ì\83^\83C\83~\83\93\83O\82Å\8aÔ\82É\8d\87\82í\82È\82¢\82±\82Æ\82ª\82 \82é\81H
if ( !route ) {
updateVisibleListItemCount();
}
break;
case NM_RCLICK:
- if ( m_selectedRoute ) {
+ if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) {
POINT point = { 0 };
::GetCursorPos( &point );
HMENU menu = ::LoadMenu( g_hinst, MAKEINTRESOURCE( IDR_SHIPROUTEMANAGEPOPUPMENU ) );
if ( count == (m_selectionIndex + 1) ) {
::EnableMenuItem( menu, IDM_JOINT_SHIP_ROUTE, MF_BYCOMMAND | MF_DISABLED );
}
- if ( m_selectedRoute->isFavorite() ) {
+ if ( selectedRoute->isFavorite() ) {
::CheckMenuItem( menu, IDM_TOGGLE_FAVORITE, MF_BYCOMMAND | MF_CHECKED );
}
::TrackPopupMenu( menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NOANIMATION,
LPNMLISTVIEW nmlv = reinterpret_cast<LPNMLISTVIEW>(nmh);
if ( ((nmlv->uOldState & LVIS_SELECTED) == 0) && (nmlv->uNewState & LVIS_SELECTED) ) {
m_selectionIndex = nmlv->iItem;
- m_selectedRoute = m_routeList->getRouteAtReverseIndex( m_selectionIndex );
- m_selectedRoute->setHilight( true );
+ GVOShipRoutePtr selectedRoute = m_routeList->getRouteAtReverseIndex( m_selectionIndex );
+ selectedRoute->setHilight( true );
+ m_selectedRoute = selectedRoute;
::InvalidateRect( g_hwndMain, NULL, FALSE );
}
else if ( (nmlv->uOldState & LVIS_SELECTED) && ((nmlv->uNewState & LVIS_SELECTED) == 0) ) {
- m_selectedRoute->setHilight( false );
- m_selectedRoute = nullptr;
+ if ( GVOShipRoutePtr selectedRoute = m_selectedRoute.lock() ) {
+ selectedRoute->setHilight( false );
+ m_selectedRoute.reset();
+ }
m_selectionIndex = -1;
::InvalidateRect( g_hwndMain, NULL, FALSE );
}
{
ListView_SetItemCountEx( m_listViewCtrl, m_routeList->getList().size(), LVSICF_NOSCROLL );
}
+
+
+void GVOShipRouteManageView::selectRow( int index, bool isSelection )
+{
+ ListView_SetItemState( m_listViewCtrl, index, isSelection ? LVIS_SELECTED : 0, LVIS_SELECTED );
+}
GVOShipRouteList * m_routeList = nullptr;
HWND m_listViewCtrl = nullptr;
- int m_selectionIndex = -1;
- GVOShipRoute * m_selectedRoute = nullptr;
+ int m_selectionIndex = -1; //!<@brief \89¼\91z\83\8a\83X\83g\83r\83\85\81[\82È\82Ì\82Å\91I\91ð\8ds\82ð\8e©\91O\8aÇ\97\9d
+ GVOShipRouteWeakPtr m_selectedRoute;
size_t m_visibleCount = 50;
::SetForegroundWindow( m_hwnd );
}
- virtual void onShipRouteListAddRoute( GVOShipRoute & shipRoute ) override;
- virtual void onShipRouteListUpdateRoute( GVOShipRoute & shipRoute ) override;
- virtual void onShipRouteListRemoveItem( GVOShipRoute & shipRoute ) override;
+ virtual void onShipRouteListAddRoute( GVOShipRoutePtr shipRoute ) override;
+ virtual void onShipRouteListUpdateRoute( GVOShipRoutePtr shipRoute ) override;
+ virtual void onShipRouteListRemoveItem( GVOShipRoutePtr shipRoute ) override;
virtual void onShipRouteListRemoveAllItems() override;
private:
static BOOL CALLBACK dlgProcThunk( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp );
void onNotify( LPNMHDR nmh );
void setupRouteList();
void updateVisibleListItemCount();
+ void selectRow( int index, bool isSelection );
};