MessageViewPresenter.ts
13 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
import { ConfigManager } from "simba-config-manager";
import { DeepReadonly } from "simba-utils";
import { PlotManager, ReadonlyPlot, richNodesToCocosString, SentenceMediaContent, SentenceTextContent, SentenceType } from "../../../avg/AVG";
import { RoleType } from "../../../avg/EditorEnums";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { GameTextData } from "../../../common/gameplay/gamedata/GameTextData";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { relationLevelConfig } from "../../../config/RelationLevelConfig";
import { role } from "../../../config/Role";
import { DirectionType, GuideLocation, GuideOperationType, GuideState, PlotSceneType } from "../../Enums";
import GameDotMgr from "../../GameDotMgr";
import { GameModelManager } from "../../model/GameModelManager";
import { MessageSceneModel } from "../../model/MessageSceneModel";
import { RegPresenter } from "../PresenterCCViewFactory";
import { AlertDialogViewProps } from "../view/type/AlertDialogView";
import { MessageView, MessageViewProps, MessageViewType } from "../view/type/MessageView";
import AlertDialogViewPresenter from "./AlertDialogViewPresenter";
import { ChatListViewPresenter } from "./ChatListViewPresenter";
import GuideViewPresenter, { GuideViewParamModel } from "./GuideViewPresenter";
import { PhoneCallViewPresenter } from "./PhoneCallViewPresenter";
import PlotStopViewPresenter from "./PlotStopViewPresenter";
function getSentenceText(content: DeepReadonly<SentenceTextContent> | DeepReadonly<SentenceMediaContent>) {
let text = ""
switch (content.type) {
case SentenceType.TEXT:
text = richNodesToCocosString(content.value);
const CHAR_LIMIT: number = 15;
// text = '<color=#000000>亲,你说不说?</color>,<color=#000000>111</color>';
// text = '亲,你说不说?亲,你说不说?亲,你说不说?';
const regex = /<color=#[0-9A-Za-z]{6,6}>/g;
let str = text.replace(regex, '');
let textStr = str.replace(/<\/color>/g, '');
text = textStr.length > CHAR_LIMIT ? textStr.slice(0, CHAR_LIMIT - 3) + "..." : textStr;
break;
case SentenceType.AUDIO:
text = "[Voice]";
break;
case SentenceType.IMAGE:
text = "[Image]";
break;
case SentenceType.VIDEO:
text = "[Video]";
break;
}
return text;
}
function getPlotString(plot?: ReadonlyPlot) {
if (plot) {
let text = "";
let sentence = plot.sentences[0];
if (sentence.content) {
if (sentence.content.type === SentenceType.SELECT) {
let select = PlotManager.getPlotSelection(plot.id);
if (select !== undefined) {
let option = sentence.content.value[select];
if (option.content) {
if (option.content.type === SentenceType.EMPTY) {
console.error("TODO handle empty plots in message");
} else {
text = getSentenceText(option.content);
}
} else {
text = option.summary;
}
}
} else {
if (sentence.content.type === SentenceType.EMPTY) {
console.error("TODO handle empty plots in message");
} else {
text = getSentenceText(sentence.content);
}
}
}
return text;
}
return GameModelManager.getLanguageTxt(GameTextData.TEXT_NEW_CHAT_MSG_VALUE);
}
@RegPresenter(MessageViewType)
export default class MessageViewPresenter extends Presenter<undefined, MessageView> {
static uuid = "MessageViewPresenter";
private _scenesActive: { [key: number]: boolean } = {};
private _currPlotHasMsg = false;
private _isCheckingPhoneCall: boolean = false;
private _viewProps: MessageViewProps;
onOpen() {
super.onOpen(undefined);
this.initViewProps();
this.checkScenesActive();
this.setViewProps();
this._disposable.add(GameModelManager.MessageSceneChanged.on(() => {
if (!this._currPlotHasMsg && !this._view.isHidden && !this._isInBackground) {
this.checkScenesActive();
this.setViewProps();
}
}));
this._disposable.add(PlotManager.PlotStartEvent.on(() => {
if (this._currPlotHasMsg && !this._view.isHidden && !this._isInBackground) {
this.checkScenesActive();
this.setViewProps();
}
}));
// this._disposable.add(GameModelManager.CheckMsgGuide.on(this.checkGuideItem));
this._disposable.add(GameModelManager.ShowPlotBlocked.on(this.onShowPlotBlocked));
this._disposable.add(GameModelManager.PlotBlockedChanged.on(this.onShowPlotBlocked));
this._disposable.add(GameModelManager.ForceClickMsgItem.on(this.onForceClickItem));
this._disposable.add(GameModelManager.RefreshAllStatus.on(this.onRefreshAllStatus));
this._isCheckingPhoneCall = false;
this.checkPhoneCall();
}
onForceClickItem = (id: number) => {
console.log("MessageViewPresenter onForceClickItem id = ", id);
if (!this._viewProps.items || 0 === this._viewProps.items.length) {
return;
}
let c = id + "";
let i = this._viewProps.items.findIndex((v) => v.key === c);
if ((-1) !== i) {
this.onItemClick(c);
}
}
onShow() {
super.onShow();
this.checkScenesActive();
this.setViewProps();
this.checkPhoneCall();
// this.checkGuideItem();
}
initViewProps() {
this._viewProps = {
items: [],
onItemClick: this.onItemClick,
PlotStopTipBtnCallback: this.PlotStopTipBtnCallback,
isShowPlotStopTipBtn: false,
}
}
async checkPhoneCall() {
if (this._isCheckingPhoneCall) {
return;
}
this._isCheckingPhoneCall = true
if (PlotManager.getCurrentPlots()[0].plotSceneType === PlotSceneType.PhoneCall) {
await UIManager.pushPresenter(PhoneCallViewPresenter, undefined);
}
this._isCheckingPhoneCall = false;
}
onEnterForeground() {
super.onEnterForeground();
this.checkScenesActive();
this.setViewProps();
this.checkPhoneCall();
}
private checkScenesActive = () => {
this._currPlotHasMsg = false;
this._scenesActive = GameModelManager.getMessageScenesModel().reduce((pv, v) => (pv[v.id] = this.checkSceneActive(v), pv), {});
}
private checkSceneActive = (model: MessageSceneModel) => {
let ret = PlotManager.getCurrentPlots().findIndex(v => v.plotSceneType === PlotSceneType.Message && v.plotSceneTypeId === model.id) >= 0;
if (ret) this._currPlotHasMsg = true;
return ret;
}
private setViewProps() {
let items = GameModelManager.getMessageScenesModel().map(
v => {
let roleConfig = ConfigManager.getConfig(role, v.config.roles[0]);
let isMajor = roleConfig.RoleType === RoleType.Role_Major;
let roleData = GameModelManager.getRoleData(v.config.roles[0]);
let data = roleData!.getRoleLikeLevel();
let nameSpr = GameModelManager.getRoleData(v.config.roles[0])!.getNameIcon();
if (v.config.roles[0] === 3) {
nameSpr = "/textures/name_icon/laoda";
}
return {
key: v.id + "", icons: [GameModelManager.getRoleData(v.config.roles[0])!.getHeadIcon()],
title: GameModelManager.getConfigLanguageTxt(v.config.title),
lastMsg: getPlotString(v.lastPlot),
redDot: this._scenesActive[v.id],
isShowGrace: isMajor,
level: isMajor ? data.level : undefined,
roleId: v.config.roles[0],
addGraceClickCallBack: this.addGraceClickCallBack,
isShowAddGrace: isMajor && data.level !== data.maxLevel,
nameSpr: nameSpr
}
}
);
//对列表进行排序,有红点的(新对话消息)排在最前面,也就是置顶
items.sort((a, b) => {
if (a.redDot) {
return -1;
}
if (b.redDot) {
return 1;
}
return 0;
});
this._viewProps = { // 暂每条只有一个头像,群聊显示单独头像,以后可能群聊显示多人头像
items: items,
onItemClick: this.onItemClick,
isShowPlotStopTipBtn: GameModelManager.checkIsPlotBlocked(),
PlotStopTipBtnCallback: this.PlotStopTipBtnCallback,
}
this.view.setProps(this._viewProps);
}
PlotStopTipBtnCallback = () => {
UIManager.pushPresenter(PlotStopViewPresenter, undefined);
}
addGraceClickCallBack = (roleId: number) => {
// GameDotMgr.getInstance().dotClickUI("click_grace");
let r = GameModelManager.getRoleData(roleId);
if (!r || r!.getConfig().RoleType !== RoleType.Role_Major) {
return;
}
let l = r.getRoleLikeLevel();
let m: number = -1;
let t = ConfigManager.getAllConfig(relationLevelConfig);
for (let id in t) {
let c = t[id];
m = m < c.id ? c.id : m;
//暂时修改最大等级为10
m = 10;
}
if (m <= l.level) {
UIManager.showToast(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_GRACE_LEVEL_MAX_VALUE));
return;
}
else {
// UIManager.showToast(StringUtils.format(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_GRACE_TIP_ROLE), r.getRoleName(), l.level));
let temp: AlertDialogViewProps =
{
dataptr: { roleId: roleId },
titlecontent: "提升好感度",
content: `当前与${r.getRoleName()}好感度等级为${l.level},观看视频提升好感度等级!`,
ishasad: true,
istwobtn: true,
adconfig: "inject_fruit",
// items: [],
hasBanner: false,
callback: (type, ret: boolean, param: any) => {
if (ret) {
if (type === "video") {
let rid = param.roleId;
let role = GameModelManager.getRoleData(rid);
if (role) {
role.addRoleLike(1000);
this.setViewProps();
}
} else {
UIManager.showToast("只能通过观看视频提升好感度等级!");
}
}
}
};
UIManager.pushPresenter(AlertDialogViewPresenter, temp);
}
}
private onItemClick = (key: string) => {
// console.log("item click", key);
GameModelManager.setGuideMsgItemRecord(key, GuideState.Complete);
let sceneModel = GameModelManager.getMessageSceneModel(parseInt(key));
if (!sceneModel) { console.error("message scene model not found ", key); return; }
let isNew = PlotManager.getCurrentPlots().findIndex(v => v.plotSceneType === PlotSceneType.Message && v.plotSceneTypeId === sceneModel!.id) !== (-1);
if (isNew || sceneModel.firstPlot.sentences[0].roleId == 3) {
GameDotMgr.getInstance().dotClickUI("click_chat_card" + sceneModel.id);
}
UIManager.pushPresenter(ChatListViewPresenter, sceneModel);
}
checkGuideItem = () => {
let k = GameModelManager.getMsgItemGuideKey();
if (k && "" !== k) {
let node = this._view.getItemNode(k);
if (node) {
let wp = node.convertToWorldSpaceAR(cc.v2(0, 0));
let m: GuideViewParamModel = {
x: wp.x,
y: wp.y,
w: node.width,
h: node.height,
d: DirectionType.DOWM,
call: () => {
this.onItemClick(k);
}
}
UIManager.pushPresenter(GuideViewPresenter, m);
GameDotMgr.getInstance().dotGuide(GuideOperationType.Show, GuideLocation.MsgItem);
}
}
}
onShowPlotBlocked = () => {
this._viewProps.isShowPlotStopTipBtn = GameModelManager.checkIsPlotBlocked();
this.view.updateProps(this._viewProps);
}
onRefreshAllStatus = () => {
this.initViewProps();
this.checkScenesActive();
this.setViewProps();
this._isCheckingPhoneCall = false;
this.checkPhoneCall();
}
}