1 ///////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2004-2010 by The Allacrost Project
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 http://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 /** ****************************************************************************
11 *** \file    shop_confirm.h
12 *** \author  Tyler Olsen, roots@allacrost.org
13 *** \brief   Header file for confirm interface of shop mode
14 ***
15 *** \note The contents of this file are near identical to the contents of
16 *** shop_leave.h. When making any changes to this file, please look to shop_leave.h
17 *** to see if it should have similar changes made.
18 *** ***************************************************************************/
19 
20 #ifndef __SHOP_CONFIRM_HEADER__
21 #define __SHOP_CONFIRM_HEADER__
22 
23 #include "defs.h"
24 #include "utils.h"
25 
26 #include "video.h"
27 #include "global.h"
28 
29 #include "shop_utils.h"
30 
31 namespace hoa_shop {
32 
33 namespace private_shop {
34 
35 /** ****************************************************************************
36 *** \brief The interface where the player confirms and completes their transaction
37 ***
38 *** After the player has selected their purchases, sales, and trades, they typically
39 *** enter this interface to finalize their choices and complete the transaction. There
40 *** are three primary actions that a player may chose from while in this interface.
41 ***
42 *** -# "Modify Order": allows the player to view the buy/sell/trade lists and change order quantities
43 *** -# "Clear Order": brings up a second confirmation that will clear all marked purchases, sales, and trades
44 *** -# "Complete Transaction": makes all purchases, sales, and trades as marked and can not be undone
45 ***
46 *** When "Modify Order" is selected, the cursor moves up to the current buy/sell/trade list being displayed.
47 *** The user can increase or decrease selected quantities in buy/sell lists, including setting the
48 *** quantity to zero, nullifying the purchase/sale. Shop objects with a zero quantity will be removed from
49 *** the buy/sell lists only after the confirm interface is no longer active, so the player can change their
50 *** mind and change the quantity back to a non-zero value without having to go back to the buy/sell interface
51 *** to re-add it. Trades work differently than buy/sell since there is no quantity associated with a trade.
52 *** Trades can be nullified and when this is done the behavior is similar to a zero quantity in that the
53 *** trade can be denullified within the confirm interface. Which display list is in view can be changed by
54 *** the player and the active display will have its header text in a more distinguished text style (header names
55 *** include "Purchases", "Sales", or "Trades"). The buy/sell/trade count data are also modified and displayed
56 *** in real time based on the player's actions of changing quantity amounts. The player can also view detailed
57 *** information about a selected item in the same manner that can be done in the buy and sell interfaces.
58 *** ***************************************************************************/
59 class ConfirmInterface : public ShopInterface {
60 	//! \brief States of the confirm interface used to determine how to process user input and what information to draw
61 	enum CONFIRM_STATE {
62 		CONFIRM_STATE_INVALID       = -1,
63 		CONFIRM_STATE_MAIN          =  0, //!< User input is focused on the main interface prompt
64 		CONFIRM_STATE_CLEAR         =  1, //!< User input is focused on the second confirmation prompt
65 		CONFIRM_STATE_LIST          =  2, //!< User input is focused on the buy/sell/trade list
66 		CONFIRM_STATE_INFO          =  3, //!< User input is focused on the detailed view of a selected object or trade
67 		CONFIRM_STATE_TOTAL         =  4
68 	};
69 
70 	//! \brief States that determine what transaction list is active and should be displayed
71 	enum ACTIVE_LIST {
72 		ACTIVE_LIST_INVALID  = -1,
73 		ACTIVE_LIST_BUY      =  0,
74 		ACTIVE_LIST_SELL     =  1,
75 		ACTIVE_LIST_TRADE    =  2,
76 		ACTIVE_LIST_TOTAL    =  3
77 	};
78 
79 public:
80 	ConfirmInterface();
81 
82 	~ConfirmInterface();
83 
84 	//! \brief Not used by this interface as all initialization is performed in the class constructor and MakeActive() method
Initialize()85 	void Initialize()
86 		{}
87 
88 	//! \brief Processes the buy/sell/trade lists and determines the counts and other information about each transaction
89 	void MakeActive();
90 
91 	//! \brief Resets all buy/sell/trade count stats and text and clears the list displays
92 	void TransactionNotification();
93 
94 	//! \brief Handles user input and internal state management
95 	void Update();
96 
97 	//! \brief Draws the visible displays, text, and GUI objects to the screen
98 	void Draw();
99 
100 private:
101 	//! \brief Stores the active state of the confirm interface
102 	CONFIRM_STATE _state;
103 
104 	//! \brief Keeps track of which type of list (buy/sell/trade) is currently active
105 	ACTIVE_LIST _active_list;
106 
107 	//! \brief True when there are no marked purchase, sale, or trade transactions
108 	bool _no_transactions;
109 
110 	//! \brief The total number of objects marked for purchase
111 	uint32 _buy_count;
112 
113 	//! \brief The number of unique objects marked for purchase (e.g. buying four healing potions count as one unique purchase)
114 	uint32 _buy_unique;
115 
116 	//! \brief The total number of objects marked for sale
117 	uint32 _sell_count;
118 
119 	//! \brief The number of unique objects marked for sale (e.g. selling four healing potions count as one unique sale)
120 	uint32 _sell_unique;
121 
122 	//! \brief The total number of marked trades
123 	uint32 _trade_count;
124 
125 	//! \brief The number of characters that will transact in at least one trade
126 	uint32 _trade_characters;
127 
128 	//! \brief Displays "Purchases" in different text styles based on whether or not the buy list is in view
129 	hoa_video::TextImage _buy_header;
130 
131 	//! \brief Displays the buy count/unique data below the buy header
132 	hoa_video::TextImage _buy_stats;
133 
134 	//! \brief Displays "Sales" in different text styles based on whether or not the sell list is in view
135 	hoa_video::TextImage _sell_header;
136 
137 	//! \brief Displays the sell count/unique data below the sell header
138 	hoa_video::TextImage _sell_stats;
139 
140 	//! \brief Displays "Trades" in different text styles based on whether or not the trade list is in view
141 	hoa_video::TextImage _trade_header;
142 
143 	//! \brief Displays the trade count/characters data below the trade header
144 	hoa_video::TextImage _trade_stats;
145 
146 	//! \brief List header text for the name field
147 	hoa_video::TextImage _name_header;
148 
149 	//! \brief List header text for the list of object properties (refer to the BuyListDisplay class)
150 	hoa_gui::OptionBox _properties_header;
151 
152 	//! \brief Text to display in the middle window when the selected transaction list is empty
153 	hoa_video::TextImage _empty_list_text;
154 
155 	//! \brief Text displayed in the lower window when there are no marked transactions of any type
156 	hoa_video::TextImage _no_transactions_text;
157 
158 	//! \brief A display of all wares marked for purchase and their properties
159 	BuyListDisplay* _buy_list_display;
160 
161 	//! \brief A display of all inventory objects marked for sale and their properties
162 	SellListDisplay* _sell_list_display;
163 
164 	// TODO: Add once trade interface is working and this class is defined
165 	// TradeListDisplay* _trade_list_display;
166 
167 	//! \brief Text that prompts the user for their desired action
168 	hoa_video::TextImage _main_prompt;
169 
170 	//! \brief The list of actions that the user can take
171 	hoa_gui::OptionBox _main_actions;
172 
173 	//! \brief Confirmation message for when the user selects the "Clear Order" action
174 	hoa_video::TextImage _clear_prompt;
175 
176 	//! \brief Confirmation actions for when the user selects the "Clear Order" action
177 	hoa_gui::OptionBox _clear_actions;
178 
179 private:
180 	/** \brief Changes the current state and modifies other members and display properties appropriately
181 	*** \param new_state The new state to change the confirm interface to
182 	**/
183 	void _ChangeState(CONFIRM_STATE new_state);
184 
185 	//! \brief Changes the active transaction list and updates the transaction header texts
186 	void _CycleActiveTransactionList();
187 
188 	//! \brief An update helper function used to change the buy list selection or selected object quantity
189 	void _UpdateBuyList();
190 
191 	//! \brief An update helper function used to change the sell list selection or selected object quantity
192 	void _UpdateSellList();
193 
194 	//! \brief An update helper function used to change the trade list selection or selected trade
195 	void _UpdateTradeList();
196 
197 	/** \brief Changes the buy quantity of a selected object and updates and re-renders buy stats text
198 	*** \param less_or_more False to decrease the quantity, true to increase it
199 	*** \param amount The amount to decrease/increase the quantity by (default value == 1)
200 	*** \return False if no quantity change could take place, true if a quantity change did occur
201 	*** \note This function signature is identical to the function of the same name as the BuyListDisplay class.
202 	*** This method serves as a wrapper to that class with the additional feature of automatically updating
203 	*** buy stats data and re-rendering the stats text as appropriate.
204 	**/
205 	bool ChangeBuyQuantity(bool less_or_more, uint32 amount = 1);
206 
207 	/** \brief Changes the sell quantity of a selected object and updates and re-renders buy stats text
208 	*** \param less_or_more False to decrease the quantity, true to increase it
209 	*** \param amount The amount to decrease/increase the quantity by (default value == 1)
210 	*** \return False if no quantity change could take place, true if a quantity change did occur
211 	*** \note This function signature is identical to the function of the same name as the SellListDisplay class.
212 	*** This method serves as a wrapper to that class with the additional feature of automatically updating
213 	*** sell stats data and re-rendering the stats text as appropriate.
214 	**/
215 	bool ChangeSellQuantity(bool less_or_more, uint32 amount = 1);
216 
217 	//! \brief Re-renders the text image for buy stats using the current buy data
218 	void _RenderBuyStats();
219 
220 	//! \brief Re-renders the text image for sell stats using the current sell data
221 	void _RenderSellStats();
222 
223 	//! \brief Re-renders the text image for trade stats using the current trade data
224 	void _RenderTradeStats();
225 
226 	//! \brief Executes a clear order command from the player, clearing all marked transactions
227 	void _ClearOrder();
228 
229 	//! \brief Performs necessary clean-ups to interface state information and marked transactions when the player leaves this interface
230 	void _LeaveInterface();
231 }; // class ConfirmInterface : public ShopInterface
232 
233 } // namespace private_shop
234 
235 } // namespace hoa_shop
236 
237 #endif // __SHOP_CONFIRM_HEADER__
238