[add] HistoryPanel 完成

This commit is contained in:
建喵 2022-05-15 14:34:42 +08:00
parent d302a52d8d
commit ded2c7c1ed
5 changed files with 2751 additions and 2482 deletions

View File

@ -47,7 +47,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 400, "width": 400,
"height": 128.00000000000009 "height": -20
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@ -91,7 +91,7 @@
"__id__": 1 "__id__": 1
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 3 "__id__": 3
@ -199,7 +199,7 @@
"__id__": 1 "__id__": 1
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 6 "__id__": 6
@ -338,7 +338,7 @@
"ctor": "Float64Array", "ctor": "Float64Array",
"array": [ "array": [
0, 0,
-126.00000000000009, 22.000000000000004,
0, 0,
0, 0,
0, 0,
@ -416,7 +416,7 @@
"_layoutSize": { "_layoutSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 400, "width": 400,
"height": 128.00000000000009 "height": -20
}, },
"_resize": 1, "_resize": 1,
"_N$layoutType": 2, "_N$layoutType": 2,

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@ import NodePackageManager from "../_BootLoader/Npm/NodePackageManager";
import ConfigManager from "./ConfigManager"; import ConfigManager from "./ConfigManager";
import { GameRecord, MemberData, ScoreResult } from "./MemberData"; import { GameRecord, MemberData, ScoreResult } from "./MemberData";
import RecordManager from "./RecordManager"; import RecordManager from "./RecordManager";
import { URLSchemeHandler } from "./URLSchemeHandler";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ -20,16 +21,16 @@ export class Badminton extends cc.Component {
//#region property //#region property
@property({ type: cc.Prefab }) @property({ type: cc.Prefab })
private toggleItem: cc.Prefab = null; public toggleItem: cc.Prefab = null;
@property({ type: cc.Prefab }) @property({ type: cc.Prefab })
private teamItem: cc.Prefab = null; public teamItem: cc.Prefab = null;
@property({ type: cc.EditBox }) @property({ type: cc.EditBox })
private inputNameText: cc.EditBox = null; public inputNameText: cc.EditBox = null;
@property({ type: cc.Label }) @property({ type: cc.Label })
private storageText: cc.Label = null; public storageText: cc.Label = null;
@property({ type: cc.Node }) @property({ type: cc.Node })
public ToggleItemContent: cc.Node = null; public ToggleItemContent: cc.Node = null;
@ -135,6 +136,7 @@ export class Badminton extends cc.Component {
CoroutineV2.Single(self.HistoryPanel.Hide()).Start(); CoroutineV2.Single(self.HistoryPanel.Hide()).Start();
} }
// textToSpeech = FindObjectOfType<TextToSpeech>(); // textToSpeech = FindObjectOfType<TextToSpeech>();
self.HistoryPanel.Initial(self);
self.AvatarPanel.Initial(self); self.AvatarPanel.Initial(self);
CoroutineV2.Single(self.Show()).Start(); CoroutineV2.Single(self.Show()).Start();
}; };
@ -150,14 +152,13 @@ export class Badminton extends cc.Component {
public *Show(): IterableIterator<any> { public *Show(): IterableIterator<any> {
CoroutineV2.Single(this.ScoreBoard.Hide()).Start(); CoroutineV2.Single(this.ScoreBoard.Hide()).Start();
this._initUI(); this._initUI();
// LoadStatus(); this.LoadStatus();
// // 跨日後計分清除 // 跨日後計分清除
// if (PlayerPrefs.GetString("date") != today) if (LocalStorageData.Instance.Date !== Badminton.Today) {
// { cc.warn("跨日後計分清除");
// Debug.LogWarning("跨日後計分清除"); this.OnClickClearAllGameResult();
// ClearAllGameResult(); }
// } URLSchemeHandler.Init();
// URLSchemeHandler.Init();
} }
//#endregion //#endregion
@ -545,6 +546,14 @@ export class Badminton extends cc.Component {
this.SaveStatus(); this.SaveStatus();
} }
public OnClickBtn_History(): void {
CoroutineV2.Single(this.HistoryPanel.Show()).Start();
}
public OnClickBtn_Sound(): void {
CoroutineV2.Single(this.VoicePanel.Show()).Start();
}
//#endregion //#endregion
public Log(a: any, b: any): void { public Log(a: any, b: any): void {

View File

@ -0,0 +1,50 @@
const { ccclass, property } = cc._decorator;
@ccclass
export class URLSchemeHandler extends cc.Component {
//#region Custom
public static Init(): boolean {
try {
// bool isFirst = false;
// if (_instance == null) {
// _instance = Component.FindObjectOfType<URLSchemeHandler>();
// if (_instance == null) {
// _instance = new GameObject("URLSchemeOriginManager").AddComponent<URLSchemeHandler>();
// }
// isFirst = true;
// #if UNITY_EDITOR
// _instance.firstOpen = false;
// #endif
// }
// #if UNITY_EDITOR
// else
// {
// isFirst = _instance.firstOpen;
// }
// #endif
// #if UNITY_EDITOR || UNITY_ANDROID
// //Debug.LogWarning("URLSchemeHandler can not use in editor mode.");
// UtilsNativeActivity.Init();
// UtilsNativeActivity.SetCallbackOnNewIntent(_instance.callbackOnNewIntent);
// return isFirst;
// #elif UNITY_IPHONE || UNITY_IOS
// UtilsNativeActivity.Init();
// UtilsNativeActivity.SetCallbackOnNewIntent(_instance.callbackOnNewIntent);
// _setCallbackURLScheme(UtilsNativeActivity.HANDLER_OBJECT_NAME, UtilsNativeActivity.HANDLER_METHOD_NAME);
// return true;
// #endif
} catch (error: any) {
cc.error("URLSchemeHandler error : " + error.toString());
}
return false;
}
//#endregion
}

View File

@ -1,21 +1,62 @@
import UIPanel from "../Engine/Component/UIPanel/UIPanel"; import UIPanel from "../Engine/Component/UIPanel/UIPanel";
import LocalStorageData from "../Engine/Data/LocalStorageData";
import NodePackageManager from "../_BootLoader/Npm/NodePackageManager";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
/** HistoryPanel */ /** HistoryPanel */
@ccclass @ccclass
export default class HistoryPanel extends UIPanel { export default class HistoryPanel extends UIPanel {
//#region property
@property({ type: cc.Node })
public HistoryView: cc.Node = null;
@property({ type: cc.Prefab })
public PlayerItem: cc.Prefab = null;
@property({ type: cc.Prefab })
public HistoryItem: cc.Prefab = null;
//#endregion
//#region property
private _dateTransform: cc.Node = null;
private _teamTransform: cc.Node = null;
private _isAwake: boolean = false;
private _needRefresh: boolean = true;
//#endregion
//#region get set //#region get set
public get History(): Map<string, string[]> { return this._m_history; } public get History(): Map<string, string[]> { return this._history; }
private _m_history: Map<string, string[]> = new Map<string, string[]>(); private _history: Map<string, string[]> = new Map<string, string[]>();
public static get Today(): string { return NodePackageManager.Instance.Dayjs().format("YYYYMMDD"); }
//#endregion //#endregion
//#region Lifecycle //#region Lifecycle
public Initial(...initData: any[]): void {
super.Initial(...initData);
if (this._history.size === 0) {
this.LoadRecord();
}
// this._dateTransform = this.HistoryView.Find("DateText");
// this._dateTransform.active = false;
// this._teamTransform = this.HistoryView.Find("Players");
// this._teamTransform.active = false;
this._isAwake = true;
}
protected *ImplementReadyShow(...param: any[]): IterableIterator<any> { protected *ImplementReadyShow(...param: any[]): IterableIterator<any> {
cc.log("HistoryPanel ImplementReadyShow"); cc.log("HistoryPanel ImplementReadyShow");
this.OpenUI();
} }
//#endregion //#endregion
@ -23,7 +64,111 @@ export default class HistoryPanel extends UIPanel {
//#region Custom //#region Custom
public LoadRecord(): void { public LoadRecord(): void {
// throw new Error("Method not implemented."); let self: this = this;
// 格式 json: {"日期":[玩家1,玩家2,...],"日期":[玩家1,玩家2,...]}
let history: Map<string, string[]> = LocalStorageData.Instance.HistoryTeam;
if (history.size === 0) {
return;
}
history.forEach((value: string[], key: string, map: Map<string, string[]>) => {
self._history.set(key, value);
});
}
public RefreshUI(): void {
if (!this._needRefresh) {
return;
}
if (this._isAwake) {
// 先清掉全部
for (let i: number = this.HistoryView.childrenCount - 1; i > 0; i--) {
let child: cc.Node = this.HistoryView.children[i];
if (child.active) {
child.destroy();
}
}
}
let dateList: string[] = [];
this._history.forEach((value: string[], key: string, map: Map<string, string[]>) => {
dateList.push(key);
});
dateList.sort();
// 越前面日期越舊
for (let j: number = dateList.length - 1; j >= 0; j--) {
let date: string = dateList[j];
// 今日不顯示
if (date === HistoryPanel.Today) {
continue;
}
let historyItem: cc.Node = this.HistoryView.ExAddChild(this.HistoryItem);
let playerList: string[] = this._history.get(date);
let dateText: cc.Label = historyItem.getChildByName("DateText").getComponent(cc.Label);
dateText.string = date;
dateText.node.active = true;
// 所有玩家
// let teamList = GameObject.Instantiate(m_TeamTransform.gameObject, this._historyView.transform);
let teamList: cc.Node = historyItem.getChildByName("Players");
teamList.active = true;
// 一個team A player B player
let teamTemplete: cc.Prefab = this.PlayerItem;
for (let i: number = 0; i < playerList.length; i = i + 2) {
let team: cc.Node = teamList.ExAddChild(teamTemplete);
let player1Text: cc.Label = team.Find("Label_1").getComponent(cc.Label);
let player2Text: cc.Label = team.Find("Label_2").getComponent(cc.Label);
team.active = true;
let name: string = playerList[i];
player1Text.string = playerList[i];
player2Text.string = i + 1 < playerList.length ? playerList[i + 1] : "";
}
}
this._needRefresh = false;
}
public OpenUI(): void {
if (this._needRefresh) {
this.RefreshUI();
}
}
public UpdateHistory(memberList): void {
if (!this._history.has(HistoryPanel.Today)) {
this._needRefresh = true;
this._history.set(HistoryPanel.Today, memberList);
} else {
// 不相同 就要重刷UI
this._needRefresh = memberList !== this._history[HistoryPanel.Today];
this._history[HistoryPanel.Today] = memberList;
}
}
// 刪掉最舊的一筆紀錄
public DeleteOldestHistory(): void {
if (this._history.size <= 0) {
return;
}
let dateList: string[] = [];
this._history.forEach((value: string[], key: string, map: Map<string, string[]>) => {
dateList.push(key);
});
dateList.sort();
// 越前面日期越舊
this._history.delete(dateList[0]);
this._needRefresh = true;
this.RefreshUI();
// 要不要及時存擋
LocalStorageData.Instance.HistoryTeam = this._history;
} }
//#endregion //#endregion