OSDN Git Service

航路管理画面を実装。
[gvonavish/GVONavish.git] / GVONavish / GVONavish / GVOShipRouteList.h
1 #pragma once
2 #include <list>
3 #include "GVONavish.h"
4 #include "GVOShipRoute.h"
5 #include "GVONormalizedPoint.h"
6
7 class GVOShipRouteList;
8 class IGVOShipRouteListObserver;
9
10 //!@brief \8dq\98H\83\8a\83X\83g\8aÇ\97\9d\83N\83\89\83X
11 class GVOShipRouteList {
12 private:
13         typedef std::list<GVOShipRoute *> RouteList;
14         RouteList m_shipRouteList;
15         IGVOShipRouteListObserver * m_observer = nullptr;
16         size_t m_maxRouteCountWithoutFavorits = 30;     //!<@brief \82¨\8bC\82É\93ü\82è\82ð\8f\9c\8aO\82µ\82½\8dq\98H\95Û\91\90\94
17
18 public:
19         GVOShipRouteList() = default;
20         ~GVOShipRouteList();
21
22         void setObserver( IGVOShipRouteListObserver * observer )
23         {
24                 m_observer = observer;
25         }
26
27         void closeRoute();
28
29         void addRoutePoint(const GVONormalizedPoint point);
30
31         const RouteList & getList() const
32         {
33                 return m_shipRouteList;
34         }
35
36         //GVOShipRoute * getRouteAtIndex( int index )
37         //{
38         //      if ( m_shipRouteList.size() <= (size_t)index ) {
39         //              return NULL;
40         //      }
41         //      RouteList::iterator it;
42         //      it = m_shipRouteList.begin();
43         //      std::advance( it, index );
44         //      return *it;
45         //}
46
47         GVOShipRoute * getRouteAtReverseIndex( int reverseIndex )
48         {
49                 if ( m_shipRouteList.size() <= (size_t)reverseIndex ) {
50                         return nullptr;
51                 }
52                 RouteList::iterator it;
53                 it = m_shipRouteList.begin();
54                 std::advance( it, indexFromReverseIndex( reverseIndex ) );
55                 _ASSERT( *it != nullptr );
56                 return *it;
57         }
58
59         int indexFromShipRoute( GVOShipRoute & shipRoute )
60         {
61                 RouteList::iterator it;
62                 it = std::find( m_shipRouteList.begin(), m_shipRouteList.end(), &shipRoute );
63                 if ( it == m_shipRouteList.end() ) {
64                         return -1;
65                 }
66                 return std::distance( m_shipRouteList.begin(), it );
67         }
68
69         void removeShipRouteAtReverseIndex( int reverseIndex );
70
71         void clearAllItems();
72
73         void joinPreviousRouteAtReverseIndex( int reverseIndex );
74 private:
75         int indexFromReverseIndex( int reverseIndex ) const
76         {
77                 return m_shipRouteList.size() - reverseIndex - 1;
78         }
79         void addRoute();
80 };
81
82
83 //!@brief \8dq\98H\8aÇ\97\9d\83\8a\83X\83g\82ð\8aÄ\8e\8b\82·\82é\83C\83\93\83^\81[\83t\83F\81[\83X
84 class IGVOShipRouteListObserver {
85 public:
86         IGVOShipRouteListObserver() = default;
87         virtual ~IGVOShipRouteListObserver() = default;
88
89         virtual void onShipRouteListAddRoute( GVOShipRoute & shipRoute ) = 0;
90         virtual void onShipRouteListUpdateRoute( GVOShipRoute & shipRoute ) = 0;
91         virtual void onShipRouteListRemoveItem( GVOShipRoute & shipRoute ) = 0;
92         virtual void onShipRouteListRemoveAllItems() = 0;
93 };