using System;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
public class CatchSceneCatchFunctionListPage :FrameLayout
{
///
/// 主控件
///
FrameLayout bodyView;
///
/// 内容区域
///
VerticalScrolViewLayout contentView;
///
/// 生成场景按钮
///
Button btnGenerateScene;
Scene scene;
///
/// 捕捉到到功能数据
///
List catchFunctionList;
///
/// 回掉更新事件
///
Action backAction;
public CatchSceneCatchFunctionListPage(Scene s, List list,Action action)
{
bodyView = this;
scene = s;
catchFunctionList = list;
backAction = action;
}
public void LoadPage()
{
new TopViewDiv(bodyView, Language.StringByID(StringId.CatchScene)).LoadTopView();
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
contentView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(667 - 64 - 60),
};
bodyView.AddChidren(contentView);
LoadFunctionRow();
btnGenerateScene = new Button()
{
Y = Application.GetRealHeight(667 - 50),
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.GenerateScene,
BackgroundColor = CSS_Color.MainBackgroundColor,
SelectedBackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(btnGenerateScene);
LoadEvent_CompleteEvent();
}
///
/// 加载功能信息行
///
private void LoadFunctionRow()
{
contentView.RemoveAll();
scene.functions.Clear();
bool isFrist = true;
foreach (var function in catchFunctionList)
{
var scenefunction = function.ConvertSceneFunction();
scene.functions.Add(scenefunction);
RowLayout functionRow = new RowLayout()
{
Height = Application.GetRealHeight(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
LineColor = 0x00000000,
};
contentView.AddChidren(functionRow);
if (isFrist)
{
isFrist = false;
}
else
{
functionRow.AddChidren(new Button()
{
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(343),
Height = Application.GetRealWidth(1),
BackgroundColor = CSS_Color.DividingLineColor,
});
}
var btnFunctionIcon = new Button()
{
X = Application.GetRealWidth(12),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(28),
Height = Application.GetMinRealAverage(28),
};
functionRow.AddChidren(btnFunctionIcon);
btnFunctionIcon.UnSelectedImagePath = $"FunctionIcon/Icon/{function.IconName}.png";
var btnName = new Button()
{
X = Application.GetRealWidth(8 + 10 + 32),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(32),
Text = function.name,
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
};
functionRow.AddChidren(btnName);
var btnFromFloor = new Button()
{
X = Application.GetRealWidth(8 + 10 + 32),
Y = Application.GetRealHeight(24),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(26),
Text = function.GetRoomListName(),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
};
functionRow.AddChidren(btnFromFloor);
Button btnRight = new Button()
{
X = Application.GetRealWidth(339),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
functionRow.AddChidren(btnRight);
var btnFunctionInfo = new Button()
{
Width = Application.GetRealWidth(327),
TextAlignment = TextAlignment.CenterRight,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
Text = scenefunction.GetFunctionScnenInfo(),
};
functionRow.AddChidren(btnFunctionInfo);
EventHandler eventHandler = (sender, e) => {
Action refreshFunctionRowAction = () => {
btnFunctionInfo.Text = scenefunction.GetFunctionScnenInfo();
};
var ssf = new SceneFunctionInfoEditPage(scene, scenefunction, refreshFunctionRowAction);
MainPage.BasePageView.AddChidren(ssf);
ssf.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
btnFunctionInfo.MouseUpEventHandler = eventHandler;
btnRight.MouseUpEventHandler = eventHandler;
Button btnDelSceneFunction = new Button()
{
BackgroundColor = CSS_Color.WarningColor,
TextColor = CSS_Color.MainBackgroundColor,
TextID = StringId.Del,
};
functionRow.AddRightView(btnDelSceneFunction);
btnDelSceneFunction.MouseUpEventHandler = (sender, e) => {
catchFunctionList.Remove(function);
LoadFunctionRow();
};
}
}
///
/// 完成按钮点击事件
///
void LoadEvent_CompleteEvent()
{
btnGenerateScene.MouseUpEventHandler += (sender, e) =>
{
var waitPage = new Loading();
MainPage.BaseView.AddChidren(waitPage);
waitPage.Start(Language.StringByID(StringId.PleaseWait));
new Thread(() =>
{
try
{
var serverScene = new Scene();
var result = FunctionList.List.AddScene(scene, out serverScene);
Application.RunOnMainThread(() =>
{
if (result == StateCode.SUCCESS)
{
scene = serverScene;
FunctionList.List.scenes.Add(scene);
backAction();
RemoveFromParent();
}
else
{
IMessageCommon.Current.ShowErrorInfoAlter(result);
}
});
}
catch { }
finally
{
Application.RunOnMainThread(() => {
waitPage.Hide();
waitPage.RemoveFromParent();
});
}
})
{ IsBackground = true, Priority = ThreadPriority.AboveNormal }.Start();
};
}
}
}