-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
513 lines (409 loc) · 16.6 KB
/
main.cpp
File metadata and controls
513 lines (409 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
#include "mainwindow.h"
#include <QApplication>
#include <QSettings>
#include "global.h"
#include <QDesktopWidget>
#include <QApplication>
#include <QFontDatabase>
#include <QTextCodec>
#include "windowinidialog.h"
#include "log.h"
#if defined(Q_OS_ANDROID)
#include<QtAndroidExtras/QAndroidJniObject>
#include<QtAndroidExtras/QAndroidJniEnvironment>
#include<QtAndroidExtras/QtAndroid>
#include <QDir>
#include "log.h"
//#include <QtAndroidExtras>
using namespace QtAndroid;
#elif defined (Q_OS_IOS)
#include "ios-sources/src/viewRoute.h"
#include <QDir>
#endif
//PaintWidget qobj;
int g_screenwidth = 0;
int g_screenheight = 0;
double g_screentimes = 1.0;
int g_gameviewleft = 0;
int g_gameviewright = 0;
int g_gameviewtop = 0;
int g_gameviewbottom = 0;
int g_gameviewlefta = 0;
int g_gameviewrighta = 0;
#if defined(Q_OS_WIN32)||defined(Q_OS_WASM)
int g_gameviewdirect = 0;//0;//0-横屏 1-竖屏
#else
int g_gameviewdirect = 1;//0;//0-横屏 1-竖屏
#endif
int g_Fontsize = 0;//字体大小
extern int g_showPicType;
extern int g_useDotFont;
extern int g_HighAtt;
extern int g_autoSave;
extern int g_allowUpdate;
extern int g_touchEnable ;
extern int g_layerKey;
extern int g_fullScreen;
extern QColor g_backColor;
extern int g_useMOD;
QString androidFont;
int version_now = 180701300;
QString title = QObject::tr("天际边三国霸业");
QString startUpIniPath;
QString versionIniPath;
//QString modverIniPath;
#include <QApplication>
#include <QDebug>
#include <windows.h>
void attachConsole() {
if (AllocConsole()) {
FILE* fp;
freopen_s(&fp, "CONOUT$", "w", stdout); // Redirect stdout to console
freopen_s(&fp, "CONOUT$", "w", stderr); // Redirect stderr to console
}
}
int main(int argc, char *argv[])
{
QTextCodec *codec = QTextCodec::codecForName("GB18030");//情况2
QTextCodec::setCodecForLocale(codec);
#if defined(Q_OS_ANDROID)
//20180609 从内部存储到SD卡
QAndroidJniObject externalStorageDir = QAndroidJniObject::callStaticObjectMethod(
"android/os/Environment",
"getExternalStorageDirectory",
"()Ljava/io/File;"
);
QString fullPath = QString("%1/skyside3gby3/").arg(externalStorageDir.toString());
QDir dir(fullPath);
if(!dir.exists())
{
dir.mkdir(fullPath);
}
QString fontPath = QString("%1/skyside3gby3/font.bin").arg(externalStorageDir.toString());
if(!QFile::exists(fontPath))
{
QFile::copy("assets:/font.bin",fontPath);
QFile fileDest(fontPath);
fileDest.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadUser|QFile::WriteUser|QFile::ExeUser|QFile::ReadGroup|QFile::WriteGroup|QFile::ExeGroup|QFile::ReadOther|QFile::WriteOther|QFile::ExeOther);
}
QString datlibPath = QString("%1/skyside3gby3/dat.lib").arg(externalStorageDir.toString());
if(!QFile::exists(datlibPath))
{
QFile::copy("assets:/dat.lib",datlibPath);
QFile fileDest(datlibPath);
fileDest.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadUser|QFile::WriteUser|QFile::ExeUser|QFile::ReadGroup|QFile::WriteGroup|QFile::ExeGroup|QFile::ReadOther|QFile::WriteOther|QFile::ExeOther);
}
QString resrlbPath = QString("%1/skyside3gby3/res.rlb").arg(externalStorageDir.toString());
//if(!QFile::exists("res.rlb"))//下个版本需要取消注释
{
QFile::copy("assets:/res.rlb",resrlbPath);
QFile fileDest2(resrlbPath);
fileDest2.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadUser|QFile::WriteUser|QFile::ExeUser|QFile::ReadGroup|QFile::WriteGroup|QFile::ExeGroup|QFile::ReadOther|QFile::WriteOther|QFile::ExeOther);
}
QString datmodPath = QString("%1/skyside3gby3/dat.mod").arg(externalStorageDir.toString());
/*if(!QFile::exists("dat.mod"))//下个版本需要取消注释
{
QFile::copy("assets:/dat.mod",datmodPath);
QFile fileDest3(datmodPath);
fileDest3.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadUser|QFile::WriteUser|QFile::ExeUser|QFile::ReadGroup|QFile::WriteGroup|QFile::ExeGroup|QFile::ReadOther|QFile::WriteOther|QFile::ExeOther);
}*/
QString startupiniPath = QString("%1/skyside3gby3/startup.ini").arg(externalStorageDir.toString());
if(!QFile::exists(startupiniPath))
{
QFile::copy("assets:/startup.ini",startupiniPath);
QFile fileDest(startupiniPath);
fileDest.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadUser|QFile::WriteUser|QFile::ExeUser|QFile::ReadGroup|QFile::WriteGroup|QFile::ExeGroup|QFile::ReadOther|QFile::WriteOther|QFile::ExeOther);
}
QString versioniniPath = QString("%1/skyside3gby3/version.ini").arg(externalStorageDir.toString());
if(QFile::exists(versioniniPath))//下个版本需要取消注释
{
QFile::remove(versioniniPath);
}
QFile::copy("assets:/version.ini",versioniniPath);
QFile fileDest(versioniniPath);
fileDest.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadUser|QFile::WriteUser|QFile::ExeUser|QFile::ReadGroup|QFile::WriteGroup|QFile::ExeGroup|QFile::ReadOther|QFile::WriteOther|QFile::ExeOther);
//QString modveriniPath = QString("%1/skyside3gby3/modver.ini").arg(externalStorageDir.toString());
//QFile::copy("assets:/modver.ini",versioniniPath);
//QFile fileDest1(modveriniPath);
//fileDest1.setPermissions(QFile::ReadOwner|QFile::WriteOwner|QFile::ExeOwner|QFile::ReadUser|QFile::WriteUser|QFile::ExeUser|QFile::ReadGroup|QFile::WriteGroup|QFile::ExeGroup|QFile::ReadOther|QFile::WriteOther|QFile::ExeOther);
#endif
QApplication a(argc, argv);
attachConsole();
logMessageFromCpp("test log");
//MainWindow m;
//m.show();
int fontId = QFontDatabase::addApplicationFont("DroidSansFallback.ttf");
logMessageFromCppFormat("font id %d", fontId);
//将字体Id传给applicationFontFamilies,得到一个QStringList,其中的第一个元素为新添加字体的family
androidFont = QFontDatabase::applicationFontFamilies(fontId).at(0);
QFont font(androidFont);
QGuiApplication::setFont(font);
#if defined(Q_OS_ANDROID)
startUpIniPath = startupiniPath ;
versionIniPath = versioniniPath ;
//modverIniPath = modveriniPath ;
#elif defined(Q_OS_IOS)
startUpIniPath = QDir::homePath() +"/Documents/srartup.ini";
versionIniPath = QDir::homePath() +"/Documents/version.ini";
//modverIniPath = "modver.ini";
#elif defined(Q_OS_WIN32)||defined(Q_OS_WASM)
startUpIniPath ="startup.ini";
versionIniPath ="version.ini";
//modverIniPath = "modver.ini";
#endif
QSettings *configIniStartUp = new QSettings(startUpIniPath, QSettings::IniFormat);
QSettings *configIniVersion = new QSettings(versionIniPath, QSettings::IniFormat);
configIniVersion->setIniCodec("GB2312");
//20190502先读取StartUp中mod配置文件
g_useMOD = 0;//configIniStartUp->value("/Mod/UseMod",0).toInt();
//将读取到的ini文件保存在QString中,先取值,然后通过toString()函数转换成QString类型
int widthx = configIniStartUp->value("/Startup/Width",800).toInt();
int heighty = configIniStartUp->value("/Startup/Height",600).toInt();
version_now = configIniVersion->value("/Startup/Version",180701300).toInt();
int color=configIniStartUp->value("/Startup/Color",0).toInt();
g_showPicType = 0; //change
if(g_showPicType == 1)g_showPicType = 2;
int backcolor=configIniStartUp->value("/Startup/BackColor",0).toInt();
if(backcolor == 0)
{
g_backColor = Qt::white;
}
else if(backcolor == 1)
{
g_backColor = QColor(132,132,132);
}
else if(backcolor == 2)
{
g_backColor = QColor(204,232,207);
}
else if(backcolor == 3)
{
g_backColor = QColor(148,198,221);
}
else if(backcolor == 4)
{
g_backColor = QColor(198,151,81);
}
int screen = configIniStartUp->value("/Startup/Screen",0).toInt();
int KeyReturn=configIniStartUp->value("/Key/Return",13).toInt();
int KeyEsc=configIniStartUp->value("/Key/Esc",27).toInt();
int KeySpace=configIniStartUp->value("/Key/Space",32).toInt();
int KeyHome=configIniStartUp->value("/Key/Home",36).toInt();
int KeyUp0=configIniStartUp->value("/Key/Up",38).toInt();
int KeyDown0=configIniStartUp->value("/Key/Down",40).toInt();
int KeyLeft0=configIniStartUp->value("/Key/Left",37).toInt();
int KeyRight0=configIniStartUp->value("/Key/Right",39).toInt();
int KeyEnable = configIniStartUp->value("/Startup/UseKey",1).toInt();
int MouseEnable = configIniStartUp->value("/Startup/UseMouse",1).toInt();
int DebugEnable = configIniStartUp->value("/Debug/Enable",0).toInt();
title = configIniVersion->value("/Startup/Title",QObject::tr("天际边三国霸业")).toString();
g_useDotFont = configIniStartUp->value("/Startup/UseDotFont",0).toInt();
g_HighAtt = configIniStartUp->value("/Startup/HighAtt",0).toInt();
g_autoSave = configIniStartUp->value("/Startup/AutoSave",1).toInt();
g_gameviewdirect = configIniStartUp->value("/Startup/ShowWay",1).toInt();
g_allowUpdate = configIniStartUp->value("/Startup/AllowUpdate",1).toInt();
g_touchEnable = configIniStartUp->value("/Startup/UseMouse",1).toInt();
g_layerKey = configIniStartUp->value("/Startup/LayerKey",0).toInt();
g_fullScreen = configIniStartUp->value("/Startup/FullScreen",0).toInt();
#if defined(Q_OS_ANDROID)
QAndroidJniEnvironment env;
QAndroidJniObject activity = androidActivity();
jint orient = activity.callMethod<jint>( "getRequestedOrientation" );
if(env->ExceptionCheck())
{
env->ExceptionClear();
}
activity.callMethod<void>("setRequestedOrientation", "(I)V", g_gameviewdirect);
if(env->ExceptionCheck())
{
env->ExceptionClear();
}
#elif defined(Q_OS_IOS)
routeView(g_gameviewdirect);
#elif defined(Q_OS_WIN32)||defined(Q_OS_WASM)
g_gameviewdirect = 0;//0;//0-横屏 1-竖屏
#endif
delete configIniStartUp;
delete configIniVersion;
#if defined(Q_OS_WIN32)||defined(Q_OS_WASM)
QString version;
version.sprintf(" ver%d.%01d.%01d",version_now%1000/100,version_now%100/10,version_now%10);
title = title + version;
QIcon icon(":/images/icon1.ico");//"Res/icon1.ico");
getGlobalWidget()->setWindowIcon(icon);
getGlobalWidget()->setWindowTitle(title);
//窗口大小
if(screen == 0)
{
g_screenwidth = widthx;
g_screenheight = heighty;
getGlobalWidget()->setFixedSize(g_screenwidth,g_screenheight);
}
else
{
QDesktopWidget *deskWgt = QApplication::desktop();
if (deskWgt)
{
g_screenwidth = deskWgt->width();
g_screenheight = deskWgt->height()-100;
}
getGlobalWidget()->setFixedSize(g_screenwidth,g_screenheight);
getGlobalWidget()->showFullScreen();
}
#elif defined(Q_OS_ANDROID)
QDesktopWidget *deskWgt = QApplication::desktop();
if (deskWgt)
{
g_screenwidth = deskWgt->width();
g_screenheight = deskWgt->height();//-100;//去除状态栏影响
}
if(g_gameviewdirect == 0)
{
int tmp1 = g_screenwidth;
g_screenwidth = g_screenheight;
g_screenheight = tmp1;
}
getGlobalWidget()->setFixedSize(g_screenwidth,g_screenheight);
#elif defined(Q_OS_IOS)
QDesktopWidget *deskWgt = QApplication::desktop();
if (deskWgt)
{
g_screenwidth = deskWgt->width();
g_screenheight = deskWgt->height();//去除菜单栏影响
}
if(g_gameviewdirect == 0)
{
int tmp1 = g_screenwidth;
g_screenwidth = g_screenheight;
g_screenheight = tmp1;
}
getGlobalWidget()->setFixedSize(g_screenwidth,g_screenheight);
#endif
if(g_gameviewdirect == 0)//横屏
{
#if defined(Q_OS_WIN32)||defined(Q_OS_WASM)
g_gameviewleft = 0;
g_gameviewtop = 50;
g_gameviewright = g_screenwidth;
int t_width = g_screenwidth;
g_gameviewbottom = t_width/5*3+50;//g_screenheight;
g_screentimes = (double)t_width/160.0;
#elif defined(Q_OS_ANDROID)
//先划分区域比例为1:6:1
int t_widthm8 = g_screenwidth/8;
g_gameviewleft = t_widthm8;
if(g_gameviewleft < 100) g_gameviewleft = 100;
g_gameviewleft += (screen * 50);//20180713
t_widthm8 = g_gameviewleft;
g_gameviewright = g_screenwidth - g_gameviewleft;
int t_width = g_screenwidth - 2 * g_gameviewleft;
int t_height = t_width/5*3;
while(t_height>g_screenheight)
{
g_gameviewleft+=10;
g_gameviewright-=10;
t_width = g_screenwidth - 2 * g_gameviewleft;
t_height = t_width/5*3;
}
g_gameviewtop = (g_screenheight - t_height)/2;
g_gameviewbottom = g_gameviewtop + t_height;
g_screentimes = (double)t_width/160.0;
//20180810
g_gameviewlefta = g_gameviewleft;
g_gameviewrighta = g_gameviewright;
/*g_gameviewleft = (g_screenwidth - g_screenheight*5/3 )/2;
if(g_gameviewleft < 100) g_gameviewleft = 100;
g_gameviewright = g_screenwidth - g_gameviewleft;
int t_width = g_screenwidth - 2 * g_gameviewleft;
g_screentimes = (double)t_width/160.0;
g_gameviewtop =0;
g_gameviewbottom = t_width/5*3;//g_screenheight;*/
#elif defined(Q_OS_IOS)
//先划分区域比例为1:6:1
int t_widthm8 = g_screenwidth/8;
g_gameviewleft = t_widthm8;
if(g_gameviewleft < 100) g_gameviewleft = 100;
g_gameviewleft += (screen * 50);//20180713
t_widthm8 = g_gameviewleft;
g_gameviewright = g_screenwidth - g_gameviewleft;
int t_width = g_screenwidth - 2 * g_gameviewleft;
int t_height = t_width/5*3;
while(t_height>g_screenheight)
{
g_gameviewleft+=10;
g_gameviewright-=10;
t_width = g_screenwidth - 2 * g_gameviewleft;
t_height = t_width/5*3;
}
g_gameviewtop = 30;
g_gameviewbottom = g_gameviewtop + t_height;
g_screentimes = (double)t_width/160.0;
#endif
}
else if (g_gameviewdirect == 1)//竖屏 默认
{
#if defined(Q_OS_WIN32)||defined(Q_OS_WASM)//windows不存在竖屏。如果有 按横屏处理
g_gameviewleft = 0;
g_gameviewtop = 50;
g_gameviewright = g_screenwidth;
int t_width = g_screenwidth;
g_gameviewbottom = t_width/5*3+50;//g_screenheight;
#elif defined(Q_OS_ANDROID)
g_gameviewleft = 0;
g_gameviewright = g_screenwidth;
g_gameviewtop = 0;//已去除状态栏
g_gameviewbottom = g_screenwidth*3/5;
g_screentimes = (double)g_screenwidth/160.0;
#elif defined(Q_OS_IOS)
g_gameviewleft = 0;
g_gameviewright = g_screenwidth;
g_gameviewtop = 30;//已去除状态栏
g_gameviewbottom = g_screenwidth*3/5;
g_screentimes = (double)g_screenwidth/160.0;
#endif
}
/*
if(g_screenwidth *3/5>= g_screenheight)
{
g_gameviewdirect = 0;
g_gameviewleft = (g_screenwidth - g_screenheight*5/3 )/2;
if(g_gameviewleft < 100) g_gameviewleft = 100;
g_gameviewright = g_screenwidth - g_gameviewleft;
g_screentimes = (double)g_screenheight/96.0;//左右有空间
g_gameviewtop =0;
g_gameviewbottom = g_screenheight;
}
else
{
g_gameviewdirect = 1;
g_screentimes = (double)g_screenwidth/160.0;//上下有空间
g_gameviewleft = 0;
g_gameviewright = g_screenwidth;
g_gameviewtop = 0;
g_gameviewbottom = g_screenwidth*3/5;
}*/
g_Fontsize = 1;
int heightOfBt = 14 *g_screentimes ;
while(true)
{
QFont tmp(androidFont, g_Fontsize, QFont::Bold);
tmp.setPointSize(g_Fontsize);
QFontMetricsF fm(tmp);
qreal pixelsHigh = fm.height();
if (pixelsHigh == heightOfBt)
break;
if (pixelsHigh > heightOfBt)
{
--g_Fontsize;
break;
}
++g_Fontsize;
}
getGlobalWidget()->show();
getGlobalWidget()->grabGesture(Qt::PinchGesture);
getGlobalWidget()->grabGesture(Qt::TapAndHoldGesture);
// NewMenuWindow mainWindow;
// mainWindow.resize(400, 300);
// mainWindow.show();
return a.exec();
}