using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
///
/// 场景和功能之间相互切换的Tab控件(完成初始化后,会根据默认选择调用回调函数)
///
public class SceneFunctionSwitchControl : FrameLayout
{
#region ■ 变量声明___________________________
///
/// 选择事件 1:场景 2:功能
///
public Action SelectTabEvent = null;
private int m_nowSelectIndex = 1;
///
/// 当前选择的分支 1:场景 2:功能
///
public int nowSelectIndex
{
get { return m_nowSelectIndex; }
}
#endregion
#region ■ 初始化_____________________________
///
/// 场景和功能之间相互切换的Tab控件(完成初始化后,会根据默认选择调用回调函数)
///
public SceneFunctionSwitchControl()
{
this.Height = Application.GetRealHeight(90);
}
///
/// 初始化控件(事件要至于它之前)
///
public void InitControl()
{
var btnTemp = new NormalViewControl(10, 10, false);
btnTemp.TextID = R.MyInternationalizationString.uScence;
//场景框(点击范围有点小,需要扩大它的点击范围)
var frameScene = new FrameLayoutControl();
frameScene.UseClickStatu = false;
frameScene.Height = Application.GetRealHeight(90);
frameScene.Width = btnTemp.GetRealWidthByText(16);
frameScene.X = ControlCommonResourse.XXLeft;
this.AddChidren(frameScene);
//场景
var btnScene = new NormalViewControl(frameScene.Width, Application.GetRealHeight(63), false);
btnScene.Text = btnTemp.Text;
btnScene.TextSize = 16;
btnScene.IsBold = true;
btnScene.TextColor = UserCenterColor.Current.TextColor2;
frameScene.AddChidren(btnScene, ChidrenBindMode.BindEventOnly);
//底线
var btnSceneLine = new NormalViewControl(40, 10, true);
btnSceneLine.Y = btnScene.Bottom + Application.GetRealHeight(14);
btnSceneLine.X = btnScene.X + btnScene.Width / 2 - Application.GetRealWidth(40) / 2;
btnSceneLine.Radius = (uint)Application.GetRealHeight(10) / 2;
btnSceneLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
frameScene.AddChidren(btnSceneLine, ChidrenBindMode.BindEventOnly);
btnTemp.TextID = R.MyInternationalizationString.uFunction;
//功能框(点击范围有点小,需要扩大它的点击范围)
var frameFunc = new FrameLayoutControl();
frameFunc.UseClickStatu = false;
frameFunc.Height = Application.GetRealHeight(90);
frameFunc.Width = btnTemp.GetRealWidthByText(16);
frameFunc.X = frameScene.Right + Application.GetRealWidth(58);
this.AddChidren(frameFunc);
//功能
var btnFunc = new NormalViewControl(frameFunc.Width, Application.GetRealHeight(63), false);
btnFunc.Text = btnTemp.Text;
btnFunc.TextColor = UserCenterColor.Current.TextGrayColor3;
frameFunc.AddChidren(btnFunc, ChidrenBindMode.BindEventOnly);
//底线
var btnFuncLine = new NormalViewControl(40, 10, true);
btnFuncLine.Y = btnFunc.Bottom + Application.GetRealHeight(14);
btnFuncLine.X = btnFunc.X + btnFunc.Width / 2 - Application.GetRealWidth(40) / 2;
btnFuncLine.Radius = (uint)Application.GetRealHeight(10) / 2;
btnFuncLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
frameFunc.AddChidren(btnFuncLine, ChidrenBindMode.BindEventOnly);
btnFuncLine.Visible = false;
frameScene.ButtonClickEvent += (sender, e) =>
{
//场景分支选择
if (this.m_nowSelectIndex == 1)
{
return;
}
this.m_nowSelectIndex = 1;
btnScene.TextSize = 16;
btnScene.IsBold = true;
btnScene.TextColor = UserCenterColor.Current.TextColor2;
btnFunc.TextSize = 14;
btnFunc.IsBold = false;
btnFunc.TextColor = UserCenterColor.Current.TextGrayColor3;
btnSceneLine.Visible = true;
btnFuncLine.Visible = false;
this.SelectTabEvent?.Invoke(1);
};
frameFunc.ButtonClickEvent += (sender, e) =>
{
//功能分支选择
if (this.m_nowSelectIndex == 2)
{
return;
}
this.m_nowSelectIndex = 2;
btnScene.TextSize = 14;
btnScene.IsBold = false;
btnScene.TextColor = UserCenterColor.Current.TextGrayColor3;
btnFunc.TextSize = 16;
btnFunc.IsBold = true;
btnFunc.TextColor = UserCenterColor.Current.TextColor2;
btnFuncLine.Visible = true;
btnSceneLine.Visible = false;
this.SelectTabEvent?.Invoke(2);
};
//回调方法
if (this.m_nowSelectIndex == 1)
{
this.m_nowSelectIndex = 0;
frameScene.ButtonClickEvent?.Invoke(null, null);
}
if (this.m_nowSelectIndex == 2)
{
this.m_nowSelectIndex = 0;
frameFunc.ButtonClickEvent?.Invoke(null, null);
}
}
#endregion
#region ■ 控件摧毁___________________________
///
/// 控件摧毁
///
public override void RemoveFromParent()
{
this.SelectTabEvent = null;
base.RemoveFromParent();
}
#endregion
#region ■ 一般方法___________________________
///
/// 设置初始选择(请在初始化完成之前调用)
///
/// 1:场景 2:功能
public void SetDefultIndex(int index)
{
this.m_nowSelectIndex = index;
}
#endregion
}
}