OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
dialogmenu.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/Font>
4#include <Tempest/Texture2d>
5#include <Tempest/Timer>
6#include <Tempest/Widget>
7#include <Tempest/SoundEffect>
8#include <Tempest/SoundDevice>
9
10#include "game/gamescript.h"
11#include "camera.h"
12
13class Npc;
14class Interactive;
15class InventoryMenu;
16class GthFont;
17
18class DialogMenu : public Tempest::Widget {
19 public:
22
23 void tick(uint64_t dt);
24 void clear();
25
26 void onWorldChanged();
27
28 bool isMobsiDialog() const;
29 void dialogCamera(Camera& camera);
30
31 void openPipe(Npc &player, Npc& npc, AiOuputPipe*& out);
32 bool isNpcInDialog(const Npc* npc) const;
33
34 bool isActive() const;
35 bool hasContent() const;
36
37 void print (std::string_view msg);
38 void printScreen(std::string_view msg, int x, int y, int time, const GthFont &font);
39 void drawMsg (Tempest::Painter& p, int offsetY);
40
41 void keyDownEvent (Tempest::KeyEvent& event) override;
42 void keyUpEvent (Tempest::KeyEvent& event) override;
43
44 protected:
45 void paintEvent (Tempest::PaintEvent& e) override;
46 void paintChoice(Tempest::PaintEvent& e);
47
48 void mouseDownEvent (Tempest::MouseEvent& event) override;
49 void mouseWheelEvent(Tempest::MouseEvent& event) override;
50
51 void onSelect();
52 void setupSettings();
53 bool isChoiceMenuActive() const;
54
55 private:
56 const Tempest::Texture2d* tex =nullptr;
57 const Tempest::Texture2d* ambient=nullptr;
58
59 struct Pipe : AiOuputPipe {
60 Pipe(DialogMenu& owner):owner(owner){}
61
62 bool output (Npc& npc, std::string_view text) override;
63 bool outputSvm(Npc& npc, std::string_view text) override;
64 bool outputOv (Npc& npc, std::string_view text) override;
65 bool printScr (Npc& npc, int time, std::string_view msg, int x, int y, std::string_view font) override;
66
67 bool close() override;
68 bool isFinished() override;
69
70 DialogMenu& owner;
71 };
72
73 enum {
74 MAX_PRINT = 3,
75 ANIM_TIME = 200,
76 };
77
78 enum class State : uint8_t {
79 Idle =0,
80 PreStart=1,
81 Active =2
82 };
83
84 struct Entry {
85 std::string txt;
86 uint64_t msgTime = 0;
87 uint64_t time = 0;
88 };
89
90 struct Forward {
91 std::string txt;
92 Npc* npc=nullptr;
93 };
94
95 struct PScreen {
96 std::string txt;
97 const GthFont* font=nullptr;
98 uint64_t time=0;
99 int x=-1;
100 int y=-1;
101 };
102
103 bool onStart(Npc& pl,Npc& other);
104 void onEntry(const GameScript::DlgChoice& e);
105 void onDoneText();
106 void close();
107 bool aiOutput (Npc& npc, std::string_view msg);
108 bool aiPrintScr(Npc& npc, int time, std::string_view msg, int x, int y, std::string_view font);
109 bool aiClose();
110
111 bool haveToWaitOutput() const;
112 bool hasPrintMsg() const;
113 bool haveToShowSubtitles(bool isPl) const;
114
115 void drawTextMultiline(Tempest::Painter& p, int x, int y, int w, int h, std::string_view txt, bool isPl);
116 Tempest::Size processTextMultiline(Tempest::Painter* p, int x, int y, int w, int h, std::string_view txt, bool isPl);
117
118 void startTrade();
119 void skipPhrase();
120
121 InventoryMenu& trade;
122 Pipe pipe;
123
124 Tempest::SoundDevice soundDevice;
125
126 std::vector<GameScript::DlgChoice> choice;
127 GameScript::DlgChoice selected;
128 Npc* pl =nullptr;
129 Npc* other=nullptr;
130 size_t dlgSel=0;
131 uint32_t depth=0;
132 std::vector<uint32_t> except;
133
134 State state=State::Idle;
135 Entry current;
136 Tempest::SoundEffect currentSnd;
137 bool curentIsPl=false;
138 bool dlgTrade=false;
139 int32_t mobsiState=-1;
140
141 std::vector<PScreen> pscreen;
142 PScreen printMsg[MAX_PRINT];
143 uint64_t remPrint=0;
144
145 bool dlgAnimation = true;
146 bool showSubtitles = true;
147 bool showSubtitlesPlayer = true;
148 uint64_t choiceAnimTime = 0;
149 };
void printScreen(std::string_view msg, int x, int y, int time, const GthFont &font)
void keyUpEvent(Tempest::KeyEvent &event) override
void paintChoice(Tempest::PaintEvent &e)
bool isNpcInDialog(const Npc *npc) const
void onSelect()
bool isActive() const
void paintEvent(Tempest::PaintEvent &e) override
void tick(uint64_t dt)
bool isChoiceMenuActive() const
void keyDownEvent(Tempest::KeyEvent &event) override
void openPipe(Npc &player, Npc &npc, AiOuputPipe *&out)
void onWorldChanged()
void drawMsg(Tempest::Painter &p, int offsetY)
bool isMobsiDialog() const
void mouseWheelEvent(Tempest::MouseEvent &event) override
void dialogCamera(Camera &camera)
void mouseDownEvent(Tempest::MouseEvent &event) override
bool hasContent() const
void print(std::string_view msg)
void setupSettings()
Definition npc.h:25