123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import { utils } from "./Utils";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class LogOutView extends cc.Component {
- scrollView: cc.ScrollView = null;
- content: cc.Node = null;
- logLabel: cc.Node = null;
- logArray: Array<string> = [];
- clearBtn: cc.Node = null;
- showLogViewBtn: cc.Node = null;
- hideLogViewBtn: cc.Node = null;
- onLoad() {
- if (utils.otherConfig && utils.otherConfig.group) {
- this.node.group = utils.otherConfig.group;
- }
- let ratio: number = 1;
- if (cc.winSize.height < cc.winSize.width) {
- // 横屏游戏
- ratio = cc.winSize.width / 1920 * 0.7;
- } else {
- ratio = cc.winSize.width / 1080;
- }
- this.node.scale = ratio;
- }
- start() {
- this.initUi();
- this.initListener();
- this.initData();
- this.schedule(() => {
- this.showLog();
- }, 0);
- }
- /**
- * 初始化UI
- */
- protected initUi(): void {
- this.scrollView = this.node.getChildByName("ScrollView").getComponent(cc.ScrollView);
- this.showLogViewBtn = this.node.getChildByName("BtnShowLogView");
- this.hideLogViewBtn = this.node.getChildByName("BtnHideLogView");
- this.clearBtn = this.node.getChildByName("BtnClearLog");
- this.content = this.scrollView.content;
- this.logLabel = this.content.children[0];
- this.content.removeAllChildren();
- }
- /**
- * 添加LOG输出
- * @param logContent log
- */
- public addLog(logContent: any, ...optionalParams: any[]): void {
- let str = "";
- str += logContent;
- optionalParams.forEach(element => {
- str += "," + element;
- });
- this.logArray.push(str);
- }
- public showLog() {
- if (this.logArray.length > 0) {
- let tempAry = this.logArray;
- this.logArray = [];
- tempAry.forEach(log => {
- let tempLogLabel = cc.instantiate(this.logLabel);
- tempLogLabel.getComponent(cc.Label).string = `日志输出:${log}`;
- this.content.addChild(tempLogLabel);
- });
- }
- }
- /**
- * 初始化监听事件
- */
- protected initListener(): void {
- }
- /**
- * 初始化数据
- */
- protected initData(): void {
- }
- /**
- * 显示日志框
- */
- onShowLogView() {
- this.scrollView.node.active = true;
- this.clearBtn.active = true;
- this.showLogViewBtn.active = false;
- this.hideLogViewBtn.active = true;
- }
- /**
- * 隐藏日志框
- */
- onHideLogView() {
- this.scrollView.node.active = false;
- this.clearBtn.active = false;
- this.showLogViewBtn.active = true;
- this.hideLogViewBtn.active = false;
- }
- /**
- * 清空日志
- */
- clearLogView() {
- this.content.removeAllChildren();
- }
- // update (dt) {}
- }
|