1 #ifndef MWGUI_DIALOGE_H
2 #define MWGUI_DIALOGE_H
3 
4 #include "windowbase.hpp"
5 #include "referenceinterface.hpp"
6 
7 #include "bookpage.hpp"
8 
9 #include "../mwdialogue/keywordsearch.hpp"
10 
11 #include <MyGUI_Delegate.h>
12 
13 namespace Gui
14 {
15     class MWList;
16 }
17 
18 namespace MWGui
19 {
20     class ResponseCallback;
21 
22     class PersuasionDialog : public WindowModal
23     {
24     public:
25         PersuasionDialog(ResponseCallback* callback);
26 
27         void onOpen() override;
28 
29         MyGUI::Widget* getDefaultKeyFocus() override;
30 
31     private:
32         std::unique_ptr<ResponseCallback> mCallback;
33 
34         MyGUI::Button* mCancelButton;
35         MyGUI::Button* mAdmireButton;
36         MyGUI::Button* mIntimidateButton;
37         MyGUI::Button* mTauntButton;
38         MyGUI::Button* mBribe10Button;
39         MyGUI::Button* mBribe100Button;
40         MyGUI::Button* mBribe1000Button;
41         MyGUI::TextBox* mGoldLabel;
42 
43         void onCancel (MyGUI::Widget* sender);
44         void onPersuade (MyGUI::Widget* sender);
45     };
46 
47 
48     struct Link
49     {
~LinkMWGui::Link50         virtual ~Link() {}
51         virtual void activated () = 0;
52     };
53 
54     struct Topic : Link
55     {
56         typedef MyGUI::delegates::CMultiDelegate1<const std::string&> EventHandle_TopicId;
57         EventHandle_TopicId eventTopicActivated;
TopicMWGui::Topic58         Topic(const std::string& id) : mTopicId(id) {}
59         std::string mTopicId;
60         void activated () override;
61     };
62 
63     struct Choice : Link
64     {
65         typedef MyGUI::delegates::CMultiDelegate1<int> EventHandle_ChoiceId;
66         EventHandle_ChoiceId eventChoiceActivated;
ChoiceMWGui::Choice67         Choice(int id) : mChoiceId(id) {}
68         int mChoiceId;
69         void activated () override;
70     };
71 
72     struct Goodbye : Link
73     {
74         typedef MyGUI::delegates::CMultiDelegate0 Event_Activated;
75         Event_Activated eventActivated;
76         void activated () override;
77     };
78 
79     typedef MWDialogue::KeywordSearch <std::string, intptr_t> KeywordSearchT;
80 
81     struct DialogueText
82     {
~DialogueTextMWGui::DialogueText83         virtual ~DialogueText() {}
84         virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const = 0;
85         std::string mText;
86     };
87 
88     struct Response : DialogueText
89     {
90         Response(const std::string& text, const std::string& title = "", bool needMargin = true);
91         void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const override;
92         void addTopicLink (BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end) const;
93         std::string mTitle;
94         bool mNeedMargin;
95     };
96 
97     struct Message : DialogueText
98     {
99         Message(const std::string& text);
100         void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const override;
101     };
102 
103     class DialogueWindow: public WindowBase, public ReferenceInterface
104     {
105     public:
106         DialogueWindow();
107         ~DialogueWindow();
108 
109         void onTradeComplete();
110 
111         bool exit() override;
112 
113         // Events
114         typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
115 
116         void notifyLinkClicked (TypesetBook::InteractiveId link);
117 
118         void setPtr(const MWWorld::Ptr& actor) override;
119 
120         /// @return true if stale keywords were updated successfully
121         bool setKeywords(std::list<std::string> keyWord);
122 
123         void addResponse (const std::string& title, const std::string& text, bool needMargin = true);
124 
125         void addMessageBox(const std::string& text);
126 
127         void onFrame(float dt) override;
clear()128         void clear() override { resetReference(); }
129 
130         void updateTopics();
131 
132         void onClose() override;
133 
134     protected:
135         void updateTopicsPane();
136         bool isCompanion(const MWWorld::Ptr& actor);
137         bool isCompanion();
138 
139         void onSelectListItem(const std::string& topic, int id);
140         void onByeClicked(MyGUI::Widget* _sender);
141         void onMouseWheel(MyGUI::Widget* _sender, int _rel);
142         void onWindowResize(MyGUI::Window* _sender);
143         void onTopicActivated(const std::string& topicId);
144         void onChoiceActivated(int id);
145         void onGoodbyeActivated();
146 
147         void onScrollbarMoved (MyGUI::ScrollBar* sender, size_t pos);
148 
149         void updateHistory(bool scrollbar=false);
150 
151         void onReferenceUnavailable() override;
152 
153     private:
154         void updateDisposition();
155         void restock();
156         void deleteLater();
157 
158         bool mIsCompanion;
159         std::list<std::string> mKeywords;
160 
161         std::vector<DialogueText*> mHistoryContents;
162         std::vector<std::pair<std::string, int> > mChoices;
163         bool mGoodbye;
164 
165         std::vector<Link*> mLinks;
166         std::map<std::string, Link*> mTopicLinks;
167 
168         std::vector<Link*> mDeleteLater;
169 
170         KeywordSearchT mKeywordSearch;
171 
172         BookPage* mHistory;
173         Gui::MWList*   mTopicsList;
174         MyGUI::ScrollBar* mScrollBar;
175         MyGUI::ProgressBar* mDispositionBar;
176         MyGUI::TextBox*     mDispositionText;
177         MyGUI::Button* mGoodbyeButton;
178 
179         PersuasionDialog mPersuasionDialog;
180 
181         MyGUI::IntSize mCurrentWindowSize;
182 
183         std::unique_ptr<ResponseCallback> mCallback;
184         std::unique_ptr<ResponseCallback> mGreetingCallback;
185 
186         void updateTopicFormat();
187     };
188 }
189 #endif
190