void RefreshAssets() { string searchText = filter_name.Text; string searchTextLower = searchText.ToLowerInvariant(); searchMarkup = new SearchRichText(searchTextLower); foreach (Grid g in stack.Children) { if (g.Tag is GameAsset asset) { string aName; string vName; if (asset is IHasNameOverride no) { vName = no.NameOverride; } else { vName = asset.name; } if (asset is ISearchNameOverride searchNameOverride) { aName = searchNameOverride.SearchNameOverride.ToLowerInvariant(); } else if (asset is IHasNameOverride nameOverride) { aName = nameOverride.NameOverride.ToLowerInvariant(); } else if (string.IsNullOrEmpty(asset.name)) { aName = string.Empty; } else { aName = asset.name.ToLowerInvariant(); } bool shouldDisplay; if (string.IsNullOrEmpty(searchText) || aName.Contains(searchTextLower) || asset.id.ToString().Contains(searchText) || Guid.TryParse(searchTextLower, out var searchGuid) && asset.guid == searchGuid) { shouldDisplay = true; } else { shouldDisplay = false; } if (shouldDisplay) { switch (asset.origin) { case EGameAssetOrigin.Project when filter_origin_project.IsChecked == false: case EGameAssetOrigin.Unturned when filter_origin_unturned.IsChecked == false: case EGameAssetOrigin.Workshop when filter_origin_workshop.IsChecked == false: shouldDisplay = false; break; default: shouldDisplay = true; break; } } if (shouldDisplay && assetFilters.Length > 0) { foreach (var af in assetFilters) { if (af.IsEnabled) { if (!af.ShouldDisplay(asset)) { shouldDisplay = false; break; } } } } if (shouldDisplay) { g.Visibility = Visibility.Visible; if (AppConfig.Instance.highlightSearch) { Label l = g.Children[0] as Label; TextBlock tb = l.Content as TextBlock; if (string.IsNullOrEmpty(searchText)) { markup.Markup(tb, vName); } else { searchMarkup.Markup(tb, vName); } } } else { g.Visibility = Visibility.Collapsed; } } } }
public void DisplayPage(NPCMessage message, int i, int page) { Simulation.OnPropertyChanged(""); formatter.Markup(mainText, FormatText(message.pages[page])); lastPage = page; if (!canDisplayNextPage) { foreach (NPCResponse res in Dialogue.Responses) { if ((res.VisibleInAll || res.visibleIn.Length <= i || res.visibleIn[i] == 1) && res.conditions.All(d => d.Check(Simulation))) { Border border = new Border() { BorderBrush = App.Current.Resources["AccentColor"] as Brush, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4), Margin = new Thickness(0, 2.5, 0, 2.5) }; border.PreviewMouseLeftButtonDown += (sender, e) => { bool shouldClose = true; if (res.openQuestId > 0) { shouldClose = false; NPCQuest questAsset; if (GameAssetManager.TryGetAsset <GameQuestAsset>(res.openQuestId, out var gameQuestAsset)) { questAsset = gameQuestAsset.quest; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_QuestNotFound", res.openQuestId)); Close(); return; } Quest_Status questStatus = Simulation.GetQuestStatus(questAsset.ID); QuestView_Window.EMode _mode; switch (questStatus) { case Quest_Status.Ready: _mode = QuestView_Window.EMode.END_QUEST; break; default: _mode = QuestView_Window.EMode.BEGIN_QUEST; break; } QuestView_Window qvw = new QuestView_Window(Character, Simulation, questAsset, _mode); if (qvw.ShowDialog() == true) { foreach (NPC.Conditions.Condition c in res.conditions) { c.Apply(Simulation); } foreach (NPC.Rewards.Reward r in res.rewards) { r.Give(Simulation); } if (res.openDialogueId > 0) { Previous = Start; NPCDialogue next; if (GameAssetManager.TryGetAsset <GameDialogueAsset>(res.openDialogueId, out var gameDialogueAsset)) { next = gameDialogueAsset.dialogue; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_DialogueNotFound", res.openDialogueId)); Close(); return; } Dialogue = next; Display(); } } return; } else if (res.openVendorId > 0) { shouldClose = false; NPCVendor vendorAsset; if (GameAssetManager.TryGetAsset <GameVendorAsset>(res.openVendorId, out var gameVendorAsset)) { vendorAsset = gameVendorAsset.vendor; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_VendorNotFound", res.openVendorId)); Close(); return; } VendorView_Window qvw = new VendorView_Window(Character, Simulation, vendorAsset); qvw.ShowDialog(); foreach (NPC.Conditions.Condition c in res.conditions) { c.Apply(Simulation); } foreach (NPC.Rewards.Reward r in res.rewards) { r.Give(Simulation); } if (res.openDialogueId > 0) { Previous = Start; NPCDialogue next; if (GameAssetManager.TryGetAsset <GameDialogueAsset>(res.openDialogueId, out var gameDialogueAsset)) { next = gameDialogueAsset.dialogue; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_DialogueNotFound", res.openDialogueId)); Close(); return; } Dialogue = next; Display(); } return; } foreach (NPC.Conditions.Condition c in res.conditions) { c.Apply(Simulation); } foreach (NPC.Rewards.Reward r in res.rewards) { r.Give(Simulation); } if (res.openDialogueId > 0) { Previous = Dialogue; NPCDialogue next; if (GameAssetManager.TryGetAsset <GameDialogueAsset>(res.openDialogueId, out var gameDialogueAsset)) { next = gameDialogueAsset.dialogue; } else { MessageBox.Show(LocalizationManager.Current.Simulation["Dialogue"].Translate("Error_DialogueNotFound", res.openDialogueId)); Close(); return; } Display(); } else if (shouldClose) { Close(); } }; Grid g = new Grid(); TextBlock tb = new TextBlock(); formatter.Markup(tb, FormatText(res.mainText)); Label l = new Label() { Content = tb, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(5) }; g.Children.Add(l); PackIconMaterial icon = null; if (res.openQuestId > 0) { switch (Simulation.GetQuestStatus(res.openQuestId)) { case Quest_Status.Ready: icon = new PackIconMaterial() { Kind = PackIconMaterialKind.Help }; break; default: icon = new PackIconMaterial() { Kind = PackIconMaterialKind.Exclamation }; break; } } else if (res.openVendorId > 0) { icon = new PackIconMaterial() { Kind = PackIconMaterialKind.ShoppingOutline }; } if (icon != null) { icon.VerticalAlignment = VerticalAlignment.Center; icon.HorizontalAlignment = HorizontalAlignment.Left; icon.Margin = new Thickness(5); icon.Foreground = App.Current.Resources["AccentColor"] as Brush; g.Children.Add(icon); } border.Child = g; responsesPanel.Children.Add(border); } } } }
public VendorView_Window(NPCCharacter character, Simulation simulation, NPCVendor vendor) { InitializeComponent(); Vendor = vendor; Simulation = simulation; formatter.Markup(title, SimulationTool.ReplacePlaceholders(character, simulation, vendor.Title)); formatter.Markup(desc, SimulationTool.ReplacePlaceholders(character, simulation, vendor.vendorDescription)); UIElement createElement(VendorItem item) { Button b = new Button() { Margin = new Thickness(2.5), MinHeight = 64, HorizontalContentAlignment = HorizontalAlignment.Stretch, VerticalContentAlignment = VerticalAlignment.Stretch }; Grid g = new Grid(); g.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); g.ColumnDefinitions.Add(new ColumnDefinition()); TextBlock tb = new TextBlock(); formatter.Markup(tb, LocalizationManager.Current.Simulation["Vendor"].Translate("Item_Cost", item.cost)); Label l = new Label() { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Content = tb }; string nameKey; switch (item.type) { case ItemType.ITEM: nameKey = "Item_Name"; break; case ItemType.VEHICLE: nameKey = "Vehicle_Name"; break; default: throw new Exception("Invalid ItemType"); } TextBlock tb2 = new TextBlock(); Label l2 = new Label() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Content = tb2 }; TextBlock tb3 = new TextBlock() { FontSize = 9 }; Label l3 = new Label() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Content = tb3 }; Grid g2 = new Grid(); g2.RowDefinitions.Add(new RowDefinition()); g2.RowDefinitions.Add(new RowDefinition()); g2.RowDefinitions.Add(new RowDefinition()); g2.Children.Add(l); g2.Children.Add(l2); g2.Children.Add(l3); Grid.SetRow(l2, 0); Grid.SetRow(l3, 1); Grid.SetRow(l, 2); g.Children.Add(g2); Grid.SetColumn(g2, 1); if (item.type == ItemType.ITEM && GameAssetManager.TryGetAsset <GameItemAsset>(item.id, out var asset)) { g.Children.Add(new Image() { Source = new BitmapImage(asset.ImagePath), Width = 48, Height = 48, Margin = new Thickness(5) }); formatter.Markup(tb2, asset.name); formatter.Markup(tb3, asset.itemDescription); } else { formatter.Markup(tb2, LocalizationManager.Current.Simulation["Vendor"].Translate(nameKey, item.id)); tb3.Text = string.Empty; } b.Content = g; return(b); } System.Collections.Generic.IEnumerable <VendorItem> buyItems = vendor.BuyItems.Where(d => d.conditions.All(c => c.Check(simulation))); System.Collections.Generic.IEnumerable <VendorItem> sellItems = vendor.SellItems.Where(d => d.conditions.All(c => c.Check(simulation))); if (!vendor.disableSorting) // enable sorting { buyItems = buyItems.OrderBy(v => v.id); sellItems = sellItems.OrderBy(v => v.id); } foreach (VendorItem b in buyItems) { UIElement elem = createElement(b); elem.PreviewMouseLeftButtonDown += (sender, e) => { if (Simulation.Items.Any(d => d.ID == b.id)) { Simulation.Items.Remove(Simulation.Items.First(d => d.ID == b.id)); changeCurrency(b.cost, false); } }; buyingPanel.Children.Add(elem); } foreach (VendorItem s in sellItems) { UIElement elem = createElement(s); elem.PreviewMouseLeftButtonDown += (sender, e) => { if (getCurrency() >= s.cost) { changeCurrency(s.cost, true); switch (s.type) { case ItemType.ITEM: { Simulation.Items.Add(new Simulation.Item() { ID = s.id, Amount = 1, Quality = 100 }); } break; case ItemType.VEHICLE: { MessageBox.Show(LocalizationManager.Current.Simulation["Vendor"].Translate("Vehicle_Spawned", s.id, s.spawnPointID)); } break; } } }; sellingPanel.Children.Add(elem); } if (string.IsNullOrEmpty(vendor.currency)) { isCurrency = false; } else { isCurrency = true; } setupCurrency(); updateCurrency(); }
public VendorView_Window(NPCCharacter character, Simulation simulation, NPCVendor vendor) { InitializeComponent(); Vendor = vendor; Simulation = simulation; formatter.Markup(title, SimulationTool.ReplacePlaceholders(character, simulation, vendor.vendorTitle)); formatter.Markup(desc, SimulationTool.ReplacePlaceholders(character, simulation, vendor.vendorDescription)); UIElement createElement(VendorItem item) { Button b = new Button() { Margin = new Thickness(2.5), Height = 64, HorizontalContentAlignment = HorizontalAlignment.Stretch, VerticalContentAlignment = VerticalAlignment.Stretch }; Grid g = new Grid(); TextBlock tb = new TextBlock(); formatter.Markup(tb, LocalizationManager.Current.Simulation["Vendor"].Translate("Item_Cost", item.cost)); Label l = new Label() { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Content = tb }; string nameKey; switch (item.type) { case ItemType.ITEM: nameKey = "Item_Name"; break; case ItemType.VEHICLE: nameKey = "Vehicle_Name"; break; default: throw new Exception("Invalid ItemType"); } TextBlock tb2 = new TextBlock(); formatter.Markup(tb2, LocalizationManager.Current.Simulation["Vendor"].Translate(nameKey, item.id)); Label l2 = new Label() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Content = tb2 }; g.Children.Add(l); g.Children.Add(l2); b.Content = g; return(b); } System.Collections.Generic.IEnumerable <VendorItem> buyItems = vendor.BuyItems.Where(d => d.conditions.All(c => c.Check(simulation))); System.Collections.Generic.IEnumerable <VendorItem> sellItems = vendor.SellItems.Where(d => d.conditions.All(c => c.Check(simulation))); if (!vendor.disableSorting) // enable sorting { buyItems = buyItems.OrderBy(v => v.id); sellItems = sellItems.OrderBy(v => v.id); } foreach (VendorItem b in buyItems) { UIElement elem = createElement(b); elem.PreviewMouseLeftButtonDown += (sender, e) => { if (Simulation.Items.Any(d => d.ID == b.id)) { Simulation.Items.Remove(Simulation.Items.First(d => d.ID == b.id)); changeCurrency(b.cost, false); } }; buyingPanel.Children.Add(elem); } foreach (VendorItem s in sellItems) { UIElement elem = createElement(s); elem.PreviewMouseLeftButtonDown += (sender, e) => { if (getCurrency() >= s.cost) { changeCurrency(s.cost, true); switch (s.type) { case ItemType.ITEM: { Simulation.Items.Add(new Simulation.Item() { ID = s.id, Amount = 1, Quality = 100 }); } break; case ItemType.VEHICLE: { MessageBox.Show(LocalizationManager.Current.Simulation["Vendor"].Translate("Vehicle_Spawned", s.id, s.spawnPointID)); } break; } } }; sellingPanel.Children.Add(elem); } updateCurrency(); }
public QuestView_Window(NPCCharacter character, Simulation simulation, NPCQuest quest, EMode mode = EMode.PREVIEW) { InitializeComponent(); Quest = quest; switch (mode) { case EMode.PREVIEW: acceptButton.IsEnabled = false; acceptButton.Visibility = Visibility.Collapsed; continueButton.IsEnabled = false; continueButton.Visibility = Visibility.Collapsed; break; case EMode.BEGIN_QUEST: continueButton.IsEnabled = false; continueButton.Visibility = Visibility.Collapsed; break; case EMode.END_QUEST: acceptButton.IsEnabled = false; acceptButton.Visibility = Visibility.Collapsed; break; } formatter.Markup(title, SimulationTool.ReplacePlaceholders(character, simulation, quest.title)); formatter.Markup(desc, SimulationTool.ReplacePlaceholders(character, simulation, quest.description)); foreach (NPC.Conditions.Condition c in quest.conditions) { string text = c.FormatCondition(simulation); if (text == null) { continue; } Border b = new Border() { BorderBrush = App.Current.Resources["AccentColor"] as Brush, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4) }; TextBlock tb = new TextBlock(); formatter.Markup(tb, text); Label l = new Label() { Content = tb }; b.Child = l; goalsPanel.Children.Add(b); } foreach (NPC.Rewards.Reward r in quest.rewards) { string text = r.FormatReward(simulation); if (text == null) { continue; } Border b = new Border() { BorderBrush = App.Current.Resources["AccentColor"] as Brush, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4) }; TextBlock tb = new TextBlock(); formatter.Markup(tb, text); Label l = new Label() { Content = tb }; b.Child = l; rewardsPanel.Children.Add(b); } }