private void CheckBox_Checked(object sender, RoutedEventArgs e) { CheckBox check = sender as CheckBox; if (null == sender) { return; } var parent = VisualTreeHelper.GetParent(check); if (null == parent) { return; } var grid = VisualTreeHelper.GetParent(parent); if (null == grid) { return; } var panel = VisualTreeHelper.GetParent(grid); if (null != panel && panel.ToString().Equals(typeof(GoodsPanel).ToString())) { GoodsPanel goods = panel as GoodsPanel; GoodsInfo info = new GoodsInfo(); info.img = source; info.imgUri = imgPath; info.count = 1; info.imageName = imageName; info.name = goods.GoodsName; info.price = goods.Price.Substring(goods.Price.IndexOf('¥') + 1); selectedGoods.Add(check, info); } }
void Initialize() { Tabs = new Dictionary <string, GUIComponent>(); Icons = TextureManager.GetTexture(ContentPaths.GUI.icons); TabButtons = new List <Button>(); GUI = new DwarfGUI(Game, Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Default), Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Title), Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Small), Input) { DebugDraw = false }; IsInitialized = true; Drawer = new Drawer2D(Game.Content, Game.GraphicsDevice); MainWindow = new GUIComponent(GUI, GUI.RootComponent) { LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2) }; Layout = new GridLayout(GUI, MainWindow, 11, 4); Layout.UpdateSizes(); Button back = new Button(GUI, Layout, "Back", GUI.DefaultFont, Button.ButtonMode.ToolButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.LeftArrow)); Layout.SetComponentPosition(back, 0, 10, 1, 1); back.OnClicked += back_OnClicked; Panel tabPanel = new Panel(GUI, Layout); Layout.SetComponentPosition(tabPanel, 0, 0, 4, 1); GridLayout tabLayout = new GridLayout(GUI, tabPanel, 1, 10) { EdgePadding = 10 }; CreateTabButton(tabLayout, "Employees", "Hire and fire dwarves", 5, 0); EmployeeDisplay employeeDisplay = new EmployeeDisplay(GUI, Layout, PlayState.Master.Faction) { IsVisible = false }; Tabs["Employees"] = employeeDisplay; CreateTabButton(tabLayout, "Assets", "Buy/Sell goods", 3, 1); GoodsPanel assetsPanel = new GoodsPanel(GUI, Layout, PlayState.Master.Faction) { IsVisible = false }; Tabs["Assets"] = assetsPanel; CreateTabButton(tabLayout, "Capital", "Financial report", 2, 1); CapitalPanel capitalPanel = new CapitalPanel(GUI, Layout, PlayState.Master.Faction) { IsVisible = false }; Tabs["Capital"] = capitalPanel; ButtonClicked(TabButtons[0]); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { object obj = e.Parameter; if (null != obj) { string path = obj as string; imgPath = path; int index = 0; while (index >= 0) { index = path.IndexOf('\\'); if (index >= 0) { path = path.Substring(index + 1); } } index = path.IndexOf('.'); if (index < 0) { imageName = path; } else { imageName = path.Substring(0, index); } StorageFile file = await StorageFile.GetFileFromPathAsync(imgPath); using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapImage image = new BitmapImage(); image.SetSource(fileStream); source = image; } InkCanvas inkCanvas = new InkCanvas(); inkCanvas.InkPresenter.StrokeContainer.Clear(); var stream = await file.OpenSequentialReadAsync(); if (null != stream) { try { await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream); if (inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Count != 0) { isInkPic = true; } } catch (Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine(ex.Message); #endif isInkPic = false; } } } if (null != source) { ResourceDictionary dic = Application.Current.Resources; IList <ResourceDictionary> dics = dic.MergedDictionaries; ResourceDictionary resource = null; foreach (var item in dics) { if (item.Source.AbsolutePath.Contains("/Files/Styles/Styles.xaml")) { resource = item; break; } } object style = null; if (null != resource) { resource.TryGetValue("CheckBoxStyle", out style); } ImageBrush brush = new ImageBrush(); brush.ImageSource = source; //item 1 GoodsPanel panel1 = new GoodsPanel(); panel1.PictureWith = PicWidth; CheckBox check1 = new CheckBox(); //check1.SetValue(StyleProperty,); check1.Checked += CheckBox_Checked; check1.Unchecked += CheckBox_Unchecked; if ((style as Style) != null) { check1.SetValue(StyleProperty, style); } panel1.Check = check1; panel1.PictureBrush = brush; panel1.GoodsName = "白杯子"; panel1.Price = "¥35"; panel1.PicturePath = imgPath; goodsPanels.Add(0, panel1); panel1.SetValue(RelativePanel.AlignLeftWithPanelProperty, true); panel1.SetValue(RelativePanel.AlignTopWithPanelProperty, true); goodsPanel.Children.Add(panel1); //item 2 GoodsPanel panel2 = new GoodsPanel(); panel2.PictureWith = PicWidth; CheckBox check2 = new CheckBox(); //check1.SetValue(StyleProperty,); check2.Checked += CheckBox_Checked; check2.Unchecked += CheckBox_Unchecked; panel2.Check = check2; if ((style as Style) != null) { check2.SetValue(StyleProperty, style); } panel2.PictureBrush = brush; panel2.GoodsName = "黑杯子"; panel2.Price = "¥35"; panel2.PicturePath = imgPath; goodsPanels.Add(1, panel2); panel2.SetValue(RelativePanel.RightOfProperty, panel1.Name); panel2.SetValue(RelativePanel.AlignTopWithPanelProperty, true); goodsPanel.Children.Add(panel2); //item 3 GoodsPanel panel3 = new GoodsPanel(); panel3.PictureWith = PicWidth; CheckBox check3 = new CheckBox(); //check1.SetValue(StyleProperty,); check3.Checked += CheckBox_Checked; check3.Unchecked += CheckBox_Unchecked; panel3.Check = check3; if ((style as Style) != null) { check3.SetValue(StyleProperty, style); } panel3.PictureBrush = brush; panel3.GoodsName = "白T恤"; panel3.Price = "¥86"; panel3.PicturePath = imgPath; goodsPanels.Add(2, panel3); panel3.SetValue(RelativePanel.RightOfProperty, panel2.Name); panel3.SetValue(RelativePanel.AlignTopWithPanelProperty, true); goodsPanel.Children.Add(panel3); //item 4 GoodsPanel panel4 = new GoodsPanel(); panel4.PictureWith = PicWidth; CheckBox check4 = new CheckBox(); //check1.SetValue(StyleProperty,); check4.Checked += CheckBox_Checked; check4.Unchecked += CheckBox_Unchecked; panel4.Check = check4; if ((style as Style) != null) { check4.SetValue(StyleProperty, style); } panel4.PictureBrush = brush; panel4.GoodsName = "黑T恤"; panel4.Price = "¥86"; panel4.PicturePath = imgPath; goodsPanels.Add(3, panel4); panel4.SetValue(RelativePanel.RightOfProperty, panel3.Name); panel4.SetValue(RelativePanel.AlignTopWithPanelProperty, true); goodsPanel.Children.Add(panel4); ResetPicturePanelPositon(); } }
void Initialize() { Tabs = new Dictionary<string, GUIComponent>(); Icons = TextureManager.GetTexture(ContentPaths.GUI.icons); TabButtons = new List<Button>(); GUI = new DwarfGUI(Game, Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Default), Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Title), Game.Content.Load<SpriteFont>(ContentPaths.Fonts.Small), Input) { DebugDraw = false }; IsInitialized = true; Drawer = new Drawer2D(Game.Content, Game.GraphicsDevice); MainWindow = new GUIComponent(GUI, GUI.RootComponent) { LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2) }; Layout = new GridLayout(GUI, MainWindow, 11, 4); Layout.UpdateSizes(); Button back = new Button(GUI, Layout, "Back", GUI.DefaultFont, Button.ButtonMode.ToolButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.LeftArrow)); Layout.SetComponentPosition(back, 0, 10, 1, 1); back.OnClicked += back_OnClicked; Panel tabPanel = new Panel(GUI, Layout); Layout.SetComponentPosition(tabPanel, 0, 0, 4, 1); GridLayout tabLayout = new GridLayout(GUI, tabPanel, 1, 10) { EdgePadding = 10 }; CreateTabButton(tabLayout, "Employees", "Hire and fire dwarves", 5, 0); EmployeeDisplay employeeDisplay = new EmployeeDisplay(GUI, Layout, PlayState.Master.Faction) { IsVisible = false }; Tabs["Employees"] = employeeDisplay; CreateTabButton(tabLayout, "Assets", "Buy/Sell goods", 3, 1); GoodsPanel assetsPanel = new GoodsPanel(GUI, Layout, PlayState.Master.Faction) { IsVisible = false }; Tabs["Assets"] = assetsPanel; CreateTabButton(tabLayout, "Capital", "Financial report", 2, 1); CapitalPanel capitalPanel = new CapitalPanel(GUI, Layout, PlayState.Master.Faction) { IsVisible = false }; Tabs["Capital"] = capitalPanel; ButtonClicked(TabButtons[0]); }