void HeroDiag(int id) { Game game = Game.Get(); Quest.Hero target = null; foreach (Quest.Hero h in game.quest.heroes) { if (h.id == id) { target = h; } } // If there are any other dialogs if (GameObject.FindGameObjectWithTag("dialog") != null) { if (game.quest.eManager.currentEvent != null && game.quest.eManager.currentEvent.qEvent.maxHeroes != 0) { target.selected = !target.selected; UpdateStatus(); } return; } if (game.quest.heroesSelected && target.heroData != null) { new HeroDialog(target); } if (!game.quest.heroesSelected) { icons[id].color = new Color((float)0.3, (float)0.3, (float)0.3); new HeroSelection(target); } }
public HeroSelection(Quest.Hero h) { Game game = Game.Get(); float x = 8; float y = 5; HeroSelectButton(new Vector2(x, y), null, h.id); foreach (KeyValuePair <string, HeroData> hd in game.cd.heros) { x += 6; if (x > UIScaler.GetRight(-13)) { x = 8; y += 6; } bool disabled = false; foreach (Quest.Hero hIt in game.quest.heroes) { if ((hIt.heroData == hd.Value) && (hIt.id != h.id)) { disabled = true; } } HeroSelectButton(new Vector2(x, y), hd.Value, h.id, disabled); } }
// Called when hero pressed void HeroDiag(int id) { Game game = Game.Get(); Quest.Hero target = null; // Find the pressed hero foreach (Quest.Hero h in game.quest.heroes) { if (h.id == id) { target = h; break; } } // Game hasn't started, remove any selected hero if (!game.quest.heroesSelected) { target.heroData = null; UpdateImages(); if (heroSelection != null) { heroSelection.Update(); } return; } // If there are any other dialogs if (GameObject.FindGameObjectWithTag(Game.DIALOG) != null) { // Check if we are in a hero selection dialog if (game.quest.eManager.currentEvent != null && game.quest.eManager.currentEvent.qEvent.maxHeroes != 0) { // Invert hero selection target.selected = !target.selected; UpdateStatus(); } // Non hero selection dialog, do nothing return; } // We are in game and a valid hero was selected if (game.quest.heroesSelected && target.heroData != null) { if (!game.quest.UIItemsPresent()) { new HeroDialog(target); } } }
// Called when hero pressed void HeroDiag(int id) { Game game = Game.Get(); Quest.Hero target = null; // Find the pressed hero foreach (Quest.Hero h in game.quest.heroes) { if (h.id == id) { target = h; break; } } // If there are any other dialogs if (GameObject.FindGameObjectWithTag("dialog") != null) { // Check if we are in a hero selection dialog if (game.quest.eManager.currentEvent != null && game.quest.eManager.currentEvent.qEvent.maxHeroes != 0) { // Invert hero selection target.selected = !target.selected; UpdateStatus(); } // Non hero selection dialog, do nothing return; } // We are in game and a valid hero was selected if (game.quest.heroesSelected && target.heroData != null) { new HeroDialog(target); } // Game hasn't started, open hero selection options if (!game.quest.heroesSelected) { // Dim selected frame icon_frames[id].color = new Color((float)0.3, (float)0.3, (float)0.3); if (icons[id].color.a > 0) { // Dim selected hero if picked icons[id].color = new Color((float)0.3, (float)0.3, (float)0.3); } new HeroSelection(target); } }
void AddHero(Quest.Hero h, Game game) { Sprite heroSprite; string heroName = h.id.ToString(); Texture2D newTex = Resources.Load("sprites/tokens/objective-token-black") as Texture2D; if (h.heroData != null) { newTex = ContentData.FileToTexture(h.heroData.image); heroName = h.heroData.name; } GameObject heroImg = new GameObject("heroImg" + heroName); heroImg.tag = "herodisplay"; heroImg.transform.parent = game.uICanvas.transform; RectTransform trans = heroImg.AddComponent <RectTransform>(); trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (0.25f + offset) * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); offset += heroSize + 0.5f; trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0.25f * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); heroImg.AddComponent <CanvasRenderer>(); UnityEngine.UI.Image image = heroImg.AddComponent <UnityEngine.UI.Image>(); icons.Add(h.id, image); heroSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1); image.sprite = heroSprite; image.rectTransform.sizeDelta = new Vector2(heroSize * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); UnityEngine.UI.Button button = heroImg.AddComponent <UnityEngine.UI.Button>(); button.interactable = true; button.onClick.AddListener(delegate { HeroDiag(h.id); }); }
// Add a hero void AddHero(Quest.Hero h, Game game) { Sprite heroSprite; Sprite frameSprite; Texture2D frameTex = Resources.Load("sprites/borders/grey_frame") as Texture2D; if (game.gameType is MoMGameType) { frameTex = Resources.Load("sprites/borders/momframeempty") as Texture2D; } string heroName = h.id.ToString(); if (h.heroData != null) { frameTex = Resources.Load("sprites/borders/blue_frame") as Texture2D; if (game.gameType is MoMGameType) { frameTex = Resources.Load("sprites/borders/momframe") as Texture2D; } heroName = h.heroData.name.Translate(); } GameObject heroFrame = new GameObject("heroFrame" + heroName); heroFrame.tag = "herodisplay"; heroFrame.transform.SetParent(game.uICanvas.transform); RectTransform transFrame = heroFrame.AddComponent <RectTransform>(); transFrame.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (0.25f + offset) * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); transFrame.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0.25f * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); heroFrame.AddComponent <CanvasRenderer>(); UnityEngine.UI.Image imageFrame = heroFrame.AddComponent <UnityEngine.UI.Image>(); icon_frames.Add(h.id, imageFrame); frameSprite = Sprite.Create(frameTex, new Rect(0, 0, frameTex.width, frameTex.height), Vector2.zero, 1); imageFrame.sprite = frameSprite; imageFrame.rectTransform.sizeDelta = new Vector2(heroSize * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); UnityEngine.UI.Button buttonFrame = heroFrame.AddComponent <UnityEngine.UI.Button>(); buttonFrame.interactable = true; buttonFrame.onClick.AddListener(delegate { HeroDiag(h.id); }); GameObject heroImg = new GameObject("heroImg" + heroName); heroImg.tag = "herodisplay"; heroImg.transform.SetParent(game.uICanvas.transform); RectTransform trans = heroImg.AddComponent <RectTransform>(); trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (0.25f + offset) * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); if (game.quest.heroes.Count > 5) { offset += 22f / game.quest.heroes.Count; } else { offset += heroSize + 0.5f; } trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0.25f * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); heroImg.AddComponent <CanvasRenderer>(); UnityEngine.UI.Image image = heroImg.AddComponent <UnityEngine.UI.Image>(); icons.Add(h.id, image); image.rectTransform.sizeDelta = new Vector2(heroSize * UIScaler.GetPixelsPerUnit() * 0.8f, heroSize * UIScaler.GetPixelsPerUnit() * 0.8f); if (game.gameType is MoMGameType) { image.rectTransform.sizeDelta = new Vector2(heroSize * UIScaler.GetPixelsPerUnit() * 0.9f, heroSize * UIScaler.GetPixelsPerUnit() * 0.9f); heroFrame.transform.SetAsLastSibling(); } image.color = Color.clear; UnityEngine.UI.Button button = heroImg.AddComponent <UnityEngine.UI.Button>(); button.interactable = true; button.onClick.AddListener(delegate { HeroDiag(h.id); }); // Add hero image if selected if (h.heroData != null) { Texture2D newTex = ContentData.FileToTexture(h.heroData.image); heroSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1); image.sprite = heroSprite; } }
// Get the text to display for the event virtual public string GetText() { string text = qEvent.text.Translate(true); // Find and replace {q:element with the name of the // element text = ReplaceComponentText(text); // Find and replace rnd:hero with a hero // replaces all occurances with the one hero Quest.Hero h = game.quest.GetRandomHero(); if (text.Contains("{rnd:hero")) { h.selected = true; } text = text.Replace("{rnd:hero}", h.heroData.name.Translate()); // Random heroes can have custom lookups if (text.StartsWith("{rnd:hero:")) { HeroData hero = h.heroData; int start = "{rnd:hero:".Length; if (!hero.ContainsTrait("male")) { if (text[start] == '{') { start = text.IndexOf("}", start); } start = text.IndexOf(":{", start) + 1; if (text[start] == '{') { start = text.IndexOf("}", start); } start = text.IndexOf(":", start) + 1; } int next = start; if (text[next] == '{') { next = text.IndexOf("}", next); } next = text.IndexOf(":{", next) + 1; int end = next; if (text[end] == '{') { end = text.IndexOf("}", end); } end = text.IndexOf(":", end); if (end < 0) { end = text.Length - 1; } string toReplace = text.Substring(next, end - next); text = new StringKey(text.Substring(start, (next - start) - 1)).Translate(); text = text.Replace(toReplace, hero.name.Translate()); } // Fix new lines and replace symbol text with special characters return(OutputSymbolReplace(text).Replace("\\n", "\n")); }
// Create page of options public HeroSelection(Quest.Hero h) { RenderPage(h.id, 0); }
public HeroDialog(Quest.Hero h) { hero = h; CreateWindow(); }
// Get the text to display for the event virtual public string GetText() { string text = qEvent.text.Translate(true); // Find and replace {q:element with the name of the // element if (text.Contains("{c:")) { Regex questItemRegex = new Regex("{c:(((?!{).)*?)}"); string replaceFrom; string componentName; string componentText; foreach (Match oneVar in questItemRegex.Matches(text)) { replaceFrom = oneVar.Value; componentName = oneVar.Groups[1].Value; QuestData.QuestComponent component; if (game.quest.qd.components.TryGetValue(componentName, out component)) { componentText = getComponentText(component); text = text.Replace(replaceFrom, componentText); } } } // Find and replace rnd:hero with a hero // replaces all occurances with the one hero Quest.Hero h = game.quest.GetRandomHero(); if (text.Contains("{rnd:hero")) { h.selected = true; } text = text.Replace("{rnd:hero}", h.heroData.name.Translate()); // Random heroes can have custom lookups if (text.StartsWith("{rnd:hero:")) { HeroData hero = h.heroData; int start = "{rnd:hero:".Length; if (!hero.ContainsTrait("male")) { if (text[start] == '{') { start = text.IndexOf("}", start); } start = text.IndexOf(":", start) + 1; if (text[start] == '{') { start = text.IndexOf("}", start); } start = text.IndexOf(":", start) + 1; } int next = start; if (text[next] == '{') { next = text.IndexOf("}", next); } next = text.IndexOf(":", next) + 1; int end = next; if (text[end] == '{') { end = text.IndexOf("}", end); } end = text.IndexOf(":", end); if (end < 0) { end = text.Length - 1; } string toReplace = text.Substring(next, end - next); text = new StringKey(text.Substring(start, (next - start) - 1)).Translate(); text = text.Replace(toReplace, hero.name.Translate()); } // Fix new lines and replace symbol text with special characters return(OutputSymbolReplace(text).Replace("\\n", "\n")); }
// Add a hero void AddHero(Quest.Hero h, Game game) { Sprite heroSprite; Sprite frameSprite; // FIXME: should be game type specific Texture2D frameTex = Resources.Load("sprites/borders/grey_frame") as Texture2D; string heroName = h.id.ToString(); // If hero selected use blue frame (FIX for game type) if (h.heroData != null) { frameTex = Resources.Load("sprites/borders/blue_frame") as Texture2D; heroName = h.heroData.name; } GameObject heroFrame = new GameObject("heroFrame" + heroName); heroFrame.tag = "herodisplay"; heroFrame.transform.parent = game.uICanvas.transform; RectTransform transFrame = heroFrame.AddComponent <RectTransform>(); transFrame.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (0.25f + offset) * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); transFrame.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0.25f * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); heroFrame.AddComponent <CanvasRenderer>(); UnityEngine.UI.Image imageFrame = heroFrame.AddComponent <UnityEngine.UI.Image>(); icon_frames.Add(h.id, imageFrame); frameSprite = Sprite.Create(frameTex, new Rect(0, 0, frameTex.width, frameTex.height), Vector2.zero, 1); imageFrame.sprite = frameSprite; imageFrame.rectTransform.sizeDelta = new Vector2(heroSize * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); UnityEngine.UI.Button buttonFrame = heroFrame.AddComponent <UnityEngine.UI.Button>(); buttonFrame.interactable = true; buttonFrame.onClick.AddListener(delegate { HeroDiag(h.id); }); GameObject heroImg = new GameObject("heroImg" + heroName); heroImg.tag = "herodisplay"; heroImg.transform.parent = game.uICanvas.transform; RectTransform trans = heroImg.AddComponent <RectTransform>(); trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, (0.25f + offset) * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); offset += heroSize + 0.5f; trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0.25f * UIScaler.GetPixelsPerUnit(), heroSize * UIScaler.GetPixelsPerUnit()); heroImg.AddComponent <CanvasRenderer>(); UnityEngine.UI.Image image = heroImg.AddComponent <UnityEngine.UI.Image>(); icons.Add(h.id, image); image.rectTransform.sizeDelta = new Vector2(heroSize * UIScaler.GetPixelsPerUnit() * 0.8f, heroSize * UIScaler.GetPixelsPerUnit() * 0.8f); image.color = Color.clear; UnityEngine.UI.Button button = heroImg.AddComponent <UnityEngine.UI.Button>(); button.interactable = true; button.onClick.AddListener(delegate { HeroDiag(h.id); }); // Add hero image if selected if (h.heroData != null) { Texture2D newTex = ContentData.FileToTexture(h.heroData.image); heroSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1); image.sprite = heroSprite; } }