diff --git a/Assets/UI/DialogueBox/DialogueBox.cs b/Assets/UI/DialogueBox/DialogueBox.cs index 4caa0a844de5d15833800a734ac0dab2f93c7671..01e775c93a16023b7509f1f0201a91ebd662c135 100644 --- a/Assets/UI/DialogueBox/DialogueBox.cs +++ b/Assets/UI/DialogueBox/DialogueBox.cs @@ -7,42 +7,45 @@ public class DialogueBox : MonoBehaviour { string ActorName = "ActorName"; string DialogueText = "DialogueText"; + TextElement[] Buttons = new TextElement[5]; + public void OnEnable() { - var uiDocument = GetComponent<UIDocument>(); - VisualElement root = uiDocument.rootVisualElement; - var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/DialogueBox/DialogueBox.uxml"); - var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/DialogueBox/DialogueBox.uss"); - VisualElement tree = visualTree.CloneTree(); - tree.styleSheets.Add(styleSheet); - root.Add(tree); - - setActor(ActorName); - setText(DialogueText); - - root.Q<Button>("Button1").visible = false; - root.Q<Button>("Button2").visible = false; - root.Q<Button>("Button3").visible = false; - root.Q<Button>("Button4").visible = false; - - root.Q<Image>("PlayIcon").image = EditorGUIUtility.IconContent("PlayButton").image; - root.Q<Image>("PlusIcon").image = EditorGUIUtility.IconContent("Toolbar Plus").image; - root.Q<Image>("MinusIcon").image = EditorGUIUtility.IconContent("Toolbar Minus").image; - - root.Q<Button>("PlayButton").RegisterCallback<MouseUpEvent>((e) => { - GetComponent<StateMachine>().nextNote(0); - if (GetComponent<StateMachine>().currentNote.Transitions == null) { - root.Q<Button>("PlayButton").visible = false;} - else { - root.Q<Button>("PlayButton").visible = true;} - }); - - root.Q<Button>("Button1").RegisterCallback<MouseUpEvent>((e) => { - GetComponent<StateMachine>().nextNote(1); - if (GetComponent<StateMachine>().currentNote.Transitions == null) { - root.Q<Button>("Button1").visible = false;} - else { - root.Q<Button>("Button1").visible = true;} - }); + var uiDocument = GetComponent<UIDocument>(); + VisualElement root = uiDocument.rootVisualElement; + var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UI/DialogueBox/DialogueBox.uxml"); + var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/DialogueBox/DialogueBox.uss"); + VisualElement tree = visualTree.CloneTree(); + tree.styleSheets.Add(styleSheet); + root.Add(tree); + + Buttons[0] = GetComponent<UIDocument>().rootVisualElement.Q<Button>("Button1"); + Buttons[1] = GetComponent<UIDocument>().rootVisualElement.Q<Button>("Button2"); + Buttons[2] = GetComponent<UIDocument>().rootVisualElement.Q<Button>("Button3"); + Buttons[3] = GetComponent<UIDocument>().rootVisualElement.Q<Button>("Button4"); + Buttons[4] = GetComponent<UIDocument>().rootVisualElement.Q<Button>("Button5"); + + setActor(ActorName); + setText(DialogueText); + + Buttons[0].RegisterCallback<MouseUpEvent>((e) => { + GetComponent<StateMachine>().nextNote(0); + }); + + Buttons[1].RegisterCallback<MouseUpEvent>((e) => { + GetComponent<StateMachine>().nextNote(1); + }); + + Buttons[2].RegisterCallback<MouseUpEvent>((e) => { + GetComponent<StateMachine>().nextNote(2); + }); + + Buttons[3].RegisterCallback<MouseUpEvent>((e) => { + GetComponent<StateMachine>().nextNote(3); + }); + + Buttons[4].RegisterCallback<MouseUpEvent>((e) => { + GetComponent<StateMachine>().nextNote(4); + }); } @@ -54,11 +57,33 @@ public void setText(string text) { GetComponent<UIDocument>().rootVisualElement.Q<TextElement>("Dialogue").text = text; } - public void setScene(string Actor, string Dialogue) { + public void setTransitions(StateMachine.Transition[] transitions) { + for (int i = 0; i < 5; i++) { + if (i < transitions.Length) { + Buttons[i].visible = true; + Buttons[i].text = transitions[i].TransitionName; + } + else { + Buttons[i].visible = false; + } + } + } + + public void setNote(string Actor, string Dialogue) { setActor(Actor); setText(Dialogue); } + public void hideButton(int count) + { + Buttons[count].visible = false; + } + + public void showButton(int count) + { + Buttons[count].visible = true; + } + } diff --git a/Assets/UI/DialogueBox/DialogueBox.uss b/Assets/UI/DialogueBox/DialogueBox.uss index 803337c47c1bf96f3c546159b8dbfdc245164b16..f486d4a45e21e51664f7268b5fd8e36de4d971e9 100644 --- a/Assets/UI/DialogueBox/DialogueBox.uss +++ b/Assets/UI/DialogueBox/DialogueBox.uss @@ -13,13 +13,14 @@ TextElement { } Button { - font-size: 20px; - -unity-font-style:normal; + font-size: 15px; + -unity-font-style:bold; color: rgb(255,255,255); - width: 50px; + width: 150px; height: 50px; - margin-left: 2px; - margin-right: 2px; + margin-left: 15px; + margin-right: 15px; + padding-top: 15px; } .row{ diff --git a/Assets/UI/DialogueBox/DialogueBox.uxml b/Assets/UI/DialogueBox/DialogueBox.uxml index 84e25d4630d2ef0c3370a90265b32552cdaff503..ee6912c3abc4958c64c5c5061dbd80a78b1c9912 100644 --- a/Assets/UI/DialogueBox/DialogueBox.uxml +++ b/Assets/UI/DialogueBox/DialogueBox.uxml @@ -6,23 +6,12 @@ <TextElement name="Dialogue"/> </VisualElement> - <VisualElement class="row"> - <Button name="Button1" /> - <Button name="Button2" /> - <Button name="Button3" /> - <Button name="Button4" /> - <Button name="PlayButton"> - <Image name="PlayIcon" /> - </Button> - </VisualElement> - - <VisualElement class="row"> - <Button name="MoreButtons"> - <Image name="PlusIcon" /> - </Button> - <Button name="LessButtons"> - <Image name="MinusIcon" /> - </Button> - </VisualElement> + <Button name="Button1" /> + <Button name="Button2" /> + <Button name="Button3" /> + <Button name="Button4" /> + <Button name="Button5" /> + + </UXML> \ No newline at end of file diff --git a/Assets/UI/DialogueBox/StateMachine.cs b/Assets/UI/DialogueBox/StateMachine.cs index 154992d2ed06df2de8bd0af77335241dc4094cc3..0140f0d4eb5c5372d59b74468614e5fbbf0ec63f 100644 --- a/Assets/UI/DialogueBox/StateMachine.cs +++ b/Assets/UI/DialogueBox/StateMachine.cs @@ -16,33 +16,45 @@ public void setNote() { var dialogueBox = GetComponent<DialogueBox>(); dialogueBox.setActor(currentNote.ActorName); dialogueBox.setText(currentNote.DialogueText); + dialogueBox.setTransitions(currentNote.Transitions); } - //Test public void Start() { Transition[] GHI = new Transition[2]; Note TestNote = new Note("Actor 3","Testing Text 3",GHI); - Transition TestingTransition = new Transition("Talk", TestNote); + Transition TestingTransition = new Transition("Continue", TestNote); Transition[] ABC = new Transition[1]; ABC[0] = TestingTransition; Note TestNote2 = new Note("Actor 2","Testing Text 2", ABC); - Transition TestingTransition1 = new Transition("Speak", TestNote2); + Transition TestingTransition1 = new Transition("Yes", TestNote2); Transition[] DEF = new Transition[1]; DEF[0] = TestingTransition1; Note TestNote3 = new Note("Actor 1","Testing Text 1", DEF); - Transition TestingTransition2 = new Transition("Speak", TestNote3); + Transition TestingTransition2 = new Transition("No", TestNote3); GHI[0] = TestingTransition1; - GHI[1] = TestingTransition2; + + Transition[] JKL = new Transition[5]; + JKL[0] = TestingTransition1; + JKL[1] = TestingTransition2; + JKL[3] = TestingTransition; + JKL[4] = TestingTransition1; + + Note TestNote4 = new Note("Actor 4", "Testing Text 4", JKL); + + Transition TestingTransition3 = new Transition("Unsure", TestNote4); + GHI[1] = TestingTransition3; + JKL[2] = TestingTransition3; currentNote = TestNote3; setNote(); } + public class Note { public string ActorName; public string DialogueText;