VPet/VPet-Simulator.Windows/WinDesign/winBetterBuy.xaml.cs

219 lines
8.0 KiB
C#
Raw Normal View History

2023-06-08 11:44:41 +00:00
using IWshRuntimeLibrary;
using Panuon.WPF;
2023-06-05 08:42:20 +00:00
using Panuon.WPF.UI;
using System;
2023-06-01 14:50:40 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
2023-06-05 08:42:20 +00:00
using System.Windows.Controls.Primitives;
2023-06-01 14:50:40 +00:00
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
2023-06-08 08:46:53 +00:00
using VPet_Simulator.Core;
using VPet_Simulator.Windows.Interface;
using static VPet_Simulator.Core.GraphCore;
using static VPet_Simulator.Core.IGraph;
2023-06-01 14:50:40 +00:00
namespace VPet_Simulator.Windows
{
/// <summary>
/// winBetterBuy.xaml 的交互逻辑
/// </summary>
2023-06-05 08:42:20 +00:00
public partial class winBetterBuy : WindowX
2023-06-01 14:50:40 +00:00
{
2023-06-05 08:42:20 +00:00
private TextBox _searchTextBox;
2023-06-08 08:46:53 +00:00
MainWindow mw;
private bool AllowChange = false;
2023-06-05 08:42:20 +00:00
2023-06-01 14:50:40 +00:00
public winBetterBuy(MainWindow mw)
{
InitializeComponent();
2023-06-08 08:46:53 +00:00
this.mw = mw;
LsbSortRule.SelectedIndex = mw.Set["betterbuy"].GetInt("lastorder");
LsbSortAsc.SelectedIndex = mw.Set["betterbuy"].GetBool("lastasc") ? 0 : 1;
AllowChange = true;
}
public void Show(Food.FoodType type)
{
2023-06-08 11:44:41 +00:00
mw.Topmost = false;
2023-06-08 08:46:53 +00:00
LsbCategory.SelectedIndex = (int)type;
//OrderItemSource(type, LsbSortRule.SelectedIndex, LsbSortAsc.SelectedIndex);
Show();
}
2023-06-08 11:44:41 +00:00
public void OrderItemSource(Food.FoodType type, int sortrule, bool sortasc, string searchtext = null)
2023-06-08 08:46:53 +00:00
{
Task.Run(() =>
2023-06-05 08:42:20 +00:00
{
2023-06-08 11:44:41 +00:00
List<Food> foods;
2023-06-08 08:46:53 +00:00
switch (type)
2023-06-05 08:42:20 +00:00
{
2023-06-08 08:46:53 +00:00
case Food.FoodType.Food:
foods = mw.Foods;
break;
case Food.FoodType.Star:
//List<Food> lf = new List<Food>();
//foreach (var sub in mw.Set["betterbuy"].FindAll("star"))
//{
// var str = sub.Info;
// var food = mw.Foods.FirstOrDefault(x => x.Name == str);
// if (food != null)
// lf.Add(food);
//}
//foods = lf;
foods = mw.Foods.FindAll(x => x.Star);
break;
default:
foods = mw.Foods.FindAll(x => x.Type == type);
break;
}
2023-06-08 11:44:41 +00:00
if (!string.IsNullOrEmpty(searchtext))
{
foods = foods.FindAll(x => x.Name.Contains(searchtext));
}
2023-06-08 08:46:53 +00:00
IOrderedEnumerable<Food> ordered;
switch (sortrule)
2023-06-05 08:42:20 +00:00
{
2023-06-08 08:46:53 +00:00
case 0:
if (sortasc)
ordered = foods.OrderBy(x => x.Name);
else
ordered = foods.OrderByDescending(x => x.Name);
break;
case 1:
if (sortasc)
ordered = foods.OrderBy(x => x.Price);
else
ordered = foods.OrderByDescending(x => x.Price);
break;
case 2:
if (sortasc)
ordered = foods.OrderBy(x => x.StrengthFood);
else
ordered = foods.OrderByDescending(x => x.StrengthFood);
break;
case 3:
if (sortasc)
ordered = foods.OrderBy(x => x.StrengthDrink);
else
ordered = foods.OrderByDescending(x => x.StrengthDrink);
break;
case 4:
if (sortasc)
ordered = foods.OrderBy(x => x.Strength);
else
ordered = foods.OrderByDescending(x => x.Strength);
break;
case 5:
if (sortasc)
ordered = foods.OrderBy(x => x.Feeling);
else
ordered = foods.OrderByDescending(x => x.Feeling);
break;
default:
if (sortasc)
ordered = foods.OrderBy(x => x.Health);
else
ordered = foods.OrderByDescending(x => x.Health);
break;
}
Dispatcher.Invoke(() =>
{
IcCommodity.ItemsSource = ordered;
});
});
2023-06-05 08:42:20 +00:00
}
2023-06-08 08:46:53 +00:00
//private void RbtnIncrease_Click(object sender, RoutedEventArgs e)
//{
// var repeatButton = sender as RepeatButton;
// var item = repeatButton.DataContext as BetterBuyItem;
// item.Quantity = Math.Max(1, item.Quantity + 1);
//}
2023-06-05 08:42:20 +00:00
2023-06-08 08:46:53 +00:00
//private void RbtnDecrease_Click(object sender, RoutedEventArgs e)
//{
// var repeatButton = sender as RepeatButton;
// var item = repeatButton.DataContext as BetterBuyItem;
// item.Quantity = Math.Max(1, item.Quantity - 1);
//}
2023-06-08 21:06:46 +00:00
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
eventArg.RoutedEvent = UIElement.MouseWheelEvent;
eventArg.Source = sender;
PageDetail.RaiseEvent(eventArg);
}
2023-06-05 08:42:20 +00:00
private void BtnBuy_Click(object sender, RoutedEventArgs e)
{
2023-06-08 11:44:41 +00:00
2023-06-08 08:46:53 +00:00
var Button = sender as Button;
var item = Button.DataContext as Food;
2023-06-08 11:44:41 +00:00
//看是什么模式
if (mw.Set.EnableFunction)
{
if (item.Price >= mw.Core.Save.Money)
{//买不起
MessageBoxX.Show($"您没有足够金钱来购买 {item.Name}\n您需要 {item.Price:f2} 金钱来购买\n您当前 {mw.Core.Save.Money:f2} 拥有金钱"
, "金钱不足");
return;
}
//开始加点
mw.Core.Save.EatFood(item);
mw.Core.Save.Money -= item.Price;
}
this.Hide();
2023-06-08 08:46:53 +00:00
IRunImage eat = (IRunImage)mw.Core.Graph.FindGraph(GraphType.Eat, GameSave.ModeType.Nomal);
var b = mw.Main.FindDisplayBorder(eat);
eat.Run(b, item.ImageSource, mw.Main.DisplayToNomal);
2023-06-08 11:44:41 +00:00
2023-06-05 08:42:20 +00:00
}
private void BtnSearch_Click(object sender, RoutedEventArgs e)
{
Search();
}
private void BtnTitle_Click(object sender, RoutedEventArgs e)
{
_searchTextBox.Text = "";
Search();
}
private void Search()
{
2023-06-08 11:44:41 +00:00
OrderItemSource((Food.FoodType)LsbCategory.SelectedIndex, LsbSortRule.SelectedIndex, LsbSortAsc.SelectedIndex == 0, _searchTextBox.Text);
2023-06-05 08:42:20 +00:00
}
private void TbTitleSearch_Loaded(object sender, RoutedEventArgs e)
{
_searchTextBox = sender as TextBox;
}
2023-06-08 08:46:53 +00:00
private void LsbSortRule_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!AllowChange)
return;
int order = LsbSortRule.SelectedIndex;
bool asc = LsbSortAsc.SelectedIndex == 0;
mw.Set["betterbuy"].SetInt("lastorder", order);
mw.Set["betterbuy"].SetBool("lastasc", asc);
2023-06-08 11:44:41 +00:00
OrderItemSource((Food.FoodType)LsbCategory.SelectedIndex, order, asc, _searchTextBox?.Text);
2023-06-08 08:46:53 +00:00
}
private void WindowX_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
2023-06-08 11:44:41 +00:00
mw.Topmost = mw.Set.TopMost;
2023-06-08 08:46:53 +00:00
e.Cancel = true;
2023-06-08 11:44:41 +00:00
IcCommodity.ItemsSource = null;
2023-06-08 08:46:53 +00:00
Hide();
}
2023-06-01 14:50:40 +00:00
}
}