UERichTextLayer.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using CommonLang.Xml;
  2. using CommonUI.Data;
  3. using CommonUI.Display.Text;
  4. using CommonUnity3D.UGUI;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using UnityEngine;
  10. namespace CommonUnity3D.UGUIEditor.UI
  11. {
  12. public abstract class BaseUERichTextBox : UIComponent
  13. {
  14. protected BaseUERichTextBox()
  15. {
  16. }
  17. public string XmlText
  18. {
  19. set { RichTextLayer.XmlText = value; }
  20. }
  21. public string UnityRichText
  22. {
  23. set { this.XmlText = UIUtils.UnityRichTextToXmlText(value); }
  24. }
  25. public abstract AttributedString AText { get; set; }
  26. public abstract UGUIRichTextLayer RichTextLayer { get; }
  27. protected override void DecodeBegin(UIEditor.Decoder editor, UIComponentMeta e)
  28. {
  29. base.DecodeBegin(editor, e);
  30. }
  31. protected override void DecodeEnd(UIEditor.Decoder editor, UIComponentMeta e)
  32. {
  33. base.DecodeEnd(editor, e);
  34. this.OnUpdateLayout();
  35. this.Decode_Text(editor, e as UETextBoxHtmlMeta);
  36. this.Enable = false;
  37. this.EnableChildren = true;
  38. }
  39. private void Decode_Text(UIEditor.Decoder editor, UETextBoxHtmlMeta e)
  40. {
  41. this.RichTextLayer.DefaultTextAttribute = new TextAttribute(
  42. CommonUI.Display.Color.toRGBA(e.textColor),
  43. e.text_size,
  44. editor.editor.DefaultFont.name,
  45. CommonUI.Display.FontStyle.STYLE_PLAIN,
  46. RichTextAlignment.taNA,
  47. UIUtils.ToTextShadowCount(new Vector2(e.text_shadow_x, e.text_shadow_y)),
  48. CommonUI.Display.Color.toRGBA(e.text_shadow_dcolor, (int)(e.text_shadow_alpha * 255))
  49. );
  50. if (!string.IsNullOrEmpty(e.HtmlText))
  51. {
  52. this.UnityRichText = e.HtmlText;
  53. }
  54. }
  55. }
  56. public class UERichTextBox : BaseUERichTextBox
  57. {
  58. protected readonly RichTextBox mRichTextBox;
  59. public UERichTextBox(bool use_bitmap)
  60. {
  61. this.mRichTextBox = new RichTextBox("rich_text", use_bitmap);
  62. this.AddChild(mRichTextBox);
  63. }
  64. public UERichTextBox() : this(UIEditor.GlobalUseBitmapText) { }
  65. public override AttributedString AText
  66. {
  67. get { return mRichTextBox.AText; }
  68. set
  69. {
  70. if (IsDispose) return;
  71. mRichTextBox.AText = value;
  72. }
  73. }
  74. public override UGUIRichTextLayer RichTextLayer
  75. {
  76. get { return mRichTextBox.RichTextLayer; }
  77. }
  78. public RichTextBox TextBox
  79. {
  80. get { return mRichTextBox; }
  81. }
  82. protected override void OnUpdate()
  83. {
  84. base.OnUpdate();
  85. Vector2 bsize = this.Size2D;
  86. if (this.Layout != null)
  87. {
  88. mRichTextBox.Position2D = new Vector2(
  89. Layout.ClipSize,
  90. Layout.ClipSize);
  91. mRichTextBox.Size2D = new Vector2(
  92. bsize.x - Layout.ClipSize2,
  93. bsize.y - Layout.ClipSize2);
  94. }
  95. else
  96. {
  97. mRichTextBox.Size2D = bsize;
  98. }
  99. }
  100. }
  101. public class UERichTextPan : BaseUERichTextBox
  102. {
  103. protected readonly RichTextPan mRichTextBox;
  104. public UERichTextPan(bool use_bitmap)
  105. {
  106. this.mRichTextBox = new RichTextPan(use_bitmap, "rich_text");
  107. this.AddChild(mRichTextBox);
  108. }
  109. public UERichTextPan() : this(UIEditor.GlobalUseBitmapText) { }
  110. public override AttributedString AText
  111. {
  112. get { return mRichTextBox.AText; }
  113. set { mRichTextBox.AText = value; }
  114. }
  115. public override UGUIRichTextLayer RichTextLayer
  116. {
  117. get { return mRichTextBox.RichTextLayer; }
  118. }
  119. public RichTextPan TextPan
  120. {
  121. get { return mRichTextBox; }
  122. }
  123. protected override void OnUpdate()
  124. {
  125. base.OnUpdate();
  126. Vector2 bsize = this.Size2D;
  127. if (this.Layout != null)
  128. {
  129. mRichTextBox.Position2D = new Vector2(
  130. Layout.ClipSize,
  131. Layout.ClipSize);
  132. mRichTextBox.Size2D = new Vector2(
  133. bsize.x - Layout.ClipSize2,
  134. bsize.y - Layout.ClipSize2);
  135. }
  136. else
  137. {
  138. mRichTextBox.Size2D = bsize;
  139. }
  140. }
  141. }
  142. }