-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCuberXUnrealGUI.h
5620 lines (5429 loc) · 188 KB
/
CuberXUnrealGUI.h
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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef $CU_STANDARD
#define $CU_STANDARD
#include<iostream>
#include<Windows.h>
#include <thread>
#include <conio.h>
#include <cmath>
#include <mmsystem.h> //导入声音头文件库
#pragma comment(lib,"winmm.lib")//导入声音的链接库
#pragma message("Creating CuberX UnrealGUI")
//关闭开始动画
#define $CU_TURN_OFF_OPENING_ACTION
using namespace std;
//版本
static const string $CU_VERSION = "Beta 0.1.2";
//预声明
namespace cuberx
{
class MainWindow;
class Container;
class FPSText;
}// namespace cuberx
//Basic
namespace cuberx
{
class Base;
//窗口信息
class WindowInfo {
public:
//获取显示句柄
static HANDLE GetDisplayHandle()
{
return GetStdHandle(STD_OUTPUT_HANDLE);
}
};
//窗口设置
class WindowSetting {
private:
public:
WindowSetting()
{
//启动信息显示
#ifndef $CU_TURN_OFF_OPENING_ACTION
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
ColorSetting('F', 'C');
SetConsoleTextAttribute(handle, (unsigned)FOREGROUND_INTENSITY | (15u + 12u * 16u));
//设置窗口大小
WindowArea(120, 32);
Sleep(5);
//隐藏光标
setCursorVisition(false);
PointJump(10, 0);
cout
<< " ======== ======== " << endl
<< " ====== == ==== ==== " << endl
<< " === == == ===== == ===== ==== ==== " << endl
<< " === == == ======== == === ===== == ======= " << endl
<< " === == == === === ======== == ======= " << endl
<< " === == == == === === == = == ==== ==== " << endl
<< " ====== ====== ======= ====== = ==== ==== " << endl
<< " ======== ======== " << endl
<< " " << endl
<< " " << endl
<< " " << endl
<< " " << endl
<< " " << endl
<< " " << endl
<< " " << endl
<< " ";
PointJump(18, 35);
cout << "========= CuberX UnrealGUI (dev) =========";
PointJump(31, 0);
colorOut("VERSION= ", 7, 12);
colorOut($CU_VERSION, 7, 12);
PointJump(31, 127);
Sleep(800);
system("cls");
PointJump(0, 0);
ColorSetting('7', '0');
SetConsoleTextAttribute(handle, (unsigned)FOREGROUND_INTENSITY | 7u);
//显示光标
setCursorVisition(true);
#endif
//设置窗口大小
WindowArea(128, 32);
Sleep(5);
}
//窗口大小
static int WindowArea(short w, short h, bool ifcls = false)
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD size = {w, h};
SetConsoleScreenBufferSize(hOut, size);
SMALL_RECT rc = {0, 0, static_cast<SHORT>(w - 1), static_cast<SHORT>(h - 1)};
SetConsoleWindowInfo(hOut, 1, &rc);
if(ifcls == 1)
{
system("cls");
}
return 0;
}
//锁定窗口大小
static int LockWindow()
{
HWND hWnd = GetConsoleWindow();//获得cmd窗口句柄
RECT rc;
GetWindowRect(hWnd, &rc);//获得cmd窗口对应矩形
//改变cmd窗口风格
SetWindowLongPtr(hWnd, GWL_STYLE, (unsigned)GetWindowLong(hWnd, GWL_STYLE) & ~(unsigned)WS_THICKFRAME & ~(unsigned)WS_MAXIMIZEBOX & ~(unsigned)WS_MINIMIZEBOX);
//因为风格涉及到边框改变,必须调用SetWindowPos,否则无效果
SetWindowPos(hWnd, nullptr, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 0);
return 0;
}
//设置全局显示颜色
static int ColorSetting(char FontsColor = '7', char WindowColor = '0')
{
char SendStr[] = "color xx";
char *p_ch = SendStr + 6;
*p_ch = WindowColor;
*(++p_ch) = FontsColor;
system(SendStr);
return 0;
}
//光标跳转
static void PointJump(SHORT pawnH, SHORT pawnW, HANDLE handle = WindowInfo::GetDisplayHandle())
{
COORD PointPawn;
PointPawn.X = pawnW;//宽坐标
PointPawn.Y = pawnH;//高坐标
SetConsoleCursorPosition(handle, {static_cast<SHORT>(pawnW), static_cast<SHORT>(pawnH)});
}
/*彩色输出
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 10 = 淡绿色
3 = 浅蓝色 11 = 淡浅绿色
4 = 红色 12 = 淡红色
5 = 紫色 13 = 淡紫色
6 = 黄色 14 = 淡黄色
7 = 白色 15 = 亮白色
https://blog.csdn.net/qq_42885747/article/details/103835671?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control
*/
static void colorOut(const string &str, int FontsColorInt, int WindowColorInt)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, (unsigned)FOREGROUND_INTENSITY | ((unsigned)FontsColorInt + (unsigned)WindowColorInt * 16u));
cout << str;
SetConsoleTextAttribute(handle, (unsigned)FOREGROUND_INTENSITY | 7u);
}
//显示/隐藏光标
static void SetCursorVisible(bool visible)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
CursorInfo.bVisible = visible; //隐藏控制台光标
SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}
};
static WindowSetting winS;
//可以变量设置大小的数组(内存安全需注意)
template<class T>
class SuperArray {
private:
T **mem;
int HEIGHT;
int WIDTH;
bool ifON;
public:
SuperArray()
{
HEIGHT = 0;
WIDTH = 0;
ifON = false;
}
SuperArray(int height, int width)
{
HEIGHT = height;
WIDTH = width;
ifON = true;
mem = new T *[HEIGHT];
//数组mem[HEIGHT][WIDTH];
for(int i = 0; i < HEIGHT; i++)
{
mem[i] = new T[WIDTH];
}
}
void reset(int newHeight, int newWidth)
{
if(ifON == 1)
{
for(int i = 0; i < HEIGHT; i++)
{
delete[] mem[i];
mem[i] = 0;
}
delete[] mem;
mem = 0;
}
HEIGHT = newHeight;
WIDTH = newWidth;
ifON = true;
mem = new T *[HEIGHT];
//数组mem[HEIGHT][WIDTH];
for(int i = 0; i < HEIGHT; i++)
{
mem[i] = new T[WIDTH];
}
}
~SuperArray()
{
for(int i = 0; i < HEIGHT; i++)
{
delete[] mem[i];
mem[i] = nullptr;
}
delete[] mem;
mem = nullptr;
}
T *operator[](int a)
{
if(a < HEIGHT)
{
return mem[a];
}
else
{
return 0;
}
}
};
template<class T>
class SuperArray1 {
private:
T *mem;
int LENGTH;
bool ifON;
public:
SuperArray1()
{
LENGTH = 0;
ifON = false;
}
SuperArray1(int length)
{
LENGTH = length;
ifON = true;
mem = new T[LENGTH];
}
void reset(int newLength)
{
if(ifON)
{
delete[] mem;
mem = nullptr;
}
LENGTH = newLength;
ifON = true;
mem = new T [LENGTH];
}
~SuperArray1()
{
delete[] mem;
mem = nullptr;
}
T& operator[](int a)
{
return mem[a];
}
};
//指针工具
class PointerTool {
public:
template<class T>
inline static T P2TA2(T **p, UINT width, UINT y, UINT x)
{
return *((T *)p + y * width + x);
}
template<class T>
inline static T P2TA2(SuperArray<T> *p, UINT width, UINT y, UINT x)
{
return (*p)[y][x];
}
template<class T>
inline static T P2TA2(SuperArray<T> p, UINT width, UINT y, UINT x)
{
return p[y][x];
}
};
//位置信息
struct Coordinate {
short width = 0;
short height = 0;
short &x = width;
short &y = height;
Coordinate(short x, short y)
{
width = x;
height = y;
}
Coordinate() = default;
};
/* 色彩信息
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 10 = 淡绿色
3 = 浅绿色 11 = 淡浅绿色
4 = 红色 12 = 淡红色
5 = 紫色 13 = 淡紫色
6 = 黄色 14 = 淡黄色
7 = 白色 15 = 亮白色
https://blog.csdn.net/qq_42885747/article/details/103835671?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control
*/
struct ColorInfo {
//此处char是为了节省内存
char backGround = 0;
char font = 7;
};
//一个纯虚函数的包装
class CUFunction {
public:
//注意:表示Base对象的指针是this_base而不是this
virtual void func(Base *this_base) = 0;
};
//任务信息
class CUTask {
private:
unsigned short index; //序号
unsigned int tag; //标签
bool enable; //是否启用
void (*runFunc)(cuberx::Base *);//运行接口函数
cuberx::Base *RunClass; //运行接口对象
DWORD CountDownTick; //剩余时刻
public:
CUTask()
{
index = 0;
tag = 0;
runFunc = nullptr;
CountDownTick = 0;
RunClass = nullptr;
enable = false;
}
void setCountDownTick(DWORD newCountDownTick)
{
CountDownTick = newCountDownTick;
}
DWORD getCountDownTick() const
{
return CountDownTick;
}
void setIndex(unsigned short newIndex)
{
this->index = newIndex;
}
unsigned short getIndex() const
{
return index;
}
void setTag(unsigned int newTag)
{
tag = newTag;
}
unsigned int getTag() const
{
return tag;
}
void setRunFunc(void (*newRunFunc)(cuberx::Base *))
{
runFunc = newRunFunc;
}
bool getEnable() const
{
return enable;
}
void setEnable(bool ifEnable)
{
enable = ifEnable;
}
//获取运行函数前者为方法本身,(cuberx::Base*)为返回的函数的参数
void (*getRunFunc())(cuberx::Base *)
{
return runFunc;
}
void setRunClass(cuberx::Base *newRunClass)
{
RunClass = newRunClass;
}
//获取目标对象的指针
cuberx::Base *getRunClass()
{
return RunClass;
}
//将剩余时刻减少1
void countDown()
{
CountDownTick -= 1;
}
//运行该任务
void run()
{
//运行绑定的函数
runFunc(RunClass);
}
//清空任务
int reset()
{
index = 0;
tag = 0;
runFunc = nullptr;
RunClass = nullptr;
CountDownTick = 0;
setEnable(false);
return 0;
}
//设置任务
int set(cuberx::Base *NewRunClass, int NewTag, void (*NewRun)(cuberx::Base *) = nullptr, DWORD NewCountDownTick = 0, bool ifEnable = true)
{
tag = NewTag;
runFunc = NewRun;
RunClass = NewRunClass;
CountDownTick = NewCountDownTick;
enable = ifEnable;
return 0;
}
};
//键位信息
class Key {
public:
static const int $UP = 72;
static const int $DOWN = 80;
static const int $LEFT = 75;
static const int $RIGHT = 77;
static const int $SPACE = 32;
static const int $BACK_SPACE = 8;
static const int $ESC = 27;
static const int $ENTER = 13;
static const int $DELETE = 83;
static const int $INSERT = 82;
static const int $TAB = 3;
};
//键位任务
class KeyTask {
private:
int key{};
cuberx::Base *this_base{};
int (*run)(cuberx::Base *){};
public:
KeyTask() = default;
KeyTask(int key, cuberx::Base *this_base, int (*run)(cuberx::Base *))
{
this->key = key;
this->this_base = this_base;
this->run = run;
}
int Run()
{
if(run != nullptr)
{
return run(this_base);
}
}
void Reset()
{
this->key = 0;
this->this_base = nullptr;
this->run = nullptr;
}
void Set(int key, cuberx::Base *this_base, int (*run)(cuberx::Base *))
{
this->key = key;
this->this_base = this_base;
this->run = run;
}
bool Empty()
{
if(key == 0)
{
return true;
}
else
{
return false;
}
}
int GetKey()
{
return key;
}
void SetKey(int newKey)
{
key = newKey;
}
cuberx::Base *GetThisBase()
{
return this_base;
}
void SetThisBase(cuberx::Base *newThisBase)
{
this_base = newThisBase;
}
int (*GetRun())(cuberx::Base *)//返回值为函数指针的方法
{
return run;
}
};
//字符串工具
class StringTool {
public:
static string WCharToString(wchar_t *firstWChar)
{
//表示为单字节时长度
int charLength = WideCharToMultiByte(CP_OEMCP, 0, firstWChar, (int)wcslen(firstWChar), nullptr, 0, nullptr, nullptr);
char *finalChar = new char[(long long)charLength + (long long)1];
//转换
WideCharToMultiByte(CP_OEMCP, 0, firstWChar, (int)wcslen(firstWChar), finalChar, charLength, nullptr, nullptr);
finalChar[charLength] = '\0';
string result = finalChar;
delete[] finalChar;
return result;
}
//注意释放内存
static wchar_t *StringToWchar(const string &firstString)
{
const char *firstChar = firstString.c_str();
//第一次调用返回转换后的字符串长度,用于确认为wchar_t*开辟多大的内存空间
int WCharLeng = MultiByteToWideChar(CP_OEMCP, 0, firstChar, (int)strlen(firstChar) + 1, nullptr, 0);
auto *finalWChar = new wchar_t[WCharLeng];
//第二次调用将单字节字符串转换成双字节字符串
MultiByteToWideChar(CP_OEMCP, 0, firstChar, (int)strlen(firstChar) + 1, finalWChar, WCharLeng);
return finalWChar;
}
};
//基本类
class Base {
protected:
cuberx::Coordinate location{};
cuberx::Coordinate size{};
cuberx::Coordinate offset{};
cuberx::MainWindow *fatherMainWindow{};
cuberx::Container *fatherContainer{};
string text{};
bool beChosed{};
bool canBeChosed{};
bool bVisible{};
public:
Base()
{
text = " ";
canBeChosed = false;
beChosed = false;
bVisible = true;
fatherMainWindow = nullptr;
}
explicit Base(const string &newText)
{
text = newText;
canBeChosed = false;
beChosed = false;
bVisible = true;
fatherMainWindow = nullptr;
}
Base(short width, short height, short x, short y)
{
location.x = x;
location.y = y;
size.width = width;
size.height = height;
canBeChosed = false;
beChosed = false;
bVisible = true;
fatherMainWindow = nullptr;
}
Base(short width, short height)
{
size.width = width;
size.height = height;
canBeChosed = false;
beChosed = false;
bVisible = true;
fatherMainWindow = nullptr;
}
Base(const string &newText, short width, short height, short x, short y)
{
text = newText;
location.x = x;
location.y = y;
size.width = width;
size.height = height;
canBeChosed = false;
beChosed = false;
bVisible = true;
fatherMainWindow = nullptr;
}
Base(const string &newText, short width, short height)
{
text = newText;
size.width = width;
size.height = height;
canBeChosed = false;
beChosed = false;
bVisible = true;
fatherMainWindow = nullptr;
}
virtual void draw(short offsetX, short offsetY)
{
}
virtual void drawNull(short offsetX, short offsetY)
{
string null_str{};
for(int i = 0; i < size.x; i++)
{
null_str += " ";
}
for(int i = 0; i < size.y; i++)
{
WindowSetting::PointJump(short(location.y + offsetY + i), short(location.x + offsetX));
cout << null_str;
}
}
virtual void whenBeChosed()
{
beChosed = true;
}
virtual void whenStopChosed()
{
beChosed = false;
}
//一般规定:1表示读取成功,0表示失败
virtual int keyAction(int newKey)
{
return 0;
}
virtual void setText(const string &newText)
{
text = newText;
}
virtual string getText()
{
return text;
}
virtual bool getVisible()
{
return bVisible;
}
virtual void setVisible(bool ifVisible)
{
bVisible = ifVisible;
}
virtual void setSize(short width, short height)
{
size.width = width;
size.height = height;
}
virtual Coordinate getSize()
{
return size;
}
virtual void setLocation(short x, short y)
{
location.x = x;
location.y = y;
}
virtual Coordinate getLocation()
{
return location;
}
virtual void setCanBeChosed(bool ifCanBeChosed)
{
canBeChosed = ifCanBeChosed;
}
virtual bool getCanBeChosed()
{
return canBeChosed;
}
virtual void setBeChosed(bool ifBeChosed)
{
beChosed = ifBeChosed;
if(ifBeChosed)
{
whenBeChosed();
}
else
{
whenStopChosed();
}
}
virtual bool getBeChosed()
{
return beChosed;
}
//设置所属主窗口信息
virtual void setFatherMainWindow(cuberx::MainWindow *newFatherMainWindow)
{
fatherMainWindow = newFatherMainWindow;
}
//重置所属主窗口信息
virtual void resetFatherMainWindow()
{
fatherMainWindow = nullptr;
}
//获取所属主窗口
virtual cuberx::MainWindow *getFatherMainWindow()
{
return fatherMainWindow;
}
//设置所属容器信息
virtual void setFatherContainer(cuberx::Container *newFatherContainer)
{
fatherContainer = newFatherContainer;
}
//重置所属容器信息
virtual void resetFatherContainer()
{
fatherContainer = nullptr;
}
//获取所属容器
virtual cuberx::Container *getFatherContainer()
{
return fatherContainer;
}
//设置绘制偏移量
virtual void setOffset(short offsetX, short offsetY)
{
this->offset.x = offsetX;
this->offset.y = offsetY;
}
//获取绘制偏移量
virtual cuberx::Coordinate getOffset()
{
return offset;
}
};
//容器类
class Container : public cuberx::Base {
protected:
int nowChosingObject;
public:
Container()
{
text = " ";
canBeChosed = false;
beChosed = false;
nowChosingObject = 0;
}
explicit Container(const string &newText)
{
text = newText;
canBeChosed = false;
beChosed = false;
nowChosingObject = 0;
}
Container(short width, short height, short x, short y)
{
location.x = x;
location.y = y;
size.width = width;
size.height = height;
canBeChosed = false;
beChosed = false;
nowChosingObject = 0;
}
Container(short width, short height)
{
size.width = width;
size.height = height;
canBeChosed = false;
beChosed = false;
nowChosingObject = 0;
}
Container(const string &newText, short width, short height, short x, short y)
{
text = newText;
location.x = x;
location.y = y;
size.width = width;
size.height = height;
canBeChosed = false;
beChosed = false;
nowChosingObject = 0;
}
Container(const string &newText, short width, short height)
{
text = newText;
size.width = width;
size.height = height;
canBeChosed = false;
beChosed = false;
nowChosingObject = 0;
}
virtual int add(cuberx::Base *newObject)
{
return 0;
}
virtual int add(cuberx::Base &newObject)
{
return 0;
}
virtual void remove(cuberx::Base *newObject)
{
}
virtual void remove(cuberx::Base &newObject)
{
}
virtual int getNowChosingObject()
{
return nowChosingObject;
}
//最好重写
virtual void setNowChosingObject(int newChosingObject)
{
nowChosingObject = newChosingObject;
}
//最好重写
virtual void exit()
{
}
};
//组件类
class Module : public cuberx::Base {
public:
Module() = default;
};
}// namespace cuberx
//MainWindow
#define $CU_MAINWINDOW_TOTAL_OBJECTS_COUNT 256
#define $CU_MAINWINDOW_TOTAL_TASKS_COUNT 256
#define $CU_MAINWINDOW_TOTAL_G_KEYACTION_BEFORE_COUNT 32
#define $CU_MAINWINDOW_TOTAL_G_KEYACTION_AFTER_COUNT 32
namespace cuberx
{
class MainWindow : public cuberx::Container {
protected:
string title; //窗口标题(反映在控制台上)
bool enable; //是否启用
bool useTickListener; //是否使用帧率管理器
bool checkKey; //是否检测键位
ULONGLONG lastTestTickTime;//上一次检测(运行)帧时间
ULONGLONG timePerTick; //帧率时间(0为无限制 单位为毫秒)
int tickListenerMode; //检测模式(1为不足则补齐,2为不足则补齐 且 超时则多次执行)
int nowChosingObject; //目前选择的CU组件(-1表示无)
cuberx::Base *objects[$CU_MAINWINDOW_TOTAL_OBJECTS_COUNT]{};
cuberx::CUTask tasks[$CU_MAINWINDOW_TOTAL_TASKS_COUNT];
cuberx::KeyTask keyTasksBefore[$CU_MAINWINDOW_TOTAL_G_KEYACTION_BEFORE_COUNT]{};
cuberx::KeyTask keyTasksAfter[$CU_MAINWINDOW_TOTAL_G_KEYACTION_AFTER_COUNT]{};
thread *tickListenerThread;
bool threadEnable;
public:
int returnInt;
MainWindow()
{
returnInt = 0;
setSize(0, 0);
title = "CuberX UnrealGUI (" + $CU_VERSION + ")";
enable = false;
for(auto &object: objects)
{
object = nullptr;
}
for(int i = 0; i < $CU_MAINWINDOW_TOTAL_TASKS_COUNT; i++)
{
tasks[i].setIndex(i);
}
timePerTick = 0;
tickListenerMode = 2;
nowChosingObject = 0;
checkKey = true;
tickListenerThread = nullptr;
threadEnable = false;
useTickListener = true;
lastTestTickTime = 0;
}
explicit MainWindow(const string &title, short new_size_width = 0, short new_size_height = 0, bool enable = false) :
Container(new_size_width, new_size_height)
{
returnInt = 0;
setSize(new_size_width, new_size_height);
this->title = title;
this->enable = enable;
for(auto &object: objects)
{
object = nullptr;
}
timePerTick = 0;
tickListenerMode = 2;
nowChosingObject = 0;
for(int i = 0; i < $CU_MAINWINDOW_TOTAL_TASKS_COUNT; i++)
{
tasks[i].setIndex(i);
}
checkKey = true;
tickListenerThread = nullptr;
threadEnable = false;
useTickListener = true;
lastTestTickTime = 0;
}
MainWindow(short new_size_width, short new_size_height, bool enable = false) :
Container(new_size_width, new_size_height)
{
returnInt = 0;
setSize(new_size_width, new_size_height);
this->title = "CuberX UnrealGUI (" + $CU_VERSION + ")";
this->enable = enable;
for(auto &object: objects)
{
object = nullptr;
}
timePerTick = 0;
tickListenerMode = 2;
nowChosingObject = 0;
for(int i = 0; i < $CU_MAINWINDOW_TOTAL_TASKS_COUNT; i++)
{
tasks[i].setIndex(i);
}
checkKey = true;
tickListenerThread = nullptr;
threadEnable = false;
useTickListener = true;
lastTestTickTime = 0;
}
~MainWindow()
{
if(tickListenerThread != nullptr)
{
enable = false;
Sleep(getTimePerTick() + 10);
// delete tickListenerThread;
tickListenerThread = nullptr;
}
}
//添加对象
int add(cuberx::Base *newObject) override
{
for(int i = 0; i < $CU_MAINWINDOW_TOTAL_OBJECTS_COUNT; i++)
{
if(objects[i] == nullptr)
{
objects[i] = newObject;
newObject->setFatherMainWindow(this);
return i;
}
}
return -1;
}
int add(cuberx::Base &newObject) override
{
for(int i = 0; i < $CU_MAINWINDOW_TOTAL_OBJECTS_COUNT; i++)
{
if(objects[i] == nullptr)
{
objects[i] = &newObject;
newObject.setFatherMainWindow(this);
return i;
}
}
return -1;
}
MainWindow &operator<<(cuberx::Base *newObject)
{
for(auto &object: objects)
{
if(object == nullptr)
{
object = newObject;
newObject->setFatherMainWindow(this);
return *this;
}
}
cout << "[CuberX UnrealGUI]No Enough Place For The New Object. Please Change #define $CU_MAINWINDOW_TOTAL_OBJECTS_COUNT.";
return *this;
}
MainWindow &operator<<(cuberx::Base &newObject)
{
for(auto &object: objects)
{