mirror of https://github.com/axmolengine/axmol.git
support win32
This commit is contained in:
parent
197ab05a99
commit
dee536def2
|
@ -53,6 +53,7 @@
|
|||
using namespace std;
|
||||
using namespace cocos2d;
|
||||
|
||||
static id SIMULATOR = nullptr;
|
||||
@implementation AppController
|
||||
|
||||
@synthesize menu;
|
||||
|
@ -86,6 +87,7 @@ static void glfwDropFunc(GLFWwindow *window, int count, const char **files)
|
|||
-(void) dealloc
|
||||
{
|
||||
Director::getInstance()->end();
|
||||
player::PlayerProtocol::getInstance()->purgeInstance();
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -94,8 +96,8 @@ static void glfwDropFunc(GLFWwindow *window, int count, const char **files)
|
|||
|
||||
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
auto player = player::PlayerMac::create();
|
||||
player->setController(self);
|
||||
SIMULATOR = self;
|
||||
player::PlayerMac::create();
|
||||
|
||||
_debugLogFile = 0;
|
||||
|
||||
|
@ -271,14 +273,11 @@ static void glfwDropFunc(GLFWwindow *window, int count, const char **files)
|
|||
[[NSApplication sharedApplication] setDelegate: self];
|
||||
[_window center];
|
||||
|
||||
if (_project.getProjectDir().length())
|
||||
[self setZoom:_project.getFrameScale()];
|
||||
Vec2 pos = _project.getWindowOffset();
|
||||
if (pos.x != 0 && pos.y != 0)
|
||||
{
|
||||
[self setZoom:_project.getFrameScale()];
|
||||
Vec2 pos = _project.getWindowOffset();
|
||||
if (pos.x != 0 && pos.y != 0)
|
||||
{
|
||||
[_window setFrameOrigin:NSMakePoint(pos.x, pos.y)];
|
||||
}
|
||||
[_window setFrameOrigin:NSMakePoint(pos.x, pos.y)];
|
||||
}
|
||||
|
||||
#if (PLAYER_SUPPORT_DROP > 0)
|
||||
|
@ -434,15 +433,13 @@ static void glfwDropFunc(GLFWwindow *window, int count, const char **files)
|
|||
}
|
||||
|
||||
string data = dArgParse["data"].GetString();
|
||||
auto player = player::PlayerProtocol::getInstance();
|
||||
|
||||
if ((data == "CLOSE_MENU") || (data == "EXIT_MENU"))
|
||||
{
|
||||
player->quit();
|
||||
Director::getInstance()->end();
|
||||
}
|
||||
else if (data == "REFRESH_MENU")
|
||||
{
|
||||
player->relaunch();
|
||||
[SIMULATOR relaunch];
|
||||
}
|
||||
else if (data.find("VIEW_SCALE_MENU_") == 0) // begin with VIEW_SCALE_MENU_
|
||||
{
|
||||
|
@ -452,7 +449,6 @@ static void glfwDropFunc(GLFWwindow *window, int count, const char **files)
|
|||
|
||||
auto glview = static_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView());
|
||||
glview->setFrameZoomFactor(scale);
|
||||
|
||||
|
||||
// update scale menu state
|
||||
for (auto &it : scaleMenuVector)
|
||||
|
@ -473,18 +469,17 @@ static void glfwDropFunc(GLFWwindow *window, int count, const char **files)
|
|||
}
|
||||
|
||||
project.setFrameSize(cocos2d::Size(size.width, size.height));
|
||||
project.setWindowOffset(cocos2d::Vec2(player->getPositionX(), player->getPositionY()));
|
||||
player->openProjectWithProjectConfig(project);
|
||||
[SIMULATOR relaunch];
|
||||
}
|
||||
else if (data == "DIRECTION_PORTRAIT_MENU")
|
||||
{
|
||||
project.changeFrameOrientationToPortait();
|
||||
player->openProjectWithProjectConfig(project);
|
||||
[SIMULATOR relaunch];
|
||||
}
|
||||
else if (data == "DIRECTION_LANDSCAPE_MENU")
|
||||
{
|
||||
project.changeFrameOrientationToLandscape();
|
||||
player->openProjectWithProjectConfig(project);
|
||||
[SIMULATOR relaunch];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "main.h"
|
||||
#include "service/PlayerWin.h"
|
||||
#include "SimulatorWin.h"
|
||||
#include <shellapi.h>
|
||||
|
||||
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||
|
@ -9,6 +9,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
|||
{
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
auto player = player::PlayerWin::getInstance();
|
||||
return player->run();
|
||||
auto simulator = SimulatorWin::getInstance();
|
||||
return simulator->run();
|
||||
}
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
#include "DeviceEx.h"
|
||||
|
||||
// for mac address
|
||||
#include <WinSock2.h>
|
||||
#include <Iphlpapi.h>
|
||||
#pragma comment(lib,"Iphlpapi.lib")
|
||||
|
||||
using namespace std;
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
DeviceEx *DeviceEx::getInstance()
|
||||
{
|
||||
static DeviceEx *instance = NULL;
|
||||
if (!instance)
|
||||
{
|
||||
instance = new DeviceEx();
|
||||
instance->init();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::string DeviceEx::getCurrentUILangName()
|
||||
{
|
||||
return _uiLangName;
|
||||
}
|
||||
|
||||
std::string DeviceEx::getUserGUID()
|
||||
{
|
||||
return _userGUID;
|
||||
}
|
||||
|
||||
|
||||
////////// private //////////
|
||||
|
||||
DeviceEx::DeviceEx()
|
||||
: _uiLangName("en")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DeviceEx::init()
|
||||
{
|
||||
makeUILangName();
|
||||
makeUserGUID();
|
||||
}
|
||||
|
||||
void DeviceEx::makeUILangName()
|
||||
{
|
||||
//
|
||||
// get language
|
||||
// http://msdn.microsoft.com/en-us/library/windows/apps/jj244362(v=vs.105).aspx
|
||||
//
|
||||
ULONG numLanguages = 0;
|
||||
DWORD cchLanguagesBuffer = 0;
|
||||
BOOL hr = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages, NULL, &cchLanguagesBuffer);
|
||||
if (hr)
|
||||
{
|
||||
WCHAR* pwszLanguagesBuffer = new WCHAR[cchLanguagesBuffer];
|
||||
hr = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages, pwszLanguagesBuffer, &cchLanguagesBuffer);
|
||||
if (hr)
|
||||
{
|
||||
size_t size = wcslen(pwszLanguagesBuffer) * 3 + 1;
|
||||
char* dest = new char[size];
|
||||
memset(dest, 0, size);
|
||||
WideCharToMultiByte(CP_UTF8, 0, pwszLanguagesBuffer, -1, dest, size, NULL, NULL);
|
||||
_uiLangName = dest;
|
||||
}
|
||||
delete pwszLanguagesBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
static bool getMacAddress(string& macstring)
|
||||
{
|
||||
bool ret = false;
|
||||
ULONG ipInfoLen = sizeof(IP_ADAPTER_INFO);
|
||||
PIP_ADAPTER_INFO adapterInfo = (IP_ADAPTER_INFO *)malloc(ipInfoLen);
|
||||
if (adapterInfo == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GetAdaptersInfo(adapterInfo, &ipInfoLen) == ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
free(adapterInfo);
|
||||
adapterInfo = (IP_ADAPTER_INFO *)malloc(ipInfoLen);
|
||||
if (adapterInfo == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (GetAdaptersInfo(adapterInfo, &ipInfoLen) == NO_ERROR)
|
||||
{
|
||||
for (PIP_ADAPTER_INFO pAdapter = adapterInfo; pAdapter != NULL; pAdapter = pAdapter->Next)
|
||||
{
|
||||
if (pAdapter->Type != MIB_IF_TYPE_ETHERNET)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pAdapter->AddressLength != 6)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
char buf32[32];
|
||||
sprintf(buf32, "%02X-%02X-%02X-%02X-%02X-%02X",
|
||||
int(pAdapter->Address[0]),
|
||||
int(pAdapter->Address[1]),
|
||||
int(pAdapter->Address[2]),
|
||||
int(pAdapter->Address[3]),
|
||||
int(pAdapter->Address[4]),
|
||||
int(pAdapter->Address[5]));
|
||||
macstring = buf32;
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(adapterInfo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string DeviceEx::makeUserGUID()
|
||||
{
|
||||
if (_userGUID.length() <= 0)
|
||||
{
|
||||
if (!getMacAddress(_userGUID))
|
||||
{
|
||||
_userGUID = "guid-fixed-1234567890";
|
||||
}
|
||||
}
|
||||
|
||||
return _userGUID;
|
||||
}
|
||||
|
||||
PLAYER_NS_END
|
|
@ -1,98 +0,0 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "cocos2d.h"
|
||||
#include "PlayerEditBoxServiceWin.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
PlayerEditBoxServiceWin::PlayerEditBoxServiceWin(HWND hwnd)
|
||||
: _hfont(NULL)
|
||||
{
|
||||
_hwnd = hwnd;
|
||||
HINSTANCE instance = (HINSTANCE)GetWindowLong(_hwnd, GWL_HINSTANCE);
|
||||
DWORD style = WS_CHILD | ES_LEFT | ES_AUTOHSCROLL;
|
||||
_hwndSingle = CreateWindowEx(WS_EX_CLIENTEDGE, L"Edit", L"", style, 0, 0, 0, 0, _hwnd, NULL, instance, NULL);
|
||||
style = WS_CHILD | ES_MULTILINE | ES_LEFT | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL;
|
||||
_hwndMulti = CreateWindowEx(WS_EX_CLIENTEDGE, L"Edit", L"", style, 0, 0, 0, 0, _hwnd, NULL, instance, NULL);
|
||||
}
|
||||
|
||||
PlayerEditBoxServiceWin::~PlayerEditBoxServiceWin()
|
||||
{
|
||||
removeFont();
|
||||
DestroyWindow(_hwndSingle);
|
||||
DestroyWindow(_hwndMulti);
|
||||
}
|
||||
|
||||
void PlayerEditBoxServiceWin::showSingleLineEditBox(const cocos2d::Rect &rect)
|
||||
{
|
||||
MoveWindow(_hwndSingle, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, TRUE);
|
||||
ShowWindow(_hwndSingle, SW_SHOW);
|
||||
SetFocus(_hwndSingle);
|
||||
}
|
||||
|
||||
void PlayerEditBoxServiceWin::showMultiLineEditBox(const cocos2d::Rect &rect)
|
||||
{
|
||||
MoveWindow(_hwndMulti, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, TRUE);
|
||||
ShowWindow(_hwndMulti, SW_SHOW);
|
||||
SetFocus(_hwndMulti);
|
||||
}
|
||||
|
||||
void PlayerEditBoxServiceWin::hide()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerEditBoxServiceWin::setText(const std::string &text)
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerEditBoxServiceWin::setFont(const std::string &name, int size)
|
||||
{
|
||||
removeFont();
|
||||
|
||||
std::u16string u16name;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(name, u16name);
|
||||
|
||||
HDC hdc = GetDC(_hwnd);
|
||||
size = -MulDiv(size, GetDeviceCaps(hdc, LOGPIXELSY), 72);
|
||||
ReleaseDC(_hwnd, hdc);
|
||||
|
||||
_hfont = CreateFont(size, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
0, OUT_DEFAULT_PRECIS, FW_NORMAL, DEFAULT_QUALITY, DEFAULT_PITCH,
|
||||
(LPCTSTR)u16name.c_str());
|
||||
if (!_hfont)
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
CCLOG("PlayerEditBoxServiceWin::setFont() - create HFONT for font \"%s\" failed, error code = 0x%08x",
|
||||
name.c_str(), err);
|
||||
}
|
||||
else
|
||||
{
|
||||
SendMessage(_hwndSingle, WM_SETFONT, (WPARAM)_hfont, NULL);
|
||||
SendMessage(_hwndMulti, WM_SETFONT, (WPARAM)_hfont, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerEditBoxServiceWin::setFontColor(const cocos2d::Color3B &color)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PlayerEditBoxServiceWin::removeFont()
|
||||
{
|
||||
if (_hfont)
|
||||
{
|
||||
SendMessage(_hwndSingle, WM_SETFONT, NULL, NULL);
|
||||
SendMessage(_hwndMulti, WM_SETFONT, NULL, NULL);
|
||||
DeleteObject(_hfont);
|
||||
}
|
||||
_hfont = NULL;
|
||||
}
|
||||
|
||||
void PlayerEditBoxServiceWin::setFormator(int /*formator*/ )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PLAYER_NS_END
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
#ifndef __PLAYER_EDITBOX_SERVICE_WIN_H_
|
||||
#define __PLAYER_EDITBOX_SERVICE_WIN_H_
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "PlayerEditBoxServiceProtocol.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
class PlayerEditBoxServiceWin : public PlayerEditBoxServiceProtocol
|
||||
{
|
||||
public:
|
||||
PlayerEditBoxServiceWin(HWND hwnd);
|
||||
virtual ~PlayerEditBoxServiceWin();
|
||||
|
||||
virtual void showSingleLineEditBox(const cocos2d::Rect &rect);
|
||||
virtual void showMultiLineEditBox(const cocos2d::Rect &rect);
|
||||
virtual void hide();
|
||||
|
||||
virtual void setText(const std::string &text);
|
||||
virtual void setFont(const std::string &name, int size);
|
||||
virtual void setFontColor(const cocos2d::Color3B &color);
|
||||
|
||||
virtual void setFormator(int formator);
|
||||
protected:
|
||||
HWND _hwnd;
|
||||
HWND _hwndSingle;
|
||||
HWND _hwndMulti;
|
||||
HFONT _hfont;
|
||||
|
||||
void removeFont();
|
||||
};
|
||||
|
||||
PLAYER_NS_END
|
||||
|
||||
#endif // __PLAYER_EDITBOX_SERVICE_WIN_H_
|
|
@ -1,265 +0,0 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <Windowsx.h>
|
||||
#include <Shlobj.h>
|
||||
#include <Commdlg.h>
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "PlayerUtils.h"
|
||||
#include "PlayerFileDialogServiceWin.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
PlayerFileDialogServiceWin::PlayerFileDialogServiceWin(HWND hwnd)
|
||||
: _hwnd(hwnd)
|
||||
{
|
||||
}
|
||||
|
||||
std::string PlayerFileDialogServiceWin::openFile(const std::string &title,
|
||||
const std::string &directory,
|
||||
const std::string &extensions) const
|
||||
{
|
||||
vector<std::string> result = openMultipleInternal(title, directory, extensions, false);
|
||||
if (result.size())
|
||||
{
|
||||
return result.at(0);
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::vector<std::string> PlayerFileDialogServiceWin::openMultiple(const std::string &title,
|
||||
const std::string &directory,
|
||||
const std::string &extensions) const
|
||||
{
|
||||
return openMultipleInternal(title, directory, extensions, true);
|
||||
}
|
||||
|
||||
std::string PlayerFileDialogServiceWin::saveFile(const std::string &title,
|
||||
const std::string &path) const
|
||||
{
|
||||
std::u16string u16title;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(title, u16title);
|
||||
|
||||
WCHAR buff[MAX_PATH + 1] = {0};
|
||||
if (path.length() > 0)
|
||||
{
|
||||
std::u16string u16filename;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(path, u16filename);
|
||||
wcscpy_s(buff, (WCHAR*)u16filename.c_str());
|
||||
}
|
||||
|
||||
OPENFILENAME ofn = {0};
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = _hwnd;
|
||||
ofn.lpstrFilter = L"All Files (*.*)\0*.*\0";
|
||||
ofn.lpstrTitle = (LPCTSTR)u16title.c_str();
|
||||
ofn.Flags = OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES;
|
||||
ofn.lpstrFile = buff;
|
||||
ofn.nMaxFile = MAX_PATH;
|
||||
|
||||
std::string result;
|
||||
if (!GetSaveFileName(&ofn))
|
||||
{
|
||||
// user cancel dialog, GetSaveFileName() will return FALSE
|
||||
DWORD err = CommDlgExtendedError();
|
||||
if (err)
|
||||
{
|
||||
CCLOG("PlayerFileDialogServiceWin::saveFile() - failed, title (%s), error code = %u", title.c_str(), err);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
cocos2d::StringUtils::UTF16ToUTF8((char16_t*)buff, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// for openDirectory
|
||||
int CALLBACK BrowseFolderCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
|
||||
{
|
||||
if (uMsg == BFFM_INITIALIZED && lpData)
|
||||
{
|
||||
LPCTSTR path = (LPCTSTR)lpData;
|
||||
SendMessage(hwnd, BFFM_SETSELECTION, true, (LPARAM)path);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string PlayerFileDialogServiceWin::openDirectory(const std::string &title,
|
||||
const std::string &directory) const
|
||||
{
|
||||
std::u16string u16title;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(title, u16title);
|
||||
|
||||
WCHAR basedir[MAX_PATH + 1];
|
||||
if (directory.length())
|
||||
{
|
||||
std::u16string u16directory;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(directory, u16directory);
|
||||
wcscpy_s(basedir, (WCHAR*)u16directory.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCurrentDirectory(MAX_PATH, basedir);
|
||||
}
|
||||
|
||||
WCHAR buff[MAX_PATH + 1] = {0};
|
||||
BROWSEINFO bi = {0};
|
||||
bi.hwndOwner = _hwnd;
|
||||
bi.pszDisplayName = buff;
|
||||
bi.lpszTitle = (LPCTSTR)u16title.c_str();
|
||||
bi.lParam = (LPARAM)basedir;
|
||||
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NONEWFOLDERBUTTON | BIF_NEWDIALOGSTYLE;
|
||||
bi.lpfn = BrowseFolderCallback;
|
||||
|
||||
PIDLIST_ABSOLUTE pid = SHBrowseForFolder(&bi);
|
||||
if (pid)
|
||||
{
|
||||
SHGetPathFromIDList(pid, buff);
|
||||
std::string result;
|
||||
cocos2d::StringUtils::UTF16ToUTF8((char16_t*)buff, result);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::string("");
|
||||
}
|
||||
}
|
||||
|
||||
LPTSTR PlayerFileDialogServiceWin::parseExtensions(const std::string &extensions) const
|
||||
{
|
||||
static WCHAR *defaultExtensions = L"All Files (*.*)\0*.*\0";
|
||||
if (extensions.length() == 0)
|
||||
{
|
||||
WCHAR *buff = new WCHAR[wcslen(defaultExtensions) + 1];
|
||||
wcscpy(buff, defaultExtensions);
|
||||
return buff;
|
||||
}
|
||||
|
||||
// "Lua Script File|*.lua;JSON File|*.json"
|
||||
// to
|
||||
// "Lua Script File (*.lua)\0*.lua\0JSON File (*.json)\0*.json\0";
|
||||
std::u16string u16extensions;
|
||||
std::u16string split1((char16_t*)L";");
|
||||
std::u16string split2((char16_t*)L"|");
|
||||
cocos2d::StringUtils::UTF8ToUTF16(extensions, u16extensions);
|
||||
vector<std::u16string> pairs = splitString(u16extensions, split1);
|
||||
|
||||
size_t buffsize = extensions.length() * 6;
|
||||
WCHAR *buff = new WCHAR[buffsize];
|
||||
memset(buff, 0, sizeof(WCHAR) * buffsize);
|
||||
size_t offset = 0;
|
||||
for (auto it = pairs.begin(); it != pairs.end(); ++it)
|
||||
{
|
||||
vector<std::u16string> p = splitString(*it, split2);
|
||||
std::u16string descr, ext;
|
||||
if (p.size() < 2)
|
||||
{
|
||||
descr = ext = *it;
|
||||
}
|
||||
else
|
||||
{
|
||||
descr = p.at(0);
|
||||
ext = p.at(1);
|
||||
}
|
||||
|
||||
wcscat(buff + offset, (WCHAR*)descr.c_str());
|
||||
wcscat(buff + offset, L" (");
|
||||
wcscat(buff + offset, (WCHAR*)ext.c_str());
|
||||
wcscat(buff + offset, L")");
|
||||
offset += descr.length() + ext.length() + 4;
|
||||
wcscat(buff + offset, (WCHAR*)ext.c_str());
|
||||
offset += ext.length() + 1;
|
||||
}
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
std::vector<std::string> PlayerFileDialogServiceWin::openMultipleInternal(const std::string &title,
|
||||
const std::string &directory,
|
||||
const std::string &extensions,
|
||||
bool isMulti) const
|
||||
{
|
||||
std::u16string u16title;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(title, u16title);
|
||||
|
||||
WCHAR basedir[MAX_PATH + 1];
|
||||
if (directory.length())
|
||||
{
|
||||
std::u16string u16directory;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(directory, u16directory);
|
||||
wcscpy_s(basedir, (WCHAR*)u16directory.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCurrentDirectory(MAX_PATH, basedir);
|
||||
}
|
||||
|
||||
size_t buffsize = MAX_PATH;
|
||||
if (isMulti) buffsize = MAX_PATH * 64;
|
||||
WCHAR *buff = new WCHAR[buffsize + 1];
|
||||
memset(buff, 0, sizeof(WCHAR) * (buffsize + 1));
|
||||
|
||||
OPENFILENAME ofn = {0};
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = _hwnd;
|
||||
ofn.lpstrFilter = parseExtensions(extensions);
|
||||
ofn.lpstrTitle = (LPCTSTR)u16title.c_str();
|
||||
ofn.lpstrInitialDir = basedir;
|
||||
ofn.Flags = OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES;
|
||||
if (isMulti) ofn.Flags |= OFN_ALLOWMULTISELECT | OFN_EXPLORER;
|
||||
ofn.lpstrFile = buff;
|
||||
ofn.nMaxFile = buffsize;
|
||||
|
||||
vector<std::string> result;
|
||||
BOOL ret = GetOpenFileName(&ofn);
|
||||
delete[] ofn.lpstrFilter;
|
||||
if (!ret)
|
||||
{
|
||||
// user cancel dialog, GetOpenFileName() will return FALSE
|
||||
DWORD err = CommDlgExtendedError();
|
||||
if (err)
|
||||
{
|
||||
CCLOG("PlayerFileDialogServiceWin::openMultipleInternal() - failed, title (%s), error code = %u", title.c_str(), err);
|
||||
}
|
||||
delete[] buff;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (isMulti)
|
||||
{
|
||||
WORD offset = 0;
|
||||
std::string path;
|
||||
while (buff[offset] != '\0')
|
||||
{
|
||||
std::string filename;
|
||||
std::u16string u16filename((char16_t*)(buff + offset));
|
||||
cocos2d::StringUtils::UTF16ToUTF8(u16filename, filename);
|
||||
|
||||
if (offset == 0)
|
||||
{
|
||||
path = filename;
|
||||
if (path[path.length() - 1] != '\\')
|
||||
{
|
||||
path.append("\\");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.push_back(path + filename);
|
||||
}
|
||||
offset += u16filename.length() + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string path;
|
||||
cocos2d::StringUtils::UTF16ToUTF8((char16_t*)buff, path);
|
||||
result.push_back(path);
|
||||
}
|
||||
delete[] buff;
|
||||
return result;
|
||||
}
|
||||
|
||||
PLAYER_NS_END
|
|
@ -1,38 +0,0 @@
|
|||
|
||||
#ifndef __PLAYER_FILE_DIALOG_SERVICE_WIN_H_
|
||||
#define __PLAYER_FILE_DIALOG_SERVICE_WIN_H_
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "PlayerFileDialogServiceProtocol.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
class PlayerFileDialogServiceWin : public PlayerFileDialogServiceProtocol
|
||||
{
|
||||
public:
|
||||
PlayerFileDialogServiceWin(HWND hwnd);
|
||||
|
||||
virtual std::string openFile(const std::string &title,
|
||||
const std::string &directory,
|
||||
const std::string &extensions) const;
|
||||
virtual std::vector<std::string> openMultiple(const std::string &title,
|
||||
const std::string &directory,
|
||||
const std::string &extensions) const;
|
||||
virtual std::string saveFile(const std::string &title,
|
||||
const std::string &path) const;
|
||||
virtual std::string openDirectory(const std::string &title,
|
||||
const std::string &directory) const;
|
||||
|
||||
protected:
|
||||
HWND _hwnd;
|
||||
|
||||
LPTSTR parseExtensions(const std::string &extensions) const;
|
||||
vector<std::string> openMultipleInternal(const std::string &title,
|
||||
const std::string &directory,
|
||||
const std::string &extensions,
|
||||
bool isMulti) const;
|
||||
};
|
||||
|
||||
PLAYER_NS_END
|
||||
|
||||
#endif // __PLAYER_FILE_DIALOG_SERVICE_WIN_H_
|
|
@ -1,351 +0,0 @@
|
|||
|
||||
#include "PlayerMenuServiceWin.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
PlayerMenuItemWin *PlayerMenuItemWin::create(const std::string &menuId, const std::string &title)
|
||||
{
|
||||
PlayerMenuItemWin *item = new PlayerMenuItemWin();
|
||||
item->_menuId = menuId;
|
||||
item->_title = title;
|
||||
item->autorelease();
|
||||
return item;
|
||||
}
|
||||
|
||||
PlayerMenuItemWin::PlayerMenuItemWin()
|
||||
: _parent(nullptr)
|
||||
, _commandId(0)
|
||||
, _hmenu(NULL)
|
||||
, _menubarEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
PlayerMenuItemWin::~PlayerMenuItemWin()
|
||||
{
|
||||
CC_SAFE_RELEASE(_parent);
|
||||
if (_hmenu)
|
||||
{
|
||||
CCLOG("PlayerMenuItemWin::~PlayerMenuItemWin() - %s (HMENU)", _menuId.c_str());
|
||||
DestroyMenu(_hmenu);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("PlayerMenuItemWin::~PlayerMenuItemWin() - %s", _menuId.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMenuItemWin::setTitle(const std::string &title)
|
||||
{
|
||||
if (title.length() == 0)
|
||||
{
|
||||
CCLOG("MenuServiceWin::setTitle() - can not set menu title to empty, menu id (%s)", _menuId.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
MENUITEMINFO menuitem;
|
||||
menuitem.cbSize = sizeof(menuitem);
|
||||
menuitem.fMask = MIIM_FTYPE | MIIM_STRING;
|
||||
menuitem.fType = (title.compare("-") == 0) ? MFT_SEPARATOR : MFT_STRING;
|
||||
std::u16string u16title;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(title, u16title);
|
||||
menuitem.dwTypeData = (LPTSTR)u16title.c_str();
|
||||
if (SetMenuItemInfo(_parent->_hmenu, _commandId, MF_BYCOMMAND, &menuitem))
|
||||
{
|
||||
_title = title;
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
CCLOG("MenuServiceWin::setTitle() - set menu title failed, menu id (%s). error code = %u", _menuId.c_str(), err);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMenuItemWin::setEnabled(bool enabled)
|
||||
{
|
||||
MENUITEMINFO menuitem = {0};
|
||||
menuitem.cbSize = sizeof(menuitem);
|
||||
menuitem.fMask = MIIM_STATE;
|
||||
menuitem.fState = (enabled && _menubarEnabled) ? MFS_ENABLED : MFS_DISABLED;
|
||||
if (SetMenuItemInfo(_parent->_hmenu, _commandId, MF_BYCOMMAND, &menuitem))
|
||||
{
|
||||
_isEnabled = enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
CCLOG("MenuServiceWin::setEnabled() - set menu enabled failed, menu id (%s). error code = %u", _menuId.c_str(), err);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMenuItemWin::setChecked(bool checked)
|
||||
{
|
||||
MENUITEMINFO menuitem;
|
||||
menuitem.cbSize = sizeof(menuitem);
|
||||
menuitem.fMask = MIIM_STATE;
|
||||
menuitem.fState = (checked) ? MFS_CHECKED : MFS_UNCHECKED;
|
||||
if (SetMenuItemInfo(_parent->_hmenu, _commandId, MF_BYCOMMAND, &menuitem))
|
||||
{
|
||||
_isChecked = checked;
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
CCLOG("MenuServiceWin::setChecked() - set menu checked failed, menu id (%s). error code = %u", _menuId.c_str(), err);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMenuItemWin::setShortcut(const std::string &shortcut)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// MenuServiceWin
|
||||
|
||||
WORD PlayerMenuServiceWin::_newCommandId = 0x1000;
|
||||
|
||||
PlayerMenuServiceWin::PlayerMenuServiceWin(HWND hwnd)
|
||||
: _hwnd(hwnd)
|
||||
, _menubarEnabled(true)
|
||||
{
|
||||
// create menu
|
||||
_root._menuId = "__ROOT__";
|
||||
_root._commandId = 0;
|
||||
|
||||
// hwnd has menu
|
||||
HMENU menu = GetMenu(hwnd);
|
||||
if (menu)
|
||||
{
|
||||
_root._hmenu = menu;
|
||||
}
|
||||
else
|
||||
{
|
||||
_root._hmenu = CreateMenu();
|
||||
SetMenu(hwnd, _root._hmenu);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerMenuServiceWin::~PlayerMenuServiceWin()
|
||||
{
|
||||
}
|
||||
|
||||
PlayerMenuItem *PlayerMenuServiceWin::addItem(const std::string &menuId,
|
||||
const std::string &title,
|
||||
const std::string &parentId,
|
||||
int order /* = MAX_ORDER */)
|
||||
{
|
||||
if (menuId.length() == 0 || title.length() == 0)
|
||||
{
|
||||
CCLOG("MenuServiceWin::addItem() - menuId and title must is non-empty");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// check menu id is exists
|
||||
if (_items.find(menuId) != _items.end())
|
||||
{
|
||||
CCLOG("MenuServiceWin::addItem() - menu id (%s) is exists", menuId.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// set parent
|
||||
PlayerMenuItemWin *parent = &_root;
|
||||
if (parentId.length())
|
||||
{
|
||||
// query parent menu
|
||||
auto it = _items.find(parentId);
|
||||
if (it != _items.end())
|
||||
{
|
||||
parent = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parent->_hmenu)
|
||||
{
|
||||
// create menu handle for parent (convert parent to submenu)
|
||||
parent->_hmenu = CreateMenu();
|
||||
parent->_isGroup = true;
|
||||
MENUITEMINFO menuitem;
|
||||
menuitem.cbSize = sizeof(menuitem);
|
||||
menuitem.fMask = MIIM_SUBMENU;
|
||||
menuitem.hSubMenu = parent->_hmenu;
|
||||
if (!SetMenuItemInfo(parent->_parent->_hmenu, parent->_commandId, MF_BYCOMMAND, &menuitem))
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
CCLOG("MenuServiceWin::addItem() - set menu handle failed, menu id (%s). error code = %u", parent->_menuId.c_str(), err);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// create new menu item
|
||||
_newCommandId++;
|
||||
PlayerMenuItemWin *item = PlayerMenuItemWin::create(menuId, title);
|
||||
item->_commandId = _newCommandId;
|
||||
item->_parent = parent;
|
||||
item->_parent->retain();
|
||||
|
||||
// add menu item to menu bar
|
||||
MENUITEMINFO menuitem;
|
||||
menuitem.cbSize = sizeof(menuitem);
|
||||
menuitem.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE | MIIM_STRING;
|
||||
menuitem.fType = (item->_title.compare("-") == 0) ? MFT_SEPARATOR : MFT_STRING;
|
||||
menuitem.fState = (item->_isEnabled) ? MFS_ENABLED : MFS_DISABLED;
|
||||
menuitem.fState |= (item->_isChecked) ? MFS_CHECKED : MFS_UNCHECKED;
|
||||
std::u16string u16title;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(item->_title, u16title);
|
||||
menuitem.dwTypeData = (LPTSTR)u16title.c_str();
|
||||
menuitem.wID = _newCommandId;
|
||||
|
||||
// check new menu item position
|
||||
if (order > parent->_children.size())
|
||||
{
|
||||
order = parent->_children.size();
|
||||
}
|
||||
else if (order < 0)
|
||||
{
|
||||
order = 0;
|
||||
}
|
||||
|
||||
// create new menu item
|
||||
if (!InsertMenuItem(parent->_hmenu, order, TRUE, &menuitem))
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
CCLOG("MenuServiceWin::addItem() - insert new menu item failed, menu id (%s). error code = %u", item->_menuId.c_str(), err);
|
||||
item->release();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// update menu state
|
||||
parent->_children.insert(order, item);
|
||||
_items[item->_menuId] = item;
|
||||
_commandId2menuId[item->_commandId] = item->_menuId;
|
||||
updateChildrenOrder(parent);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
PlayerMenuItem *PlayerMenuServiceWin::addItem(const std::string &menuId,
|
||||
const std::string &title)
|
||||
{
|
||||
return addItem(menuId, title, "");
|
||||
}
|
||||
|
||||
PlayerMenuItem *PlayerMenuServiceWin::getItem(const std::string &menuId)
|
||||
{
|
||||
auto it = _items.find(menuId);
|
||||
if (it == _items.end())
|
||||
{
|
||||
CCLOG("MenuServiceWin::getItem() - Invalid menu id (%s)", menuId.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool PlayerMenuServiceWin::removeItem(const std::string &menuId)
|
||||
{
|
||||
return removeItemInternal(menuId, true);
|
||||
}
|
||||
|
||||
void PlayerMenuServiceWin::setMenuBarEnabled(bool enabled)
|
||||
{
|
||||
_menubarEnabled = enabled;
|
||||
|
||||
UINT state = enabled ? MFS_ENABLED : MFS_DISABLED;
|
||||
for (auto it = _root._children.begin(); it != _root._children.end(); ++it)
|
||||
{
|
||||
PlayerMenuItemWin *item = *it;
|
||||
MENUITEMINFO menuitem = {0};
|
||||
menuitem.cbSize = sizeof(menuitem);
|
||||
menuitem.fMask = MIIM_STATE;
|
||||
menuitem.fState = state;
|
||||
SetMenuItemInfo(item->_parent->_hmenu, item->_commandId, MF_BYCOMMAND, &menuitem);
|
||||
item->_menubarEnabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerMenuItemWin *PlayerMenuServiceWin::getItemByCommandId(WORD commandId)
|
||||
{
|
||||
auto it = _commandId2menuId.find(commandId);
|
||||
if (it == _commandId2menuId.end()) return nullptr;
|
||||
return _items[it->second];
|
||||
}
|
||||
|
||||
bool PlayerMenuServiceWin::removeItemInternal(const std::string &menuId, bool isUpdateChildrenOrder)
|
||||
{
|
||||
auto it = _items.find(menuId);
|
||||
if (it == _items.end())
|
||||
{
|
||||
CCLOG("MenuServiceWin::removeItem() - Invalid menu id (%s)", menuId.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerMenuItemWin *item = it->second;
|
||||
if (item->_children.size() == 0)
|
||||
{
|
||||
if (!DeleteMenu(item->_parent->_hmenu, item->_commandId, MF_BYCOMMAND))
|
||||
{
|
||||
DWORD err = GetLastError();
|
||||
CCLOG("MenuServiceWin::removeItem() - remove menu item failed, menu id (%s). error code = %u", item->_menuId.c_str(), err);
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove item from parent
|
||||
bool removed = false;
|
||||
auto *children = &item->_parent->_children;
|
||||
for (auto it = children->begin(); it != children->end(); ++it)
|
||||
{
|
||||
if ((*it)->_commandId == item->_commandId)
|
||||
{
|
||||
CCLOG("MenuServiceWin::removeItem() - remove menu item (%s)", item->_menuId.c_str());
|
||||
children->erase(it);
|
||||
removed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!removed)
|
||||
{
|
||||
CCLOG("MenuServiceWin::removeItem() - remove menu item (%s) failed, not found command id from parent->children", item->_menuId.c_str());
|
||||
}
|
||||
|
||||
// remove menu id mapping
|
||||
_items.erase(menuId);
|
||||
_commandId2menuId.erase(item->_commandId);
|
||||
if (isUpdateChildrenOrder)
|
||||
{
|
||||
updateChildrenOrder(item->_parent);
|
||||
}
|
||||
DrawMenuBar(_hwnd);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove all children
|
||||
while (item->_children.size() != 0)
|
||||
{
|
||||
PlayerMenuItemWin *child = *item->_children.begin();
|
||||
if (!removeItemInternal(child->_menuId.c_str(), false))
|
||||
{
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return removeItemInternal(menuId, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PlayerMenuServiceWin::updateChildrenOrder(PlayerMenuItemWin *parent)
|
||||
{
|
||||
auto *children = &parent->_children;
|
||||
int order = 0;
|
||||
for (auto it = children->begin(); it != children->end(); ++it)
|
||||
{
|
||||
(*it)->_order = order;
|
||||
order++;
|
||||
}
|
||||
}
|
||||
|
||||
PLAYER_NS_END
|
|
@ -1,70 +0,0 @@
|
|||
|
||||
#ifndef __PLAYER_MENU_SERVICE_WIN_H_
|
||||
#define __PLAYER_MENU_SERVICE_WIN_H_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "stdafx.h"
|
||||
#include "PlayerMenuServiceProtocol.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
class PlayerMenuItemWin : public PlayerMenuItem
|
||||
{
|
||||
public:
|
||||
static PlayerMenuItemWin *create(const std::string &menuId, const std::string &title);
|
||||
virtual ~PlayerMenuItemWin();
|
||||
|
||||
virtual void setTitle(const std::string &title);
|
||||
virtual void setEnabled(bool enabled);
|
||||
virtual void setChecked(bool checked);
|
||||
virtual void setShortcut(const std::string &shortcut);
|
||||
|
||||
protected:
|
||||
PlayerMenuItemWin();
|
||||
|
||||
PlayerMenuItemWin *_parent;
|
||||
UINT _commandId;
|
||||
HMENU _hmenu;
|
||||
bool _menubarEnabled;
|
||||
cocos2d::Vector<PlayerMenuItemWin*> _children;
|
||||
|
||||
friend class PlayerMenuServiceWin;
|
||||
};
|
||||
|
||||
class PlayerMenuServiceWin : public PlayerMenuServiceProtocol
|
||||
{
|
||||
public:
|
||||
PlayerMenuServiceWin(HWND hwnd);
|
||||
virtual ~PlayerMenuServiceWin();
|
||||
|
||||
virtual PlayerMenuItem *addItem(const std::string &menuId,
|
||||
const std::string &title,
|
||||
const std::string &parentId,
|
||||
int order = MAX_ORDER);
|
||||
virtual PlayerMenuItem *addItem(const std::string &menuId,
|
||||
const std::string &title);
|
||||
virtual PlayerMenuItem *getItem(const std::string &menuId);
|
||||
virtual bool removeItem(const std::string &menuId);
|
||||
virtual void setMenuBarEnabled(bool enabled);
|
||||
|
||||
PlayerMenuItemWin *getItemByCommandId(WORD commandId);
|
||||
|
||||
private:
|
||||
static WORD _newCommandId;
|
||||
|
||||
HWND _hwnd;
|
||||
bool _menubarEnabled;
|
||||
PlayerMenuItemWin _root;
|
||||
std::unordered_map<std::string, PlayerMenuItemWin*> _items;
|
||||
std::unordered_map<WORD, std::string> _commandId2menuId;
|
||||
|
||||
bool removeItemInternal(const std::string &menuId, bool isUpdateChildrenOrder);
|
||||
void updateChildrenOrder(PlayerMenuItemWin *parent);
|
||||
};
|
||||
|
||||
PLAYER_NS_END
|
||||
|
||||
#endif // __PLAYER_MENU_SERVICE_WIN_H_
|
|
@ -1,67 +0,0 @@
|
|||
|
||||
#include "PlayerMessageBoxServiceWin.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
PlayerMessageBoxServiceWin::PlayerMessageBoxServiceWin(HWND hwnd)
|
||||
: _hwnd(hwnd)
|
||||
{
|
||||
}
|
||||
|
||||
int PlayerMessageBoxServiceWin::showMessageBox(const std::string &title,
|
||||
const std::string &message,
|
||||
int buttonsType /* = BUTTONS_OK */)
|
||||
{
|
||||
std::u16string u16title;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(title, u16title);
|
||||
std::u16string u16message;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(message, u16message);
|
||||
|
||||
CCLOG("PlayerMessageBoxServiceWin::showMessageBox() - title = %s, message = %s", title.c_str(), message.c_str());
|
||||
|
||||
UINT mbtype = MB_APPLMODAL;
|
||||
switch (buttonsType)
|
||||
{
|
||||
case BUTTONS_OK_CANCEL:
|
||||
mbtype |= MB_OKCANCEL | MB_ICONQUESTION;
|
||||
break;
|
||||
|
||||
case BUTTONS_YES_NO:
|
||||
mbtype |= MB_YESNO | MB_ICONQUESTION;
|
||||
break;
|
||||
|
||||
case BUTTONS_YES_NO_CANCEL:
|
||||
mbtype |= MB_YESNOCANCEL | MB_ICONQUESTION;
|
||||
break;
|
||||
|
||||
default:
|
||||
mbtype |= MB_OK | MB_ICONINFORMATION;
|
||||
}
|
||||
|
||||
// MessageBox() used by cocos2d
|
||||
int result = ::MessageBoxW(_hwnd, (LPCTSTR)u16message.c_str(), (LPCTSTR)u16title.c_str(), mbtype);
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case IDCANCEL:
|
||||
result = BUTTON_CANCEL;
|
||||
break;
|
||||
|
||||
case IDYES:
|
||||
result = BUTTON_YES;
|
||||
break;
|
||||
|
||||
case IDNO:
|
||||
result = BUTTON_NO;
|
||||
break;
|
||||
|
||||
default:
|
||||
result = BUTTON_OK;
|
||||
}
|
||||
|
||||
CCLOG("PlayerMessageBoxServiceWin::showMessageBox() - result = %d", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PLAYER_NS_END
|
|
@ -1,28 +0,0 @@
|
|||
|
||||
#ifndef __PLAYER_MESSAGEBOX_SERVICE_WIN_H_
|
||||
#define __PLAYER_MESSAGEBOX_SERVICE_WIN_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "cocos2d.h"
|
||||
#include "PlayerMessageBoxServiceProtocol.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
class PlayerMessageBoxServiceWin : public PlayerMessageBoxServiceProtocol
|
||||
{
|
||||
public:
|
||||
PlayerMessageBoxServiceWin(HWND hwnd);
|
||||
|
||||
virtual int showMessageBox(const std::string &title,
|
||||
const std::string &message,
|
||||
int buttonsType = BUTTONS_OK);
|
||||
|
||||
protected:
|
||||
HWND _hwnd;
|
||||
};
|
||||
|
||||
PLAYER_NS_END
|
||||
|
||||
#endif // __PLAYER_MESSAGEBOX_SERVICE_WIN_H_
|
|
@ -1,272 +0,0 @@
|
|||
|
||||
#include <sstream>
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "shellapi.h"
|
||||
#include "PlayerTaskServiceWin.h"
|
||||
|
||||
static const int MAX_LOG_LENGTH = 16 * 1024;// from 2dx
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
PlayerTaskWin *PlayerTaskWin::create(const std::string &name, const std::string &executePath, const std::string &commandLineArguments)
|
||||
{
|
||||
PlayerTaskWin *task = new PlayerTaskWin(name, executePath, commandLineArguments);
|
||||
task->autorelease();
|
||||
return task;
|
||||
}
|
||||
|
||||
PlayerTaskWin::PlayerTaskWin(const std::string &name,
|
||||
const std::string &executePath,
|
||||
const std::string &commandLineArguments)
|
||||
: PlayerTask(name, executePath, commandLineArguments)
|
||||
, _childStdInRead(NULL)
|
||||
, _childStdInWrite(NULL)
|
||||
, _childStdOutRead(NULL)
|
||||
, _childStdOutWrite(NULL)
|
||||
, _outputBuff(NULL)
|
||||
, _outputBuffWide(NULL)
|
||||
{
|
||||
ZeroMemory(&_pi, sizeof(_pi));
|
||||
}
|
||||
|
||||
PlayerTaskWin::~PlayerTaskWin()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
bool PlayerTaskWin::run()
|
||||
{
|
||||
if (!isIdle())
|
||||
{
|
||||
CCLOG("PlayerTaskWin::run() - task is not idle");
|
||||
return false;
|
||||
}
|
||||
|
||||
//BOOL WINAPI CreateProcess(
|
||||
// _In_opt_ LPCTSTR lpApplicationName,
|
||||
// _Inout_opt_ LPTSTR lpCommandLine,
|
||||
// _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
// _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
||||
// _In_ BOOL bInheritHandles,
|
||||
// _In_ DWORD dwCreationFlags,
|
||||
// _In_opt_ LPVOID lpEnvironment,
|
||||
// _In_opt_ LPCTSTR lpCurrentDirectory,
|
||||
// _In_ LPSTARTUPINFO lpStartupInfo,
|
||||
// _Out_ LPPROCESS_INFORMATION lpProcessInformation
|
||||
//);
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
|
||||
SECURITY_ATTRIBUTES sa = {0};
|
||||
sa.nLength = sizeof(sa);
|
||||
sa.bInheritHandle = TRUE;
|
||||
|
||||
// Create a pipe for the child process's STDOUT.
|
||||
if (!CreatePipe(&_childStdOutRead, &_childStdOutWrite, &sa, 0) || !SetHandleInformation(_childStdOutRead, HANDLE_FLAG_INHERIT, 0))
|
||||
{
|
||||
CCLOG("PlayerTaskWin::run() - create stdout handle failed, for execute %s", _executePath.c_str());
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create a pipe for the child process's STDIN.
|
||||
if (!CreatePipe(&_childStdInRead, &_childStdInWrite, &sa, 0) || !SetHandleInformation(_childStdInWrite, HANDLE_FLAG_INHERIT, 0))
|
||||
{
|
||||
CCLOG("PlayerTaskWin::run() - create stdout handle failed, for execute %s", _executePath.c_str());
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
ZeroMemory(&_pi, sizeof(_pi));
|
||||
STARTUPINFO si = {0};
|
||||
|
||||
si.cb = sizeof(STARTUPINFO);
|
||||
si.hStdError = _childStdOutWrite;
|
||||
si.hStdOutput = _childStdOutWrite;
|
||||
si.hStdInput = _childStdInRead;
|
||||
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
|
||||
si.wShowWindow = SW_HIDE;
|
||||
|
||||
#define MAX_COMMAND 4096 //MAX_PATH
|
||||
const std::u16string u16command = makeCommandLine();
|
||||
WCHAR command[MAX_COMMAND];
|
||||
wcscpy_s(command, MAX_COMMAND, (WCHAR*)u16command.c_str());
|
||||
|
||||
BOOL success = CreateProcess(NULL,
|
||||
command, // command line
|
||||
NULL, // process security attributes
|
||||
NULL, // primary thread security attributes
|
||||
TRUE, // handles are inherited
|
||||
0, // creation flags
|
||||
NULL, // use parent's environment
|
||||
NULL, // use parent's current directory
|
||||
&si, // STARTUPINFO pointer
|
||||
&_pi); // receives PROCESS_INFORMATION
|
||||
|
||||
if (!success)
|
||||
{
|
||||
CCLOG("PlayerTaskWin::run() - create process failed, for execute %s", _executePath.c_str());
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
_outputBuff = new CHAR[BUFF_SIZE + 1];
|
||||
_outputBuffWide = new WCHAR[BUFF_SIZE];
|
||||
_state = STATE_RUNNING;
|
||||
|
||||
cocos2d::Director::getInstance()->getScheduler()->scheduleUpdate(this, 0, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlayerTaskWin::runInTerminal()
|
||||
{
|
||||
std::stringstream buf;
|
||||
buf << "/K ";
|
||||
buf << _executePath;
|
||||
buf << " ";
|
||||
buf << _commandLineArguments;
|
||||
|
||||
std::u16string u16command;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(buf.str(), u16command);
|
||||
|
||||
ShellExecute(NULL, NULL, L"CMD.EXE", (WCHAR*)u16command.c_str(), NULL, SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
void PlayerTaskWin::stop()
|
||||
{
|
||||
if (_pi.hProcess)
|
||||
{
|
||||
TerminateProcess(_pi.hProcess, 0);
|
||||
_resultCode = -1;
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void PlayerTaskWin::update(float dt)
|
||||
{
|
||||
_lifetime += dt;
|
||||
|
||||
// read output
|
||||
for (;;)
|
||||
{
|
||||
DWORD readCount = 0;
|
||||
PeekNamedPipe(_childStdOutRead, NULL, NULL, NULL, &readCount, NULL);
|
||||
if (readCount == 0) break;
|
||||
if (_output.length() > MAX_LOG_LENGTH) break;
|
||||
|
||||
readCount = 0;
|
||||
ZeroMemory(_outputBuff, BUFF_SIZE + 1);
|
||||
BOOL success = ReadFile(_childStdOutRead, _outputBuff, BUFF_SIZE - 1, &readCount, NULL);
|
||||
if (!success || readCount == 0) break;
|
||||
|
||||
int chars = MultiByteToWideChar(CP_OEMCP, 0, _outputBuff, readCount, _outputBuffWide, BUFF_SIZE);
|
||||
if (chars)
|
||||
{
|
||||
ZeroMemory(_outputBuff, BUFF_SIZE + 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, _outputBuffWide, chars, _outputBuff, BUFF_SIZE + 1, 0, NULL);
|
||||
_output.append(_outputBuff);
|
||||
if (_output.length() > MAX_LOG_LENGTH) break;
|
||||
}
|
||||
}
|
||||
|
||||
// get child process exit code
|
||||
DWORD resultCode = 0;
|
||||
if (GetExitCodeProcess(_pi.hProcess, &resultCode))
|
||||
{
|
||||
if (resultCode == STILL_ACTIVE) return;
|
||||
_resultCode = (int)resultCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
// unexpected error
|
||||
_resultCode = (int)GetLastError();
|
||||
}
|
||||
|
||||
cocos2d::Director::getInstance()->getScheduler()->unscheduleAllForTarget(this);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void PlayerTaskWin::cleanup()
|
||||
{
|
||||
if (_pi.hProcess) CloseHandle(_pi.hProcess);
|
||||
if (_pi.hThread) CloseHandle(_pi.hThread);
|
||||
ZeroMemory(&_pi, sizeof(_pi));
|
||||
|
||||
if (_outputBuff) delete[] _outputBuff;
|
||||
_outputBuff = NULL;
|
||||
if (_outputBuffWide) delete[] _outputBuffWide;
|
||||
_outputBuffWide = NULL;
|
||||
|
||||
if (_childStdOutRead) CloseHandle(_childStdOutRead);
|
||||
if (_childStdOutWrite) CloseHandle(_childStdOutWrite);
|
||||
if (_childStdInRead) CloseHandle(_childStdInRead);
|
||||
if (_childStdInWrite) CloseHandle(_childStdInWrite);
|
||||
|
||||
_childStdOutRead = NULL;
|
||||
_childStdOutWrite = NULL;
|
||||
_childStdInRead = NULL;
|
||||
_childStdInWrite = NULL;
|
||||
|
||||
_state = STATE_COMPLETED;
|
||||
|
||||
CCLOG("CMD: %s", _output.c_str());
|
||||
|
||||
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(_name);
|
||||
}
|
||||
|
||||
std::u16string PlayerTaskWin::makeCommandLine() const
|
||||
{
|
||||
std::stringstream buf;
|
||||
buf << "\"";
|
||||
buf << _executePath;
|
||||
buf << "\" ";
|
||||
buf << _commandLineArguments;
|
||||
|
||||
std::u16string u16command;
|
||||
cocos2d::StringUtils::UTF8ToUTF16(buf.str(), u16command);
|
||||
return u16command;
|
||||
}
|
||||
|
||||
PlayerTaskServiceWin::PlayerTaskServiceWin(HWND hwnd)
|
||||
: _hwnd(hwnd)
|
||||
{
|
||||
}
|
||||
|
||||
PlayerTaskServiceWin::~PlayerTaskServiceWin()
|
||||
{
|
||||
for (auto it = _tasks.begin(); it != _tasks.end(); ++it)
|
||||
{
|
||||
it->second->stop();
|
||||
}
|
||||
}
|
||||
|
||||
PlayerTask *PlayerTaskServiceWin::createTask(const std::string &name,
|
||||
const std::string &executePath,
|
||||
const std::string &commandLineArguments)
|
||||
{
|
||||
CCASSERT(_tasks.find(name) == _tasks.end(), "Task already exists.");
|
||||
PlayerTaskWin *task = PlayerTaskWin::create(name, executePath, commandLineArguments);
|
||||
_tasks.insert(name, task);
|
||||
return task;
|
||||
}
|
||||
|
||||
PlayerTask *PlayerTaskServiceWin::getTask(const std::string &name)
|
||||
{
|
||||
auto it = _tasks.find(name);
|
||||
return it != _tasks.end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
void PlayerTaskServiceWin::removeTask(const std::string &name)
|
||||
{
|
||||
auto it = _tasks.find(name);
|
||||
if (it != _tasks.end())
|
||||
{
|
||||
if (!it->second->isCompleted())
|
||||
{
|
||||
it->second->stop();
|
||||
}
|
||||
_tasks.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
PLAYER_NS_END
|
|
@ -1,65 +0,0 @@
|
|||
|
||||
#ifndef __PLAYER_TASK_SERVICE_WIN_H_
|
||||
#define __PLAYER_TASK_SERVICE_WIN_H_
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "PlayerTaskServiceProtocol.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
class PlayerTaskWin : public PlayerTask
|
||||
{
|
||||
public:
|
||||
static PlayerTaskWin *create(const std::string &name,
|
||||
const std::string &executePath,
|
||||
const std::string &commandLineArguments);
|
||||
|
||||
virtual ~PlayerTaskWin();
|
||||
|
||||
virtual bool run();
|
||||
virtual void stop();
|
||||
virtual void runInTerminal();
|
||||
|
||||
// check task status
|
||||
virtual void update(float dt);
|
||||
|
||||
protected:
|
||||
PlayerTaskWin(const std::string &name,
|
||||
const std::string &executePath,
|
||||
const std::string &commandLineArguments);
|
||||
|
||||
void cleanup();
|
||||
std::u16string makeCommandLine() const;
|
||||
|
||||
HANDLE _childStdInRead;
|
||||
HANDLE _childStdInWrite;
|
||||
HANDLE _childStdOutRead;
|
||||
HANDLE _childStdOutWrite;
|
||||
PROCESS_INFORMATION _pi;
|
||||
|
||||
static const size_t BUFF_SIZE = 4096;
|
||||
CHAR *_outputBuff;
|
||||
WCHAR *_outputBuffWide;
|
||||
};
|
||||
|
||||
class PlayerTaskServiceWin : public PlayerTaskServiceProtocol
|
||||
{
|
||||
public:
|
||||
PlayerTaskServiceWin(HWND hwnd);
|
||||
virtual ~PlayerTaskServiceWin();
|
||||
|
||||
virtual PlayerTask *createTask(const std::string &name,
|
||||
const std::string &executePath,
|
||||
const std::string &commandLineArguments);
|
||||
virtual PlayerTask *getTask(const std::string &name);
|
||||
virtual void removeTask(const std::string &name);
|
||||
|
||||
protected:
|
||||
HWND _hwnd;
|
||||
cocos2d::Map<std::string, PlayerTaskWin*> _tasks;
|
||||
};
|
||||
|
||||
PLAYER_NS_END
|
||||
|
||||
#endif // __PLAYER_TASK_SERVICE_WIN_H_
|
|
@ -1,863 +0,0 @@
|
|||
|
||||
#pragma comment(lib, "comctl32.lib")
|
||||
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <io.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <Commdlg.h>
|
||||
#include <Shlobj.h>
|
||||
#include <winnls.h>
|
||||
#include <shobjidl.h>
|
||||
#include <objbase.h>
|
||||
#include <objidl.h>
|
||||
#include <shlguid.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
#include "PlayerWin.h"
|
||||
|
||||
#include "glfw3.h"
|
||||
#include "glfw3native.h"
|
||||
|
||||
#include "CCLuaEngine.h"
|
||||
#include "AppEvent.h"
|
||||
#include "AppLang.h"
|
||||
#include "ConfigParser.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
static WNDPROC g_oldWindowProc = NULL;
|
||||
INT_PTR CALLBACK AboutDialogCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(lParam);
|
||||
switch (message)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
return (INT_PTR)TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
||||
{
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (INT_PTR)FALSE;
|
||||
}
|
||||
void onHelpAbout()
|
||||
{
|
||||
DialogBox(GetModuleHandle(NULL),
|
||||
MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
|
||||
Director::getInstance()->getOpenGLView()->getWin32Window(),
|
||||
AboutDialogCallback);
|
||||
}
|
||||
|
||||
void shutDownApp()
|
||||
{
|
||||
auto glview = dynamic_cast<GLViewImpl*> (Director::getInstance()->getOpenGLView());
|
||||
HWND hWnd = glview->getWin32Window();
|
||||
::SendMessage(hWnd, WM_CLOSE, NULL, NULL);
|
||||
}
|
||||
|
||||
std::string getCurAppPath(void)
|
||||
{
|
||||
TCHAR szAppDir[MAX_PATH] = { 0 };
|
||||
if (!GetModuleFileName(NULL, szAppDir, MAX_PATH))
|
||||
return "";
|
||||
int nEnd = 0;
|
||||
for (int i = 0; szAppDir[i]; i++)
|
||||
{
|
||||
if (szAppDir[i] == '\\')
|
||||
nEnd = i;
|
||||
}
|
||||
szAppDir[nEnd] = 0;
|
||||
int iLen = 2 * wcslen(szAppDir);
|
||||
char* chRtn = new char[iLen + 1];
|
||||
wcstombs(chRtn, szAppDir, iLen + 1);
|
||||
std::string strPath = chRtn;
|
||||
delete[] chRtn;
|
||||
chRtn = NULL;
|
||||
char fuldir[MAX_PATH] = { 0 };
|
||||
_fullpath(fuldir, strPath.c_str(), MAX_PATH);
|
||||
return fuldir;
|
||||
}
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
PlayerWin *PlayerWin::_instance = nullptr;
|
||||
|
||||
PlayerWin::PlayerWin()
|
||||
: _app(nullptr)
|
||||
, _hwnd(NULL)
|
||||
, _hwndConsole(NULL)
|
||||
, _writeDebugLogFile(nullptr)
|
||||
, _messageBoxService(nullptr)
|
||||
, _menuService(nullptr)
|
||||
, _editboxService(nullptr)
|
||||
, _taskService(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
PlayerWin::~PlayerWin()
|
||||
{
|
||||
CC_SAFE_DELETE(_menuService);
|
||||
CC_SAFE_DELETE(_messageBoxService);
|
||||
CC_SAFE_DELETE(_fileDialogService);
|
||||
CC_SAFE_DELETE(_app);
|
||||
if (_writeDebugLogFile)
|
||||
{
|
||||
fclose(_writeDebugLogFile);
|
||||
}
|
||||
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
PlayerWin *PlayerWin::getInstance()
|
||||
{
|
||||
if (!_instance)
|
||||
{
|
||||
_instance = new PlayerWin();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
PlayerFileDialogServiceProtocol *PlayerWin::getFileDialogService()
|
||||
{
|
||||
return _fileDialogService;
|
||||
}
|
||||
|
||||
PlayerMessageBoxServiceProtocol *PlayerWin::getMessageBoxService()
|
||||
{
|
||||
return _messageBoxService;
|
||||
}
|
||||
|
||||
PlayerMenuServiceProtocol *PlayerWin::getMenuService()
|
||||
{
|
||||
return _menuService;
|
||||
}
|
||||
|
||||
PlayerEditBoxServiceProtocol *PlayerWin::getEditBoxService()
|
||||
{
|
||||
return _editboxService;
|
||||
}
|
||||
|
||||
PlayerTaskServiceProtocol *PlayerWin::getTaskService()
|
||||
{
|
||||
return _taskService;
|
||||
}
|
||||
|
||||
void PlayerWin::quit()
|
||||
{
|
||||
Director::getInstance()->end();
|
||||
}
|
||||
|
||||
void PlayerWin::relaunch()
|
||||
{
|
||||
_project.setWindowOffset(Vec2(getPositionX(), getPositionY()));
|
||||
openNewPlayerWithProjectConfig(_project);
|
||||
|
||||
quit();
|
||||
}
|
||||
|
||||
void PlayerWin::openNewPlayer()
|
||||
{
|
||||
openNewPlayerWithProjectConfig(_project);
|
||||
}
|
||||
|
||||
void PlayerWin::openNewPlayerWithProjectConfig(const ProjectConfig &config)
|
||||
{
|
||||
static long taskid = 100;
|
||||
stringstream buf;
|
||||
buf << taskid++;
|
||||
|
||||
string commandLine;
|
||||
commandLine.append(getApplicationExePath());
|
||||
commandLine.append(" ");
|
||||
commandLine.append(config.makeCommandLine());
|
||||
|
||||
CCLOG("PlayerWin::openNewPlayerWithProjectConfig(): %s", commandLine.c_str());
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
|
||||
SECURITY_ATTRIBUTES sa = {0};
|
||||
sa.nLength = sizeof(sa);
|
||||
|
||||
PROCESS_INFORMATION pi = {0};
|
||||
STARTUPINFO si = {0};
|
||||
si.cb = sizeof(STARTUPINFO);
|
||||
|
||||
#define MAX_COMMAND 1024 // lenth of commandLine is always beyond MAX_PATH
|
||||
|
||||
WCHAR command[MAX_COMMAND];
|
||||
memset(command, 0, sizeof(command));
|
||||
MultiByteToWideChar(CP_UTF8, 0, commandLine.c_str(), -1, command, MAX_COMMAND);
|
||||
|
||||
BOOL success = CreateProcess(NULL,
|
||||
command, // command line
|
||||
NULL, // process security attributes
|
||||
NULL, // primary thread security attributes
|
||||
FALSE, // handles are inherited
|
||||
0, // creation flags
|
||||
NULL, // use parent's environment
|
||||
NULL, // use parent's current directory
|
||||
&si, // STARTUPINFO pointer
|
||||
&pi); // receives PROCESS_INFORMATION
|
||||
|
||||
if (!success)
|
||||
{
|
||||
CCLOG("PlayerTaskWin::run() - create process failed, for execute %s", commandLine.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerWin::openProjectWithProjectConfig(const ProjectConfig &config)
|
||||
{
|
||||
openNewPlayerWithProjectConfig(config);
|
||||
quit();
|
||||
}
|
||||
|
||||
int PlayerWin::getPositionX()
|
||||
{
|
||||
RECT rect;
|
||||
GetWindowRect(_hwnd, &rect);
|
||||
return rect.left;
|
||||
}
|
||||
|
||||
int PlayerWin::getPositionY()
|
||||
{
|
||||
RECT rect;
|
||||
GetWindowRect(_hwnd, &rect);
|
||||
return rect.top;
|
||||
}
|
||||
|
||||
int PlayerWin::run()
|
||||
{
|
||||
INITCOMMONCONTROLSEX InitCtrls;
|
||||
InitCtrls.dwSize = sizeof(InitCtrls);
|
||||
InitCtrls.dwICC = ICC_WIN95_CLASSES;
|
||||
InitCommonControlsEx(&InitCtrls);
|
||||
|
||||
parseCocosProjectConfig(_project);
|
||||
|
||||
// load project config from command line args
|
||||
vector<string> args;
|
||||
for (int i = 0; i < __argc; ++i)
|
||||
{
|
||||
wstring ws(__wargv[i]);
|
||||
string s;
|
||||
s.assign(ws.begin(), ws.end());
|
||||
args.push_back(s);
|
||||
}
|
||||
_project.parseCommandLine(args);
|
||||
|
||||
if (_project.getProjectDir().empty())
|
||||
{
|
||||
if (args.size() == 2)
|
||||
{
|
||||
// for Code IDE before RC2
|
||||
_project.setProjectDir(args.at(1));
|
||||
_project.setDebuggerType(kCCRuntimeDebuggerCodeIDE);
|
||||
}
|
||||
}
|
||||
|
||||
// create the application instance
|
||||
_app = new AppDelegate();
|
||||
_app->setProjectConfig(_project);
|
||||
|
||||
// create console window
|
||||
if (_project.isShowConsole())
|
||||
{
|
||||
AllocConsole();
|
||||
_hwndConsole = GetConsoleWindow();
|
||||
if (_hwndConsole != NULL)
|
||||
{
|
||||
ShowWindow(_hwndConsole, SW_SHOW);
|
||||
BringWindowToTop(_hwndConsole);
|
||||
freopen("CONOUT$", "wt", stdout);
|
||||
freopen("CONOUT$", "wt", stderr);
|
||||
|
||||
HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE);
|
||||
if (hmenu != NULL)
|
||||
{
|
||||
DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log file
|
||||
if (_project.isWriteDebugLogToFile())
|
||||
{
|
||||
const string debugLogFilePath = _project.getDebugLogFilePath();
|
||||
_writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w");
|
||||
if (!_writeDebugLogFile)
|
||||
{
|
||||
CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// set environments
|
||||
SetCurrentDirectoryA(_project.getProjectDir().c_str());
|
||||
FileUtils::getInstance()->setDefaultResourceRootPath(_project.getProjectDir());
|
||||
FileUtils::getInstance()->setWritablePath(_project.getWritableRealPath().c_str());
|
||||
|
||||
// check screen DPI
|
||||
HDC screen = GetDC(0);
|
||||
int dpi = GetDeviceCaps(screen, LOGPIXELSX);
|
||||
ReleaseDC(0, screen);
|
||||
|
||||
// set scale with DPI
|
||||
// 96 DPI = 100 % scaling
|
||||
// 120 DPI = 125 % scaling
|
||||
// 144 DPI = 150 % scaling
|
||||
// 192 DPI = 200 % scaling
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#dpi_and_the_desktop_scaling_factor
|
||||
//
|
||||
// enable DPI-Aware with DeclareDPIAware.manifest
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#declaring_dpi_awareness
|
||||
float screenScale = 1.0f;
|
||||
if (dpi >= 120 && dpi < 144)
|
||||
{
|
||||
screenScale = 1.25f;
|
||||
}
|
||||
else if (dpi >= 144 && dpi < 192)
|
||||
{
|
||||
screenScale = 1.5f;
|
||||
}
|
||||
else if (dpi >= 192)
|
||||
{
|
||||
screenScale = 2.0f;
|
||||
}
|
||||
CCLOG("SCREEN DPI = %d, SCREEN SCALE = %0.2f", dpi, screenScale);
|
||||
|
||||
// create opengl view
|
||||
Size frameSize = _project.getFrameSize();
|
||||
float frameScale = 1.0f;
|
||||
if (_project.isRetinaDisplay())
|
||||
{
|
||||
frameSize.width *= screenScale;
|
||||
frameSize.height *= screenScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
frameScale = screenScale;
|
||||
}
|
||||
|
||||
const Rect frameRect = Rect(0, 0, frameSize.width, frameSize.height);
|
||||
const bool isResize = _project.isResizeWindow();
|
||||
std::stringstream title;
|
||||
title << "Cocos Simulator - " << ConfigParser::getInstance()->getInitViewName();
|
||||
auto glview = GLViewImpl::createWithRect(title.str(), frameRect, frameScale);
|
||||
_hwnd = glview->getWin32Window();
|
||||
DragAcceptFiles(_hwnd, TRUE);
|
||||
//SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon);
|
||||
//SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon);
|
||||
//FreeResource(icon);
|
||||
|
||||
auto director = Director::getInstance();
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
director->setAnimationInterval(1.0 / 60.0);
|
||||
|
||||
// set window position
|
||||
if (_project.getProjectDir().length())
|
||||
{
|
||||
setZoom(_project.getFrameScale());
|
||||
}
|
||||
Vec2 pos = _project.getWindowOffset();
|
||||
if (pos.x != 0 && pos.y != 0)
|
||||
{
|
||||
RECT rect;
|
||||
GetWindowRect(_hwnd, &rect);
|
||||
MoveWindow(_hwnd, pos.x, pos.y, rect.right - rect.left, rect.bottom - rect.top, FALSE);
|
||||
}
|
||||
|
||||
// register event handlers
|
||||
auto eventDispatcher = director->getEventDispatcher();
|
||||
eventDispatcher->addCustomEventListener("APP.VIEW_SCALE", CC_CALLBACK_1(PlayerWin::onWindowScale, this));
|
||||
|
||||
// path for looking Lang file, Studio Default images
|
||||
FileUtils::getInstance()->addSearchPath(getApplicationPath().c_str());
|
||||
|
||||
// init player services
|
||||
initServices();
|
||||
setupUI();
|
||||
DrawMenuBar(_hwnd);
|
||||
|
||||
// prepare
|
||||
FileUtils::getInstance()->setPopupNotify(false);
|
||||
_project.dump();
|
||||
auto app = Application::getInstance();
|
||||
|
||||
g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)PlayerWin::windowProc);
|
||||
|
||||
// update window size
|
||||
RECT rect;
|
||||
GetWindowRect(_hwnd, &rect);
|
||||
MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE);
|
||||
|
||||
// startup message loop
|
||||
return app->run();
|
||||
}
|
||||
|
||||
// services
|
||||
void PlayerWin::initServices()
|
||||
{
|
||||
CCASSERT(_menuService == nullptr, "CAN'T INITIALIZATION SERVICES MORE THAN ONCE");
|
||||
_menuService = new PlayerMenuServiceWin(_hwnd);
|
||||
_messageBoxService = new PlayerMessageBoxServiceWin(_hwnd);
|
||||
_fileDialogService = new PlayerFileDialogServiceWin(_hwnd);
|
||||
_editboxService = new PlayerEditBoxServiceWin(_hwnd);
|
||||
_taskService = new PlayerTaskServiceWin(_hwnd);
|
||||
|
||||
if (!_project.isAppMenu())
|
||||
{
|
||||
// remove menu
|
||||
SetMenu(_hwnd, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerWin::onWindowScale(EventCustom* event)
|
||||
{
|
||||
//float scale = atof(event->getDataString().c_str());
|
||||
//setZoom(scale);
|
||||
|
||||
//if (_project.isAppMenu() && GetMenu(_hwnd))
|
||||
//{
|
||||
// // update window size
|
||||
// RECT rect;
|
||||
// GetWindowRect(_hwnd, &rect);
|
||||
// MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE);
|
||||
//}
|
||||
}
|
||||
|
||||
void PlayerWin::setupUI()
|
||||
{
|
||||
auto menuBar = player::PlayerProtocol::getInstance()->getMenuService();
|
||||
|
||||
// FILE
|
||||
menuBar->addItem("FILE_MENU", tr("File"));
|
||||
menuBar->addItem("EXIT_MENU", tr("Exit"), "FILE_MENU");
|
||||
|
||||
// VIEW
|
||||
menuBar->addItem("VIEW_MENU", tr("View"));
|
||||
SimulatorConfig *config = SimulatorConfig::getInstance();
|
||||
int current = config->checkScreenSize(_project.getFrameSize());
|
||||
for (int i = 0; i < config->getScreenSizeCount(); i++)
|
||||
{
|
||||
SimulatorScreenSize size = config->getScreenSize(i);
|
||||
std::stringstream menuId;
|
||||
menuId << "VIEWSIZE_ITEM_MENU_" << i;
|
||||
auto menuItem = menuBar->addItem(menuId.str(), size.title.c_str(), "VIEW_MENU");
|
||||
|
||||
if (i == current)
|
||||
{
|
||||
menuItem->setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
menuBar->addItem("DIRECTION_MENU_SEP", "-", "VIEW_MENU");
|
||||
menuBar->addItem("DIRECTION_PORTRAIT_MENU", tr("Portrait"), "VIEW_MENU")
|
||||
->setChecked(_project.isPortraitFrame());
|
||||
menuBar->addItem("DIRECTION_LANDSCAPE_MENU", tr("Landscape"), "VIEW_MENU")
|
||||
->setChecked(_project.isLandscapeFrame());
|
||||
|
||||
menuBar->addItem("VIEW_SCALE_MENU_SEP", "-", "VIEW_MENU");
|
||||
std::vector<player::PlayerMenuItem*> scaleMenuVector;
|
||||
auto scale100Menu = menuBar->addItem("VIEW_SCALE_MENU_100", tr("Zoom Out").append(" (100%)"), "VIEW_MENU");
|
||||
auto scale75Menu = menuBar->addItem("VIEW_SCALE_MENU_75", tr("Zoom Out").append(" (75%)"), "VIEW_MENU");
|
||||
auto scale50Menu = menuBar->addItem("VIEW_SCALE_MENU_50", tr("Zoom Out").append(" (50%)"), "VIEW_MENU");
|
||||
auto scale25Menu = menuBar->addItem("VIEW_SCALE_MENU_25", tr("Zoom Out").append(" (25%)"), "VIEW_MENU");
|
||||
int frameScale = int(_project.getFrameScale() * 100);
|
||||
if (frameScale == 100)
|
||||
{
|
||||
scale100Menu->setChecked(true);
|
||||
}
|
||||
else if (frameScale == 75)
|
||||
{
|
||||
scale75Menu->setChecked(true);
|
||||
}
|
||||
else if (frameScale == 50)
|
||||
{
|
||||
scale50Menu->setChecked(true);
|
||||
}
|
||||
else if (frameScale == 25)
|
||||
{
|
||||
scale25Menu->setChecked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
scale100Menu->setChecked(true);
|
||||
}
|
||||
|
||||
scaleMenuVector.push_back(scale100Menu);
|
||||
scaleMenuVector.push_back(scale75Menu);
|
||||
scaleMenuVector.push_back(scale50Menu);
|
||||
scaleMenuVector.push_back(scale25Menu);
|
||||
|
||||
menuBar->addItem("REFRESH_MENU_SEP", "-", "VIEW_MENU");
|
||||
menuBar->addItem("REFRESH_MENU", tr("Refresh"), "VIEW_MENU");
|
||||
|
||||
HWND &hwnd = _hwnd;
|
||||
ProjectConfig &project = _project;
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
dispatcher->addEventListenerWithFixedPriority(EventListenerCustom::create("APP.EVENT", [&project, &hwnd, scaleMenuVector](EventCustom* event){
|
||||
auto menuEvent = dynamic_cast<AppEvent*>(event);
|
||||
if (menuEvent)
|
||||
{
|
||||
rapidjson::Document dArgParse;
|
||||
dArgParse.Parse<0>(menuEvent->getDataString().c_str());
|
||||
if (dArgParse.HasMember("name"))
|
||||
{
|
||||
string strcmd = dArgParse["name"].GetString();
|
||||
|
||||
if (strcmd == "menuClicked")
|
||||
{
|
||||
player::PlayerMenuItem *menuItem = static_cast<player::PlayerMenuItem*>(menuEvent->getUserData());
|
||||
if (menuItem)
|
||||
{
|
||||
if (menuItem->isChecked())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string data = dArgParse["data"].GetString();
|
||||
auto player = player::PlayerProtocol::getInstance();
|
||||
|
||||
if ((data == "CLOSE_MENU") || (data == "EXIT_MENU"))
|
||||
{
|
||||
player->quit();
|
||||
}
|
||||
else if (data == "REFRESH_MENU")
|
||||
{
|
||||
player->relaunch();
|
||||
}
|
||||
else if (data.find("VIEW_SCALE_MENU_") == 0) // begin with VIEW_SCALE_MENU_
|
||||
{
|
||||
string tmp = data.erase(0, strlen("VIEW_SCALE_MENU_"));
|
||||
float scale = atof(tmp.c_str()) / 100.0f;
|
||||
project.setFrameScale(scale);
|
||||
|
||||
auto glview = static_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView());
|
||||
glview->setFrameZoomFactor(scale);
|
||||
|
||||
// update scale menu state
|
||||
for (auto &it : scaleMenuVector)
|
||||
{
|
||||
it->setChecked(false);
|
||||
}
|
||||
menuItem->setChecked(true);
|
||||
|
||||
// update window size
|
||||
RECT rect;
|
||||
GetWindowRect(hwnd, &rect);
|
||||
MoveWindow(hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE);
|
||||
|
||||
// fix: can not update window on some windows system
|
||||
::SendMessage(hwnd, WM_MOVE, NULL, NULL);
|
||||
}
|
||||
else if (data.find("VIEWSIZE_ITEM_MENU_") == 0) // begin with VIEWSIZE_ITEM_MENU_
|
||||
{
|
||||
string tmp = data.erase(0, strlen("VIEWSIZE_ITEM_MENU_"));
|
||||
int index = atoi(tmp.c_str());
|
||||
SimulatorScreenSize size = SimulatorConfig::getInstance()->getScreenSize(index);
|
||||
|
||||
if (project.isLandscapeFrame())
|
||||
{
|
||||
std::swap(size.width, size.height);
|
||||
}
|
||||
|
||||
project.setFrameSize(cocos2d::Size(size.width, size.height));
|
||||
project.setWindowOffset(cocos2d::Vec2(player->getPositionX(), player->getPositionY()));
|
||||
player->openProjectWithProjectConfig(project);
|
||||
}
|
||||
else if (data == "DIRECTION_PORTRAIT_MENU")
|
||||
{
|
||||
project.changeFrameOrientationToPortait();
|
||||
player->openProjectWithProjectConfig(project);
|
||||
}
|
||||
else if (data == "DIRECTION_LANDSCAPE_MENU")
|
||||
{
|
||||
project.changeFrameOrientationToLandscape();
|
||||
player->openProjectWithProjectConfig(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}), 1);
|
||||
|
||||
AppDelegate *app = _app;
|
||||
auto listener = EventListenerCustom::create(kAppEventDropName, [&project, app](EventCustom* event)
|
||||
{
|
||||
AppEvent *dropEvent = dynamic_cast<AppEvent*>(event);
|
||||
if (dropEvent)
|
||||
{
|
||||
string dirPath = dropEvent->getDataString() + "/";
|
||||
string configFilePath = dirPath + CONFIG_FILE;
|
||||
|
||||
if (FileUtils::getInstance()->isDirectoryExist(dirPath) &&
|
||||
FileUtils::getInstance()->isFileExist(configFilePath))
|
||||
{
|
||||
// parse config.json
|
||||
ConfigParser::getInstance()->readConfig(configFilePath);
|
||||
|
||||
project.setProjectDir(dirPath);
|
||||
project.setScriptFile(ConfigParser::getInstance()->getEntryFile());
|
||||
project.setWritablePath(dirPath);
|
||||
|
||||
app->setProjectConfig(project);
|
||||
app->reopenProject();
|
||||
}
|
||||
}
|
||||
});
|
||||
dispatcher->addEventListenerWithFixedPriority(listener, 1);
|
||||
}
|
||||
|
||||
void PlayerWin::setZoom(float frameScale)
|
||||
{
|
||||
_project.setFrameScale(frameScale);
|
||||
cocos2d::Director::getInstance()->getOpenGLView()->setFrameZoomFactor(frameScale);
|
||||
}
|
||||
|
||||
// debug log
|
||||
void PlayerWin::writeDebugLog(const char *log)
|
||||
{
|
||||
if (!_writeDebugLogFile) return;
|
||||
|
||||
fputs(log, _writeDebugLogFile);
|
||||
fputc('\n', _writeDebugLogFile);
|
||||
fflush(_writeDebugLogFile);
|
||||
}
|
||||
|
||||
void PlayerWin::parseCocosProjectConfig(ProjectConfig &config)
|
||||
{
|
||||
// get project directory
|
||||
ProjectConfig tmpConfig;
|
||||
// load project config from command line args
|
||||
vector<string> args;
|
||||
for (int i = 0; i < __argc; ++i)
|
||||
{
|
||||
wstring ws(__wargv[i]);
|
||||
string s;
|
||||
s.assign(ws.begin(), ws.end());
|
||||
args.push_back(s);
|
||||
}
|
||||
|
||||
if (args.size() >= 2)
|
||||
{
|
||||
if (args.size() && args.at(1).at(0) == '/')
|
||||
{
|
||||
// FIXME:
|
||||
// for Code IDE before RC2
|
||||
tmpConfig.setProjectDir(args.at(1));
|
||||
}
|
||||
|
||||
tmpConfig.parseCommandLine(args);
|
||||
}
|
||||
|
||||
// set project directory as search root path
|
||||
FileUtils::getInstance()->setDefaultResourceRootPath(tmpConfig.getProjectDir().c_str());
|
||||
|
||||
// parse config.json
|
||||
auto parser = ConfigParser::getInstance();
|
||||
auto configPath = tmpConfig.getProjectDir().append(CONFIG_FILE);
|
||||
parser->readConfig(configPath);
|
||||
|
||||
// set information
|
||||
config.setConsolePort(parser->getConsolePort());
|
||||
config.setFileUploadPort(parser->getUploadPort());
|
||||
config.setFrameSize(parser->getInitViewSize());
|
||||
if (parser->isLanscape())
|
||||
{
|
||||
config.changeFrameOrientationToLandscape();
|
||||
}
|
||||
config.setScriptFile(parser->getEntryFile());
|
||||
}
|
||||
|
||||
//
|
||||
// D:\aaa\bbb\ccc\ddd\abc.txt --> D:/aaa/bbb/ccc/ddd/abc.txt
|
||||
//
|
||||
std::string PlayerWin::convertPathFormatToUnixStyle(const std::string& path)
|
||||
{
|
||||
std::string ret = path;
|
||||
int len = ret.length();
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (ret[i] == '\\')
|
||||
{
|
||||
ret[i] = '/';
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
// @return: C:/Users/win8/Documents/
|
||||
//
|
||||
std::string PlayerWin::getUserDocumentPath()
|
||||
{
|
||||
TCHAR filePath[MAX_PATH];
|
||||
SHGetSpecialFolderPath(NULL, filePath, CSIDL_PERSONAL, FALSE);
|
||||
int length = 2 * wcslen(filePath);
|
||||
char* tempstring = new char[length + 1];
|
||||
wcstombs(tempstring, filePath, length + 1);
|
||||
string userDocumentPath(tempstring);
|
||||
free(tempstring);
|
||||
|
||||
userDocumentPath = convertPathFormatToUnixStyle(userDocumentPath);
|
||||
userDocumentPath.append("/");
|
||||
|
||||
return userDocumentPath;
|
||||
}
|
||||
|
||||
//
|
||||
// convert Unicode/LocalCode TCHAR to Utf8 char
|
||||
//
|
||||
char* PlayerWin::convertTCharToUtf8(const TCHAR* src)
|
||||
{
|
||||
#ifdef UNICODE
|
||||
WCHAR* tmp = (WCHAR*)src;
|
||||
size_t size = wcslen(src) * 3 + 1;
|
||||
char* dest = new char[size];
|
||||
memset(dest, 0, size);
|
||||
WideCharToMultiByte(CP_UTF8, 0, tmp, -1, dest, size, NULL, NULL);
|
||||
return dest;
|
||||
#else
|
||||
char* tmp = (char*)src;
|
||||
uint32 size = strlen(tmp) + 1;
|
||||
WCHAR* dest = new WCHAR[size];
|
||||
memset(dest, 0, sizeof(WCHAR)*size);
|
||||
MultiByteToWideChar(CP_ACP, 0, src, -1, dest, (int)size); // convert local code to unicode.
|
||||
|
||||
size = wcslen(dest) * 3 + 1;
|
||||
char* dest2 = new char[size];
|
||||
memset(dest2, 0, size);
|
||||
WideCharToMultiByte(CP_UTF8, 0, dest, -1, dest2, size, NULL, NULL); // convert unicode to utf8.
|
||||
delete[] dest;
|
||||
return dest2;
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
std::string PlayerWin::getApplicationExePath()
|
||||
{
|
||||
TCHAR szFileName[MAX_PATH];
|
||||
GetModuleFileName(NULL, szFileName, MAX_PATH);
|
||||
std::u16string u16ApplicationName;
|
||||
char *applicationExePath = convertTCharToUtf8(szFileName);
|
||||
std::string path(applicationExePath);
|
||||
CC_SAFE_FREE(applicationExePath);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string PlayerWin::getApplicationPath()
|
||||
{
|
||||
std::string path = getApplicationExePath();
|
||||
size_t pos;
|
||||
while ((pos = path.find_first_of("\\")) != std::string::npos)
|
||||
{
|
||||
path.replace(pos, 1, "/");
|
||||
}
|
||||
size_t p = path.find_last_of("/");
|
||||
string workdir;
|
||||
if (p != path.npos)
|
||||
{
|
||||
workdir = path.substr(0, p);
|
||||
}
|
||||
|
||||
return workdir;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK PlayerWin::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (!_instance) return 0;
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_COMMAND:
|
||||
{
|
||||
if (HIWORD(wParam) == 0)
|
||||
{
|
||||
// menu
|
||||
WORD menuId = LOWORD(wParam);
|
||||
PlayerMenuItemWin *menuItem = _instance->_menuService->getItemByCommandId(menuId);
|
||||
if (menuItem)
|
||||
{
|
||||
AppEvent event("APP.EVENT", APP_EVENT_MENU);
|
||||
|
||||
std::stringstream buf;
|
||||
buf << "{\"data\":\"" << menuItem->getMenuId().c_str() << "\"";
|
||||
buf << ",\"name\":" << "\"menuClicked\"" << "}";
|
||||
event.setDataString(buf.str());
|
||||
event.setUserData(menuItem);
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
|
||||
}
|
||||
|
||||
if (menuId == ID_HELP_ABOUT)
|
||||
{
|
||||
onHelpAbout();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_KEYDOWN:
|
||||
{
|
||||
if (wParam == VK_F5)
|
||||
{
|
||||
PlayerProtocol::getInstance()->relaunch();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_COPYDATA:
|
||||
{
|
||||
PCOPYDATASTRUCT pMyCDS = (PCOPYDATASTRUCT) lParam;
|
||||
if (pMyCDS->dwData == 1)
|
||||
{
|
||||
const char *szBuf = (const char*)(pMyCDS->lpData);
|
||||
PlayerWin::getInstance()->writeDebugLog(szBuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case WM_DESTROY:
|
||||
{
|
||||
DragAcceptFiles(hWnd, FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_DROPFILES:
|
||||
{
|
||||
HDROP hDrop = (HDROP)wParam;
|
||||
|
||||
const int count = DragQueryFileW(hDrop, 0xffffffff, NULL, 0);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
int fileIndex = 0;
|
||||
|
||||
const UINT length = DragQueryFileW(hDrop, fileIndex, NULL, 0);
|
||||
WCHAR* buffer = (WCHAR*)calloc(length + 1, sizeof(WCHAR));
|
||||
|
||||
DragQueryFileW(hDrop, fileIndex, buffer, length + 1);
|
||||
char *utf8 = PlayerWin::convertTCharToUtf8(buffer);
|
||||
std::string firstFile(utf8);
|
||||
CC_SAFE_FREE(utf8);
|
||||
DragFinish(hDrop);
|
||||
|
||||
// broadcast drop event
|
||||
AppEvent forwardEvent("APP.EVENT.DROP", APP_EVENT_DROP);
|
||||
forwardEvent.setDataString(firstFile);
|
||||
|
||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&forwardEvent);
|
||||
}
|
||||
} // WM_DROPFILES
|
||||
|
||||
}
|
||||
return g_oldWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
PLAYER_NS_END
|
|
@ -1,82 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Resource.h"
|
||||
#include "cocos2d.h"
|
||||
#include "AppDelegate.h"
|
||||
#include "ProjectConfig/ProjectConfig.h"
|
||||
#include "ProjectConfig/SimulatorConfig.h"
|
||||
|
||||
#include "PlayerMacros.h"
|
||||
#include "PlayerProtocol.h"
|
||||
#include "PlayerMenuServiceWin.h"
|
||||
#include "PlayerMessageBoxServiceWin.h"
|
||||
#include "PlayerFileDialogServiceWin.h"
|
||||
#include "PlayerEditBoxServiceWin.h"
|
||||
#include "PlayerTaskServiceWin.h"
|
||||
|
||||
PLAYER_NS_BEGIN
|
||||
|
||||
class PlayerWin : public PlayerProtocol, public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
static PlayerWin *getInstance();
|
||||
virtual ~PlayerWin();
|
||||
int run();
|
||||
|
||||
virtual PlayerFileDialogServiceProtocol *getFileDialogService();
|
||||
virtual PlayerMessageBoxServiceProtocol *getMessageBoxService();
|
||||
virtual PlayerMenuServiceProtocol *getMenuService();
|
||||
virtual PlayerEditBoxServiceProtocol *getEditBoxService();
|
||||
virtual PlayerTaskServiceProtocol *getTaskService();
|
||||
|
||||
virtual void quit();
|
||||
virtual void relaunch();
|
||||
virtual void openNewPlayer();
|
||||
virtual void openNewPlayerWithProjectConfig(const ProjectConfig &config);
|
||||
virtual void openProjectWithProjectConfig(const ProjectConfig &config);
|
||||
|
||||
virtual int getPositionX();
|
||||
virtual int getPositionY();
|
||||
protected:
|
||||
PlayerWin();
|
||||
|
||||
static PlayerWin *_instance;
|
||||
ProjectConfig _project;
|
||||
HWND _hwnd;
|
||||
HWND _hwndConsole;
|
||||
AppDelegate *_app;
|
||||
FILE *_writeDebugLogFile;
|
||||
|
||||
PlayerMenuServiceWin *_menuService;
|
||||
PlayerMessageBoxServiceWin *_messageBoxService;
|
||||
PlayerFileDialogServiceWin *_fileDialogService;
|
||||
PlayerEditBoxServiceWin *_editboxService;
|
||||
PlayerTaskServiceWin *_taskService;
|
||||
|
||||
// services
|
||||
void initServices();
|
||||
|
||||
// event handlers
|
||||
void onWindowScale(cocos2d::EventCustom* event);
|
||||
|
||||
//
|
||||
void setupUI();
|
||||
void setZoom(float frameScale);
|
||||
|
||||
// debug log
|
||||
void writeDebugLog(const char *log);
|
||||
void parseCocosProjectConfig(ProjectConfig &config);
|
||||
|
||||
// helper
|
||||
std::string convertPathFormatToUnixStyle(const std::string& path);
|
||||
std::string getUserDocumentPath();
|
||||
std::string getApplicationExePath();
|
||||
std::string getApplicationPath();
|
||||
static char* convertTCharToUtf8(const TCHAR* src);
|
||||
|
||||
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
};
|
||||
|
||||
|
||||
PLAYER_NS_END
|
|
@ -1,38 +0,0 @@
|
|||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by game.rc
|
||||
//
|
||||
#define IDS_PROJNAME 100
|
||||
#define IDR_TESTLUA 100
|
||||
#define IDR_MENU_COCOS 201
|
||||
#define IDD_DIALOG1 202
|
||||
#define IDD_DIALOG_ABOUT 202
|
||||
#define IDC_EDIT2 1001
|
||||
#define ID_VIEW_SIZE 30001
|
||||
#define ID_FILE_NEW_WINDOW 32771
|
||||
#define ID_VIEW_PORTRAIT 32775
|
||||
#define ID_VIEW_LANDSCAPE 32776
|
||||
#define ID_VIEW_CUSTOM 32777
|
||||
#define ID_HELP_ABOUT 32778
|
||||
#define ID_FILE_EXIT 32779
|
||||
#define ID_Menu 32780
|
||||
#define ID_Menu32781 32781
|
||||
#define ID_TEST_RESET 32782
|
||||
#define ID_CONTROL 32783
|
||||
#define ID_CONTROL_RELOAD 32784
|
||||
#define ID_VIEW_ZOOMOUT100 32785
|
||||
#define ID_VIEW_ZOOMOUT75 32786
|
||||
#define ID_VIEW_ZOOMOUT50 32787
|
||||
#define ID_VIEW_ZOOMOUT25 32788
|
||||
#define ID_CONTROL_TOP 32793
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 204
|
||||
#define _APS_NEXT_COMMAND_VALUE 32794
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// player.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
|
@ -1,21 +0,0 @@
|
|||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files:
|
||||
#include <windows.h>
|
||||
|
||||
// C RunTime Header Files
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
|
@ -1,8 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// Including SDKDDKVer.h defines the highest available Windows platform.
|
||||
|
||||
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
|
||||
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
||||
|
||||
#include <SDKDDKVer.h>
|
|
@ -1,18 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.30501.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simulator", "simulator.vcxproj", "{4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\..\cocos2d-x\cocos\2d\libcocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}"
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\..\..\..\..\cocos\2d\libcocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libluacocos2d", "..\..\cocos2d-x\cocos\scripting\lua-bindings\proj.win32\libluacocos2d.vcxproj", "{9F2D6CE6-C893-4400-B50C-6DB70CC2562F}"
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libluacocos2d", "..\..\..\..\..\cocos\scripting\lua-bindings\proj.win32\libluacocos2d.vcxproj", "{9F2D6CE6-C893-4400-B50C-6DB70CC2562F}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d", "..\..\cocos2d-x\external\Box2D\proj.win32\libbox2d.vcxproj", "{929480E7-23C0-4DF6-8456-096D71547116}"
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbox2d", "..\..\..\..\..\external\Box2D\proj.win32\libbox2d.vcxproj", "{929480E7-23C0-4DF6-8456-096D71547116}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine", "..\..\cocos2d-x\cocos\editor-support\spine\proj.win32\libSpine.vcxproj", "{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}"
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine", "..\..\..\..\..\cocos\editor-support\spine\proj.win32\libSpine.vcxproj", "{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsimulator", "..\..\..\libsimulator\proj.win32\libsimulator.vcxproj", "{001B324A-BB91-4E83-875C-C92F75C40857}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -40,6 +44,10 @@ Global
|
|||
{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}.Release|Win32.Build.0 = Release|Win32
|
||||
{001B324A-BB91-4E83-875C-C92F75C40857}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{001B324A-BB91-4E83-875C-C92F75C40857}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{001B324A-BB91-4E83-875C-C92F75C40857}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{001B324A-BB91-4E83-875C-C92F75C40857}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -38,13 +38,13 @@
|
|||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\cocos2d-x\cocos\2d\cocos2dx.props" />
|
||||
<Import Project="..\..\cocos2d-x\cocos\2d\cocos2d_headers.props" />
|
||||
<Import Project="..\..\..\..\..\cocos\2d\cocos2dx.props" />
|
||||
<Import Project="..\..\..\..\..\cocos\2d\cocos2d_headers.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\cocos2d-x\cocos\2d\cocos2dx.props" />
|
||||
<Import Project="..\..\cocos2d-x\cocos\2d\cocos2d_headers.props" />
|
||||
<Import Project="..\..\..\..\..\cocos\2d\cocos2dx.props" />
|
||||
<Import Project="..\..\..\..\..\cocos\2d\cocos2d_headers.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
|
@ -68,9 +68,8 @@
|
|||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\Classes;$(ProjectDir)..\Classes\runtime;$(ProjectDir)..\Classes\service;$(ProjectDir)..\Classes\protobuf-lite;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\lua\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\curl\include\win32;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\Classes;$(ProjectDir)..\Classes\runtime;$(ProjectDir)..\Classes\protobuf-lite;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\lua\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\curl\include\win32;$(EngineRoot)tools\simulator\libsimulator\lib\service;$(EngineRoot)tools\simulator\libsimulator\lib;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
|
@ -125,7 +124,7 @@ xcopy /Y /Q "$(ProjectDir)..\Classes\lang" "$(ProjectDir)..\..\..\runtime\win32\
|
|||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\Classes;$(ProjectDir)..\Classes\service;$(ProjectDir)..\Classes\runtime;$(ProjectDir)..\Classes\protobuf-lite;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\lua\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;$(EngineRoot)external\curl\include\win32;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\Classes;$(ProjectDir)..\Classes\service;$(ProjectDir)..\Classes\runtime;$(ProjectDir)..\Classes\protobuf-lite;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)cocos\scripting\lua-bindings\auto;$(EngineRoot)cocos\scripting\lua-bindings\manual;$(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\lua\lua;$(EngineRoot)external\lua\tolua;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;$(EngineRoot)external\curl\include\win32;$(EngineRoot)tools\simulator\libsimulator\lib;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
|
@ -165,7 +164,7 @@ xcopy /Y /Q "$(ProjectDir)..\Classes\lang" "$(ProjectDir)..\..\..\runtime\win32\
|
|||
</DllDataFileName>
|
||||
</Midl>
|
||||
<PreBuildEvent>
|
||||
<Command>if not exist "$(LocalDebuggerWorkingDirectory)" mkdir "$(LocalDebuggerWorkingDirectory)"</Command>
|
||||
<Command>if not exist "$(LocalDebuggerWorkingDirectory)" mkdir "$(LocalDebuggerWorkingDirectory)"</Command>
|
||||
<Message>copy files</Message>
|
||||
</PreBuildEvent>
|
||||
<PreLinkEvent>
|
||||
|
@ -180,10 +179,6 @@ xcopy /Y /Q "$(ProjectDir)..\Classes\lang" "$(ProjectDir)..\..\..\runtime\win32\
|
|||
<ItemGroup>
|
||||
<ClInclude Include="..\Classes\AppDelegate.h" />
|
||||
<ClInclude Include="..\Classes\ConfigParser.h" />
|
||||
<ClInclude Include="..\Classes\network\CCHTTPRequest.h" />
|
||||
<ClInclude Include="..\Classes\network\CCHTTPRequestDelegate.h" />
|
||||
<ClInclude Include="..\Classes\ProjectConfig\ProjectConfig.h" />
|
||||
<ClInclude Include="..\Classes\ProjectConfig\SimulatorConfig.h" />
|
||||
<ClInclude Include="..\Classes\protobuf-lite\google\protobuf\extension_set.h" />
|
||||
<ClInclude Include="..\Classes\protobuf-lite\google\protobuf\generated_message_util.h" />
|
||||
<ClInclude Include="..\Classes\protobuf-lite\google\protobuf\io\coded_stream.h" />
|
||||
|
@ -212,37 +207,16 @@ xcopy /Y /Q "$(ProjectDir)..\Classes\lang" "$(ProjectDir)..\..\..\runtime\win32\
|
|||
<ClInclude Include="..\Classes\runtime\Protos.pb.h" />
|
||||
<ClInclude Include="..\Classes\runtime\ResData.h" />
|
||||
<ClInclude Include="..\Classes\runtime\Runtime.h" />
|
||||
<ClInclude Include="..\Classes\service\AppEvent.h" />
|
||||
<ClInclude Include="..\Classes\service\AppLang.h" />
|
||||
<ClInclude Include="..\Classes\service\DeviceEx.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerEditBoxServiceProtocol.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerFileDialogServiceProtocol.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerMacros.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerMenuServiceProtocol.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerMessageBoxServiceProtocol.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerProtocol.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerServiceProtocol.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerSettings.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerTaskServiceProtocol.h" />
|
||||
<ClInclude Include="..\Classes\service\PlayerUtils.h" />
|
||||
<ClInclude Include="..\Classes\VisibleRect.h" />
|
||||
<ClInclude Include="main.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="service\PlayerEditBoxServiceWin.h" />
|
||||
<ClInclude Include="service\PlayerFileDialogServiceWin.h" />
|
||||
<ClInclude Include="service\PlayerMenuServiceWin.h" />
|
||||
<ClInclude Include="service\PlayerMessageBoxServiceWin.h" />
|
||||
<ClInclude Include="service\PlayerTaskServiceWin.h" />
|
||||
<ClInclude Include="service\PlayerWin.h" />
|
||||
<ClInclude Include="service\stdafx.h" />
|
||||
<ClInclude Include="service\targetver.h" />
|
||||
<ClInclude Include="SimulatorWin.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Classes\AppDelegate.cpp" />
|
||||
<ClCompile Include="..\Classes\ConfigParser.cpp" />
|
||||
<ClCompile Include="..\Classes\network\CCHTTPRequest.cpp" />
|
||||
<ClCompile Include="..\Classes\ProjectConfig\ProjectConfig.cpp" />
|
||||
<ClCompile Include="..\Classes\ProjectConfig\SimulatorConfig.cpp" />
|
||||
<ClCompile Include="..\Classes\protobuf-lite\google\protobuf\extension_set.cc" />
|
||||
<ClCompile Include="..\Classes\protobuf-lite\google\protobuf\generated_message_util.cc" />
|
||||
<ClCompile Include="..\Classes\protobuf-lite\google\protobuf\io\coded_stream.cc" />
|
||||
|
@ -266,25 +240,11 @@ xcopy /Y /Q "$(ProjectDir)..\Classes\lang" "$(ProjectDir)..\..\..\runtime\win32\
|
|||
<ClCompile Include="..\Classes\runtime\Protos.pb.cc" />
|
||||
<ClCompile Include="..\Classes\runtime\Runtime.cpp" />
|
||||
<ClCompile Include="..\Classes\runtime\Shine_png.cpp" />
|
||||
<ClCompile Include="..\Classes\service\AppEvent.cpp" />
|
||||
<ClCompile Include="..\Classes\service\AppLang.cpp" />
|
||||
<ClCompile Include="..\Classes\service\PlayerMenuServiceProtocol.cpp" />
|
||||
<ClCompile Include="..\Classes\service\PlayerProtocol.cpp" />
|
||||
<ClCompile Include="..\Classes\service\PlayerServiceProtocol.cpp" />
|
||||
<ClCompile Include="..\Classes\service\PlayerSettings.cpp" />
|
||||
<ClCompile Include="..\Classes\service\PlayerTaskServiceProtocol.cpp" />
|
||||
<ClCompile Include="..\Classes\service\PlayerUtils.cpp" />
|
||||
<ClCompile Include="..\Classes\VisibleRect.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Runtime_win32.cpp" />
|
||||
<ClCompile Include="service\DeviceEx-win32.cpp" />
|
||||
<ClCompile Include="service\PlayerEditBoxServiceWin.cpp" />
|
||||
<ClCompile Include="service\PlayerFileDialogServiceWin.cpp" />
|
||||
<ClCompile Include="service\PlayerMenuServiceWin.cpp" />
|
||||
<ClCompile Include="service\PlayerMessageBoxServiceWin.cpp" />
|
||||
<ClCompile Include="service\PlayerTaskServiceWin.cpp" />
|
||||
<ClCompile Include="service\PlayerWin.cpp" />
|
||||
<ClCompile Include="service\stdafx.cpp" />
|
||||
<ClCompile Include="SimulatorWin.cpp" />
|
||||
<ClCompile Include="stdafx.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="game.rc" />
|
||||
|
@ -293,9 +253,12 @@ xcopy /Y /Q "$(ProjectDir)..\Classes\lang" "$(ProjectDir)..\..\..\runtime\win32\
|
|||
<Image Include="res\game.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\cocos2d-x\cocos\scripting\lua-bindings\proj.win32\libluacocos2d.vcxproj">
|
||||
<ProjectReference Include="..\..\..\..\..\cocos\scripting\lua-bindings\proj.win32\libluacocos2d.vcxproj">
|
||||
<Project>{9f2d6ce6-c893-4400-b50c-6db70cc2562f}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\libsimulator\proj.win32\libsimulator.vcxproj">
|
||||
<Project>{001b324a-bb91-4e83-875c-c92f75c40857}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
@ -16,18 +16,6 @@
|
|||
<Filter Include="Classes\runtime\protobuf-lite">
|
||||
<UniqueIdentifier>{28edb895-7c19-408b-abd6-130196087d96}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Classes\service">
|
||||
<UniqueIdentifier>{b0ffeea4-e5fa-483a-8be4-c26a9ed47c60}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Classes\network">
|
||||
<UniqueIdentifier>{e2010b29-c067-4846-8f28-667d95056987}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Classes\ProjectConfig">
|
||||
<UniqueIdentifier>{6a6237c1-312d-4c66-82b3-b0de869920c8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="win32\service">
|
||||
<UniqueIdentifier>{9d6fbab4-6525-4c43-9438-9d3923429d52}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\Classes\AppDelegate.h">
|
||||
|
@ -127,80 +115,12 @@
|
|||
<ClInclude Include="..\Classes\runtime\FileServer.h">
|
||||
<Filter>Classes\runtime</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\AppEvent.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
<ClInclude Include="SimulatorWin.h" />
|
||||
<ClInclude Include="stdafx.h">
|
||||
<Filter>win32</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\AppLang.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\DeviceEx.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerEditBoxServiceProtocol.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerFileDialogServiceProtocol.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerMacros.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerMenuServiceProtocol.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerMessageBoxServiceProtocol.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerProtocol.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerServiceProtocol.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerSettings.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerTaskServiceProtocol.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\service\PlayerUtils.h">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\network\CCHTTPRequest.h">
|
||||
<Filter>Classes\network</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\network\CCHTTPRequestDelegate.h">
|
||||
<Filter>Classes\network</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\ProjectConfig\ProjectConfig.h">
|
||||
<Filter>Classes\ProjectConfig</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\ProjectConfig\SimulatorConfig.h">
|
||||
<Filter>Classes\ProjectConfig</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="service\PlayerEditBoxServiceWin.h">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="service\PlayerFileDialogServiceWin.h">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="service\PlayerMenuServiceWin.h">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="service\PlayerMessageBoxServiceWin.h">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="service\PlayerTaskServiceWin.h">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="service\PlayerWin.h">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="service\stdafx.h">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="service\targetver.h">
|
||||
<Filter>win32\service</Filter>
|
||||
<ClInclude Include="targetver.h">
|
||||
<Filter>win32</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -288,62 +208,9 @@
|
|||
<ClCompile Include="..\Classes\runtime\FileServer.cpp">
|
||||
<Filter>Classes\runtime</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\service\AppEvent.cpp">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\service\AppLang.cpp">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\service\PlayerMenuServiceProtocol.cpp">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\service\PlayerProtocol.cpp">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\service\PlayerServiceProtocol.cpp">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\service\PlayerSettings.cpp">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\service\PlayerTaskServiceProtocol.cpp">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\service\PlayerUtils.cpp">
|
||||
<Filter>Classes\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\network\CCHTTPRequest.cpp">
|
||||
<Filter>Classes\network</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\ProjectConfig\ProjectConfig.cpp">
|
||||
<Filter>Classes\ProjectConfig</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\ProjectConfig\SimulatorConfig.cpp">
|
||||
<Filter>Classes\ProjectConfig</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service\DeviceEx-win32.cpp">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service\PlayerEditBoxServiceWin.cpp">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service\PlayerFileDialogServiceWin.cpp">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service\PlayerMenuServiceWin.cpp">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service\PlayerMessageBoxServiceWin.cpp">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service\PlayerTaskServiceWin.cpp">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service\PlayerWin.cpp">
|
||||
<Filter>win32\service</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service\stdafx.cpp">
|
||||
<Filter>win32\service</Filter>
|
||||
<ClCompile Include="SimulatorWin.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<Filter>win32</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -27,15 +27,6 @@ public:
|
|||
virtual PlayerEditBoxServiceProtocol *getEditBoxService();
|
||||
virtual PlayerTaskServiceProtocol *getTaskService();
|
||||
|
||||
void quit();
|
||||
void relaunch();
|
||||
void openNewPlayer();
|
||||
void openNewPlayerWithProjectConfig(const ProjectConfig& config);
|
||||
void openProjectWithProjectConfig(const ProjectConfig& config);
|
||||
|
||||
void setController(id controller);
|
||||
int getPositionX();
|
||||
int getPositionY();
|
||||
protected:
|
||||
PlayerMac();
|
||||
|
||||
|
|
|
@ -72,7 +72,6 @@ PlayerEditBoxServiceProtocol *PlayerMac::getEditBoxService()
|
|||
|
||||
PlayerTaskServiceProtocol *PlayerMac::getTaskService()
|
||||
{
|
||||
|
||||
if (!_taskService)
|
||||
{
|
||||
_taskService = new PlayerTaskServiceMac();
|
||||
|
@ -80,56 +79,4 @@ PlayerTaskServiceProtocol *PlayerMac::getTaskService()
|
|||
return _taskService;
|
||||
}
|
||||
|
||||
void PlayerMac::quit()
|
||||
{
|
||||
cocos2d::Director::getInstance()->end();
|
||||
}
|
||||
|
||||
void PlayerMac::relaunch()
|
||||
{
|
||||
if (_appController && [_appController respondsToSelector:NSSelectorFromString(@"relaunch")])
|
||||
{
|
||||
[_appController performSelector:NSSelectorFromString(@"relaunch")];
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMac::openNewPlayer()
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerMac::openNewPlayerWithProjectConfig(const ProjectConfig& config)
|
||||
{
|
||||
if (_appController && [_appController respondsToSelector:NSSelectorFromString(@"launch:")])
|
||||
{
|
||||
NSString *commandLine = [NSString stringWithCString:config.makeCommandLine().c_str()
|
||||
encoding:NSUTF8StringEncoding];
|
||||
NSArray *arguments = [NSMutableArray arrayWithArray:[commandLine componentsSeparatedByString:@" "]];
|
||||
|
||||
[_appController performSelector:NSSelectorFromString(@"launch:") withObject:arguments];
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMac::openProjectWithProjectConfig(const ProjectConfig& config)
|
||||
{
|
||||
this->openNewPlayerWithProjectConfig(config);
|
||||
this->quit();
|
||||
}
|
||||
|
||||
void PlayerMac::setController(id controller)
|
||||
{
|
||||
_appController = controller;
|
||||
}
|
||||
|
||||
int PlayerMac::getPositionX()
|
||||
{
|
||||
NSWindow *window = dynamic_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView())->getCocoaWindow();
|
||||
return window.frame.origin.x;
|
||||
}
|
||||
|
||||
int PlayerMac::getPositionY()
|
||||
{
|
||||
NSWindow *window = dynamic_cast<GLViewImpl*>(Director::getInstance()->getOpenGLView())->getCocoaWindow();
|
||||
return window.frame.origin.y;
|
||||
}
|
||||
|
||||
PLAYER_NS_END
|
||||
|
|
|
@ -31,18 +31,6 @@ public:
|
|||
virtual PlayerMenuServiceProtocol *getMenuService() = 0;
|
||||
virtual PlayerEditBoxServiceProtocol *getEditBoxService() = 0;
|
||||
virtual PlayerTaskServiceProtocol *getTaskService() = 0;
|
||||
|
||||
// player function
|
||||
|
||||
virtual void quit() = 0;
|
||||
virtual void relaunch() = 0;
|
||||
virtual void openNewPlayer() = 0;
|
||||
virtual void openNewPlayerWithProjectConfig(const ProjectConfig &config) = 0;
|
||||
virtual void openProjectWithProjectConfig(const ProjectConfig &config) = 0;
|
||||
|
||||
// window info
|
||||
virtual int getPositionX() = 0;
|
||||
virtual int getPositionY() = 0;
|
||||
|
||||
protected:
|
||||
PlayerProtocol(); // avoid create instance from outside
|
||||
|
|
Loading…
Reference in New Issue