2019-12-28 01:08:45 +08:00
|
|
|
|
using CodeWalker.GameFiles;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace CodeWalker.Project.Panels
|
|
|
|
|
{
|
2019-12-28 13:01:09 +08:00
|
|
|
|
public partial class EditYtypMloEntSetPanel : ProjectPanel
|
2019-12-28 01:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
public ProjectForm ProjectForm;
|
|
|
|
|
public MCMloEntitySet CurrentEntitySet { get; set; }
|
|
|
|
|
|
2019-12-28 13:01:09 +08:00
|
|
|
|
private bool populatingui = false;
|
2019-12-28 01:08:45 +08:00
|
|
|
|
private bool SelectingLocation = false;
|
|
|
|
|
|
2019-12-28 13:01:09 +08:00
|
|
|
|
public EditYtypMloEntSetPanel(ProjectForm owner)
|
2019-12-28 01:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
ProjectForm = owner;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetEntitySet(MCMloEntitySet entset)
|
|
|
|
|
{
|
|
|
|
|
CurrentEntitySet = entset;
|
|
|
|
|
Tag = entset;
|
|
|
|
|
UpdateFormTitle();
|
|
|
|
|
MloInstanceData instance = ProjectForm.TryGetMloInstance(entset?.OwnerMlo);
|
|
|
|
|
//ProjectForm.WorldForm?.SelectMloEntitySet(entset, instance);
|
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateControls()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (CurrentEntitySet != null)
|
|
|
|
|
{
|
2019-12-28 13:01:09 +08:00
|
|
|
|
populatingui = true;
|
2019-12-28 01:08:45 +08:00
|
|
|
|
EntitySetNameTextBox.Text = CurrentEntitySet.Name;
|
|
|
|
|
ForceVisibleCheckBox.Checked = CurrentEntitySet.ForceVisible;
|
|
|
|
|
SelectedLocationGroupBox.Visible = false;
|
|
|
|
|
UpdateSelectedLocationRoomCombo();
|
2019-12-28 13:01:09 +08:00
|
|
|
|
populatingui = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EntitySetNameTextBox.Text = string.Empty;
|
|
|
|
|
ForceVisibleCheckBox.Checked = false;
|
|
|
|
|
SelectedLocationGroupBox.Visible = false;
|
|
|
|
|
SelectedLocationRoomCombo.Items.Clear();
|
2019-12-28 01:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateLocationsListBox();
|
|
|
|
|
}
|
|
|
|
|
private void UpdateLocationsListBox()
|
|
|
|
|
{
|
|
|
|
|
LocationsListBox.Items.Clear();
|
2019-12-28 13:01:09 +08:00
|
|
|
|
if (CurrentEntitySet?.Locations != null)
|
2019-12-28 01:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < CurrentEntitySet.Locations.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var loc = CurrentEntitySet.Locations[i];
|
|
|
|
|
var ent = ((CurrentEntitySet.Entities != null) && (i < CurrentEntitySet.Entities.Length)) ? CurrentEntitySet.Entities[i] : null;
|
|
|
|
|
var item = new LocationItem() { Location = loc, Entity = ent, Index = i };
|
|
|
|
|
LocationsListBox.Items.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void UpdateSelectedLocationRoomCombo()
|
|
|
|
|
{
|
|
|
|
|
SelectedLocationRoomCombo.Items.Clear();
|
2019-12-28 13:01:09 +08:00
|
|
|
|
if (CurrentEntitySet?.OwnerMlo?.rooms != null)
|
2019-12-28 01:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (var room in CurrentEntitySet.OwnerMlo.rooms)
|
|
|
|
|
{
|
|
|
|
|
SelectedLocationRoomCombo.Items.Add(room);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateFormTitle()
|
|
|
|
|
{
|
|
|
|
|
Text = CurrentEntitySet?.Name ?? "Entity Set";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EntitySetNameTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-12-28 13:01:09 +08:00
|
|
|
|
if (populatingui) return;
|
2019-12-28 01:08:45 +08:00
|
|
|
|
if (CurrentEntitySet == null) return;
|
|
|
|
|
|
|
|
|
|
var str = EntitySetNameTextBox.Text;
|
|
|
|
|
if (CurrentEntitySet.Name != str)
|
|
|
|
|
{
|
|
|
|
|
uint h = 0;
|
|
|
|
|
if (uint.TryParse(str, out h))
|
|
|
|
|
{
|
|
|
|
|
CurrentEntitySet._Data.name = h;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
JenkIndex.Ensure(str);
|
|
|
|
|
CurrentEntitySet._Data.name = JenkHash.GenHash(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeNode tn = ProjectForm.ProjectExplorer?.FindMloEntitySetTreeNode(CurrentEntitySet);
|
|
|
|
|
if (tn != null)
|
|
|
|
|
{
|
|
|
|
|
tn.Text = CurrentEntitySet.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateFormTitle();
|
|
|
|
|
ProjectForm.SetYtypHasChanged(true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ForceVisibleCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CurrentEntitySet == null) return;
|
|
|
|
|
CurrentEntitySet.ForceVisible = ForceVisibleCheckBox.Checked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LocationsListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SelectedLocationGroupBox.Visible = false;
|
|
|
|
|
|
|
|
|
|
if (CurrentEntitySet == null) return;
|
|
|
|
|
|
|
|
|
|
var item = LocationsListBox.SelectedItem as LocationItem;
|
|
|
|
|
if (item == null) return;
|
|
|
|
|
|
|
|
|
|
SelectingLocation = true;
|
|
|
|
|
SelectedLocationEntityLabel.Text = (item.Entity != null) ? item.Entity.Name : "-";
|
|
|
|
|
SelectedLocationRoomCombo.SelectedIndex = (item.Location < SelectedLocationRoomCombo.Items.Count) ? (int)item.Location : 0;
|
|
|
|
|
SelectingLocation = false;
|
|
|
|
|
SelectedLocationGroupBox.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectedLocationRoomCombo_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SelectingLocation) return;
|
|
|
|
|
if (CurrentEntitySet?.Locations == null) return;
|
|
|
|
|
|
|
|
|
|
var item = LocationsListBox.SelectedItem as LocationItem;
|
|
|
|
|
if (item == null) return;
|
|
|
|
|
|
|
|
|
|
item.Location = (SelectedLocationRoomCombo.SelectedIndex >= 0) ? (uint)SelectedLocationRoomCombo.SelectedIndex : 0;
|
|
|
|
|
|
|
|
|
|
var ind = item.Index;
|
|
|
|
|
if (ind < CurrentEntitySet.Locations.Length)
|
|
|
|
|
{
|
|
|
|
|
CurrentEntitySet.Locations[ind] = item.Location;
|
|
|
|
|
|
|
|
|
|
ProjectForm.SetYtypHasChanged(true);
|
|
|
|
|
|
|
|
|
|
if ((ind >= 0) && (ind < LocationsListBox.Items.Count))
|
|
|
|
|
{
|
|
|
|
|
LocationsListBox.Items[ind] = LocationsListBox.Items[ind];//refresh the item text...
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-28 20:24:36 +08:00
|
|
|
|
private void AddEntityButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ProjectForm.SetProjectItem(CurrentEntitySet);
|
|
|
|
|
ProjectForm.NewMloEntity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ProjectForm.SetProjectItem(CurrentEntitySet);
|
|
|
|
|
ProjectForm.DeleteMloEntitySet();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-28 01:08:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LocationItem
|
|
|
|
|
{
|
|
|
|
|
public uint Location { get; set; }
|
|
|
|
|
public MCEntityDef Entity { get; set; }
|
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
if (Entity == null) return Location.ToString();
|
|
|
|
|
return Location.ToString() + ": " + Entity.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|