Advertisement
osdever

DialogSys

May 14th, 2020
1,310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1.     struct IDialogItem
  2.     {
  3.         virtual ~IDialogItem() {}
  4.         virtual void Render() {}
  5.     };
  6.  
  7.     class Dialog
  8.     {
  9.     public:
  10.         Dialog(const std::string& title) : mTitle(title) {}
  11.  
  12.         void Add(IDialogItem* pItem)
  13.         {
  14.             mItems.push_back(std::unique_ptr<IDialogItem>(pItem));
  15.         }
  16.  
  17.         void Render() {
  18.             ImGui::SetNextWindowPos(ImVec2(Speed::DX9::screenWidth * 0.5f, Speed::DX9::screenHeight * 0.5f), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
  19.             ImGui::Begin(mTitle.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse);
  20.  
  21.             for (auto& item : mItems)
  22.             {
  23.                 item->Render();
  24.             }
  25.  
  26.             ImGui::End();
  27.         }
  28.     private:
  29.         std::string mTitle;
  30.         std::vector<std::unique_ptr<IDialogItem>> mItems;
  31.     };
  32.  
  33.     class IGText : public IDialogItem
  34.     {
  35.     public:
  36.         IGText(const std::string& text) : mText(text) {}
  37.         void Render() {
  38.             ColoredChat::TextWithColors("%s", mText.c_str());
  39.         }
  40.     private:
  41.         std::string mText;
  42.     };
  43.     class IGBulletText : public IDialogItem
  44.     {
  45.     public:
  46.         IGBulletText(const std::string& text) : mText(text) {}
  47.         void Render() {
  48.             ColoredChat::TextWithColors("%s", mText.c_str());
  49.         }
  50.     private:
  51.         std::string mText;
  52.     };
  53.     class IGSameLine : public IDialogItem
  54.     {
  55.     public:
  56.         void Render() {
  57.             ImGui::SameLine();
  58.         }
  59.     };
  60.     class IGButton : public IDialogItem
  61.     {
  62.     public:
  63.         IGButton(const std::string& text, bool* pClicked) : mpClicked(pClicked), mText(text) {}
  64.         void Render() {
  65.             *mpClicked = ImGui::Button(mText.c_str());
  66.         }
  67.     private:
  68.         std::string mText;
  69.         bool* mpClicked;
  70.     };
  71.  
  72.     class DialogBuilder
  73.     {
  74.     public:
  75.         DialogBuilder(const std::string title) : mDialog(title) {}
  76.  
  77.         DialogBuilder& Text(const std::string& text) {
  78.             mDialog.Add(new IGText(text));
  79.             return *this;
  80.         }
  81.         DialogBuilder& BulletText(const std::string& text) {
  82.             mDialog.Add(new IGBulletText(text));
  83.             return *this;
  84.         }
  85.         DialogBuilder& SameLine() {
  86.             mDialog.Add(new IGSameLine());
  87.             return *this;
  88.         }
  89.         DialogBuilder& Button(const std::string& text, bool& clicked) {
  90.             mDialog.Add(new IGButton(text, &clicked));
  91.             return *this;
  92.         }
  93.  
  94.         Dialog& Get() {
  95.             return mDialog;
  96.         }
  97.     private:
  98.         Dialog mDialog;
  99.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement