private GraphicInstance CreateGraphicVisualizedInstance(Type type, LogicalInstance logicalInstance, DragEventArgs args) { Point position = args.GetPosition(this); double width = (double)type.GetProperty("Width").GetValue(Activator.CreateInstance(type), null); double height = (double)type.GetProperty("Height").GetValue(Activator.CreateInstance(type), null); GraphicInstance graphicInstance = null; if (type.IsSubclassOf(typeof(NodeType))) { ParentableInstance parent = (this.Content as CanvasItemsControl).FindParent(position, graphicInstance); graphicInstance = new NodeInstance { X = position.X, Y = position.Y, Width = (width != 0 && !double.IsNaN(width)) ? width : 200, Height = (height != 0 && !double.IsNaN(height)) ? height : 200, LogicalInstance = logicalInstance, Parent = parent }; } else { graphicInstance = new EdgeInstance { X = position.X, Y = position.Y, Width = (width != 0 && !double.IsNaN(width)) ? width : 200, Height = (height != 0 && !double.IsNaN(height)) ? height : 200, LogicalInstance = logicalInstance, Parent = InstancesManager.Instance.CanvasRootElement }; } return(graphicInstance); }
// Update the meshes to correct UVs depending on the property lookingAt (direction from human.movement) public void UpdateLookingAt(Direction dir) { this.bodyGraphic = GraphicInstance.GetNew( this.human.def.graphics, Defs.colorPallets["human_body"].colors[this.skinData.bodyColorID], Res.textures["Body_" + (this.skinData.bodyID).ToString()], 0, MeshPool.GetHumanPlaneMesh(this.size, dir) ); this.headGraphic = GraphicInstance.GetNew( this.human.def.graphics, Defs.colorPallets["human_body"].colors[this.skinData.bodyColorID], Res.textures["Head_" + (this.skinData.headID).ToString()], 1, MeshPool.GetHumanPlaneMesh(this.size, dir) ); this.eyesGraphic = GraphicInstance.GetNew( this.human.def.graphics, Color.white, Res.textures["Eye_" + (this.skinData.eyeID).ToString()], 2, MeshPool.GetHumanPlaneMesh(this.size, dir) ); this.hairGraphic = GraphicInstance.GetNew( this.human.def.graphics, Defs.colorPallets["human_hair"].colors[this.skinData.hairColorID], Res.textures["Hair_" + (this.skinData.hairID).ToString()], 3, MeshPool.GetHumanPlaneMesh(this.size, dir) ); }
private void ContentPresenterLoaded(object sender, RoutedEventArgs e) { ContentPresenter contentPresenter = sender as ContentPresenter; GraphicInstance graphicInstance = contentPresenter.Content as GraphicInstance; LogicalInstance logicalInstance = graphicInstance.LogicalInstance; TypesManager.Instance.InitProperties(logicalInstance); Canvas itemsCanvas = VisualTreeHelper.GetChild(contentPresenter, 0) as Canvas; ObjectType objectType = VisualTreeHelper.GetChild(itemsCanvas, 0) as ObjectType; SetPropertyBindings(logicalInstance, objectType); objectType.Clicked += new ClickHandler(ObjectTypeClicked); Binding bindingSelected = new Binding { Mode = BindingMode.TwoWay, Path = new PropertyPath("SelectedGraphicInstance"), Source = UIManager.Instance, Converter = new IdToSelectedConverter(objectType) }; objectType.SetBinding(ObjectType.SelectedProperty, bindingSelected); objectType.ZIndexChanged += new ZIndexChangedHandler(ObjectTypeZIndexChanged); objectType.MouseLeftButtonUp += ObjectTypeMouseLeftButtonUp; SetContextMenu(objectType); }
public Building(Vector2Int position, TilableDef def) { this.position = position; this.def = def; this.recipe = new Recipe(this.def.recipeDef, this, position); this.work = 0; if (this.def.type == TilableType.BuildingConnected) { this.mainGraphic = GraphicInstance.GetNew( this.def.graphics, new Color(112 / 255f, 78 / 255f, 46 / 255f, .5f), // update alpha when constructed Res.textures[this.def.graphics.textureName + "_0"], 1 ); this._connectedUtility = new ConnectedTilable(this); } this.addGraphics = new Dictionary <string, GraphicInstance>(); Tilable tilable = Loki.map.grids[Layer.Plant].GetTilableAt(this.position); if (tilable != null && tilable.def.cuttable) { tilable.AddOrder(Defs.orders["cut_plants"]); } }
public void DeleteInstance(GraphicInstance graphicInstance) { RecursiveDeleteInstance(graphicInstance); InstancesContext.SubmitChanges(); if (graphicInstance is RootInstance) { SetCanvasRootItem(null); } }
private void DeleteGraphicInstance(GraphicInstance graphicInstance) { LogicalInstance logicalInstance = graphicInstance.LogicalInstance; InstancesContext.GraphicInstances.Remove(graphicInstance); if (!graphicInstance.LogicalInstance.GraphicInstances.Any()) { InstancesContext.LogicalInstances.Remove(logicalInstance); } }
public Stackable(Vector2Int position, TilableDef def, int count) { this.position = position; this.def = def; this.inventory = new InventoryTilable(this, count); this.position = position; this.def = def; this.mainGraphic = GraphicInstance.GetNew(this.def.graphics); Loki.stackableLabelController.AddLabel(this); }
private void LayoutRoot_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { GraphicInstance selectedGraphicInstance = UIManager.Instance.SelectedGraphicInstance; if (selectedGraphicInstance != null) { InstancesManager.Instance.DeleteInstance(selectedGraphicInstance); } } }
public Mountain(Vector2Int position, TilableDef def) { this.position = position; this.def = def; this._connectedUtility = new ConnectedTilable(this); this.mainGraphic = GraphicInstance.GetNew( this.def.graphics, default(Color), Res.textures[this.def.graphics.textureName + "_0"], 1 ); this.addGraphics = new Dictionary <string, GraphicInstance>(); }
public Stackable(Vector2Int position, StockArea area) { this.position = position; this.def = Defs.empty; this.area = area; this.inventory = null; this.mainGraphic = GraphicInstance.GetNew( this.def.graphics, this.area.color, Res.TextureUnicolor(this.area.color), 1 ); }
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); GraphicInstance graphicInstance = item as GraphicInstance; ContentPresenter contentPresenter = element as ContentPresenter; LogicalInstance logicalInstance = graphicInstance.LogicalInstance; if (logicalInstance != null) { contentPresenter.ContentTemplate = Create(TypesManager.Instance.GetType(logicalInstance.Type)); } contentPresenter.Loaded += new RoutedEventHandler(ContentPresenterLoaded); }
public virtual void UpdateOrderGraphics() { if (!this.addGraphics.ContainsKey(this.currentOrder.name)) { this.addGraphics.Add(this.currentOrder.name, GraphicInstance.GetNew( this.currentOrder.graphics, Color.white, Res.textures[this.currentOrder.graphics.textureName], 42 ) ); } }
public void Construct() { this.mainGraphic = GraphicInstance.GetNew( this.def.graphics, new Color(112 / 255f, 78 / 255f, 46 / 255f, 1f), this.mainGraphic.texture, 1 ); this.UpdateGraphics(); if (this.bucket != null) { this.bucket.rebuildMatrices = true; } }
public void WorkDirt() { this.dirt = true; this.addGraphics["dirt"] = GraphicInstance.GetNew( this.def.graphics, Color.white, Res.textures["dirt_ready"], 2 ); if (this.bucket != null) { this.bucket.rebuildMatrices = true; } }
public BaseCharacter(Vector2Int position, LivingDef def) { this.stats = new CharacterStats(); this.def = def; this.movement = new CharacterMovement(position, this); this.brain = new CharacterBrain(this, this.GetBrainNode()); this.name = this.SetName(); if (this.def.graphics != null && this.def.graphics.textureName != string.Empty) // @TODO: do this but better. { this.graphics = GraphicInstance.GetNew(this.def.graphics); } Loki.tick.toAdd.Enqueue(this.Update); }
public ParentableInstance FindParent(Point position, GraphicInstance instance) { foreach (var item in this.Items) { NodeInstance nodeInstance = item as NodeInstance; if ((nodeInstance == null) || (nodeInstance == instance)) { continue; } Rect itemBoundingRect = new Rect(nodeInstance.X, nodeInstance.Y, nodeInstance.Width, nodeInstance.Height); if (itemBoundingRect.Contains(position)) { return(nodeInstance); } } return(InstancesManager.Instance.CanvasRootElement); }
public override void UpdateGraphics() { if (this.def.type == TilableType.Grass) // If we are a grass { this._leafColor = Defs.colorPallets["cols_leafsGreen"].GetRandom(); this.mainGraphic = GraphicInstance.GetNew(def.graphics, this._leafColor); } else if (this.def.type == TilableType.Tree) // If we are groot { this._leafColor = Defs.colorPallets["cols_leafsGreen"].GetRandom(); this._woodColor = Defs.colorPallets["cols_wood"].colors[0]; this.mainGraphic = GraphicInstance.GetNew( def.graphics, this._woodColor, Res.textures[this.def.graphics.textureName + "_base"], 1 ); if (this.addGraphics.ContainsKey("leafs")) { this.addGraphics["leafs"] = GraphicInstance.GetNew( def.graphics, this._leafColor, Res.textures[this.def.graphics.textureName + "_leafs"], 2 ); } else { this.addGraphics.Add("leafs", GraphicInstance.GetNew( def.graphics, this._leafColor, Res.textures[this.def.graphics.textureName + "_leafs"], 2 ) ); } } else // Standard graphics no coloring or override. { this.mainGraphic = GraphicInstance.GetNew(def.graphics); } }
private void CreateItem(DragEventArgs args, Type type, LogicalInstance logicalInstance) { GraphicInstance graphicInstance = null; if (InstancesManager.Instance.CanvasRootElement == null) { graphicInstance = new RootInstance { LogicalInstance = logicalInstance }; } else { graphicInstance = CreateGraphicVisualizedInstance(type, logicalInstance, args); } InstancesManager.Instance.InstancesContext.GraphicInstances.Add(graphicInstance); InstancesManager.Instance.AddInstance(graphicInstance); InstancesManager.Instance.InstancesContext.SubmitChanges(); }
private void ObjectTypeMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { GraphicInstance dataContext = (sender as ObjectType).DataContext as GraphicInstance; if (dataContext is NodeInstance) { Point position = e.GetPosition(this); ParentableInstance parent = FindParent(position, dataContext); ((sender as ObjectType).DataContext as NodeInstance).Parent = parent; if (parent is NodeInstance) { Point positionInParent = new Point((dataContext as NodeInstance).X - (parent as NodeInstance).X, (dataContext as NodeInstance).Y - (parent as NodeInstance).Y); (parent as NodeInstance).Width = Math.Max(positionInParent.X + (dataContext as NodeInstance).Width + 5, (parent as NodeInstance).Width); (parent as NodeInstance).Height = Math.Max(positionInParent.Y + (dataContext as NodeInstance).Height + 5, (parent as NodeInstance).Height); } } }
public RootInstance GetRootParent(GraphicInstance graphicInstance) { if (graphicInstance == null) { return(null); } else if (graphicInstance is RootInstance) { return(graphicInstance as RootInstance); } else if (graphicInstance is EdgeInstance) { return((graphicInstance as EdgeInstance).Parent); } else { return(GetRootParent((graphicInstance as NodeInstance).Parent)); } }
public void AddInstance(GraphicInstance graphicInstance) { if (graphicInstance is RootInstance) { if (!RootInstances.Contains(graphicInstance as RootInstance)) { RootInstances.Add(graphicInstance as RootInstance); if (CanvasRootElement == graphicInstance) { UpdateCanvasInstancesSource(); } } } else { if (CanvasRootElement != null && CanvasRootElement == GetRootParent(graphicInstance) && !CanvasInstancesSource.Contains(graphicInstance)) { CanvasInstancesSource.Add(graphicInstance); } } }
private void RecursiveDeleteInstance(GraphicInstance graphicInstance) { if (graphicInstance is ParentableInstance) { while ((graphicInstance as ParentableInstance).Children.Any()) { RecursiveDeleteInstance((graphicInstance as ParentableInstance).Children.First()); } } if (graphicInstance is NodeInstance) { foreach (var edgeFrom in (graphicInstance as NodeInstance).EdgesFrom) { DeleteGraphicInstance(edgeFrom); } foreach (var edgeTo in (graphicInstance as NodeInstance).EdgesTo) { DeleteGraphicInstance(edgeTo); } } DeleteGraphicInstance(graphicInstance); }
public Field(Vector2Int position, TilableDef def, GrowArea area) { this.addGraphics = new Dictionary <string, GraphicInstance>(); this.area = area; this.dirt = false; this.position = position; this.def = def; this.mainGraphic = GraphicInstance.GetNew( this.def.graphics, this.area.color, Res.TextureUnicolor(this.area.color), 1 ); this.addGraphics.Add("dirt", GraphicInstance.GetNew( this.def.graphics, Color.white, Res.TextureUnicolor(Color.clear), 2 ) ); }
public Stackable(Vector2Int position, TilableDef def, int count) { this.position = position; this.def = def; this.inventory = new Inventory(this, count); this.mainGraphic = GraphicInstance.GetNew(this.def.graphics); this.area = null; this.SetNeigbours(); Loki.stackableLabelController.AddLabel(this); if (count > 0) { WorldUtils.AddStackable(def, this); } this.inventory.OnClear += delegate { WorldUtils.ClearStackable(this.inventory.def, this); }; this.inventory.OnAdd += delegate { WorldUtils.AddStackable(this.inventory.def, this); }; this.inventory.OnChangeCount += delegate(int change) { WorldUtils.UpdateStackableCount(this.inventory.def, change); }; }
public Ground(Vector2Int position, TilableDef def) { this.position = position; this.def = def; this.mainGraphic = GraphicInstance.GetNew(def.graphics); }
public void SetCanvasRootItem(GraphicInstance selectedGraphicInstance) { CanvasRootElement = GetRootParent(selectedGraphicInstance); }
/// Update this.tilable graphics according to the tilable connections. public void UpdateGraphics() { int connsInt = 0; this.SetLinks(); int i = 0; foreach (int direction in DirectionUtils.cardinals) { if (this.connections[direction]) { connsInt += DirectionUtils.connections[i]; } i++; } // Check if we need a roof or basicly checks corners here. i = 0; this.allCorners = true; bool hasCorner = false; foreach (int direction in DirectionUtils.corners) { if ( (i != 0 || this.connections[direction] && (this.connections[(int)Direction.W] && this.connections[(int)Direction.S])) && (i != 1 || this.connections[direction] && (this.connections[(int)Direction.W] && this.connections[(int)Direction.N])) && (i != 2 || this.connections[direction] && (this.connections[(int)Direction.E] && this.connections[(int)Direction.N])) && (i != 3 || this.connections[direction] && (this.connections[(int)Direction.E] && this.connections[(int)Direction.S])) ) { this.corners[i] = true; hasCorner = true; } else { this.corners[i] = false; this.allCorners = false; } i++; } if (connsInt != this.connectionsInt) { this.connectionsInt = connsInt; if (this.allCorners) { this.tilable.mainGraphic = GraphicInstance.GetNew( this.tilable.def.graphics, default(Color), Res.textures[this.tilable.def.graphics.textureName + "_cover"], 1 ); Loki.map.GetTilableAt(this.tilable.position, Layer.Ground).hidden = true; } else { this.tilable.mainGraphic = GraphicInstance.GetNew( this.tilable.def.graphics, default(Color), Res.textures[this.tilable.def.graphics.textureName + "_" + this.connectionsInt.ToString()], 1 ); if (hasCorner) { this.tilable.addGraphics.Add("cover", GraphicInstance.GetNew( this.tilable.def.graphics, default(Color), Res.textures[this.tilable.def.graphics.textureName + "_cover"], 2, MeshPool.GetCornersPlane(this.corners) ) ); } Loki.map.GetTilableAt(this.tilable.position, Layer.Ground).hidden = false; } } }
private static void DeleteMenuItemItemClick(object sender, RoutedEventArgs e) { GraphicInstance graphicInstance = ((sender as MenuItem).DataContext as GraphicInstance); InstancesManager.Instance.DeleteInstance(graphicInstance); }