forked from scarsty/kys-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.cpp
More file actions
259 lines (243 loc) · 8.3 KB
/
Console.cpp
File metadata and controls
259 lines (243 loc) · 8.3 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
#include "Console.h"
#include "BattleNetwork.h"
#include "BattleScene.h"
#include "DrawableOnCall.h"
#include "Font.h"
#include "InputBox.h"
#include "MainScene.h"
#include "PotConv.h"
#include "Save.h"
#include "SuperMenuText.h"
#include "TextureManager.h"
#include "strfunc.h"
#include <algorithm>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "Event.h"
Console::Console()
{
std::string code;
{
auto input = std::make_shared<InputBox>("神秘代碼:", 30);
input->setInputPosition(350, 300);
input->run();
if (input->getResult() >= 0)
{
code = input->getText();
}
else
{
return;
}
}
// 捂脸
code = PotConv::conv(code, "cp936", "utf-8");
auto splits = strfunc::splitString(code, " ");
//if (splits.empty()) return;
if (code == "menutest")
{
std::vector<std::pair<int, std::string>> generated;
for (int i = 0; i < 450; i++)
{
generated.emplace_back(i, "a" + std::to_string(i));
}
auto smt = std::make_shared<SuperMenuText>("少废话", 28, generated, 10);
smt->setInputPosition(180, 80);
smt->run();
int id = smt->getResult();
fmt1::print("result %d\n", id);
}
else if (code == "chuansong" || code == "teleport" || code == "mache" || code == "")
{
std::vector<std::pair<int, std::string>> locs;
for (const auto& info : Save::getInstance()->getSubMapInfos())
{
// 还有其他要求 这里作为一个demo就意思意思
if (info->MainEntranceX1 != 0 && info->MainEntranceY1 != 0)
{
std::string name(info->Name);
// 有空格方便完成双击确认
locs.emplace_back(info->ID, name);
}
}
int dx = 180;
int dy = 80;
auto drawScene = [dx, dy](DrawableOnCall* d)
{
if (d->getID() == -1)
{
return;
}
int id = d->getID();
auto scene = Save::getInstance()->getSubMapInfos()[id];
int nx = dx + 350;
int ny = dy + 100;
int fontSize = 28;
TextureManager::getInstance()->renderTexture("title", 126, { nx, ny, 400, 400 }, { 192, 192, 192, 255 }, 255);
//Engine::getInstance()->fillColor({ 0, 0, 0, 192 }, nx, ny, 400, 400);
Font::getInstance()->draw(fmt1::format("{},{}", scene->Name, scene->ID), fontSize, nx + 20, ny + 20);
Font::getInstance()->draw(fmt1::format("({},{})", scene->MainEntranceX1, scene->MainEntranceY1),
fontSize, nx + 20, ny + 20 + fontSize * 1.5);
int man_x_ = scene->MainEntranceX1;
int man_y_ = scene->MainEntranceY1;
auto mainScene = MainScene::getInstance();
if (man_x_ == 0 && man_y_ == 0)
{
return;
}
// 不会画场景,需要慢慢学习,不行我复制个代码 强行搞
struct DrawInfo
{
int index;
Texture* t;
Point p;
};
std::vector<DrawInfo> building_vec(1000);
int building_count = 0;
int hw = 2;
for (int sum = -hw; sum <= hw + 10; sum++)
{
for (int i = -hw; i <= hw; i++)
{
int ix = man_x_ + i + (sum / 2);
int iy = man_y_ - i + (sum - sum / 2);
auto p = mainScene->getPositionOnRender(ix, iy, man_x_, man_y_);
p.x += nx - 160;
p.y += ny;
if (mainScene->building_layer_.data(ix, iy).getTexture())
{
//根据图片的宽度计算图的中点, 为避免出现小数, 实际是中点坐标的2倍
//次要排序依据是y坐标
//直接设置z轴
auto tex = mainScene->building_layer_.data(ix, iy).getTexture();
if (tex == nullptr)
{
continue;
}
auto w = tex->w;
auto h = tex->h;
auto dy = tex->dy;
int c = ((ix + iy) - (w + 35) / 36 - (dy - h + 1) / 9) * 1024 + ix;
//map[2 * c + 1] = { 2*c+1, t, p };
building_vec[building_count++] = { 2 * c + 1, tex, p };
}
auto sort_building = [](DrawInfo& d1, DrawInfo& d2)
{
return d1.index < d2.index;
};
std::sort(building_vec.begin(), building_vec.begin() + building_count, sort_building);
for (int i = 0; i < building_count; i++)
{
auto& d = building_vec[i];
TextureManager::getInstance()->renderTexture(d.t, d.p.x, d.p.y);
}
}
}
};
std::shared_ptr<DrawableOnCall> doc = std::make_shared<DrawableOnCall>(drawScene);
auto smt = std::make_shared<SuperMenuText>("可輸入傳送地名,編號或拼音搜索:", 28, locs, 15);
smt->setInputPosition(dx, dy);
smt->addDrawableOnCall(doc);
smt->run();
int id = smt->getResult();
if (id != -1)
{
auto scene = Save::getInstance()->getSubMapInfos()[id];
MainScene::getInstance()->forceEnterSubScene(id, scene->EntranceX, scene->EntranceY);
MainScene::getInstance()->setManPosition(scene->MainEntranceX1, scene->MainEntranceY1);
fmt1::print("傳送到{}\n", id);
}
}
/*
else if (splits[0] == "newsave" && splits.size() >= 2)
{
int rec;
try
{
rec = std::stoi(splits[1]);
}
catch (...)
{
return;
}
auto save = Save::getInstance();
auto main_scene = MainScene::getInstance();
main_scene->getManPosition(save->MainMapX, save->MainMapY);
save->InSubMap = -1;
Save::getInstance()->saveRToCSV(rec);
Save::getInstance()->saveSD(rec);
}
else if (splits[0] == "newload" && splits.size() >= 2)
{
int rec;
try
{
rec = std::stoi(splits[1]);
}
catch (...)
{
return;
}
auto save = Save::getInstance();
auto main_scene = MainScene::getInstance();
Save::getInstance()->loadRFromCSV(rec);
Save::getInstance()->loadSD(rec);
main_scene->setManPosition(save->MainMapX, save->MainMapY);
if (save->InSubMap >= 0)
{
main_scene->forceEnterSubScene(save->InSubMap, save->SubMapX, save->SubMapY);
}
}
else if (splits[0] == "rinsert" && splits.size() >= 3)
{
int idx;
try
{
idx = std::stoi(splits[2]);
}
catch (...)
{
return;
}
Save::getInstance()->insertAt(splits[1], idx);
}*/
else if (splits[0] == "host" && splits.size() > 1)
{
Save::getInstance()->save(11);
auto host = BattleNetworkFactory::MakeHost(splits[1]);
if (!host)
{
return;
}
auto battle = std::make_shared<BattleScene>();
battle->setupNetwork(std::move(host));
battle->run();
Save::getInstance()->load(11);
}
else if (splits[0] == "client" && splits.size() > 1)
{
Save::getInstance()->save(11);
auto client = BattleNetworkFactory::MakeClient(splits[1]);
if (!client)
{
return;
}
auto battle = std::make_shared<BattleScene>();
battle->setupNetwork(std::move(client));
battle->run();
Save::getInstance()->load(11);
}
else if ((splits[0] == "battle" || splits[0] == "b") && splits.size() > 1)
{
Save::getInstance()->save(11);
int k = atoi(splits[1].c_str());
Event::getInstance()->tryBattle(k, 0);
//Save::getInstance()->load(11);
}
}