protected void SetModel(object sender, DependencyPropertyChangedEventArgs e) { _model = this.DataContext as BetTreeNodeModel; if (_model == null) return; MetaList.DataContext = _model.Tree.GetPartials(_model); }
public BetTreeNodeModel AddChild(BetTreeModel tree, BetTreeNodeModel parent) { HoldemHandRound round = parent.Snapshot.NextPlayer == null ? (HoldemHandRound)((int)parent.Snapshot.Round) + 1 : parent.Snapshot.Round; int? player = parent.Snapshot.NextPlayer == null ? parent.Snapshot.GetNextRoundStart() : parent.Snapshot.NextPlayer; BetTreeNodeModel model; switch (round) { case HoldemHandRound.PreFlop: model = AddPreflopStandard(parent, round, (int)player); break; case HoldemHandRound.Flop: case HoldemHandRound.Turn: case HoldemHandRound.River: model = AddPostflopStandard(parent, round, (int)player); break; default: model = AddShowdownStandard(parent); break; } parent.AddChild(model); model.AddNode += tree.OnAddNode; model.EditNode += tree.OnEditNode; model.DeleteNode += tree.OnDeleteNode; model.ShowWizard += tree.OnShowWizard; return model; }
public BetTreeNodeInfoModel(BetTreeNodeModel model, bool manual) { Parent = model; Parent.MetaUpdated += UpdateDisplay; DisplayResultsIndex = model.Tree.Hero; Manual = manual; }
public TreeGridItem() { InitializeComponent(); this.DataContextChanged += SetModel; Model = DataContext as BetTreeNodeModel; _children = new List<TreeGridItem>(); NodeDisplay.OnLayoutUpdated += OnFixLayout; }
public PartialGenerator(TreePartialMeta meta, BetTreeModel tree, BetTreeNodeModel node, BetTreeNodeService service) { this.Meta = meta; this.Wizard = tree.GeneratePartialWizard(meta); this.Tree = tree; this.Node = node; this.Service = service; SetContainer(); }
public BetTreeNodeModel(BetTreeModel tree, BetTreeNodeDisplay display, BetTreeNodeStyle style, HandSnapshotModel snapshot, BetTreeNodeModel parent, bool isDynamic) { this.Tree = tree; this.DisplayModel = display; this.StyleModel = style; this._parentSnapshot = snapshot; this.Snapshot = snapshot; this.Parent = parent; this.IsDynamic = isDynamic; this.Result = new BetTreeNodeResults(snapshot.Stacks.Length); this.Children = new ObservableCollection<BetTreeNodeModel>(); this.CanRemove = IsFixed() ? Visibility.Collapsed : Visibility.Visible; this.Info = new BetTreeNodeInfoModel(this, this.Data is ManualResultsModel); }
public void EditNode(BetTreeNodeModel model) { _activeModel = model; if (_activeModel == null) return; switch (_activeModel.Meta) { case BetTreeNodeService.PREFLOP_NODE_META: case BetTreeNodeService.POSTFLOP_NODE_META: ShowBetRangeEditor(); break; case BetTreeNodeService.RESULT_NODE_META: ShowResultEditor(); break; case BetTreeNodeService.SHOWDOWN_NODE_META: break; } }
public void GetPartialTree(BetTreeNodeModel parent) { if (Meta.Type == TreePartialMetaType.Xml) { TreePartialContainer container = Tree.LoadPartial(Node, Meta); if (container.Root == null) return; List<BetTreeNodeModel> ret = new List<BetTreeNodeModel>(); foreach (BetTreeNodeXml child in container.Root.Children) ret.Add(LoadNode(parent, child)); } else { Wizard.GenerateTree(parent); } }
public PartialVariableListModel LoadVariables(BetTreeNodeModel Node) { int numPlayers = Node.Snapshot.Active.Count(x => x); Variables = new PartialVariableListModel(); ObservableCollection<PartialVariableModel> defs = new ObservableCollection<PartialVariableModel>(); foreach (TreePartialVariableDefinition[] defSet in _variables) { foreach (TreePartialVariableDefinition defSingle in defSet) { PartialVariableModel var = new PartialVariableModel() { Name = defSingle.ID, Variable = defSingle.Variable, Default = defSingle.Default }; ObservableCollection<PartialPlayerValueModel> players = new ObservableCollection<PartialPlayerValueModel>(); for (int i = 0; i < numPlayers; i++) players.Add(new PartialPlayerValueModel() { Index = i }); var.Players = players; defs.Add(var); } } Variables.Definitions = defs; return Variables; }
public void OnShowWizard(BetTreeNodeModel model) { if (ShowWizard != null) ShowWizard(model); }
public void OnDeleteNode(BetTreeNodeModel node) { node.Parent.RemoveChild(node); node.Parent.InvalidateProperty(BetTreeNodeModel.ChildrenProperty); if (this.NodeDeleted != null) NodeDeleted(node); }
public PartialVariableListModel LoadVariables(BetTreeNodeModel node, TreePartialMeta meta) { TreePartialContainer container = LoadPartial(node, meta); PartialVariableListModel variables = container.Variables.GetVariableListModel(); return variables; }
public List<TreePartialMeta> GetPartials(BetTreeNodeModel node) { return Service.GetPartialMeta(node); }
protected void NodeDeleted(BetTreeNodeModel node) { TreeGridItem childDisplay = _items.Find(x => x.DataContext == node); TreeGridItem parentDisplay = _items.Find(x => x.DataContext == node.Parent); bool found = (parentDisplay == null) ? false : RemoveItem(parentDisplay.Children, childDisplay); if (!found) { TreeGridStart start = GetGrid(parentDisplay, StartGrid); RemoveItem(start.MainGrid, childDisplay); } foreach (BetTreeNodeModel child in node.Children) RemoveFromChildCanvases(child, childDisplay); UpdateDimensions(parentDisplay, true); UpdateCanvas(childDisplay.Model.Snapshot.Round); }
/// <summary> /// Updates the visual layout of the tree after a node has been added to the tree model /// </summary> /// <param name="node">The node which has been added</param> /// <returns>The node which has been added</returns> protected BetTreeNodeModel NodeAdded(BetTreeNodeModel node) { //------------------------------------------------------------------------------------- // If there is already a display for this node, then no need to continue here //------------------------------------------------------------------------------------- TreeGridItem nodeDisplay = GetDisplay(node); if (nodeDisplay != null) return node; TreeGridItem parentDisplay = GetDisplay(node.Parent); //------------------------------------------------------------------------------------- // If there is no parent node or the parent node is a different round, then we need // to add the visual component to a round root. Otherwise, we just add the visual // component to it's parent //------------------------------------------------------------------------------------- if (parentDisplay == null || node.Parent.Snapshot.Round != node.Snapshot.Round) { AddRootNode(node, parentDisplay); } else { AddStandardNode(node, parentDisplay); } return node; }
protected void InitialiseNode(BetTreeNodeModel node) { foreach (BetTreeNodeModel child in node.Children) { NodeAdded(child); InitialiseNode(child); } }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <param name="parentDisplay"></param> /// <returns></returns> protected TreeGridStart GetNewGridStart(BetTreeNodeModel node, TreeGridItem parentDisplay) { TreeGridStart start = new TreeGridStart(); start.LinkedItem = parentDisplay; start.LayoutUpdated += this.RefreshCanvas; Canvas canvas = _canvases[node.Snapshot.Round]; canvas.Children.Add(start); _grids[parentDisplay] = start; return start; }
protected void SetModel(object sender, DependencyPropertyChangedEventArgs e) { Model = DataContext as BetTreeNodeModel; if (Model == null) return; }
protected void SetExpanded(BetTreeNodeModel model, bool parentExpanded) { TreeGridItem display = GetDisplay(model); Visibility visibility = parentExpanded ? Visibility.Visible : Visibility.Collapsed ; if (visibility != display.Visibility) { display.Visibility = visibility; UpdateDimensions(display, true); } foreach (BetTreeNodeModel child in model.Children) SetExpanded(child, parentExpanded && model.IsExpanded); }
public TreePartialContainer LoadPartial(BetTreeNodeModel parent, TreePartialMeta meta) { return Service.GetPartialTree(meta); }
public bool HasPartials(BetTreeNodeModel node) { return GetPartials(node).Count > 0; }
private void RemoveFromChildCanvases(BetTreeNodeModel node, TreeGridItem parentDisplay) { TreeGridItem nodeDisplay = _items.Find(x => x.DataContext == node); foreach (BetTreeNodeModel child in node.Children) RemoveFromChildCanvases(child, nodeDisplay); TreeGridStart start = GetGrid(parentDisplay, null); if (start != null) RemoveItem(start.MainGrid, nodeDisplay); }
public void LoadPlayerValues(BetTreeNodeModel node, PartialVariableListModel variables) { List<PlayerModel> activePlayers = new List<PlayerModel>(); int nextPlayer = (int)node.Snapshot.NextPlayer; for (int i = 0; i < node.Snapshot.Active.Length; i++) { int playerIndex = (i + nextPlayer) % node.Snapshot.Active.Length; if (node.Snapshot.Active[playerIndex]) { activePlayers.Add(Table.Seats[playerIndex].Player); } } foreach (PartialVariableModel model in variables.Definitions) { foreach (PartialPlayerValueModel player in model.Players) { player.Player = activePlayers[player.Index]; VariableGroup group = player.Player.Container.Groups.First(x => x.Name == node.Snapshot.Round.ToString()); player.Value = new ValueModel(); player.Value.Value = model.Default; player.Value.Variable = group.Variables.FirstOrDefault(x => x.Name == model.Variable); if (player.Value.Variable == null) player.Value.Value = model.Default; } } }
private void UpdateGridDimensions(BetTreeNodeModel node, TreeGridItem itemDisplay, TreeGridItem parentDisplay) { TreeGridStart grid = GetGrid(parentDisplay, StartGrid); double height = 0, width = 0; for (int i = 0; i < grid.MainGrid.Children.Count; i++) { TreeGridItem child = grid.MainGrid.Children[i] as TreeGridItem; if (child.Visibility == Visibility.Visible) { if (child.Width > width) width = child.Width; height += child.Height; } if (child == itemDisplay) { grid.MainGrid.RowDefinitions[i].Height = new GridLength(child.Height); } } grid.MainGrid.ColumnDefinitions[0].Width = new GridLength(width); grid.Width = width; grid.Height = height; }
public BetTreeNodeModel OnAddNode(BetTreeNodeModel parent) { BetTreeNodeModel child = Service.AddChild(this, parent); parent.InvalidateProperty(BetTreeNodeModel.ChildrenProperty); if (this.NodeAdded != null) NodeAdded(child); return child; }
protected void SetModel(object sender, DependencyPropertyChangedEventArgs e) { Model = this.DataContext as BetTreeNodeModel; }
public void OnEditNode(BetTreeNodeModel node) { if (this.EditNode != null) EditNode(node); }
public void RemoveChild(BetTreeNodeModel model) { this.IsExpanded = true; Children.Remove(model); CanCollapse = this.Children.Count > 0 ? Visibility.Visible : Visibility.Hidden; }
protected BetTreeNodeModel LoadNode(BetTreeNodeModel parent, BetTreeNodeXml node, bool relative) { BetTreeNodeModel ret = Service.AddChild(this, parent); ret.LoadFromXml(node, relative); if (!ret.Snapshot.IsHandEnd) foreach (BetTreeNodeXml child in node.Children) LoadNode(ret, child, relative); return ret; }
public BetTreeNodeModel(BetTreeModel tree, BetTreeNodeDisplay display, BetTreeNodeStyle style, HandSnapshotModel snapshot, BetTreeNodeModel parent) : this(tree, display, style, snapshot, parent, false) { }