1 ///////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2012-2017 by Bertram (Valyria Tear)
3 //                         All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See https://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 #ifndef __MENU_SKILLGRAPH_WINDOW__
11 #define __MENU_SKILLGRAPH_WINDOW__
12 
13 #include "skill_node_bottom_info.h"
14 
15 #include "common/global/global.h"
16 #include "common/gui/textbox.h"
17 
18 #include "common/gui/menu_window.h"
19 #include "common/gui/option.h"
20 
21 namespace vt_menu
22 {
23 
24 class MenuMode;
25 
26 namespace private_menu
27 {
28 
29 //! \brief The menu sub states
30 enum SKILLGRAPH_STATE {
31     SKILLGRAPH_STATE_NONE = 0,
32     SKILLGRAPH_STATE_CHAR = 1,
33     SKILLGRAPH_STATE_LIST = 2,
34     SKILLGRAPH_STATE_SIZE = 3
35 };
36 
37 /**
38 *** \brief handles showing the skill tree and the selection of new nodes.
39 *** The player will be able to use skill points and other items to get his/her way
40 *** through the skill tree and earns either new stats upgrades or new skills.
41 *** The "tree" is in fact a way point map.
42 **/
43 class SkillGraphWindow : public vt_gui::MenuWindow
44 {
45     friend class vt_menu::MenuMode;
46     //friend class SkillGraphState;
47 
48 public:
49     SkillGraphWindow();
50 
~SkillGraphWindow()51     virtual ~SkillGraphWindow() override
52     {
53     }
54 
55     //! \brief Performs updates
56     void Update() override;
57 
58     //! \brief Draws skill graph main window
59     void Draw() override;
60 
61     //! \brief Draws bottom window
62     void DrawBottomWindow();
63 
64     //! \brief Result of whether or not this window is active
65     //! \return true if this window is active
IsActive()66     bool IsActive() override {
67         return _active;
68     }
69 
70     //! \brief Set the active state of this window, and do any associated work.
71     void SetActive(bool is_active_state);
72 
GetSkillGraphState()73     SKILLGRAPH_STATE GetSkillGraphState() const {
74         return _skillgraph_state;
75     }
76 
77     //! \brief Set the character for this window using the character selection
78     //! \returns Whether the character was set
79     bool SetCharacter();
80 
81 private:
82     //! \brief The current selected character id
83     SKILLGRAPH_STATE _skillgraph_state;
84 
85     //! \brief The current selected character id
86     vt_global::GlobalCharacter* _selected_character;
87 
88     //! \brief the location pointer. this is loaded in the constructor
89     vt_video::StillImage _location_pointer;
90 
91     //! \brief The character icon. this is loaded in the constructor
92     vt_video::StillImage _character_icon;
93 
94     //! \brief Offsets for the current skill tree to view in the center of the window
95     vt_common::Position2D _current_offset;
96 
97     //! \brief The current centered view offsets
98     vt_common::Position2D _view_position;
99 
100     //! \brief The current index to the location the pointer is on
101     uint32_t _selected_node_id;
102 
103     //! \brief The current index to the location the character is on
104     uint32_t _character_node_id;
105 
106     //! \brief Indicates whether this window is active or not
107     bool _active;
108 
109     //! \brief The currently displayed skill nodes
110     std::vector<vt_global::SkillNode*> _displayed_skill_nodes;
111     //! \brief The currently displayed link between the nodes
112     std::vector<vt_common::Line2D> _displayed_node_links;
113     //! \brief The currenty displayed link between nodes obtained by the character
114     std::vector<vt_common::Line2D> _colored_displayed_node_links;
115 
116     //! \brief The skill node description text, icon, ...
117     SkillNodeBottomInfo _bottom_info;
118 
119     //! The character select option box
120     vt_gui::OptionBox _char_select;
121 
122     //! \brief Text to select character
123     vt_video::TextImage _select_character_text;
124 
125     //! \brief Initializes the character selector
126     void _InitCharSelect();
127 
128     //! \brief Update function when in character select state
129     void _UpdateSkillCharacterSelectState();
130 
131     //! \brief Update function when in skill graph list state
132     void _UpdateSkillGraphListState();
133 
134     //! \brief Draw function when in character select state
135     void _DrawCharacterState();
136 
137     //! \brief Draw function when in skill graph list state
138     void _DrawSkillGraphState();
139 
140     //! \brief Reset the view centered on the currently selected node.
141     void _ResetSkillGraphView();
142 
143     //! \brief Update the skill tree view based on the current offset information
144     void _UpdateSkillGraphView(bool scroll = true, bool force = false);
145 
146     //! \brief Handles navigation to the neighbor node
147     //! in given direction based on key press.
148     //! \returns Whether a new node was selected.
149     bool _Navigate();
150 
151     //! \brief Handles pressing confirm when on the skill graph.
152     //! This permits to buy nodes for XP.
153     void _HandleNodeTransaction();
154 };
155 
156 } // namespace private_menu
157 
158 } // namespace vt_menu
159 
160 #endif // __MENU_SKILLGRAPH_WINDOW__
161