ExchangeCodeViewPresenter.ts
3.19 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
import { RegPresenter } from "../PresenterCCViewFactory";
import { ExchangeCodeViewType, ExchangeCodeView, ExchangeCodeViewProps } from "../view/type/ExChangeCodeView";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { HttpRequests } from "../../network/HttpRequests";
import { GameModelManager } from "../../model/GameModelManager";
import { GameConstData } from "../../../common/gameplay/gamedata/GameConstData";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { GameTextData } from "../../../common/gameplay/gamedata/GameTextData";
interface ExchangeCodeParam {
titletxt: string;
contenttxt: string;
}
@RegPresenter(ExchangeCodeViewType)
export default class ExchangeCodeViewPresenter extends Presenter<ExchangeCodeParam, ExchangeCodeView>
{
static uuid = "ExchangeCodeViewPresenter";
private _viewProps: ExchangeCodeViewProps;
constructor() {
super();
this._viewProps = {
titletxt: "",
contenttxt: "",
onActionClick: this.onActionClickCallback
};
}
onOpen(param: ExchangeCodeParam) {
super.onOpen(param);
this._viewProps.titletxt = param.titletxt;
this._viewProps.contenttxt = param.contenttxt;
this._view.setProps(this._viewProps);
}
onActionClickCallback = async (ret: boolean, cdkey: string) => {
if (ret) {
let ret = await HttpRequests.exchangeCDKEY(cdkey) as any;
console.log("current ret is" + JSON.stringify(ret));
if (ret.code === "0") {
let player = GameModelManager.getPlayerData();
let outstr = "";
for (let i = 0; i < ret.obj.props.length; i++) {
let data = ret.obj.props[i];
let id = Number.parseInt(data.prop_id);
if (id === GameConstData.GAME_CONST_GOLD_ID_VALUE) {
player.addGoldCoin(data.count);
} else if (id === GameConstData.GAME_CONST_CLOTH_ID_VALUE) {
player.addClothCoin(data.count);
} else {
player.addProps(id, data.count);
}
let item = GameModelManager.getItemConfig(id);
outstr += item.name + " x" + data.count;
if (i != ret.obj.props.length - 1) {
outstr += ",";
}
}
UIManager.showToast(outstr);
} else if (ret.code === "104001") {//错误的验证码
let content = GameModelManager.getLanguageTxt(GameTextData.TEXT_CDKEYINVALID_VALUE);
UIManager.showToast(content);
} else if (ret.code === "104002")//已经领过了
{
let content = GameModelManager.getLanguageTxt(GameTextData.TEXT_CDKEYHADEXCHANGED_VALUE);
UIManager.showToast(content);
} else {//其他
let content = GameModelManager.getLanguageTxt(GameTextData.TEXT_CDKEYINVALID_VALUE);
UIManager.showToast(content);
}
}
}
}