mirror of https://github.com/axmolengine/axmol.git
add libsimulator
This commit is contained in:
parent
dee536def2
commit
82f37fcf72
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"has_native": true,
|
||||||
|
"project_type": "lua"
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
{
|
||||||
|
"init_cfg":{
|
||||||
|
"isLandscape": true,
|
||||||
|
"isWindowTop": false,
|
||||||
|
"name": "HelloLua",
|
||||||
|
"width": 960,
|
||||||
|
"height": 640,
|
||||||
|
"entry": "src/main.lua",
|
||||||
|
"consolePort": 6010,
|
||||||
|
"uploadPort": 6020
|
||||||
|
},
|
||||||
|
"simulator_screen_size": [
|
||||||
|
{
|
||||||
|
"title": "iPhone 3Gs (480x320)",
|
||||||
|
"width": 480,
|
||||||
|
"height": 320
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "iPhone 4 (960x640)",
|
||||||
|
"width": 960,
|
||||||
|
"height": 640
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "iPhone 5 (1136x640)",
|
||||||
|
"width": 1136,
|
||||||
|
"height": 640
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "iPad (1024x768)",
|
||||||
|
"width": 1024,
|
||||||
|
"height": 768
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "iPad Retina (2048x1536)",
|
||||||
|
"width": 2048,
|
||||||
|
"height": 1536
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Android (800x480)",
|
||||||
|
"width": 800,
|
||||||
|
"height": 480
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Android (854x480)",
|
||||||
|
"width": 854,
|
||||||
|
"height": 480
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Android (1280x720)",
|
||||||
|
"width": 1280,
|
||||||
|
"height": 720
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Android (1920x1080)",
|
||||||
|
"width": 1920,
|
||||||
|
"height": 1080
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -184,6 +184,10 @@ static void glfwDropFunc(GLFWwindow *window, int count, const char **files)
|
||||||
{
|
{
|
||||||
config->changeFrameOrientationToLandscape();
|
config->changeFrameOrientationToLandscape();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config->changeFrameOrientationToPortait();
|
||||||
|
}
|
||||||
config->setScriptFile(parser->getEntryFile());
|
config->setScriptFile(parser->getEntryFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,800 @@
|
||||||
|
|
||||||
|
#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 "SimulatorWin.h"
|
||||||
|
|
||||||
|
#include "glfw3.h"
|
||||||
|
#include "glfw3native.h"
|
||||||
|
|
||||||
|
#include "CCLuaEngine.h"
|
||||||
|
#include "AppEvent.h"
|
||||||
|
#include "AppLang.h"
|
||||||
|
#include "ConfigParser.h"
|
||||||
|
|
||||||
|
#include "platform/win32/PlayerWin.h"
|
||||||
|
#include "platform/win32/PlayerMenuServiceWin.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimulatorWin *SimulatorWin::_instance = nullptr;
|
||||||
|
|
||||||
|
SimulatorWin *SimulatorWin::getInstance()
|
||||||
|
{
|
||||||
|
if (!_instance)
|
||||||
|
{
|
||||||
|
_instance = new SimulatorWin();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimulatorWin::SimulatorWin()
|
||||||
|
: _app(nullptr)
|
||||||
|
, _hwnd(NULL)
|
||||||
|
, _hwndConsole(NULL)
|
||||||
|
, _writeDebugLogFile(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SimulatorWin::~SimulatorWin()
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(_app);
|
||||||
|
if (_writeDebugLogFile)
|
||||||
|
{
|
||||||
|
fclose(_writeDebugLogFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::quit()
|
||||||
|
{
|
||||||
|
Director::getInstance()->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::relaunch()
|
||||||
|
{
|
||||||
|
_project.setWindowOffset(Vec2(getPositionX(), getPositionY()));
|
||||||
|
openNewPlayerWithProjectConfig(_project);
|
||||||
|
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::openNewPlayer()
|
||||||
|
{
|
||||||
|
openNewPlayerWithProjectConfig(_project);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::openNewPlayerWithProjectConfig(const ProjectConfig &config)
|
||||||
|
{
|
||||||
|
static long taskid = 100;
|
||||||
|
stringstream buf;
|
||||||
|
buf << taskid++;
|
||||||
|
|
||||||
|
string commandLine;
|
||||||
|
commandLine.append(getApplicationExePath());
|
||||||
|
commandLine.append(" ");
|
||||||
|
commandLine.append(config.makeCommandLine());
|
||||||
|
|
||||||
|
CCLOG("SimulatorWin::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 SimulatorWin::openProjectWithProjectConfig(const ProjectConfig &config)
|
||||||
|
{
|
||||||
|
openNewPlayerWithProjectConfig(config);
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorWin::getPositionX()
|
||||||
|
{
|
||||||
|
RECT rect;
|
||||||
|
GetWindowRect(_hwnd, &rect);
|
||||||
|
return rect.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorWin::getPositionY()
|
||||||
|
{
|
||||||
|
RECT rect;
|
||||||
|
GetWindowRect(_hwnd, &rect);
|
||||||
|
return rect.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorWin::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();
|
||||||
|
player::PlayerWin::createWithHwnd(_hwnd);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// path for looking Lang file, Studio Default images
|
||||||
|
FileUtils::getInstance()->addSearchPath(getApplicationPath().c_str());
|
||||||
|
|
||||||
|
// init player services
|
||||||
|
setupUI();
|
||||||
|
DrawMenuBar(_hwnd);
|
||||||
|
|
||||||
|
// prepare
|
||||||
|
FileUtils::getInstance()->setPopupNotify(false);
|
||||||
|
_project.dump();
|
||||||
|
auto app = Application::getInstance();
|
||||||
|
|
||||||
|
g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)SimulatorWin::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 SimulatorWin::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();
|
||||||
|
|
||||||
|
if ((data == "CLOSE_MENU") || (data == "EXIT_MENU"))
|
||||||
|
{
|
||||||
|
_instance->quit();
|
||||||
|
}
|
||||||
|
else if (data == "REFRESH_MENU")
|
||||||
|
{
|
||||||
|
_instance->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(_instance->getPositionX(), _instance->getPositionY()));
|
||||||
|
_instance->openProjectWithProjectConfig(project);
|
||||||
|
}
|
||||||
|
else if (data == "DIRECTION_PORTRAIT_MENU")
|
||||||
|
{
|
||||||
|
project.changeFrameOrientationToPortait();
|
||||||
|
_instance->openProjectWithProjectConfig(project);
|
||||||
|
}
|
||||||
|
else if (data == "DIRECTION_LANDSCAPE_MENU")
|
||||||
|
{
|
||||||
|
project.changeFrameOrientationToLandscape();
|
||||||
|
_instance->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 SimulatorWin::setZoom(float frameScale)
|
||||||
|
{
|
||||||
|
_project.setFrameScale(frameScale);
|
||||||
|
cocos2d::Director::getInstance()->getOpenGLView()->setFrameZoomFactor(frameScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug log
|
||||||
|
void SimulatorWin::writeDebugLog(const char *log)
|
||||||
|
{
|
||||||
|
if (!_writeDebugLogFile) return;
|
||||||
|
|
||||||
|
fputs(log, _writeDebugLogFile);
|
||||||
|
fputc('\n', _writeDebugLogFile);
|
||||||
|
fflush(_writeDebugLogFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::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();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config.changeFrameOrientationToPortait();
|
||||||
|
}
|
||||||
|
config.setScriptFile(parser->getEntryFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// D:\aaa\bbb\ccc\ddd\abc.txt --> D:/aaa/bbb/ccc/ddd/abc.txt
|
||||||
|
//
|
||||||
|
std::string SimulatorWin::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 SimulatorWin::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* SimulatorWin::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 SimulatorWin::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 SimulatorWin::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 SimulatorWin::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);
|
||||||
|
auto menuService = dynamic_cast<player::PlayerMenuServiceWin*> (player::PlayerProtocol::getInstance()->getMenuService());
|
||||||
|
auto menuItem = 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)
|
||||||
|
{
|
||||||
|
_instance->relaunch();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WM_COPYDATA:
|
||||||
|
{
|
||||||
|
PCOPYDATASTRUCT pMyCDS = (PCOPYDATASTRUCT) lParam;
|
||||||
|
if (pMyCDS->dwData == 1)
|
||||||
|
{
|
||||||
|
const char *szBuf = (const char*)(pMyCDS->lpData);
|
||||||
|
SimulatorWin::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 = SimulatorWin::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);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "Resource.h"
|
||||||
|
#include "cocos2d.h"
|
||||||
|
#include "AppDelegate.h"
|
||||||
|
#include "ProjectConfig/ProjectConfig.h"
|
||||||
|
#include "ProjectConfig/SimulatorConfig.h"
|
||||||
|
|
||||||
|
class SimulatorWin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static SimulatorWin *getInstance();
|
||||||
|
virtual ~SimulatorWin();
|
||||||
|
int run();
|
||||||
|
|
||||||
|
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:
|
||||||
|
SimulatorWin();
|
||||||
|
|
||||||
|
static SimulatorWin *_instance;
|
||||||
|
ProjectConfig _project;
|
||||||
|
HWND _hwnd;
|
||||||
|
HWND _hwndConsole;
|
||||||
|
AppDelegate *_app;
|
||||||
|
FILE *_writeDebugLogFile;
|
||||||
|
|
||||||
|
//
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// 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
|
|
@ -0,0 +1,21 @@
|
||||||
|
// 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
|
|
@ -0,0 +1,8 @@
|
||||||
|
#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>
|
|
@ -0,0 +1,137 @@
|
||||||
|
#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
|
|
@ -0,0 +1,98 @@
|
||||||
|
|
||||||
|
#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
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
#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_
|
|
@ -0,0 +1,265 @@
|
||||||
|
|
||||||
|
#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
|
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
#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_
|
|
@ -0,0 +1,351 @@
|
||||||
|
|
||||||
|
#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
|
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
#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_
|
|
@ -0,0 +1,67 @@
|
||||||
|
|
||||||
|
#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
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
#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_
|
|
@ -0,0 +1,272 @@
|
||||||
|
|
||||||
|
#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
|
|
@ -0,0 +1,65 @@
|
||||||
|
|
||||||
|
#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_
|
|
@ -0,0 +1,68 @@
|
||||||
|
|
||||||
|
#include "PlayerWin.h"
|
||||||
|
|
||||||
|
USING_NS_CC;
|
||||||
|
PLAYER_NS_BEGIN
|
||||||
|
|
||||||
|
PlayerWin::PlayerWin()
|
||||||
|
: PlayerProtocol()
|
||||||
|
, _messageBoxService(nullptr)
|
||||||
|
, _menuService(nullptr)
|
||||||
|
, _editboxService(nullptr)
|
||||||
|
, _taskService(nullptr)
|
||||||
|
, _hwnd(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerWin::~PlayerWin()
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(_menuService);
|
||||||
|
CC_SAFE_DELETE(_messageBoxService);
|
||||||
|
CC_SAFE_DELETE(_fileDialogService);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerWin *PlayerWin::createWithHwnd(HWND hWnd)
|
||||||
|
{
|
||||||
|
auto instance = new PlayerWin();
|
||||||
|
instance->_hwnd = hWnd;
|
||||||
|
instance->initServices();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
PLAYER_NS_END
|
|
@ -0,0 +1,43 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cocos2d.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 *createWithHwnd(HWND hWnd);
|
||||||
|
virtual ~PlayerWin();
|
||||||
|
|
||||||
|
virtual PlayerFileDialogServiceProtocol *getFileDialogService();
|
||||||
|
virtual PlayerMessageBoxServiceProtocol *getMessageBoxService();
|
||||||
|
virtual PlayerMenuServiceProtocol *getMenuService();
|
||||||
|
virtual PlayerEditBoxServiceProtocol *getEditBoxService();
|
||||||
|
virtual PlayerTaskServiceProtocol *getTaskService();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PlayerWin();
|
||||||
|
|
||||||
|
// services
|
||||||
|
void initServices();
|
||||||
|
|
||||||
|
PlayerMenuServiceWin *_menuService;
|
||||||
|
PlayerMessageBoxServiceWin *_messageBoxService;
|
||||||
|
PlayerFileDialogServiceWin *_fileDialogService;
|
||||||
|
PlayerEditBoxServiceWin *_editboxService;
|
||||||
|
PlayerTaskServiceWin *_taskService;
|
||||||
|
|
||||||
|
HWND _hwnd;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
PLAYER_NS_END
|
|
@ -0,0 +1,795 @@
|
||||||
|
|
||||||
|
#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 "SimulatorWin.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimulatorWin *SimulatorWin::_instance = nullptr;
|
||||||
|
|
||||||
|
SimulatorWin *SimulatorWin::getInstance()
|
||||||
|
{
|
||||||
|
if (!_instance)
|
||||||
|
{
|
||||||
|
_instance = new SimulatorWin();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
SimulatorWin::SimulatorWin()
|
||||||
|
: _app(nullptr)
|
||||||
|
, _hwnd(NULL)
|
||||||
|
, _hwndConsole(NULL)
|
||||||
|
, _writeDebugLogFile(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SimulatorWin::~SimulatorWin()
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(_app);
|
||||||
|
if (_writeDebugLogFile)
|
||||||
|
{
|
||||||
|
fclose(_writeDebugLogFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::quit()
|
||||||
|
{
|
||||||
|
Director::getInstance()->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::relaunch()
|
||||||
|
{
|
||||||
|
_project.setWindowOffset(Vec2(getPositionX(), getPositionY()));
|
||||||
|
openNewPlayerWithProjectConfig(_project);
|
||||||
|
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::openNewPlayer()
|
||||||
|
{
|
||||||
|
openNewPlayerWithProjectConfig(_project);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::openNewPlayerWithProjectConfig(const ProjectConfig &config)
|
||||||
|
{
|
||||||
|
static long taskid = 100;
|
||||||
|
stringstream buf;
|
||||||
|
buf << taskid++;
|
||||||
|
|
||||||
|
string commandLine;
|
||||||
|
commandLine.append(getApplicationExePath());
|
||||||
|
commandLine.append(" ");
|
||||||
|
commandLine.append(config.makeCommandLine());
|
||||||
|
|
||||||
|
CCLOG("SimulatorWin::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 SimulatorWin::openProjectWithProjectConfig(const ProjectConfig &config)
|
||||||
|
{
|
||||||
|
openNewPlayerWithProjectConfig(config);
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorWin::getPositionX()
|
||||||
|
{
|
||||||
|
RECT rect;
|
||||||
|
GetWindowRect(_hwnd, &rect);
|
||||||
|
return rect.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorWin::getPositionY()
|
||||||
|
{
|
||||||
|
RECT rect;
|
||||||
|
GetWindowRect(_hwnd, &rect);
|
||||||
|
return rect.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SimulatorWin::run()
|
||||||
|
{
|
||||||
|
auto player = player::PlayerWin::create();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)SimulatorWin::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 SimulatorWin::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 SimulatorWin::setZoom(float frameScale)
|
||||||
|
{
|
||||||
|
_project.setFrameScale(frameScale);
|
||||||
|
cocos2d::Director::getInstance()->getOpenGLView()->setFrameZoomFactor(frameScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug log
|
||||||
|
void SimulatorWin::writeDebugLog(const char *log)
|
||||||
|
{
|
||||||
|
if (!_writeDebugLogFile) return;
|
||||||
|
|
||||||
|
fputs(log, _writeDebugLogFile);
|
||||||
|
fputc('\n', _writeDebugLogFile);
|
||||||
|
fflush(_writeDebugLogFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimulatorWin::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 SimulatorWin::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 SimulatorWin::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* SimulatorWin::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 SimulatorWin::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 SimulatorWin::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 SimulatorWin::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);
|
||||||
|
SimulatorWin::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 = SimulatorWin::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
|
|
@ -0,0 +1,54 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "Resource.h"
|
||||||
|
#include "cocos2d.h"
|
||||||
|
#include "AppDelegate.h"
|
||||||
|
#include "ProjectConfig/ProjectConfig.h"
|
||||||
|
#include "ProjectConfig/SimulatorConfig.h"
|
||||||
|
|
||||||
|
class SimulatorWin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static SimulatorWin *getInstance();
|
||||||
|
virtual ~SimulatorWin();
|
||||||
|
int run();
|
||||||
|
|
||||||
|
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:
|
||||||
|
SimulatorWin();
|
||||||
|
|
||||||
|
static SimulatorWin *_instance;
|
||||||
|
ProjectConfig _project;
|
||||||
|
HWND _hwnd;
|
||||||
|
HWND _hwndConsole;
|
||||||
|
AppDelegate *_app;
|
||||||
|
FILE *_writeDebugLogFile;
|
||||||
|
|
||||||
|
//
|
||||||
|
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
|
|
@ -0,0 +1,19 @@
|
||||||
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
LOCAL_MODULE := cocos2d_simulator_static
|
||||||
|
|
||||||
|
LOCAL_MODULE_FILENAME := libsimulator
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES := \
|
||||||
|
../lib/ProjectConfig/ProjectConfig.cpp \
|
||||||
|
../lib/ProjectConfig/SimulatorConfig.cpp
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../lib
|
||||||
|
|
||||||
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../lib
|
||||||
|
|
||||||
|
LOCAL_STATIC_LIBRARIES := cocos2d_lua_static
|
||||||
|
|
||||||
|
include $(BUILD_STATIC_LIBRARY)
|
|
@ -0,0 +1,137 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>{001B324A-BB91-4E83-875C-C92F75C40857}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>libsimulator</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v120</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v120</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
<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="..\..\..\..\cocos\2d\cocos2dx.props" />
|
||||||
|
<Import Project="..\..\..\..\cocos\2d\cocos2d_headers.props" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS_DEBUG;COCOS2D_DEBUG=1;GLFW_EXPOSE_NATIVE_WIN32;GLFW_EXPOSE_NATIVE_WGL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>
|
||||||
|
</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..\lib;$(ProjectDir)..\lib\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)tools\simulator\libsimulator\lib;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<DisableSpecificWarnings>4267;4251;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||||
|
<CompileAs>CompileAsCpp</CompileAs>
|
||||||
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<ForcedIncludeFiles>algorithm</ForcedIncludeFiles>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\lib\cocos2dx_extra.h" />
|
||||||
|
<ClInclude Include="..\lib\network\CCHTTPRequest.h" />
|
||||||
|
<ClInclude Include="..\lib\network\CCHTTPRequestDelegate.h" />
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerEditBoxServiceWin.h" />
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerFileDialogServiceWin.h" />
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerMenuServiceWin.h" />
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerMessageBoxServiceWin.h" />
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerTaskServiceWin.h" />
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerWin.h" />
|
||||||
|
<ClInclude Include="..\lib\ProjectConfig\ProjectConfig.h" />
|
||||||
|
<ClInclude Include="..\lib\ProjectConfig\SimulatorConfig.h" />
|
||||||
|
<ClInclude Include="..\lib\service\AppEvent.h" />
|
||||||
|
<ClInclude Include="..\lib\service\AppLang.h" />
|
||||||
|
<ClInclude Include="..\lib\service\DeviceEx.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerEditBoxServiceProtocol.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerFileDialogServiceProtocol.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerMacros.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerMenuServiceProtocol.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerMessageBoxServiceProtocol.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerProtocol.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerServiceProtocol.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerSettings.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerTaskServiceProtocol.h" />
|
||||||
|
<ClInclude Include="..\lib\service\PlayerUtils.h" />
|
||||||
|
<ClInclude Include="stdafx.h" />
|
||||||
|
<ClInclude Include="targetver.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\lib\network\CCHTTPRequest.cpp" />
|
||||||
|
<ClCompile Include="..\lib\platform\win32\DeviceEx-win32.cpp" />
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerEditBoxServiceWin.cpp" />
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerFileDialogServiceWin.cpp" />
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerMenuServiceWin.cpp" />
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerMessageBoxServiceWin.cpp" />
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerTaskServiceWin.cpp" />
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerWin.cpp" />
|
||||||
|
<ClCompile Include="..\lib\ProjectConfig\ProjectConfig.cpp" />
|
||||||
|
<ClCompile Include="..\lib\ProjectConfig\SimulatorConfig.cpp" />
|
||||||
|
<ClCompile Include="..\lib\service\AppEvent.cpp" />
|
||||||
|
<ClCompile Include="..\lib\service\AppLang.cpp" />
|
||||||
|
<ClCompile Include="..\lib\service\PlayerMenuServiceProtocol.cpp" />
|
||||||
|
<ClCompile Include="..\lib\service\PlayerProtocol.cpp" />
|
||||||
|
<ClCompile Include="..\lib\service\PlayerServiceProtocol.cpp" />
|
||||||
|
<ClCompile Include="..\lib\service\PlayerSettings.cpp" />
|
||||||
|
<ClCompile Include="..\lib\service\PlayerTaskServiceProtocol.cpp" />
|
||||||
|
<ClCompile Include="..\lib\service\PlayerUtils.cpp" />
|
||||||
|
<ClCompile Include="stdafx.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,155 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="network">
|
||||||
|
<UniqueIdentifier>{2c74ba1d-1959-47a0-a821-7442ff714dbb}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="service">
|
||||||
|
<UniqueIdentifier>{4f295ca0-5110-4f3a-9c39-d5299950cdb6}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="ProjectConfig">
|
||||||
|
<UniqueIdentifier>{b2915876-d3ac-4a5b-8b5d-51b974f58a61}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="platform">
|
||||||
|
<UniqueIdentifier>{d2596198-3717-4acf-bdd8-0a97447a2ab9}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="platform\win32">
|
||||||
|
<UniqueIdentifier>{83fb01cd-6985-4d45-a797-da585ec17316}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\lib\network\CCHTTPRequest.h">
|
||||||
|
<Filter>network</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\network\CCHTTPRequestDelegate.h">
|
||||||
|
<Filter>network</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\ProjectConfig\ProjectConfig.h">
|
||||||
|
<Filter>ProjectConfig</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\ProjectConfig\SimulatorConfig.h">
|
||||||
|
<Filter>ProjectConfig</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\AppEvent.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\AppLang.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\DeviceEx.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerEditBoxServiceProtocol.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerFileDialogServiceProtocol.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerMacros.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerMenuServiceProtocol.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerMessageBoxServiceProtocol.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerProtocol.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerServiceProtocol.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerSettings.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerTaskServiceProtocol.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\service\PlayerUtils.h">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerEditBoxServiceWin.h">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerFileDialogServiceWin.h">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerMenuServiceWin.h">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerMessageBoxServiceWin.h">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerTaskServiceWin.h">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\platform\win32\PlayerWin.h">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\lib\cocos2dx_extra.h" />
|
||||||
|
<ClInclude Include="stdafx.h" />
|
||||||
|
<ClInclude Include="targetver.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\lib\network\CCHTTPRequest.cpp">
|
||||||
|
<Filter>network</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\ProjectConfig\ProjectConfig.cpp">
|
||||||
|
<Filter>ProjectConfig</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\ProjectConfig\SimulatorConfig.cpp">
|
||||||
|
<Filter>ProjectConfig</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\service\AppEvent.cpp">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\service\AppLang.cpp">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\service\PlayerMenuServiceProtocol.cpp">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\service\PlayerProtocol.cpp">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\service\PlayerServiceProtocol.cpp">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\service\PlayerSettings.cpp">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\service\PlayerTaskServiceProtocol.cpp">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\service\PlayerUtils.cpp">
|
||||||
|
<Filter>service</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\platform\win32\DeviceEx-win32.cpp">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerEditBoxServiceWin.cpp">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerFileDialogServiceWin.cpp">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerMenuServiceWin.cpp">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerMessageBoxServiceWin.cpp">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerTaskServiceWin.cpp">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\lib\platform\win32\PlayerWin.cpp">
|
||||||
|
<Filter>platform\win32</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="stdafx.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
// 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
|
|
@ -0,0 +1,21 @@
|
||||||
|
// 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
|
|
@ -0,0 +1,8 @@
|
||||||
|
#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>
|
Loading…
Reference in New Issue