summaryrefslogtreecommitdiff
path: root/include/SSVOpenHexagon/Core/HexagonDialogBox.hpp
blob: ff43cfbe7a90a2a59303856e7382a776e4d21ae8 (plain)
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
// Copyright (c) 2013-2020 Vittorio Romeo
// License: Academic Free License ("AFL") v. 3.0
// AFL License page: https://opensource.org/licenses/AFL-3.0

#pragma once

#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/Window/Keyboard.hpp>

#include <string>
#include <vector>

namespace ssvs {
class GameWindow;
}

namespace hg::Utils {
class FastVertexVectorTris;
} // namespace hg::Utils

namespace hg {

enum class DBoxDraw
{
    topLeft = 0,
    center,
    centerUpperHalf
};

class HexagonDialogBox
{
private:
    using KKey = sf::Keyboard::Key;

    ssvs::GameWindow& window;

    DBoxDraw drawMode;

    std::vector<std::string> dialogText;
    sf::Text txtDialog;

    float dialogWidth{0.f};
    float frameSize{0.f};
    float doubleFrameSize{0.f};
    float lineHeight{0.f};
    float totalHeight{0.f};

    float xPos{0.f};
    float yPos{0.f};

    KKey keyToClose{KKey::Unknown};

    bool inputBox{false};
    bool inputBoxPassword{false};
    std::string input;

    void drawText(
        const sf::Color& txtColor, const float xOffset, const float yOffset);
    void drawBox(Utils::FastVertexVectorTris& quads,
        const sf::Color& frameColor, const float x1, const float x2,
        const float y1, const float y2);
    void drawCenter(const sf::Color& txtColor, const sf::Color& backdropColor);
    void drawCenterUpperHalf(
        const sf::Color& txtColor, const sf::Color& backdropColor);
    void drawTopLeft(const sf::Color& txtColor, const sf::Color& backdropColor);

public:
    explicit HexagonDialogBox(sf::Font& font, ssvs::GameWindow& window);

    void create(const std::string& output, const int charSize,
        const float mFrameSize, const DBoxDraw mDrawMode,
        const float xPos = 0.f, const float yPos = 0.f,
        const bool mInputBox = false);

    void create(const std::string& output, const int charSize,
        const float mFrameSize, const DBoxDraw mDrawMode,
        const KKey mKeyToClose, const float mXPos = 0.f,
        const float mYPos = 0.f);

    void createInput(const std::string& output, const int charSize,
        const float mFrameSize, const DBoxDraw mDrawMode);

    void draw(const sf::Color& txtColor, const sf::Color& backdropColor);

    void clearDialogBox();

    [[nodiscard]] KKey getKeyToClose() const noexcept;
    [[nodiscard]] bool empty() const noexcept;
    [[nodiscard]] bool isInputBox() const noexcept;
    [[nodiscard]] std::string& getInput() noexcept;
    [[nodiscard]] const std::string& getInput() const noexcept;
    void setInputBoxPassword(const bool x) noexcept;
    [[nodiscard]] bool getInputBoxPassword() noexcept;
};

} // namespace hg