1 /* 2 * The ManaPlus Client 3 * Copyright (C) 2010 The Mana Developers 4 * Copyright (C) 2011-2019 The ManaPlus Developers 5 * Copyright (C) 2019-2021 Andrei Karas 6 * 7 * This file is part of The ManaPlus Client. 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef GUI_WIDGETS_TABS_SOCIALTAB_H 24 #define GUI_WIDGETS_TABS_SOCIALTAB_H 25 26 #include "gui/windows/socialwindow.h" 27 28 #include "gui/windows/confirmdialog.h" 29 #include "gui/windows/textdialog.h" 30 31 #include "gui/widgets/avatarlistbox.h" 32 #include "gui/widgets/createwidget.h" 33 #include "gui/widgets/scrollarea.h" 34 35 #include "gui/widgets/tabs/tab.h" 36 37 #include "localconsts.h" 38 39 class AvatarListModel; 40 41 class SocialTab notfinal : public Tab 42 { 43 public: A_DELETE_COPY(SocialTab)44 A_DELETE_COPY(SocialTab) 45 46 virtual void invite() 47 { 48 } 49 leave()50 virtual void leave() 51 { 52 } 53 updateList()54 virtual void updateList() 55 { 56 } 57 updateAvatar(const std::string & name A_UNUSED)58 virtual void updateAvatar(const std::string &name A_UNUSED) 59 { 60 } 61 resetDamage(const std::string & name A_UNUSED)62 virtual void resetDamage(const std::string &name A_UNUSED) 63 { 64 } 65 selectIndex(const unsigned num A_UNUSED)66 virtual void selectIndex(const unsigned num A_UNUSED) 67 { 68 } 69 buildCounter(const int online A_UNUSED,const int total A_UNUSED)70 virtual void buildCounter(const int online A_UNUSED, 71 const int total A_UNUSED) 72 { 73 } 74 75 protected: 76 friend class SocialWindow; 77 SocialTab(const Widget2 * const widget)78 explicit SocialTab(const Widget2 *const widget) : 79 Tab(widget), 80 mInviteDialog(nullptr), 81 mConfirmDialog(nullptr), 82 mScroll(nullptr), 83 mList(nullptr), 84 mCounterString(), 85 mMenuAction("menu") 86 { 87 } 88 ~SocialTab()89 ~SocialTab() override 90 { 91 // Cleanup dialogs 92 if (mInviteDialog != nullptr) 93 { 94 mInviteDialog->close(); 95 mInviteDialog->scheduleDelete(); 96 mInviteDialog = nullptr; 97 } 98 99 if (mConfirmDialog != nullptr) 100 { 101 mConfirmDialog->close(); 102 mConfirmDialog->scheduleDelete(); 103 mConfirmDialog = nullptr; 104 } 105 } 106 createControls(AvatarListModel * const listModel,const Opaque showBackground)107 void createControls(AvatarListModel *const listModel, 108 const Opaque showBackground) 109 { 110 CREATEWIDGETV(mList, AvatarListBox, this, listModel); 111 mScroll = new ScrollArea(this, mList, showBackground, 112 "social_background.xml"); 113 114 mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); 115 mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); 116 } 117 setCurrent()118 void setCurrent() override final 119 { 120 updateCounter(); 121 updateMenu(); 122 } 123 updateCounter()124 void updateCounter() const 125 { 126 if (socialWindow != nullptr) 127 socialWindow->updateCounter(this, mCounterString); 128 } 129 updateMenu()130 void updateMenu() const 131 { 132 if (socialWindow != nullptr) 133 socialWindow->updateMenu(this, mMenuAction); 134 } 135 136 TextDialog *mInviteDialog; 137 ConfirmDialog *mConfirmDialog; 138 ScrollArea *mScroll; 139 AvatarListBox *mList; 140 std::string mCounterString; 141 std::string mMenuAction; 142 }; 143 144 #endif // GUI_WIDGETS_TABS_SOCIALTAB_H 145