private void TipViewDesignViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Container")
            {
                UIConfigPath = $"UI\\{config.options.Style.Theme.ThemeName}_{ScreenName}.json";
                Debug.WriteLine("窗口:" + WindowInstance.ActualWidth + ",屏幕:" + ScreenName + ",界面文件:" + UIConfigPath);
                if (Container != null)
                {
                    try
                    {
                        var data = new UIDesignModel();
                        if (FileHelper.Exists(UIConfigPath))
                        {
                            data = JsonConvert.DeserializeObject <UIDesignModel>(FileHelper.Read(UIConfigPath));
                        }
                        else
                        {
                            data = theme.GetCreateDefaultTipWindowUI(config.options.Style.Theme.ThemeName, ScreenName);
                            FileHelper.Write(UIConfigPath, JsonConvert.SerializeObject(data));
                        }
                        Container.SetContainerAttr(data.ContainerAttr);
                        Container.ImportElements(data.Elements);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Warning(ex.ToString());

                        Modal("无法加载现有UI配置文件,系统尝试创建默认UI失败!请尝试重程序。");
                    }
                }
            }
        }
示例#2
0
        private void saveCommand_action(object obj)
        {
            var container = obj as Project1UIDesignContainer;
            var data      = new UIDesignModel();

            data.ContainerAttr = container.GetContainerAttr();
            data.Elements      = container.GetElements();
            string json = JsonConvert.SerializeObject(data);

            FileHelper.Write(UIConfigPath, json);
            MessageBox.Show("更新布局需要重新启动软件才会生效", "提示");
        }
        private void saveCommand_action(object obj)
        {
            var container = obj as Project1UIDesignContainer;
            var data      = new UIDesignModel();

            data.ContainerAttr = container.GetContainerAttr();
            data.Elements      = container.GetElements();
            string json = JsonConvert.SerializeObject(data);

            FileHelper.Write(UIConfigPath, json);

            main.CreateTipWindows();
            Modal("布局已更新");
        }
示例#4
0
        private UIDesignModel GetDefaultUI()
        {
            //创建默认布局
            var data = new UIDesignModel();

            data.ContainerAttr = new ContainerModel()
            {
                Background = Brushes.White,
                Opacity    = .98
            };
            var elements = new List <ElementModel>();
            var tipimage = new ElementModel();

            tipimage.Type    = Project1.UI.Controls.Enums.DesignItemType.Image;
            tipimage.Width   = 272;
            tipimage.Opacity = 1;
            tipimage.Height  = 187;
            tipimage.Image   = $"pack://application:,,,/ProjectEye;component/Resources/Themes/{config.options.Style.Theme.ThemeName}/Images/tipImage.png";
            tipimage.X       = WindowInstance.Width / 2 - tipimage.Width / 2;
            tipimage.Y       = WindowInstance.Height * .24;

            var tipText = new ElementModel();

            tipText.Type      = Project1.UI.Controls.Enums.DesignItemType.Text;
            tipText.Text      = "您已持续用眼{t}分钟,休息一会吧!请将注意力集中在至少6米远的地方20秒!";
            tipText.Opacity   = 1;
            tipText.TextColor = Project1UIColor.Get("#45435b");
            tipText.Width     = 400;
            tipText.Height    = 50;
            tipText.X         = WindowInstance.Width / 2 - tipText.Width / 2;
            tipText.Y         = tipimage.Y + tipimage.Height + tipText.Height + 10;
            tipText.FontSize  = 20;

            var restBtn = new ElementModel();

            restBtn.Type     = Project1.UI.Controls.Enums.DesignItemType.Button;
            restBtn.Width    = 110;
            restBtn.Height   = 45;
            restBtn.FontSize = 14;
            restBtn.Text     = "好的";
            restBtn.Opacity  = 1;
            restBtn.Command  = "rest";

            restBtn.X = WindowInstance.Width / 2 - (restBtn.Width * 2 + 10) / 2;
            restBtn.Y = tipText.Y + tipText.Height + 20;

            var breakBtn = new ElementModel();

            breakBtn.Type     = Project1.UI.Controls.Enums.DesignItemType.Button;
            breakBtn.Width    = 110;
            breakBtn.Height   = 45;
            breakBtn.FontSize = 14;
            breakBtn.Text     = "暂时不";
            breakBtn.Style    = "basic";
            breakBtn.Command  = "break";
            breakBtn.Opacity  = 1;
            breakBtn.X        = WindowInstance.Width / 2 - (restBtn.Width * 2 + 10) / 2 + (restBtn.Width + 10);
            breakBtn.Y        = tipText.Y + tipText.Height + 20;

            var countDownText = new ElementModel();

            countDownText.Text       = "{countdown}";
            countDownText.FontSize   = 50;
            countDownText.IsTextBold = true;
            countDownText.Type       = Project1.UI.Controls.Enums.DesignItemType.Text;
            countDownText.TextColor  = Brushes.Black;
            countDownText.Opacity    = 1;
            countDownText.Width      = 100;
            countDownText.Height     = 60;
            countDownText.X          = WindowInstance.Width / 2 - countDownText.Width / 2;
            countDownText.Y          = restBtn.Y + restBtn.Height;
            elements.Add(tipimage);
            elements.Add(tipText);
            elements.Add(restBtn);
            elements.Add(breakBtn);
            elements.Add(countDownText);


            data.Elements = elements;

            return(data);
        }
示例#5
0
        /// <summary>
        /// 创建默认的提示界面布局UI
        /// </summary>
        /// <param name="themeName">主题名</param>
        /// <param name="screenName">屏幕名称</param>
        /// <returns></returns>
        public UIDesignModel GetCreateDefaultTipWindowUI(
            string themeName,
            string screenName)
        {
            screenName = screenName.Replace("\\", "");

            var screen = System.Windows.Forms.Screen.PrimaryScreen;

            if (screenName != string.Empty)
            {
                foreach (var item in System.Windows.Forms.Screen.AllScreens)
                {
                    string itemScreenName = item.DeviceName.Replace("\\", "");
                    if (itemScreenName == screenName)
                    {
                        screen = item;
                        break;
                    }
                }
            }

            var screenSize = WindowManager.GetSize(screen);

            //创建默认布局
            var data = new UIDesignModel();

            data.ContainerAttr = new ContainerModel()
            {
                Background = Brushes.White,
                Opacity    = .98
            };

            var elements = new List <ElementModel>();
            var tipimage = new ElementModel();

            tipimage.Type    = Project1.UI.Controls.Enums.DesignItemType.Image;
            tipimage.Width   = 272;
            tipimage.Opacity = 1;
            tipimage.Height  = 187;
            tipimage.Image   = $"pack://application:,,,/ProjectEye;component/Resources/Themes/{themeName}/Images/tipImage.png";
            tipimage.X       = screenSize.Width / 2 - tipimage.Width / 2;
            tipimage.Y       = screenSize.Height * .24;

            var tipText = new ElementModel();

            tipText.Type      = Project1.UI.Controls.Enums.DesignItemType.Text;
            tipText.Text      = "您已持续用眼{t}分钟,休息一会吧!请将注意力集中在至少6米远的地方20秒!";
            tipText.Opacity   = 1;
            tipText.TextColor = Project1UIColor.Get("#45435b");
            tipText.Width     = 400;
            tipText.Height    = 50;
            tipText.X         = screenSize.Width / 2 - tipText.Width / 2;
            tipText.Y         = tipimage.Y + tipimage.Height + tipText.Height + 10;
            tipText.FontSize  = 20;

            var restBtn = new ElementModel();

            restBtn.Type     = Project1.UI.Controls.Enums.DesignItemType.Button;
            restBtn.Width    = 110;
            restBtn.Height   = 45;
            restBtn.FontSize = 14;
            restBtn.Text     = "好的";
            restBtn.Opacity  = 1;
            restBtn.Command  = "rest";

            restBtn.X = screenSize.Width / 2 - (restBtn.Width * 2 + 10) / 2;
            restBtn.Y = tipText.Y + tipText.Height + 20;

            var breakBtn = new ElementModel();

            breakBtn.Type     = Project1.UI.Controls.Enums.DesignItemType.Button;
            breakBtn.Width    = 110;
            breakBtn.Height   = 45;
            breakBtn.FontSize = 14;
            breakBtn.Text     = "暂时不";
            breakBtn.Style    = "basic";
            breakBtn.Command  = "break";
            breakBtn.Opacity  = 1;
            breakBtn.X        = screenSize.Width / 2 - (restBtn.Width * 2 + 10) / 2 + (restBtn.Width + 10);
            breakBtn.Y        = tipText.Y + tipText.Height + 20;

            var countDownText = new ElementModel();

            countDownText.Text       = "{countdown}";
            countDownText.FontSize   = 50;
            countDownText.IsTextBold = true;
            countDownText.Type       = Project1.UI.Controls.Enums.DesignItemType.Text;
            countDownText.TextColor  = Brushes.Black;
            countDownText.Opacity    = 1;
            countDownText.Width      = 100;
            countDownText.Height     = 60;
            countDownText.X          = screenSize.Width / 2 - countDownText.Width / 2;
            countDownText.Y          = restBtn.Y + restBtn.Height;



            if (themeName == "Dark")
            {
                //深色主题的样式

                data.ContainerAttr.Background = Project1UIColor.Get("#1A1B1C");
                tipText.TextColor             = Project1UIColor.Get("#D9D9D9");
                countDownText.TextColor       = Project1UIColor.Get("#D9D9D9");
            }
            elements.Add(tipimage);
            elements.Add(tipText);
            elements.Add(restBtn);
            elements.Add(breakBtn);
            elements.Add(countDownText);


            data.Elements = elements;

            return(data);
        }