|
@@ -1,4 +1,4 @@
|
|
-import { _decorator, CacheMode, Color, Component, Label, Node, Size, Tween, tween, UITransform, Vec3, view } from 'cc';
|
|
|
|
|
|
+import { _decorator, CacheMode, Color, Component, Label, Node, RichText, Size, Tween, tween, UITransform, Vec3, view } from 'cc';
|
|
import { guangboData } from '../../data';
|
|
import { guangboData } from '../../data';
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@@ -15,22 +15,36 @@ export class home_guangbo extends Component {
|
|
this.data_list = data_list
|
|
this.data_list = data_list
|
|
// console.log(this.data_list)
|
|
// console.log(this.data_list)
|
|
if(this.data_list.length==0) {
|
|
if(this.data_list.length==0) {
|
|
- this.lab_content.getComponent(Label).getComponent(Label).string = ''
|
|
|
|
|
|
+ this.setLabContent('')
|
|
this.unscheduleAllCallbacks()
|
|
this.unscheduleAllCallbacks()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
this.cur_index = 0
|
|
this.cur_index = 0
|
|
- this.getContentText()
|
|
|
|
|
|
+ // this.getContentLabelText()
|
|
|
|
+ this.getContentRichText()
|
|
}
|
|
}
|
|
|
|
|
|
- private getContentText() {
|
|
|
|
|
|
+ private getContentRichText() {
|
|
if(this.cur_index>=this.data_list.length) {
|
|
if(this.cur_index>=this.data_list.length) {
|
|
this.cur_index = 0
|
|
this.cur_index = 0
|
|
}
|
|
}
|
|
let cur_content = this.data_list[this.cur_index].title
|
|
let cur_content = this.data_list[this.cur_index].title
|
|
- let lab_com = this.lab_content.getComponent(Label)
|
|
|
|
- lab_com.getComponent(Label).string = cur_content
|
|
|
|
- let cur_content_width = this.computeTextWidth(cur_content,lab_com.fontSize,lab_com.lineHeight)
|
|
|
|
|
|
+ cur_content = '<b>' + cur_content + '</b>' // 加粗
|
|
|
|
+ this.setLabContent(cur_content)
|
|
|
|
+ let cur_content_width = this.lab_content.getComponent(UITransform).contentSize.width
|
|
|
|
+ // console.log('cur_content_width=',cur_content_width)
|
|
|
|
+ this.lab_content.setPosition(this.screen_width/2+this.left_padding,this.lab_content.getPosition().y,0)
|
|
|
|
+ this.runContent(cur_content_width)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private getContentLabelText() {
|
|
|
|
+ if(this.cur_index>=this.data_list.length) {
|
|
|
|
+ this.cur_index = 0
|
|
|
|
+ }
|
|
|
|
+ let cur_content = this.data_list[this.cur_index].title
|
|
|
|
+ this.setLabContent(cur_content)
|
|
|
|
+ let lab_component = this.lab_content.getComponent(Label)
|
|
|
|
+ let cur_content_width = this.computeLabelTextWidth(cur_content,lab_component.fontSize,lab_component.lineHeight)
|
|
// console.log('cur_content_width=',cur_content_width)
|
|
// console.log('cur_content_width=',cur_content_width)
|
|
let cur_content_height = this.lab_content.getComponent(UITransform).contentSize.height
|
|
let cur_content_height = this.lab_content.getComponent(UITransform).contentSize.height
|
|
this.lab_content.getComponent(UITransform).setContentSize(new Size(cur_content_width,cur_content_height))
|
|
this.lab_content.getComponent(UITransform).setContentSize(new Size(cur_content_width,cur_content_height))
|
|
@@ -49,18 +63,25 @@ export class home_guangbo extends Component {
|
|
run_pos_x = this.screen_width/2+this.left_padding
|
|
run_pos_x = this.screen_width/2+this.left_padding
|
|
this.unscheduleAllCallbacks()
|
|
this.unscheduleAllCallbacks()
|
|
this.cur_index++
|
|
this.cur_index++
|
|
- this.getContentText()
|
|
|
|
|
|
+ // this.getContentLabelText()
|
|
|
|
+ this.getContentRichText()
|
|
}
|
|
}
|
|
},0.08)
|
|
},0.08)
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
|
|
+ private setLabContent(text:string) {
|
|
|
|
+ // this.lab_content.getComponent(Label).string = text
|
|
|
|
+ this.lab_content.getComponent(RichText).string = text
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* @param text 要显示文本内容
|
|
* @param text 要显示文本内容
|
|
* @param designSize label的设计宽高
|
|
* @param designSize label的设计宽高
|
|
* @param fontSize 字体大小
|
|
* @param fontSize 字体大小
|
|
* @param lineHeight 行高
|
|
* @param lineHeight 行高
|
|
*/
|
|
*/
|
|
- private computeTextWidth(text: string, fontSize: number, lineHeight: number):number {
|
|
|
|
|
|
+ private computeLabelTextWidth(text: string, fontSize: number, lineHeight: number):number {
|
|
|
|
+ // 计算Label宽度
|
|
let node = new Node();
|
|
let node = new Node();
|
|
var newlabel :Label = node.addComponent(Label);
|
|
var newlabel :Label = node.addComponent(Label);
|
|
newlabel.fontSize = fontSize;
|
|
newlabel.fontSize = fontSize;
|
|
@@ -74,7 +95,7 @@ export class home_guangbo extends Component {
|
|
newlabel.updateRenderData(true);
|
|
newlabel.updateRenderData(true);
|
|
let textWidth = newlabel.getComponent(UITransform).contentSize.width;
|
|
let textWidth = newlabel.getComponent(UITransform).contentSize.width;
|
|
node.destroy();
|
|
node.destroy();
|
|
-
|
|
|
|
|
|
+
|
|
return textWidth;
|
|
return textWidth;
|
|
}
|
|
}
|
|
|
|
|