1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/* PlayerInfoPanel.h
Copyright (c) 2017 by Michael Zahniser
Endless Sky is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later version.
Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "Panel.h"
#include "ClickZone.h"
#include "InfoPanelState.h"
#include "text/Layout.h"
#include "Point.h"
#include <set>
#include <vector>
class PlayerInfo;
class Rectangle;
// This panel displays detailed information about the player and their fleet. If
// the player is landed on a planet, it also allows them to reorder the ships in
// their fleet (including changing which one is the flagship).
class PlayerInfoPanel : public Panel {
public:
explicit PlayerInfoPanel(PlayerInfo &player);
explicit PlayerInfoPanel(PlayerInfo &player, InfoPanelState panelState);
virtual ~PlayerInfoPanel() override;
virtual void Step() override;
virtual void Draw() override;
// The player info panel allow fast-forward to stay active.
bool AllowsFastForward() const noexcept final;
protected:
// Only override the ones you need; the default action is to return false.
virtual bool KeyDown(SDL_Keycode key, Uint16 mod, const Command &command, bool isNewPress) override;
virtual bool Click(int x, int y, MouseButton button, int clicks) override;
virtual bool Hover(int x, int y) override;
virtual bool Drag(double dx, double dy) override;
virtual bool Release(int x, int y, MouseButton button) override;
virtual bool Scroll(double dx, double dy) override;
private:
// Draw the two subsections of this panel.
void DrawPlayer(const Rectangle &bounds);
void DrawFleet(const Rectangle &bounds);
// Handle mouse hover (also including hover during drag actions):
bool Hover(const Point &point);
// Adjust the scroll by the given amount. Return true if it changed.
bool Scroll(int distance);
// Try to scroll to the given position. Return true if position changed.
bool ScrollAbsolute(int scroll);
void SortShips(InfoPanelState::ShipComparator *shipComparator);
class SortableColumn {
public:
SortableColumn(std::string name, double offset, double endX, Layout layout, InfoPanelState::ShipComparator *shipSort);
std::string name;
double offset = 0.;
double endX = 0.;
Layout layout;
InfoPanelState::ShipComparator *shipSort = nullptr;
};
private:
PlayerInfo &player;
static const SortableColumn columns[];
InfoPanelState panelState;
// Column headers that sort ships when clicked.
std::vector<ClickZone<InfoPanelState::ShipComparator *>> menuZones;
// Keep track of which ship the mouse is hovering over.
int hoverIndex = -1;
// Initialize mouse point to something off-screen to not
// make the game think the player is hovering on something.
Point hoverPoint = Point(-10000, -10000);
// When reordering ships, the names of ships being moved are displayed alongside the cursor.
bool isDragging = false;
};
|