Skip to content

Commit

Permalink
UI rearrangements - minor improvement to behavior editing
Browse files Browse the repository at this point in the history
  • Loading branch information
apoch committed Feb 11, 2018
1 parent 2e6ea2b commit 00bf880
Show file tree
Hide file tree
Showing 9 changed files with 698 additions and 492 deletions.
9 changes: 9 additions & 0 deletions Curvature.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
<Compile Include="Widgets\EditWidgetBehaviors.Designer.cs">
<DependentUpon>EditWidgetBehaviors.cs</DependentUpon>
</Compile>
<Compile Include="Widgets\EditWidgetBehaviorScoring.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Widgets\EditWidgetBehaviorScoring.Designer.cs">
<DependentUpon>EditWidgetBehaviorScoring.cs</DependentUpon>
</Compile>
<Compile Include="Widgets\EditWidgetBehaviorSet.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down Expand Up @@ -237,6 +243,9 @@
<EmbeddedResource Include="Widgets\EditWidgetBehaviors.resx">
<DependentUpon>EditWidgetBehaviors.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Widgets\EditWidgetBehaviorScoring.resx">
<DependentUpon>EditWidgetBehaviorScoring.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Widgets\EditWidgetBehaviorSet.resx">
<DependentUpon>EditWidgetBehaviorSet.cs</DependentUpon>
</EmbeddedResource>
Expand Down
319 changes: 42 additions & 277 deletions Widgets/EditWidgetBehavior.Designer.cs

Large diffs are not rendered by default.

187 changes: 23 additions & 164 deletions Widgets/EditWidgetBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Curvature
{
public partial class EditWidgetBehavior : UserControl, IInputBroker
public partial class EditWidgetBehavior : UserControl
{
private Behavior EditBehavior;
private Project EditProject;
Expand All @@ -35,21 +35,8 @@ public EditWidgetBehavior()
internal void Attach(Behavior behavior, Project project)
{
EditProject = project;

foreach (Control ctl in ScoreLayoutPanel.Controls)
ctl.Dispose();

ScoreLayoutPanel.Controls.Clear();


foreach (Control ctl in InputFlowPanel.Controls)
ctl.Dispose();

InputFlowPanel.Controls.Clear();


EditBehavior = behavior;
NameEditWidget.Attach("Behavior", EditBehavior, EditProject);

if (!string.IsNullOrEmpty(EditBehavior.Payload))
CustomPayload.Text = EditBehavior.Payload;
else
Expand All @@ -62,127 +49,20 @@ internal void Attach(Behavior behavior, Project project)
ActionComboBox.SelectedIndex = (int)EditBehavior.Action;
CanTargetSelfCheckBox.Checked = EditBehavior.CanTargetSelf;
CanTargetOthersCheckBox.Checked = EditBehavior.CanTargetOthers;

var inputs = new Dictionary<InputAxis, List<InputAxis>>();
foreach (var consideration in EditBehavior.Considerations)
{
if (consideration.Input != null)
{
if (!inputs.ContainsKey(consideration.Input))
inputs.Add(consideration.Input, new List<InputAxis>());

var clamped = consideration.Input.Clamp(consideration.ParameterValues);
inputs[consideration.Input].Add(clamped);

ScoreLayoutPanel.Controls.Add(new EditWidgetConsiderationScore(consideration, this));
}
}

foreach (var kvp in inputs)
{
InputAxis union = null;
foreach (var input in kvp.Value)
union = input.Union(union);

if (union == null)
continue;

var widget = new EditWidgetConsiderationInput(union, this);
widget.Tag = kvp.Key;
InputFlowPanel.Controls.Add(widget);
}

RefreshInputs();
}

public double GetInputValue(Consideration consideration)
{
foreach (EditWidgetConsiderationInput input in InputFlowPanel.Controls)
{
if (input.Tag == consideration.Input)
{
if (consideration.Input.KBRec.Params == KnowledgeBase.Record.Parameterization.Enumeration)
{
var p = consideration.Input.Parameters[0] as InputParameterEnumeration;
var v = consideration.ParameterValues[0] as InputParameterValueEnumeration;
var comparison = string.Compare(v.Key, input.GetStringValue(), StringComparison.CurrentCultureIgnoreCase);

if (p.ScoreOnMatch)
{
if (comparison == 0)
return 1.0;

return 0.0;
}
else
{
if (comparison != 0)
return 1.0;

return 0.0;
}
}

return input.GetRawValue();
}
}

return 0.0;
}

public double GetInputValue(Consideration consideration, Scenario.Context context)
{
return 0.0;
}

public void RefreshInputs()
internal void Rebuild()
{
ScoreListView.Items.Clear();

double finalScore = (double)BehaviorWeightEditBox.Value;
double compensationFactor = 1.0 - (1.0 / (double)ScoreLayoutPanel.Controls.Count);

var weightItem = new ListViewItem(new string[] { $"{finalScore:f3}", "Behavior weight" });
weightItem.Group = ScoreListView.Groups[1];

ScoreListView.Items.Add(weightItem);

foreach (EditWidgetConsiderationScore score in ScoreLayoutPanel.Controls)
{
score.Refresh();

string considerationName = score.GetName();
double considerationScore = score.GetValue();
double modification = (1.0 - considerationScore) * compensationFactor;

if (CompensationCheckBox.Checked)
considerationScore = considerationScore + (modification * considerationScore);

var item = new ListViewItem(new string[] { $"{considerationScore:f3}", $"{considerationName}" });
item.Group = ScoreListView.Groups[0];

ScoreListView.Items.Add(item);
finalScore *= considerationScore;
}

if (MomentumBonusCheckBox.Checked)
{
finalScore *= 1.25;

var item = new ListViewItem(new string[] { "1.250", "Momentum bonus" });
item.Group = ScoreListView.Groups[1];

ScoreListView.Items.Add(item);
}
EditBehavior.DialogRebuildNeeded -= Rebuild;
Attach(EditBehavior, EditProject);

FinalScoreLabel.Text = $"Final Score = {finalScore:f3}";
DialogRebuildNeeded?.Invoke();
}






private void ActionComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (EditBehavior != null)
Expand All @@ -194,70 +74,49 @@ private void ActionComboBox_SelectedIndexChanged(object sender, EventArgs e)
}
}

private void CanTargetSelfCheckBox_CheckedChanged(object sender, EventArgs e)
private void CustomPayload_TextChanged(object sender, EventArgs e)
{
if (EditBehavior != null)
{
var prev = EditBehavior.CanTargetSelf;
EditBehavior.CanTargetSelf = CanTargetSelfCheckBox.Checked;
if (prev != EditBehavior.CanTargetSelf)
var prev = EditBehavior.Payload;
EditBehavior.Payload = CustomPayload.Text;
if (prev != EditBehavior.Payload)
EditProject.MarkDirty();
}
}

private void CanTargetOthersCheckBox_CheckedChanged(object sender, EventArgs e)
private void BehaviorWeightEditBox_ValueChanged(object sender, EventArgs e)
{
if (EditBehavior != null)
{
var prev = EditBehavior.CanTargetOthers;
EditBehavior.CanTargetOthers = CanTargetOthersCheckBox.Checked;
if (EditBehavior.CanTargetOthers != prev)
var prev = EditBehavior.Weight;
EditBehavior.Weight = (double)BehaviorWeightEditBox.Value;
if (prev != EditBehavior.Weight)
EditProject.MarkDirty();
}
}

private void CustomPayload_TextChanged(object sender, EventArgs e)

private void CanTargetSelfCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (EditBehavior != null)
{
var prev = EditBehavior.Payload;
EditBehavior.Payload = CustomPayload.Text;
if (prev != EditBehavior.Payload)
var prev = EditBehavior.CanTargetSelf;
EditBehavior.CanTargetSelf = CanTargetSelfCheckBox.Checked;
if (prev != EditBehavior.CanTargetSelf)
EditProject.MarkDirty();
}
}

internal void Rebuild()
{
EditBehavior.DialogRebuildNeeded -= Rebuild;
Attach(EditBehavior, EditProject);

DialogRebuildNeeded?.Invoke();
}

private void MomentumBonusCheckBox_CheckedChanged(object sender, EventArgs e)
{
RefreshInputs();
}


private void CompensationCheckBox_CheckedChanged(object sender, EventArgs e)
{
RefreshInputs();
}


private void BehaviorWeightEditBox_ValueChanged(object sender, EventArgs e)
private void CanTargetOthersCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (EditBehavior != null)
{
var prev = EditBehavior.Weight;
EditBehavior.Weight = (double)BehaviorWeightEditBox.Value;
if (prev != EditBehavior.Weight)
var prev = EditBehavior.CanTargetOthers;
EditBehavior.CanTargetOthers = CanTargetOthersCheckBox.Checked;
if (EditBehavior.CanTargetOthers != prev)
EditProject.MarkDirty();
}

RefreshInputs();
}
}
}
Loading

0 comments on commit 00bf880

Please sign in to comment.