Skip to content

Commit

Permalink
Fixed implementation of ring editing
Browse files Browse the repository at this point in the history
  • Loading branch information
8vogt committed Mar 17, 2021
1 parent 67b070e commit 589f811
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void BuildEditingSubMenu()

var topCombo = GetCombo();
Vector2 start = m_systemObjectsBox.Position + new Vector2(-0.001f, MARGIN_VERT * 2 + m_systemObjectsBox.Size.Y);
Vector2 end = start + new Vector2(topCombo.Size.X, 0.8f - MARGIN_VERT);
Vector2 end = new Vector2(topCombo.Size.X, 0.5f - MARGIN_VERT);

m_scrollPane = new MyGuiControlScrollablePanel(m_scrollTable);
m_scrollPane.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public bool OnEditMenuSelectItem(float usableWidth, MyGuiControlParentTableLayou
parentTable.AddTableRow(deleteRingButton);

MyGuiControlButton editRingButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Edit ring", OnEditRing);

parentTable.AddTableRow(editRingButton);

parentTable.AddTableSeparator();
Expand Down Expand Up @@ -280,13 +279,24 @@ public bool CreateSpawnMenu(float usableWidth, MyGuiControlParentTableLayout par
return true;
}

/// <summary>
/// Callback when edit ring button is pressed
/// </summary>
/// <param name="button">Button to press</param>
private void OnEditRing(MyGuiControlButton button)
{
var data = GetAsteroidDataFromGui();

MyAsteroidRingProvider.Static.EditInstance(m_currentSelectedAsteroid, data);

MyPluginGuiHelper.DisplayMessage("The ring was updated", "Message");
}

/// <summary>
/// Generates the specific gui elements to set ring data and puts them into the parent table
/// </summary>
/// <param name="usableWidth">Usable width for gui elements</param>
/// <param name="parentTable">Parent table</param>
private void GenerateRingSettingElements(float usableWidth, MyGuiControlParentTableLayout parentTable)
{
m_radiusSlider = new MyGuiControlClickableSlider(width: usableWidth - 0.1f, minValue: 0, maxValue: 1, labelSuffix: " km", showLabel: true);
Expand Down Expand Up @@ -515,21 +525,51 @@ private void SetSliderValues(MySystemAsteroids instance)
MyAsteroidRingData data = MyAsteroidRingProvider.Static.GetInstanceData(instance) as MyAsteroidRingData;
var planet = m_fetchedStarSytem.GetObjectById(instance.ParentId) as MySystemPlanet;

if (planet == null) return;
if (planet == null)
{
var settings = MySettingsSession.Static.Settings.GeneratorSettings;

m_radiusSlider.MinValue = settings.MinMaxOrbitDistance.Min / 1000;
m_radiusSlider.MaxValue = settings.WorldSize < 0 ? int.MaxValue / 1000 : settings.WorldSize / 1000;
m_radiusSlider.Value = m_radiusSlider.MinValue + (m_radiusSlider.MaxValue - m_radiusSlider.MinValue) / 2;
m_radiusSlider.Enabled = true;

m_widthSlider.MinValue = settings.MinMaxOrbitDistance.Min / 2000;
m_widthSlider.MaxValue = settings.MinMaxOrbitDistance.Max / 1000;
m_widthSlider.Value = m_widthSlider.MinValue + (m_widthSlider.MaxValue - m_widthSlider.MinValue) / 2;
m_widthSlider.Enabled = true;

m_heightSlider.MinValue = m_widthSlider.MinValue / 10;
m_heightSlider.MaxValue = m_widthSlider.MaxValue / 10;
m_heightSlider.Value = m_heightSlider.MinValue + (m_heightSlider.MaxValue - m_heightSlider.MinValue) / 2;
m_heightSlider.Enabled = true;

m_asteroidSizesSlider.Enabled = true;
m_asteroidSizesSlider.SetValues(32, 1024);

m_angleXSlider.Enabled = true;
m_angleXSlider.Value = 0;
m_angleYSlider.Enabled = true;
m_angleYSlider.Value = 0;
m_angleZSlider.Enabled = true;
m_angleZSlider.Value = 0;

return;
}

m_radiusSlider.MinValue = (int)planet.Diameter / 1000 * 0.75f;
m_radiusSlider.MaxValue = (int)planet.Diameter / 1000 * 2f;
m_radiusSlider.Value = (float)data.Radius;
m_radiusSlider.Value = (float)data.Radius / 1000;
m_radiusSlider.Enabled = true;

m_widthSlider.MinValue = (int)planet.Diameter / 1000 / 20f;
m_widthSlider.MaxValue = (int)planet.Diameter / 1000 / 1.25f;
m_widthSlider.Value = (float)data.Width;
m_widthSlider.Value = (float)data.Width / 1000;
m_widthSlider.Enabled = true;

m_heightSlider.MinValue = m_widthSlider.MinValue / 10;
m_heightSlider.MaxValue = m_widthSlider.MaxValue / 10;
m_heightSlider.Value = (float)data.Height;
m_heightSlider.Value = (float)data.Height / 1000;
m_heightSlider.Enabled = true;

m_asteroidSizesSlider.Enabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ private static void AddRingServer(MySystemAsteroids systemInstance, MyAsteroidRi
[Server]
private static void EditRingServer(MySystemAsteroids systemInstance, MyAsteroidRingData ringData)
{
Static?.m_loadedRings.Add(systemInstance.Id, ringData);
if (Static == null) return;
if (!Static.m_loadedRings.ContainsKey(systemInstance.Id)) return;

Static.m_loadedRings[systemInstance.Id] = ringData;

PluginEventHandler.Static.RaiseStaticEvent(NotifyEditInstance, systemInstance.Id, ringData);
}

Expand Down

0 comments on commit 589f811

Please sign in to comment.