public static string CreateHtml(Treasure treasure, bool showTitle) { StringBuilder blocks = new StringBuilder(); blocks.CreateHtmlHeader(); if (treasure.Coin != null && treasure.Coin.GPValue != 0) { blocks.CreateSectionHeader("Coin"); blocks.AppendOpenTag("p"); blocks.AppendHtml(treasure.Coin.ToString()); blocks.AppendCloseTag("p"); } if (treasure.Goods.Count > 0) { SortedDictionary <string, List <Good> > groupedItems = new SortedDictionary <string, List <Good> >(); foreach (Good t in treasure.Goods) { if (!groupedItems.ContainsKey(t.Name)) { groupedItems[t.Name] = new List <Good>(); } groupedItems[t.Name].Add(t); } StringBuilder subBlocks = new StringBuilder(); subBlocks.AppendOpenTag("p"); bool first = true; decimal goodsVal = 0; foreach (List <Good> list in groupedItems.Values) { if (!first) { subBlocks.AppendLineBreak(); } if (list.Count > 1) { subBlocks.AppendHtml(list.Count + " x "); } Good good = list[0]; subBlocks.AppendHtml(good.Name); bool firstTreasure = true; subBlocks.AppendHtml(" ("); decimal tv = 0; bool allSame = true; foreach (Good ti in list) { goodsVal += ti.Value; if (firstTreasure) { tv = ti.Value; firstTreasure = false; } else { if (tv != ti.Value) { allSame = false; } } } if (allSame && list.Count > 1) { subBlocks.AppendHtml(good.Value + " gp each)"); } else { firstTreasure = true; foreach (Good ti in list) { if (!firstTreasure) { subBlocks.AppendHtml(", "); } firstTreasure = false; subBlocks.AppendHtml(ti.Value + " gp"); } subBlocks.AppendHtml(")"); } first = false; } subBlocks.AppendCloseTag("p"); blocks.CreateSectionHeader("Goods (" + goodsVal + " gp)"); blocks.Append(subBlocks.ToString()); } if (treasure.Items.Count > 0) { SortedDictionary <string, List <TreasureItem> > groupedItems = new SortedDictionary <string, List <TreasureItem> >(); foreach (TreasureItem t in treasure.Items) { if (!groupedItems.ContainsKey(t.Name)) { groupedItems[t.Name] = new List <TreasureItem>(); } groupedItems[t.Name].Add(t); } StringBuilder subBlocks = new StringBuilder(); subBlocks.AppendOpenTag("p"); bool first = true; string type = ""; decimal itemsVal = 0; foreach (List <TreasureItem> list in groupedItems.Values) { TreasureItem item = list[0]; if (item.Type != type) { if (type != "") { subBlocks.AppendLineBreak(); } type = item.Type; subBlocks.AppendHtmlSpan("itemspace", type); first = true; } if (first) { subBlocks.AppendLineBreak(); } if (list.Count > 1) { subBlocks.AppendHtml(list.Count + " x "); } if (item.MagicItem != null) { subBlocks.AppendHtml(item.MagicItem.Name); } else if ((item.Type == "Scroll" || item.Type == "Wand" || item.Type == "Potion") && item.Spell != null) { if (item.Type == "Scroll") { subBlocks.AppendHtml("Scroll of "); } else if (item.Type == "Potion") { subBlocks.AppendHtml("Potion of "); } else { subBlocks.AppendHtml("Wand of "); } subBlocks.AppendHtml(item.Spell.Name); } else { subBlocks.AppendHtml(item.Name); } bool firstTreasure = true; subBlocks.AppendHtml(" ("); decimal tv = 0; bool allSame = true; foreach (TreasureItem ti in list) { itemsVal += ti.Value; if (firstTreasure) { tv = ti.Value; firstTreasure = false; } else { if (tv != ti.Value) { allSame = false; } } } if (allSame && list.Count > 1) { subBlocks.AppendHtml(item.Value + " gp each)"); } else { firstTreasure = true; foreach (TreasureItem ti in list) { if (!firstTreasure) { subBlocks.AppendHtml(", "); } firstTreasure = false; subBlocks.AppendHtml(ti.Value + " gp"); } subBlocks.AppendHtml(")"); } subBlocks.AppendLineBreak(); first = false; } subBlocks.AppendCloseTag("p"); blocks.CreateSectionHeader("Items (" + itemsVal + " gp)"); blocks.Append(subBlocks.ToString()); } blocks.CreateSectionHeader("Total Value " + treasure.TotalValue.ToString("0.##") + " gp"); return(blocks.ToString()); }
public List <Block> CreateBlocks(Treasure treasure) { List <Block> blocks = new List <Block>(); if (treasure.Coin != null && treasure.Coin.GPValue != 0) { blocks.AddRange(CreateSectionHeader("Coin", true)); Paragraph coin = new Paragraph(); coin.Inlines.Add(treasure.Coin.ToString()); coin.Margin = new Thickness(0, 3, 0, 16); blocks.Add(coin); } if (treasure.Goods.Count > 0) { SortedDictionary <string, List <Good> > groupedItems = new SortedDictionary <string, List <Good> >(); foreach (Good t in treasure.Goods) { if (!groupedItems.ContainsKey(t.Name)) { groupedItems[t.Name] = new List <Good>(); } groupedItems[t.Name].Add(t); } Paragraph goods = new Paragraph(); goods.Margin = new Thickness(0, 3, 0, 16); bool first = true; decimal goodsVal = 0; foreach (List <Good> list in groupedItems.Values) { if (!first) { goods.Inlines.Add(new LineBreak()); } if (list.Count > 1) { goods.Inlines.Add(list.Count + " x "); } Good good = list[0]; goods.Inlines.Add(good.Name); bool firstTreasure = true; goods.Inlines.Add(" ("); decimal tv = 0; bool allSame = true; foreach (Good ti in list) { goodsVal += ti.Value; if (firstTreasure) { tv = ti.Value; firstTreasure = false; } else { if (tv != ti.Value) { allSame = false; } } } if (allSame && list.Count > 1) { goods.Inlines.Add(good.Value + " gp each)"); } else { firstTreasure = true; foreach (Good ti in list) { if (!firstTreasure) { goods.Inlines.Add(", "); } firstTreasure = false; goods.Inlines.Add(ti.Value + " gp"); } goods.Inlines.Add(")"); } first = false; } blocks.AddRange(CreateSectionHeader("Goods (" + goodsVal + " gp)", true)); blocks.Add(goods); } if (treasure.Items.Count > 0) { SortedDictionary <string, List <TreasureItem> > groupedItems = new SortedDictionary <string, List <TreasureItem> >(); foreach (TreasureItem t in treasure.Items) { if (!groupedItems.ContainsKey(t.Name)) { groupedItems[t.Name] = new List <TreasureItem>(); } groupedItems[t.Name].Add(t); } Paragraph items = new Paragraph(); items.Margin = new Thickness(0, 3, 0, 16); bool first = true; string type = ""; decimal itemsVal = 0; foreach (List <TreasureItem> list in groupedItems.Values) { TreasureItem item = list[0]; if (item.Type != type) { if (type != "") { items.Inlines.Add(new LineBreak()); } type = item.Type; items.Inlines.Add(new Italic(new Underline(new Run(type)))); first = true; } if (first) { items.Inlines.Add(new LineBreak()); } if (list.Count > 1) { items.Inlines.Add(list.Count + " x "); } if (item.MagicItem != null) { Hyperlink link = new Hyperlink(new Run(item.Name)); link.Tag = item.Name; link.Click += new RoutedEventHandler(MagicItemLinkClicked); link.DataContext = item.MagicItem; ToolTip t = (ToolTip)App.Current.MainWindow.FindResource("ObjectToolTip"); if (t != null) { ToolTipService.SetShowDuration(link, 360000); link.ToolTip = t; link.ToolTipOpening += new ToolTipEventHandler(link_ToolTipOpening); } items.Inlines.Add(link); } else if ((item.Type == "Scroll" || item.Type == "Wand" || item.Type == "Potion") && item.Spell != null) { if (item.Type == "Scroll") { items.Inlines.Add("Scroll of "); } else if (item.Type == "Potion") { items.Inlines.Add("Potion of "); } else { items.Inlines.Add("Wand of "); } Hyperlink link = new Hyperlink(new Run(item.Spell.name)); link.Tag = item.Spell.name; link.Click += new RoutedEventHandler(MagicItemLinkClicked); link.DataContext = item.Spell; ToolTip t = (ToolTip)App.Current.MainWindow.FindResource("ObjectToolTip"); if (t != null) { ToolTipService.SetShowDuration(link, 360000); link.ToolTip = t; link.ToolTipOpening += new ToolTipEventHandler(link_ToolTipOpening); } items.Inlines.Add(link); } else { items.Inlines.Add(item.Name); } bool firstTreasure = true; items.Inlines.Add(" ("); decimal tv = 0; bool allSame = true; foreach (TreasureItem ti in list) { itemsVal += ti.Value; if (firstTreasure) { tv = ti.Value; firstTreasure = false; } else { if (tv != ti.Value) { allSame = false; } } } if (allSame && list.Count > 1) { items.Inlines.Add(item.Value + " gp each)"); } else { firstTreasure = true; foreach (TreasureItem ti in list) { if (!firstTreasure) { items.Inlines.Add(", "); } firstTreasure = false; items.Inlines.Add(ti.Value + " gp"); } items.Inlines.Add(")"); } items.Inlines.Add(new LineBreak()); first = false; } blocks.AddRange(CreateSectionHeader("Items (" + itemsVal + " gp)", true)); blocks.Add(items); } blocks.AddRange(CreateSectionHeader("Total Value " + treasure.TotalValue + " gp")); return(blocks); }
public static string CreateHtml(Treasure treasure) { return(CreateHtml(treasure, true)); }
public void AddTreasure(Treasure treasure) { }