/// <summary> /// 调节文本内容,多余的内容“...”表示(For NGUI) /// </summary> /// <param name="label"></param> /// <param name="strContent"></param> public static void LabelWarp(UILabel label, string strContent, Action <bool> callback = null) { string strOut = string.Empty; // 当前配置下的UILabel是否能够包围Text内容 // Wrap是NGUI中自带的方法,其中strContent表示要在UILabel中显示的内容,strOur表示处理好后返回的字符串,uiLabel.height是字符串的高度 。 bool bWarp = label.Wrap(strContent, out strOut, label.height); if (strOut.Length <= 0) { bWarp = true; } // 如果不能,就是说Text内容不能全部显示,这个时候,我们把最后一个字符去掉,换成省略号"..." if (!bWarp) { strOut = strOut.Substring(0, strOut.Length - 1); strOut += "..."; label.text = strOut; } if (callback != null) { callback(bWarp); } // 如果可以包围,就是说Text内容可以完全显示,这个时候,我们不做处理,直接显示内容。 }
static int Wrap(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 3) { UILabel obj = (UILabel)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UILabel"); string arg0 = LuaScriptMgr.GetLuaString(L, 2); string arg1 = null; bool o = obj.Wrap(arg0, out arg1); LuaScriptMgr.Push(L, o); LuaScriptMgr.Push(L, arg1); return(2); } else if (count == 4) { UILabel obj = (UILabel)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UILabel"); string arg0 = LuaScriptMgr.GetLuaString(L, 2); string arg1 = null; int arg2 = (int)LuaScriptMgr.GetNumber(L, 4); bool o = obj.Wrap(arg0, out arg1, arg2); LuaScriptMgr.Push(L, o); LuaScriptMgr.Push(L, arg1); return(2); } else { LuaDLL.luaL_error(L, "invalid arguments to method: UILabel.Wrap"); } return(0); }
public static void SetWrapLabel(UILabel lab, string text, int height) { string text2 = null; lab.UpdateNGUIText(); if (!lab.Wrap(text, out text2, height)) { text2 = text2.Substring(0, text2.Length - 1); text2 += "..."; } lab.text = text2; }
private static string ConvertWrap(UILabel label, string orgText) { string final = string.Empty; if (!label.Wrap(orgText, out final)) { final = orgText; } if (orgText.Equals(final)) { return(final); } string text = string.Empty; final = final.Replace("\n", "\n "); string[] array = final.Split('\n'); for (int i = 0; i < array.Length; i++) { string text2 = array[i]; if (text2.Length != 0) { string value = text2[0].ToString(); if (text.Length > 0 && SuppressionHead.IndexOf(value) >= 0) { text = text.Insert(text.Length - 1, "\n"); for (int j = i; j < array.Length; j++) { text += array[j]; } break; } string value2 = text2[text2.Length - 1].ToString(); if (SuppressionTail.IndexOf(value2) >= 0) { text2 = text2.Insert(text2.Length - 1, "\n"); text += text2; for (int k = i + 1; k < array.Length; k++) { text += array[k]; } break; } text += text2; } } return(text); }
public static int Wrap(IntPtr l) { int result; try { int num = LuaDLL.pua_gettop(l); if (num == 3) { UILabel uILabel = (UILabel)LuaObject.checkSelf(l); string text; LuaObject.checkType(l, 2, out text); string s; bool b = uILabel.Wrap(text, out s); LuaObject.pushValue(l, true); LuaObject.pushValue(l, b); LuaObject.pushValue(l, s); result = 3; } else if (num == 4) { UILabel uILabel2 = (UILabel)LuaObject.checkSelf(l); string text2; LuaObject.checkType(l, 2, out text2); int height; LuaObject.checkType(l, 4, out height); string s2; bool b2 = uILabel2.Wrap(text2, out s2, height); LuaObject.pushValue(l, true); LuaObject.pushValue(l, b2); LuaObject.pushValue(l, s2); result = 3; } else { LuaObject.pushValue(l, false); LuaDLL.pua_pushstring(l, "No matched override function to call"); result = 2; } } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
/// <summary> /// 获取裁剪后的文字 /// </summary> /// <param name="s">文字</param> /// <param name="label">label的长宽需要是固定的</param> /// <param name="changeLen">替换文字的长度</param> /// <param name="changeStr">替换文字</param> /// <returns></returns> public static string GetClampText(string s, UILabel label, int changeLen, string changeStr) { string strOut = string.Empty; if (!string.IsNullOrEmpty(s)) { label.text = s; // 当前配置下的UILabel是否能够包围Text内容 // Wrap是NGUI中自带的方法,其中strContent表示要在UILabel中显示的内容,strOur表示处理好后返回的字符串,uiLabel.height是字符串的高度 。 bool bWarp = label.Wrap(s, out strOut, label.height); // 如果不能,就是说Text内容不能全部显示,这个时候,我们把最后一个字符去掉,换成省略号"..." if (!bWarp) { strOut = strOut.Substring(0, strOut.Length - changeLen); strOut += changeStr; } } return(strOut); }
static public int Wrap(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 3) { UILabel self = (UILabel)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.String a2; var ret = self.Wrap(a1, out a2); pushValue(l, true); pushValue(l, ret); pushValue(l, a2); return(3); } else if (argc == 4) { UILabel self = (UILabel)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.String a2; System.Int32 a3; checkType(l, 4, out a3); var ret = self.Wrap(a1, out a2, a3); pushValue(l, true); pushValue(l, ret); pushValue(l, a2); return(3); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
public static string Convert(UILabel label, string orgText) { string final = string.Empty; if (!label.Wrap(orgText, out final)) { final = label.text; } if (final.Equals(orgText)) { return(orgText); } string text = orgText.Replace("\r\n", "\n"); bool flag = true; while (flag) { flag = false; string text2 = string.Empty; string[] array = text.Split('\n'); for (int i = 0; i < array.Length; i++) { if (0 < i) { text2 += '\n'; } string orgText2 = array[i]; string str = ConvertWrap(label, orgText2); text2 += str; } if (!text2.Equals(text)) { flag = true; text = text2; } } return(text); }
static int Wrap(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 3) { UILabel obj = (UILabel)ToLua.CheckObject<UILabel>(L, 1); string arg0 = ToLua.CheckString(L, 2); string arg1 = null; bool o = obj.Wrap(arg0, out arg1); LuaDLL.lua_pushboolean(L, o); LuaDLL.lua_pushstring(L, arg1); return 2; } else if (count == 4) { UILabel obj = (UILabel)ToLua.CheckObject<UILabel>(L, 1); string arg0 = ToLua.CheckString(L, 2); string arg1 = null; int arg2 = (int)LuaDLL.luaL_checknumber(L, 4); bool o = obj.Wrap(arg0, out arg1, arg2); LuaDLL.lua_pushboolean(L, o); LuaDLL.lua_pushstring(L, arg1); return 2; } else { return LuaDLL.luaL_throw(L, "invalid arguments to method: UILabel.Wrap"); } } catch (Exception e) { return LuaDLL.toluaL_exception(L, e); } }
public static void SetWrapText(this UILabel mUILabel, string format, params object[] objects) { if (mUILabel.IsNull()) { return; } if (format.IsNullOrEmpty()) { mUILabel.text = string.Empty; } string content = format.Format(objects); bool bWarp = mUILabel.Wrap(content, out content, mUILabel.height); if (!bWarp && !content.IsNullOrEmpty()) { content = content.Substring(0, content.Length - 1); content = content.Insert(content.Length, "..."); } else { content = format.Format(objects); } mUILabel.text = content; }
public static void SetWrapText(this UILabel mUILabel, object t) { if (mUILabel.IsNull()) { return; } // TODO: raise exception or log error if (t.IsNull()) { mUILabel.text = string.Empty; } string content = t.ToString(); bool bWarp = mUILabel.Wrap(content, out content, mUILabel.height); if (!bWarp && !content.IsNullOrEmpty()) { content = content.Substring(0, content.Length - 1); content = content.Insert(content.Length, "..."); } else { content = t.ToString(); } mUILabel.text = content; }
private IEnumerator DoAddMessage(string name, string msg, StoryDirector.POS tail_dir, StoryDirector.MSG_TYPE msg_type) { typewriter = null; Transform table_t = GetCtrl(UI.TBL_MESSAGE); string prefab_name = "StoryMessageItem0"; if (msg_type == StoryDirector.MSG_TYPE.MONOLOGUE) { prefab_name = "StoryMessageItem1"; } Transform message_item_t = Realizes(prefab_name, table_t, true); message_item_t.SetSiblingIndex(0); UIWidget message_item_w = message_item_t.GetComponent <UIWidget>(); lastMessageItem = message_item_t; balloon = base.GetComponent <UISprite>(message_item_t, (Enum)UI.SPR_BALLOON); tailLeft = FindCtrl(message_item_t, UI.SPR_TAIL_L); tailRight = FindCtrl(message_item_t, UI.SPR_TAIL_R); tailCenter = FindCtrl(message_item_t, UI.SPR_TAIL_C); nameLabel = base.GetComponent <UILabel>(message_item_t, (Enum)UI.LBL_NAME); messageLabel = base.GetComponent <UILabel>(message_item_t, (Enum)UI.LBL_MESSAGE); initBaseHeight = message_item_w.height; messageLabel.text = " "; initMessageHeight = messageLabel.height; messageHeight = initMessageHeight; string temp = string.Empty; if (messageLabel.Wrap(msg, out temp)) { msg = WordWrap.Convert(messageLabel, msg); } SetLastMessageFocus(true); SetMessageDragEnabled(false); if (msg_type == StoryDirector.MSG_TYPE.NORMAL) { if (tailLeft != null && tail_dir != StoryDirector.POS.LEFT) { tailLeft.get_gameObject().SetActive(false); } if (tailRight != null && tail_dir != StoryDirector.POS.RIGHT) { tailRight.get_gameObject().SetActive(false); } if (tailCenter != null && tail_dir != StoryDirector.POS.CENTER) { tailCenter.get_gameObject().SetActive(false); } nameLabel.text = name; } UIWidget next_arrow_w = base.GetComponent <UIWidget>((Enum)UI.SPR_NEXT); next_arrow_w.get_gameObject().SetActive(false); List <UITweener> tweens = new List <UITweener>(); message_item_t.GetComponentsInChildren <UITweener>(tweens); while (tweens.Find((UITweener o) => o.get_enabled()) != null) { yield return((object)null); } SoundManager.PlaySystemSE(SoundID.UISE.POPUP, 1f); messageLabel.text = msg; typewriter = messageLabel.get_gameObject().AddComponent <TypewriterEffect>(); typewriter.charsPerSecond = StoryDirector.SPEED_TYPEWRITER; typewriter.ResetToBeginning(); while (typewriter.isActive) { yield return((object)null); } yield return((object)null); next_arrow_w.get_gameObject().SetActive(true); Vector3[] message_corners = message_item_w.worldCorners; Vector3[] next_arrow_corners = next_arrow_w.worldCorners; ((UIRect)next_arrow_w).SetAnchor(null); next_arrow_w.cachedTransform.set_position(new Vector3((next_arrow_corners[0].x + next_arrow_corners[2].x) * 0.5f, message_corners[0].y - (next_arrow_corners[1].y - next_arrow_corners[0].y) * 0.5f, next_arrow_corners[0].z)); SetMessageDragEnabled(true); Object.Destroy(typewriter); typewriter = null; messageHeight = 0; messageNum++; coroutine = null; }
public void EnabledTypewriter() { mTyping = true; mLabel.supportEncoding = true; mOffset = 0; mNextChar = 0; colorStr = ""; mLabel.pivot = UIWidget.Pivot.TopLeft; colorList.Clear(); int colorCount = 0; int addIter = 0; string CopymLabel = mLabel.text; while (mLabel.text.Contains("{")) { int index = mLabel.text.IndexOf("{"); mLabel.text = mLabel.text.Remove(index, 8); } mLabel.Wrap(mLabel.text, out mText); int NIndex = 0; while (mText.Contains("\n")) { NIndex = mText.IndexOf("\n"); break; } while (CopymLabel.Contains("{")) { int index = CopymLabel.IndexOf("{"); if (NIndex < 1) { addIter = 0; } else { if (index >= NIndex) { addIter = 1; } if (index >= NIndex * 2) { addIter = 2; } if (index >= NIndex * 3) { addIter = 3; } } ColorInfo aColorInfo = new ColorInfo(); aColorInfo.startIndex = addIter + index + colorCount * 8; aColorInfo.color = CopymLabel.Substring(index, 8); CopymLabel = CopymLabel.Remove(index, 8); colorList.Add(aColorInfo); colorCount++; } for (int i = 0; i < colorList.Count; i++) { mText = mText.Insert(colorList[i].startIndex, colorList[i].color); } }