diff --git a/CQSDKCPP/CQAPI_EX.cpp b/CQSDKCPP/CQAPI_EX.cpp index cbdf2d1f..4d5b3bee 100644 --- a/CQSDKCPP/CQAPI_EX.cpp +++ b/CQSDKCPP/CQAPI_EX.cpp @@ -348,9 +348,6 @@ std::map CQ::getFriendList() noexcept { FriendInfo info(pack.getUnpack()); //ȡ ret[info.QQID] = info; //дmap } - std::ofstream fout("friendinfo.log", std::ios::out | std::ios::app); - fout << "friend add" << std::endl; - fout.close(); return ret; } bool CQ::canSendImage() noexcept diff --git a/Dice/BlackListManager.cpp b/Dice/BlackListManager.cpp index 40a4adac..e9553ad8 100644 --- a/Dice/BlackListManager.cpp +++ b/Dice/BlackListManager.cpp @@ -364,7 +364,14 @@ int DDBlackManager::find(const DDBlackMark& mark) { } else { unordered_set sInter; - std::set_intersection(sRange.begin(), sRange.end(), sTimeRange.begin(), sTimeRange.end(), std::inserter(sInter, sInter.begin())); + for (const auto& item : sRange) + { + if (sTimeRange.count(item)) + { + sInter.insert(item); + } + } + //std::set_intersection(sRange.begin(), sRange.end(), sTimeRange.begin(), sTimeRange.end(), std::inserter(sInter, sInter.begin())); if (sInter.empty())return -1; sRange.swap(sInter); } @@ -380,7 +387,14 @@ int DDBlackManager::find(const DDBlackMark& mark) { } else { unordered_set sInter; - std::set_intersection(sRange.begin(), sRange.end(), sGroupRange.begin(), sGroupRange.end(), std::inserter(sInter, sInter.begin())); + for(const auto& item: sRange) + { + if(sGroupRange.count(item)) + { + sInter.insert(item); + } + } + //std::set_intersection(sRange.begin(), sRange.end(), sGroupRange.begin(), sGroupRange.end(), std::inserter(sInter, sInter.begin())); if (sInter.empty())return -1; sRange.swap(sInter); } @@ -397,7 +411,14 @@ int DDBlackManager::find(const DDBlackMark& mark) { } else { unordered_set sInter; - std::set_intersection(sRange.begin(), sRange.end(), sQQRange.begin(), sQQRange.end(), std::inserter(sInter, sInter.begin())); + for (const auto& item : sRange) + { + if (sQQRange.count(item)) + { + sInter.insert(item); + } + } + //std::set_intersection(sRange.begin(), sRange.end(), sQQRange.begin(), sQQRange.end(), std::inserter(sInter, sInter.begin())); if (sInter.empty())return -1; sRange.swap(sInter); } diff --git a/Dice/Dice.cpp b/Dice/Dice.cpp index 061f43ed..4598b8db 100644 --- a/Dice/Dice.cpp +++ b/Dice/Dice.cpp @@ -50,6 +50,7 @@ #include "CharacterCard.h" #include "DiceEvent.h" #include "DiceSession.h" +#include "DiceGUI.h" #pragma warning(disable:4996) #pragma warning(disable:6031) @@ -756,6 +757,10 @@ EVE_Menu(eventMasterMode) { return 0; } +EVE_Menu(eventGUI) { + return GUIMain(); +} + EVE_Disable(eventDisable) { Enabled = false; diff --git a/Dice/Dice.ico b/Dice/Dice.ico new file mode 100644 index 00000000..0c0849d8 Binary files /dev/null and b/Dice/Dice.ico differ diff --git a/Dice/Dice.vcxproj b/Dice/Dice.vcxproj index bcad14ec..6376ae2b 100644 --- a/Dice/Dice.vcxproj +++ b/Dice/Dice.vcxproj @@ -109,7 +109,7 @@ true WIN32;NDEBUG;DICE_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) true - SyncCThrow + Sync true MultiThreaded AnySuitable @@ -133,6 +133,13 @@ NotSet %(AdditionalLibraryDirectories) + + + + + + copy /Y $(TargetPath) "D:\酷Q Air\dev\com.w4123.dice" + @@ -152,6 +159,13 @@ true %(AdditionalLibraryDirectories) + + + + + + copy /Y $(TargetPath) "D:\酷Q Air\dev\com.w4123.dice" + @@ -171,6 +185,13 @@ true %(AdditionalLibraryDirectories) + + + + + + copy /Y $(TargetPath) "D:\酷Q Air\dev\com.w4123.dice" + @@ -204,6 +225,13 @@ NotSet %(AdditionalLibraryDirectories) + + + + + + copy /Y $(TargetPath) "D:\酷Q Air\dev\com.w4123.dice" + @@ -220,6 +248,7 @@ + @@ -268,6 +297,7 @@ + @@ -284,6 +314,7 @@ + @@ -294,6 +325,14 @@ + + + + + + + + diff --git a/Dice/Dice.vcxproj.DotSettings b/Dice/Dice.vcxproj.DotSettings new file mode 100644 index 00000000..21022da7 --- /dev/null +++ b/Dice/Dice.vcxproj.DotSettings @@ -0,0 +1,2 @@ + + Cpp17 \ No newline at end of file diff --git a/Dice/Dice.vcxproj.filters b/Dice/Dice.vcxproj.filters index f747eb6f..94acb848 100644 --- a/Dice/Dice.vcxproj.filters +++ b/Dice/Dice.vcxproj.filters @@ -117,6 +117,9 @@ 源文件 + + 源文件 + @@ -263,6 +266,12 @@ 头文件 + + 头文件 + + + 头文件 + @@ -274,4 +283,20 @@ 资源文件 + + + 资源文件 + + + + + 资源文件 + + + 资源文件 + + + 资源文件 + + \ No newline at end of file diff --git a/Dice/DiceEvent.cpp b/Dice/DiceEvent.cpp index 9bd134c1..e4845508 100644 --- a/Dice/DiceEvent.cpp +++ b/Dice/DiceEvent.cpp @@ -502,6 +502,10 @@ int FromMsg::MasterSet() { return 1; } else if (strOption == "reset") { + if (console.master() != fromQQ) { + reply(GlobalMsg["strNotMaster"]); + return 1; + } string strMaster = readDigit(); if (strMaster.empty() || stoll(strMaster) == console.master()) { reply("MasterҪDz!"); @@ -1899,15 +1903,23 @@ int FromMsg::DiceReply() { chatType ToChat = mLinkedList[fromChat]; mLinkedList.erase(fromChat); auto Range = mFwdList.equal_range(fromChat); - for (auto it = Range.first; it != Range.second; ++it) { + for (auto it = Range.first; it != Range.second;) { if (it->second == ToChat) { - mFwdList.erase(it); + it = mFwdList.erase(it); + } + else + { + ++it; } } Range = mFwdList.equal_range(ToChat); - for (auto it = Range.first; it != Range.second; ++it) { + for (auto it = Range.first; it != Range.second;) { if (it->second == fromChat) { - mFwdList.erase(it); + it = mFwdList.erase(it); + } + else + { + ++it; } } reply(GlobalMsg["strLinkLoss"]); @@ -2060,7 +2072,7 @@ int FromMsg::DiceReply() { if (!UserList.count(llTarget)) { reply(GlobalMsg["strUserNotFound"]); return 1; - } + } strVar["trust"] = to_string(trustedQQ(llTarget)); reply(GlobalMsg["strUserTrustShow"]); return 1; diff --git a/Dice/DiceGUI.cpp b/Dice/DiceGUI.cpp new file mode 100644 index 00000000..90dedeca --- /dev/null +++ b/Dice/DiceGUI.cpp @@ -0,0 +1,1092 @@ +#include "DiceGUI.h" +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#include +#include + +#include "DiceEvent.h" +#include "DiceConsole.h" +#include "GlobalVar.h" +#include "Jsonio.h" +#include "Resource.h" + +#pragma comment(lib, "comctl32.lib") + +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + + + +template +class BaseWindow +{ +public: + static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) + { + T* pThis = nullptr; + + if (uMsg == WM_NCCREATE) + { + LPCREATESTRUCTA pCreate = reinterpret_cast(lParam); + pThis = (T*)pCreate->lpCreateParams; + SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)pThis); + + pThis->m_hwnd = hwnd; + } + else + { + pThis = (T*)GetWindowLongPtrA(hwnd, GWLP_USERDATA); + } + + if (pThis) + { + return pThis->HandleMessage(uMsg, wParam, lParam); + } + return DefWindowProcA(hwnd, uMsg, wParam, lParam); + } + BaseWindow() : m_hwnd(nullptr) { } + BOOL Create( + PCSTR lpWindowName, + DWORD dwStyle, + DWORD dwExStyle = 0, + int x = CW_USEDEFAULT, + int y = CW_USEDEFAULT, + int nWidth = CW_USEDEFAULT, + int nHeight = CW_USEDEFAULT, + HWND hWndParent = 0, + HMENU hMenu = 0 + ) + { + WNDCLASS wc = { 0 }; + + wc.lpfnWndProc = T::WindowProc; + wc.hInstance = hDllModule; + wc.lpszClassName = ClassName(); + wc.hIcon = (HICON)LoadImageA(hDllModule, MAKEINTRESOURCEA(IDI_ICON), IMAGE_ICON, 256, 256, LR_LOADTRANSPARENT | LR_SHARED); + + RegisterClassA(&wc); + + m_hwnd = CreateWindowExA( + dwExStyle, ClassName(), lpWindowName, dwStyle, x, y, + nWidth, nHeight, hWndParent, hMenu, hDllModule, this + ); + + return (m_hwnd ? TRUE : FALSE); + } + HWND Window() const { return m_hwnd; } + +protected: + + virtual PCSTR ClassName() const = 0; + virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) = 0; + + HWND m_hwnd; +}; + +// ListView +// ʹ֮ǰȵInitCommonControl/InitCommonControlEx +class BasicListView +{ +public: + BasicListView() : hwnd(nullptr) { } + HWND Window() const { return hwnd; } + BOOL Create( + PCSTR lpWindowName, + DWORD dwStyle, + DWORD dwExStyle = 0, + int x = CW_USEDEFAULT, + int y = CW_USEDEFAULT, + int nWidth = CW_USEDEFAULT, + int nHeight = CW_USEDEFAULT, + HWND hWndParent = 0, + HMENU hMenu = 0 + ) + { + hwnd = CreateWindowExA( + dwExStyle, WC_LISTVIEWA, lpWindowName, dwStyle, x, y, + nWidth, nHeight, hWndParent, hMenu, hDllModule, this + ); + + return (hwnd ? TRUE : FALSE); + } + int AddTextColumn(const char* pszText, int width = 150, int fmt = LVCFMT_LEFT, int isubItem = -1) + { + LVCOLUMNA lvC; + lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvC.pszText = const_cast(pszText); + lvC.cx = width; + lvC.fmt = fmt; + if (isubItem == -1) + { + HWND header = ListView_GetHeader(hwnd); + isubItem = Header_GetItemCount(header); + } + return ListView_InsertColumn(hwnd, isubItem, &lvC); + } + // + void AddAllTextColumn(const std::map& texts) + { + for (const auto& item : texts) + { + AddTextColumn(item.first.c_str(), item.second); + } + } + void AddAllTextColumn(const std::initializer_list& texts) + { + for(const auto& item: texts) + { + AddTextColumn(item.c_str()); + } + } + void AddTextRow(const std::initializer_list& texts, int index = -1) + { + if (texts.size() == 0) return; + LVITEMA lvI; + lvI.mask = LVIF_TEXT; + lvI.pszText = const_cast(texts.begin()->c_str()); + if (index == -1) + { + index = ListView_GetItemCount(hwnd); + } + lvI.iItem = index; + lvI.iSubItem = 0; + ListView_InsertItem(hwnd, &lvI); + int curr = 1; + for (auto s = texts.begin() + 1; s != texts.end(); s++) + { + ListView_SetItemText(hwnd, index, curr, const_cast(s->c_str())); + curr++; + } + } + + DWORD SetExtendedListViewStyle(DWORD style) + { + return ListView_SetExtendedListViewStyle(hwnd, style); + } + + [[nodiscard]] int GetItemIndexByText(const std::string& text, int iStart = -1) + { + LVFINDINFOA info; + info.flags = LVFI_STRING; + info.psz = const_cast(text.c_str()); + return ListView_FindItem(hwnd, iStart, &info); + } + + void SetItemText(const string& text, int index, int subindex = 0) + { + if (index < 0)return; + ListView_SetItemText(hwnd, index, subindex, const_cast(text.c_str())); + } + + // Ϊ1000 + [[nodiscard]] std::string GetItemText(int index, int subindex = 0) + { + char buffer[1000]; + ListView_GetItemText(hwnd, index, subindex, buffer, 1000); + return buffer; + } + + BOOL DeleteItemByIndex(int index) + { + return ListView_DeleteItem(hwnd, index); + } + + BOOL DeleteAllItems() + { + return ListView_DeleteAllItems(hwnd); + } + + BOOL DeleteColumn(int iCol = 0) + { + return ListView_DeleteColumn(hwnd, iCol); + } + BOOL Show(bool show = true) + { + return ShowWindow(hwnd, show ? SW_SHOW : SW_HIDE); + } +protected: + HWND hwnd; +}; + +// Edit +class BasicEdit +{ +public: + BasicEdit() : hwnd(nullptr) { } + HWND Window() const { return hwnd; } + BOOL Create( + PCSTR lpWindowName, + DWORD dwStyle, + DWORD dwExStyle = 0, + int x = CW_USEDEFAULT, + int y = CW_USEDEFAULT, + int nWidth = CW_USEDEFAULT, + int nHeight = CW_USEDEFAULT, + HWND hWndParent = 0, + HMENU hMenu = 0 + ) + { + hwnd = CreateWindowExA( + dwExStyle, "EDIT", lpWindowName, dwStyle, x, y, + nWidth, nHeight, hWndParent, hMenu, hDllModule, this + ); + + return (hwnd ? TRUE : FALSE); + } + LRESULT SetFont(const HFONT& hFont) + { + return SendMessageA(hwnd, WM_SETFONT, (WPARAM)hFont, 1); + } + void SetText(const std::string& text) + { + Edit_SetText(hwnd, text.c_str()); + } + [[nodiscard]] std::string GetText() + { + int length = Edit_GetTextLength(hwnd) + 1; + std::unique_ptr uptr = std::make_unique(length); + if (uptr) + { + Edit_GetText(hwnd, uptr.get(), length); + return uptr.get(); + } + return ""; + } + + BOOL Show(bool show = true) + { + return ShowWindow(hwnd, show ? SW_SHOW : SW_HIDE); + } +protected: + HWND hwnd; +}; + +// Button +class BasicButton +{ +public: + BasicButton() : hwnd(nullptr) { } + HWND Window() const { return hwnd; } + BOOL Create( + PCSTR lpWindowName, + DWORD dwStyle, + DWORD dwExStyle = 0, + int x = CW_USEDEFAULT, + int y = CW_USEDEFAULT, + int nWidth = CW_USEDEFAULT, + int nHeight = CW_USEDEFAULT, + HWND hWndParent = 0, + HMENU hMenu = 0 + ) + { + hwnd = CreateWindowExA( + dwExStyle, "BUTTON", lpWindowName, dwStyle, x, y, + nWidth, nHeight, hWndParent, hMenu, hDllModule, this + ); + + return (hwnd ? TRUE : FALSE); + } + LRESULT SetFont(const HFONT& hFont) + { + return SendMessageA(hwnd, WM_SETFONT, (WPARAM)hFont, 1); + } + BOOL Show(bool show = true) + { + return ShowWindow(hwnd, show ? SW_SHOW : SW_HIDE); + } + void SetText(const std::string& text) + { + Button_SetText(hwnd, text.c_str()); + } +protected: + HWND hwnd; +}; + +// Static +class BasicStatic +{ +public: + BasicStatic() : hwnd(nullptr) { } + HWND Window() const { return hwnd; } + BOOL Create( + PCSTR lpWindowName, + DWORD dwStyle, + DWORD dwExStyle = 0, + int x = CW_USEDEFAULT, + int y = CW_USEDEFAULT, + int nWidth = CW_USEDEFAULT, + int nHeight = CW_USEDEFAULT, + HWND hWndParent = 0, + HMENU hMenu = 0 + ) + { + hwnd = CreateWindowExA( + dwExStyle, "STATIC", lpWindowName, dwStyle, x, y, + nWidth, nHeight, hWndParent, hMenu, hDllModule, this + ); + + return (hwnd ? TRUE : FALSE); + } + LRESULT SetFont(const HFONT& hFont) + { + return SendMessageA(hwnd, WM_SETFONT, (WPARAM)hFont, 1); + } + BOOL Show(bool show = true) + { + return ShowWindow(hwnd, show ? SW_SHOW : SW_HIDE); + } + void SetText(const std::string& text) + { + Static_SetText(hwnd, text.c_str()); + } + [[nodiscard]] std::string GetText() + { + int length = Static_GetTextLength(hwnd) + 1; + std::unique_ptr uptr = std::make_unique(length); + if (uptr) + { + Static_GetText(hwnd, uptr.get(), length); + return uptr.get(); + } + return ""; + } + void SetBitmap(HBITMAP hBitmap) + { + SendMessageA(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap); + } +protected: + HWND hwnd; +}; + +class DiceGUI : public BaseWindow +{ +public: + int CurrentTab = 0; + map> TabChangeFunction; + HWND Tab{}; + + // CustomMsg + LVITEMA itemNow{}; + BasicButton ButtonSaveCustomMsg; + BasicListView ListViewCustomMsg; + int ListViewCustomMsgCurrentActivated = -1; + BasicEdit EditCustomMsg; + BasicStatic StaticMainLabel; + + // Master + BasicListView ListViewUserTrust; + BasicButton ButtonMaster; + BasicStatic StaticMasterLabel; + BasicEdit EditMaster; + BasicStatic StaticUserTrustLabel; + BasicEdit EditUserTrustID; + BasicButton ButtonUserRemove; + BasicEdit EditUserTrustLevel; + BasicButton ButtonUserTrustLevelSet; + BasicListView ListViewConfig; + BasicStatic StaticCurrentSettingLabel; + BasicStatic StaticCurrentConfigLabel; + BasicStatic StaticValueLabel; + BasicEdit EditConfigValue; + BasicButton ButtonConfigSet; + + // About + BasicStatic StaticImageDiceLogo; + BasicStatic StaticVersionInfo; + BasicStatic StaticAuthorInfo; + BasicStatic StaticSupportLabel; + BasicButton ButtonSupport; + BasicButton ButtonDocument; + BasicButton ButtonGithub; + BasicButton ButtonQQGroup; + + // All + std::map Fonts; + std::vector Bitmaps; + std::unordered_map nicknameMp; + + DiceGUI(const std::unordered_map& nicknameMp); + DiceGUI(std::unordered_map&& nicknameMp); + PCSTR ClassName() const override { return "DiceGUI"; } + LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override; + LRESULT CreateCustomMsgPage(); + LRESULT CreateMasterPage(); + LRESULT CreateAboutPage(); + LRESULT ShowCustomMsgPage(bool Show); + LRESULT ShowMasterPage(bool Show); + LRESULT ShowAboutPage(bool Show); +}; + +struct ListViewSorting +{ + BasicListView* pLV; + int Column; + bool isAsc; +}; + +int CALLBACK ListViewUserTrustComp(LPARAM lp1, LPARAM lp2, LPARAM sortParam) +{ + ListViewSorting sort = *reinterpret_cast(sortParam); + bool isAsc = sort.isAsc; + int column = sort.Column; + std::string str1 = sort.pLV->GetItemText(lp1, column); + std::string str2 = sort.pLV->GetItemText(lp2, column); + try + { + switch (column) + { + case 0: + if (isAsc) return (int)std::clamp(std::stoll(str1) - std::stoll(str2), (long long)INT_MIN , (long long)INT_MAX); + else return (int)std::clamp(std::stoll(str2) - std::stoll(str1), (long long)INT_MIN, (long long)INT_MAX); + break; + case 1: + return 0; + case 2: + if (isAsc) return (int)std::clamp(std::stoll(str1) - std::stoll(str2), (long long)INT_MIN, (long long)INT_MAX); + else return (int)std::clamp(std::stoll(str2) - std::stoll(str1), (long long)INT_MIN, (long long)INT_MAX); + break; + default: + return 0; + } + } + catch(...) + { + return 0; + } + return 0; +} + +DiceGUI::DiceGUI(std::unordered_map&& nicknameMp) : nicknameMp(std::move(nicknameMp)) +{ + TabChangeFunction[0] = std::bind(&DiceGUI::ShowCustomMsgPage, std::ref(*this), std::placeholders::_1); + TabChangeFunction[1] = std::bind(&DiceGUI::ShowMasterPage, std::ref(*this), std::placeholders::_1); + TabChangeFunction[2] = std::bind(&DiceGUI::ShowAboutPage, std::ref(*this), std::placeholders::_1); +} + +DiceGUI::DiceGUI(const std::unordered_map& nicknameMp) : nicknameMp(nicknameMp) +{ + TabChangeFunction[0] = std::bind(&DiceGUI::ShowCustomMsgPage, std::ref(*this), std::placeholders::_1); + TabChangeFunction[1] = std::bind(&DiceGUI::ShowMasterPage, std::ref(*this), std::placeholders::_1); + TabChangeFunction[2] = std::bind(&DiceGUI::ShowAboutPage, std::ref(*this), std::placeholders::_1); +} + +LRESULT DiceGUI::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + + case WM_CREATE: + { + + RECT rcClient; // The parent window's client area. + GetClientRect(m_hwnd, &rcClient); + + Tab = CreateWindowA(WC_TABCONTROLA, "", + WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | TCS_FIXEDWIDTH , + 0, 0, rcClient.right, rcClient.bottom, + m_hwnd, NULL, ((LPCREATESTRUCTA)lParam)->hInstance, NULL); + + TCITEMA tie; + // Tab 0 + tie.mask = TCIF_TEXT; + tie.pszText = const_cast("Զظ"); + if (TabCtrl_InsertItem(Tab, 0, &tie) == -1) + { + DestroyWindow(Tab); + return -1; + } + // Tab 1 + tie.pszText = const_cast("Master"); + if (TabCtrl_InsertItem(Tab, 1, &tie) == -1) + { + DestroyWindow(Tab); + return -1; + } + // Tab 2 + tie.pszText = const_cast(""); + if (TabCtrl_InsertItem(Tab, 2, &tie) == -1) + { + DestroyWindow(Tab); + return -1; + } + + // /ͼƬ + Fonts["Yahei14"] = CreateFontA(14, 0, 0, 0, FW_DONTCARE, FALSE, + FALSE, FALSE, GB2312_CHARSET, OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "΢ź"); + Fonts["Yahei18"] = CreateFontA(18, 0, 0, 0, FW_DONTCARE, FALSE, + FALSE, FALSE, GB2312_CHARSET, OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "΢ź"); + Fonts["Yahei22"] = CreateFontA(22, 0, 0, 0, FW_DONTCARE, FALSE, + FALSE, FALSE, GB2312_CHARSET, OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "΢ź"); + + SendMessage(m_hwnd, WM_SETFONT, (WPARAM)Fonts["Yahei14"], 1); + SendMessage(Tab, WM_SETFONT, (WPARAM)Fonts["Yahei18"], 1); + CreateCustomMsgPage(); + ShowCustomMsgPage(true); + CreateMasterPage(); + ShowMasterPage(false); + CreateAboutPage(); + ShowAboutPage(false); + + return 0; + + } + + return 0; + case WM_CLOSE: + if (MessageBoxA(m_hwnd, "δ/õĿᱻ棬ȷ˳?", "Dice! GUI", MB_OKCANCEL) == IDOK) + { + DestroyWindow(m_hwnd); + } + return 0; + + case WM_DESTROY: + PostQuitMessage(0); + for (const auto& font: Fonts) + { + DeleteObject(font.second); + } + for (const auto& bitmap : Bitmaps) + { + DeleteObject(bitmap); + } + Fonts.clear(); + Bitmaps.clear(); + return 0; + + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(m_hwnd, &ps); + FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1)); + EndPaint(m_hwnd, &ps); + } + return 0; + case WM_CTLCOLORSTATIC: + { + HDC hdcStatic = (HDC)wParam; + //SetTextColor(hdcStatic, RGB(255, 255, 255)); + SetBkMode(hdcStatic, TRANSPARENT); + return (INT_PTR)(HBRUSH)GetStockObject(COLOR_WINDOW + 1); + } + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDB_BUTTON_SAVE: + { + if (ListViewCustomMsgCurrentActivated == -1) return 0; + std::string curr = ListViewCustomMsg.GetItemText(ListViewCustomMsgCurrentActivated); + std::string str = EditCustomMsg.GetText(); + GlobalMsg[curr] = str; + EditedMsg[curr] = str; + ListViewCustomMsg.SetItemText(str, ListViewCustomMsgCurrentActivated, 1); + saveJMap(DiceDir + "\\conf\\CustomMsg.json", EditedMsg); + } + return 0; + case ID_MASTER_BUTTONMASTER: + { + std::string str = EditMaster.GetText(); + while (str.length() > 1 && str[0] == '0')str.erase(str.begin()); + if (str == "0") + { + if (console) + { + console.killMaster(); + StaticMasterLabel.SetText("Masterģʽѹر"); + MessageBoxA(nullptr, "Masterģʽѹرա\nmaster", "Masterģʽл", MB_OK | MB_ICONINFORMATION); + console.isMasterMode = false; + } + return 0; + } + + if (str.length() < 5 || str.length() > 17) + { + MessageBoxA(m_hwnd, "QQЧ!", "Dice! GUI", MB_OK | MB_ICONWARNING); + return 0; + } + long long qq = std::stoll(str); + StaticMasterLabel.SetText("ǰMasterΪ" + to_string(qq) + "(QQΪ0ԹرMasterģʽ)"); + if (console) + { + if (console.masterQQ != qq) + { + console.killMaster(); + console.newMaster(qq); + } + } + else + { + MessageBoxA(nullptr, "Masterģʽѿ", "Masterģʽл", MB_OK | MB_ICONINFORMATION); + console.newMaster(qq); + console.isMasterMode = true; + } + + } + return 0; + case ID_MASTER_BUTTONUSERTRUSTREMOVE: + { + std::string str = EditUserTrustID.GetText(); + while (str.length() > 1 && str[0] == '0')str.erase(str.begin()); + if (str.length() < 5 || str.length() > 17) + { + MessageBoxA(m_hwnd, "QQЧ!", "Dice! GUI", MB_OK | MB_ICONWARNING); + return 0; + } + long long qq = std::stoll(str); + int ret = ListViewUserTrust.GetItemIndexByText(str); + if (ret == -1 && !UserList.count(qq)) + { + MessageBoxA(m_hwnd, "Ҳû", "Dice GUI!", MB_OK | MB_ICONWARNING); + } + else + { + if (ret != -1) ListView_DeleteItem(ListViewUserTrust.Window(), ret); + if (UserList.count(qq)) UserList.erase(qq); + } + } + return 0; + case ID_MASTER_BUTTONUSERTRUSTSET: + { + std::string str = EditUserTrustID.GetText(); + while (str.length() > 1 && str[0] == '0')str.erase(str.begin()); + if (str.length() < 5 || str.length() > 17) + { + MessageBoxA(m_hwnd, "QQЧ!", "Dice! GUI", MB_OK | MB_ICONWARNING); + return 0; + } + long long qq = std::stoll(str); + int ret = ListViewUserTrust.GetItemIndexByText(str); + + string trust = EditUserTrustLevel.GetText(); + if (trust.length() != 1) + { + MessageBoxA(m_hwnd, "εȼЧ!", "Dice! GUI", MB_OK | MB_ICONWARNING); + return 0; + } + int trustlevel = std::stoi(trust); + if (trustlevel < 0 || trustlevel > 5) + { + MessageBoxA(m_hwnd, "εȼЧ!", "Dice! GUI", MB_OK | MB_ICONWARNING); + return 0; + } + UserList[qq].trust(trustlevel); + + if (ret == -1) + { + string nickname = CQ::getStrangerInfo(qq).nick; + ListViewUserTrust.AddTextRow({ str, nickname, trust }); + } + else + { + ListViewUserTrust.SetItemText(trust, ret, 2); + } + } + return 0; + case ID_MASTER_BUTTONCONFIGSET: + { + std::string text = StaticCurrentConfigLabel.GetText(); + int index = ListViewConfig.GetItemIndexByText(text); + if (index == -1)return 0; + std::string valstr = EditConfigValue.GetText(); + while (valstr.length() > 1 && valstr[0] == '0')valstr.erase(valstr.begin()); + if (valstr.length() == 0 || valstr.length() > 9) + { + MessageBoxA(m_hwnd, "ֵЧ!", "Dice! GUI", MB_OK | MB_ICONWARNING); + return 0; + } + int val = std::stoi(valstr); + console.set(text, val); + ListViewConfig.SetItemText(valstr, index, 1); + } + return 0; + case ID_ABOUT_BUTTONSUPPORT: + { + ShellExecute(m_hwnd, "open", "https://afdian.net/@suhuiw4123", nullptr, nullptr, SW_SHOWDEFAULT); + } + return 0; + case ID_ABOUT_BUTTONGITHUB: + { + ShellExecute(m_hwnd, "open", "https://github.com/w4123/Dice", nullptr, nullptr, SW_SHOWDEFAULT); + } + return 0; + case ID_ABOUT_BUTTONQQGROUP: + { + ShellExecute(m_hwnd, "open", "https://jq.qq.com/?_wv=1027&k=Wy9CsHcq", nullptr, nullptr, SW_SHOWDEFAULT); + } + return 0; + case ID_ABOUT_BUTTONDOCUMENT: + { + MessageBoxA(m_hwnd, "ĵ, ʱ!", "Dice! GUI", MB_OK); + } + return 0; + default: + return DefWindowProc(m_hwnd, uMsg, wParam, lParam); + } + return TRUE; + } + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + case LVN_ITEMACTIVATE: + if (((LPNMHDR)lParam)->idFrom == IDM_LIST_MSG) + { + LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)lParam; + if (lpnmitem->iItem != -1) + { + std::string text = ListViewCustomMsg.GetItemText(lpnmitem->iItem); + ListViewCustomMsgCurrentActivated = lpnmitem->iItem; + EditCustomMsg.SetText(GlobalMsg[text]); + } + return 0; + } + else if(((LPNMHDR)lParam)->idFrom == ID_MASTER_LISTVIEWUSERTRUST) + { + LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)lParam; + if (lpnmitem->iItem != -1) + { + string text = ListViewUserTrust.GetItemText(lpnmitem->iItem); + EditUserTrustID.SetText(text); + string trust = ListViewUserTrust.GetItemText(lpnmitem->iItem, 2); + EditUserTrustLevel.SetText(trust); + } + } + else if(((LPNMHDR)lParam)->idFrom == ID_MASTER_LISTVIEWCONFIG) + { + LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)lParam; + if (lpnmitem->iItem != -1) + { + string text = ListViewConfig.GetItemText(lpnmitem->iItem); + StaticCurrentConfigLabel.SetText(text); + string value = ListViewConfig.GetItemText(lpnmitem->iItem, 1); + EditConfigValue.SetText(value); + } + } + return 0; + case LVN_COLUMNCLICK: + if (((LPNMHDR)lParam)->idFrom == ID_MASTER_LISTVIEWUSERTRUST) + { + LPNMLISTVIEW pLVInfo = reinterpret_cast(lParam); + static int nSortColumn = 0; + static BOOL bSortAscending = TRUE; + + // get new sort parameters + if (pLVInfo->iSubItem == nSortColumn) + bSortAscending = !bSortAscending; + else + { + nSortColumn = pLVInfo->iSubItem; + bSortAscending = TRUE; + } + ListViewSorting sort{ &this->ListViewUserTrust, nSortColumn, (bool)bSortAscending }; + ListView_SortItemsEx(ListViewUserTrust.Window(), ListViewUserTrustComp, reinterpret_cast(&sort)); + } + case TCN_SELCHANGING: + return 0; + case TCN_SELCHANGE: + { + if (TabChangeFunction[CurrentTab](false)) return -1; + CurrentTab = TabCtrl_GetCurSel(Tab); + if (TabChangeFunction[CurrentTab](true)) return -1; + } + return 0; + default: + return DefWindowProc(m_hwnd, uMsg, wParam, lParam); + } + } + default: + return DefWindowProc(m_hwnd, uMsg, wParam, lParam); + } + return TRUE; +} + +LRESULT DiceGUI::CreateCustomMsgPage() +{ + RECT rcClient; + GetClientRect(m_hwnd, &rcClient); + DiceLogger.Info(to_string(rcClient.right)); + DiceLogger.Info(to_string(rcClient.bottom)); + + ButtonSaveCustomMsg.Create("", WS_CHILD | WS_VISIBLE, 0, + 80, rcClient.bottom - 70, 70, 30, m_hwnd, (HMENU)IDB_BUTTON_SAVE); + + EditCustomMsg.Create("˫беĿ", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER, 0, + 300, rcClient.bottom - 80, rcClient.right - rcClient.left - 320, 60, m_hwnd, (HMENU)ID_EDIT); + + + StaticMainLabel.Create("ӭDice!Զظ޸\r\n˫Ҳ⣬·ı\r\nı\r\nÿı޸ĺһ", + WS_CHILD | WS_VISIBLE, 0, + 25, 40, 230, 200, m_hwnd, (HMENU)ID_MAINLABEL); + + ListViewCustomMsg.Create("", + WS_CHILD | LVS_REPORT | WS_VISIBLE | WS_BORDER | LVS_SINGLESEL, + 0, + 300, 40, + rcClient.right - rcClient.left - 320, + rcClient.bottom - rcClient.top - 140, + m_hwnd, + (HMENU)IDM_LIST_MSG); + ListViewCustomMsg.SetExtendedListViewStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_AUTOSIZECOLUMNS | LVS_EX_TWOCLICKACTIVATE | LVS_EX_UNDERLINEHOT); + + ListViewCustomMsg.AddAllTextColumn(std::map{ {"", 150}, { "", 500 } }); + int index = 0; + for (const auto& item : GlobalMsg) + { + ListViewCustomMsg.AddTextRow({ item.first, item.second }, index); + index++; + } + + HFONT Yahei18 = Fonts["Yahei18"]; + ButtonSaveCustomMsg.SetFont(Yahei18); + EditCustomMsg.SetFont(Yahei18); + StaticMainLabel.SetFont(Yahei18); + return 0; +} + +LRESULT DiceGUI::CreateMasterPage() +{ + RECT rcClient; + GetClientRect(m_hwnd, &rcClient); + ButtonMaster.Create("Master", + WS_CHILD | WS_VISIBLE, 0, rcClient.right - 180, 40, 140, 30, + m_hwnd, (HMENU)ID_MASTER_BUTTONMASTER); + + StaticMasterLabel.Create((!console ? "Masterģʽѹر" : ("ǰMasterΪ" + to_string(console.masterQQ) + "(QQΪ0ԹرMasterģʽ)").c_str()), + WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, 0, 30, 40, 450, 30, + m_hwnd, (HMENU)ID_MASTER_LABELMASTER); + + EditMaster.Create("0", + WS_CHILD | WS_VISIBLE | ES_NUMBER | WS_BORDER, + 0, 490, 40, 200, 30, + m_hwnd, (HMENU)ID_MASTER_EDITMASTER); + + ListViewUserTrust.Create("", + WS_CHILD | LVS_REPORT | WS_VISIBLE | WS_BORDER | LVS_SINGLESEL, + 0, + 30, 140, + 500, + rcClient.bottom - rcClient.top - 170, + m_hwnd, + (HMENU)ID_MASTER_LISTVIEWUSERTRUST); + ListViewUserTrust.SetExtendedListViewStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_AUTOSIZECOLUMNS | LVS_EX_TWOCLICKACTIVATE | LVS_EX_UNDERLINEHOT); + ListViewUserTrust.AddAllTextColumn({ "QQ", "dz", "εȼ" }); + int index = 0; + for (const auto& item : UserList) + { + string qq = to_string(item.first); + string trust = to_string(item.second.nTrust); + string nick = nicknameMp[item.first]; + ListViewUserTrust.AddTextRow({ qq, nick, trust }, index); + index++; + } + + + EditUserTrustID.Create(nullptr, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER, 0, + 30, 90, 200, 30, m_hwnd, (HMENU)ID_MASTER_EDITUSERTRUSTID); + + ButtonUserRemove.Create("Ƴ", WS_CHILD | WS_VISIBLE, 0, 240, 90, 80, 30, m_hwnd, + (HMENU)ID_MASTER_BUTTONUSERTRUSTREMOVE); + + StaticUserTrustLabel.Create("εȼ:", WS_CHILD | WS_VISIBLE | SS_CENTER | SS_CENTERIMAGE, 0, + 330, 90, 60, 30, m_hwnd); + + EditUserTrustLevel.Create("0", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER, 0, + 400, 90, 40, 30, m_hwnd, (HMENU)ID_MASTER_EDITUSERTRUSTLEVEL); + + ButtonUserTrustLevelSet.Create("", WS_CHILD | WS_VISIBLE, 0, 450, 90, 80, 30, m_hwnd, + (HMENU)ID_MASTER_BUTTONUSERTRUSTSET); + + ListViewConfig.Create(nullptr, WS_CHILD | LVS_REPORT | WS_VISIBLE | WS_BORDER | LVS_SINGLESEL, + 0, 550, 140, rcClient.right - rcClient.left - 590, rcClient.bottom - rcClient.top - 170, + m_hwnd, (HMENU)ID_MASTER_LISTVIEWCONFIG); + + ListViewConfig.SetExtendedListViewStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_AUTOSIZECOLUMNS | LVS_EX_TWOCLICKACTIVATE | LVS_EX_UNDERLINEHOT); + + ListViewConfig.AddAllTextColumn({ "Ŀ", "ֵ" }); + int index1 = 0; + for (const auto& item:console.intDefault) + { + string value = to_string(console[item.first.c_str()]); + ListViewConfig.AddTextRow({item.first, value}, index1); + index1++; + } + + StaticCurrentSettingLabel.Create("ǰĿ:", WS_CHILD | WS_VISIBLE | SS_CENTER | SS_CENTERIMAGE, 0, + 550, 90, 60, 30, m_hwnd); + + StaticCurrentConfigLabel.Create("", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, 0, + 620, 90, 150, 30, m_hwnd, (HMENU)ID_MASTER_STATICCURRENTCONFIGLABEL); + + StaticValueLabel.Create("ֵ:", WS_CHILD | WS_VISIBLE | SS_CENTER | SS_CENTERIMAGE, 0, + 780, 90, 40, 30, m_hwnd); + + EditConfigValue.Create("0", WS_CHILD | WS_VISIBLE | ES_NUMBER | WS_BORDER, 0, + 830, 90, 100, 30, m_hwnd, (HMENU)ID_MASTER_EDITCONFIGVALUE); + + ButtonConfigSet.Create("", WS_CHILD | WS_VISIBLE, 0, + 940, 90, rcClient.right - rcClient.left - 980, 30, m_hwnd, (HMENU)ID_MASTER_BUTTONCONFIGSET); + + HFONT Yahei18 = Fonts["Yahei18"]; + ButtonMaster.SetFont(Yahei18); + StaticMasterLabel.SetFont(Yahei18); + EditMaster.SetFont(Yahei18); + EditUserTrustID.SetFont(Yahei18); + ButtonUserRemove.SetFont(Yahei18); + EditUserTrustLevel.SetFont(Yahei18); + ButtonUserTrustLevelSet.SetFont(Yahei18); + StaticUserTrustLabel.SetFont(Yahei18); + StaticCurrentSettingLabel.SetFont(Yahei18); + StaticCurrentConfigLabel.SetFont(Yahei18); + StaticValueLabel.SetFont(Yahei18); + EditConfigValue.SetFont(Yahei18); + ButtonConfigSet.SetFont(Yahei18); + return 0; +} + +LRESULT DiceGUI::CreateAboutPage() +{ + StaticImageDiceLogo.Create(nullptr, WS_CHILD | WS_VISIBLE | SS_BITMAP | SS_REALSIZECONTROL, 0, + 40, 40, 300, 300, m_hwnd); + + StaticVersionInfo.Create(Dice_Full_Ver_For.c_str(), WS_CHILD | WS_VISIBLE, 0, + 40, 350, 300, 50, m_hwnd); + + StaticAuthorInfo.Create("Ҫ: Shiki\r\nAGPLv3Э¿Դ", WS_CHILD | WS_VISIBLE, 0, + 40, 400, 300, 50, m_hwnd); + + StaticSupportLabel.Create("ϲӦ, Կ:", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, 0, + 40, 440, 200, 30, m_hwnd); + + ButtonSupport.Create("", WS_CHILD | WS_VISIBLE, 0, + 250, 440, 90, 30, m_hwnd, (HMENU)ID_ABOUT_BUTTONSUPPORT); + + ButtonDocument.Create("ĵ", WS_CHILD | WS_VISIBLE, 0, + 40, 480, 80, 30, m_hwnd, (HMENU)ID_ABOUT_BUTTONDOCUMENT); + + ButtonGithub.Create("Դ", WS_CHILD | WS_VISIBLE, 0, + 150, 480, 80, 30, m_hwnd, (HMENU)ID_ABOUT_BUTTONGITHUB); + + ButtonQQGroup.Create("ӹٷȺ", WS_CHILD | WS_VISIBLE, 0, + 260, 480, 80, 30, m_hwnd, (HMENU)ID_ABOUT_BUTTONQQGROUP); + + HBITMAP hBitmap = (HBITMAP)LoadImageA(hDllModule, MAKEINTRESOURCEA(ID_BITMAP_DICELOGO), IMAGE_BITMAP, 0, 0, LR_SHARED); + StaticImageDiceLogo.SetBitmap(hBitmap); + + + HFONT Yahei18 = Fonts["Yahei18"]; + StaticVersionInfo.SetFont(Yahei18); + StaticAuthorInfo.SetFont(Yahei18); + StaticSupportLabel.SetFont(Yahei18); + ButtonSupport.SetFont(Yahei18); + ButtonDocument.SetFont(Yahei18); + ButtonGithub.SetFont(Yahei18); + ButtonQQGroup.SetFont(Yahei18); + + return 0; +} + +LRESULT DiceGUI::ShowCustomMsgPage(bool Show) +{ + ButtonSaveCustomMsg.Show(Show); + ListViewCustomMsg.Show(Show); + EditCustomMsg.Show(Show); + StaticMainLabel.Show(Show); + return 0; +} + +LRESULT DiceGUI::ShowMasterPage(bool Show) +{ + StaticMasterLabel.Show(Show); + EditMaster.Show(Show); + ButtonMaster.Show(Show); + ListViewUserTrust.Show(Show); + EditUserTrustID.Show(Show); + ButtonUserRemove.Show(Show); + EditUserTrustLevel.Show(Show); + ButtonUserTrustLevelSet.Show(Show); + StaticUserTrustLabel.Show(Show); + ListViewConfig.Show(Show); + StaticCurrentSettingLabel.Show(Show); + StaticCurrentConfigLabel.Show(Show); + StaticValueLabel.Show(Show); + EditConfigValue.Show(Show); + ButtonConfigSet.Show(Show); + return 0; +} + +LRESULT DiceGUI::ShowAboutPage(bool Show) +{ + StaticImageDiceLogo.Show(Show); + StaticVersionInfo.Show(Show); + StaticAuthorInfo.Show(Show); + StaticSupportLabel.Show(Show); + ButtonSupport.Show(Show); + ButtonDocument.Show(Show); + ButtonGithub.Show(Show); + ButtonQQGroup.Show(Show); + return 0; +} + +int WINAPI GUIMain() +{ + // hDllModuleӦΪ + assert(hDllModule); + + // ʼCommonControl + INITCOMMONCONTROLSEX icex; // Structure for control initialization. + icex.dwSize = sizeof(INITCOMMONCONTROLSEX); + icex.dwICC = ICC_STANDARD_CLASSES | ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES | ICC_PROGRESS_CLASS; + InitCommonControlsEx(&icex); + + // Nickname洢ṹ + std::unordered_map nicknameMp; + + // + HWND progress = CreateWindowA(PROGRESS_CLASSA, nullptr, WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_BORDER | PBS_SMOOTHREVERSE | PBS_SMOOTH + , CW_USEDEFAULT, CW_USEDEFAULT, 200, 50, nullptr, nullptr, hDllModule, nullptr); + SendMessageA(progress, PBM_SETRANGE, 0, MAKELPARAM(0, UserList.size())); + + SendMessageA(progress, PBM_SETSTEP, (WPARAM)1, 0); + ShowWindow(progress, SW_SHOWDEFAULT); + + // ȡNickname + for (const auto& item:UserList) + { + nicknameMp[item.first] = CQ::getStrangerInfo(item.first).nick; + SendMessageA(progress, PBM_STEPIT, 0, 0); + MSG msg; + while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + } + DestroyWindow(progress); + + // GUI + DiceGUI MainWindow(std::move(nicknameMp)); + + if (!MainWindow.Create("Dice! GUI", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_BORDER | WS_CLIPSIBLINGS, 0, CW_USEDEFAULT, CW_USEDEFAULT,1146, 564)) + { + return 0; + } + + ShowWindow(MainWindow.Window(), SW_SHOWDEFAULT); + + // Run the message loop. + + MSG msg = { }; + while (GetMessageA(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + + return 0; +} diff --git a/Dice/DiceGUI.h b/Dice/DiceGUI.h new file mode 100644 index 00000000..668f971f --- /dev/null +++ b/Dice/DiceGUI.h @@ -0,0 +1,7 @@ +#pragma once +#ifndef DICE_GUI +#define DICE_GUI +#define WIN32_LEAN_AND_MEAN +#include +int WINAPI GUIMain(); +#endif \ No newline at end of file diff --git a/Dice/DiceL5R.cpp b/Dice/DiceL5R.cpp new file mode 100644 index 00000000..4099fce2 --- /dev/null +++ b/Dice/DiceL5R.cpp @@ -0,0 +1,196 @@ +#include "DiceL5R.h" +#include +#include +#include "CQTools.h" +#include "GlobalVar.h" + +using namespace std; + +const string DiceL5R::symbolB[7] = { "","B","O+St","O","S+St","S","ES+St" }; +const string DiceL5R::symbolW[13] = { "","B","B","O","O","O","S+St","S+St","S","S","S+O","ES+St","ES" }; + +std::string DiceL5R::roll() +{ + string result; + auto iter = diceList.begin(); + int i = 1; + for (; iter != diceList.end(); iter++) + { + if (iter->status == dropped) continue; + if (iter->status == normal) + { + if (iter->type == white) + iter->result = Randint(1, 12); + else + iter->result = Randint(1, 6); + + iter->status = rolled; + } + + result += "" + to_string(i++) + ""; + if (iter->type == white) + result += symbolW[iter->result] + "(w)"; + else + result += symbolB[iter->result] + "(b)"; + + if (iter->status == additional) + result += "(add)"; + } + return result; +} + +void DiceL5R::insertW(int cnt, bool isAdd) +{ + while (cnt) + { + if (isAdd) + diceList.push_back(l5rD(white, additional, Randint(1, 12))); + else + diceList.push_back(l5rD(white, normal)); + cnt--; + } +} + +void DiceL5R::insertB(int cnt, bool isAdd) +{ + while (cnt) + { + if (isAdd) + diceList.push_back(l5rD(black, additional, Randint(1, 6))); + else + diceList.push_back(l5rD(black, normal)); + cnt--; + } + +} + +void DiceL5R::reRoll(int i) +{ + if (i > diceList.size()) + return; + + auto iter = diceList.begin(); + + if ((iter + i - 1)->type == white) + (iter + i - 1)->result = Randint(1, 12); + else + (iter + i - 1)->result = Randint(1, 6); +} + +void DiceL5R::drop(int i) +{ + if (i > diceList.size()) + return; + + auto iter = diceList.begin(); + (iter + i - 1)->status = diceStatus::dropped; + +} + +std::string DiceL5R::encodeToDB() +{ + string result; + auto iter = diceList.begin(); + for (; iter != diceList.end(); iter++) + { + if (iter->status == dropped) continue; + + if (iter->type == white) + { + result += 'w' + to_string(iter->result); + } + else + result += 'b' + to_string(iter->result); + + if (iter->status == additional) + result += 'a'; + if (iter->status == rolled) + result += 'r'; + + result += ' '; + } + return base64_encode(result); +} + +void DiceL5R::decode(std::string& read) +{ + read = base64_decode(read); + string strBuf; + stringstream ss; + stringstream buf; + char charBuf; + int intBuf; + ss.str(read); + while (ss >> strBuf) + { + buf.clear(); + buf.str(strBuf); + if (strBuf.length() == 3) + { + buf >> charBuf; + buf >> intBuf; + if (strBuf[2] == 'a') + { + if (charBuf == 'w') + { + diceList.push_back(l5rD(white, additional, intBuf)); + } + else + { + diceList.push_back(l5rD(black, additional, intBuf)); + } + } + else if (strBuf[2] == 'r') + { + if (charBuf == 'w') + { + diceList.push_back(l5rD(white, rolled, intBuf)); + } + else + { + diceList.push_back(l5rD(black, rolled, intBuf)); + } + } + } + else + { + buf >> charBuf; + buf >> intBuf; + if (charBuf == 'w') + { + diceList.push_back(l5rD(white, normal, intBuf)); + } + else + { + diceList.push_back(l5rD(black, normal, intBuf)); + } + } + } +} + + +int DiceL5R::getDiceCnt() +{ + return diceList.size(); +} + +std::string DiceL5R::getResult() +{ + string reply; + int i = 1; + auto iter = diceList.begin(); + for (; iter != diceList.end(); iter++) + { + if (iter->status == dropped) continue; + + reply += "" + to_string(i++) + ""; + if (iter->type == white) + reply += symbolW[iter->result] + "(w)"; + else + reply += symbolB[iter->result] + "(b)"; + + if (iter->status == additional) + reply += "(add)"; + } + return reply; +} \ No newline at end of file diff --git a/Dice/DiceL5R.h b/Dice/DiceL5R.h new file mode 100644 index 00000000..f74515fd --- /dev/null +++ b/Dice/DiceL5R.h @@ -0,0 +1,42 @@ +#pragma once +#include +#include +#include +#include "CharacterCard.h" + +class DiceL5R +{ +private: + enum diceType { white, black }; + enum diceStatus { normal, additional, dropped, kept, rolled }; + typedef struct l5rD + { + diceType type; + diceStatus status; + int result = 0; + l5rD(diceType a, diceStatus b) :type(a), status(b) {}; + l5rD(diceType a, diceStatus b, int r) :type(a), status(b), result(r) {}; + }l5rD; + using l5rDList = std::vector; + const static std::string symbolB[7]; + const static std::string symbolW[13]; +private: + l5rDList diceList; + int Randint(int lowest, int highest) + { + std::mt19937 gen(static_cast(RandomGenerator::GetCycleCount())); + const std::uniform_int_distribution dis(lowest, highest); + return dis(gen); + } +public: + std::string roll(); + void insertW(int, bool isAdd = false); + void insertB(int, bool isAdd = false); + void reRoll(int); + void drop(int); + std::string encodeToDB(); + void decode(std::string&); + int getDiceCnt(); + std::string getResult(); + +}; diff --git a/Dice/DiceLogo.bmp b/Dice/DiceLogo.bmp new file mode 100644 index 00000000..9786d4fd Binary files /dev/null and b/Dice/DiceLogo.bmp differ diff --git a/Dice/GlobalVar.cpp b/Dice/GlobalVar.cpp index 0361252d..7cd14daa 100644 --- a/Dice/GlobalVar.cpp +++ b/Dice/GlobalVar.cpp @@ -20,6 +20,8 @@ * You should have received a copy of the GNU Affero General Public License along with this * program. If not, see . */ +#define WIN32_LEAN_AND_MEAN +#include #include "CQLogger.h" #include "GlobalVar.h" #include "MsgFormat.h" @@ -28,9 +30,13 @@ bool Enabled = false; bool Mirai = false; + std::string Dice_Full_Ver_For = Dice_Full_Ver + " For CoolQ]"; + std::string strModulePath; +HMODULE hDllModule = nullptr; + bool msgSendThreadRunning = false; CQ::logger DiceLogger("Dice!"); @@ -295,26 +301,18 @@ std::map GlobalMsg .helpȺ 鿴Ⱥָ .help趨 ȷ趨 .help 鿴Դĵ -Ⱥ1029435374 +ٷ(ˮ)Ⱥ: 624807593 941980833 882747577 +ShikiȺ1029435374 ˽Ⱥ863062599)"} }; std::map EditedMsg; const std::map HelpDoc = { -{"",R"(556:ϵͳ -555:û¼/Ⱥϵͳ -554:ɫ -553:nameܵ -552:̨ϵͳ -551:ļȡƶ -550:ּ춨 -549:ˢ -547:ָ -537:.send)"}, -{"Э","0.ЭShiki(The StarDeathJudgementThe World)ķЭ顣㿴仰ζMasterӦĬЭ飬ע⡣\n1.ʹȺĶЭΪͬⲢŵشЭ飬ʹ.dismissƳ\n2.ԡƳˢȶIJΪЩΪﱻƲõķաӦʹ.bot on/off\n3.ĬΪȵõȺͬ⣬ԶͬȺ롣ʹΪʱδԤеΡ\n4.ֹڶIJΥΪ\n5.dzƵ޷ԤпΪܻұܾṩ\n6.ڼԼʽԭ޷֤100%ʱȶУܲʱͣάᣬӦἰʱ֪ͨͨ½⡣ʱͣﲻκӦʶӰȺڻ״̬ȻֹΪ\n7.ΥЭΪォֹûȺṩ񣬲¼ṩ˿ṩЭ̣ղöȨڷṩ\n8.ЭʱпܸĶעϢǩռ䡢ٷȺȴﶯ̬\n9.ṩȫѵģӭͶʳ\n10.սȨṩС"}, +{"",R"(V2.4.0 ๦ܸ Dice! GUI )"}, +{"Э","0.ЭDice!ĬϷЭ顣㿴仰ζMasterӦĬЭ飬ע⡣\n1.ʹȺĶЭΪͬⲢŵشЭ飬ʹ.dismissƳ\n2.ԡƳˢȶIJΪЩΪﱻƲõķաӦʹ.bot on/off\n3.ĬΪȵõȺͬ⣬ԶͬȺ롣ʹΪʱδԤеΡ\n4.ֹڶIJΥΪ\n5.dzƵ޷ԤпΪܻұܾṩ\n6.ڼԼʽԭ޷֤100%ʱȶУܲʱͣάᣬӦἰʱ֪ͨͨ½⡣ʱͣﲻκӦʶӰȺڻ״̬ȻֹΪ\n7.ΥЭΪォֹûȺṩ񣬲¼ṩ˿ṩЭ̣ղöȨڷṩ\n8.ЭʱпܸĶעϢǩռ䡢ٷȺȴﶯ̬\n9.ṩȫѵģӭͶʳ\n10.սȨṩС"}, {"","鿴Դ:https://github.com/mystringEmpty/Dice\n:https://github.com/mystringEmpty/Dice/releases\nûֲ:http://shiki.stringempty.xyz/download/Shiki_User_Manual.pdf\nֲ:http://shiki.stringempty.xyz/download/Shiki_Master_Manual.pdf\nֲ:http://shiki.stringempty.xyz/download/DiceMaid_CookBook.html\n(ĵ)https://dice.c-j.dev/\nst│:http://shiki.stringempty.xyz/download/COC7_player_card_shiki.xlsx"}, -{"趨","Master{master}\n.meʹãֹ\n.jrrpʹã\n봦ƣǽ\nʹã\nƳƣȺͲ\nԷƣĬȺȺ\nˢƣ\nΣ\nܣ\n\nȺ:δã\nٷ(ˮ)Ⱥ: 624807593 941980833 882747577\n˽Ⱥ863062599\nȺ1029435374"}, -{"","Copyright (C) 2018-2020 w4123\nCopyright (C) 2019-2020 String.Empty"}, +{"趨","Master{master}\n.meʹãֹ\n.jrrpʹã\n봦ƣǽ\nʹã\nƳƣȺͲ\nԷƣĬȺȺ\nˢƣ\nΣ\nܣ\n\nȺ:δã\nٷ(ˮ)Ⱥ: 624807593 941980833 882747577\n˽Ⱥ863062599\nShikiȺ1029435374"}, +{"","Copyright (C) 2018-2020 w4123\nCopyright (C) 2019-2020 String.Empty\nӦAGPLv3Ȩ"}, {"ָ",R"(atָָﵥӦat.bot off ָҪӲ.helpӦָ ȡϸϢ ָ: diff --git a/Dice/GlobalVar.h b/Dice/GlobalVar.h index 8e0157bb..b682318d 100644 --- a/Dice/GlobalVar.h +++ b/Dice/GlobalVar.h @@ -24,6 +24,8 @@ #pragma once #ifndef DICE_GLOBAL_VAR #define DICE_GLOBAL_VAR +#define WIN32_LEAN_AND_MEAN +#include #include "CQLogger.h" #include #include "STLExtern.hpp" @@ -33,9 +35,9 @@ * ޸Dice_Build, Dice_Ver_Without_BuildDiceRequestHeaderԼDice_Ver * ޸Dice_Short_VerDice_Full_VerԴﵽ汾Զ */ -const unsigned short Dice_Build = 561u; -inline const std::string Dice_Ver_Without_Build = "2.4.0beta"; -constexpr auto DiceRequestHeader = "Dice/2.4.0BETA"; +const unsigned short Dice_Build = 562u; +inline const std::string Dice_Ver_Without_Build = "2.4.0beta2"; +constexpr auto DiceRequestHeader = "Dice/2.4.0BETA2"; inline const std::string Dice_Ver = Dice_Ver_Without_Build + "(" + std::to_string(Dice_Build) + ")"; inline const std::string Dice_Short_Ver = "Dice! by Shiki Ver " + Dice_Ver; @@ -61,8 +63,8 @@ const std::string Dice_Full_Ver = Dice_Short_Ver + " [UNKNOWN COMPILER"; #endif - - +// DLL hModule +extern HMODULE hDllModule; // ӦǷ extern bool Enabled; diff --git a/Dice/ManagerSystem.cpp b/Dice/ManagerSystem.cpp index b1dc3bcc..aa993866 100644 --- a/Dice/ManagerSystem.cpp +++ b/Dice/ManagerSystem.cpp @@ -54,9 +54,6 @@ string getName(long long QQ, long long GroupID) string nick; if (getUser(QQ).getNick(nick, GroupID))return nick; if (GroupID && !(nick = strip(CQ::getGroupMemberInfo(GroupID, QQ).GroupNick)).empty())return nick; - CQ::FriendInfo frd = CQ::getFriendList()[QQ]; - if (!(nick = strip(frd.remark)).empty())return nick; - if (!(nick = strip(frd.nick)).empty())return nick; if (!(nick = strip(CQ::getStrangerInfo(QQ).nick)).empty())return nick; return GlobalMsg["stranger"] + "(" + to_string(QQ) + ")"; } diff --git a/Dice/Resource.aps b/Dice/Resource.aps new file mode 100644 index 00000000..14abb9ab Binary files /dev/null and b/Dice/Resource.aps differ diff --git a/Dice/Resource.rc b/Dice/Resource.rc new file mode 100644 index 00000000..35c41535 --- /dev/null +++ b/Dice/Resource.rc @@ -0,0 +1,118 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// (壬й) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) +LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED +#pragma code_page(936) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_ICON ICON "Dice.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 2,4,0,0 + PRODUCTVERSION 2,4,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0xbL +#else + FILEFLAGS 0xaL +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080404b0" + BEGIN + VALUE "CompanyName", "Dice! Developer Group" + VALUE "FileDescription", "Dice! Main Dll" + VALUE "FileVersion", "2.4.0.0" + VALUE "InternalName", "app.dll" + VALUE "LegalCopyright", "Copyright (C) 2020 Shiki" + VALUE "OriginalFilename", "app.dll" + VALUE "ProductName", "Dice!" + VALUE "ProductVersion", "2.4.0.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x804, 1200 + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +ID_BITMAP_DICELOGO BITMAP "DiceLogo.bmp" + +#endif // (壬й) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Dice/app.json b/Dice/app.json index 55bd441d..34f2626e 100644 --- a/Dice/app.json +++ b/Dice/app.json @@ -112,6 +112,10 @@ { "name": "全局开关", "function": "eventGlobalSwitch" + }, + { + "name": "综合管理", + "function": "eventGUI" } ], "status": [ // 悬浮窗状态(将应用运行状态等显示在酷Q悬浮窗) diff --git a/Dice/dllmain.cpp b/Dice/dllmain.cpp index d2f7f090..daba03f4 100644 --- a/Dice/dllmain.cpp +++ b/Dice/dllmain.cpp @@ -22,11 +22,13 @@ */ #define WIN32_LEAN_AND_MEAN #include +#include "GlobalVar.h" BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { + hDllModule = hModule; return TRUE; } diff --git a/Dice/resource.h b/Dice/resource.h new file mode 100644 index 00000000..45eb4dc5 --- /dev/null +++ b/Dice/resource.h @@ -0,0 +1,39 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ ɵİļ +// Resource.rc ʹ +// +#define IDI_ICON1 108 +#define IDI_ICON 108 +#define ID_BITMAP_DICELOGO 109 +#define IDB_BUTTON_SAVE 201 +#define IDM_LIST_MSG 301 +#define ID_EDIT 501 +#define ID_MAINLABEL 502 +#define ID_MASTER_BUTTONMASTER 1001 +#define ID_MASTER_LABELMASTER 1002 +#define ID_MASTER_EDITMASTER 1003 +#define ID_MASTER_LISTVIEWUSERTRUST 1004 +#define ID_MASTER_EDITUSERTRUSTID 1005 +#define ID_MASTER_BUTTONUSERTRUSTREMOVE 1006 +#define ID_MASTER_EDITUSERTRUSTLEVEL 1007 +#define ID_MASTER_BUTTONUSERTRUSTSET 1008 +#define ID_MASTER_LISTVIEWCONFIG 1009 +#define ID_MASTER_STATICCURRENTCONFIGLABEL 1010 +#define ID_MASTER_EDITCONFIGVALUE 1011 +#define ID_MASTER_BUTTONCONFIGSET 1012 +#define ID_ABOUT_BUTTONSUPPORT 1100 +#define ID_ABOUT_BUTTONDOCUMENT 1101 +#define ID_ABOUT_BUTTONGITHUB 1102 +#define ID_ABOUT_BUTTONQQGROUP 1103 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NO_MFC 1 +#define _APS_NEXT_RESOURCE_VALUE 110 +#define _APS_NEXT_COMMAND_VALUE 40005 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 119 +#endif +#endif