1 /* OutfitterPanel.h
2 Copyright (c) 2014 by Michael Zahniser
3 
4 Endless Sky is free software: you can redistribute it and/or modify it under the
5 terms of the GNU General Public License as published by the Free Software
6 Foundation, either version 3 of the License, or (at your option) any later version.
7 
8 Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
11 */
12 
13 #ifndef OUTFITTER_PANEL_H_
14 #define OUTFITTER_PANEL_H_
15 
16 #include "ShopPanel.h"
17 
18 #include "Sale.h"
19 
20 #include <map>
21 #include <set>
22 #include <string>
23 #include <vector>
24 
25 class Outfit;
26 class PlayerInfo;
27 class Point;
28 class Ship;
29 
30 
31 
32 // Class representing the Outfitter UI panel, which allows you to buy new
33 // outfits to install in your ship or to sell the ones you own. Any outfit you
34 // sell is available to be bought again until you close this panel, even if it
35 // is not normally sold here. You can also directly install any outfit that you
36 // have plundered from another ship and are storing in your cargo bay. This
37 // panel makes an attempt to ensure that you do not leave with a ship that is
38 // configured in such a way that it cannot fly (e.g. no engines or steering).
39 class OutfitterPanel : public ShopPanel {
40 public:
41 	explicit OutfitterPanel(PlayerInfo &player);
42 
43 	virtual void Step() override;
44 
45 
46 protected:
47 	virtual int TileSize() const override;
48 	virtual int DrawPlayerShipInfo(const Point &point) override;
49 	virtual bool HasItem(const std::string &name) const override;
50 	virtual void DrawItem(const std::string &name, const Point &point, int scrollY) override;
51 	virtual int DividerOffset() const override;
52 	virtual int DetailWidth() const override;
53 	virtual int DrawDetails(const Point &center) override;
54 	virtual bool CanBuy(bool checkAlreadyOwned = true) const override;
55 	virtual void Buy(bool alreadyOwned = false) override;
56 	virtual void FailBuy() const override;
57 	virtual bool CanSell(bool toStorage = false) const override;
58 	virtual void Sell(bool toStorage = false) override;
59 	virtual void FailSell(bool toStorage = false) const override;
60 	virtual bool ShouldHighlight(const Ship *ship) override;
61 	virtual void DrawKey() override;
62 	virtual void ToggleForSale() override;
63 	virtual void ToggleCargo() override;
64 
65 
66 private:
67 	static bool ShipCanBuy(const Ship *ship, const Outfit *outfit);
68 	static bool ShipCanSell(const Ship *ship, const Outfit *outfit);
69 	static void DrawOutfit(const Outfit &outfit, const Point &center, bool isSelected, bool isOwned);
70 	bool HasMapped(int mapSize) const;
71 	bool IsLicense(const std::string &name) const;
72 	bool HasLicense(const std::string &name) const;
73 	std::string LicenseName(const std::string &name) const;
74 	void CheckRefill();
75 	void Refill();
76 	// Shared code for reducing the selected ships to those that have the
77 	// same quantity of the selected outfit.
78 	const std::vector<Ship *> GetShipsToOutfit(bool isBuy = false) const;
79 
80 private:
81 	// Record whether we've checked if the player needs ammo refilled.
82 	bool checkedRefill = false;
83 	// Allow toggling whether outfits that are for sale are shown. If turned
84 	// off, only outfits in the currently selected ships are shown.
85 	bool showForSale = true;
86 	// Remember what ships are selected if the player switches to cargo.
87 	Ship *previousShip = nullptr;
88 	std::set<Ship *> previousShips;
89 
90 	Sale<Outfit> outfitter;
91 
92 	// Keep track of how many of the outfitter help screens have been shown
93 	bool checkedHelp = false;
94 };
95 
96 
97 #endif
98