using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Timers; using Timer = System.Timers.Timer; using Panuon.WPF.UI; using System.Windows.Threading; namespace VPet_Simulator.Core { /// /// ToolBar.xaml 的交互逻辑 /// public partial class ToolBar : UserControl, IDisposable { Main m; public Timer CloseTimer; bool onFocus = false; Timer closePanelTimer; public ToolBar(Main m) { InitializeComponent(); this.m = m; CloseTimer = new Timer() { Interval = 4000, AutoReset = false, Enabled = false }; CloseTimer.Elapsed += Closetimer_Elapsed; closePanelTimer = new Timer(); closePanelTimer.Elapsed += ClosePanelTimer_Tick; m.TimeUIHandle += M_TimeUIHandle; } private void M_TimeUIHandle(Main m) { if (BdrPanel.Visibility == Visibility.Visible) { Tlv.Text = "Lv " + m.Core.Save.Level.ToString(); tMoney.Text = "$ " + m.Core.Save.Money.ToString("N2"); if (m.Core.Controller.EnableFunction) { till.Visibility = m.Core.Save.Mode == GameSave.ModeType.Ill ? Visibility.Visible : Visibility.Collapsed; tfun.Visibility = Visibility.Collapsed; } else { till.Visibility = Visibility.Collapsed; tfun.Visibility = Visibility.Visible; } pExp.Maximum = m.Core.Save.LevelUpNeed(); pExp.Value = m.Core.Save.Exp; pStrength.Value = m.Core.Save.Strength; pFeeling.Value = m.Core.Save.Feeling; pStrengthFood.Value = m.Core.Save.StrengthFood; pStrengthDrink.Value = m.Core.Save.StrengthDrink; tStrength.Text = $"{m.Core.Save.ChangeStrength:f1}/t"; tFeeling.Text = $"{m.Core.Save.ChangeFeeling:f1}/t"; tStrengthDrink.Text = $"{m.Core.Save.ChangeStrengthDrink:f1}/t"; tStrengthFood.Text = $"{m.Core.Save.ChangeStrengthFood:f1}/t"; } } private void ClosePanelTimer_Tick(object sender, EventArgs e) { Dispatcher.Invoke(() => { if (BdrPanel.IsMouseOver || MenuPanel.IsMouseOver) { closePanelTimer.Stop(); return; } BdrPanel.Visibility = Visibility.Collapsed; }); } private void Closetimer_Elapsed(object sender, ElapsedEventArgs e) { if (onFocus) { onFocus = false; CloseTimer.Start(); } else Dispatcher.Invoke(() => this.Visibility = Visibility.Collapsed); } public void Show() { if (m.UIGrid.Children.IndexOf(this) != m.UIGrid.Children.Count - 1) { Panel.SetZIndex(this, m.UIGrid.Children.Count); } Visibility = Visibility.Visible; if (CloseTimer.Enabled) onFocus = true; else CloseTimer.Start(); } private void UserControl_MouseEnter(object sender, MouseEventArgs e) { CloseTimer.Enabled = false; } private void UserControl_MouseLeave(object sender, MouseEventArgs e) { CloseTimer.Start(); } private void MenuPanel_Click(object sender, RoutedEventArgs e) { m.Core.Controller.ShowPanel(); } /// /// 窗口类型 /// public enum MenuType { /// /// 投喂 /// Feed, /// /// 互动 /// Interact, /// /// 自定 /// DIY, /// /// 设置 /// Setting, } /// /// 添加按钮 /// /// 按钮位置 /// 显示名称 /// 功能 public void AddMenuButton(MenuType parentMenu, string displayName, Action clickCallback) { var menuItem = new MenuItem() { Header = displayName, HorizontalContentAlignment = HorizontalAlignment.Center }; menuItem.Click += delegate { clickCallback?.Invoke(); }; switch (parentMenu) { case MenuType.Feed: MenuFeed.Items.Add(menuItem); break; case MenuType.Interact: MenuInteract.Items.Add(menuItem); break; case MenuType.DIY: MenuDIY.Items.Add(menuItem); break; case MenuType.Setting: MenuSetting.Items.Add(menuItem); break; } } private void PgbExperience_GeneratingPercentText(object sender, GeneratingPercentTextRoutedEventArgs e) { e.Text = $"{e.Value} / {pExp.Maximum}"; } private void PgbStrength_GeneratingPercentText(object sender, GeneratingPercentTextRoutedEventArgs e) { e.Text = $"{e.Value} / 100"; } private void PgbSpirit_GeneratingPercentText(object sender, GeneratingPercentTextRoutedEventArgs e) { var progressBar = (ProgressBar)sender; progressBar.Foreground = GetForeground(e.Value); e.Text = $"{e.Value} / 100"; } private void PgbHunger_GeneratingPercentText(object sender, GeneratingPercentTextRoutedEventArgs e) { var progressBar = (ProgressBar)sender; progressBar.Foreground = GetForeground(e.Value); e.Text = $"{e.Value} / 100"; } private void PgbThirsty_GeneratingPercentText(object sender, GeneratingPercentTextRoutedEventArgs e) { var progressBar = (ProgressBar)sender; progressBar.Foreground = GetForeground(e.Value); e.Text = $"{e.Value} / 100"; //if (e.Value <= 20) //{ // tHearth.Visibility = Visibility.Visible; //} } private Brush GetForeground(double value) { if (value >= 80) { return FindResource("SuccessProgressBarForeground") as Brush; } else if (value >= 50) { return FindResource("WarningProgressBarForeground") as Brush; } else { return FindResource("DangerProgressBarForeground") as Brush; } } private void MenuPanel_MouseEnter(object sender, MouseEventArgs e) { BdrPanel.Visibility = Visibility.Visible; M_TimeUIHandle(m); } private void MenuPanel_MouseLeave(object sender, MouseEventArgs e) { closePanelTimer.Start(); } private void MenuDIY_Click(object sender, RoutedEventArgs e) { //m.Say("您好,我是萝莉斯, 让我来帮您熟悉并掌握使用vos系统,成为永世流传的虚拟主播."); } public void Dispose() { m = null; CloseTimer.Dispose(); closePanelTimer.Dispose(); } private void Sleep_Click(object sender, RoutedEventArgs e) { if (m.Core.Save.Mode != GameSave.ModeType.Ill) if (m.State == Main.WorkingState.Sleep) m.Display(GraphCore.GraphType.Sleep_C_End, m.DisplayNomal); else m.DisplaySleep(true); this.Visibility = Visibility.Collapsed; } private void Study_Click(object sender, RoutedEventArgs e) { if (m.Core.Save.Mode != GameSave.ModeType.Ill) if (m.State == Main.WorkingState.Study) m.Display(GraphCore.GraphType.Study_C_End, m.DisplayNomal); else m.DisplayStudy(); this.Visibility = Visibility.Collapsed; } private void Work1_Click(object sender, RoutedEventArgs e) { if (m.Core.Save.Mode != GameSave.ModeType.Ill) if (m.State == Main.WorkingState.WorkONE) m.Display(GraphCore.GraphType.WorkONE_C_End, m.DisplayNomal); else m.DisplayWorkONE(); this.Visibility = Visibility.Collapsed; } private void Work2_Click(object sender, RoutedEventArgs e) { if (m.Core.Save.Mode != GameSave.ModeType.Ill) if (m.State == Main.WorkingState.WorkTWO) m.Display(GraphCore.GraphType.WorkTWO_C_End, m.DisplayNomal); else m.DisplayWorkTWO(); this.Visibility = Visibility.Collapsed; } } }