123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using CommonLang.Xml;
- using CommonUI.Data;
- using CommonUI.Display.Text;
- using CommonUnity3D.UGUI;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- namespace CommonUnity3D.UGUIEditor.UI
- {
- public abstract class BaseUERichTextBox : UIComponent
- {
- protected BaseUERichTextBox()
- {
- }
- public string XmlText
- {
- set { RichTextLayer.XmlText = value; }
- }
- public string UnityRichText
- {
- set { this.XmlText = UIUtils.UnityRichTextToXmlText(value); }
- }
- public abstract AttributedString AText { get; set; }
- public abstract UGUIRichTextLayer RichTextLayer { get; }
- protected override void DecodeBegin(UIEditor.Decoder editor, UIComponentMeta e)
- {
- base.DecodeBegin(editor, e);
- }
- protected override void DecodeEnd(UIEditor.Decoder editor, UIComponentMeta e)
- {
- base.DecodeEnd(editor, e);
- this.OnUpdateLayout();
- this.Decode_Text(editor, e as UETextBoxHtmlMeta);
- this.Enable = false;
- this.EnableChildren = true;
- }
- private void Decode_Text(UIEditor.Decoder editor, UETextBoxHtmlMeta e)
- {
- this.RichTextLayer.DefaultTextAttribute = new TextAttribute(
- CommonUI.Display.Color.toRGBA(e.textColor),
- e.text_size,
- editor.editor.DefaultFont.name,
- CommonUI.Display.FontStyle.STYLE_PLAIN,
- RichTextAlignment.taNA,
- UIUtils.ToTextShadowCount(new Vector2(e.text_shadow_x, e.text_shadow_y)),
- CommonUI.Display.Color.toRGBA(e.text_shadow_dcolor, (int)(e.text_shadow_alpha * 255))
- );
- if (!string.IsNullOrEmpty(e.HtmlText))
- {
- this.UnityRichText = e.HtmlText;
- }
- }
- }
- public class UERichTextBox : BaseUERichTextBox
- {
- protected readonly RichTextBox mRichTextBox;
- public UERichTextBox(bool use_bitmap)
- {
- this.mRichTextBox = new RichTextBox("rich_text", use_bitmap);
- this.AddChild(mRichTextBox);
- }
- public UERichTextBox() : this(UIEditor.GlobalUseBitmapText) { }
- public override AttributedString AText
- {
- get { return mRichTextBox.AText; }
- set
- {
- if (IsDispose) return;
- mRichTextBox.AText = value;
- }
- }
- public override UGUIRichTextLayer RichTextLayer
- {
- get { return mRichTextBox.RichTextLayer; }
- }
- public RichTextBox TextBox
- {
- get { return mRichTextBox; }
- }
- protected override void OnUpdate()
- {
- base.OnUpdate();
- Vector2 bsize = this.Size2D;
- if (this.Layout != null)
- {
- mRichTextBox.Position2D = new Vector2(
- Layout.ClipSize,
- Layout.ClipSize);
- mRichTextBox.Size2D = new Vector2(
- bsize.x - Layout.ClipSize2,
- bsize.y - Layout.ClipSize2);
- }
- else
- {
- mRichTextBox.Size2D = bsize;
- }
- }
- }
- public class UERichTextPan : BaseUERichTextBox
- {
- protected readonly RichTextPan mRichTextBox;
- public UERichTextPan(bool use_bitmap)
- {
- this.mRichTextBox = new RichTextPan(use_bitmap, "rich_text");
- this.AddChild(mRichTextBox);
- }
- public UERichTextPan() : this(UIEditor.GlobalUseBitmapText) { }
- public override AttributedString AText
- {
- get { return mRichTextBox.AText; }
- set { mRichTextBox.AText = value; }
- }
- public override UGUIRichTextLayer RichTextLayer
- {
- get { return mRichTextBox.RichTextLayer; }
- }
- public RichTextPan TextPan
- {
- get { return mRichTextBox; }
- }
- protected override void OnUpdate()
- {
- base.OnUpdate();
- Vector2 bsize = this.Size2D;
- if (this.Layout != null)
- {
- mRichTextBox.Position2D = new Vector2(
- Layout.ClipSize,
- Layout.ClipSize);
- mRichTextBox.Size2D = new Vector2(
- bsize.x - Layout.ClipSize2,
- bsize.y - Layout.ClipSize2);
- }
- else
- {
- mRichTextBox.Size2D = bsize;
- }
- }
- }
- }
|