Skip to content

Commit

Permalink
Added label lock
Browse files Browse the repository at this point in the history
Bugfix: connectivity issues
  • Loading branch information
danebou committed Feb 23, 2017
1 parent 5651941 commit 7797117
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 83 deletions.
3 changes: 2 additions & 1 deletion Source/SM64 Diagnostic/Controls/ObjectSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ObjectSlot : Panel
public enum MouseStateType {None, Over, Down};
public MouseStateType MouseState;

public bool Selected
public bool SelectedOnMap
{
get
{
Expand Down Expand Up @@ -105,6 +105,7 @@ public Color TextColor
{
_textBrush.Color = value;
}
Invalidate();
}
}

Expand Down
62 changes: 39 additions & 23 deletions Source/SM64 Diagnostic/Managers/ObjectSlotsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ namespace SM64_Diagnostic.Managers
{
public class ObjectSlotsManager
{
public class ObjectSlotData
{
public uint Address;
public byte ObjectProcessGroup;
public int ProcessIndex;
public int? VacantSlotIndex;
public float DistanceToMario;
public bool IsActive;
public uint Behavior;
}

const int DefaultSlotSize = 36;

public ObjectSlot[] ObjectSlots;

public ObjectAssociations ObjectAssoc;
Expand All @@ -28,7 +40,8 @@ public class ObjectSlotsManager

Dictionary<uint, MapObject> _mapObjects = new Dictionary<uint, MapObject>();
Dictionary<uint, int> _memoryAddressSlotIndex;
Dictionary<uint, string> _lastSlotLabel = new Dictionary<uint, string>();
Dictionary<uint, Tuple<int?, int?>> _lastSlotLabel = new Dictionary<uint, Tuple<int?, int?>>();
bool _labelsLocked = false;
public List<uint> SelectedSlotsAddresses = new List<uint>();

List<byte> _toggleMapGroups = new List<byte>();
Expand Down Expand Up @@ -146,7 +159,7 @@ private void OnSlotClick(object sender, EventArgs e)
else
_toggleMapSlots.Add(selectedSlot.Address);

UpdateSelectedObjectSlots();
UpdateSelectedMapObjectSlots();

break;
case MapToggleModeType.ObjectType:
Expand All @@ -156,7 +169,7 @@ private void OnSlotClick(object sender, EventArgs e)
else
_toggleMapBehaviors.Add(behavior);

UpdateSelectedObjectSlots();
UpdateSelectedMapObjectSlots();
break;

case MapToggleModeType.ProcessGroup:
Expand All @@ -166,30 +179,30 @@ private void OnSlotClick(object sender, EventArgs e)
else
_toggleMapGroups.Add(group);

UpdateSelectedObjectSlots();
UpdateSelectedMapObjectSlots();
break;
}
break;
}
}

public void SetAllSelectedObjectSlots()
public void SetAllSelectedMapObjectSlots()
{
foreach (var objSlot in ObjectSlots)
{
objSlot.Selected = true;
objSlot.SelectedOnMap = true;
}
}

public void UpdateSelectedObjectSlots()
public void UpdateSelectedMapObjectSlots()
{
foreach (var objSlot in ObjectSlots)
{
bool selected = !_toggleMapGroups.Contains(objSlot.ProcessGroup)
&& !_toggleMapBehaviors.Contains(objSlot.Behavior)
&& !_toggleMapSlots.Contains(objSlot.Address);

objSlot.Selected = selected;
objSlot.SelectedOnMap = selected;
}
}

Expand Down Expand Up @@ -238,7 +251,6 @@ private List<ObjectSlotData> GetProcessedObjects(ObjectGroupsConfig groupConfig,
// Loop through every object within the group
while ((currentGroupObject != processGroupStructAddress && currentSlot < slotConfig.MaxSlots))
{

// Validate current object
if (_stream.GetUInt16(currentGroupObject + Config.ObjectSlots.HeaderOffset) != 0x18)
return null;
Expand Down Expand Up @@ -290,7 +302,6 @@ public void Update()
var slotConfig = Config.ObjectSlots;

var newObjectSlotData = GetProcessedObjects(groupConfig, slotConfig);

if (newObjectSlotData == null)
return;

Expand Down Expand Up @@ -361,10 +372,18 @@ public void Update()
: s.DistanceToMario).First().Address;

// Update slots
UpdateSlots(newObjectSlotData);
}

private void UpdateSlots(List<ObjectSlotData> newObjectSlotData)
{
// Lock label update
_labelsLocked = ManagerGui.LockLabelsCheckbox.Checked;

BehaviorCriteria? multiBehavior = null;
List<BehaviorCriteria> selectedBehaviorCriterias = new List<BehaviorCriteria>();
bool firstObject = true;
for (int i = 0; i < slotConfig.MaxSlots; i++)
for (int i = 0; i < Config.ObjectSlots.MaxSlots; i++)
{
var behaviorCritera = UpdateSlot(newObjectSlotData[i], ObjectSlots[i]);
if (!SelectedSlotsAddresses.Contains(newObjectSlotData[i].Address))
Expand Down Expand Up @@ -477,6 +496,9 @@ private BehaviorCriteria UpdateSlot(ObjectSlotData objData, ObjectSlot objSlot)
Config.ObjectGroups.ProcessingGroupsColor[objData.ObjectProcessGroup];
objSlot.BackColor = newColor;

if (!_labelsLocked)
_lastSlotLabel[objAddress] = new Tuple<int?, int?>(objData.ProcessIndex, objData.VacantSlotIndex);

string labelText = "";
switch ((SlotLabelType)ManagerGui.LabelMethodComboBox.SelectedItem)
{
Expand All @@ -492,28 +514,22 @@ private BehaviorCriteria UpdateSlot(ObjectSlotData objData, ObjectSlot objSlot)
break;

case SlotLabelType.SlotPos:
labelText = String.Format("{0}", objData.ProcessIndex
labelText = String.Format("{0}", _lastSlotLabel[objAddress].Item1
+ (Config.SlotIndexsFromOne ? 1 : 0));
break;

case SlotLabelType.SlotPosVs:
if (!objData.VacantSlotIndex.HasValue)
var vacantSlotIndex = _lastSlotLabel[objAddress].Item2;
if (!vacantSlotIndex.HasValue)
goto case SlotLabelType.SlotPos;

labelText = String.Format("VS{0}", objData.VacantSlotIndex.Value
labelText = String.Format("VS{0}", vacantSlotIndex.Value
+ (Config.SlotIndexsFromOne ? 1 : 0));
break;
}

if (ManagerGui.LockLabelsCheckbox.Checked)
{
if (!_lastSlotLabel.ContainsKey(objAddress))
_lastSlotLabel.Add(objAddress, labelText);
else
_lastSlotLabel[objAddress] = labelText;
}
objSlot.TextColor = ManagerGui.LockLabelsCheckbox.Checked ? Color.Red : Color.Blue;
objSlot.Text = ManagerGui.LockLabelsCheckbox.Checked ? _lastSlotLabel[objAddress] : labelText;
objSlot.TextColor = _labelsLocked ? Color.Red : Color.Blue;
objSlot.Text = labelText;

// Update object manager image
if (SelectedSlotsAddresses.Count <= 1 && SelectedSlotsAddresses.Contains(objAddress))
Expand Down
1 change: 0 additions & 1 deletion Source/SM64 Diagnostic/SM64 Diagnostic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
<Compile Include="Structs\Configurations\ObjectSlotsConfig.cs" />
<Compile Include="Structs\Configurations\ObjectGroupsConfig.cs" />
<Compile Include="Extensions\ColorExtensions.cs" />
<Compile Include="Structs\ObjectSlotData.cs" />
<Compile Include="Structs\RomHack.cs" />
<Compile Include="Structs\SpawnHack.cs" />
<Compile Include="Utilities\Kernal32NativeMethods.cs" />
Expand Down
1 change: 0 additions & 1 deletion Source/SM64 Diagnostic/StroopMainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions Source/SM64 Diagnostic/StroopMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ private void StroopMainForm_Load(object sender, EventArgs e)
_sm64Stream.FpsUpdated += _sm64Stream_FpsUpdated;
_sm64Stream.OnDisconnect += _sm64Stream_OnDisconnect;
_sm64Stream.WarnReadonlyOff += _sm64Stream_WarnReadonlyOff;
_sm64Stream.OnClose += _sm64Stream_OnClose;

currentContext.DisassemblyManager = _disManager = new DisassemblyManager(_sm64Stream, tabPageDisassembly);
currentContext.ScriptManager = _scriptManager = new ScriptManager(_sm64Stream, _scriptParser, checkBoxUseRomHack);
Expand Down Expand Up @@ -160,7 +161,7 @@ private void StroopMainForm_Load(object sender, EventArgs e)

private void _sm64Stream_WarnReadonlyOff(object sender, EventArgs e)
{
this.Invoke(new Action(() =>
Invoke(new Action(() =>
{
var dr = MessageBox.Show("Warning! Editing variables and enabling hacks may cause the emulator to freeze. Turn off read-only mode?",
"Turn Off Read-only Mode?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
Expand All @@ -184,7 +185,7 @@ private void _sm64Stream_WarnReadonlyOff(object sender, EventArgs e)

private void _sm64Stream_OnDisconnect(object sender, EventArgs e)
{
this.Invoke(new Action(() => {
this.BeginInvoke(new Action(() => {
buttonRefresh_Click(this, new EventArgs());
panelConnect.Visible = true;
}));
Expand Down Expand Up @@ -258,7 +259,7 @@ private void OnUpdate(object sender, EventArgs e)

private void _sm64Stream_FpsUpdated(object sender, EventArgs e)
{
Invoke(new Action(() =>
BeginInvoke(new Action(() =>
{
labelFpsCounter.Text = "FPS: " + (int)_sm64Stream.Fps;
}));
Expand Down Expand Up @@ -429,9 +430,22 @@ await Task.Run(() => {
_mapManager.Load();
}

private void StroopMainForm_FormClosing(object sender, FormClosingEventArgs e)
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (_sm64Stream.IsRunning)
{
_sm64Stream.Stop();
e.Cancel = true;
Hide();
return;
}

base.OnFormClosing(e);
}

private void _sm64Stream_OnClose(object sender, EventArgs e)
{
_sm64Stream.Stop();
Invoke(new Action(() => Close()));
}

private void buttonCollapseBottom_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -526,13 +540,13 @@ private void tabControlMain_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControlMain.SelectedTab == tabPageMap)
{
_objectSlotManager.UpdateSelectedObjectSlots();
_objectSlotManager.UpdateSelectedMapObjectSlots();
comboBoxMapToggleMode.Visible = true;
labelToggleMode.Visible = true;
}
else
{
_objectSlotManager.SetAllSelectedObjectSlots();
_objectSlotManager.SetAllSelectedMapObjectSlots();
comboBoxMapToggleMode.Visible = false;
labelToggleMode.Visible = false;
}
Expand Down
20 changes: 0 additions & 20 deletions Source/SM64 Diagnostic/Structs/ObjectSlotData.cs

This file was deleted.

Loading

0 comments on commit 7797117

Please sign in to comment.