void PollControls() { if (Input.GetMouseButtonUp(0)) { if (changingSpawnPoint) { changingSpawnPoint = false; } else if (spawnPoint.GetComponent <SpriteRenderer>().bounds.Contains(GetMousePos())) { changingSpawnPoint = true; } } if (changingSpawnPoint) { spawnPoint.position = CalcSpawnPos(); } if (Input.GetKeyUp(KeyCode.T)) { if (taskInterface.GetActive()) { taskInterface.GetComponentInChildren <NodeEditorFramework.Standard.RTNodeEditor>().AutoSave(); } taskInterface.ToggleActive(); } if (Input.GetKeyDown(KeyCode.C) && !system.IsPointerOverGameObject()) { ActivateCharacterHandler(); } }
public void next(Dialogue dialogue, int ID, Entity speaker) { if (dialogue.nodes.Count == 0) { Debug.LogWarning("Empty dialogue: " + dialogue.name); endDialogue(0, false); return; } if (player.GetIsDead()) { Debug.Log("Dead player"); endDialogue(0, false); return; } // clear everything if (buttons != null) { for (int i = 0; i < buttons.Length; i++) { Destroy(buttons[i]); } } // find dialogue index int currentIndex = getNodeIndex(dialogue, ID); if (currentIndex == -1) { Debug.LogWarning("Missing node '" + ID + "' in " + dialogue.name); endDialogue(); return; } Dialogue.Node current = dialogue.nodes[currentIndex]; // check if the node has an action switch (current.action) { case Dialogue.DialogueAction.None: AudioManager.PlayClipByID("clip_typing", true); break; case Dialogue.DialogueAction.Outpost: endDialogue(0, false); if (speaker.faction != player.faction) { return; } if (((Vector3)speakerPos - player.transform.position).magnitude < dialogue.vendingBlueprint.range) { vendorUI.SetVendor(speaker as IVendor, player); vendorUI.openUI(); } endDialogue(0, false); return; case Dialogue.DialogueAction.Shop: OpenTrader((Vector3)speakerPos, dialogue.traderInventory); endDialogue(0, false); return; case Dialogue.DialogueAction.Yard: OpenBuilder((Vector3)speakerPos); endDialogue(0, false); return; case Dialogue.DialogueAction.Exit: endDialogue(0, true); return; case Dialogue.DialogueAction.Workshop: workshop.yardPosition = (Vector3)speakerPos; workshop.InitializeSelectionPhase(); endDialogue(0, false); return; case Dialogue.DialogueAction.Upgrader: upgraderScript.initialize(); endDialogue(0, false); return; default: break; } // radio image window.GetComponentInChildren <SelectionDisplayHandler>().AssignDisplay(speaker.blueprint, null); window.transform.Find("Name").GetComponent <Text>().text = speaker.blueprint.entityName; // change text text = current.text.Replace("<br>", "\n"); characterCount = 0; nextCharacterTime = (float)(Time.time + timeBetweenCharacters); textRenderer.color = current.textColor; // create buttons buttons = new GameObject[current.nextNodes.Count]; for (int i = 0; i < current.nextNodes.Count; i++) { int nextIndex = getNodeIndex(dialogue, current.nextNodes[i]); if (nextIndex == -1) { Debug.LogWarning("Missing node '" + current.nextNodes[i] + "' in " + dialogue.name); endDialogue(); return; } Dialogue.Node next = dialogue.nodes[nextIndex]; Transform button = CreateButton(next.buttonText, null, 24 + 16 * (current.nextNodes.Count - (i + 1))).transform; button.GetComponent <Button>().onClick.AddListener(() => { Next(dialogue, nextIndex, speaker); }); if (dialogue.nodes[nextIndex].action != Dialogue.DialogueAction.Exit) { button.GetComponent <Button>().onClick.AddListener(() => { AudioManager.PlayClipByID("clip_select", true); // need condition to ensure no sound clashes occur }); } buttons[i] = button.gameObject; } }
/// /// Instantiates the given prefab and sets it up as a window. /// private void CreateWindow(GameObject prefab, string text, Color color, Entity speaker) { if (window) { Destroy(window.transform.parent.gameObject); } //create window speakerPos = null; if (speaker) { speakerPos = speaker.transform.position; } window = Instantiate(prefab).GetComponentInChildren <GUIWindowScripts>(); window.Activate(); window.transform.SetSiblingIndex(0); background = window.transform.Find("Background").GetComponent <RectTransform>(); var exit = background.transform.Find("Exit"); exit.GetComponent <Button>().onClick.AddListener(() => { endDialogue(); }); if (isInCutscene) { exit.gameObject.SetActive(false); } window.OnCancelled.AddListener(() => { endDialogue(); }); textRenderer = background.transform.Find("Text").GetComponent <Text>(); textRenderer.font = shellcorefont; // radio image if (window.GetComponentInChildren <SelectionDisplayHandler>()) { if (speaker) { DialogueViewTransitionIn(speaker); window.GetComponentInChildren <SelectionDisplayHandler>().AssignDisplay(speaker.blueprint, null, speaker.faction); window.transform.Find("Name").GetComponent <Text>().text = speaker.blueprint.entityName; } else { window.GetComponentInChildren <SelectionDisplayHandler>().gameObject.SetActive(false); window.transform.Find("Name").GetComponent <Text>().text = "Unknown Speaker"; } } // change text this.text = text.Replace("<br>", "\n"); characterCount = 0; nextCharacterTime = (float)(Time.time + timeBetweenCharacters); characterCount = 0; nextCharacterTime = (float)(Time.time + timeBetweenCharacters); textRenderer.color = color; if (speaker) { AudioManager.PlayClipByID("clip_typing"); } }