void Align() { int nLineGap = 0; // 先让Y轴居中吧 float fOffsetY = m_fLineOffsetY + m_fCurLineHeight * 0.5f; for (int i = m_nStartLineIndex; i < m_nTitleNumb; ++i) { HUDTilteLine title = m_TitleLine[i]; HudTitleAttribute titleAttrib = HudSetting.Instance.TitleSets[(int)title.m_nType].GetTitle(title.m_nColorIndex); if (titleAttrib.AlignType == HUDAlignType.align_right) { OffsetXY(title.m_nStart, title.m_nEnd, m_fCurLineWidth * 0.5f + titleAttrib.CharGap, fOffsetY); } else if (titleAttrib.AlignType == HUDAlignType.align_left) { OffsetXY(title.m_nStart, title.m_nEnd, -m_fCurLineWidth * 0.5f - title.m_fWidth - titleAttrib.CharGap, fOffsetY); } else { OffsetXY(title.m_nStart, title.m_nEnd, title.m_fWidth * -0.5f, fOffsetY); } if (nLineGap < titleAttrib.LineGap) { nLineGap = titleAttrib.LineGap; } } m_fLineOffsetY += m_fCurLineHeight + nLineGap; m_nStartLineIndex = m_nTitleNumb; }
public void PushIcon(HUDTilteType titleType, int nSpriteID) { HudTitleAttribute titleAttrib = HudSetting.Instance.TitleSets[(int)titleType].GetTitle(0); UISpriteInfo sp = CAtlasMng.instance.GetSafeSpriteByID(nSpriteID); int nWidth = 0; int nHeight = 0; int nStart = m_aSprite.size; if (sp != null) { nWidth = (int)sp.outer.width; nHeight = (int)sp.outer.height; PushSprite(nSpriteID, nWidth, nHeight, 0.0f, titleAttrib.SpriteOffsetY); } if (m_TitleLine[m_nTitleNumb] == null) { m_TitleLine[m_nTitleNumb] = new HUDTilteLine(); } m_TitleLine[m_nTitleNumb].m_nType = titleType; m_TitleLine[m_nTitleNumb].m_fWidth = nWidth; m_TitleLine[m_nTitleNumb].m_nHeight = nHeight; m_TitleLine[m_nTitleNumb].m_nStart = nStart; m_TitleLine[m_nTitleNumb].m_nEnd = m_aSprite.size; m_TitleLine[m_nTitleNumb].m_szText = string.Empty; m_TitleLine[m_nTitleNumb].m_nColorIndex = 0; m_TitleLine[m_nTitleNumb].m_nLine = m_nLines; m_TitleLine[m_nTitleNumb].m_nSpriteID = nSpriteID; if (titleAttrib.AlignType == HUDAlignType.align_center) { m_fCurLineWidth = nWidth; } nHeight += titleAttrib.SpriteReduceHeight; if (nHeight < titleAttrib.LockMaxHeight && titleAttrib.LockMaxHeight > 0) { nHeight = titleAttrib.LockMaxHeight; } if (m_fCurLineHeight < nHeight) { m_fCurLineHeight = nHeight; } ++m_nTitleNumb; }
void ShowTalk(string szTalk, int nColorIndex = 0) { if (nColorIndex < 0) { nColorIndex = 0; } else if (nColorIndex >= HudSetting.Instance.TalkTitle.Length) { nColorIndex = HudSetting.Instance.TalkTitle.Length - 1; } HudTitleAttribute titleAttrib = HudSetting.Instance.TalkTitle[nColorIndex]; int nTalkWidth = HudSetting.Instance.m_nTalkWidth; int nSpriteID = HudSetting.Instance.m_nTalkBk; UISpriteInfo sp = CAtlasMng.instance.GetSafeSpriteByID(nSpriteID); int nAtlasID = sp != null ? sp.m_nAtlasID : 0; // 先分析文本 UIFont mFont = GetHUDTitleFont(); HUDTextParse hudParse = HUDTextParse.Instance; hudParse.ParseText(szTalk); mFont.PrepareQueryText(hudParse.m_szText); int nFontH = mFont.GetFontHeight(); m_szTalk = hudParse.m_szText; m_HyperlinkNode.Clear(); // 先搞背景 for (int i = 0; i < 9; ++i) { HUDVertex node = HUDVertex.QueryVertex(); node.WorldPos = m_vPos; node.ScreenPos = m_vScreenPos; node.SpriteID = nSpriteID; node.AtlasID = nAtlasID; node.Scale = 1f; node.Offset.Set(0f, 0f); node.Move.Set(0f, 0f); node.width = (short)nTalkWidth; node.height = (short)100; m_aSprite.Add(node); } int nCharGap = titleAttrib.CharGap; int nLineGap = titleAttrib.LineGap; HudTitleAttribute.Effect nStyle = titleAttrib.Style; float fShadowX = titleAttrib.OffsetX; float fShadowY = titleAttrib.OffsetY; Color32 clrLeftUp = titleAttrib.clrLeftUp; Color32 clrLeftDown = titleAttrib.clrLeftDown; Color32 clrRightUp = titleAttrib.clrRightUp; Color32 clrRightDown = titleAttrib.clrRightDown; Color32 clrShadow = titleAttrib.clrShadow; Color32 clrCustom; // 计算文本的行数 CharacterInfo tempCharInfo = new CharacterInfo(); HUDCharInfo[] Sprites = hudParse.m_Sprites; int nSpriteCount = hudParse.m_SpriteCount; int nX = 0; int nY = 0; char ch; int nCurLineHeight = nFontH; int nLines = 0; int nTalkHeight = 0; short[] LineHeight = hudParse.LineHeight; int nWidthMax = 0; int nSpaceWidth = 0; for (int i = 0; i < nSpriteCount; ++i) { if (Sprites[i].bChar) { ch = Sprites[i].ch; if (ch == ' ') { if (nSpaceWidth == 0) { mFont.GetCharacterInfo('o', ref tempCharInfo); nSpaceWidth = HUDVertex.GetCharWidth(tempCharInfo); } Sprites[i].SpriteWidth = (short)nSpaceWidth; Sprites[i].SpriteHeight = (short)nFontH; } else { mFont.GetCharacterInfo(ch, ref tempCharInfo); Sprites[i].SpriteWidth = (short)HUDVertex.GetCharWidth(tempCharInfo); Sprites[i].SpriteHeight = (short)tempCharInfo.glyphHeight; } } else { if (Sprites[i].CharType == UIFontUnitType.UnitType_Icon) { sp = CAtlasMng.instance.GetSafeSpriteByID(Sprites[i].SpriteID); if (sp != null) { Sprites[i].SpriteWidth = (short)(sp.outer.width + 0.5f); Sprites[i].SpriteHeight = (short)(sp.outer.height + 0.5f); } } else if (Sprites[i].CharType == UIFontUnitType.UnitType_Gif) { int nGifID = Sprites[i].SpriteID; Sprites[i].SpriteWidth = (short)UISpriteGifManager.Instance.GetSpriteGifWidth(nGifID); Sprites[i].SpriteHeight = (short)UISpriteGifManager.Instance.GetSpriteGifHeight(nGifID); } } if (nX + Sprites[i].SpriteWidth > nTalkWidth || Sprites[i].CharType == UIFontUnitType.UnitType_Enter) { LineHeight[nLines] = (short)nCurLineHeight; nTalkHeight += nCurLineHeight + nLineGap; nX = 0; nY = nTalkHeight; // 按下对齐 nCurLineHeight = nFontH; ++nLines; } Sprites[i].nX = nX; Sprites[i].nY = nY; Sprites[i].nLine = nLines; nX += Sprites[i].SpriteWidth + nCharGap; if (nCurLineHeight < Sprites[i].SpriteHeight) { nCurLineHeight = Sprites[i].SpriteHeight; } if (nX > nWidthMax) { nWidthMax = nX; } } LineHeight[nLines] = (short)nCurLineHeight; nTalkHeight += nCurLineHeight; nTalkWidth = nWidthMax; nY = nTalkHeight; // 需要倒过来 for (int i = 0; i < nSpriteCount; ++i) { Sprites[i].nY = nY - Sprites[i].nY - LineHeight[Sprites[i].nLine]; } // -------- 更新 for (int i = 0; i < nSpriteCount; ++i) { nX = Sprites[i].nX; nY = Sprites[i].nY; if (Sprites[i].bChar) { ch = Sprites[i].ch; mFont.GetCharacterInfo(ch, ref tempCharInfo); if (nStyle != HudTitleAttribute.Effect.None) { PushShadow(ref tempCharInfo, ch, nX, nY, clrShadow, fShadowX, fShadowY); if (nStyle == HudTitleAttribute.Effect.Outline) { PushShadow(ref tempCharInfo, ch, nX, nY, clrShadow, fShadowX, -fShadowY); PushShadow(ref tempCharInfo, ch, nX, nY, clrShadow, -fShadowX, fShadowY); PushShadow(ref tempCharInfo, ch, nX, nY, clrShadow, -fShadowX, -fShadowY); } } if (Sprites[i].bCustomColor) { clrCustom = Sprites[i].CustomColor; HUDVertex node = PushChar(ref tempCharInfo, ch, nX, nY, clrCustom, clrCustom, clrCustom, clrCustom); } else { HUDVertex node = PushChar(ref tempCharInfo, ch, nX, nY, clrLeftUp, clrLeftDown, clrRightUp, clrRightDown); } } else { // 图片 if (Sprites[i].CharType == UIFontUnitType.UnitType_Icon) { HUDVertex node = PushSprite(Sprites[i].SpriteID, Sprites[i].SpriteWidth, Sprites[i].SpriteHeight, nX, nY); } else if (Sprites[i].CharType == UIFontUnitType.UnitType_Gif) { m_bHaveHyperlink = true; HUDGif gif = new HUDGif(); gif.InitGif(Sprites[i].SpriteID); HUDVertex node = PushSprite(gif.GetSpriteID(), Sprites[i].SpriteWidth, Sprites[i].SpriteHeight, nX, nY); node.hudGif = gif; m_HyperlinkNode.Add(node); } } } int nTalkBkBorderWidth = HudSetting.Instance.TalkBorderWidth; int nTalkBkBorderHeight = HudSetting.Instance.TalkBorderHeight; // 填充背景气泡 int nTalkBkWidth = nTalkWidth + nTalkBkBorderWidth * 2; int nTalkBkHeight = nTalkHeight + nTalkBkBorderHeight * 2; for (int i = 0; i < 9; ++i) { m_aSprite[i].width = (short)nTalkBkWidth; m_aSprite[i].height = (short)nTalkBkHeight; } SlicedFill(nSpriteID, nTalkBkWidth, nTalkBkHeight, 0, 1.0f); Offset(0, 9, -nTalkBkBorderWidth - nTalkWidth / 2, -nTalkBkBorderHeight + HudSetting.Instance.m_nTalkBkOffsetY); // Y越小,越在屏幕下面 Offset(9, m_aSprite.size, -nTalkWidth / 2, 0.0f); for (int i = 0; i < m_aSprite.size; ++i) { HUDVertex v = m_aSprite[i]; if (v.hudMesh == null) { if (v.AtlasID != 0) { v.hudMesh = m_MeshRender.QueryMesh(v.AtlasID); } else { v.hudMesh = m_MeshRender.FontMesh(); } v.hudMesh.PushHUDVertex(v); } } }
void UpdateMeridianNumber(int nMeridianNumb) { // 必须是在最后 if (0 == m_nMeridianIndex || m_nMeridianIndex != m_nTitleNumb - 1) { return; } // 先释放旧的吧 HUDTilteLine title = m_TitleLine[m_nMeridianIndex]; if (title.m_nType != HUDTilteType.HeadIcon) { return; } if (nMeridianNumb < 0) { nMeridianNumb = 0; } m_nMeridianNumb = nMeridianNumb; HudTitleAttribute titleAttrib = HudSetting.Instance.TitleSets[(int)HUDTilteType.HeadIcon].GetTitle(0); int nCharGap = titleAttrib.CharGap; int nPow = 1; while (nPow * 10 <= nMeridianNumb) { nPow *= 10; } int nWidth = 0; int nHeight = 0; int nMaxWidth = 0; int nMaxHeight = 0; int[] PicID = HudSetting.Instance.MeridianPic; int nSpriteID = 0; int nValue = nMeridianNumb; int nStart = title.m_nStart; int nEnd = title.m_nEnd; int nX = 0; while (nPow > 0) { int nIndex = nValue / nPow; nValue %= nPow; nPow /= 10; nSpriteID = PicID[nIndex]; UISpriteInfo sp = CAtlasMng.instance.GetSafeSpriteByID(nSpriteID); nWidth = (int)sp.outer.width; nHeight = (int)sp.outer.height; nMaxWidth += nWidth + nCharGap; if (nMaxHeight < nHeight) { nMaxHeight = nHeight; } HUDVertex v = null; if (nStart < m_aSprite.size) { v = m_aSprite[nStart]; if (v.AtlasID != sp.m_nAtlasID) { if (v.hudMesh != null) { v.hudMesh.EraseHUDVertex(v); } v.hudMesh = null; v.AtlasID = sp.m_nAtlasID; } v.SpriteID = nSpriteID; v.Offset.Set(nX, titleAttrib.SpriteOffsetY); v.InitSprite(nWidth, nHeight); } else { v = PushSprite(nSpriteID, nWidth, nHeight, nX, titleAttrib.SpriteOffsetY); } v.Scale = m_fScale; if (v.hudMesh == null) { if (m_bInitHUDMesh) { v.hudMesh = m_pBatcher.m_MeshRender.QueryMesh(sp.m_nAtlasID); v.hudMesh.PushHUDVertex(v); } } else { v.hudMesh.VertexDirty(); } nX = nMaxWidth; ++nStart; } title.m_nEnd = nStart; // 删除多余的 for (--nEnd; nEnd >= nStart; --nEnd) { HUDVertex v = m_aSprite[nEnd]; if (v.hudMesh != null) { v.hudMesh.EraseHUDVertex(v); } v.hudMesh = null; m_aSprite.RemoveAt(nEnd); HUDVertex.ReleaseVertex(v); } nMaxWidth -= nCharGap; title.m_fWidth = nMaxWidth; title.m_nHeight = nMaxHeight; nMaxHeight += titleAttrib.SpriteReduceHeight; m_fCurLineWidth = nMaxWidth; m_fCurLineHeight = nMaxHeight; }
// 必须先有居中的 public void PushTitle(string szText, HUDTilteType titleType, int nColorIndex) { if (m_nTitleNumb >= m_TitleLine.Length) { return; } UIFont mFont = GetHUDTitleFont(); CharacterInfo tempCharInfo = new CharacterInfo(); HudTitleAttribute titleAttrib = HudSetting.Instance.TitleSets[(int)titleType].GetTitle(nColorIndex); int nLineGap = titleAttrib.LineGap; int nCharGap = titleAttrib.CharGap; HUDTextParse hudParse = HUDTextParse.Instance; hudParse.ParseText(szText); mFont.PrepareQueryText(hudParse.m_szText); HudTitleAttribute.Effect nStyle = titleAttrib.Style; int nSpriteCount = hudParse.m_SpriteCount; HUDCharInfo[] Sprites = hudParse.m_Sprites; char ch; float fShadowX = titleAttrib.OffsetX; float fShadowY = titleAttrib.OffsetY; float fx = 0.0f; Color32 clrLeftUp = titleAttrib.clrLeftUp; Color32 clrLeftDown = titleAttrib.clrLeftDown; Color32 clrRightUp = titleAttrib.clrRightUp; Color32 clrRightDown = titleAttrib.clrRightDown; Color32 clrShadow = titleAttrib.clrShadow; Color32 clrCustom; int nStart = m_aSprite.size; int nHeight = mFont.GetFontHeight(); int nFontH = titleAttrib.Height; int nFontOffsetY = titleAttrib.FontOffsetY; int nY = 0; for (int i = 0; i < nSpriteCount; ++i) { if (Sprites[i].bChar) { ch = Sprites[i].ch; mFont.GetCharacterInfo(ch, ref tempCharInfo); nY = (tempCharInfo.glyphHeight - nFontH) / 2 + nFontOffsetY; if (nStyle != HudTitleAttribute.Effect.None) { PushShadow(ref tempCharInfo, ch, fx, nY, clrShadow, fShadowX, fShadowY); if (nStyle == HudTitleAttribute.Effect.Outline) { PushShadow(ref tempCharInfo, ch, fx, nY, clrShadow, fShadowX, -fShadowY); PushShadow(ref tempCharInfo, ch, fx, nY, clrShadow, -fShadowX, fShadowY); PushShadow(ref tempCharInfo, ch, fx, nY, clrShadow, -fShadowX, -fShadowY); } } if (Sprites[i].bCustomColor) { clrCustom = Sprites[i].CustomColor; HUDVertex node = PushChar(ref tempCharInfo, ch, fx, nY, clrCustom, clrCustom, clrCustom, clrCustom); fx += node.width + nCharGap; } else { HUDVertex node = PushChar(ref tempCharInfo, ch, fx, nY, clrLeftUp, clrLeftDown, clrRightUp, clrRightDown); fx += node.width + nCharGap; } } else { // 图片 if (Sprites[i].CharType == UIFontUnitType.UnitType_Icon) { HUDVertex node = PushSprite(Sprites[i].SpriteID, Sprites[i].SpriteWidth, Sprites[i].SpriteHeight, fx, titleAttrib.SpriteOffsetY); fx += node.width + nCharGap; if (nHeight < node.height - titleAttrib.SpriteReduceHeight) { nHeight = node.height - titleAttrib.SpriteReduceHeight; } } } } if (m_TitleLine[m_nTitleNumb] == null) { m_TitleLine[m_nTitleNumb] = new HUDTilteLine(); } m_TitleLine[m_nTitleNumb].m_nType = titleType; m_TitleLine[m_nTitleNumb].m_fWidth = fx - nCharGap; m_TitleLine[m_nTitleNumb].m_nHeight = nHeight; m_TitleLine[m_nTitleNumb].m_nStart = nStart; m_TitleLine[m_nTitleNumb].m_nEnd = m_aSprite.size; m_TitleLine[m_nTitleNumb].m_szText = szText; m_TitleLine[m_nTitleNumb].m_szValidText = hudParse.m_szText; m_TitleLine[m_nTitleNumb].m_nColorIndex = nColorIndex; m_TitleLine[m_nTitleNumb].m_nLine = m_nLines; m_TitleLine[m_nTitleNumb].m_nSpriteID = 0; if (titleAttrib.AlignType == HUDAlignType.align_center) { m_fCurLineWidth = fx - nCharGap; } if (nHeight < titleAttrib.LockMaxHeight && titleAttrib.LockMaxHeight > 0) { nHeight = titleAttrib.LockMaxHeight; } if (m_fCurLineHeight < nHeight) { m_fCurLineHeight = nHeight; } ++m_nTitleNumb; }
public HudTitleLabelSet(HudTitleAttribute p) { m_pData = new HudTitleAttribute[1]; m_pData[0] = p; }