public void TranslateHTML(BigAl_pl game, string HTML) { #if UNITY_EDITOR Logger.Log(HTML); System.IO.File.WriteAllText(testHtmlpath, HTML); if (openHTML) { StartCoroutine(ShowHTMLInBrowser()); } #endif _game = game; inputSender._game = game; string HTMLafterActionSetup = HTML.Substring(HTML.IndexOf(actionInputString) + actionInputString.Length); int actionLength = HTMLafterActionSetup.IndexOf("'"); string actionstring = HTML.Substring(HTML.IndexOf(actionInputString) + actionInputString.Length, actionLength); string HTMLafterMoveNumSetup = HTML.Substring(HTML.IndexOf(movenumberInputString) + movenumberInputString.Length); int movenumberLength = HTMLafterMoveNumSetup.IndexOf("'"); string movenumberstring = HTML.Substring(HTML.IndexOf(movenumberInputString) + movenumberInputString.Length, movenumberLength); int movenumberint; int.TryParse(movenumberstring, out movenumberint); document = new JsDocument() { forms = new JsForm[] { new JsForm() { action = actionstring, move_number = movenumberint } } }; UpdateUI(game, HTML); }
internal void SetMapVisibility(BigAl_pl game, string hTML) { ResetMap(game, hTML); for (int i = 0; i < game.visited.Length; i++) { for (int j = 0; j < game.visited[0].Length; j++) { if (game.visited[i][j] > 0) { int combinedIndex = i * game.visited[0].Length + j; int spriteIndex = j * game.visited.Length + i; mapSquares[combinedIndex].SetSprite(mapSprites[spriteIndex]); mapSquares[combinedIndex].SetAl(false); mapSquares[combinedIndex].SetMum(false); } } } int alIndex = game.y * game.visited[0].Length + game.x; mapSquares[alIndex].SetAl(true); if (game.have_mother) { int mumIndex = game.my * game.visited[0].Length + game.mx; mapSquares[mumIndex].SetMum(true); } }
internal void SetEnemy(BigAl_pl game, string enemyKey, PerlInterface.speciesObj enemy, bool mateAvailable) { _game = game; if (enemySpriteDictionary == null) { enemySpriteDictionary = enemySprites.ToDictionary(x => x.name); } attackbutton.onClick.RemoveAllListeners(); matebutton.onClick.RemoveAllListeners(); FFbutton.onClick.RemoveAllListeners(); enemyImage.sprite = UnityUIManager.GetSpriteWithFilename(enemySpriteDictionary, enemy.Image); enemyNameText.text = enemyKey; for (int i = 0; i < 3; i++) { try { string[] values = game.enemyBars[enemyNum][i].Split('|'); if (values.Length != 3) { Logger.LogError($"Enemy {enemyNum} has invalid bar string: {game.enemyBars[enemyNum][i]}"); } else { switch (i) { case 0: SetBar(fiercebar, fiercebarImage, enemyFiercenessText, values); break; case 1: SetBar(agilitybar, agilitybarImage, enemyAgilityText, values); break; case 2: SetBar(energybar, energybarImage, enemyEnergyText, values); break; } } } catch { Logger.LogError($"Enemy bar data missing for enemy {enemyNum}"); break; } } attackCommand = $"Attack:{enemyKey}:{game.current_pack_size}"; string popupCommand = $"Popup:{enemy.URL}"; string mateCommand = $"Mate:{enemyKey}"; attackbutton.onClick.AddListener(() => { UIInputSender.instance.SendInput(attackCommand); }); FFbutton.onClick.AddListener(() => { UIInputSender.instance.SendInput(popupCommand); }); matebutton.gameObject.SetActive(mateAvailable); if (mateAvailable) { matebutton.onClick.AddListener(() => { UIInputSender.instance.SendInput(mateCommand); }); } this.gameObject.SetActive(true); }
internal void ResetMap(BigAl_pl game, string hTML) { for (int j = 0; j < mapSquares.Count; j++) { mapSquares[j].SetSprite(mapSpriteBlank); mapSquares[j].SetAl(false); mapSquares[j].SetMum(false); } }
private string AllowForDiploAttack(BigAl_pl game, string desc) { string attackDiploButtonHtml = $"<A OnMouseOver='self.status=\"Attack the Diplodocus\"; return true;' HREF='javascript:do_action(\"Attack:Diplodocus:{game.current_pack_size}\");'><IMG BORDER=0 ALIGN='BASELINE' SRC='images/level_3/3_m_attack.gif' ALT='Attack the Diplodocus' WIDTH='43' HEIGHT='18'></A>"; bool available = desc.Contains(attackDiploButtonHtml); attackDiploButton.gameObject.SetActive(available); UIInputSender.instance.SetDiploAttack(available, game.current_pack_size); desc = desc.Replace(attackDiploButtonHtml, ""); return(desc); }
internal void SetAlStats(BigAl_pl game, string hTML) { labellevel.text = "Level: " + game.level; labelscore.text = "Score: " + game.score; labelweight.text = "Weight: " + Math.Round(game.weight, 2) + "kg"; picturealweight.sprite = GetSpriteWithFilename(alWeightSpriteDictionary, game.currentWeightSprite); labelenergy.text = "Energy: " + Math.Floor(game.energy) + "%"; picturealenergy.sprite = GetSpriteWithFilename(alFilledSpriteDictionary, game.currentEnergySprite); labelfitness.text = "Fitness: " + Math.Floor(game.fitness) + "%"; picturealfitness.sprite = GetSpriteWithFilename(alFilledSpriteDictionary, game.currentFitnessSprite); }
internal void SetEnemies(BigAl_pl game, string hTML) { int index = 0; foreach (var enemy in game.species_present) { enemyUIs[index].SetEnemy(game, enemy.Key, BigAl_pl.species[enemy.Key], game.level == 4); index++; } for (int i = index; i < 4; i++) { enemyUIs[i].HideEnemy(); } }
internal void SetLocationDescription(BigAl_pl game, string hTML) { string desc = game.currentDescription; desc = desc.Replace(@"<FONT FACE='Arial,Helvetica,Helv' SIZE=2 style=""font-size: 8pt;"">", ""); desc = desc.Replace(@"</FONT>", ""); desc = AllowForEatEgg(game, desc); desc = AllowForDiploAttack(game, desc); const string matingDecisionIndicator = "document.forms[0].action.value = 'Mate:Female Allosaurus';"; const string matingMovesIndicator = "move in front and show off eye crests"; const string matingQuestionIndicator = "The female turns round and asks you a question"; matingUIController.ToggleMatingDecisionUI(hTML.Contains(matingDecisionIndicator), hTML.Contains(matingMovesIndicator), hTML.Contains(matingQuestionIndicator)); desc = matingUIController.ReplaceUnsupportedHTML(game, desc); labeldesc.text = desc; }
private string AllowForEatEgg(BigAl_pl game, string desc) { int level = game.level > 0 ? game.level : 1; string eatEggsButtonHtml = $"<A OnMouseOver='self.status=\"Eat one of the eggs\"; return true;' HREF='javascript:do_action(\"EatEgg\");'><IMG BORDER=0 ALIGN='BASELINE' SRC='images/level_{level}/{level}_eategg.gif' ALT='Eat one of the eggs' WIDTH='' HEIGHT='18'></A>"; string eatEggButtonHtml = $"<A OnMouseOver='self.status=\"Eat the egg\"; return true;' HREF='javascript:do_action(\"EatEgg\");'><IMG BORDER=0 ALIGN='BASELINE' SRC='images/level_{level}/{level}_eategg.gif' ALT='Eat the egg' WIDTH='' HEIGHT='18'></A>"; if (desc.Contains(eatEggsButtonHtml) || desc.Contains(eatEggButtonHtml)) { desc = desc.Replace(eatEggButtonHtml, ""); desc = desc.Replace(eatEggsButtonHtml, ""); eatEggButton.gameObject.SetActive(true); } else { eatEggButton.gameObject.SetActive(false); } return(desc); }
public void UpdateUI(BigAl_pl game, string HTML) { if (game.popupURL != null) { popwin_ff(game.popupURL, "_blank"); } colourManager.SetColours(game.level); UIManager.SetLevelUI(game.levellingUp, game, HTML); UIManager.SetLocationImage(game, HTML); UIManager.SetLocationDescription(game, HTML); UIManager.SetMapVisibility(game, HTML); UIManager.SetHintText(game, HTML); UIManager.SetMapKey(HTML); UIManager.SetAlStats(game, HTML); UIManager.SetEnemies(game, HTML); UIManager.ToggleSuspendedState(game.suspended); UpdateTimer(game.realtime, game.realtime > 0 ? game.timeExpiredAction : ""); }
private void SetMatingQuestionAnswers(BigAl_pl game) { string[] answers = game.matingAnswers; UIInputSender.instance.SetNumberParam(game.matingQNumber); Button[] buttons = new Button[] { decision1Button, decision2Button, decision3Button, decision4Button, decision5Button }; string[] answerCommands = new string[] { "A", "B", "C", "D", "E" }; string questionString = ""; bulletsText.text = ""; for (int i = 0; i < buttons.Length; i++) { buttons[i].enabled = false; } for (int i = 0; i < answers.Length; i++) { buttons[i].enabled = true; SetupButton(buttons[i], answers.Length > i ? answerCommands[i] : null); questionString += "<color=white>•</color> " + answers[i] + "\n"; } questionText.text = questionString; }
internal string ReplaceUnsupportedHTML(BigAl_pl game, string desc) { string reaction = FemaleReactionInDesc(desc); if (!string.IsNullOrEmpty(reaction)) { desc = reaction + " What now?"; } if (desc.Contains("The female turns round and asks you a question")) { int qStartIndex = desc.IndexOf("<INPUT TYPE = HIDDEN NAME=decision>") + "<INPUT TYPE = HIDDEN NAME=decision>".Length; int qEndIndex = desc.IndexOf("<LI><A HREF="); desc = "The female turns round and asks you a question:" + "\n" + game.matingQuestion; SetMatingQuestionAnswers(game); } else { desc = desc.Replace("<P>", ""); } return(desc); }
// Start is called before the first frame update void Start() { game = new BigAl_pl(); PerlInterface.htmlTranslator = htmlTranslator; PerlInterface.screenManager = screenManager; }
internal void SetHintText(BigAl_pl game, string hTML) { labelHint.text = game.currentHint; }
internal void SetLevelUI(bool active, BigAl_pl game, string hTML) { levelChoiceGroup.SetActive(active); levelRadioGroup.SetActive(false); level2DropdownGroup.SetActive(false); level3DropdownGroup.SetActive(false); if (active) { string levelString = ""; switch (game.level) { case 1: levelString = FileContents.level1HtmlNoLinks; levelRadioGroup.SetActive(true); level2DropdownGroup.SetActive(false); level3DropdownGroup.SetActive(false); break; case 2: levelString = FileContents.level2HtmlNoLinks; levelRadioGroup.SetActive(false); level2DropdownGroup.SetActive(true); level3DropdownGroup.SetActive(false); break; case 3: levelString = FileContents.level3HtmlNoLinks; levelRadioGroup.SetActive(false); level2DropdownGroup.SetActive(false); level3DropdownGroup.SetActive(true); break; case 4: levelString = FileContents.level4HtmlNoLinks; levelRadioGroup.SetActive(false); level2DropdownGroup.SetActive(false); level3DropdownGroup.SetActive(false); break; default: Logger.LogError($"Unknown level up {game.level}"); break; } //remove unsupported html levelString = levelString.Replace("<P>", ""); levelString = levelString.Replace(@"<INPUT name=decision value=Yes type=radio>Yes <INPUT CHECKED name=decision value=No type=radio>No", ""); levelString = levelString.Replace(@" <SELECT NAME = ""decision"" > <OPTION VALUE=0.2> Very Slowly </OPTION> <OPTION VALUE = 0.5 > Quite Slowly </OPTION> <OPTION VALUE = 1 > Medium </OPTION > <OPTION VALUE= 2 > Quite Fast</OPTION> <OPTION VALUE = 5 > Very Fast</OPTION> </SELECT>", ""); levelString = levelString.Replace(@"<SELECT NAME = 'decision' > <OPTION> 1 </OPTION> <OPTION> 2 </OPTION> <OPTION> 3 </OPTION> <OPTION> 4 </OPTION> <OPTION> 6 </OPTION> <OPTION> 8 </OPTION> </SELECT>", ""); levelString = levelString.Replace("</P> ", ""); levelText.text = levelString; } }
internal void SetLocationImage(BigAl_pl game, string hTML) { locationImage.sprite = game.currentLocationImage == null ? null : GetSpriteWithFilename(locationSpriteDictionary, game.currentLocationImage); }