提交修改
This commit is contained in:
@@ -1,122 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class UIComponentLanguage : Dictionary<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class UIComponentLanguagePack : Dictionary<string, UIComponentLanguage>
|
||||
{
|
||||
public bool Has(string url)
|
||||
{
|
||||
return ContainsKey(url);
|
||||
}
|
||||
|
||||
public void TrySetComponentLanguage(GComponent component)
|
||||
{
|
||||
if (component.packageItem == null) return;
|
||||
SetComponentFont(component);
|
||||
if (!Has(component.resourceURL)) return;
|
||||
SetComponentLanguage(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置Panel时不判断配置中是否有数据
|
||||
/// </summary>
|
||||
/// <param name="component"></param>
|
||||
public void TrySetPanelLanguage(GComponent component)
|
||||
{
|
||||
SetComponentFont(component);
|
||||
SetComponentLanguage(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置组件多语言
|
||||
/// </summary>
|
||||
/// <param name="component"></param>
|
||||
public void SetComponentLanguage(GComponent component)
|
||||
{
|
||||
bool comHasLanConfig = false;
|
||||
UIComponentLanguage componentLangeage = null;
|
||||
if (component.packageItem != null && TryGetValue(component.resourceURL, out componentLangeage))
|
||||
comHasLanConfig = true;
|
||||
|
||||
var count = component.numChildren;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var child = component.GetChildAt(i);
|
||||
if (child.packageItem != null && child is GComponent childCom)
|
||||
{
|
||||
SetComponentLanguage(childCom);
|
||||
}
|
||||
else if (child is GList list)
|
||||
{
|
||||
SetComponentLanguage(list);
|
||||
}
|
||||
|
||||
if (comHasLanConfig)
|
||||
{
|
||||
var id = child.id;
|
||||
if (componentLangeage.TryGetValue(id, out var key))
|
||||
{
|
||||
if (child is GLoader gLoader)
|
||||
{
|
||||
gLoader.SetLanguageImage(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
child.SetLanguage(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetComponentFont(GComponent component)
|
||||
{
|
||||
var count = component.numChildren;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var child = component.GetChildAt(i);
|
||||
if (child is GComponent childCom)
|
||||
{
|
||||
SetComponentFont(childCom);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetChildFont(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetChildFont(GObject child)
|
||||
{
|
||||
GTextField curField = null;
|
||||
if (child is GRichTextField richTextField)
|
||||
{
|
||||
curField = richTextField;
|
||||
}
|
||||
else if (child is GButton button)
|
||||
{
|
||||
curField = button.GetTextField();
|
||||
}
|
||||
else if (child is GLabel label)
|
||||
{
|
||||
curField = label.GetTextField();
|
||||
}
|
||||
else if (child is GTextField gtextField)
|
||||
{
|
||||
curField = gtextField;
|
||||
}
|
||||
|
||||
if (curField == null) return;
|
||||
var textFormat = curField.textFormat;
|
||||
var font = textFormat.GetCurLanguageFont();
|
||||
if (font == null) return;
|
||||
textFormat.font = font;
|
||||
curField.textFormat = textFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user