100 lines
3.3 KiB
C#
100 lines
3.3 KiB
C#
using Simulator.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UVC.UI.Window.PropertyWindow;
|
|
|
|
public class QueueProperty : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private PropertyWindow propertyWindow;
|
|
private void Awake()
|
|
{
|
|
propertyWindow.PropertyValueChanged += OnPropertyValueChanged;
|
|
}
|
|
public void SetPropertyWindow(ComponentType type, ComponentDataBase data)
|
|
{
|
|
if (PlayerPropertyDataBase.isPlaying)
|
|
{
|
|
return;
|
|
}
|
|
InitNodeProperty(data as QueueDataClass);
|
|
}
|
|
|
|
void SaveChange(object source, object value, string name)
|
|
{
|
|
var path = PathIndexer.GetNodePath(source);
|
|
Patch updateData = new Patch();
|
|
updateData.value = value;
|
|
UpdateValueStack.AddPatch($"{path}.{name}", value);
|
|
}
|
|
|
|
public void InitNodeProperty(QueueDataClass queue)
|
|
{
|
|
var entries = new List<IPropertyEntry>
|
|
{
|
|
new StringProperty("name", "이름", queue.name)
|
|
{
|
|
IsReadOnly=true
|
|
},
|
|
new StringProperty("label", "라벨", queue.label)
|
|
{
|
|
IsReadOnly=false
|
|
}.Bind(
|
|
setter: v => {queue.label = v;SaveChange(queue,v,"label"); }
|
|
),
|
|
CreatePositionGroup(queue),
|
|
new BoolProperty("is_unlimited","수용 용량 무제한", queue.is_unlimited)
|
|
{
|
|
IsReadOnly=false
|
|
},
|
|
new IntProperty("capacity","최대 수용 개수", queue.capacity)
|
|
{
|
|
IsReadOnly=false
|
|
}.Bind(
|
|
setter: v => { queue.capacity = v; SaveChange(queue, v, "capacity"); }
|
|
),
|
|
new ListProperty("queue_type","대기열 처리 방식",new List<string>(){ "fifo", "lifo", "priority" }, queue.queue_type)
|
|
{
|
|
IsReadOnly=false,
|
|
}.Bind(
|
|
setter: v => { queue.queue_type = v; SaveChange(queue, v, "queue_type"); }
|
|
),
|
|
};
|
|
|
|
entries.AddRange(PolicyPropertyBuilder.CreatePolicyEntries(
|
|
"CostPolicy", "대기 비용 처리 정책", "display_mode_CostPolicy",
|
|
() => queue.cost_policy, v => queue.cost_policy = v,
|
|
"cost_policy", queue, SaveChange));
|
|
|
|
propertyWindow.LoadMixedProperties(entries);
|
|
|
|
PolicyPropertyBuilder.HandleDisplayModeChanged(propertyWindow, "CostPolicy", queue.cost_policy.policy.ToString());
|
|
propertyWindow.SetPropertyEnabled("capacity", !queue.is_unlimited);
|
|
}
|
|
|
|
private void OnPropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
|
|
{
|
|
Debug.Log($"[PropertyChanged] Id:{e.PropertyId}, Type:{e.PropertyType}, Value:{e.NewValue}");
|
|
|
|
PolicyPropertyBuilder.TryHandleDisplayModeChanged(e, propertyWindow, "display_mode_CostPolicy", "CostPolicy");
|
|
|
|
if (e.PropertyId == "is_unlimited")
|
|
{
|
|
bool flag = Convert.ToBoolean(e.NewValue);
|
|
propertyWindow.SetPropertyEnabled("capacity", !flag);
|
|
}
|
|
}
|
|
|
|
private PropertyGroup CreatePositionGroup(QueueDataClass queue)
|
|
{
|
|
return PropertyHelper.CreatePositionGroup("queue_position", queue, propertyWindow, SaveChange);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (propertyWindow != null)
|
|
propertyWindow.PropertyValueChanged -= OnPropertyValueChanged;
|
|
}
|
|
}
|