OpenMW
apps/openmw/mwgui/dialogue.hpp
Go to the documentation of this file.
00001 #ifndef MWGUI_DIALOGE_H
00002 #define MWGUI_DIALOGE_H
00003 
00004 #include "windowbase.hpp"
00005 #include "referenceinterface.hpp"
00006 
00007 #include "bookpage.hpp"
00008 
00009 #include "keywordsearch.hpp"
00010 
00011 namespace MWGui
00012 {
00013     class WindowManager;
00014 
00015     namespace Widgets
00016     {
00017         class MWList;
00018     }
00019 }
00020 
00021 /*
00022   This file contains the dialouge window
00023   Layout is defined by resources/mygui/openmw_dialogue_window.layout.
00024  */
00025 
00026 namespace MWGui
00027 {
00028     class DialogueHistoryViewModel;
00029     class BookPage;
00030 
00031     class PersuasionDialog : public WindowModal
00032     {
00033     public:
00034         PersuasionDialog();
00035 
00036         virtual void open();
00037 
00038     private:
00039         MyGUI::Button* mCancelButton;
00040         MyGUI::Button* mAdmireButton;
00041         MyGUI::Button* mIntimidateButton;
00042         MyGUI::Button* mTauntButton;
00043         MyGUI::Button* mBribe10Button;
00044         MyGUI::Button* mBribe100Button;
00045         MyGUI::Button* mBribe1000Button;
00046         MyGUI::TextBox* mGoldLabel;
00047 
00048         void onCancel (MyGUI::Widget* sender);
00049         void onPersuade (MyGUI::Widget* sender);
00050     };
00051 
00052 
00053     struct Link
00054     {
00055         virtual ~Link() {}
00056         virtual void activated () = 0;
00057     };
00058 
00059     struct Topic : Link
00060     {
00061         Topic(const std::string& id) : mTopicId(id) {}
00062         std::string mTopicId;
00063         virtual void activated ();
00064     };
00065 
00066     struct Choice : Link
00067     {
00068         Choice(int id) : mChoiceId(id) {}
00069         int mChoiceId;
00070         virtual void activated ();
00071     };
00072 
00073     struct Goodbye : Link
00074     {
00075         virtual void activated ();
00076     };
00077 
00078     typedef KeywordSearch <std::string, intptr_t> KeywordSearchT;
00079 
00080     struct DialogueText
00081     {
00082         virtual ~DialogueText() {}
00083         virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const = 0;
00084         std::string mText;
00085     };
00086 
00087     struct Response : DialogueText
00088     {
00089         Response(const std::string& text, const std::string& title = "");
00090         virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const;
00091         void addTopicLink (BookTypesetter::Ptr typesetter, intptr_t topicId, size_t begin, size_t end) const;
00092         std::string mTitle;
00093     };
00094 
00095     struct Message : DialogueText
00096     {
00097         Message(const std::string& text);
00098         virtual void write (BookTypesetter::Ptr typesetter, KeywordSearchT* keywordSearch, std::map<std::string, Link*>& topicLinks) const;
00099     };
00100 
00101     class DialogueWindow: public WindowBase, public ReferenceInterface
00102     {
00103     public:
00104         DialogueWindow();
00105 
00106         // Events
00107         typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
00108 
00109         void notifyLinkClicked (TypesetBook::InteractiveId link);
00110 
00111         void startDialogue(MWWorld::Ptr actor, std::string npcName);
00112         void setKeywords(std::list<std::string> keyWord);
00113 
00114         void addResponse (const std::string& text, const std::string& title="");
00115 
00116         void addMessageBox(const std::string& text);
00117 
00118         void addChoice(const std::string& choice, int id);
00119         void clearChoices();
00120 
00121         void goodbye();
00122         void onFrame();
00123 
00124         // make sure to call these before setKeywords()
00125         void setServices(int services) { mServices = services; }
00126 
00127         enum Services
00128         {
00129             Service_Trade = 0x01,
00130             Service_BuySpells = 0x02,
00131             Service_CreateSpells = 0x04,
00132             Service_Enchant = 0x08,
00133             Service_Training = 0x10,
00134             Service_Travel = 0x20,
00135             Service_Repair = 0x40
00136         };
00137 
00138     protected:
00139         void onSelectTopic(const std::string& topic, int id);
00140         void onByeClicked(MyGUI::Widget* _sender);
00141         void onMouseWheel(MyGUI::Widget* _sender, int _rel);
00142         void onWindowResize(MyGUI::Window* _sender);
00143 
00144         void onScrollbarMoved (MyGUI::ScrollBar* sender, size_t pos);
00145 
00146         void updateHistory(bool scrollbar=false);
00147 
00148         virtual void onReferenceUnavailable();
00149 
00150     private:
00151         void updateOptions();
00152 
00153         int mServices;
00154 
00155         bool mEnabled;
00156 
00157         bool mGoodbye;
00158 
00159         std::vector<DialogueText*> mHistoryContents;
00160         std::map<std::string, int> mChoices;
00161 
00162         std::vector<Link*> mLinks;
00163         std::map<std::string, Link*> mTopicLinks;
00164 
00165         KeywordSearchT mKeywordSearch;
00166 
00167         BookPage* mHistory;
00168         Widgets::MWList*   mTopicsList;
00169         MyGUI::ScrollBar* mScrollBar;
00170         MyGUI::ProgressPtr mDispositionBar;
00171         MyGUI::EditBox*     mDispositionText;
00172 
00173         PersuasionDialog mPersuasionDialog;
00174     };
00175 }
00176 #endif