From b79021431d929bfdd0891b07aba0855516d9734d Mon Sep 17 00:00:00 2001 From: Patryk26g Date: Sun, 29 Dec 2024 16:47:59 +0100 Subject: [PATCH 1/6] Rigidity slider fix --- src/microbe_stage/editor/CellEditorComponent.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/microbe_stage/editor/CellEditorComponent.cs b/src/microbe_stage/editor/CellEditorComponent.cs index 7be89e7878..e46637c874 100644 --- a/src/microbe_stage/editor/CellEditorComponent.cs +++ b/src/microbe_stage/editor/CellEditorComponent.cs @@ -1261,7 +1261,7 @@ public void OnRigidityChanged(int desiredRigidity) if (previousRigidity == desiredRigidity) return; - int costPerStep = (int)Math.Min(Constants.MEMBRANE_RIGIDITY_COST_PER_STEP * CostMultiplier, 100); + var costPerStep = Math.Min(Constants.MEMBRANE_RIGIDITY_COST_PER_STEP * CostMultiplier, 100); var data = new RigidityActionData(desiredRigidity / Constants.MEMBRANE_RIGIDITY_SLIDER_TO_VALUE_RATIO, Rigidity) { @@ -1272,7 +1272,7 @@ public void OnRigidityChanged(int desiredRigidity) if (cost > Editor.MutationPoints) { - int stepsToCutOff = (int)Math.Ceiling((float)(cost - Editor.MutationPoints) / costPerStep); + int stepsToCutOff = (int)Math.Ceiling((cost - Editor.MutationPoints) / costPerStep); data.NewRigidity -= (desiredRigidity - previousRigidity > 0 ? 1 : -1) * stepsToCutOff / Constants.MEMBRANE_RIGIDITY_SLIDER_TO_VALUE_RATIO; @@ -1281,6 +1281,12 @@ public void OnRigidityChanged(int desiredRigidity) return; } + if (Editor.MutationPoints == 0 && cost == 0) + { + UpdateRigiditySlider(previousRigidity); + return; + } + var action = new SingleEditorAction(DoRigidityChangeAction, UndoRigidityChangeAction, data); Editor.EnqueueAction(action); From 582e32cc3231e78eb1cb556071ccd9b2b7290977 Mon Sep 17 00:00:00 2001 From: Patryk26g Date: Mon, 30 Dec 2024 20:04:29 +0100 Subject: [PATCH 2/6] Comment --- src/microbe_stage/editor/CellEditorComponent.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/microbe_stage/editor/CellEditorComponent.cs b/src/microbe_stage/editor/CellEditorComponent.cs index e46637c874..522b6dc17f 100644 --- a/src/microbe_stage/editor/CellEditorComponent.cs +++ b/src/microbe_stage/editor/CellEditorComponent.cs @@ -1281,6 +1281,8 @@ public void OnRigidityChanged(int desiredRigidity) return; } + // Make sure that if there are no mutation points the player cannot drag the slider + // when the cost is rounded to zero if (Editor.MutationPoints == 0 && cost == 0) { UpdateRigiditySlider(previousRigidity); From 4ff8ea832a5185b8ce7c58126b4bbb2b7a03a042 Mon Sep 17 00:00:00 2001 From: Patryk26g Date: Wed, 1 Jan 2025 15:46:02 +0100 Subject: [PATCH 3/6] Fix --- src/microbe_stage/editor/CellEditorComponent.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/microbe_stage/editor/CellEditorComponent.cs b/src/microbe_stage/editor/CellEditorComponent.cs index 522b6dc17f..89d1ee3323 100644 --- a/src/microbe_stage/editor/CellEditorComponent.cs +++ b/src/microbe_stage/editor/CellEditorComponent.cs @@ -1270,7 +1270,7 @@ public void OnRigidityChanged(int desiredRigidity) var cost = Editor.WhatWouldActionsCost(new[] { data }); - if (cost > Editor.MutationPoints) + if (cost > Editor.MutationPoints && Editor.MutationPoints != 0) { int stepsToCutOff = (int)Math.Ceiling((cost - Editor.MutationPoints) / costPerStep); data.NewRigidity -= (desiredRigidity - previousRigidity > 0 ? 1 : -1) * stepsToCutOff / @@ -1283,7 +1283,7 @@ public void OnRigidityChanged(int desiredRigidity) // Make sure that if there are no mutation points the player cannot drag the slider // when the cost is rounded to zero - if (Editor.MutationPoints == 0 && cost == 0) + if (cost >= 0 && (Editor.MutationPoints - cost < 0 || costPerStep > Editor.MutationPoints)) { UpdateRigiditySlider(previousRigidity); return; From e17fc2ef6d6e8cf35b7d5f731c98c19e18056301 Mon Sep 17 00:00:00 2001 From: Patryk26g Date: Sun, 5 Jan 2025 13:35:12 +0100 Subject: [PATCH 4/6] Fix --- src/microbe_stage/editor/CellEditorComponent.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/microbe_stage/editor/CellEditorComponent.cs b/src/microbe_stage/editor/CellEditorComponent.cs index 89d1ee3323..6d7542126a 100644 --- a/src/microbe_stage/editor/CellEditorComponent.cs +++ b/src/microbe_stage/editor/CellEditorComponent.cs @@ -1268,7 +1268,9 @@ public void OnRigidityChanged(int desiredRigidity) CostMultiplier = CostMultiplier, }; - var cost = Editor.WhatWouldActionsCost(new[] { data }); + // In some cases "theoreticalCost" might get rounded improperly + var theoreticalCost = Editor.WhatWouldActionsCost(new[] { data }); + var cost = (int)Math.Ceiling(Math.Ceiling(theoreticalCost / costPerStep) * costPerStep); if (cost > Editor.MutationPoints && Editor.MutationPoints != 0) { From 497d9d39e5f4404c193bbb9675549edfacfa8fed Mon Sep 17 00:00:00 2001 From: Patryk26g Date: Tue, 14 Jan 2025 22:38:53 +0100 Subject: [PATCH 5/6] Yet another fix --- src/microbe_stage/editor/CellEditorComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/microbe_stage/editor/CellEditorComponent.cs b/src/microbe_stage/editor/CellEditorComponent.cs index 6d7542126a..0d57b1341b 100644 --- a/src/microbe_stage/editor/CellEditorComponent.cs +++ b/src/microbe_stage/editor/CellEditorComponent.cs @@ -1285,7 +1285,7 @@ public void OnRigidityChanged(int desiredRigidity) // Make sure that if there are no mutation points the player cannot drag the slider // when the cost is rounded to zero - if (cost >= 0 && (Editor.MutationPoints - cost < 0 || costPerStep > Editor.MutationPoints)) + if (theoreticalCost >= 0 && (Editor.MutationPoints - cost < 0 || costPerStep > Editor.MutationPoints)) { UpdateRigiditySlider(previousRigidity); return; From 69b98714c1274779bcb5dc87b991925ac1a8e618 Mon Sep 17 00:00:00 2001 From: Patryk26g Date: Tue, 14 Jan 2025 22:41:13 +0100 Subject: [PATCH 6/6] Comment --- src/microbe_stage/editor/CellEditorComponent.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/microbe_stage/editor/CellEditorComponent.cs b/src/microbe_stage/editor/CellEditorComponent.cs index 0d57b1341b..8a5cf32870 100644 --- a/src/microbe_stage/editor/CellEditorComponent.cs +++ b/src/microbe_stage/editor/CellEditorComponent.cs @@ -1272,6 +1272,7 @@ public void OnRigidityChanged(int desiredRigidity) var theoreticalCost = Editor.WhatWouldActionsCost(new[] { data }); var cost = (int)Math.Ceiling(Math.Ceiling(theoreticalCost / costPerStep) * costPerStep); + // Cases where mutation points are equal 0 are handled below in the next "if" statement if (cost > Editor.MutationPoints && Editor.MutationPoints != 0) { int stepsToCutOff = (int)Math.Ceiling((cost - Editor.MutationPoints) / costPerStep);