From 384e22ff04bea85832deb660cec19e6b6ab28046 Mon Sep 17 00:00:00 2001 From: ZeaS Date: Thu, 5 Jul 2018 20:55:20 +0800 Subject: [PATCH] some new features: - keyboard support & key remap (in develop) - custom skin (in develop) and fix some bugs --- .../ConfigManager/GlobalConfigManager.cpp | 26 +- .../ConfigManager/GlobalConfigManager.h | 5 + .../ConfigManager/LocaleConfigManager.cpp | 2 + src/core/environ/cocos2d/CCKeyCodeConv.cpp | 326 ++++++++++++++++++ src/core/environ/cocos2d/CCKeyCodeConv.h | 216 +----------- src/core/environ/cocos2d/CustomFileUtils.cpp | 152 +++++++- src/core/environ/cocos2d/CustomFileUtils.h | 54 +-- src/core/environ/cocos2d/MainScene.cpp | 100 ++++-- src/core/environ/ui/GlobalPreferenceForm.cpp | 20 +- .../environ/ui/IndividualPreferenceForm.cpp | 19 +- src/core/environ/ui/MainFileSelectorForm.cpp | 37 +- src/core/environ/ui/MessageBox.cpp | 2 +- src/core/environ/ui/PreferenceConfig.h | 58 ++++ src/core/environ/ui/PreferenceForm.cpp | 116 ++++++- src/core/environ/ui/PreferenceForm.h | 47 ++- src/core/environ/ui/SeletListForm.cpp | 53 +++ src/core/environ/ui/SeletListForm.h | 20 +- src/core/environ/ui/XP3RepackForm.cpp | 10 +- src/core/environ/ui/extension/UIExtension.cpp | 1 + src/core/visual/FontImpl.h | 1 + src/core/visual/GraphicsLoaderIntf.cpp | 111 +++--- src/core/visual/GraphicsLoaderIntf.h | 2 + src/core/visual/LayerIntf.cpp | 24 ++ src/core/visual/ogl/imagepacker.cpp | 1 + src/core/visual/win32/BitmapBitsAlloc.cpp | 10 +- src/core/visual/win32/LayerBitmapImpl.cpp | 4 +- 26 files changed, 1027 insertions(+), 390 deletions(-) create mode 100644 src/core/environ/cocos2d/CCKeyCodeConv.cpp diff --git a/src/core/environ/ConfigManager/GlobalConfigManager.cpp b/src/core/environ/ConfigManager/GlobalConfigManager.cpp index f1b46222..c92e86d3 100644 --- a/src/core/environ/ConfigManager/GlobalConfigManager.cpp +++ b/src/core/environ/ConfigManager/GlobalConfigManager.cpp @@ -66,6 +66,14 @@ void iSysConfigManager::Initialize() { CustomArguments.emplace_back(key, val); } } + for (tinyxml2::XMLElement *item = rootElement->FirstChildElement("KeyMap"); item; item = item->NextSiblingElement("KeyMap")) { + int key, val; + if (tinyxml2::XML_SUCCESS == item->QueryIntAttribute("key", &key) && + tinyxml2::XML_SUCCESS == item->QueryIntAttribute("value", &val) && + key && val) { + KeyMap.emplace(key, val); + } + } } } if (fp) fclose(fp); @@ -90,7 +98,14 @@ void iSysConfigManager::SaveToFile() { item->SetAttribute("value", it->second.c_str()); rootElement->LinkEndChild(item); } - + for (auto &it : KeyMap) { + if (it.first && it.second) { + tinyxml2::XMLElement *item = doc.NewElement("KeyMap"); + item->SetAttribute("key", it.first); + item->SetAttribute("value", it.second); + rootElement->LinkEndChild(item); + } + } doc.LinkEndChild(rootElement); XMLMemPrinter stream; doc.Print(&stream); @@ -162,6 +177,15 @@ void iSysConfigManager::SetValue(const std::string &name, const std::string & va ConfigUpdated = true; } +void iSysConfigManager::SetKeyMap(int k/* 0 means remove */, int v) +{ + if (v == 0) { + KeyMap.erase(k); + } else { + KeyMap[k] = v; + } +} + std::vector iSysConfigManager::GetCustomArgumentsForPush() { std::vector ret; for (auto arg : CustomArguments) { diff --git a/src/core/environ/ConfigManager/GlobalConfigManager.h b/src/core/environ/ConfigManager/GlobalConfigManager.h index f1e85f21..b7d281cc 100644 --- a/src/core/environ/ConfigManager/GlobalConfigManager.h +++ b/src/core/environ/ConfigManager/GlobalConfigManager.h @@ -2,11 +2,13 @@ #include #include #include +#include class iSysConfigManager { protected: std::unordered_map AllConfig; std::vector > CustomArguments; + std::map KeyMap; bool ConfigUpdated; @@ -31,6 +33,9 @@ class iSysConfigManager { return CustomArguments; } + const std::map& GetKeyMap() { return KeyMap; } + void SetKeyMap(int k, int v/* 0 means remove */); + const std::vector > &GetCustomArguments() const { return CustomArguments; } std::vector GetCustomArgumentsForPush(); diff --git a/src/core/environ/ConfigManager/LocaleConfigManager.cpp b/src/core/environ/ConfigManager/LocaleConfigManager.cpp index b6329ba6..e02548f9 100644 --- a/src/core/environ/ConfigManager/LocaleConfigManager.cpp +++ b/src/core/environ/ConfigManager/LocaleConfigManager.cpp @@ -72,6 +72,7 @@ bool LocaleConfigManager::initText(cocos2d::ui::Text *ctrl, const std::string &t std::string txt = GetText(tid); if (txt.empty()) { + ctrl->setString(tid); ctrl->setColor(cocos2d::Color3B::RED); return false; } @@ -85,6 +86,7 @@ bool LocaleConfigManager::initText(cocos2d::ui::Button *ctrl, const std::string std::string txt = GetText(tid); if (txt.empty()) { + ctrl->setTitleText(tid); ctrl->setTitleColor(cocos2d::Color3B::RED); return false; } diff --git a/src/core/environ/cocos2d/CCKeyCodeConv.cpp b/src/core/environ/cocos2d/CCKeyCodeConv.cpp new file mode 100644 index 00000000..e8eb1ff1 --- /dev/null +++ b/src/core/environ/cocos2d/CCKeyCodeConv.cpp @@ -0,0 +1,326 @@ +#include "CCKeyCodeConv.h" +#include "cocos/base/CCController.h" +#include "vkdefine.h" + +int TVPConvertMouseBtnToVKCode(tTVPMouseButton _mouseBtn) +{ + int btncode; + switch (_mouseBtn) { + case mbLeft: btncode = VK_LBUTTON; break; + case mbMiddle: btncode = VK_MBUTTON; break; + case mbRight: btncode = VK_RBUTTON; break; + default: btncode = 0; break; + } + return btncode; +} + +int TVPConvertKeyCodeToVKCode(cocos2d::EventKeyboard::KeyCode keyCode) +{ +#define CASE(x) case cocos2d::EventKeyboard::KeyCode::KEY_##x: return VK_##x + switch (keyCode) { + CASE(0); + CASE(1); + CASE(2); + CASE(3); + CASE(4); + CASE(5); + CASE(6); + CASE(7); + CASE(8); + CASE(9); + CASE(A); + CASE(B); + CASE(C); + CASE(D); + CASE(E); + CASE(F); + CASE(G); + CASE(H); + CASE(I); + CASE(J); + CASE(K); + CASE(L); + CASE(M); + CASE(N); + CASE(O); + CASE(P); + CASE(Q); + CASE(R); + CASE(S); + CASE(T); + CASE(U); + CASE(V); + CASE(W); + CASE(X); + CASE(Y); + CASE(Z); + CASE(F1); + CASE(F2); + CASE(F3); + CASE(F4); + CASE(F5); + CASE(F6); + CASE(F7); + CASE(F8); + CASE(F9); + CASE(F10); + CASE(F11); + CASE(F12); + CASE(PAUSE); + CASE(PRINT); + CASE(ESCAPE); + case cocos2d::EventKeyboard::KeyCode::KEY_BACK_TAB: + CASE(TAB); + CASE(RETURN); + case cocos2d::EventKeyboard::KeyCode::KEY_SCROLL_LOCK: return VK_SCROLL; + case cocos2d::EventKeyboard::KeyCode::KEY_SYSREQ: return VK_SNAPSHOT; + case cocos2d::EventKeyboard::KeyCode::KEY_BREAK: return VK_CANCEL; + case cocos2d::EventKeyboard::KeyCode::KEY_BACKSPACE: return VK_BACK; + case cocos2d::EventKeyboard::KeyCode::KEY_CAPS_LOCK: return VK_CAPITAL; + case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_SHIFT: return VK_SHIFT; // LR the same + case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: return VK_SHIFT; + case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_CTRL: return VK_CONTROL; // LR the same + case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_CTRL: return VK_CONTROL; + case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ALT: return VK_MENU; + case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ALT: return VK_MENU; + case cocos2d::EventKeyboard::KeyCode::KEY_MENU: return VK_APPS; + case cocos2d::EventKeyboard::KeyCode::KEY_HYPER: return VK_LWIN; + CASE(INSERT); + CASE(HOME); + CASE(DELETE); + CASE(END); + case cocos2d::EventKeyboard::KeyCode::KEY_KP_PG_UP: + case cocos2d::EventKeyboard::KeyCode::KEY_PG_UP: return VK_PRIOR; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_PG_DOWN: + case cocos2d::EventKeyboard::KeyCode::KEY_PG_DOWN: return VK_NEXT; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_LEFT: + case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW: return VK_LEFT; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_RIGHT: + case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ARROW: return VK_RIGHT; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_UP: + case cocos2d::EventKeyboard::KeyCode::KEY_UP_ARROW: return VK_UP; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_DOWN: + case cocos2d::EventKeyboard::KeyCode::KEY_DOWN_ARROW: return VK_DOWN; + case cocos2d::EventKeyboard::KeyCode::KEY_NUM_LOCK: return VK_NUMLOCK; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_PLUS: return VK_ADD; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_MINUS: return VK_SUBTRACT; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_MULTIPLY: return VK_MULTIPLY; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_DIVIDE: return VK_DIVIDE; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_ENTER: return VK_RETURN; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_HOME: return VK_HOME; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_FIVE: return VK_NUMPAD5; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_END: return VK_END; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_INSERT: return VK_INSERT; + case cocos2d::EventKeyboard::KeyCode::KEY_KP_DELETE: return VK_DELETE; + CASE(SPACE); + case cocos2d::EventKeyboard::KeyCode::KEY_EXCLAM: return VK_SPACE; + case cocos2d::EventKeyboard::KeyCode::KEY_QUOTE: return VK_OEM_7; + case cocos2d::EventKeyboard::KeyCode::KEY_COMMA: return VK_OEM_COMMA; + case cocos2d::EventKeyboard::KeyCode::KEY_MINUS: return VK_OEM_MINUS; + case cocos2d::EventKeyboard::KeyCode::KEY_PERIOD: return VK_OEM_PERIOD; + case cocos2d::EventKeyboard::KeyCode::KEY_EQUAL: return VK_OEM_PLUS; + case cocos2d::EventKeyboard::KeyCode::KEY_SLASH: return VK_OEM_2; + case cocos2d::EventKeyboard::KeyCode::KEY_SEMICOLON: return VK_OEM_1; + case cocos2d::EventKeyboard::KeyCode::KEY_BACK_SLASH: return VK_OEM_5; + case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_BRACE: return VK_OEM_4; + case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_BRACE: return VK_OEM_6; + case cocos2d::EventKeyboard::KeyCode::KEY_PLAY: return VK_PLAY; + case cocos2d::EventKeyboard::KeyCode::KEY_NUMBER: + case cocos2d::EventKeyboard::KeyCode::KEY_DOLLAR: + case cocos2d::EventKeyboard::KeyCode::KEY_PERCENT: + case cocos2d::EventKeyboard::KeyCode::KEY_CIRCUMFLEX: + case cocos2d::EventKeyboard::KeyCode::KEY_AMPERSAND: + case cocos2d::EventKeyboard::KeyCode::KEY_APOSTROPHE: + case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_PARENTHESIS: + case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_PARENTHESIS: + case cocos2d::EventKeyboard::KeyCode::KEY_ASTERISK: + case cocos2d::EventKeyboard::KeyCode::KEY_COLON: + case cocos2d::EventKeyboard::KeyCode::KEY_LESS_THAN: + case cocos2d::EventKeyboard::KeyCode::KEY_PLUS: + case cocos2d::EventKeyboard::KeyCode::KEY_GREATER_THAN: + case cocos2d::EventKeyboard::KeyCode::KEY_QUESTION: + case cocos2d::EventKeyboard::KeyCode::KEY_AT: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_A: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_B: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_C: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_D: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_E: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_F: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_G: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_H: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_I: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_J: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_K: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_L: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_M: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_N: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_O: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_P: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_Q: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_R: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_S: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_T: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_U: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_V: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_W: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_X: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_Y: + case cocos2d::EventKeyboard::KeyCode::KEY_CAPITAL_Z: + case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_BRACKET: + case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_BRACKET: + case cocos2d::EventKeyboard::KeyCode::KEY_UNDERSCORE: + case cocos2d::EventKeyboard::KeyCode::KEY_GRAVE: + case cocos2d::EventKeyboard::KeyCode::KEY_BAR: + case cocos2d::EventKeyboard::KeyCode::KEY_TILDE: + case cocos2d::EventKeyboard::KeyCode::KEY_EURO: + case cocos2d::EventKeyboard::KeyCode::KEY_POUND: + case cocos2d::EventKeyboard::KeyCode::KEY_YEN: + case cocos2d::EventKeyboard::KeyCode::KEY_MIDDLE_DOT: + case cocos2d::EventKeyboard::KeyCode::KEY_SEARCH: + case cocos2d::EventKeyboard::KeyCode::KEY_DPAD_LEFT: + case cocos2d::EventKeyboard::KeyCode::KEY_DPAD_RIGHT: + case cocos2d::EventKeyboard::KeyCode::KEY_DPAD_UP: + case cocos2d::EventKeyboard::KeyCode::KEY_DPAD_DOWN: + case cocos2d::EventKeyboard::KeyCode::KEY_DPAD_CENTER: + case cocos2d::EventKeyboard::KeyCode::KEY_ENTER: + default: return 0; + } +#undef CASE +} + +int TVPConvertPadKeyCodeToVKCode(int keyCode) +{ + switch (keyCode) { + case cocos2d::Controller::BUTTON_A: return VK_PAD1; + case cocos2d::Controller::BUTTON_B: return VK_PAD2; + case cocos2d::Controller::BUTTON_C: return VK_PAD3; + case cocos2d::Controller::BUTTON_X: return VK_PAD4; + case cocos2d::Controller::BUTTON_Y: return VK_PAD5; + case cocos2d::Controller::BUTTON_Z: return VK_PAD6; + case cocos2d::Controller::BUTTON_LEFT_SHOULDER: return VK_PAD7; + case cocos2d::Controller::BUTTON_RIGHT_SHOULDER: return VK_PAD8; + case cocos2d::Controller::BUTTON_LEFT_THUMBSTICK: return VK_PAD9; + case cocos2d::Controller::BUTTON_RIGHT_THUMBSTICK: return VK_PAD10; + case cocos2d::Controller::BUTTON_START: return VK_PAD9; + case cocos2d::Controller::BUTTON_SELECT: return VK_PAD10; + case cocos2d::Controller::AXIS_LEFT_TRIGGER: return VK_PAD5; + case cocos2d::Controller::AXIS_RIGHT_TRIGGER: return VK_PAD6; + case cocos2d::Controller::BUTTON_PAUSE: return VK_PAD7; + case cocos2d::Controller::BUTTON_DPAD_UP: return VK_PADUP; + case cocos2d::Controller::BUTTON_DPAD_DOWN: return VK_PADDOWN; + case cocos2d::Controller::BUTTON_DPAD_LEFT: return VK_PADLEFT; + case cocos2d::Controller::BUTTON_DPAD_RIGHT: return VK_PADRIGHT; + case cocos2d::Controller::BUTTON_DPAD_CENTER: + default: return 0; + } +} + + +const std::unordered_map & TVPGetVKCodeNameMap() +{ + static std::unordered_map ret({ +#define CASE(x) { #x, VK_##x } + CASE(0), + CASE(1), + CASE(2), + CASE(3), + CASE(4), + CASE(5), + CASE(6), + CASE(7), + CASE(8), + CASE(9), + CASE(A), + CASE(B), + CASE(C), + CASE(D), + CASE(E), + CASE(F), + CASE(G), + CASE(H), + CASE(I), + CASE(J), + CASE(K), + CASE(L), + CASE(M), + CASE(N), + CASE(O), + CASE(P), + CASE(Q), + CASE(R), + CASE(S), + CASE(T), + CASE(U), + CASE(V), + CASE(W), + CASE(X), + CASE(Y), + CASE(Z), + CASE(F1), + CASE(F2), + CASE(F3), + CASE(F4), + CASE(F5), + CASE(F6), + CASE(F7), + CASE(F8), + CASE(F9), + CASE(F10), + CASE(F11), + CASE(F12), + CASE(PAUSE), + CASE(PRINT), + CASE(ESCAPE), + CASE(TAB), + CASE(RETURN), + CASE(SCROLL), + CASE(SNAPSHOT), + CASE(CANCEL), + CASE(BACK), + CASE(CAPITAL), + CASE(SHIFT), + CASE(CONTROL), + CASE(MENU), + CASE(APPS), + CASE(LWIN), + CASE(INSERT), + CASE(HOME), + CASE(DELETE), + CASE(END), + CASE(PRIOR), + CASE(NEXT), + CASE(LEFT), + CASE(RIGHT), + CASE(UP), + CASE(DOWN), + CASE(NUMLOCK), + CASE(ADD), + CASE(SUBTRACT), + CASE(MULTIPLY), + CASE(DIVIDE), + CASE(HOME), + CASE(NUMPAD5), + CASE(END), + CASE(INSERT), + CASE(DELETE), + CASE(SPACE), + CASE(OEM_COMMA), + CASE(OEM_MINUS), + CASE(OEM_PERIOD), + CASE(OEM_PLUS), + CASE(OEM_1), + CASE(OEM_2), + CASE(OEM_4), + CASE(OEM_5), + CASE(OEM_6), + CASE(OEM_7), + CASE(PLAY), +#undef CASE + }); + return ret; +} + +std::string TVPGetVKCodeName(int keyCode) +{ + return ""; +} diff --git a/src/core/environ/cocos2d/CCKeyCodeConv.h b/src/core/environ/cocos2d/CCKeyCodeConv.h index 504ef30c..b8c5570b 100644 --- a/src/core/environ/cocos2d/CCKeyCodeConv.h +++ b/src/core/environ/cocos2d/CCKeyCodeConv.h @@ -1,209 +1,9 @@ -static int _ConvertMouseBtnToVKCode(tTVPMouseButton _mouseBtn) { - int btncode; - switch (_mouseBtn) { - case mbLeft: btncode = VK_LBUTTON; break; - case mbMiddle: btncode = VK_MBUTTON; break; - case mbRight: btncode = VK_RBUTTON; break; - default: btncode = 0; break; - } - return btncode; -} +#include "tjsTypes.h" +#include "tvpinputdefs.h" +#include "cocos2d.h" -static int _ConvertKeyCodeToVKCode(EventKeyboard::KeyCode keyCode) { -#define CASE(x) case EventKeyboard::KeyCode::KEY_##x: return VK_##x - switch (keyCode) { - CASE(0); - CASE(1); - CASE(2); - CASE(3); - CASE(4); - CASE(5); - CASE(6); - CASE(7); - CASE(8); - CASE(9); - CASE(A); - CASE(B); - CASE(C); - CASE(D); - CASE(E); - CASE(F); - CASE(G); - CASE(H); - CASE(I); - CASE(J); - CASE(K); - CASE(L); - CASE(M); - CASE(N); - CASE(O); - CASE(P); - CASE(Q); - CASE(R); - CASE(S); - CASE(T); - CASE(U); - CASE(V); - CASE(W); - CASE(X); - CASE(Y); - CASE(Z); - CASE(F1); - CASE(F2); - CASE(F3); - CASE(F4); - CASE(F5); - CASE(F6); - CASE(F7); - CASE(F8); - CASE(F9); - CASE(F10); - CASE(F11); - CASE(F12); - CASE(PAUSE); - CASE(PRINT); - CASE(ESCAPE); - case EventKeyboard::KeyCode::KEY_BACK_TAB: - CASE(TAB); - CASE(RETURN); - case EventKeyboard::KeyCode::KEY_SCROLL_LOCK: return VK_SCROLL; - case EventKeyboard::KeyCode::KEY_SYSREQ: return VK_SNAPSHOT; - case EventKeyboard::KeyCode::KEY_BREAK: return VK_CANCEL; - case EventKeyboard::KeyCode::KEY_BACKSPACE: return VK_BACK; - case EventKeyboard::KeyCode::KEY_CAPS_LOCK: return VK_CAPITAL; - case EventKeyboard::KeyCode::KEY_LEFT_SHIFT: return VK_SHIFT; // LR the same - case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: return VK_SHIFT; - case EventKeyboard::KeyCode::KEY_LEFT_CTRL: return VK_CONTROL; // LR the same - case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: return VK_CONTROL; - case EventKeyboard::KeyCode::KEY_LEFT_ALT: return VK_MENU; - case EventKeyboard::KeyCode::KEY_RIGHT_ALT: return VK_MENU; - case EventKeyboard::KeyCode::KEY_MENU: return VK_APPS; - case EventKeyboard::KeyCode::KEY_HYPER: return VK_LWIN; - CASE(INSERT); - CASE(HOME); - CASE(DELETE); - CASE(END); - case EventKeyboard::KeyCode::KEY_KP_PG_UP: - case EventKeyboard::KeyCode::KEY_PG_UP: return VK_PRIOR; - case EventKeyboard::KeyCode::KEY_KP_PG_DOWN: - case EventKeyboard::KeyCode::KEY_PG_DOWN: return VK_NEXT; - case EventKeyboard::KeyCode::KEY_KP_LEFT: - case EventKeyboard::KeyCode::KEY_LEFT_ARROW: return VK_LEFT; - case EventKeyboard::KeyCode::KEY_KP_RIGHT: - case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: return VK_RIGHT; - case EventKeyboard::KeyCode::KEY_KP_UP: - case EventKeyboard::KeyCode::KEY_UP_ARROW: return VK_UP; - case EventKeyboard::KeyCode::KEY_KP_DOWN: - case EventKeyboard::KeyCode::KEY_DOWN_ARROW: return VK_DOWN; - case EventKeyboard::KeyCode::KEY_NUM_LOCK: return VK_NUMLOCK; - case EventKeyboard::KeyCode::KEY_KP_PLUS: return VK_ADD; - case EventKeyboard::KeyCode::KEY_KP_MINUS: return VK_SUBTRACT; - case EventKeyboard::KeyCode::KEY_KP_MULTIPLY: return VK_MULTIPLY; - case EventKeyboard::KeyCode::KEY_KP_DIVIDE: return VK_DIVIDE; - case EventKeyboard::KeyCode::KEY_KP_ENTER: return VK_RETURN; - case EventKeyboard::KeyCode::KEY_KP_HOME: return VK_HOME; - case EventKeyboard::KeyCode::KEY_KP_FIVE: return VK_NUMPAD5; - case EventKeyboard::KeyCode::KEY_KP_END: return VK_END; - case EventKeyboard::KeyCode::KEY_KP_INSERT: return VK_INSERT; - case EventKeyboard::KeyCode::KEY_KP_DELETE: return VK_DELETE; - CASE(SPACE); - case EventKeyboard::KeyCode::KEY_EXCLAM: return VK_SPACE; - case EventKeyboard::KeyCode::KEY_QUOTE: return VK_OEM_7; - case EventKeyboard::KeyCode::KEY_COMMA: return VK_OEM_COMMA; - case EventKeyboard::KeyCode::KEY_MINUS: return VK_OEM_MINUS; - case EventKeyboard::KeyCode::KEY_PERIOD: return VK_OEM_PERIOD; - case EventKeyboard::KeyCode::KEY_EQUAL: return VK_OEM_PLUS; - case EventKeyboard::KeyCode::KEY_SLASH: return VK_OEM_2; - case EventKeyboard::KeyCode::KEY_SEMICOLON: return VK_OEM_1; - case EventKeyboard::KeyCode::KEY_BACK_SLASH: return VK_OEM_5; - case EventKeyboard::KeyCode::KEY_LEFT_BRACE: return VK_OEM_4; - case EventKeyboard::KeyCode::KEY_RIGHT_BRACE: return VK_OEM_6; - case EventKeyboard::KeyCode::KEY_PLAY: return VK_PLAY; - case EventKeyboard::KeyCode::KEY_NUMBER: - case EventKeyboard::KeyCode::KEY_DOLLAR: - case EventKeyboard::KeyCode::KEY_PERCENT: - case EventKeyboard::KeyCode::KEY_CIRCUMFLEX: - case EventKeyboard::KeyCode::KEY_AMPERSAND: - case EventKeyboard::KeyCode::KEY_APOSTROPHE: - case EventKeyboard::KeyCode::KEY_LEFT_PARENTHESIS: - case EventKeyboard::KeyCode::KEY_RIGHT_PARENTHESIS: - case EventKeyboard::KeyCode::KEY_ASTERISK: - case EventKeyboard::KeyCode::KEY_COLON: - case EventKeyboard::KeyCode::KEY_LESS_THAN: - case EventKeyboard::KeyCode::KEY_PLUS: - case EventKeyboard::KeyCode::KEY_GREATER_THAN: - case EventKeyboard::KeyCode::KEY_QUESTION: - case EventKeyboard::KeyCode::KEY_AT: - case EventKeyboard::KeyCode::KEY_CAPITAL_A: - case EventKeyboard::KeyCode::KEY_CAPITAL_B: - case EventKeyboard::KeyCode::KEY_CAPITAL_C: - case EventKeyboard::KeyCode::KEY_CAPITAL_D: - case EventKeyboard::KeyCode::KEY_CAPITAL_E: - case EventKeyboard::KeyCode::KEY_CAPITAL_F: - case EventKeyboard::KeyCode::KEY_CAPITAL_G: - case EventKeyboard::KeyCode::KEY_CAPITAL_H: - case EventKeyboard::KeyCode::KEY_CAPITAL_I: - case EventKeyboard::KeyCode::KEY_CAPITAL_J: - case EventKeyboard::KeyCode::KEY_CAPITAL_K: - case EventKeyboard::KeyCode::KEY_CAPITAL_L: - case EventKeyboard::KeyCode::KEY_CAPITAL_M: - case EventKeyboard::KeyCode::KEY_CAPITAL_N: - case EventKeyboard::KeyCode::KEY_CAPITAL_O: - case EventKeyboard::KeyCode::KEY_CAPITAL_P: - case EventKeyboard::KeyCode::KEY_CAPITAL_Q: - case EventKeyboard::KeyCode::KEY_CAPITAL_R: - case EventKeyboard::KeyCode::KEY_CAPITAL_S: - case EventKeyboard::KeyCode::KEY_CAPITAL_T: - case EventKeyboard::KeyCode::KEY_CAPITAL_U: - case EventKeyboard::KeyCode::KEY_CAPITAL_V: - case EventKeyboard::KeyCode::KEY_CAPITAL_W: - case EventKeyboard::KeyCode::KEY_CAPITAL_X: - case EventKeyboard::KeyCode::KEY_CAPITAL_Y: - case EventKeyboard::KeyCode::KEY_CAPITAL_Z: - case EventKeyboard::KeyCode::KEY_LEFT_BRACKET: - case EventKeyboard::KeyCode::KEY_RIGHT_BRACKET: - case EventKeyboard::KeyCode::KEY_UNDERSCORE: - case EventKeyboard::KeyCode::KEY_GRAVE: - case EventKeyboard::KeyCode::KEY_BAR: - case EventKeyboard::KeyCode::KEY_TILDE: - case EventKeyboard::KeyCode::KEY_EURO: - case EventKeyboard::KeyCode::KEY_POUND: - case EventKeyboard::KeyCode::KEY_YEN: - case EventKeyboard::KeyCode::KEY_MIDDLE_DOT: - case EventKeyboard::KeyCode::KEY_SEARCH: - case EventKeyboard::KeyCode::KEY_DPAD_LEFT: - case EventKeyboard::KeyCode::KEY_DPAD_RIGHT: - case EventKeyboard::KeyCode::KEY_DPAD_UP: - case EventKeyboard::KeyCode::KEY_DPAD_DOWN: - case EventKeyboard::KeyCode::KEY_DPAD_CENTER: - case EventKeyboard::KeyCode::KEY_ENTER: - default: return 0; - } -#undef CASE -} - -static int _ConvertPadKeyCodeToVKCode(int keyCode) { - switch (keyCode) { - case Controller::BUTTON_A: return VK_PAD1; - case Controller::BUTTON_B: return VK_PAD2; - case Controller::BUTTON_C: return VK_PAD3; - case Controller::BUTTON_X: return VK_PAD4; - case Controller::BUTTON_Y: return VK_PAD5; - case Controller::BUTTON_Z: return VK_PAD6; - case Controller::BUTTON_LEFT_SHOULDER: return VK_PAD7; - case Controller::BUTTON_RIGHT_SHOULDER: return VK_PAD8; - case Controller::BUTTON_LEFT_THUMBSTICK: return VK_PAD9; - case Controller::BUTTON_RIGHT_THUMBSTICK: return VK_PAD10; - case Controller::BUTTON_START: return VK_PAD9; - case Controller::BUTTON_SELECT: return VK_PAD10; - case Controller::AXIS_LEFT_TRIGGER: return VK_PAD5; - case Controller::AXIS_RIGHT_TRIGGER: return VK_PAD6; - case Controller::BUTTON_PAUSE: return VK_PAD7; - case Controller::BUTTON_DPAD_UP: return VK_PADUP; - case Controller::BUTTON_DPAD_DOWN: return VK_PADDOWN; - case Controller::BUTTON_DPAD_LEFT: return VK_PADLEFT; - case Controller::BUTTON_DPAD_RIGHT: return VK_PADRIGHT; - case Controller::BUTTON_DPAD_CENTER: - default: return 0; - } -} +int TVPConvertMouseBtnToVKCode(tTVPMouseButton _mouseBtn); +int TVPConvertKeyCodeToVKCode(cocos2d::EventKeyboard::KeyCode keyCode); +int TVPConvertPadKeyCodeToVKCode(int keyCode); +const std::unordered_map &TVPGetVKCodeNameMap(); +std::string TVPGetVKCodeName(int keyCode); \ No newline at end of file diff --git a/src/core/environ/cocos2d/CustomFileUtils.cpp b/src/core/environ/cocos2d/CustomFileUtils.cpp index 22cfca6c..2f1c8451 100644 --- a/src/core/environ/cocos2d/CustomFileUtils.cpp +++ b/src/core/environ/cocos2d/CustomFileUtils.cpp @@ -1,7 +1,54 @@ #include "CustomFileUtils.h" +#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 +#include "platform/win32/CCFileUtils-win32.h" +#elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS +#import +#import "platform/apple/CCFileUtils-apple.h" +#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID +#include "platform/android/CCFileUtils-android.h" +#endif +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources +#include "external/unzip/unzip.h" +#endif +#include "ConfigManager/LocaleConfigManager.h" NS_CC_BEGIN +typedef +#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 +FileUtilsWin32 +#elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS +FileUtilsApple +#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID +FileUtilsAndroid +#endif +FileUtilsInherit; + +class CustomFileUtils : public FileUtilsInherit +{ +public: + CustomFileUtils(); + + void addAutoSearchArchive(const std::string& path); + virtual std::string fullPathForFilename(const std::string &filename) const override; + virtual std::string getStringFromFile(const std::string& filename) override; + virtual Data getDataFromFile(const std::string& filename) override; + virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t *size) override; + virtual bool isFileExistInternal(const std::string& strFilePath) const override; + virtual bool isDirectoryExistInternal(const std::string& dirPath) const override; + virtual bool init() override { + return FileUtilsInherit::init(); + } + +private: + unsigned char* getFileDataFromArchive(const std::string& filename, ssize_t *size); + + std::unordered_map > _autoSearchArchive; + std::mutex _lock; +}; + CustomFileUtils::CustomFileUtils() { } @@ -101,14 +148,25 @@ std::string CustomFileUtils::getStringFromFile(const std::string& filename) NS_CC_END -cocos2d::CustomFileUtils *TVPCreateCustomFileUtils() { +cocos2d::FileUtils *TVPCreateCustomFileUtils() { cocos2d::CustomFileUtils *ret = new cocos2d::CustomFileUtils; ret->init(); return ret; } +void TVPAddAutoSearchArchive(const std::string &path) +{ + cocos2d::CustomFileUtils *fileutils =static_cast(cocos2d::FileUtils::getInstance()); + fileutils->addAutoSearchArchive(path); +} + #include "StorageImpl.h" #include "Platform.h" +#include "ConfigManager/GlobalConfigManager.h" +#include "tinyxml2/tinyxml2.h" + +USING_NS_CC; + static bool TVPCopyFolder(const std::string &from, const std::string &to) { if (!TVPCheckExistentLocalFolder(to) && !TVPCreateFolders(to)) { return false; @@ -149,3 +207,95 @@ bool TVPCopyFile(const std::string &from, const std::string &to) fclose(fto); return true; } + +TVPSkinManager* TVPSkinManager::getInstance() +{ + static TVPSkinManager instance; + return &instance; +} + +void TVPSkinManager::InitSkin() +{ + std::string skinpath = GlobalConfigManager::GetInstance()->GetValue("skin_path", ""); + if (!skinpath.empty()) { + if (!Check(skinpath)) { + TVPShowSimpleMessageBox( + LocaleConfigManager::GetInstance()->GetText("invalid_skin_desc"), + LocaleConfigManager::GetInstance()->GetText("invalid_skin")); + Reset(); + } else { + static_cast(FileUtils::getInstance())->addAutoSearchArchive(skinpath); + } + } +} + +static const char *_adapted_skin_version = "1.3.4"; + +bool TVPSkinManager::Check(const std::string &path) +{ + if (!cocos2d::FileUtils::getInstance()->isFileExist(path)) { + return false; + } + + tinyxml2::XMLDocument doc; + + unzFile file = nullptr; + file = unzOpen(FileUtils::getInstance()->getSuitableFOpen(path).c_str()); + unz_file_info file_info; + do { + unz_file_pos entry; + if (unzGetFilePos(file, &entry) == UNZ_OK) { + char filename_inzip[1024]; + if (unzGetCurrentFileInfo(file, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0) == UNZ_OK) { + if (strcmp(filename_inzip, "meta.xml")) { + if (unzGoToFilePos(&file, &entry) != UNZ_OK) + break; + unsigned char *buffer = (unsigned char*)malloc(file_info.uncompressed_size); + int readedSize = unzReadCurrentFile(&file, buffer, static_cast(file_info.uncompressed_size)); + if (readedSize != (int)file_info.uncompressed_size) { + free(buffer); + break; + } + doc.Parse((char*)buffer); + free(buffer); + break; + } + } + } + } while (unzGoToNextFile(file) == UNZ_OK); + unzClose(file); + + tinyxml2::XMLElement* root = doc.RootElement(); + if (!root) + return false; + + const char *s = root->Attribute("version"); + if (!s) + return false; + + return !strcmp(s, _adapted_skin_version); +} + +void TVPSkinManager::Reset() +{ + GlobalConfigManager::GetInstance()->SetValue("skin_path", ""); + GlobalConfigManager::GetInstance()->SaveToFile(); +} + +bool TVPSkinManager::Use(const std::string &skin_path) +{ + GlobalConfigManager::GetInstance()->SetValue("skin_path", skin_path); + GlobalConfigManager::GetInstance()->SaveToFile(); + return true; +} + +bool TVPSkinManager::InstallAndUse(const std::string &skin_path) +{ + std::string path = FileUtils::getInstance()->getWritablePath() + "default.skin"; + FileUtils::getInstance()->removeFile(path); + if (!TVPCopyFile(skin_path, path)) { + return false; + } + GlobalConfigManager::GetInstance()->SetValue("skin_path", path); + return true; +} diff --git a/src/core/environ/cocos2d/CustomFileUtils.h b/src/core/environ/cocos2d/CustomFileUtils.h index f1046ca4..7bb805c9 100644 --- a/src/core/environ/cocos2d/CustomFileUtils.h +++ b/src/core/environ/cocos2d/CustomFileUtils.h @@ -1,52 +1,14 @@ #pragma once #include "cocos2d.h" -#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 -#include "platform/win32/CCFileUtils-win32.h" -#elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS -#import -#import "platform/apple/CCFileUtils-apple.h" -#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID -#include "platform/android/CCFileUtils-android.h" -#endif -#ifdef MINIZIP_FROM_SYSTEM -#include -#else // from our embedded sources -#include "external/unzip/unzip.h" -#endif -NS_CC_BEGIN - -typedef -#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 -FileUtilsWin32 -#elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS -FileUtilsApple -#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID -FileUtilsAndroid -#endif -FileUtilsInherit; - -class CustomFileUtils : public FileUtilsInherit -{ +void TVPAddAutoSearchArchive(const std::string &path); +class TVPSkinManager { public: - CustomFileUtils(); - - void addAutoSearchArchive(const std::string& path); - virtual std::string fullPathForFilename(const std::string &filename) const override; - virtual std::string getStringFromFile(const std::string& filename) override; - virtual Data getDataFromFile(const std::string& filename) override; - virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t *size) override; - virtual bool isFileExistInternal(const std::string& strFilePath) const override; - virtual bool isDirectoryExistInternal(const std::string& dirPath) const override; - virtual bool init() override { - return FileUtilsInherit::init(); - } + static TVPSkinManager* getInstance(); -private: - unsigned char* getFileDataFromArchive(const std::string& filename, ssize_t *size); - - std::unordered_map > _autoSearchArchive; - std::mutex _lock; + void InitSkin(); + static bool Check(const std::string &skin_path); + static void Reset(); + static bool Use(const std::string &skin_path); + static bool InstallAndUse(const std::string &skin_path); }; - -NS_CC_END \ No newline at end of file diff --git a/src/core/environ/cocos2d/MainScene.cpp b/src/core/environ/cocos2d/MainScene.cpp index 805415de..a2417a9c 100644 --- a/src/core/environ/cocos2d/MainScene.cpp +++ b/src/core/environ/cocos2d/MainScene.cpp @@ -58,6 +58,7 @@ static int _touchBeginTick; static bool _virutalMouseMode = false; static bool _mouseMoved, _mouseClickedDown; static tjs_uint8 _scancode[0x200]; +static tjs_uint16 _keymap[0x200]; static Label *_fpsLabel = nullptr; #include "CCKeyCodeConv.h" @@ -72,7 +73,7 @@ void TVPSetPostUpdateEvent(void(*f)()) { _postUpdate = f; } static void _refadeMouseCursor() { _mouseCursor->stopAllActions(); _mouseCursor->setOpacity(255); - _mouseCursor->runAction(Sequence::createWithTwoActions(DelayTime::create(3), FadeOut::create(0.3))); + _mouseCursor->runAction(Sequence::createWithTwoActions(DelayTime::create(3), FadeOut::create(0.3f))); } static void AdjustNumerAndDenom(tjs_int &n, tjs_int &d) @@ -222,7 +223,7 @@ Sprite *TVPLoadCursorCUR(tTJSBinaryStream *pStream) { tjs_uint32 palette[256]; if (bmhdr.biBitCount <= 8) { if (bmhdr.biClrUsed == 0) bmhdr.biClrUsed = 1 << bmhdr.biBitCount; - for (int j = 0; j < bmhdr.biClrUsed; ++j) { + for (unsigned int j = 0; j < bmhdr.biClrUsed; ++j) { union { tjs_uint32 u32; tjs_uint8 u8[4]; @@ -296,7 +297,7 @@ Sprite *TVPLoadCursorCUR(tTJSBinaryStream *pStream) { } } cocos2d::Image *surface = new cocos2d::Image; - surface->initWithRawData(&pixbuf[0], pixbuf.size(), bmhdr.biWidth, bmhdr.biHeight, 32, false); + surface->initWithRawData(&pixbuf[0], pixbuf.size(), bmhdr.biWidth, bmhdr.biHeight, Texture2D::PixelFormat::RGBA8888, false); Texture2D *tex = new Texture2D(); tex->initWithImage(surface); Sprite *sprite = Sprite::create(); @@ -471,13 +472,12 @@ class TVPWindowLayer : public cocos2d::extension::ScrollView, public iWindowLaye void onMouseDownEvent(Event *_e) { EventMouse *e = static_cast(_e); - int btn = e->getMouseButton(); - switch (btn) { - case 1: + switch (e->getMouseButton()) { + case EventMouse::MouseButton::BUTTON_RIGHT: _mouseBtn = mbRight; onMouseDown(e->getLocation()); break; - case 2: + case EventMouse::MouseButton::BUTTON_MIDDLE: _mouseBtn = mbMiddle; onMouseDown(e->getLocation()); break; @@ -488,13 +488,12 @@ class TVPWindowLayer : public cocos2d::extension::ScrollView, public iWindowLaye void onMouseUpEvent(Event *_e) { EventMouse *e = static_cast(_e); - int btn = e->getMouseButton(); - switch (btn) { - case 1: + switch (e->getMouseButton()) { + case EventMouse::MouseButton::BUTTON_RIGHT: _mouseBtn = mbRight; onMouseUp(e->getLocation()); break; - case 2: + case EventMouse::MouseButton::BUTTON_MIDDLE: _mouseBtn = mbMiddle; onMouseUp(e->getLocation()); break; @@ -566,7 +565,7 @@ class TVPWindowLayer : public cocos2d::extension::ScrollView, public iWindowLaye Vec2 nsp = PrimaryLayerArea->convertToNodeSpace(_touchPoint); _LastMouseX = nsp.x, _LastMouseY = PrimaryLayerArea->getContentSize().height - nsp.y; TVPPostInputEvent(new tTVPOnMouseMoveInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY, TVPGetCurrentShiftKeyState())); - _scancode[_ConvertMouseBtnToVKCode(_mouseBtn)] = 0x11; + _scancode[TVPConvertMouseBtnToVKCode(_mouseBtn)] = 0x11; TVPPostInputEvent(new tTVPOnMouseDownInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY, _mouseBtn, TVPGetCurrentShiftKeyState())); _touchMoved = true; } else if (_touchMoved) { @@ -598,7 +597,7 @@ class TVPWindowLayer : public cocos2d::extension::ScrollView, public iWindowLaye PrimaryLayerArea->getContentSize().height - nsp.y, _mouseBtn, TVPGetCurrentShiftKeyState())); TVPPostInputEvent(new tTVPOnClickInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY)); } - _scancode[_ConvertMouseBtnToVKCode(_mouseBtn)] = 0x10; + _scancode[TVPConvertMouseBtnToVKCode(_mouseBtn)] = 0x10; TVPPostInputEvent(new tTVPOnMouseUpInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY, _mouseBtn, TVPGetCurrentShiftKeyState())); } } @@ -609,7 +608,7 @@ class TVPWindowLayer : public cocos2d::extension::ScrollView, public iWindowLaye { _dragging = false; _touchMoved = false; - _scancode[_ConvertMouseBtnToVKCode(_mouseBtn)] &= 0x10; + _scancode[TVPConvertMouseBtnToVKCode(_mouseBtn)] &= 0x10; } } @@ -637,14 +636,14 @@ class TVPWindowLayer : public cocos2d::extension::ScrollView, public iWindowLaye void onMouseDown(const Vec2 &pt) { Vec2 nsp = PrimaryLayerArea->convertToNodeSpace(pt); _LastMouseX = nsp.x, _LastMouseY = PrimaryLayerArea->getContentSize().height - nsp.y; - _scancode[_ConvertMouseBtnToVKCode(_mouseBtn)] = 0x11; + _scancode[TVPConvertMouseBtnToVKCode(_mouseBtn)] = 0x11; TVPPostInputEvent(new tTVPOnMouseDownInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY, _mouseBtn, TVPGetCurrentShiftKeyState())); } void onMouseUp(const Vec2 &pt) { Vec2 nsp = PrimaryLayerArea->convertToNodeSpace(pt); _LastMouseX = nsp.x, _LastMouseY = PrimaryLayerArea->getContentSize().height - nsp.y; - _scancode[_ConvertMouseBtnToVKCode(_mouseBtn)] &= 0x10; + _scancode[TVPConvertMouseBtnToVKCode(_mouseBtn)] &= 0x10; TVPPostInputEvent(new tTVPOnMouseUpInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY, _mouseBtn, TVPGetCurrentShiftKeyState())); } @@ -660,7 +659,7 @@ class TVPWindowLayer : public cocos2d::extension::ScrollView, public iWindowLaye Vec2 nsp = PrimaryLayerArea->convertToNodeSpace(pt); _LastMouseX = nsp.x, _LastMouseY = PrimaryLayerArea->getContentSize().height - nsp.y; TVPPostInputEvent(new tTVPOnMouseMoveInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY, TVPGetCurrentShiftKeyState()), TVP_EPT_DISCARDABLE); - _scancode[_ConvertMouseBtnToVKCode(_mouseBtn)] = 0x10; + _scancode[TVPConvertMouseBtnToVKCode(_mouseBtn)] = 0x10; TVPPostInputEvent(new tTVPOnMouseDownInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY, _mouseBtn, TVPGetCurrentShiftKeyState())); TVPPostInputEvent(new tTVPOnClickInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY)); TVPPostInputEvent(new tTVPOnMouseUpInputEvent(TJSNativeInstance, _LastMouseX, _LastMouseY, _mouseBtn, TVPGetCurrentShiftKeyState())); @@ -1616,6 +1615,7 @@ void TVPMainScene::initialize() { ctrllistener->onKeyUp = CC_CALLBACK_3(TVPMainScene::onPadKeyUp, this); ctrllistener->onKeyRepeat = CC_CALLBACK_3(TVPMainScene::onPadKeyRepeat, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(ctrllistener, this); + cocos2d::Controller::startDiscoveryController(); // for win32 & iOS } TVPMainScene * TVPMainScene::create() { @@ -1724,6 +1724,16 @@ bool TVPMainScene::startupFrom(const std::string &path) { if (GlobalConfigManager::GetInstance()->GetValue("keep_screen_alive", true)) { Device::setKeepScreenOn(true); } + + for (int i = 0; i < sizeof(_keymap) / sizeof(_keymap[0]); ++i) { + _keymap[i] = i; + } + + const auto& keymap = pGlobalCfgMgr->GetKeyMap(); + for (const auto &it : keymap) { + if (!it.second) continue; + _keymap[it.first] = _keymap[it.second]; + } // if (pGlobalCfgMgr->GetValueBool("rot_screen_180", false)) { // GameNode->setRotation(90); // } @@ -1776,6 +1786,8 @@ void TVPMainScene::doStartup(float dt, std::string path) { _fpsLabel->enableOutline(Color4B::BLACK, 1); GameNode->addChild(_fpsLabel, GAME_MENU_ORDER); } + int fps = pGlobalCfgMgr->GetValue("fps_limit", 60); + cocos2d::Director::getInstance()->setAnimationInterval(1.0f / fps); } extern ttstr TVPGetErrorDialogTitle(); @@ -1927,8 +1939,10 @@ void TVPMainScene::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event) { default: break; } - int code = _ConvertKeyCodeToVKCode(keyCode); - if (!code) return; + unsigned int code = TVPConvertKeyCodeToVKCode(keyCode); + if (!code || code >= 0x200) return; + code = _keymap[code]; + _scancode[code] = 0x11; if (_currentWindowLayer) { _currentWindowLayer->InternalKeyDown(code, TVPGetCurrentShiftKeyState()); @@ -1970,8 +1984,9 @@ void TVPMainScene::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event) { } global->Release(); } - int code = _ConvertKeyCodeToVKCode(keyCode); - if (!code) return; + unsigned int code = TVPConvertKeyCodeToVKCode(keyCode); + if (!code || code >= 0x200) return; + code = _keymap[code]; bool isPressed = _scancode[code] & 1; _scancode[code] &= 0x10; if (isPressed && _currentWindowLayer) { @@ -2232,13 +2247,45 @@ void TVPMainScene::onTextInput(const std::string &text) { } void TVPMainScene::onAxisEvent(cocos2d::Controller* ctrl, int keyCode, cocos2d::Event *e) { - + if (!_currentWindowLayer || !_currentWindowLayer->PrimaryLayerArea) return; + if (!_virutalMouseMode || _windowMgrOverlay) return; + const float threashold = 0.1f; + const cocos2d::Controller::KeyStatus& keyStatus = ctrl->getKeyStatus(keyCode); +// CCLOG("Axis KeyCode:%d Axis Value:%f", keyCode, keyStatus.value); + if (std::abs(keyStatus.value) < threashold) { + return; + } + float offv = keyStatus.value; + if (offv > 0) offv = (offv - threashold) / (1 - threashold); + else offv = (offv + threashold) / (1 - threashold); + Vec2 pt = Vec2(_currentWindowLayer->_LastMouseX, _currentWindowLayer->_LastMouseY); + float *pValue = nullptr; + switch (keyCode) { + case cocos2d::Controller::JOYSTICK_LEFT_X: + pValue = &pt.x; break; + case cocos2d::Controller::JOYSTICK_LEFT_Y: + pValue = &pt.y; break; + default: + return; + } + *pValue += offv * 16; + pt = _currentWindowLayer->PrimaryLayerArea->convertToWorldSpace(pt); + pt = GameNode->convertToNodeSpace(pt); + Vec2 newpt = pt; + Size size = GameNode->getContentSize(); + if (pt.x < 0) newpt.x = 0; + else if (pt.x > size.width) newpt.x = size.width; + if (pt.y < 0) newpt.y = 0; + else if (pt.y > size.height) newpt.y = size.height; + _mouseCursor->setPosition(newpt); + _currentWindowLayer->onMouseMove(GameNode->convertToWorldSpace(newpt)); } void TVPMainScene::onPadKeyDown(cocos2d::Controller* ctrl, int keyCode, cocos2d::Event *e) { if (!UINode->getChildren().empty()) return; - int code = _ConvertPadKeyCodeToVKCode(keyCode); - if (!code) return; + unsigned int code = TVPConvertPadKeyCodeToVKCode(keyCode); + if (!code || code >= 0x200) return; + code = _keymap[code]; _scancode[code] = 0x11; if (_currentWindowLayer) { _currentWindowLayer->InternalKeyDown(code, TVPGetCurrentShiftKeyState()); @@ -2246,8 +2293,9 @@ void TVPMainScene::onPadKeyDown(cocos2d::Controller* ctrl, int keyCode, cocos2d: } void TVPMainScene::onPadKeyUp(cocos2d::Controller* ctrl, int keyCode, cocos2d::Event *e) { - int code = _ConvertPadKeyCodeToVKCode(keyCode); - if (!code) return; + unsigned int code = TVPConvertPadKeyCodeToVKCode(keyCode); + if (!code || code >= 0x200) return; + code = _keymap[code]; bool isPressed = _scancode[code] & 1; _scancode[code] &= 0x10; if (isPressed && _currentWindowLayer) { diff --git a/src/core/environ/ui/GlobalPreferenceForm.cpp b/src/core/environ/ui/GlobalPreferenceForm.cpp index 55863b07..75d24a69 100644 --- a/src/core/environ/ui/GlobalPreferenceForm.cpp +++ b/src/core/environ/ui/GlobalPreferenceForm.cpp @@ -13,23 +13,9 @@ using namespace cocos2d::ui; const char * const FileName_NaviBar = "ui/NaviBar.csb"; const char * const FileName_Body = "ui/ListView.csb"; -static bool PreferenceGetValueBool(const std::string &name, bool defval) { - return GlobalConfigManager::GetInstance()->GetValue(name, defval); -} -static void PreferenceSetValueBool(const std::string &name, bool v) { - GlobalConfigManager::GetInstance()->SetValueInt(name, v); -} -static std::string PreferenceGetValueString(const std::string &name, const std::string& defval) { - return GlobalConfigManager::GetInstance()->GetValue(name, defval); -} -static void PreferenceSetValueString(const std::string &name, const std::string& v) { - GlobalConfigManager::GetInstance()->SetValue(name, v); -} -static float PreferenceGetValueFloat(const std::string &name, float defval) { - return GlobalConfigManager::GetInstance()->GetValue(name, defval); -} -static void PreferenceSetValueFloat(const std::string &name, float v) { - GlobalConfigManager::GetInstance()->SetValueFloat(name, v); + +static iSysConfigManager* GetConfigManager() { + return GlobalConfigManager::GetInstance(); } #include "PreferenceConfig.h" diff --git a/src/core/environ/ui/IndividualPreferenceForm.cpp b/src/core/environ/ui/IndividualPreferenceForm.cpp index 129d2515..5bd4c87b 100644 --- a/src/core/environ/ui/IndividualPreferenceForm.cpp +++ b/src/core/environ/ui/IndividualPreferenceForm.cpp @@ -15,23 +15,8 @@ const char * const FileName_NaviBar = "ui/NaviBar.csb"; const char * const FileName_Body = "ui/ListView.csb"; #define TVPGlobalPreferenceForm IndividualPreferenceForm -static bool PreferenceGetValueBool(const std::string &name, bool defval) { - return IndividualConfigManager::GetInstance()->GetValue(name, defval); -} -static void PreferenceSetValueBool(const std::string &name, bool v) { - IndividualConfigManager::GetInstance()->SetValueInt(name, v); -} -static std::string PreferenceGetValueString(const std::string &name, const std::string& defval) { - return IndividualConfigManager::GetInstance()->GetValue(name, defval); -} -static void PreferenceSetValueString(const std::string &name, const std::string& v) { - IndividualConfigManager::GetInstance()->SetValue(name, v); -} -static float PreferenceGetValueFloat(const std::string &name, float defval) { - return IndividualConfigManager::GetInstance()->GetValue(name, defval); -} -static void PreferenceSetValueFloat(const std::string &name, float v) { - IndividualConfigManager::GetInstance()->SetValueFloat(name, v); +static iSysConfigManager* GetConfigManager() { + return IndividualConfigManager::GetInstance(); } #include "PreferenceConfig.h" diff --git a/src/core/environ/ui/MainFileSelectorForm.cpp b/src/core/environ/ui/MainFileSelectorForm.cpp index 0753a9e4..f7e766fc 100644 --- a/src/core/environ/ui/MainFileSelectorForm.cpp +++ b/src/core/environ/ui/MainFileSelectorForm.cpp @@ -20,6 +20,7 @@ #include "StorageImpl.h" #include "TipsHelpForm.h" #include "XP3RepackForm.h" +#include "cocos2d/CustomFileUtils.h" using namespace cocos2d; using namespace cocos2d::ui; @@ -200,6 +201,26 @@ void TVPMainFileSelectorForm::onCellClicked(int idx) { SimpleMediaFilePlayer *player = SimpleMediaFilePlayer::create(); TVPMainScene::GetInstance()->addChild(player, 10);// pushUIForm(player); player->PlayFile(info.FullPath.c_str()); + } else if (archiveType && FileUtils::getInstance()->getFileExtension(info.NameForCompare) == ".skin") { + // maybe skin + if (TVPSkinManager::Check(info.FullPath)) { + std::vector btns; + btns.emplace_back("Direct Use"); + btns.emplace_back("Install"); + btns.emplace_back("Cancel"); + switch (TVPShowSimpleMessageBox("Install or direct use it ? (restart needed)", "Skin found", btns)) { + case 0: // direct use + TVPSkinManager::Use(info.FullPath); + TVPShowSimpleMessageBox("Active after restart.", "Skin"); + break; + case 1: // install + TVPSkinManager::InstallAndUse(info.FullPath); + TVPShowSimpleMessageBox("Active after restart.", "Skin"); + break; + default: + break; + } + } } } @@ -371,13 +392,15 @@ void TVPMainFileSelectorForm::showMenu(Ref*) { case 1: TVPOpenPatchLibUrl(); break; - case 2: { - std::string text = TVPGetOpenGLInfo(); - const char *pOK = LocaleConfigManager::GetInstance()->GetText("ok").c_str(); - TVPShowSimpleMessageBox(text.c_str(), - LocaleConfigManager::GetInstance()->GetText("device_info").c_str(), - 1, &pOK); - } break; + case 2: + cocos2d::Director::getInstance()->getScheduler()->performFunctionInCocosThread([]{ + std::string text = TVPGetOpenGLInfo(); + const char *pOK = LocaleConfigManager::GetInstance()->GetText("ok").c_str(); + TVPShowSimpleMessageBox(text.c_str(), + LocaleConfigManager::GetInstance()->GetText("device_info").c_str(), + 1, &pOK); + }); + break; } }); reader.findWidget("btnExit")->addClickEventListener([](Ref*) { diff --git a/src/core/environ/ui/MessageBox.cpp b/src/core/environ/ui/MessageBox.cpp index 1781b7dc..9019e571 100644 --- a/src/core/environ/ui/MessageBox.cpp +++ b/src/core/environ/ui/MessageBox.cpp @@ -48,7 +48,7 @@ void TVPMessageBoxForm::init(const std::string &caption, const std::string &text } } _btnModel->retain(); - _btnModel->removeFromParent(); + _btnModel->removeFromParentAndCleanup(false); std::vector btns; diff --git a/src/core/environ/ui/PreferenceConfig.h b/src/core/environ/ui/PreferenceConfig.h index e6e18f0a..4fcbe307 100644 --- a/src/core/environ/ui/PreferenceConfig.h +++ b/src/core/environ/ui/PreferenceConfig.h @@ -1,6 +1,25 @@ extern void TVPInitTextureFormatList(); extern bool TVPIsSupportTextureFormat(GLenum fmt); +static bool PreferenceGetValueBool(const std::string &name, bool defval) { + return GetConfigManager()->GetValue(name, defval); +} +static void PreferenceSetValueBool(const std::string &name, bool v) { + GetConfigManager()->SetValueInt(name, v); +} +static std::string PreferenceGetValueString(const std::string &name, const std::string& defval) { + return GetConfigManager()->GetValue(name, defval); +} +static void PreferenceSetValueString(const std::string &name, const std::string& v) { + GetConfigManager()->SetValue(name, v); +} +static float PreferenceGetValueFloat(const std::string &name, float defval) { + return GetConfigManager()->GetValue(name, defval); +} +static void PreferenceSetValueFloat(const std::string &name, float v) { + GetConfigManager()->SetValueFloat(name, v); +} + namespace { static tPreferenceScreen RootPreference; static tPreferenceScreen OpenglOptPreference, SoftRendererOptPreference; @@ -199,12 +218,48 @@ class tTVPPreferenceInfoFetchSDCardPermission : public iTVPPreferenceInfo { } }; +class tTVPPreferenceInfoResetDefaultSkin : public iTVPPreferenceInfo { +public: + tTVPPreferenceInfoResetDefaultSkin(const std::string &cap) : iTVPPreferenceInfo(cap, "") {} + virtual iPreferenceItem *createItem(int idx) override { + LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance(); + tPreferenceItemConstant* ret = CreatePreferenceItem(idx, PrefListSize, locmgr->GetText(Caption)); + ret->setTouchEnabled(true); + ret->addClickEventListener([](Ref*) { + LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance(); + if (TVPShowSimpleMessageBoxYesNo(locmgr->GetText("preference_ensure_reset_skin"), locmgr->GetText("notice")) == 0) { + PreferenceSetValueString("skin_path", ""); + } + }); + return ret; + } +}; + +class tTVPPreferenceInfoKeyMap : public iTVPPreferenceInfo { +public: + tTVPPreferenceInfoKeyMap(const std::string &cap) : iTVPPreferenceInfo(cap, "") {} + virtual iPreferenceItem *createItem(int idx) override { + LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance(); + iPreferenceItem *ret = CreatePreferenceItem(idx, PrefListSize, locmgr->GetText(Caption)); + ret->addClickEventListener([this](Ref*) { + TVPMainScene::GetInstance()->pushUIForm(KeyMapPreferenceForm::create(GetConfigManager())); + }); + return ret; + } +}; + static void initAllConfig() { if (!RootPreference.Preferences.empty()) return; RootPreference.Title = "preference_title"; RootPreference.Preferences = { new tTVPPreferenceInfoCheckBox("preference_output_log", "outputlog", true), new tTVPPreferenceInfoCheckBox("preference_show_fps", "showfps", false), + new tTVPPreferenceInfoSelectList("preference_fps_limit", "fps_limit", "60",{ + { "60", "60" }, + { "45", "45" }, + { "30", "30" }, + { "15", "15" } + }), new tTVPPreferenceInfoSelectList("preference_select_renderer", "renderer", "software", { { "preference_opengl", "opengl" }, { "preference_software", "software" } @@ -225,12 +280,15 @@ static void initAllConfig() { new tTVPPreferenceInfoCheckBox("preference_keep_screen_alive", "keep_screen_alive", true), new tTVPPreferenceInfoSliderIcon("preference_virtual_cursor_scale", "vcursor_scale", 0.5f), new tTVPPreferenceInfoSliderText("preference_menu_handler_opacity", "menu_handler_opa", 0.15f), + new tTVPPreferenceInfoKeyMap("preference_keymap"), #ifdef GLOBAL_PREFERENCE new tTVPPreferenceInfoCheckBox("preference_remember_last_path", "remember_last_path", true), #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID new tTVPPreferenceInfoCheckBox("preference_hide_android_sys_btn", "hide_android_sys_btn", false), new tTVPPreferenceInfoFetchSDCardPermission("preference_android_fetch_sdcard_permission"), #endif + new tTVPPreferenceInfoResetDefaultSkin("preference_reset_def_skin"), + #endif #if 0 new tTVPPreferenceInfo(tTVPPreferenceInfo::eTypeSubPref, "preference_custom_option"), diff --git a/src/core/environ/ui/PreferenceForm.cpp b/src/core/environ/ui/PreferenceForm.cpp index d70e0e91..4cb48443 100644 --- a/src/core/environ/ui/PreferenceForm.cpp +++ b/src/core/environ/ui/PreferenceForm.cpp @@ -144,21 +144,20 @@ const char* tPreferenceItemSubDir::getUIFileName() const { return "ui/comctrl/SubDirItem.csb"; } -void tPreferenceItemSubDir::initController(const NodeMap &allNodes) { +void tPreferenceItemWithHighlight::initController(const NodeMap &allNodes) { setTouchEnabled(true); highlight = allNodes.findController("highlight"); } -void tPreferenceItemSubDir::onPressStateChangedToNormal() { +void tPreferenceItemWithHighlight::onPressStateChangedToNormal() { if (highlight) highlight->setVisible(false); } -void tPreferenceItemSubDir::onPressStateChangedToPressed() { +void tPreferenceItemWithHighlight::onPressStateChangedToPressed() { if (highlight) highlight->setVisible(true); } tPreferenceItemSubDir::tPreferenceItemSubDir() - : highlight(nullptr) { } @@ -183,7 +182,10 @@ void tPreferenceItemSelectList::showForm(cocos2d::Ref*) { TVPSelectListForm *form = TVPSelectListForm::create(lst, highlightTid, [this](int idx){ const std::pair& item = CurInfo->getListInfo()[idx]; highlightTid = item.first; - LocaleConfigManager::GetInstance()->initText(selected, highlightTid); + if (highlightTid.empty()) + selected->setString(item.second); + else + LocaleConfigManager::GetInstance()->initText(selected, highlightTid); _setter(item.second); }); TVPMainScene::GetInstance()->pushUIForm(form, TVPMainScene::eEnterFromBottom); @@ -438,3 +440,107 @@ void tPreferenceItemFileSelect::updateHightlight() { if (selected) selected->setString(_getter()); } + +KeyMapPreferenceForm::KeyMapPreferenceForm(iSysConfigManager* mgr) + : _mgr(mgr) +{ + +} + +void KeyMapPreferenceForm::initData() +{ + LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance(); + PrefList->removeAllItems(); + locmgr->initText(_title, "preference_keymap_title"); + + Size size = PrefList->getContentSize(); +#if 0 + tPreferenceItemConstant* celladd = CreatePreferenceItem(0, size, locmgr->GetText("preference_keymap_add")); + celladd->setTouchEnabled(true); + celladd->addClickEventListener([this](Ref*) { + TVPKeyPairSelectForm *form = TVPKeyPairSelectForm::create([this](int k) { + TVPKeyPairSelectForm *form = TVPKeyPairSelectForm::create([this, k](int v) { + _mgr->SetKeyMap(k, v); + initData(); + }); + TVPMainScene::GetInstance()->pushUIForm(form, TVPMainScene::eEnterFromBottom); + }); + TVPMainScene::GetInstance()->pushUIForm(form, TVPMainScene::eEnterFromBottom); + }); + PrefList->pushBackCustomItem(celladd); + + const auto& keymap = _mgr->GetKeyMap(); + int counter = 0; + for (const std::pair& it : keymap) { + if (it.first && it.second) { + tPreferenceItemKeyMap *cell = new tPreferenceItemKeyMap; + cell->initData(it.first, it.second, ++counter, size); + cell->_onDelete = [this](tPreferenceItemDeletable* cell) { + auto &keypair = static_cast(cell)->_keypair; + _mgr->SetKeyMap(keypair.first, 0); + }; + PrefList->pushBackCustomItem(cell); + } + } +#endif + Widget *nullcell = new Widget(); + nullcell->setContentSize(Size(PrefList->getContentSize().width, 200)); + PrefList->pushBackCustomItem(nullcell); +} + +KeyMapPreferenceForm* KeyMapPreferenceForm::create(iSysConfigManager* mgr) +{ + KeyMapPreferenceForm *ret = new KeyMapPreferenceForm(mgr); + ret->autorelease(); + ret->initFromFile("ui/NaviBar.csb", "ui/ListView.csb", nullptr); + ret->initData(); + return ret; +} + +void tPreferenceItemDeletable::initController(const NodeMap &allNodes) +{ + _deleteIcon = allNodes.findWidget("delete"); + _scrollview = allNodes.findController("scrollview"); + _scrollview->setScrollBarEnabled(false); + Size viewSize = _scrollview->getContentSize(); + float iconWidth = _deleteIcon->getContentSize().width; + viewSize.width += iconWidth; + _scrollview->setInnerContainerSize(viewSize); + walkTouchEvent(_scrollview); + _deleteIcon->addTouchEventListener(nullptr); + _deleteIcon->addClickEventListener([this](Ref*) { + if (_onDelete) _onDelete(this); + }); +} + +const char* tPreferenceItemDeletable::getUIFileName() const +{ + return "ui/comctrl/DeletableItem.csb"; +} + +void tPreferenceItemDeletable::onTouchEvent(cocos2d::Ref* p, cocos2d::ui::Widget::TouchEventType ev) +{ + +} + +void tPreferenceItemDeletable::walkTouchEvent(Widget* node) +{ + node->addTouchEventListener(std::bind(&tPreferenceItemDeletable::onTouchEvent, + this, std::placeholders::_1, std::placeholders::_2)); + auto &vecChildren = node->getChildren(); + for (Node *child : vecChildren) { + Widget *widget = dynamic_cast(child); + if (widget) { + walkTouchEvent(widget); + } + } +} + +void tPreferenceItemKeyMap::initData(int k, int v, int idx, const cocos2d::Size &size) +{ + _keypair.first = k; _keypair.second = v; + char buf[32]; + sprintf(buf, "%d <=> %d", k, v); + initFromInfo(idx, size, buf); +} + diff --git a/src/core/environ/ui/PreferenceForm.h b/src/core/environ/ui/PreferenceForm.h index f4102e51..dc41df7e 100644 --- a/src/core/environ/ui/PreferenceForm.h +++ b/src/core/environ/ui/PreferenceForm.h @@ -66,7 +66,7 @@ class TVPPreferenceForm : public iTVPBaseForm { virtual void bindBodyController(const NodeMap &allNodes) override; virtual void bindHeaderController(const NodeMap &allNodes) override; - const tPreferenceScreen *Config; + const tPreferenceScreen *Config = nullptr; cocos2d::ui::ListView *PrefList; cocos2d::ui::Button *_title; }; @@ -120,18 +120,22 @@ class tPreferenceItemCheckBox : public tPreferenceItem { cocos2d::Node *highlight; }; -class tPreferenceItemSubDir : public iPreferenceItem { -public: - tPreferenceItemSubDir(); - +class tPreferenceItemWithHighlight : public iPreferenceItem { protected: virtual void initController(const NodeMap &allNodes) override; - virtual const char* getUIFileName() const override; virtual void onPressStateChangedToNormal() override; virtual void onPressStateChangedToPressed() override; - cocos2d::Node *highlight; + cocos2d::Node *highlight = nullptr; +}; + +class tPreferenceItemSubDir : public tPreferenceItemWithHighlight { +public: + tPreferenceItemSubDir(); + +protected: + virtual const char* getUIFileName() const override; }; class tPreferenceItemConstant : public tPreferenceItemSubDir { @@ -265,3 +269,32 @@ class tPreferenceItemTextSlider : public iPreferenceItemSlider { cocos2d::ui::Text *_text; std::function _strScaleConv; }; + +class tPreferenceItemDeletable : public iPreferenceItem { + virtual void initController(const NodeMap &allNodes) override; + virtual const char* getUIFileName() const override; + void onTouchEvent(cocos2d::Ref*, cocos2d::ui::Widget::TouchEventType); + void walkTouchEvent(cocos2d::ui::Widget* node); + + cocos2d::ui::Widget *_deleteIcon; + cocos2d::ui::ScrollView *_scrollview; + +public: + std::function _onDelete; +}; + +class tPreferenceItemKeyMap : public tPreferenceItemDeletable { +public: + std::pair _keypair; + + void initData(int k, int v, int idx, const cocos2d::Size &size); +}; + +class KeyMapPreferenceForm : public TVPPreferenceForm { + iSysConfigManager* _mgr; + KeyMapPreferenceForm(iSysConfigManager* mgr); + void initData(); + +public: + static KeyMapPreferenceForm* create(iSysConfigManager* mgr); +}; diff --git a/src/core/environ/ui/SeletListForm.cpp b/src/core/environ/ui/SeletListForm.cpp index 81040b04..f1af66f6 100644 --- a/src/core/environ/ui/SeletListForm.cpp +++ b/src/core/environ/ui/SeletListForm.cpp @@ -7,6 +7,7 @@ #include "platform/CCDevice.h" #include "cocos2d/MainScene.h" #include "ConfigManager/LocaleConfigManager.h" +#include "cocos2d/CCKeyCodeConv.h" using namespace cocos2d; using namespace cocos2d::ui; @@ -121,3 +122,55 @@ void TVPTextPairInputForm::initWithInfo(const std::string &text1, const std::str input1->setString(text1); input2->setString(text2); } + +TVPKeyPairSelectForm * TVPKeyPairSelectForm::create(const std::function &funcok) +{ + TVPKeyPairSelectForm *ret = new TVPKeyPairSelectForm; + ret->autorelease(); + ret->_funcok = funcok; + ret->initFromFile(FileName_Body); + ret->initWithInfo(); + return ret; +} + +TVPKeyPairSelectForm::~TVPKeyPairSelectForm() +{ + if (_keylistener) { + _eventDispatcher->removeEventListener(_keylistener); + } +} + +void TVPKeyPairSelectForm::initWithInfo() +{ + FuncOK = [this](int idx) { + auto &namemap = TVPGetVKCodeNameMap(); + auto it = namemap.find(_keyinfo[idx]); + if (it == namemap.end()) { + return; + } + _funcok(it->second); + }; + auto &namemap = TVPGetVKCodeNameMap(); + _keyinfo.clear(); + _keyinfo.reserve(namemap.size()); + for (const auto &it : namemap) { + _keyinfo.emplace_back(it.first); + } + inherit::initWithInfo(_keyinfo, "0"); + _keylistener = EventListenerKeyboard::create(); + _keylistener->onKeyPressed = CC_CALLBACK_2(TVPKeyPairSelectForm::onKeyPressed, this); + _keylistener->onKeyReleased = CC_CALLBACK_2(TVPKeyPairSelectForm::onKeyReleased, this); + _eventDispatcher->addEventListenerWithFixedPriority(_keylistener, 1); +} + +void TVPKeyPairSelectForm::onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event) +{ +} + +void TVPKeyPairSelectForm::onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event) +{ + unsigned int code = TVPConvertKeyCodeToVKCode(keyCode); + if (!code || code >= 0x200) return; + + _funcok(code); +} diff --git a/src/core/environ/ui/SeletListForm.h b/src/core/environ/ui/SeletListForm.h index 76e2e40b..0b766c16 100644 --- a/src/core/environ/ui/SeletListForm.h +++ b/src/core/environ/ui/SeletListForm.h @@ -12,7 +12,7 @@ class TVPSelectListForm : public iTVPHalfScreenForm { static TVPSelectListForm *create(const std::vector &info, const std::string &highlight_tid, const std::function &funcok); -private: +protected: virtual void bindBodyController(const NodeMap &allNodes) override; void initWithInfo(const std::vector &info, const std::string &highlight_tid); @@ -33,4 +33,22 @@ class TVPTextPairInputForm : public iTVPHalfScreenForm { std::function FuncOK; cocos2d::ui::TextField *input1, *input2; +}; + +class TVPKeyPairSelectForm : public TVPSelectListForm { + typedef TVPSelectListForm inherit; + + cocos2d::EventListenerKeyboard* _keylistener = nullptr; + std::vector _keyinfo; + std::function _funcok; + +public: + static TVPKeyPairSelectForm *create(const std::function &funcok); + + virtual ~TVPKeyPairSelectForm(); + + void initWithInfo(); + + void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event); + void onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event); }; \ No newline at end of file diff --git a/src/core/environ/ui/XP3RepackForm.cpp b/src/core/environ/ui/XP3RepackForm.cpp index 7c032556..65e8a167 100644 --- a/src/core/environ/ui/XP3RepackForm.cpp +++ b/src/core/environ/ui/XP3RepackForm.cpp @@ -146,17 +146,17 @@ void TVPXP3Repacker::OnProgress(uint64_t total_size, uint64_t arc_size, uint64_t LastUpdate = tick; Director::getInstance()->getScheduler()->performFunctionInCocosThread([this, total_size, arc_size] { - ProgressForm->setPercentOnly((float)total_size / TotalSize); - ProgressForm->setPercentOnly2((float)arc_size / CurrentArcSize); + ProgressForm->setPercentOnly2((float)total_size / TotalSize); + ProgressForm->setPercentOnly((float)arc_size / CurrentArcSize); char buf[64]; int sizeMB = static_cast(total_size / (1024 * 1024)), totalMB = static_cast(TotalSize / (1024 * 1024)); sprintf(buf, "%d / %dMB", sizeMB, totalMB); - ProgressForm->setPercentText(buf); + ProgressForm->setPercentText2(buf); sizeMB = static_cast(arc_size / (1024 * 1024)); totalMB = static_cast(CurrentArcSize / (1024 * 1024)); sprintf(buf, "%d / %dMB", sizeMB, totalMB); - ProgressForm->setPercentText2(buf); + ProgressForm->setPercentText(buf); }); } @@ -338,7 +338,7 @@ void TVPProcessXP3Repack(const std::string &dir) delete st; }); if (filelist.empty()) { - TVPShowSimpleMessageBox(locmgr->GetText("archive_repack_no_xp3").c_str(), "XP3Repack"); + TVPShowSimpleMessageBox(locmgr->GetText("archive_repack_no_xp3").c_str(), "XP3Repack", 0, nullptr); } else { TVPXP3RepackFileListForm::show(filelist, dir); } diff --git a/src/core/environ/ui/extension/UIExtension.cpp b/src/core/environ/ui/extension/UIExtension.cpp index 7db133f0..4da07316 100644 --- a/src/core/environ/ui/extension/UIExtension.cpp +++ b/src/core/environ/ui/extension/UIExtension.cpp @@ -3,6 +3,7 @@ #include "ui/UIWidget.h" #include "cocostudio/ActionTimeline/CSLoader.h" #include "cocostudio/WidgetReader/NodeReader/NodeReader.h" +#include "base/CCEventDispatcher.h" USING_NS_CC; using namespace cocos2d::ui; diff --git a/src/core/visual/FontImpl.h b/src/core/visual/FontImpl.h index 61ec4087..1d7483c9 100644 --- a/src/core/visual/FontImpl.h +++ b/src/core/visual/FontImpl.h @@ -5,6 +5,7 @@ void TVPInitFontNames(); int TVPEnumFontsProc(const ttstr &FontPath); +const ttstr &TVPGetDefaultFontName(); tTJSBinaryStream* TVPCreateFontStream(const ttstr &fontname); struct TVPFontNamePathInfo { ttstr Path; diff --git a/src/core/visual/GraphicsLoaderIntf.cpp b/src/core/visual/GraphicsLoaderIntf.cpp index 6fe097b4..5f1fdbe7 100644 --- a/src/core/visual/GraphicsLoaderIntf.cpp +++ b/src/core/visual/GraphicsLoaderIntf.cpp @@ -156,6 +156,14 @@ class tTVPGraphicType tTVPGraphicType() { // register some native-supported formats + Handlers.push_back(tTVPGraphicHandlerType( + TJS_W(".pvr"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, nullptr, nullptr, NULL)); + Handlers.push_back(tTVPGraphicHandlerType( + TJS_W(".jxr"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, TVPSaveAsJXR, TVPAcceptSaveAsJXR, NULL)); + Handlers.push_back(tTVPGraphicHandlerType( + TJS_W(".bpg"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, nullptr, nullptr, NULL)); + Handlers.push_back(tTVPGraphicHandlerType( + TJS_W(".webp"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, nullptr, nullptr, NULL)); Handlers.push_back(tTVPGraphicHandlerType( TJS_W(".bmp"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, TVPSaveAsBMP, TVPAcceptSaveAsBMP, NULL)); Handlers.push_back(tTVPGraphicHandlerType( @@ -174,14 +182,6 @@ class tTVPGraphicType TJS_W(".tlg5"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, TVPSaveAsTLG, TVPAcceptSaveAsTLG, NULL)); Handlers.push_back(tTVPGraphicHandlerType( TJS_W(".tlg6"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, TVPSaveAsTLG, TVPAcceptSaveAsTLG, NULL)); - Handlers.push_back(tTVPGraphicHandlerType( - TJS_W(".jxr"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, TVPSaveAsJXR, TVPAcceptSaveAsJXR, NULL)); - Handlers.push_back(tTVPGraphicHandlerType( - TJS_W(".bpg"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, nullptr, nullptr, NULL)); - Handlers.push_back(tTVPGraphicHandlerType( - TJS_W(".webp"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, nullptr, nullptr, NULL)); - Handlers.push_back(tTVPGraphicHandlerType( - TJS_W(".pvr"), TVPLoadGraphicRouter, TVPLoadHeaderRouter, nullptr, nullptr, NULL)); ReCreateHash(); Avail = true; } @@ -783,11 +783,13 @@ static void TVPWriteLE32(tTJSBinaryStream * stream, tjs_uint32 number) stream->WriteBuffer(data, 4); } //--------------------------------------------------------------------------- -void TVPSaveAsBMP( void* formatdata, tTJSBinaryStream* dst, const iTVPBaseBitmap* bmp, const ttstr & mode, iTJSDispatch2* meta ) +void TVPSaveTextureAsBMP(tTJSBinaryStream* dst, iTVPTexture2D* bmp, const ttstr & mode, iTJSDispatch2* meta) { tjs_int pixelbytes; - if(mode == TJS_W("bmp32") || mode == TJS_W("bmp")) + if (bmp->GetFormat() == TVPTextureFormat::Gray) + pixelbytes = 1; + else if(mode == TJS_W("bmp32") || mode == TJS_W("bmp")) pixelbytes = 4; else if(mode == TJS_W("bmp24")) pixelbytes = 3; @@ -850,45 +852,60 @@ void TVPSaveAsBMP( void* formatdata, tTJSBinaryStream* dst, const iTVPBaseBitmap { tjs_uint8 palette[1024]; tjs_uint8 * p = palette; - for(tjs_int i = 0; i < 256; i++) - { - p[0] = TVP252DitherPalette[0][i]; - p[1] = TVP252DitherPalette[1][i]; - p[2] = TVP252DitherPalette[2][i]; - p[3] = 0; - p += 4; + if (bmp->GetFormat() == TVPTextureFormat::Gray) { + for (tjs_int i = 0; i < 256; i++) + { + p[0] = i; + p[1] = i; + p[2] = i; + p[3] = 0; + p += 4; + } + } else { + for (tjs_int i = 0; i < 256; i++) + { + p[0] = TVP252DitherPalette[0][i]; + p[1] = TVP252DitherPalette[1][i]; + p[2] = TVP252DitherPalette[2][i]; + p[3] = 0; + p += 4; + } } stream->WriteBuffer(palette, 1024); } // write bitmap body - for(tjs_int y = bmp->GetHeight() - 1; y >= 0; y --) - { - if(!buf) buf = new tjs_uint8[bmppitch]; - if(pixelbytes == 4) + if (bmp->GetFormat() == TVPTextureFormat::Gray) { + for (tjs_int y = bmp->GetHeight() - 1; y >= 0; y--) { - TVPReverseRGB((tjs_uint32 *)buf, (const tjs_uint32 *)bmp->GetScanLine(y), bmp->GetWidth()); + if (!buf) buf = new tjs_uint8[bmppitch]; + memcpy(buf, bmp->GetScanLineForRead(y), bmp->GetWidth()); + stream->WriteBuffer(buf, bmppitch); } - else if(pixelbytes == 1) - { - TVPDither32BitTo8Bit(buf, (const tjs_uint32*)bmp->GetScanLine(y), - bmp->GetWidth(), 0, y); - } - else + } else { + for (tjs_int y = bmp->GetHeight() - 1; y >= 0; y--) { - const tjs_uint8 *src = (const tjs_uint8 *)bmp->GetScanLine(y); - tjs_uint8 *dest = buf; - tjs_int w = bmp->GetWidth(); - for(tjs_int x = 0; x < w; x++) - { - dest[0] = src[2]; - dest[1] = src[1]; - dest[2] = src[0]; - dest += 3; - src += 4; + if (!buf) buf = new tjs_uint8[bmppitch]; + if (pixelbytes == 4) { + TVPReverseRGB((tjs_uint32 *)buf, (const tjs_uint32 *)bmp->GetScanLineForRead(y), bmp->GetWidth()); + } else if (pixelbytes == 1) { + TVPDither32BitTo8Bit(buf, (const tjs_uint32*)bmp->GetScanLineForRead(y), + bmp->GetWidth(), 0, y); + } else { + const tjs_uint8 *src = (const tjs_uint8 *)bmp->GetScanLineForRead(y); + tjs_uint8 *dest = buf; + tjs_int w = bmp->GetWidth(); + for (tjs_int x = 0; x < w; x++) + { + dest[0] = src[2]; + dest[1] = src[1]; + dest[2] = src[0]; + dest += 3; + src += 4; + } } + stream->WriteBuffer(buf, bmppitch); } - stream->WriteBuffer(buf, bmppitch); } } catch(...) @@ -898,6 +915,18 @@ void TVPSaveAsBMP( void* formatdata, tTJSBinaryStream* dst, const iTVPBaseBitmap } if(buf) delete [] buf; } + +void TVPSaveTextureAsBMP(const ttstr &path, iTVPTexture2D* tex, const ttstr &mode, iTJSDispatch2* meta) +{ + tTJSBinaryStream *dst = TVPCreateStream(path, TJS_BS_WRITE); + TVPSaveTextureAsBMP(dst, tex, mode, meta); + delete dst; +} + +void TVPSaveAsBMP(void* formatdata, tTJSBinaryStream* dst, const iTVPBaseBitmap* bmp, const ttstr & mode, iTJSDispatch2* meta) +{ + TVPSaveTextureAsBMP(dst, bmp->GetTexture(), mode, meta); +} //--------------------------------------------------------------------------- void TVPLoadHeaderBMP( void* formatdata, tTJSBinaryStream *src, iTJSDispatch2** dic ) @@ -2132,11 +2161,11 @@ class TVPGraphicPreload { continue; } - unsigned int totalSize = 0; + tjs_uint totalSize = 0; for(auto it = CurrentTask->items.begin(); it != CurrentTask->items.end(); ++it) { if(ReqInterrupt) break; totalSize += loadOneGraph(*it); - if(totalSize >= CurrentTask->limit) break; + if(totalSize >= (tjs_uint)CurrentTask->limit) break; } delete CurrentTask; } diff --git a/src/core/visual/GraphicsLoaderIntf.h b/src/core/visual/GraphicsLoaderIntf.h index 32aaea21..7affc02b 100644 --- a/src/core/visual/GraphicsLoaderIntf.h +++ b/src/core/visual/GraphicsLoaderIntf.h @@ -226,6 +226,8 @@ extern bool TVPAcceptSaveAsJXR(void* formatdata, const ttstr & type, iTJSDispatc extern bool TVPAcceptSaveAsTLG(void* formatdata, const ttstr & type, iTJSDispatch2** dic ); //--------------------------------------------------------------------------- +void TVPSaveTextureAsBMP(tTJSBinaryStream* dst, class iTVPTexture2D* bmp, const ttstr & mode = TJS_W(""), iTJSDispatch2* meta = nullptr); +void TVPSaveTextureAsBMP(const ttstr &path, class iTVPTexture2D* tex, const ttstr &mode = TJS_W(""), iTJSDispatch2* meta = nullptr); //--------------------------------------------------------------------------- // JPEG loading handler diff --git a/src/core/visual/LayerIntf.cpp b/src/core/visual/LayerIntf.cpp index c7d0429d..18371104 100644 --- a/src/core/visual/LayerIntf.cpp +++ b/src/core/visual/LayerIntf.cpp @@ -14,6 +14,8 @@ #include "tjsCommHead.h" #include +#include +#include #include "tjsArray.h" #include "LayerIntf.h" @@ -40,6 +42,7 @@ #include "vkdefine.h" #include "RenderManager.h" #include +#include "FontImpl.h" extern void TVPSetFontRasterizer( tjs_int index ); extern tjs_int TVPGetFontRasterizer(); @@ -11306,6 +11309,27 @@ TJS_BEGIN_NATIVE_PROP_DECL(rasterizer) TJS_END_NATIVE_PROP_SETTER } TJS_END_NATIVE_STATIC_PROP_DECL(rasterizer) +//---------------------------------------------------------------------- +TJS_BEGIN_NATIVE_PROP_DECL(defaultFaceName) +{ + TJS_BEGIN_NATIVE_PROP_GETTER + { + *result = TVPGetDefaultFontName(); + // *result = ttstr(TVPFontSystem->GetDefaultFontName()); + return TJS_S_OK; + } + TJS_END_NATIVE_PROP_GETTER + + TJS_BEGIN_NATIVE_PROP_SETTER + { + ttstr name( *param ); + // don't override, specified by preference + // TVPFontSystem->SetDefaultFontName( name.c_str() ); + return TJS_S_OK; + } + TJS_END_NATIVE_PROP_SETTER +} +TJS_END_NATIVE_STATIC_PROP_DECL(defaultFaceName) //---------------------------------------------------------------------- TJS_END_NATIVE_MEMBERS diff --git a/src/core/visual/ogl/imagepacker.cpp b/src/core/visual/ogl/imagepacker.cpp index 34a644c3..f7d49512 100644 --- a/src/core/visual/ogl/imagepacker.cpp +++ b/src/core/visual/ogl/imagepacker.cpp @@ -1,6 +1,7 @@ #include "imagepacker.h" #include #include +#include using namespace std; diff --git a/src/core/visual/win32/BitmapBitsAlloc.cpp b/src/core/visual/win32/BitmapBitsAlloc.cpp index 684a7abe..c73b86ce 100644 --- a/src/core/visual/win32/BitmapBitsAlloc.cpp +++ b/src/core/visual/win32/BitmapBitsAlloc.cpp @@ -106,10 +106,10 @@ tTJSCriticalSection tTVPBitmapBitsAlloc::AllocCS; void tTVPBitmapBitsAlloc::InitializeAllocator() { if( Allocator == NULL ) { +#if 0 tTJSVariant val; - if(TVPGetCommandLine(TJS_W("-bitmapallocator"), &val)) { + if (TVPGetCommandLine(TJS_W("-bitmapallocator"), &val)) { ttstr str(val); -#if 0 if(str == TJS_W("globalalloc")) Allocator = new GlobalAllocAllocator(); else if(str == TJS_W("separateheap")) @@ -117,13 +117,11 @@ void tTVPBitmapBitsAlloc::InitializeAllocator() { else // malloc #endif Allocator = new BasicAllocator(); - } else { #if 0 + } else { Allocator = new GlobalAllocAllocator(); -#else - Allocator = new BasicAllocator(); -#endif } +#endif } } void tTVPBitmapBitsAlloc::FreeAllocator() { diff --git a/src/core/visual/win32/LayerBitmapImpl.cpp b/src/core/visual/win32/LayerBitmapImpl.cpp index 9c0bc3bf..7e594eec 100644 --- a/src/core/visual/win32/LayerBitmapImpl.cpp +++ b/src/core/visual/win32/LayerBitmapImpl.cpp @@ -561,7 +561,9 @@ void tTVPNativeBaseBitmap::SetHeight(tjs_uint h) //--------------------------------------------------------------------------- void tTVPNativeBaseBitmap::SetSize(tjs_uint w, tjs_uint h, bool keepimage) { - if(Bitmap->GetWidth() != w || Bitmap->GetHeight() != h) + if (w == 0) w = 1; + if (h == 0) h = 1; + if (Bitmap->GetWidth() != w || Bitmap->GetHeight() != h) { // create a new bitmap and copy existing bitmap iTVPTexture2D *newbitmap;