Skip to content

Commit

Permalink
Add joint fitness penalty property, slider tooltips and custom toolti…
Browse files Browse the repository at this point in the history
…p heights
  • Loading branch information
keiwando committed Sep 17, 2022
1 parent 3053ecf commit ee03d5f
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Assets/Experiments/Raycast/RaycastExperiments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Awake() {
private IEnumerator TestGroundDistance() {

var joints = new List<JointData>() {
new JointData(0, new Vector2(0, 2f), 1f)
new JointData(0, new Vector2(0, 2f), 1f, 0f)
};

var config = new SceneController.SimulationSceneLoadConfig(
Expand Down
3 changes: 2 additions & 1 deletion Assets/Experiments/Shared Material/SharedMaterialTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ private void CreateFromPrefab() {
new JointData(
0,
new Vector2(0, 0),
1f
1f,
0f
)
);

Expand Down
211 changes: 208 additions & 3 deletions Assets/Scenes/EditorScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -5185,7 +5185,7 @@ RectTransform:
m_LocalScale: {x: 0.6999999, y: 0.6999999, z: 1}
m_Children: []
m_Father: {fileID: 997488835}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 1}
m_AnchorMax: {x: 0.5, y: 1}
Expand Down Expand Up @@ -5913,6 +5913,209 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 364965494}
m_CullTransparentMesh: 0
--- !u!1001 &366531710
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 997488835}
m_Modifications:
- target: {fileID: 7028291651565176436, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651565176437, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchoredPosition.x
value: -170.8
objectReference: {fileID: 0}
- target: {fileID: 7028291651565176437, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 43.1
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815405, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_Name
value: Tooltip Button
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 112
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -14.7
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_SizeDelta.x
value: 22
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_SizeDelta.y
value: 22
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_Pivot.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 7028291651971815407, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: rootContainer
value:
objectReference: {fileID: 44314773}
- target: {fileID: 7028291651971815407, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: tooltip
value:
objectReference: {fileID: 366531712}
- target: {fileID: 7028291653577406798, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291653577406798, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7028291653577406798, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 144.2
objectReference: {fileID: 0}
- target: {fileID: 7028291653577406798, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -33.6
objectReference: {fileID: 0}
- target: {fileID: 7028291653577406798, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalRotation.z
value: -0.38268343
objectReference: {fileID: 0}
- target: {fileID: 7028291653577406798, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.92387956
objectReference: {fileID: 0}
- target: {fileID: 7028291653577406798, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: -45
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6dedbf8c94a074d1ab8fb2357c973346, type: 3}
--- !u!224 &366531711 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 7028291651971815406, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
m_PrefabInstance: {fileID: 366531710}
m_PrefabAsset: {fileID: 0}
--- !u!1 &366531712 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 7028291651565176436, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
m_PrefabInstance: {fileID: 366531710}
m_PrefabAsset: {fileID: 0}
--- !u!114 &366531713 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7028291651971815407, guid: 6dedbf8c94a074d1ab8fb2357c973346,
type: 3}
m_PrefabInstance: {fileID: 366531710}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 46c0b133f08e84c46b335226e6dcada6, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &368847364
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -15100,6 +15303,7 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 366531711}
- {fileID: 1399081793}
- {fileID: 333225040}
- {fileID: 1936284832}
Expand Down Expand Up @@ -15134,6 +15338,7 @@ MonoBehaviour:
slider: {fileID: 1936284833}
descriptionLabel: {fileID: 1399081794}
valueLabel: {fileID: 333225041}
tooltip: {fileID: 366531713}
--- !u!1 &1002326365
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -21644,7 +21849,7 @@ RectTransform:
m_LocalScale: {x: 0.6999999, y: 0.6999999, z: 1}
m_Children: []
m_Father: {fileID: 997488835}
m_RootOrder: 0
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 1}
m_AnchorMax: {x: 0.5, y: 1}
Expand Down Expand Up @@ -28927,7 +29132,7 @@ RectTransform:
- {fileID: 1239820023}
- {fileID: 15777283}
m_Father: {fileID: 997488835}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0}
m_AnchorMax: {x: 0.5, y: 0}
Expand Down
5 changes: 2 additions & 3 deletions Assets/Scripts/Controllers/BoneSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Keiwando.Evolution {

public class BoneSettingsManager: BodyComponentSettingsManager {

// FIXME: THe last word here is getting cut off
private const string WING_TOOLTIP = "These wings generate force when they are moved in the direction of their feathers.";
private const string INVERT_TOOLTIP = "Flips the wing and therefore the direction of the force that it generates.";

Expand Down Expand Up @@ -39,7 +38,7 @@ public BoneSettingsManager(Bone bone, AdvancedBodyControlsViewController viewCon
Refresh();
};

wingToggle = viewController.AddToggle("Wing", WING_TOOLTIP);
wingToggle = viewController.AddToggle("Wing", new TooltipData(WING_TOOLTIP, 90f));
wingToggle.onValueChanged += delegate (bool isWing) {
var oldData = bone.BoneData;
if (isWing != oldData.isWing) {
Expand All @@ -53,7 +52,7 @@ public BoneSettingsManager(Bone bone, AdvancedBodyControlsViewController viewCon
Refresh();
};

invertedToggle = viewController.AddToggle("Invert", INVERT_TOOLTIP);
invertedToggle = viewController.AddToggle("Invert", new TooltipData(INVERT_TOOLTIP));
invertedToggle.onValueChanged += delegate (bool inverted) {
var oldData = bone.BoneData;
if (inverted != oldData.inverted) {
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Controllers/CreatureBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public bool TryPlacingJoint(Vector3 position) {
/// </summary>
private void PlaceJoint(Vector3 position) {

var jointData = new JointData(idCounter++, position, 1f);
var jointData = new JointData(idCounter++, position, 1f, 0f);
joints.Add(Joint.CreateFromData(jointData));
}

Expand Down Expand Up @@ -384,7 +384,7 @@ public bool MoveEnded(ICollection<Joint> jointsToMove) {
if (didChange) {
foreach (var joint in jointsToMove) {
var oldData = joint.JointData;
var newData = new JointData(oldData.id, joint.center, oldData.weight);
var newData = new JointData(oldData.id, joint.center, oldData.weight, oldData.fitnessPenaltyForTouchingGround);
joint.JointData = newData;
}
}
Expand Down
20 changes: 19 additions & 1 deletion Assets/Scripts/Controllers/JointSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,54 @@ namespace Keiwando.Evolution {

public class JointSettingsManager: BodyComponentSettingsManager {

private const string PENALTY_TOOLTIP = "The fitness of the creature is reduced by this amount if this joint ever touches the ground.";

private const float MIN_WEIGHT = 0.2f;
private const float MAX_WEIGHT = 5f;

private Joint joint;
private AdvancedBodyControlsViewController viewController;
private LabelledSlider weightSlider;
private LabelledSlider penaltySlider;

public JointSettingsManager(Joint joint, AdvancedBodyControlsViewController viewController): base() {
this.joint = joint;
this.viewController = viewController;

viewController.Reset();
viewController.SetTitle("Joint Settings");

weightSlider = viewController.AddSlider("Weight");
weightSlider.onDragWillBegin += delegate () {
DataWillChange();
};
weightSlider.onValueChanged += delegate (float value) {
var oldData = joint.JointData;
var weight = SliderToWeight(value);
var data = new JointData(oldData.id, oldData.position, weight);
var data = new JointData(oldData.id, oldData.position, weight, oldData.fitnessPenaltyForTouchingGround);
joint.JointData = data;
Refresh();
};

penaltySlider = viewController.AddSlider("Fitness Penalty", new TooltipData(PENALTY_TOOLTIP, 90f));
penaltySlider.onDragWillBegin += delegate () {
DataWillChange();
};
penaltySlider.onValueChanged += delegate (float penalty) {
var oldData = joint.JointData;
var data = new JointData(oldData.id, oldData.position, oldData.weight, penalty);
joint.JointData = data;
Refresh();
};

Refresh();
}

public override void Refresh() {
var weight = joint.JointData.weight;
weightSlider.Refresh(WeightToSlider(weight), string.Format("{0}x", weight.ToString("0.0")));
var penalty = joint.JointData.fitnessPenaltyForTouchingGround;
penaltySlider.Refresh(penalty, string.Format("{0}%", (int)(penalty * 100.0f)));
}

private float SliderToWeight(float value) {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Controllers/MuscleSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public MuscleSettingsManager(Muscle muscle, AdvancedBodyControlsViewController v
};

// DEBUG: Tooltip just for testing
canExpandToggle = viewController.AddToggle("Can Expand", CAN_EXPAND_TOOLTIP);
canExpandToggle = viewController.AddToggle("Can Expand", new TooltipData(CAN_EXPAND_TOOLTIP));
canExpandToggle.onValueChanged += delegate (bool canExpand) {
var oldData = muscle.MuscleData;
if (canExpand != oldData.canExpand) {
Expand Down
Loading

0 comments on commit ee03d5f

Please sign in to comment.