1 ///////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2004-2011 by The Allacrost Project
3 //            Copyright (C) 2012-2016 by Bertram (Valyria Tear)
4 //                         All Rights Reserved
5 //
6 // This code is licensed under the GNU GPL version 2. It is free software
7 // and you may modify it and/or redistribute it under the terms of this license.
8 // See https://www.gnu.org/copyleft/gpl.html for details.
9 ///////////////////////////////////////////////////////////////////////////////
10 
11 /** ****************************************************************************
12 *** \file    shop_trade.h
13 *** \author  Tyler Olsen, roots@allacrost.org
14 *** \author  Josh Niehenke, jnskeer@gmail.com
15 *** \author  Yohann Ferreira, yohann ferreira orange fr
16 *** \brief   Header file for sell interface of shop mode
17 *** ***************************************************************************/
18 
19 #ifndef __SHOP_TRADE_HEADER__
20 #define __SHOP_TRADE_HEADER__
21 
22 #include "common/global/global.h"
23 
24 #include "shop_utils.h"
25 
26 namespace vt_shop
27 {
28 
29 namespace private_shop
30 {
31 
32 class TradeListDisplay;
33 
34 /** ****************************************************************************
35 *** \brief Manages the shop when it is in buy mode and enables the player to view and purchase wares
36 ***
37 *** This interface displays the list of objects that are available for sale. It organizes
38 *** these objects based on their object type/category (item, weapon, etc.) and allows the
39 *** player to switch between views of these different categories. This interface also displays
40 *** information about the currently selected object such as its description, statistical
41 *** ratings, usable characters, etc.
42 *** ***************************************************************************/
43 class TradeInterface : public ShopInterface
44 {
45 public:
46     TradeInterface();
47     virtual ~TradeInterface() override;
48 
49     //! \brief (Re)initializes the data containers and GUI objects to be used
50     void Reinitialize() override;
51 
52     //! \brief Sets the selected object for the ShopObjectViewer class
53     void MakeActive() override;
54 
55     //! \brief Reconstructs all buy display lists and resets the current category
56     void TransactionNotification() override;
57 
58     /** \brief Takes all necessary action for when the active view mode is to be altered
59     *** \param new_mode The new view mode to set
60     **/
61     void ChangeViewMode(SHOP_VIEW_MODE new_mode);
62 
63     //! \brief Processes user input and sends appropriate commands to helper class objects
64     void Update() override;
65 
66     //! \brief Draws the GUI elements to the screen
67     void Draw() override;
68 
69 private:
70     //! \brief Stores the active view state of the buy interface
71     SHOP_VIEW_MODE _view_mode;
72 
73     //! \brief A pointer to the currently selected object in the active list display
74     ShopObject *_selected_object;
75 
76     //! \brief A bit vector that represents the types of merchandise that the shop deals in (items, weapons, etc)
77     uint8_t _trade_deal_types;
78 
79     //! \brief Retains the number of object categories for sale
80     uint32_t _number_categories;
81 
82     //! \brief Serves as an index to the following containers: _category_names, _category_icons, and _list_displays
83     uint32_t _current_category;
84 
85     //! \brief Header text for the category field
86     vt_video::TextImage _category_header;
87 
88     //! \brief Header text for the name field
89     vt_video::TextImage _name_header;
90 
91     //! \brief Header text for the list of object properties (refer to the BuyListDisplay class)
92     vt_gui::OptionBox _properties_header;
93 
94     //! \brief String representations of all object categories where purchases are available
95     std::vector<vt_utils::ustring> _category_names;
96 
97     //! \brief A pointer to the icon image for each purchasable object category
98     std::vector<vt_video::StillImage *> _category_icons;
99 
100     //! \brief Display manager for the current category of objects selected
101     ObjectCategoryDisplay _category_display;
102 
103     //! \brief Class objects used to display the object data to the player
104     std::vector<TradeListDisplay *> _list_displays;
105 
106     //! \brief A copy of the selected object's icon, scaled to 1/4 size
107     vt_video::StillImage _selected_icon;
108 
109     //! \brief Text image of the selected object's name
110     vt_video::TextImage _selected_name;
111 
112     //! \brief A single row option box containing the selected object's properties
113     vt_gui::OptionBox _selected_properties;
114 
115     /**
116     ***  Update the available deal types. Called only in _RefreshItemCategories().
117     */
118     void _UpdateAvailableTradeDealTypes();
119 
120     /**
121     *** Refresh the available item categories.
122     **/
123     void _RefreshItemCategories();
124 
125     /** \brief Changes the current category and object list that is being displayed
126     *** \param left_or_right False to move the category to the left, or true for the right
127     *** \return True if the _selected_object member has changed
128     **/
129     bool _ChangeCategory(bool left_or_right);
130 
131     /** \brief Changes the current selection in the object list
132     *** \param up_or_down False to move the selection cursor up, or true to move it down
133     *** \return True if the _selected_object member has changed
134     **/
135     bool _ChangeSelection(bool up_or_down);
136 }; // class TradeInterface : public ShopInterface
137 
138 
139 /** ****************************************************************************
140 *** \brief A display class that manages and draws lists of objects that may be marked to buy
141 ***
142 *** The "identify" list contains a 0.25x size icon of the object and the object's name.
143 *** The "properties" list contains price, shop stock, amount owned by the player, and
144 *** requested buy quantity. Only buy quantity requires regular refreshing based upon
145 *** the player's actions while the buy interface is active.
146 *** ***************************************************************************/
147 class TradeListDisplay : public ObjectListDisplay
148 {
149 public:
TradeListDisplay()150     TradeListDisplay()
151     {}
152 
~TradeListDisplay()153     ~TradeListDisplay()
154     {}
155 
156     //! \brief Reconstructs all option box entries from the object data
157     void ReconstructList();
158 
159     /** \brief Changes the buy count of the selected object, refreshes the list entry, and updates financial totals
160     *** \param less_or_more False to decrease the quantity, true to increase it
161     *** \param amount The amount to decrease/increase the quantity by (default value == 1)
162     *** \return False if no quantity change could take place, true if a quantity change did occur
163     *** \note Even if the function returns true, there is no guarantee that the requested amount
164     *** was fully met. For example, if the function is asked to increase the buy quantity by 10 but
165     *** the shop only has 6 instances of the selected object in stock, the function will increase
166     *** the quantity by 6 (not 10) and return true.
167     **/
168     bool ChangeTradeQuantity(bool less_or_more, uint32_t amount = 1);
169 }; // class TradeListDisplay : public ObjectListDisplay
170 
171 } // namespace private_shop
172 
173 } // namespace vt_shop
174 
175 #endif // __SHOP_TRADE_HEADER__
176