ReviewPlotViewPresenter.ts
4.4 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
import { PlotManager } from "simba-avg-core";
import { GameRecord } from "../../../avg/AVG";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { GameModelManager } from "../../model/GameModelManager";
import { RegPresenter } from "../PresenterCCViewFactory";
import { ReviewPlotViewType, ReviewPlotViewProps, ReviewPlotView } from "../view/type/ReviewPlotView";
export interface ReviewPlotViewParam {
isReview: boolean,
plotString: string,
startPlotId: number,
currentPlotId: number,
}
@RegPresenter(ReviewPlotViewType)
export default class ReviewPlotViewPresenter extends Presenter<ReviewPlotViewParam, ReviewPlotView>{
static uuid = "ReviewPlotViewPresenter";
private _viewProps: ReviewPlotViewProps;
private _param: ReviewPlotViewParam;
constructor() {
super();
this._viewProps = {
onCloseButtonClickCallback: this.onCloseButtonClickCallback,
}
}
onOpen(param: ReviewPlotViewParam) {
super.onOpen(param);
this._param = param;
this.view.setProps(this._viewProps);
this.onShow();
}
onShow() {
super.onShow();
this.initViewDate();
}
onEnterBackground() {
super.onEnterBackground();
}
onEnterForeground() {
super.onEnterForeground();
}
onClose() {
super.onClose();
}
initViewDate() {
this.view.getPlotRichText().string = "";
this.view.getLoadingNode().active = true;
this.view.getPlotRichText().scheduleOnce(async () => {
if (this._param.isReview) {
this.view.getPlotRichText().string = this._param.plotString;
} else {
this.view.getPlotRichText().string = await this.getReviewPlotContent();
}
if (this.view.getPlotRichText().node.height >= this.view.getPlotScrollView().node.height) {
this.view.getPlotScrollView().scrollToBottom();
}
this.view.getLoadingNode().active = false;
});
}
async getReviewPlotContent(): Promise<string> {
let showWhileNotSelect: boolean = false;//未选择时是否展示选项列表
let showCurrentPlot: boolean = true;//是否展示当前剧情内容
let plotStr = "";
let startPlotId = this._param.startPlotId;
let currentPlotId = this._param.currentPlotId;
let currentRecordIndex = PlotManager.getCurrentRecordIndex();
let currentRecord = GameRecord.getRecords()[currentRecordIndex].d;
let startPlotIdIndex = 0;
let currentPlotIdIndex = 0;
for (let i = 0; i < currentRecord.length; i++) {
if (startPlotId == currentRecord[i].p[0]) {
startPlotIdIndex = i;
}
if (currentPlotId == currentRecord[i].p[0]) {
currentPlotIdIndex = i;
}
}
if (showCurrentPlot) {
currentPlotIdIndex += 1;
}
let newCurrentRecord = currentRecord.slice(startPlotIdIndex, currentPlotIdIndex);
for (let i = 0; i < newCurrentRecord.length; i++) {
let content = await GameModelManager.getPlotContent(newCurrentRecord[i].p[0]);
if (content) {
let roleData = GameModelManager.getRoleData(content.roleId)!;
let plotName = "";
let plotContent = "";
if (content.content.length === 0) {
continue;
}
if (content.content.length > 1) {
if (newCurrentRecord[i].s && newCurrentRecord[i].s?.length !== 0) {
plotName = "<color=#D36777>" + "选项" + ":</c>\n"
plotContent = content.content[newCurrentRecord[i].s![0]] + "\n";
} else {
if (showWhileNotSelect) {
for (let j = 0; j < content.content.length; j++) {
plotContent = content.content[j] + "\n";
}
}
}
} else {
plotName = "<color=#EFDA91>" + roleData.getConfig().name + ":</c>\n"
plotContent = content.content[0] + "\n";
}
plotStr += plotName + plotContent;
}
}
return plotStr;
}
onCloseButtonClickCallback = async () => {
this.view.close();
}
}