cc2ae273-cdb2-44c9-bdb2-c7cc3d991f47.js
16.5 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
"use strict";
cc._RF.push(module, 'cc2aeJzzbJEyb2yx8w9mR9H', 'ChatListViewPresenter');
// script/game/ui/presenter/ChatListViewPresenter.ts
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatListViewPresenter = void 0;
const simba_eventkit_1 = require("simba-eventkit");
const simba_utils_1 = require("simba-utils");
const ActionManager_1 = require("../../../avg/ActionManager");
const EditorEnums_1 = require("../../../avg/EditorEnums");
const GameRecord_1 = require("../../../avg/game-data/GameRecord");
const PlotsData_1 = require("../../../avg/game-data/PlotsData");
const PlotManager_1 = require("../../../avg/PlotManager");
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const Enums_1 = require("../../Enums");
const GameModelManager_1 = require("../../model/GameModelManager");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const ChatListView_1 = require("../view/type/ChatListView");
const SentenceSelectorViewPresenter_1 = require("./SentenceSelectorViewPresenter");
const MAX_HISTORY = 50;
let ChatListViewPresenter = /** @class */ (() => {
let ChatListViewPresenter = class ChatListViewPresenter extends PresenterBase_1.Presenter {
constructor() {
super();
this._historyMessages = {};
this._currPlotShowed = false;
this._itemKey = 0;
this._plotExecuting = false;
this._excutedPlots = {};
this.onSelectIndexCallback = (index) => {
this.selectSentence(index);
};
this.onSetContent = (content) => {
if (content != undefined) {
let props = {
sentence: content,
backgroundpath: "textures/message/selector_bg",
clickcausehide: false,
onSelectIndexCallback: this.onSelectIndexCallback
};
UIManager_1.UIManager.pushPresenter(SentenceSelectorViewPresenter_1.default, props);
}
};
this.isSentenceSelectVisible = () => {
let preset = UIManager_1.UIManager.getTopPresenter();
if (preset instanceof SentenceSelectorViewPresenter_1.default) {
let selectorPresenter = preset;
return !selectorPresenter.view.isHidden;
}
return false;
};
this.closeAction = () => {
if (this._plotExecuting)
return;
UIManager_1.UIManager.popToPresenter(this);
this._view.closeAnimation().then(() => {
this._view.close();
});
};
this.selectChapter = () => {
};
this.selectSentence = (index) => {
if (!this._currPlot)
throw new Error("ChatList: ePlot error! No currnt plot!");
this.completePlot(index, ChatListView_1.ChatListAutoNextPlot);
};
this.showCurrPlot = async () => {
if (this._currPlot && !this._excutedPlots[this._currPlot.id] && !this._plotExecuting && !this._currPlotShowed) {
let item = this.convertPlotToViewModel(this._currPlot);
this._excutedPlots[this._currPlot.id] = true;
this._plotExecuting = true;
let disposable = new simba_eventkit_1.CompositeDisposable;
this._plotChangeLike = undefined;
GameRecord_1.GameRecord.onRecordVariableChange("like" + this._currPlot.sentences[0].roleId, (scope, varName, preValue, value) => {
this._plotChangeLike = value - preValue;
});
await ActionManager_1.ActionManager.executeActions(this._currPlot.sentences[0].actions); // TODO 处理加好感
disposable.dispose();
this._plotExecuting = false;
if (item) {
if (this._chatList.length >= MAX_HISTORY) {
this._chatList.shift();
}
this._chatList.push(item);
if (item.type === "plot" && this._plotChangeLike) {
item.addLike = this._plotChangeLike;
}
this._view.updateProps({ items: this._chatList });
}
this._currPlotShowed = true;
}
else if (this._currPlot && this._excutedPlots[this._currPlot.id]) {
this._currPlotShowed = true;
}
};
this.completePlot = async (index, proceedNext = true) => {
if (!this._currPlot)
return;
if (!this._currPlotShowed) {
this.showCurrPlot();
return;
}
if (index !== undefined) { // 刷新界面剧情选择
let lastItem = this._chatList.pop();
if (lastItem.type === "plot") {
this._chatList.push(Object.assign(Object.assign({}, lastItem), { select: index }));
}
else {
throw new Error("ChatList: Plot error!");
}
this._view.updateProps({ items: this._chatList });
}
// await this.execCurrPlot(); // 改为开始的时候执行
if (proceedNext) {
this.sceneModel.lastPlot = this._currPlot;
if (this._selectIndex !== undefined) {
index = this._selectIndex;
this._selectIndex = undefined;
}
if (ChatListView_1.ChatListAutoNextPlot)
await simba_utils_1.delay(0.5);
await this.nextPlot(index);
}
else {
this._selectIndex = index;
}
};
this.nextPlot = async (index) => {
if (this.isClosed())
return;
if (this._currPlot) {
await PlotManager_1.PlotManager.completePlot(this._currPlot, index, this._plotChangeLike ? { addlike: this._plotChangeLike } : undefined);
}
else {
console.error("ChatList: Plot error! No current plot!");
}
};
this.convertPlotToViewModel = (plot, select, customData) => {
let role = GameModelManager_1.GameModelManager.getRoleData(plot.sentences[0].roleId);
let content = plot.sentences[0].content;
if (plot.id >= 0) {
if (!content)
return undefined;
return { key: (this._itemKey++).toString(), type: "plot", name: role.getConfig().RoleType === EditorEnums_1.RoleType.Role_Blank ? "" : role.getConfig().name, icon: role.getHeadIcon(true), isSelf: role.getConfig().RoleType === EditorEnums_1.RoleType.Role_Player, content, select, addLike: customData ? customData["addlike"] : undefined };
}
else {
// // custom plot
// let giftId = plot.customData?.giftId;
// if (giftId) {// 送礼
// let giftItem = ConfigManager.getConfig(itemConfig, giftId);
// return { key: (this._itemKey++).toString(), type: "customplot", name: role.getConfig().name, icon: role.getHeadIcon(true), isSelf: true, gift: { icon: GameResData.GAME_ICON_BASE_PATH + giftItem.icon, text: "送你一个" + giftItem.name } };
// } else {
// if (content && content.type !== SentenceType.SELECT) {
// let addLike = plot.customData?.addLike;
// return { key: (this._itemKey++).toString(), type: "customplot", name: role.getConfig().name, icon: role.getHeadIcon(true), isSelf: false, content, addLike }
// } else {
// throw new Error("This cannot happen!");
// }
// }
}
};
this.handlePlotsStart = async (plots) => {
let plot = plots.find(v => v.plotSceneType === Enums_1.PlotSceneType.Message && v.plotSceneTypeId === this._sceneModel.id);
if (plot) {
if (this._currPlot && plot === this._currPlot)
return; // 有分支剧情的情况
this._currPlot = plot;
this._currPlotShowed = false;
await this.showCurrPlot();
}
else if (this._currPlot && this._currPlot.id >= 0) {
this._currPlot = undefined;
this._chatList.push({ key: (this._itemKey++).toString(), type: "end" });
if (this._chatList.length >= MAX_HISTORY) {
this._chatList.shift();
}
this._view.updateProps({ items: this._chatList, backRedDot: true });
}
};
PlotManager_1.PlotManager.PlotsRollbackEvent.on(() => {
this._excutedPlots = {};
});
}
get sceneModel() { return this._sceneModel; }
getRoleId() {
if (this.sceneModel.config.roles.length == 1)
return this.sceneModel.config.roles[0];
return 1;
}
async onOpen(scene) {
this._sceneModel = scene;
super.onOpen(scene);
this._disposable.add(PlotManager_1.PlotManager.PlotStartEvent.on(this.handlePlotsStart));
this._currPlot = PlotManager_1.PlotManager.getCurrentPlots().find(v => v.plotSceneType === Enums_1.PlotSceneType.Message && v.plotSceneTypeId === scene.id);
//@ts-ignore
delete this._chatList;
if (this._historyMessages[scene.id]) {
this._chatList = this._historyMessages[scene.id];
}
if (this._chatList && this._chatList.length) {
if (this._chatList[this._chatList.length - 1].type === "end") { // 上一次的结束改为历史
let item = this._chatList.pop();
this._chatList.push({ key: item.key, type: "history" });
for (let i = this._chatList.length - 2; i >= 0; i--) { // 删除之前的历史分割,只保留最后一个
let item = this._chatList[i];
if (item.type === "history") {
this._chatList.splice(i, 1);
break;
}
}
}
this._viewProps = {
msgSceneId: scene.id, title: GameModelManager_1.GameModelManager.getConfigLanguageTxt(scene.config.title),
items: this._chatList, historyMsgCount: this._chatList.length,
onCloseBtnClick: this.closeAction,
onSelectChapter: this.selectChapter,
onCompletePlot: this.completePlot,
onSelectSentence: this.selectSentence,
onSetContent: this.onSetContent,
isSentenceSelectVisible: this.isSentenceSelectVisible,
backRedDot: !this._currPlot
};
this._view.setProps(this._viewProps);
}
else {
this._viewProps = {
msgSceneId: scene.id, title: GameModelManager_1.GameModelManager.getConfigLanguageTxt(scene.config.title),
items: [], historyMsgCount: 0,
onCloseBtnClick: this.closeAction,
onSelectChapter: this.selectChapter,
onCompletePlot: this.completePlot,
onSelectSentence: this.selectSentence,
onSetContent: this.onSetContent,
isSentenceSelectVisible: this.isSentenceSelectVisible,
backRedDot: !this._currPlot
};
this._view.setProps(this._viewProps);
await this.loadChatList();
}
if (this._currPlot) {
this._currPlotShowed = false;
await this.showCurrPlot();
if (this._plotChangeLike) {
let item = Object.assign({}, this._chatList.pop());
if (item.type === "plot") { // 理论上肯定成立
item.addLike = this._plotChangeLike;
}
this._chatList.push(item);
this.view.updateProps({ items: this._chatList });
}
}
}
async loadChatList() {
// if (chapter === -1) {
// chapter = GameModelManager.getCurrentChapterId();
// }
if (this._historyMessages[this._sceneModel.id] && this._historyMessages[this._sceneModel.id]) {
this._view.updateProps({ items: this._chatList });
return;
}
this._historyMessages[this._sceneModel.id] = [];
let historyPlots = [];
let records = GameRecord_1.GameRecord.getCurrentRecordItems();
let pushHistory = false;
let hasHistory = false;
let lastPlotId = Number.MAX_SAFE_INTEGER;
for (let i = records.length - 1; i >= 0; i--) {
let item = records[i];
for (let j = 0; j < item.p.length; j++) {
let plotId = item.p[j];
if (plotId === lastPlotId)
break;
let plot = (await PlotsData_1.getPlot(plotId));
if (!plot)
continue;
if (plot.plotSceneType === Enums_1.PlotSceneType.Message && plot.plotSceneTypeId === this._sceneModel.id) {
lastPlotId = plotId;
if (i === records.length - 1)
continue;
if (pushHistory && !hasHistory) {
historyPlots.unshift({ key: (this._itemKey++).toString(), type: "history" });
hasHistory = true;
}
let select = undefined;
if (item.s)
select = item.s[j];
let customData = undefined;
if (item.c)
customData = item.c[j];
let vm = this.convertPlotToViewModel(plot, select, customData);
if (vm)
historyPlots.unshift(vm);
}
else { // TODO process branch plots if needed.
if (!pushHistory && !hasHistory) {
pushHistory = true;
}
}
if (plot.id === this._sceneModel.firstPlot.id) {
break;
}
}
if (historyPlots.length >= MAX_HISTORY) {
break;
}
}
this._chatList = historyPlots;
this._view.updateProps({ items: historyPlots, historyMsgCount: this._chatList.length });
this._historyMessages[this._sceneModel.id] = this._chatList;
}
isClosed() {
return !this._disposable;
}
};
ChatListViewPresenter.uuid = "ChatListViewPresenter";
ChatListViewPresenter = __decorate([
PresenterCCViewFactory_1.RegPresenter(ChatListView_1.ChatListViewType)
], ChatListViewPresenter);
return ChatListViewPresenter;
})();
exports.ChatListViewPresenter = ChatListViewPresenter;
cc._RF.pop();