12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- /****************************************************************************
- * 2024.7 LXD
- ****************************************************************************/
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using I2.Loc;
- namespace QFramework
- {
- public partial class ToolMessageElement : UIElement
- {
- /// <summary>
- /// 高度基准
- /// </summary>
- private float heightBasic = 219.6412f;
- /// <summary>
- /// 展示工具信息
- /// </summary>
- public void ShowToolInfo(ToolConfigInfo toolConfigInfo)
- {
- ToolName.text = toolConfigInfo.toolName;
- //"\u3000"首行缩进没效果,改用透明占位符
- ToolMessage.text = "<color=#FFFFFF00>占位</color>" + toolConfigInfo.toolDescription.Replace(" ", "\u3000");
- #region 多语言
- if (LocalizationConfig.localization && LocalizationManager.CurrentLanguage == "English")
- {
- ToolName.text = toolConfigInfo.en_toolName;
- ToolMessage.text = "<color=#FFFFFF00>XXXX</color>" + toolConfigInfo.en_toolDescription.Replace(" ", "\u00A0"); ;
- }
- #endregion
- Content.SetHeight(ToolMessage.preferredHeight);
- ToolConfigProxy toolConfigProxy = DAL.Instance.Get<ToolConfigProxy>();
- Sprite tmpSprite = toolConfigProxy.GetSpriteByToolName(toolConfigInfo.toolName);
- if (tmpSprite != null)
- {
- ToolIcon.sprite = tmpSprite;
- SetInfoOfImage(ToolIcon.sprite);
- }
- else
- {
- ToolIcon.sprite = null;
- }
- }
- /// <summary>
- /// 设置Image信息
- /// </summary>
- /// <param name="_sprite"></param>
- private void SetInfoOfImage(Sprite _sprite)
- {
- if (_sprite == null) return;
- float width = _sprite.texture.width * CalculateScale(_sprite.texture.height);
- float height = _sprite.texture.height * CalculateScale(_sprite.texture.height);
- ToolIcon.rectTransform.sizeDelta = new Vector2(width, height);
- ToolIcon.sprite = _sprite;
- }
- /// <summary>
- /// 计算比例,以高度为基数计算
- /// </summary>
- /// <param name="_spriteHeight"></param>
- private float CalculateScale(float _spriteHeight)
- {
- if (_spriteHeight <= heightBasic)
- {
- return 1;
- }
- else
- {
- return heightBasic / _spriteHeight;
- }
- }
- }
- }
|