private void VendorTabSelect_SelectionChanged(object sender, SelectionChangedEventArgs e) { var tab = MainWindow.Instance.vendorTabSelect; if (tab.SelectedItem != null && tab.SelectedItem is TabItem tabItem && tabItem.DataContext != null) { NPCVendor selectedTabChar = tabItem.DataContext as NPCVendor; if (selectedTabChar != null) { Vendor = selectedTabChar; } } if (tab.SelectedItem is null) { MainWindow.Instance.vendorTabGrid.IsEnabled = false; MainWindow.Instance.vendorTabGrid.Visibility = Visibility.Collapsed; MainWindow.Instance.vendorTabGridNoSelection.Visibility = Visibility.Visible; } else { MainWindow.Instance.vendorTabGrid.IsEnabled = true; MainWindow.Instance.vendorTabGrid.Visibility = Visibility.Visible; MainWindow.Instance.vendorTabGridNoSelection.Visibility = Visibility.Collapsed; } }
private void VendorTabButtonAdd_Click(object sender, RoutedEventArgs e) { NPCVendor item = new NPCVendor(); MainWindow.CurrentProject.data.vendors.Add(item); MetroTabItem tabItem = CreateTab(item); MainWindow.Instance.vendorTabSelect.Items.Add(tabItem); MainWindow.Instance.vendorTabSelect.SelectedIndex = MainWindow.Instance.vendorTabSelect.Items.Count - 1; }
// Use this for initialization void Start() { if (player == null) { player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerNew>(); } npcTextOrig = npcText; textNum = 0; if (HighlightLight != null) { HighlightLight.enabled = false; } if (npcNameLevel != null) { npcNameLevel.text = NpcName; } vendor = GetComponent <NPCVendor>(); if (vendor != null) { isVendor = true; } else { isVendor = false; } blacksmith = GetComponent <NPCBlacksmith>(); if (blacksmith != null) { isBlacksmith = true; } else { isBlacksmith = false; } if (string.IsNullOrEmpty(buttonText[0])) { buttonText[0] = "Next"; } if (string.IsNullOrEmpty(buttonText[1])) { buttonText[0] = "Close"; } }
public VendorTabViewModel() { Vendor = new NPCVendor(); }
public VendorTabViewModel() { MainWindow.Instance.vendorTabSelect.SelectionChanged += VendorTabSelect_SelectionChanged; MainWindow.Instance.vendorTabButtonAdd.Click += VendorTabButtonAdd_Click; NPCVendor empty = new NPCVendor(); Vendor = empty; UpdateTabs(); ContextMenu cmenu2 = new ContextMenu(); cmenu2.Items.Add(ContextHelper.CreateAddFromTemplateButton(typeof(VendorItem), (result) => { if (result is VendorItem item) { if (item.isBuy) { AddItemBuy(item); } else { AddItemSell(item); } } })); MainWindow.Instance.vendorAddItemButton.ContextMenu = cmenu2; ContextMenu cmenu3 = new ContextMenu(); cmenu3.Items.Add(ContextHelper.CreateAddFromTemplateButton(typeof(NPCVendor), (result) => { if (result is NPCVendor item) { MainWindow.CurrentProject.data.vendors.Add(item); MetroTabItem tabItem = CreateTab(item); MainWindow.Instance.vendorTabSelect.Items.Add(tabItem); MainWindow.Instance.vendorTabSelect.SelectedIndex = MainWindow.Instance.vendorTabSelect.Items.Count - 1; } })); MainWindow.Instance.vendorTitleTxtBox.ContextMenu = ContextHelper.CreateContextMenu(ContextHelper.EContextOption.Group_Rich | ContextHelper.EContextOption.Group_TextEdit); MainWindow.Instance.vendorDescTxtBox.ContextMenu = ContextHelper.CreateContextMenu(ContextHelper.EContextOption.Group_Rich | ContextHelper.EContextOption.Group_TextEdit); ContextMenu cmenu4 = new ContextMenu(); cmenu4.Items.Add(ContextHelper.CreateSelectAssetButton(typeof(GameCurrencyAsset), (asset) => { Currency = asset.guid.ToString("N"); MainWindow.Instance.vendorCurrencyBox.Text = asset.guid.ToString("N"); }, "Control_SelectAsset_Currency", MahApps.Metro.IconPacks.PackIconMaterialKind.CurrencyUsd)); cmenu4.Items.Add(ContextHelper.CreateGenericButton(new AdvancedCommand(() => { Currency = string.Empty; MainWindow.Instance.vendorCurrencyBox.Text = string.Empty; }, (obj) => { return(!string.IsNullOrEmpty(Currency)); }), "Control_Vendor_SwitchToExperience", MahApps.Metro.IconPacks.PackIconMaterialKind.Star)); MainWindow.Instance.vendorCurrencyBox.ContextMenu = cmenu4; var vendorIdTxtBoxContext = new ContextMenu(); vendorIdTxtBoxContext.Items.Add(ContextHelper.CreateFindUnusedIDButton((id) => { this.ID = id; MainWindow.Instance.vendorIdTxtBox.Value = id; }, GameIntegration.EGameAssetCategory.NPC)); MainWindow.Instance.vendorIdTxtBox.ContextMenu = vendorIdTxtBoxContext; }
private MetroTabItem CreateTab(NPCVendor vendor) { MetroTabItem tabItem = new MetroTabItem(); tabItem.CloseButtonEnabled = true; tabItem.CloseTabCommand = CloseTabCommand; tabItem.CloseTabCommandParameter = tabItem; var binding = new Binding() { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.OneWay, Path = new PropertyPath("UIText") }; Label l = new Label(); l.SetBinding(Label.ContentProperty, binding); tabItem.Header = l; tabItem.DataContext = vendor; var cmenu = new ContextMenu(); List <MenuItem> cmenuItems = new List <MenuItem>() { ContextHelper.CreateCopyButton((object sender, RoutedEventArgs e) => { Save(); ContextMenu context = (sender as MenuItem).Parent as ContextMenu; MetroTabItem target = context.PlacementTarget as MetroTabItem; ClipboardManager.SetObject(Universal_ItemList.ReturnType.Vendor, target.DataContext); }), ContextHelper.CreateDuplicateButton((object sender, RoutedEventArgs e) => { Save(); ContextMenu context = (sender as MenuItem).Parent as ContextMenu; MetroTabItem target = context.PlacementTarget as MetroTabItem; var cloned = (target.DataContext as NPCVendor).Clone(); MainWindow.CurrentProject.data.vendors.Add(cloned); MetroTabItem ti = CreateTab(cloned); MainWindow.Instance.vendorTabSelect.Items.Add(ti); }), ContextHelper.CreatePasteButton((object sender, RoutedEventArgs e) => { if (ClipboardManager.TryGetObject(ClipboardManager.VendorFormat, out var obj) && !(obj is null) && obj is NPCVendor cloned) { MainWindow.CurrentProject.data.vendors.Add(cloned); MetroTabItem ti = CreateTab(cloned); MainWindow.Instance.vendorTabSelect.Items.Add(ti); } }) }; foreach (var cmenuItem in cmenuItems) { cmenu.Items.Add(cmenuItem); } tabItem.ContextMenu = cmenu; return(tabItem); }
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 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 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 = MainWindow.CurrentProject.data.quests.Single(d => d.id == res.openQuestId); 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 = MainWindow.CurrentProject.data.dialogues.Single(d => d.id == res.openDialogueId); Dialogue = next; Display(); } } return; } else if (res.openVendorId > 0) { shouldClose = false; NPCVendor vendorAsset = MainWindow.CurrentProject.data.vendors.Single(d => d.id == res.openVendorId); 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 = MainWindow.CurrentProject.data.dialogues.Single(d => d.id == res.openDialogueId); 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 = MainWindow.CurrentProject.data.dialogues.Single(d => d.id == res.openDialogueId); Dialogue = next; 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 GameVendorAsset(NPCVendor vendor, EGameAssetOrigin origin) : base(vendor.Title, vendor.ID, Guid.Parse(vendor.GUID), "Vendor", origin) { this.vendor = vendor; }