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.cpp
12 *** \author Tyler Olsen, roots@allacrost.org
13 *** \brief Source 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.cpp. When making any changes to this file, please look to shop_leave.cpp
17 *** to see if it should have similar changes made.
18 *** ***************************************************************************/
19
20 #include "defs.h"
21 #include "utils.h"
22
23 #include "audio.h"
24 #include "input.h"
25 #include "system.h"
26 #include "video.h"
27
28 #include "shop.h"
29 #include "shop_confirm.h"
30 #include "shop_buy.h"
31 #include "shop_sell.h"
32 #include "shop_trade.h"
33
34 using namespace std;
35
36 using namespace hoa_utils;
37 using namespace hoa_audio;
38 using namespace hoa_input;
39 using namespace hoa_system;
40 using namespace hoa_video;
41 using namespace hoa_gui;
42
43 namespace hoa_shop {
44
45 namespace private_shop {
46
47 // *****************************************************************************
48 // ***** ConfirmInterface class methods
49 // *****************************************************************************
50
ConfirmInterface()51 ConfirmInterface::ConfirmInterface() :
52 _state(CONFIRM_STATE_MAIN),
53 _active_list(ACTIVE_LIST_BUY),
54 _no_transactions(true),
55 _buy_count(0),
56 _buy_unique(0),
57 _sell_count(0),
58 _sell_unique(0),
59 _trade_count(0),
60 _trade_characters(0),
61 _buy_list_display(NULL),
62 _sell_list_display(NULL)
63 {
64 TextStyle stats_style("text20");
65
66 _buy_header.SetStyle(TextStyle("title22", Color::white));
67 _buy_header.SetText(UTranslate("Purchases"));
68 _buy_stats.SetStyle(stats_style);
69
70 _sell_header.SetStyle(TextStyle("title22", Color::white));
71 _sell_header.SetText(UTranslate("Sales"));
72 _sell_stats.SetStyle(stats_style);
73
74 _trade_header.SetStyle(TextStyle("title22", Color::white));
75 _trade_header.SetText(UTranslate("Trades"));
76 _trade_stats.SetStyle(stats_style);
77
78 _name_header.SetStyle(TextStyle("title24"));
79 _name_header.SetText(UTranslate("Name"));
80
81 _properties_header.SetOwner(ShopMode::CurrentInstance()->GetMiddleWindow());
82 _properties_header.SetPosition(480.0f, 390.0f);
83 _properties_header.SetDimensions(300.0f, 30.0f, 4, 1, 4, 1);
84 _properties_header.SetOptionAlignment(VIDEO_X_RIGHT, VIDEO_Y_CENTER);
85 _properties_header.SetTextStyle(TextStyle("title24"));
86 _properties_header.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
87 _properties_header.AddOption(UTranslate("Price"));
88 _properties_header.AddOption(UTranslate("Stock"));
89 _properties_header.AddOption(UTranslate("Own"));
90 _properties_header.AddOption(MakeUnicodeString(""));
91
92 _empty_list_text.SetStyle(TextStyle("text24"));
93 _empty_list_text.SetText(UTranslate("No marked transactions."));
94
95 _buy_list_display = new BuyListDisplay();
96 _sell_list_display = new SellListDisplay();
97
98 _no_transactions_text.SetStyle(TextStyle("text24"));
99 _no_transactions_text.SetText(UTranslate("There are no marked purchases, sales, or trades."));
100
101 _main_prompt.SetStyle(TextStyle("text24"));
102 _main_prompt.SetText(UTranslate("Will that be all?"));
103 _main_actions.SetOwner(ShopMode::CurrentInstance()->GetBottomWindow());
104 _main_actions.SetPosition(60.0f, 80.0f);
105 _main_actions.SetDimensions(600.0f, 40.0f, 3, 1, 3, 1);
106 _main_actions.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
107 _main_actions.SetTextStyle(TextStyle("title24"));
108 _main_actions.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
109 _main_actions.SetCursorOffset(-55.0f, 30.0f);
110 _main_actions.SetHorizontalWrapMode(VIDEO_WRAP_MODE_NONE);
111 _main_actions.AddOption(UTranslate("Modify Order"));
112 _main_actions.AddOption(UTranslate("Clear Order"));
113 _main_actions.AddOption(UTranslate("Complete Transaction"));
114 _main_actions.SetSelection(0);
115
116 _clear_prompt.SetStyle(TextStyle("text24"));
117 _clear_prompt.SetText(UTranslate("This will remove all marked purchases, sales, and trades. Are you sure?"));
118 _clear_actions.SetOwner(ShopMode::CurrentInstance()->GetBottomWindow());
119 _clear_actions.SetPosition(60.0f, 80.0f);
120 _clear_actions.SetDimensions(400.0f, 40.0f, 2, 1, 2, 1);
121 _clear_actions.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
122 _clear_actions.SetTextStyle(TextStyle("title24"));
123 _clear_actions.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
124 _clear_actions.SetCursorOffset(-55.0f, 30.0f);
125 _clear_actions.SetHorizontalWrapMode(VIDEO_WRAP_MODE_NONE);
126 _clear_actions.AddOption(UTranslate("No"));
127 _clear_actions.AddOption(UTranslate("Yes"));
128 _clear_actions.SetSelection(0);
129 }
130
131
132
~ConfirmInterface()133 ConfirmInterface::~ConfirmInterface() {
134 if (_buy_list_display != NULL)
135 delete _buy_list_display;
136 if (_sell_list_display != NULL)
137 delete _sell_list_display;
138
139 _buy_list_display = NULL;
140 _sell_list_display = NULL;
141 }
142
143
144
MakeActive()145 void ConfirmInterface::MakeActive() {
146 map<uint32, ShopObject*>* buy_list = ShopMode::CurrentInstance()->GetBuyList();
147 map<uint32, ShopObject*>* sell_list = ShopMode::CurrentInstance()->GetSellList();
148 // TODO: Get a container of all trades
149
150 // Vector constructs required by the BuyListDisplay/SellListDisplay classes
151 vector<ShopObject*> buy_vector;
152 vector<ShopObject*> sell_vector;
153
154 buy_vector.reserve(buy_list->size());
155 sell_vector.reserve(sell_list->size());
156
157 _buy_count = 0;
158 _buy_unique = 0;
159 for (map<uint32, ShopObject*>::iterator i = buy_list->begin(); i != buy_list->end(); i++) {
160 _buy_unique++;
161 _buy_count += i->second->GetBuyCount();
162 buy_vector.push_back(i->second);
163 }
164
165 _sell_count = 0;
166 _sell_unique = 0;
167 for (map<uint32, ShopObject*>::iterator i = sell_list->begin(); i != sell_list->end(); i++) {
168 _sell_unique++;
169 _sell_count += i->second->GetSellCount();
170 sell_vector.push_back(i->second);
171 }
172
173 _trade_count = 0;
174 _trade_characters = 0;
175 // TODO: Iterate through the trade container similar to buy and sell containers
176
177 _buy_list_display->PopulateList(buy_vector);
178 _sell_list_display->PopulateList(sell_vector);
179
180 // Determine which active list should be initially shown and change properties as needed
181 if (_buy_count != 0) {
182 _no_transactions = false;
183 _active_list = ACTIVE_LIST_BUY;
184 _buy_header.SetStyle(TextStyle("title24", Color::yellow));
185 _sell_header.SetStyle(TextStyle("title22", Color::white));
186 _trade_header.SetStyle(TextStyle("title22", Color::white));
187 _properties_header.SetOptionText(3, UTranslate("Buy"));
188 }
189 else if (_sell_count != 0) {
190 _no_transactions = false;
191 _active_list = ACTIVE_LIST_SELL;
192 _buy_header.SetStyle(TextStyle("title22", Color::white));
193 _sell_header.SetStyle(TextStyle("title24", Color::yellow));
194 _trade_header.SetStyle(TextStyle("title22", Color::white));
195 _properties_header.SetOptionText(3, UTranslate("Sell"));
196 }
197 else if (_trade_count != 0) {
198 _no_transactions = false;
199 _active_list = ACTIVE_LIST_TRADE;
200 _buy_header.SetStyle(TextStyle("title22", Color::white));
201 _sell_header.SetStyle(TextStyle("title22", Color::white));
202 _trade_header.SetStyle(TextStyle("title24", Color::yellow));
203 }
204 else {
205 _no_transactions = true;
206 _active_list = ACTIVE_LIST_BUY;
207 _buy_header.SetStyle(TextStyle("title24", Color::yellow));
208 _sell_header.SetStyle(TextStyle("title22", Color::white));
209 _trade_header.SetStyle(TextStyle("title22", Color::white));
210 _properties_header.SetOptionText(3, UTranslate("Buy"));
211 }
212
213 _RenderBuyStats();
214 _RenderSellStats();
215 _RenderTradeStats();
216
217 _state = CONFIRM_STATE_MAIN;
218 _main_actions.SetSelection(0);
219 _clear_actions.SetSelection(0);
220
221 _main_actions.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
222 _clear_actions.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
223 _buy_list_display->GetIdentifyList().SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
224 _sell_list_display->GetIdentifyList().SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
225
226 ShopMode::CurrentInstance()->ObjectViewer()->SetSelectedObject(NULL);
227 ShopMode::CurrentInstance()->ObjectViewer()->ChangeViewMode(SHOP_VIEW_MODE_INFO);
228 } // void ConfirmInterface::MakeActive()
229
230
231
TransactionNotification()232 void ConfirmInterface::TransactionNotification() {
233 _buy_count = 0;
234 _buy_unique = 0;
235 _sell_count = 0;
236 _sell_unique = 0;
237 _trade_count = 0;
238 _trade_characters = 0;
239 _buy_list_display->Clear();
240 _sell_list_display->Clear();
241 _no_transactions = true;
242 _RenderBuyStats();
243 _RenderSellStats();
244 _RenderTradeStats();
245 }
246
247
248
Update()249 void ConfirmInterface::Update() {
250 _main_actions.Update();
251 _clear_actions.Update();
252 _buy_list_display->Update();
253 _sell_list_display->Update();
254
255 // A swap press changes the active transaction list being shown. It takes precedence over all other
256 // input events. Only the "info" state ignores this command because the transaction list is not visible
257 // while in this state
258 if ((InputManager->SwapPress()) && (_state != CONFIRM_STATE_INFO)) {
259 _CycleActiveTransactionList();
260 return;
261 }
262
263 // If no transactions are available the user can not modify, clear, or complete them. Perform no other updates
264 // or processing of user input except for confirm and cancel presses to leave the interface
265 if (_no_transactions == true) {
266 if (InputManager->ConfirmPress() || InputManager->CancelPress()) {
267 _LeaveInterface();
268 }
269 return;
270 }
271
272 if (_state == CONFIRM_STATE_MAIN) {
273 if (InputManager->CancelPress()) {
274 _LeaveInterface();
275 return;
276 }
277
278 else if (InputManager->ConfirmPress()) {
279 switch (_main_actions.GetSelection()) {
280 case 0: // "Modify Order"
281 _ChangeState(CONFIRM_STATE_LIST);
282 return;
283 case 1: // "Clear Order"
284 _ChangeState(CONFIRM_STATE_CLEAR);
285 return;
286 case 2: // "Complete Transaction"
287 // Make sure that at least one purchase/sale/trade is going to take place
288 if ((_buy_count != 0) || (_sell_count != 0) || (_trade_count != 0)) {
289 ShopMode::CurrentInstance()->Media()->GetSound("coins")->Play();
290 // Calling ShopMode::CompleteTransaction() will call the TransactionNotification() method
291 // for this interface class. which will reset all transaction counts and list displays.
292 ShopMode::CurrentInstance()->CompleteTransaction();
293 }
294 // Otherwise simply clear the order without a confirmation prompt
295 else {
296 _ClearOrder();
297 }
298 return;
299 default:
300 IF_PRINT_WARNING(SHOP_DEBUG) << "invalid selection in primary action options: "
301 << _main_actions.GetSelection() << endl;
302 return;
303 }
304 }
305
306 else if (InputManager->LeftPress()) {
307 _main_actions.InputLeft();
308 }
309 else if (InputManager->RightPress()) {
310 _main_actions.InputRight();
311 }
312 }
313
314 else if (_state == CONFIRM_STATE_CLEAR) {
315 if (InputManager->ConfirmPress()) {
316 switch (_clear_actions.GetSelection()) {
317 case 0: // "No"
318 _ChangeState(CONFIRM_STATE_MAIN);
319 return;
320 case 1: // "Yes"
321 _ClearOrder();
322 _ChangeState(CONFIRM_STATE_MAIN);
323 return;
324 default:
325 IF_PRINT_WARNING(SHOP_DEBUG) << "invalid selection in clear action options: "
326 << _clear_actions.GetSelection() << endl;
327 return;
328 }
329 }
330 else if (InputManager->ConfirmPress()) {
331 _ChangeState(CONFIRM_STATE_MAIN);
332 }
333 else if (InputManager->LeftPress()) {
334 _clear_actions.InputLeft();
335 }
336 else if (InputManager->RightPress()) {
337 _clear_actions.InputRight();
338 }
339 }
340
341 else if (_state == CONFIRM_STATE_LIST) {
342 if (InputManager->CancelPress()) {
343 _ChangeState(CONFIRM_STATE_MAIN);
344 return;
345 }
346
347 switch (_active_list) {
348 case ACTIVE_LIST_BUY:
349 _UpdateBuyList();
350 return;
351 case ACTIVE_LIST_SELL:
352 _UpdateSellList();
353 return;
354 case ACTIVE_LIST_TRADE:
355 _UpdateTradeList();
356 return;
357 default:
358 IF_PRINT_WARNING(SHOP_DEBUG) << "invalid transaction list was active: "
359 << _active_list << endl;
360 return;
361 }
362 }
363
364 else if (_state == CONFIRM_STATE_INFO) {
365 if (InputManager->ConfirmPress() || InputManager->CancelPress()) {
366 _ChangeState(CONFIRM_STATE_LIST);
367 return;
368 }
369 }
370
371 else {
372 IF_PRINT_WARNING(SHOP_DEBUG) << "invalid confirm state was active: " << _state << endl;
373 _state = CONFIRM_STATE_MAIN;
374 }
375 } // void ConfirmInterface::Update()
376
377
378
Draw()379 void ConfirmInterface::Draw() {
380 // Draw the contents of the middle window. Either selected object information or the active transaction list
381 if (_state == CONFIRM_STATE_INFO) {
382 ShopMode::CurrentInstance()->ObjectViewer()->Draw();
383 }
384 else {
385 // Draw the transaction type headers and stats
386 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
387 VideoManager->Move(140.0f, 525.0f);
388 _buy_header.Draw();
389 VideoManager->SetDrawFlags(VIDEO_Y_TOP, 0);
390 _buy_stats.Draw();
391
392 VideoManager->SetDrawFlags(VIDEO_Y_BOTTOM, 0);
393 VideoManager->MoveRelative(0.0f, -105.0f);
394 _sell_header.Draw();
395 VideoManager->SetDrawFlags(VIDEO_Y_TOP, 0);
396 _sell_stats.Draw();
397
398 VideoManager->SetDrawFlags(VIDEO_Y_BOTTOM, 0);
399 VideoManager->MoveRelative(0.0f, -105.0f);
400 _trade_header.Draw();
401 VideoManager->SetDrawFlags(VIDEO_Y_TOP, 0);
402 _trade_stats.Draw();
403
404 // Draw the list headers and contents
405 if ((_active_list == ACTIVE_LIST_BUY) && (_buy_list_display->IsListEmpty() == false)) {
406 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
407 VideoManager->Move(295.0f, 558.0f);
408 _name_header.Draw();
409
410 _properties_header.Draw();
411 _buy_list_display->Draw();
412 }
413 else if ((_active_list == ACTIVE_LIST_SELL) && (_sell_list_display->IsListEmpty() == false)) {
414 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
415 VideoManager->Move(295.0f, 558.0f);
416 _name_header.Draw();
417
418 _properties_header.Draw();
419 _sell_list_display->Draw();
420 }
421 else if ((_active_list == ACTIVE_LIST_TRADE) && (_trade_count != 0)) {
422 // TODO: once trade support is added, change above condition `(_trade_count != 0)`
423 // to a check on the trade list display's empty status
424 }
425 else { // The active list is empty
426 VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_CENTER, 0);
427 VideoManager->Move(560.0f, 405.0f);
428 _empty_list_text.Draw();
429 }
430 }
431
432 // Draw the contents of the lower window. Either the clear prompt/actions or the main prompt/actions
433 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_CENTER, 0);
434 VideoManager->Move(160.0f, 180.0f);
435 if (_no_transactions == true) {
436 _no_transactions_text.Draw();
437 }
438 else if (_state == CONFIRM_STATE_CLEAR) {
439 _clear_prompt.Draw();
440 _clear_actions.Draw();
441 }
442 else {
443 _main_prompt.Draw();
444 _main_actions.Draw();
445 }
446 } // void ConfirmInterface::Draw()
447
448
449
_ChangeState(CONFIRM_STATE new_state)450 void ConfirmInterface::_ChangeState(CONFIRM_STATE new_state) {
451 if (_state == new_state) {
452 IF_PRINT_WARNING(SHOP_DEBUG) << "new state was the same as the current state: " << _state << endl;
453 return;
454 }
455
456 // Modify appropriate display properties of former state
457 if (_state == CONFIRM_STATE_MAIN) {
458 _main_actions.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
459 }
460 else if (_state == CONFIRM_STATE_CLEAR) {
461 _clear_actions.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
462 }
463 else if (_state == CONFIRM_STATE_LIST) {
464 _buy_list_display->GetIdentifyList().SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
465 _sell_list_display->GetIdentifyList().SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
466 }
467 else if (_state == CONFIRM_STATE_INFO) {
468 ShopMode::CurrentInstance()->ObjectViewer()->SetSelectedObject(NULL);
469 }
470
471 // Modify appropriate display properties of new state
472 if (new_state == CONFIRM_STATE_MAIN) {
473 _main_actions.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
474 }
475 else if (new_state == CONFIRM_STATE_CLEAR) {
476 _clear_actions.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
477 _clear_actions.SetSelection(0);
478 }
479 else if (new_state == CONFIRM_STATE_LIST) {
480 _buy_list_display->GetIdentifyList().SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
481 _sell_list_display->GetIdentifyList().SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
482 }
483 else if (new_state == CONFIRM_STATE_INFO) {
484 ShopObject* selected_object = NULL;
485 switch (_active_list) {
486 case ACTIVE_LIST_BUY:
487 selected_object = _buy_list_display->GetSelectedObject();
488 break;
489 case ACTIVE_LIST_SELL:
490 selected_object = _sell_list_display->GetSelectedObject();
491 break;
492 case ACTIVE_LIST_TRADE:
493 // TODO: implement once trade interface is complete
494 break;
495 default:
496 IF_PRINT_WARNING(SHOP_DEBUG) << "invalid transaction list was active: " << _active_list << endl;
497 break;
498 }
499 ShopMode::CurrentInstance()->ObjectViewer()->SetSelectedObject(selected_object);
500 }
501 _state = new_state;
502 } // void ConfirmInterface::_ChangeState(CONFIRM_STATE new_state)
503
504
505
_CycleActiveTransactionList()506 void ConfirmInterface::_CycleActiveTransactionList() {
507 TextStyle highlight("title24", Color::yellow);
508 TextStyle standard("title22", Color::white);
509
510 if (_active_list == ACTIVE_LIST_BUY) {
511 _active_list = ACTIVE_LIST_SELL;
512 _buy_header.SetStyle(standard);
513 _sell_header.SetStyle(highlight);
514 _properties_header.SetOptionText(3, UTranslate("Sell"));
515 }
516 else if (_active_list == ACTIVE_LIST_SELL) {
517 _active_list = ACTIVE_LIST_TRADE;
518 _sell_header.SetStyle(standard);
519 _trade_header.SetStyle(highlight);
520 }
521 else if (_active_list == ACTIVE_LIST_TRADE) {
522 _active_list = ACTIVE_LIST_BUY;
523 _trade_header.SetStyle(standard);
524 _buy_header.SetStyle(highlight);
525 _properties_header.SetOptionText(3, UTranslate("Buy"));
526 }
527 else {
528 IF_PRINT_WARNING(SHOP_DEBUG) << "invalid transaction list was active: " << _active_list << endl;
529 }
530 }
531
532
533
_UpdateBuyList()534 void ConfirmInterface::_UpdateBuyList() {
535 if (_buy_list_display->IsListEmpty() == true)
536 return;
537
538 if (InputManager->ConfirmPress()) {
539 _ChangeState(CONFIRM_STATE_INFO);
540 }
541 else if (InputManager->UpPress()) {
542 _buy_list_display->InputUp();
543 }
544 else if (InputManager->DownPress()) {
545 _buy_list_display->InputDown();
546 }
547 else if (InputManager->LeftPress()) {
548 if (ChangeBuyQuantity(false) == true)
549 ShopMode::CurrentInstance()->Media()->GetSound("confirm")->Play();
550 else
551 ShopMode::CurrentInstance()->Media()->GetSound("bump")->Play();
552 }
553 else if (InputManager->RightPress()) {
554 if (ChangeBuyQuantity(true) == true)
555 ShopMode::CurrentInstance()->Media()->GetSound("confirm")->Play();
556 else
557 ShopMode::CurrentInstance()->Media()->GetSound("bump")->Play();
558 }
559 else if (InputManager->LeftSelectPress()) {
560 if (ChangeBuyQuantity(false, 10) == true)
561 ShopMode::CurrentInstance()->Media()->GetSound("confirm")->Play();
562 else
563 ShopMode::CurrentInstance()->Media()->GetSound("bump")->Play();
564 }
565 else if (InputManager->RightSelectPress()) {
566 if (ChangeBuyQuantity(true, 10) == true)
567 ShopMode::CurrentInstance()->Media()->GetSound("confirm")->Play();
568 else
569 ShopMode::CurrentInstance()->Media()->GetSound("bump")->Play();
570 }
571 }
572
573
574
_UpdateSellList()575 void ConfirmInterface::_UpdateSellList() {
576 if (_sell_list_display->IsListEmpty() == true)
577 return;
578
579 if (InputManager->ConfirmPress()) {
580 _ChangeState(CONFIRM_STATE_INFO);
581 }
582 else if (InputManager->UpPress()) {
583 _sell_list_display->InputUp();
584 }
585 else if (InputManager->DownPress()) {
586 _sell_list_display->InputDown();
587 }
588 else if (InputManager->LeftPress()) {
589 if (ChangeSellQuantity(false) == true)
590 ShopMode::CurrentInstance()->Media()->GetSound("confirm")->Play();
591 else
592 ShopMode::CurrentInstance()->Media()->GetSound("bump")->Play();
593 }
594 else if (InputManager->RightPress()) {
595 if (ChangeSellQuantity(true) == true)
596 ShopMode::CurrentInstance()->Media()->GetSound("confirm")->Play();
597 else
598 ShopMode::CurrentInstance()->Media()->GetSound("bump")->Play();
599 }
600 else if (InputManager->LeftSelectPress()) {
601 if (ChangeSellQuantity(false, SHOP_BATCH_COUNT) == true)
602 ShopMode::CurrentInstance()->Media()->GetSound("confirm")->Play();
603 else
604 ShopMode::CurrentInstance()->Media()->GetSound("bump")->Play();
605 }
606 else if (InputManager->RightSelectPress()) {
607 if (ChangeSellQuantity(true, SHOP_BATCH_COUNT) == true)
608 ShopMode::CurrentInstance()->Media()->GetSound("confirm")->Play();
609 else
610 ShopMode::CurrentInstance()->Media()->GetSound("bump")->Play();
611 }
612 }
613
614
615
_UpdateTradeList()616 void ConfirmInterface::_UpdateTradeList() {
617 // TODO: implement this method when trade interface is complete
618 }
619
620
621
ChangeBuyQuantity(bool less_or_more,uint32 amount)622 bool ConfirmInterface::ChangeBuyQuantity(bool less_or_more, uint32 amount) {
623 ShopObject* obj = _buy_list_display->GetSelectedObject();
624 int32 old_count = obj->GetBuyCount();
625
626 if (_buy_list_display->ChangeBuyQuantity(less_or_more, amount) == false) {
627 return false;
628 }
629
630 // new_count should never equal old_count if BuyListDisplay::ChangeBuyQuantity() returned true
631 int32 new_count = obj->GetBuyCount();
632
633 // Update the unique and count buy members and re-render the stats
634 if (old_count == 0)
635 _buy_unique++;
636 if (new_count == 0)
637 _buy_unique--;
638 _buy_count += (new_count - old_count);
639 _RenderBuyStats();
640 return true;
641 }
642
643
644
ChangeSellQuantity(bool less_or_more,uint32 amount)645 bool ConfirmInterface::ChangeSellQuantity(bool less_or_more, uint32 amount) {
646 ShopObject* obj = _sell_list_display->GetSelectedObject();
647 int32 old_count = obj->GetSellCount();
648
649 if (_sell_list_display->ChangeSellQuantity(less_or_more, amount) == false) {
650 return false;
651 }
652
653 // new_count should never equal old_count if SellListDisplay::ChangeSellQuantity() returned true
654 int32 new_count = obj->GetSellCount();
655
656 // Update the unique and count sell members and re-render the stats
657 if (old_count == 0)
658 _sell_unique++;
659 if (new_count == 0)
660 _sell_unique--;
661 _sell_count += (new_count - old_count);
662 _RenderSellStats();
663 return true;
664 }
665
666
667
_RenderBuyStats()668 void ConfirmInterface::_RenderBuyStats() {
669 _buy_stats.SetText(NumberToString(_buy_count) + Translate(" count") + "\n" +
670 NumberToString(_buy_unique) + Translate(" unique"));
671 }
672
673
674
_RenderSellStats()675 void ConfirmInterface::_RenderSellStats() {
676 _sell_stats.SetText(NumberToString(_sell_count) + Translate(" count") + "\n" +
677 NumberToString(_sell_unique) + Translate(" unique"));
678 }
679
680
681
_RenderTradeStats()682 void ConfirmInterface::_RenderTradeStats() {
683 _trade_stats.SetText(NumberToString(_trade_count) + Translate(" count") + "\n" +
684 NumberToString(_trade_characters) + Translate(" characters"));
685 }
686
687
688
_ClearOrder()689 void ConfirmInterface::_ClearOrder() {
690 _buy_count = 0;
691 _buy_unique = 0;
692 _sell_count = 0;
693 _sell_unique = 0;
694 _trade_count = 0;
695 _trade_characters = 0;
696 _buy_list_display->Clear();
697 _sell_list_display->Clear();
698 _no_transactions = true;
699 ShopMode::CurrentInstance()->ClearOrder();
700 // TODO: play appropriate sound
701 }
702
703
704
_LeaveInterface()705 void ConfirmInterface::_LeaveInterface() {
706 map<uint32, ShopObject*>* buy_list = ShopMode::CurrentInstance()->GetBuyList();
707 map<uint32, ShopObject*>* sell_list = ShopMode::CurrentInstance()->GetSellList();
708
709 // Go through the lists and remove any entries that have had their counts set to zero
710 for (map<uint32, ShopObject*>::iterator i = buy_list->begin(); i != buy_list->end(); i++) {
711 if (i->second->GetBuyCount() == 0)
712 buy_list->erase(i);
713 }
714 for (map<uint32, ShopObject*>::iterator i = sell_list->begin(); i != sell_list->end(); i++) {
715 if (i->second->GetSellCount() == 0)
716 sell_list->erase(i);
717 }
718
719 ShopMode::CurrentInstance()->ChangeState(SHOP_STATE_ROOT);
720 }
721
722 } // namespace private_shop
723
724 } // namespace hoa_shop
725