using System.Collections;
|
using System.Collections.Generic;
|
using TableConfig;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class ChatBubbleModel : Model
|
{
|
public Dictionary<int, ChatBubble> chatBubbles = new Dictionary<int, ChatBubble>();
|
public override void Init()
|
{
|
ParseConfig();
|
}
|
|
public override void UnInit()
|
{
|
}
|
|
void ParseConfig()
|
{
|
var configs = Config.Instance.GetAllValues<ChatBubbleBoxConfig>();
|
for (int i = 0; i < configs.Count; i++)
|
{
|
var config = configs[i];
|
if (chatBubbles.ContainsKey(config.ID))
|
{
|
continue;
|
}
|
var bubble = new ChatBubble();
|
bubble.id = config.ID;
|
bubble.name = config.Name;
|
bubble.requireLevel = config.NeedLV;
|
bubble.requireVipLevel = config.NeedVIPLVGift;
|
bubble.leftBubbleIcon = config.leftBubbleIcon;
|
bubble.rightBubbleIcon = config.rightBubbleIcon;
|
bubble.leftPadding = new RectOffset()
|
{
|
left = config.leftOffset.Length > 0 ? config.leftOffset[0] : 0,
|
right = config.leftOffset.Length > 1 ? config.leftOffset[1] : 0,
|
top = config.leftOffset.Length > 2 ? config.leftOffset[2] : 0,
|
bottom = config.leftOffset.Length > 3 ? config.leftOffset[3] : 0,
|
};
|
bubble.rifhtPadding = new RectOffset()
|
{
|
left = config.rightOffset.Length > 0 ? config.rightOffset[0] : 0,
|
right = config.rightOffset.Length > 1 ? config.rightOffset[1] : 0,
|
top = config.rightOffset.Length > 2 ? config.rightOffset[2] : 0,
|
bottom = config.rightOffset.Length > 3 ? config.rightOffset[3] : 0,
|
};
|
chatBubbles.Add(config.ID, bubble);
|
}
|
}
|
|
public bool TryGetBubble(int id, out ChatBubble bubble)
|
{
|
return chatBubbles.TryGetValue(id, out bubble);
|
}
|
|
public struct ChatBubble
|
{
|
public int id;
|
public string name;
|
public int requireLevel;
|
public int requireVipLevel;
|
public string leftBubbleIcon;
|
public string rightBubbleIcon;
|
public RectOffset leftPadding;
|
public RectOffset rifhtPadding;
|
|
public string GetBubbleIcon(bool left, ref bool isFlip)
|
{
|
isFlip = false;
|
if (left)
|
{
|
if (string.IsNullOrEmpty(leftBubbleIcon))
|
{
|
isFlip = true;
|
return rightBubbleIcon;
|
}
|
return leftBubbleIcon;
|
}
|
else
|
{
|
if (string.IsNullOrEmpty(rightBubbleIcon))
|
{
|
isFlip = true;
|
return leftBubbleIcon;
|
}
|
return rightBubbleIcon;
|
}
|
}
|
}
|
}
|
}
|