/// <summary> /// 刷新,根据所有数据刷新显示,这个排版方式虽然还可以,但是过于不优雅了. /// 日后需要从引擎层面加以改善,目前是notepad排版,然后用这个拼 /// </summary> public void Refresh(Character character) { ColorStringBuilder sb = new ColorStringBuilder(); sb.AppendString("-[", DefaultColor); sb.AppendString(CharUtils.SubStr(character.ClassName, 2), Color.Blue); sb.AppendString("][", DefaultColor); sb.AppendString(CharUtils.SubStr(character.CharacterName, 12), Color.DarkCyan); sb.AppendString("]-[HP]", DefaultColor); string hp = "[ " + CharUtils.ParseNum(character.HP, 4) + "/" + CharUtils.ParseNum(character.MaxHP, 4) + "]"; sb.AppendString(hp); if (character.Buffs.Count > 0) { sb.AppendString("-[", DefaultColor); sb.AppendString(character.Buffs[0].Icon); } #region 略 太丑了 if (character.Buffs.Count > 1) { sb.AppendString("][", DefaultColor); sb.AppendString(character.Buffs[1].Icon); } if (character.Buffs.Count > 2) { sb.AppendString("][", DefaultColor); sb.AppendString(character.Buffs[2].Icon); } if (character.Buffs.Count > 3) { sb.AppendString("] -[", DefaultColor); sb.AppendString(character.Buffs[3].Icon); } if (character.Buffs.Count > 4) { sb.AppendString("][", DefaultColor); sb.AppendString(character.Buffs[4].Icon); } #endregion if (character.Buffs.Count > 5) { sb.AppendString("][", DefaultColor); sb.AppendString(character.Buffs[5].Icon); sb.AppendString("] ", DefaultColor); } labelCom.Rendering(sb.ToRenderer()); progressBar.MaxValue = character.MaxHP; progressBar.Value = character.HP; }
/// <summary> /// /// </summary> public override void Update() { int am = GunBox.Instance.CurrertAM; ColorStringBuilder colorStringBuilder = new ColorStringBuilder(); colorStringBuilder.ForeColor = Color.Blue; colorStringBuilder.AppendString("AM: "); if (am > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < am; i++) { sb.Append('>'); } colorStringBuilder.ForeColor = Color.Green; colorStringBuilder.AppendString(sb.ToString()); } else { colorStringBuilder.ForeColor = Color.Red; colorStringBuilder.AppendString("EMPTY"); //这里展示了组件化的好处(坏处)如何找一个要找的物体 /* * Gunbox.Instance 获取Gunbox这个脚本的引用.这个脚本有一个单例引用 * .GetComponent<ListBox>() 获取这个物体上的ListBox组件 * .CurrentItem 组件当前正在被选区的对象 * .GetComponent<Renderer>() 由于更改颜色是一个组件本身不提供的功能,这个功能位于同一物体的Renderer组件中 * .SetForeColor(Color.Red); 调用这个子物体的Renderer组件完成变色 * 这是一个其他的例子 * GunBox.Instanse..GetComponent<ListBox>().CurrentItem.GetComponent<Gun>().AM = 0; */ GunBox.Instance.GetComponent <ListBox>().CurrentItem.GetComponent <Renderer>().SetForeColor(Color.Red); } textBox.Labels[2].Rendering(colorStringBuilder.ToRenderer()); }
protected async Task ReadRawText(string rawtext) { TextArea.Margin = TextAreaMargin; TextArea.Clear(true); int ip = 0; int line = 4; Color clr = ArticleTextColor; ColorStringBuilder text = new ColorStringBuilder(); bool waiting = true; while (ip < rawtext.Length) { // ignore any \r characters. we will interpret \n as the new line character. if (rawtext[ip] == '\r') { ip++; continue; } if (rawtext[ip] == '\n') { line--; text = new ColorStringBuilder(); int i = 1; while (rawtext[ip + i] == ' ') { i++; } if (rawtext[ip + i] == '|') { ip += i - 1; } await TextArea.PrintLine(); } else if (rawtext[ip] == '|' && (text.Text == null || text.Text.Trim() == "")) { text.Clear(); } else if (rawtext[ip] != '`') { text.AddText(rawtext[ip].ToString(), clr); await TextArea.Print(rawtext[ip].ToString(), clr); if (waiting) { string punctuation = ",.!"; int time = 30; if (punctuation.Contains(rawtext[ip].ToString())) { time = 350 * (1 + punctuation.IndexOf(rawtext[ip])); } await GameControl.WaitAsync(time, true); } } else { int next = rawtext.IndexOf('`', ip + 1); if (next < 0) { throw new ArgumentException("Text had unmatched quote!"); } string substr = rawtext.Substring(ip + 1, next - ip - 1); ip = next; if (substr.StartsWith("image:")) { int image = int.Parse(substr.Substring(6)); ImageID = image; } else { switch (substr) { case "": break; case "white": clr = XleColor.White; break; case "cyan": clr = XleColor.Cyan; break; case "yellow": clr = XleColor.Yellow; break; case "green": clr = XleColor.Green; break; case "purple": clr = XleColor.Purple; break; case "pause": await GameControl.WaitForKey(); break; case "clear": TextArea.Clear(true); line = 4; break; case "sound:VeryGood": SoundMan.PlaySound(LotaSound.VeryGood); break; case "wait:off": waiting = false; break; case "wait:on": waiting = true; break; default: System.Diagnostics.Trace.WriteLine("Failed to understand command: " + substr); break; } } } ip++; } TextArea.Margin = 1; await TextArea.PrintLine(); }
public override async Task Execute() { MenuItemList menuItems = new MenuItemList("Yes", "No"); int choice; bool saved = false; await TextArea.PrintLine("\nWould you like to save"); await TextArea.PrintLine("the game in progress?"); await TextArea.PrintLine(); choice = await menu.QuickMenu(menuItems, 2); if (choice == 0) { gamePersistance.Save(Player); saved = true; await TextArea.PrintLine(); await TextArea.PrintLine("Game Saved."); await TextArea.PrintLine(); } else { ColorStringBuilder builder = new ColorStringBuilder(); await TextArea.PrintLine(); await TextArea.Print("Game ", XleColor.White); await TextArea.Print("not", XleColor.Yellow); await TextArea.Print(" saved.", XleColor.White); await TextArea.PrintLine(); await TextArea.PrintLine(); } await gameControl.WaitAsync(1500); await TextArea.PrintLine("Quit and return to title screen?"); if (saved == false) { await TextArea.PrintLine("Unsaved progress will be lost.", XleColor.Yellow); } else { await TextArea.PrintLine(); } await TextArea.PrintLine(); choice = await menu.QuickMenu(menuItems, 2, 1); if (choice == 0) { systemState.ReturnToTitle = true; } }