@cc-component/cc-core 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cc-ex-component.md +12 -0
- package/assets/core/config/CommonEnum.ts +94 -0
- package/assets/core/config/CommonEnum.ts.meta +9 -0
- package/assets/core/config/IConfig.ts +89 -0
- package/assets/core/config/IConfig.ts.meta +9 -0
- package/assets/core/config/LayerType.ts +44 -0
- package/assets/core/config/LayerType.ts.meta +9 -0
- package/assets/core/config/LayerUI.ts +113 -0
- package/assets/core/config/LayerUI.ts.meta +9 -0
- package/assets/core/config.meta +9 -0
- package/assets/core/editor/LanguageManager.ts +323 -0
- package/assets/core/editor/LanguageManager.ts.meta +9 -0
- package/assets/core/editor/SpineRunner.ts +39 -0
- package/assets/core/editor/SpineRunner.ts.meta +9 -0
- package/assets/core/editor/i18nEditorComponent.ts +137 -0
- package/assets/core/editor/i18nEditorComponent.ts.meta +9 -0
- package/assets/core/editor.meta +9 -0
- package/assets/core/home/AudioUtil.ts +164 -0
- package/assets/core/home/AudioUtil.ts.meta +9 -0
- package/assets/core/home/BaseBoxView.ts +60 -0
- package/assets/core/home/BaseBoxView.ts.meta +9 -0
- package/assets/core/home/BaseLaunchComponent.ts +9 -0
- package/assets/core/home/BaseLaunchComponent.ts.meta +9 -0
- package/assets/core/home/BaseLoading.ts +136 -0
- package/assets/core/home/BaseLoading.ts.meta +9 -0
- package/assets/core/home/BaseSkeleton.ts +39 -0
- package/assets/core/home/BaseSkeleton.ts.meta +9 -0
- package/assets/core/home/CameraAngel.ts +326 -0
- package/assets/core/home/CameraAngel.ts.meta +9 -0
- package/assets/core/home/DouYinShow.ts +27 -0
- package/assets/core/home/DouYinShow.ts.meta +9 -0
- package/assets/core/home/EventManager.ts +39 -0
- package/assets/core/home/EventManager.ts.meta +9 -0
- package/assets/core/home/ExView.ts +9 -0
- package/assets/core/home/ExView.ts.meta +9 -0
- package/assets/core/home/FollowCamera.ts +205 -0
- package/assets/core/home/FollowCamera.ts.meta +9 -0
- package/assets/core/home/InViewCenter.ts +52 -0
- package/assets/core/home/InViewCenter.ts.meta +9 -0
- package/assets/core/home/JsonUtil.ts +102 -0
- package/assets/core/home/JsonUtil.ts.meta +9 -0
- package/assets/core/home/LoadingWindow.ts +44 -0
- package/assets/core/home/LoadingWindow.ts.meta +9 -0
- package/assets/core/home/ParabolaTween.ts +110 -0
- package/assets/core/home/ParabolaTween.ts.meta +9 -0
- package/assets/core/home/ProgessView.ts +96 -0
- package/assets/core/home/ProgessView.ts.meta +9 -0
- package/assets/core/home/Quaternion.ts +237 -0
- package/assets/core/home/Quaternion.ts.meta +9 -0
- package/assets/core/home/ResUtil.ts +132 -0
- package/assets/core/home/ResUtil.ts.meta +9 -0
- package/assets/core/home/ResourceManager.ts +430 -0
- package/assets/core/home/ResourceManager.ts.meta +9 -0
- package/assets/core/home/StateMachine.ts +93 -0
- package/assets/core/home/StateMachine.ts.meta +9 -0
- package/assets/core/home/StorageManager.ts +161 -0
- package/assets/core/home/StorageManager.ts.meta +9 -0
- package/assets/core/home/ThirdFreeLookCamera.ts +201 -0
- package/assets/core/home/ThirdFreeLookCamera.ts.meta +9 -0
- package/assets/core/home/TimeManager.ts +486 -0
- package/assets/core/home/TimeManager.ts.meta +9 -0
- package/assets/core/home/Tools.ts +103 -0
- package/assets/core/home/Tools.ts.meta +9 -0
- package/assets/core/home/prefabs.meta +12 -0
- package/assets/core/home/util/EncryptUtil.ts +60 -0
- package/assets/core/home/util/EncryptUtil.ts.meta +11 -0
- package/assets/core/home/util/MathUtil.ts +22 -0
- package/assets/core/home/util/MathUtil.ts.meta +9 -0
- package/assets/core/home/util/Md5.ts +202 -0
- package/assets/core/home/util/Md5.ts.meta +11 -0
- package/assets/core/home/util/RandomUtil.ts +61 -0
- package/assets/core/home/util/RandomUtil.ts.meta +9 -0
- package/assets/core/home/util/ResUtil.ts +129 -0
- package/assets/core/home/util/ResUtil.ts.meta +9 -0
- package/assets/core/home/util/crypto-js.d.ts +30 -0
- package/assets/core/home/util/crypto-js.d.ts.meta +11 -0
- package/assets/core/home/util/crypto-js.js +6030 -0
- package/assets/core/home/util/crypto-js.js.meta +9 -0
- package/assets/core/home/util.meta +12 -0
- package/assets/core/home.meta +12 -0
- package/assets/core/interface/ISceneParam.ts +11 -0
- package/assets/core/interface/ISceneParam.ts.meta +9 -0
- package/assets/core/interface/Interface.ts +160 -0
- package/assets/core/interface/Interface.ts.meta +1 -0
- package/assets/core/interface/MainModule.ts +1019 -0
- package/assets/core/interface/MainModule.ts.meta +9 -0
- package/assets/core/interface.meta +9 -0
- package/assets/core/lib/Logger.ts +286 -0
- package/assets/core/lib/Logger.ts.meta +9 -0
- package/assets/core/lib/language/.language.md +1 -0
- package/assets/core/lib/language/Language.ts +133 -0
- package/assets/core/lib/language/Language.ts.meta +13 -0
- package/assets/core/lib/language/LanguageData.ts +114 -0
- package/assets/core/lib/language/LanguageData.ts.meta +9 -0
- package/assets/core/lib/language/LanguageLabel.ts +172 -0
- package/assets/core/lib/language/LanguageLabel.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePack.ts +126 -0
- package/assets/core/lib/language/LanguagePack.ts.meta +13 -0
- package/assets/core/lib/language/LanguagePointLabel.ts.meta +16 -0
- package/assets/core/lib/language/LanguageSpine.ts +60 -0
- package/assets/core/lib/language/LanguageSpine.ts.meta +9 -0
- package/assets/core/lib/language/LanguageSprite.ts +138 -0
- package/assets/core/lib/language/LanguageSprite.ts.meta +13 -0
- package/assets/core/lib/language.meta +9 -0
- package/assets/core/lib/logger/ELoggerLevel.ts +16 -0
- package/assets/core/lib/logger/ELoggerLevel.ts.meta +9 -0
- package/assets/core/lib/logger/MLogger.ts +118 -0
- package/assets/core/lib/logger/MLogger.ts.meta +9 -0
- package/assets/core/lib/logger.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts +2729 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js +8 -0
- package/assets/core/lib/net/libs/proto/output/protobuf.min.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts +102 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.d.ts.meta +9 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js +222 -0
- package/assets/core/lib/net/libs/proto/output/protobuf_custom.js.meta +9 -0
- package/assets/core/lib/net/libs/proto/output.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto +6 -0
- package/assets/core/lib/net/libs/proto/source/Cmd.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto +12 -0
- package/assets/core/lib/net/libs/proto/source/UserLogin.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/base.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/base.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/command.proto +31 -0
- package/assets/core/lib/net/libs/proto/source/command.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto +13 -0
- package/assets/core/lib/net/libs/proto/source/domain/boos_battle_info.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto +26 -0
- package/assets/core/lib/net/libs/proto/source/domain/player_auth.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/domain.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto +23 -0
- package/assets/core/lib/net/libs/proto/source/message/game_push.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_request.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto +24 -0
- package/assets/core/lib/net/libs/proto/source/message/game_response.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/message.meta +9 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto +43 -0
- package/assets/core/lib/net/libs/proto/source/push/boss_battle_events.proto.meta +11 -0
- package/assets/core/lib/net/libs/proto/source/push.meta +9 -0
- package/assets/core/lib/net/libs/proto/source.meta +12 -0
- package/assets/core/lib/net/libs/proto.meta +9 -0
- package/assets/core/lib/net/libs.meta +9 -0
- package/assets/core/lib/net/net/HttpManager.ts +307 -0
- package/assets/core/lib/net/net/HttpManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetInterface.ts +114 -0
- package/assets/core/lib/net/net/NetInterface.ts.meta +9 -0
- package/assets/core/lib/net/net/NetManager.ts +77 -0
- package/assets/core/lib/net/net/NetManager.ts.meta +9 -0
- package/assets/core/lib/net/net/NetNode.ts +471 -0
- package/assets/core/lib/net/net/NetNode.ts.meta +9 -0
- package/assets/core/lib/net/net/WebSock.ts +81 -0
- package/assets/core/lib/net/net/WebSock.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts +41 -0
- package/assets/core/lib/net/net/custom/NetChannelManager.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts +11 -0
- package/assets/core/lib/net/net/custom/NetConfig.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts +4 -0
- package/assets/core/lib/net/net/custom/NetErrorCode.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts +53 -0
- package/assets/core/lib/net/net/custom/NetGameTips.ts.meta +9 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts +105 -0
- package/assets/core/lib/net/net/custom/NetNodeGame.ts.meta +9 -0
- package/assets/core/lib/net/net/custom.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts +39 -0
- package/assets/core/lib/net/net/protocol/NetProtocolJson.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts +85 -0
- package/assets/core/lib/net/net/protocol/NetProtocolProtobuf.ts.meta +9 -0
- package/assets/core/lib/net/net/protocol.meta +9 -0
- package/assets/core/lib/net/net.meta +9 -0
- package/assets/core/lib/net/prompt.meta +9 -0
- package/assets/core/lib/net.meta +9 -0
- package/assets/core/lib/old/VM2.ts +619 -0
- package/assets/core/lib/old/VM2.ts.meta +9 -0
- package/assets/core/lib/old/ViewModel.ts +905 -0
- package/assets/core/lib/old/ViewModel.ts.meta +9 -0
- package/assets/core/lib/old/ViewSearch.ts +125 -0
- package/assets/core/lib/old/ViewSearch.ts.meta +9 -0
- package/assets/core/lib/old.meta +9 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts +113 -0
- package/assets/core/lib/tabbar/TabBarComponent.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarController.ts +86 -0
- package/assets/core/lib/tabbar/TabBarController.ts.meta +9 -0
- package/assets/core/lib/tabbar/TabBarItem.ts +52 -0
- package/assets/core/lib/tabbar/TabBarItem.ts.meta +9 -0
- package/assets/core/lib/tabbar.meta +9 -0
- package/assets/core/lib.meta +12 -0
- package/assets/core.meta +9 -0
- package/assets.meta +9 -0
- package/index.ts +3 -0
- package/index.ts.meta +9 -0
- package/package.json +19 -0
- package/package.json.meta +11 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { error, isValid, js } from "cc";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const inject_vsearch = function (key, targetDataBinding) {
|
|
5
|
+
let propertys = targetDataBinding["vsearch"] || [];
|
|
6
|
+
if (propertys.length == 0) return;
|
|
7
|
+
|
|
8
|
+
let allNodeMap = new Map();
|
|
9
|
+
vsearchHandler(this.node, allNodeMap);
|
|
10
|
+
for (const property of propertys) {
|
|
11
|
+
let className = property.className;
|
|
12
|
+
let tag = property.tag || property.name;
|
|
13
|
+
|
|
14
|
+
let instance = allNodeMap.get(tag);
|
|
15
|
+
if (className.prototype.__classname__ != "cc.Node") {
|
|
16
|
+
instance = instance?.getComponent(className) ?? instance?.addComponent(className);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (instance == null) {
|
|
20
|
+
console.error(`没有找到属性 ${key}->${tag}`);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
this[property.name] = instance;
|
|
24
|
+
}
|
|
25
|
+
allNodeMap = null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const dataBindingContainer = new WeakMap();
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export function ViewSearch(target: any) {
|
|
32
|
+
const onLoad = target.prototype.onLoad;
|
|
33
|
+
/**
|
|
34
|
+
* 重载onload 注入更新
|
|
35
|
+
*/
|
|
36
|
+
target.prototype.onLoad = function () {
|
|
37
|
+
let classKey = js.getClassName(target);
|
|
38
|
+
let targetDataBinding = dataBindingContainer.get(target.prototype) || {};
|
|
39
|
+
//console.log("vm onload111", classKey, targetDataBinding);
|
|
40
|
+
inject_vsearch.call(this, classKey, targetDataBinding);
|
|
41
|
+
//调用之前的onload
|
|
42
|
+
onLoad?.call(this);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function vsearchHandler(parent: any, map: Map<string, Node>) {
|
|
47
|
+
map.set(parent.name, parent);
|
|
48
|
+
let children = parent.children;
|
|
49
|
+
for (const key in children) {
|
|
50
|
+
if (!isValid(children[key])) continue;
|
|
51
|
+
vsearchHandler(children[key], map);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 通过 属性名称 或者标签查询对应的node 或组件
|
|
58
|
+
* @example
|
|
59
|
+
* @vsearch(Label) //查找名节点称为icon的Label组件
|
|
60
|
+
* icon:Label = null;
|
|
61
|
+
*
|
|
62
|
+
* @vsearch(Label,"aa") //查找名节点称为aa的Label组件,并赋值给version
|
|
63
|
+
* version:Label = null;
|
|
64
|
+
*
|
|
65
|
+
* @param className 组件名称
|
|
66
|
+
* @param tag 名称
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
export function vsearch(className: any, tag?: string) {
|
|
70
|
+
return (target: any, propertyKey: string) => {
|
|
71
|
+
let targetDataBinding = dataBindingContainer.get(target) || {};
|
|
72
|
+
let propertys = targetDataBinding["vsearch"] || [];
|
|
73
|
+
propertys.push({ tag: tag, name: propertyKey, className: className });
|
|
74
|
+
targetDataBinding["vsearch"] = propertys;
|
|
75
|
+
dataBindingContainer.set(target, targetDataBinding);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
export function BindUI(target: any, key: string, callback: (key: string, value: any) => void, superPath?: string) {
|
|
81
|
+
const privateKey = `__${key}`;
|
|
82
|
+
target[privateKey] = target[key];
|
|
83
|
+
if (!superPath) {
|
|
84
|
+
superPath = key;
|
|
85
|
+
} else {
|
|
86
|
+
superPath += `.${key}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Object.defineProperty(target, key, {
|
|
90
|
+
get() {
|
|
91
|
+
return this[privateKey];
|
|
92
|
+
},
|
|
93
|
+
set(value) {
|
|
94
|
+
const path = superPath;
|
|
95
|
+
this[privateKey] = value;
|
|
96
|
+
if (callback) {
|
|
97
|
+
callback(path, value);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// **跳过数组,避免递归绑定数组**
|
|
105
|
+
if (target[key] && typeof target[key] === "object" && !Array.isArray(target[key])) {
|
|
106
|
+
BindViewModel(target[key], callback, superPath);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function BindViewModel(viewModel: any, callback: (key: string, value: any) => void, superPath?: string) {
|
|
111
|
+
Object.keys(viewModel).forEach((key) => {
|
|
112
|
+
if (!key.includes("$")) {
|
|
113
|
+
BindUI(viewModel, key, callback, superPath);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface IViewModel {
|
|
119
|
+
/**数据 */
|
|
120
|
+
viewModel: any
|
|
121
|
+
vmMessage: Map<string, any>;
|
|
122
|
+
/**状态改变 */
|
|
123
|
+
updateState(key: string, value: any);
|
|
124
|
+
}
|
|
125
|
+
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// TabBarComponent.ts
|
|
2
|
+
import { Color } from 'cc';
|
|
3
|
+
import { _decorator, Component, Node, Button, Label, Sprite } from 'cc';
|
|
4
|
+
const { ccclass, property } = _decorator;
|
|
5
|
+
|
|
6
|
+
export interface TabItemConfig {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
icon?: string;
|
|
10
|
+
selectedIcon?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@ccclass('TabBarComponent')
|
|
14
|
+
export class TabBarComponent extends Component {
|
|
15
|
+
tabContainer: Node = null;
|
|
16
|
+
|
|
17
|
+
contentContainer: Node = null;
|
|
18
|
+
|
|
19
|
+
private tabItems: Node[] = [];
|
|
20
|
+
private contentItems: Node[] = [];
|
|
21
|
+
private currentIndex: number = 0;
|
|
22
|
+
private tabConfigs: TabItemConfig[] = [];
|
|
23
|
+
|
|
24
|
+
onLoad() {
|
|
25
|
+
this.initTabBar();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
initTabBar() {
|
|
29
|
+
// 清空现有内容
|
|
30
|
+
this.tabItems = [];
|
|
31
|
+
this.contentItems = [];
|
|
32
|
+
|
|
33
|
+
// 根据配置创建标签项
|
|
34
|
+
for (let i = 0; i < this.tabConfigs.length; i++) {
|
|
35
|
+
const config = this.tabConfigs[i];
|
|
36
|
+
this.createTabItem(i, config);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 默认选中第一个标签
|
|
40
|
+
if (this.tabConfigs.length > 0) {
|
|
41
|
+
this.switchTab(0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
createTabItem(index: number, config: TabItemConfig) {
|
|
46
|
+
// 创建标签按钮
|
|
47
|
+
const tabNode = new Node(`Tab_${index}`);
|
|
48
|
+
tabNode.parent = this.tabContainer;
|
|
49
|
+
|
|
50
|
+
const button = tabNode.addComponent(Button);
|
|
51
|
+
const label = tabNode.addComponent(Label);
|
|
52
|
+
|
|
53
|
+
label.string = config.title;
|
|
54
|
+
|
|
55
|
+
// 添加点击事件
|
|
56
|
+
button.node.on(Button.EventType.CLICK, () => {
|
|
57
|
+
this.switchTab(index);
|
|
58
|
+
}, this);
|
|
59
|
+
|
|
60
|
+
this.tabItems.push(tabNode);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
switchTab(index: number) {
|
|
64
|
+
if (index === this.currentIndex) return;
|
|
65
|
+
|
|
66
|
+
// 更新标签状态
|
|
67
|
+
this.updateTabState(this.currentIndex, false);
|
|
68
|
+
this.updateTabState(index, true);
|
|
69
|
+
|
|
70
|
+
// 切换内容视图
|
|
71
|
+
this.switchContent(this.currentIndex, index);
|
|
72
|
+
|
|
73
|
+
this.currentIndex = index;
|
|
74
|
+
|
|
75
|
+
// 发送事件通知
|
|
76
|
+
this.node.emit('tab-switched', {
|
|
77
|
+
from: this.currentIndex,
|
|
78
|
+
to: index
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
updateTabState(index: number, selected: boolean) {
|
|
83
|
+
const tabNode = this.tabItems[index];
|
|
84
|
+
if (!tabNode) return;
|
|
85
|
+
|
|
86
|
+
// 更新标签样式(可根据需要自定义)
|
|
87
|
+
const label = tabNode.getComponent(Label);
|
|
88
|
+
if (label) {
|
|
89
|
+
label.color = selected ? Color.BLUE : Color.GRAY;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
switchContent(fromIndex: number, toIndex: number) {
|
|
94
|
+
// 隐藏当前内容
|
|
95
|
+
if (this.contentItems[fromIndex]) {
|
|
96
|
+
this.contentItems[fromIndex].active = false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 显示新内容
|
|
100
|
+
if (this.contentItems[toIndex]) {
|
|
101
|
+
this.contentItems[toIndex].active = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
addTab(config: TabItemConfig, contentNode: Node) {
|
|
106
|
+
this.tabConfigs.push(config);
|
|
107
|
+
if (contentNode) {
|
|
108
|
+
contentNode.parent = this.contentContainer;
|
|
109
|
+
contentNode.active = false;
|
|
110
|
+
this.contentItems.push(contentNode);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// TabBarController.ts
|
|
2
|
+
import { _decorator, Component, Node, Vec3, Enum } from 'cc';
|
|
3
|
+
import { instantiate } from 'cc';
|
|
4
|
+
import { Layout } from 'cc';
|
|
5
|
+
import { Prefab } from 'cc';
|
|
6
|
+
import { BindEventClick } from '../../home/Tools';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const { ccclass, property } = _decorator;
|
|
10
|
+
|
|
11
|
+
enum TabBarPosition {
|
|
12
|
+
BOTTOM = 0,
|
|
13
|
+
TOP = 1
|
|
14
|
+
}
|
|
15
|
+
export interface TabItemConfig {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
icon?: string;
|
|
19
|
+
selectedIcon?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@ccclass('TabBarController')
|
|
24
|
+
export class TabBarController extends Component {
|
|
25
|
+
/**
|
|
26
|
+
* 列表项配置
|
|
27
|
+
*/
|
|
28
|
+
public count = 0;
|
|
29
|
+
public selectRowNomal: number = 2;
|
|
30
|
+
|
|
31
|
+
public updateCell: (cell: Node, row: number) => void;
|
|
32
|
+
public callbackSelect: (row: number, selelNode: Node, lastNode: Node) => void = null;
|
|
33
|
+
|
|
34
|
+
@property(Prefab)
|
|
35
|
+
HomeTabbarItem: Prefab = null;
|
|
36
|
+
@property(Node)
|
|
37
|
+
bottom: Node = null;
|
|
38
|
+
|
|
39
|
+
layout: Layout;
|
|
40
|
+
itemList: Node[] = [];
|
|
41
|
+
public selectRow: number = 0;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
onLoad() {
|
|
47
|
+
super.onLoad();
|
|
48
|
+
this.layout = this.bottom.getComponent(Layout);
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
reload() {
|
|
53
|
+
for (let index = 0; index < this.count; index++) {
|
|
54
|
+
let node = this.itemList[index]
|
|
55
|
+
if (!node) {
|
|
56
|
+
node = instantiate(this.HomeTabbarItem)
|
|
57
|
+
this.itemList.push(node);
|
|
58
|
+
node.parent = this.bottom;
|
|
59
|
+
}
|
|
60
|
+
node.name = index.toString();
|
|
61
|
+
node.active = true;
|
|
62
|
+
this.updateCell?.(node, index)
|
|
63
|
+
|
|
64
|
+
node.off(Node.EventType.TOUCH_END)
|
|
65
|
+
node.on(Node.EventType.TOUCH_END, () => {
|
|
66
|
+
this.switchTab(index);
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
if (this.selectRowNomal === index) {
|
|
70
|
+
this.switchTab(index, true);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.layout.updateLayout();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
switchTab(index: number, isDefault: boolean = false) {
|
|
77
|
+
if (this.selectRow === index && !isDefault) { return }
|
|
78
|
+
this.callbackSelect?.(index, this.itemList[index], this.itemList[this.selectRow])
|
|
79
|
+
this.selectRow = index;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// TabBarItem.ts
|
|
2
|
+
import { _decorator, Component, Node, Sprite, Label, Button, Color } from 'cc';
|
|
3
|
+
const { ccclass, property } = _decorator;
|
|
4
|
+
|
|
5
|
+
@ccclass('TabBarItem')
|
|
6
|
+
export class TabBarItem extends Component {
|
|
7
|
+
@property(Label)
|
|
8
|
+
titleLabel: Label = null;
|
|
9
|
+
|
|
10
|
+
@property(Sprite)
|
|
11
|
+
iconSprite: Sprite = null;
|
|
12
|
+
|
|
13
|
+
@property(Color)
|
|
14
|
+
normalColor: Color = Color.GRAY;
|
|
15
|
+
|
|
16
|
+
@property(Color)
|
|
17
|
+
selectedColor: Color = Color.BLUE;
|
|
18
|
+
|
|
19
|
+
private _isSelected: boolean = false;
|
|
20
|
+
private _title: string = '';
|
|
21
|
+
private _icon: string = '';
|
|
22
|
+
|
|
23
|
+
get isSelected(): boolean {
|
|
24
|
+
return this._isSelected;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set title(value: string) {
|
|
28
|
+
this._title = value;
|
|
29
|
+
if (this.titleLabel) {
|
|
30
|
+
this.titleLabel.string = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get title(): string {
|
|
35
|
+
return this._title;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
start() {
|
|
39
|
+
const button = this.node.addComponent(Button);
|
|
40
|
+
button.transition = Button.Transition.COLOR;
|
|
41
|
+
button.normalColor = Color.WHITE;
|
|
42
|
+
button.pressedColor = new Color(220, 220, 220);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setSelected(selected: boolean) {
|
|
46
|
+
this._isSelected = selected;
|
|
47
|
+
if (this.titleLabel) {
|
|
48
|
+
this.titleLabel.color = selected ? this.selectedColor : this.normalColor;
|
|
49
|
+
}
|
|
50
|
+
// 可以在这里添加图标切换逻辑
|
|
51
|
+
}
|
|
52
|
+
}
|
package/assets/core.meta
ADDED
package/assets.meta
ADDED
package/index.ts
ADDED
package/index.ts.meta
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cc-component/cc-core",
|
|
3
|
+
"version": "1.2.8",
|
|
4
|
+
"engine": ">=3.8.6",
|
|
5
|
+
"description": "系统组件添加常用扩展方法",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://gitee.com/YangFanHome/cc-core"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT"
|
|
19
|
+
}
|