Skip to content

Commit 542af32

Browse files
authored
Merge pull request #44 from VitoBarra/main
Wire Type menu hot fix
2 parents 87e367c + b294242 commit 542af32

File tree

4 files changed

+76
-57
lines changed

4 files changed

+76
-57
lines changed

Assets/Scripts/Chip/InputSignal.cs

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,61 @@
33

44
// Provides input signal (0 or 1) to a chip.
55
// When designing a chip, this input signal can be manually set to 0 or 1 by the player.
6-
public class InputSignal : ChipSignal {
7-
8-
9-
protected override void Start () {
10-
base.Start ();
11-
SetCol ();
12-
}
13-
14-
public void ToggleActive () {
15-
currentState = 1 - currentState;
16-
SetCol ();
17-
}
18-
19-
public void SendSignal (int signal) {
20-
currentState = signal;
21-
outputPins[0].ReceiveSignal (signal);
22-
SetCol ();
23-
}
24-
25-
public void SendOffSignal()
26-
{
27-
outputPins[0].ReceiveSignal(0);
28-
SetCol();
29-
}
30-
31-
public void SendSignal () {
32-
outputPins[0].ReceiveSignal (currentState);
33-
}
34-
35-
void SetCol () {
36-
SetDisplayState (currentState);
37-
}
38-
39-
public override void UpdateSignalName (string newName) {
40-
base.UpdateSignalName (newName);
41-
outputPins[0].pinName = newName;
42-
}
43-
44-
void OnMouseDown () {
45-
// Allow only to click on single wires, not on bus wires
46-
if(outputPins.All(x => x.wireType == Pin.WireType.Simple))
47-
ToggleActive ();
48-
}
6+
public class InputSignal : ChipSignal
7+
{
8+
9+
10+
protected override void Start()
11+
{
12+
base.Start();
13+
SetCol();
14+
}
15+
16+
public void ToggleActive()
17+
{
18+
currentState = 1 - currentState;
19+
SetCol();
20+
}
21+
22+
public void SetState(int state)
23+
{
24+
currentState = state >= 1 ? 1 : 0;
25+
SetCol();
26+
}
27+
28+
public void SendSignal(int signal)
29+
{
30+
currentState = signal;
31+
outputPins[0].ReceiveSignal(signal);
32+
SetCol();
33+
}
34+
35+
public void SendOffSignal()
36+
{
37+
outputPins[0].ReceiveSignal(0);
38+
SetCol();
39+
}
40+
41+
public void SendSignal()
42+
{
43+
outputPins[0].ReceiveSignal(currentState);
44+
}
45+
46+
void SetCol()
47+
{
48+
SetDisplayState(currentState);
49+
}
50+
51+
public override void UpdateSignalName(string newName)
52+
{
53+
base.UpdateSignalName(newName);
54+
outputPins[0].pinName = newName;
55+
}
56+
57+
void OnMouseDown()
58+
{
59+
// Allow only to click on single wires, not on bus wires
60+
if (outputPins.All(x => x.wireType == Pin.WireType.Simple))
61+
ToggleActive();
62+
}
4963
}

Assets/Scripts/Chip/Pin.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ public class Pin : MonoBehaviour
77
public enum WireType { Simple, Bus4, Bus8, Bus16, Bus32 }
88
public enum PinType { ChipInput, ChipOutput }
99
public PinType pinType;
10+
1011
public WireType wireType;
12+
1113
// The chip that this pin is attached to (either as an input or output
1214
// terminal)
1315
public Chip chip;
@@ -189,4 +191,6 @@ public void MouseExit()
189191
transform.localScale = Vector3.one * radius * 2;
190192
UpdateColor();
191193
}
194+
195+
192196
}

Assets/Scripts/Interaction/ChipInterfaceEditor.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,27 @@ public override void FocusLostHandler()
126126

127127

128128
// Event handler when changed input or output pin wire type
129-
public void ModeChanged(int mode)
129+
public void ChangeWireType(int mode)
130130
{
131131
if (!IsSomethingSelected)
132132
return;
133133

134134
// Change output pin wire mode
135+
foreach (var sig in selectedSignals)
136+
sig.wireType = (Pin.WireType)mode;
137+
135138
foreach (var pin in selectedSignals.SelectMany(x => x.inputPins))
136-
{
137139
pin.wireType = (Pin.WireType)mode;
138-
}
139140

140141
// Change input pin wire mode
141142
if (selectedSignals[0] is InputSignal)
142143
{
143144
foreach (InputSignal signal in selectedSignals)
144145
{
145146
var pin = signal.outputPins[0];
146-
if (pin == null)
147-
return;
147+
if (pin == null) return;
148148
pin.wireType = (Pin.WireType)mode;
149-
// Turn off input pin
150-
if (pin.State == 1)
151-
signal.ToggleActive();
149+
signal.SetState(0);
152150
}
153151
}
154152
}
@@ -347,7 +345,7 @@ void HandleSpawning()
347345
visiblePins.AddRange(spawnedSignal.inputPins);
348346
visiblePins.AddRange(spawnedSignal.outputPins);
349347
spawnedSignals[i] = spawnedSignal;
350-
348+
351349
}
352350

353351
if (isGroup)
@@ -428,7 +426,7 @@ void DrawSignalHandles()
428426

429427
if (selectedSignals.Contains(singnal))
430428
handleState = HasFocus ? HandleState.SelectedAndFocused : HandleState.Selected;
431-
else if(singnal == highlightedSignal)
429+
else if (singnal == highlightedSignal)
432430
handleState = HandleState.Highlighted;
433431

434432
DrawHandle(singnal.transform.position.y, handleState);
@@ -494,8 +492,10 @@ void SelectSignal(ChipSignal signalToDrag)
494492
dragHandleStartY = selectedSignals[selectedSignals.Count / 2].transform.position.y;
495493
}
496494

497-
PropertiesMenu.EnableUI(this, selectedSignals[0].signalName, selectedSignals.Count > 1, selectedSignals[0].useTwosComplement,
498-
currentEditorName, signalToDrag.signalName, (int)selectedSignals[0].wireType);
495+
PropertiesMenu?.EnableUI(this,
496+
selectedSignals[0].signalName, selectedSignals.Count > 1,
497+
selectedSignals[0].useTwosComplement, currentEditorName,
498+
signalToDrag.signalName, (int)selectedSignals[0].wireType);
499499
RequestFocus();
500500

501501
UpdatePropertyUIPosition();

Assets/Scripts/UI/Menu/ChipPropertiesMenu.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void EnableUI(ChipInterfaceEditor chipInterfaceEditor, string signalName,
5555

5656
Opened = true;
5757
}
58-
58+
5959
public void DisableUI()
6060
{
6161
if (!Opened) return;
@@ -90,6 +90,7 @@ void Delete()
9090
}
9191
void OnValueDropDownChange(int mode)
9292
{
93-
CurrentInterface.ModeChanged(mode);
93+
if (CurrentInterface != null)
94+
CurrentInterface.ChangeWireType(mode);
9495
}
9596
}

0 commit comments

Comments
 (0)