1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ULTIMA8_GUMPS_REMORSEMENUGUMP_H
24 #define ULTIMA8_GUMPS_REMORSEMENUGUMP_H
25 
26 #include "ultima/ultima8/gumps/modal_gump.h"
27 #include "ultima/ultima8/misc/classtype.h"
28 
29 namespace Ultima {
30 namespace Ultima8 {
31 
32 class WeaselDat;
33 
34 /**
35  * Weasel weapon seller Crusader.
36  */
37 class WeaselGump : public ModalGump {
38 public:
39 	ENABLE_RUNTIME_CLASSTYPE()
40 
41 	enum WeaselGumpState {
42 		kWeaselStart,
43 		kWeaselConfirmPurchaseMovie,
44 		kWeaselConfirmPurchaseText,
45 		kWeaselCancelledPurchaseMovie,
46 		kWeaselCancelledPurchaseText,
47 		kWeaselCompletedPurchase,
48 		kWeaselInsufficientFunds,
49 		kWeaselBrowsing,
50 		kWeaselClosing,
51 		kWeaselCheckBuyMoreMovie,
52 		kWeaselCheckBuyMoreText,
53 		kWeaselShowIntro
54 	};
55 
56 	WeaselGump(uint16 level);
57 	~WeaselGump() override;
58 
59 	// Init the gump, call after construction
60 	void InitGump(Gump *newparent, bool take_focus = true) override;
61 	void Close(bool no_del = false) override;
62 
63 	void run() override;
64 
65 	// Paint the Gump
66 	void PaintThis(RenderSurface *, int32 lerp_factor, bool scaled) override;
67 
68 	bool OnKeyDown(int key, int mod) override;
69 	bool OnTextInput(int unicode) override;
70 	void ChildNotify(Gump *child, uint32 message) override;
71 
72 	static uint32 I_showWeaselGump(const uint8 *args, unsigned int /*argsize*/);
73 
74 private:
75 
76 	void onButtonClick(int entry);
77 
78 	void prevItem();
79 	void nextItem();
80 	void buyItem();
81 	void updateForAmmoMode();
82 	void checkClose();
83 	void completePurchase();
84 	void abortPurchase();
85 	void checkBuyMore();
86 	void confirmPurchase();
87 	void setYesNoQuestion(const Std::string &msg);
88 	void browsingMode(bool browsing);
89 	int purchasedCount(uint16 shape) const;
90 
91 	void updateItemDisplay();
92 	Gump *playMovie(const Std::string &filename);
93 
94 	/// Gump to hold all the UI items (not the movies)
95 	Gump *_ui;
96 
97 	/// Gump for playing movies
98 	Gump *_movie;
99 
100 	/// The menu of items on offer
101 	uint16 _level;
102 
103 	/// Current gump state
104 	WeaselGumpState _state;
105 
106 	const WeaselDat *_weaselDat;
107 
108 	/// Remaining balance including pending purchases
109 	int32 _credits;
110 
111 	/// The list of pending purchases (shape nums)
112 	Std::vector<uint16> _purchases;
113 
114 	/// The current item num being browsed
115 	int _curItem;
116 
117 	/// Whether we're browsing ammo or weapons
118 	bool _ammoMode;
119 
120 	/// Cost of current item
121 	int32 _curItemCost;
122 
123 	/// Shape of current item
124 	uint16 _curItemShape;
125 
126 	/**
127 	 * Whether the first intro movie has been played. Remember this between
128 	 * displays of the gump, but don't save.
129 	 *
130 	 * It only ever shows on level 1 so there is only a single way it can be re-shown
131 	 * (save during the first time at the base and reload after restarting the game).
132 	 *
133 	 * TODO: test if original does this to be perfectly faithful
134 	 */
135 	static bool _playedIntroMovie;
136 };
137 
138 } // End of namespace Ultima8
139 } // End of namespace Ultima
140 
141 #endif
142