/** * This method does a recursive check of whether there are any repeat guesses * in the element or its subtree. This is a necessary step when initializing * the model to be able to identify whether new repeats can be used. * * @param parent The form element to begin checking * @return true if the element or any of its descendants is a repeat * which has a count guess, false otherwise. */ private Boolean containsRepeatGuesses(IFormElement parent) { if (parent is GroupDef) { GroupDef g = (GroupDef)parent; if (g.Repeat && g.CountReference != null) { return(true); } } List <IFormElement> children = parent.Children; if (children == null) { return(false); } for (IEnumerator en = children.GetEnumerator(); en.MoveNext();) { if (containsRepeatGuesses((IFormElement)en.Current)) { return(true); } } return(false); }
protected virtual List <Control> CreateCardMenuItems(GroupDef def) { int nCardActions = def.CardActions == null ? 0 : def.CardActions.Length; var items = new List <Control>(); if (nCardActions > 0 || group.Controller == null) { _cardHeader = new MenuItem(); _cardHeader.SetResourceReference(StyleProperty, "MenuHeader"); items.Add(_cardHeader); } if (nCardActions > 0) { for (int i = 0; i < nCardActions; i++) { if (def.CardActions != null) { items.Add(CreateCardMenuItem(def.CardActions[i])); } } if (group.Controller == null) { items.Add(new Separator()); } } if (group.Controller == null) { items.Add(CreateCardPassToItem()); } return(items); }
/// <summary> This method does a recursive check of whether there are any repeat guesses /// in the element or its subtree. This is a necessary step when initializing /// the model to be able to identify whether new repeats can be used. /// /// </summary> /// <param name="parent">The form element to begin checking /// </param> /// <returns> true if the element or any of its descendants is a repeat /// which has a count guess, false otherwise. /// </returns> private bool containsRepeatGuesses(IFormElement parent) { if (parent is GroupDef) { GroupDef g = (GroupDef)parent; if (g.Repeat && g.CountReference != null) { return(true); } } if (children == null) { return(false); } //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'" for (System.Collections.IEnumerator en = children.elements(); en.MoveNext();) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'" if (containsRepeatGuesses((IFormElement)en.Current)) { return(true); } } return(false); }
private void GameOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) { if (propertyChangedEventArgs.PropertyName == "IsTableBackgroundFlipped") { GroupDef tableDef = Program.Game.Definition.TableDefinition; this.SetBackground(tableDef); } }
internal Group(Player owner, GroupDef def) : base(owner) { Def = def; ResetVisibility(); GroupShortcuts = CreateShortcuts(def.GroupActions); CardShortcuts = CreateShortcuts(def.CardActions); if (def.Shortcut != null) { MoveToShortcut = (KeyGesture)KeyConverter.ConvertFromInvariantString(def.Shortcut); } }
public TableControl() { InitializeComponent(); if (DesignerProperties.GetIsInDesignMode(this)) { return; } GroupDef tableDef = Program.Game.Definition.TableDefinition; if (tableDef.Background != null) { SetBackground(tableDef); } if (!Program.GameSettings.HideBoard) { if (tableDef.Board != null) { SetBoard(tableDef); } } if (!Program.GameSettings.UseTwoSidedTable) { middleLine.Visibility = Visibility.Collapsed; } if (Player.LocalPlayer.InvertedTable) { transforms.Children.Insert(0, new ScaleTransform(-1, -1)); } _defaultWidth = Program.Game.Definition.CardDefinition.Width; _defaultHeight = Program.Game.Definition.CardDefinition.Height; SizeChanged += delegate { IsCardSizeValid = false; AspectRatioChanged(); }; MoveCard.Done += CardMoved; CreateCard.Done += CardCreated; Unloaded += delegate { MoveCard.Done -= CardMoved; CreateCard.Done -= CardCreated; }; Loaded += delegate { CenterView(); }; Program.Game.PropertyChanged += GameOnPropertyChanged; }
private void SetBoard(GroupDef tableDef) { Rect pos = tableDef.BoardPosition; var img = new Image { Source = ExtensionMethods.BitmapFromUri(new Uri(tableDef.Board)), Width = pos.Width, Height = pos.Height, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(pos.Left, pos.Top, 0, 0) }; boardContainer.Children.Insert(0, img); }
private void CreateContextMenus() { _cardHeader = null; _defaultGroupAction = _defaultCardAction = null; GroupDef def = group.Definition; // Create the card actions List <Control> cardItems = CreateCardMenuItems(def); _cardMenu.Collection = cardItems; // Create the group actions List <Control> groupItems = CreateGroupMenuItems(def); _groupMenu.Collection = groupItems; }
public List <String> getRepetitionsText() { GroupDef g = (GroupDef)element; if (!g.Repeat) { throw new SystemException("not a repeat"); } int numRepetitions = getNumRepetitions(); List <String> reps = new List <String>(); for (int i = 0; i < numRepetitions; i++) { reps.Add(getRepetitionText("choose", form.descendIntoRepeat(index, i), false)); } return(reps); }
private void InitBlock() { GroupDef g = (GroupDef)element; if (!g.Repeat) { throw new System.SystemException("not a repeat"); } int numRepetitions = NumRepetitions; List <String> reps = new List <String>(); for (int i = 0; i < numRepetitions; i++) { reps.addElement(getRepetitionText("choose", form.descendIntoRepeat(index, i), false)); } return(reps); }
protected virtual List <Control> CreateGroupMenuItems(GroupDef def) { int nGroupActions = def.GroupActions == null ? 0 : def.GroupActions.Length; var items = new List <Control> { CreateGroupHeader() }; for (int i = 0; i < nGroupActions; i++) { if (def.GroupActions != null) { items.Add(CreateGroupMenuItem(def.GroupActions[i])); } } if (nGroupActions > 0) { items.Add(new Separator()); } if (group.Controller != null) { items.Add(CreateGroupPassToItem()); } if (group.Visibility != GroupVisibility.Undefined) { items.Add(CreateVisibilityItem()); } MenuItem item = CreateLookAtCardsMenuItem(); if (item != null) { items.Add(item); } if (items.Last() is Separator) { items.RemoveAt(items.Count - 1); } return(items); }
private System.String getRepetitionText(System.String type, FormIndex index, bool newrep) { if (element is GroupDef && ((GroupDef)element).Repeat && index.ElementMultiplicity >= 0) { GroupDef g = (GroupDef)element; System.String title = LongText; int ix = index.ElementMultiplicity + 1; int count = NumRepetitions; System.String caption = null; if ("header".Equals(type)) { caption = g.entryHeader; } else if ("choose".Equals(type)) { caption = g.chooseCaption; if (caption == null) { caption = g.entryHeader; } } if (caption == null) { return(title + " " + ix + "/" + count); } HashMap <String, Object> vars = new HashMap <String, Object>(); vars.put("name", title); vars.put("i", (System.Int32)ix); vars.put("n", (System.Int32)count); vars.put("new", newrep); return(form.fillTemplateString(caption, index.Reference, vars)); } else { return(null); } }
private String getRepetitionText(String type, FormIndex index, Boolean newrep) { if (element is GroupDef && ((GroupDef)element).Repeat && index.getElementMultiplicity() >= 0) { GroupDef g = (GroupDef)element; String title = getLongText(); int ix = index.getElementMultiplicity() + 1; int count = getNumRepetitions(); String caption = null; if ("header".Equals(type)) { caption = g.entryHeader; } else if ("choose".Equals(type)) { caption = g.chooseCaption; if (caption == null) { caption = g.entryHeader; } } if (caption == null) { return(title + " " + ix + "/" + count); } IDictionary <String, Object> vars = new Dictionary <String, Object>(); vars.Add("name", title); vars.Add("i", ix); vars.Add("n", count); vars.Add("new", newrep); return(form.fillTemplateString(caption, index.getReference(), vars)); } else { return(null); } }
private void SetBackground(GroupDef tableDef) { var bim = new BitmapImage(); bim.BeginInit(); bim.CacheOption = BitmapCacheOption.OnLoad; bim.UriSource = new Uri(tableDef.Background); if (Program.Game.IsTableBackgroundFlipped) { bim.Rotation = Rotation.Rotate180; } bim.EndInit(); var backBrush = new ImageBrush(bim); if (tableDef.BackgroundStyle != null) { switch (tableDef.BackgroundStyle) { case "tile": backBrush.TileMode = TileMode.Tile; backBrush.Viewport = new Rect(0, 0, backBrush.ImageSource.Width, backBrush.ImageSource.Height); backBrush.ViewportUnits = BrushMappingMode.Absolute; break; case "uniform": backBrush.Stretch = Stretch.Uniform; break; case "uniformToFill": backBrush.Stretch = Stretch.UniformToFill; break; case "stretch": backBrush.Stretch = Stretch.Fill; break; } } Background = backBrush; }
/// <summary> For the current index: Checks whether the index represents a node which /// should exist given a non-interactive repeat, along with a count for that /// repeat which is beneath the dynamic level specified. /// /// If this index does represent such a node, the new model for the repeat is /// created behind the scenes and the index for the initial question is /// returned. /// /// Note: This method will not prevent the addition of new repeat elements in /// the interface, it will merely use the xforms repeat hint to create new /// nodes that are assumed to exist /// /// </summary> /// <param name="index">The index to be evaluated as to whether the underlying model is /// hinted to exist /// </param> private void createModelIfNecessary(FormIndex index) { if (index.InForm) { IFormElement e = Form.getChild(index); if (e is GroupDef) { GroupDef g = (GroupDef)e; if (g.Repeat && g.CountReference != null) { // Lu Gram: repeat count XPath needs to be contextualized for nested repeat groups TreeReference countRef = FormInstance.unpackReference(g.CountReference); TreeReference contextualized = countRef.contextualize(index.Reference); IAnswerData count = Form.MainInstance.resolveReference(contextualized).getValue(); if (count != null) { long fullcount = ((System.Int32)count.Value); TreeReference ref_Renamed = Form.getChildInstanceRef(index); TreeElement element = Form.MainInstance.resolveReference(ref_Renamed); if (element == null) { if (index.getTerminal().InstanceIndex < fullcount) { try { Form.createNewRepeat(index); } catch (InvalidReferenceException ire) { SupportClass.WriteStackTrace(ire, Console.Error); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.SystemException("Invalid Reference while creting new repeat!" + ire.Message); } } } } } } } }
/** * For the current index: Checks whether the index represents a node which * should exist given a non-interactive repeat, along with a count for that * repeat which is beneath the dynamic level specified. * * If this index does represent such a node, the new model for the repeat is * created behind the scenes and the index for the initial question is * returned. * * Note: This method will not prevent the addition of new repeat elements in * the interface, it will merely use the xforms repeat hint to create new * nodes that are assumed to exist * * @param The index to be evaluated as to whether the underlying model is * hinted to exist */ private void createModelIfNecessary(FormIndex index) { if (index.isInForm()) { IFormElement e = getForm().getChild(index); if (e is GroupDef) { GroupDef g = (GroupDef)e; if (g.Repeat && g.CountReference != null) { IAnswerData count = getForm().Instance.getDataValue(g.CountReference); if (count != null) { long fullcount = ((int)count.Value); TreeReference ref_ = getForm().getChildInstanceRef(index); TreeElement element = getForm().Instance.resolveReference(ref_); if (element == null) { if (index.getInstanceIndex() < fullcount) { try { getForm().createNewRepeat(index); } catch (InvalidReferenceException ire) { Console.WriteLine(ire.StackTrace); throw new SystemException("Invalid Reference while creting new repeat!" + ire.Message); } } } } } } } }
public Hand(Player owner, GroupDef def) : base(owner, def) { }
//TODO: this is explicitly missing integration with the new multi-media support //TODO: localize the default captions public virtual System.String getRepeatText(System.String typeKey) { GroupDef g = (GroupDef)element; if (!g.Repeat) { throw new System.SystemException("not a repeat"); } System.String title = LongText; int count = NumRepetitions; System.String caption = null; if ("mainheader".Equals(typeKey)) { caption = g.mainHeader; if (caption == null) { return(title); } } else if ("add".Equals(typeKey)) { caption = g.addCaption; if (caption == null) { return("Add another " + title); } } else if ("add-empty".Equals(typeKey)) { caption = g.addEmptyCaption; if (caption == null) { caption = g.addCaption; } if (caption == null) { return("None - Add " + title); } } else if ("del".Equals(typeKey)) { caption = g.delCaption; if (caption == null) { return("Delete " + title); } } else if ("done".Equals(typeKey)) { caption = g.doneCaption; if (caption == null) { return("Done"); } } else if ("done-empty".Equals(typeKey)) { caption = g.doneEmptyCaption; if (caption == null) { caption = g.doneCaption; } if (caption == null) { return("Skip"); } } else if ("delheader".Equals(typeKey)) { caption = g.delHeader; if (caption == null) { return("Delete which " + title + "?"); } } HashMap <String, Object> vars = new HashMap <String, Object>(); vars.put("name", title); vars.put("n", (System.Int32)count); return(form.fillTemplateString(caption, index.Reference, vars)); }
//TODO: this is explicitly missing integration with the new multi-media support //TODO: localize the default captions public String getRepeatText(String typeKey) { GroupDef g = (GroupDef)element; if (!g.Repeat) { throw new SystemException("not a repeat"); } String title = getLongText(); int count = getNumRepetitions(); String caption = null; if ("mainheader".Equals(typeKey)) { caption = g.mainHeader; if (caption == null) { return(title); } } else if ("add".Equals(typeKey)) { caption = g.addCaption; if (caption == null) { return("Add another " + title); } } else if ("add-empty".Equals(typeKey)) { caption = g.addEmptyCaption; if (caption == null) { caption = g.addCaption; } if (caption == null) { return("None - Add " + title); } } else if ("del".Equals(typeKey)) { caption = g.delCaption; if (caption == null) { return("Delete " + title); } } else if ("done".Equals(typeKey)) { caption = g.doneCaption; if (caption == null) { return("Done"); } } else if ("done-empty".Equals(typeKey)) { caption = g.doneEmptyCaption; if (caption == null) { caption = g.doneCaption; } if (caption == null) { return("Skip"); } } else if ("delheader".Equals(typeKey)) { caption = g.delHeader; if (caption == null) { return("Delete which " + title + "?"); } } IDictionary <String, Object> vars = new Dictionary <String, Object>(); vars.Add("name", title); vars.Add("n", count); return(form.fillTemplateString(caption, index.getReference(), vars)); }
private void incrementHelper(ArrayList indexes, ArrayList multiplicities, ArrayList elements, Boolean descend) { int i = indexes.Count - 1; Boolean exitRepeat = false; //if exiting a repetition? (i.e., go to next repetition instead of one level up) if (i == -1 || elements[i] is GroupDef) { // current index is group or repeat or the top-level form if (i >= 0) { // find out whether we're on a repeat, and if so, whether the // specified instance actually exists GroupDef group = (GroupDef)elements[i]; if (group.Repeat) { if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR) { if (((System.Int32)multiplicities[multiplicities.Count - 1]) == TreeReference.INDEX_REPEAT_JUNCTURE) { descend = false; exitRepeat = true; } } else { if (form.Instance.resolveReference(form.getChildInstanceRef(elements, multiplicities)) == null) { descend = false; // repeat instance does not exist; do not descend into it exitRepeat = true; } } } } if (descend) { indexes.Add(0); multiplicities.Add(0); elements.Add((i == -1 ? form : (IFormElement)elements[i]).getChild(0)); if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR) { if (elements[elements.Count - 1] is GroupDef && ((GroupDef)elements[elements.Count - 1]).Repeat) { multiplicities[multiplicities.Count - 1] = (System.Int32)TreeReference.INDEX_REPEAT_JUNCTURE; } } return; } } while (i >= 0) { // if on repeat, increment to next repeat EXCEPT when we're on a // repeat instance that does not exist and was not created // (repeat-not-existing can only happen at lowest level; exitRepeat // will be true) if (!exitRepeat && elements[i] is GroupDef && ((GroupDef)elements[i]).Repeat) { if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR) { multiplicities[i] = (System.Int32)TreeReference.INDEX_REPEAT_JUNCTURE; } else { multiplicities[i] = (System.Int32)(((System.Int32)multiplicities[i]) + 1); } return; } IFormElement parent = (i == 0 ? form : (IFormElement)elements[i - 1]); int curIndex = ((System.Int32)indexes[i]); // increment to the next element on the current level if (curIndex + 1 >= parent.Children.Count) { // at the end of the current level; move up one level and start // over indexes.RemoveAt(i); multiplicities.RemoveAt(i); elements.RemoveAt(i); i--; exitRepeat = false; } else { indexes[i] = (System.Int32)(curIndex + 1); multiplicities[i] = 0; elements[i] = parent.getChild(curIndex + 1); if (repeatStructure == REPEAT_STRUCTURE_NON_LINEAR) { if (elements[elements.Count - 1] is GroupDef && ((GroupDef)elements[elements.Count - 1]).Repeat) { multiplicities[multiplicities.Count - 1] = (System.Int32)TreeReference.INDEX_REPEAT_JUNCTURE; } } return; } } }
internal Pile(Player owner, GroupDef def) : base(owner, def) { _collapsed = def.Collapsed; }
protected override List <Control> CreateCardMenuItems(GroupDef def) { List <Control> items = base.CreateCardMenuItems(def); var item = new MenuItem { Header = "Move to" }; var subItem = new MenuItem { Header = Program.Game.Definition.PlayerDefinition.Hand.Name, InputGestureText = Program.Game.Definition.PlayerDefinition.Hand.Shortcut }; subItem.Click += delegate { Selection.Do(c => c.MoveTo(Player.LocalPlayer.Hand, true), ContextCard); }; item.Items.Add(subItem); GroupDef[] groupDefs = Program.Game.Definition.PlayerDefinition.Groups; var moveToBottomItems = new List <MenuItem>(); for (int i = 0; i < groupDefs.Length; ++i) { GroupDef groupDef = groupDefs[i]; Group indexedGroup = Player.LocalPlayer.IndexedGroups[i + 1]; // 0 is hand subItem = new MenuItem { Header = groupDef.Name, InputGestureText = groupDef.Shortcut }; subItem.Click += delegate { Selection.Do(c => c.MoveTo(indexedGroup, true), ContextCard); }; item.Items.Add(subItem); subItem = new MenuItem { Header = string.Format("Bottom of {0}", groupDef.Name), InputGestureText = string.IsNullOrEmpty(groupDef.Shortcut) ? null : "Alt+" + groupDef.Shortcut }; subItem.Click += delegate { Selection.Do(c => c.MoveTo(indexedGroup, true, indexedGroup.Count), ContextCard); }; moveToBottomItems.Add(subItem); } if (moveToBottomItems.Count > 0) { item.Items.Add(new Separator()); } foreach (MenuItem x in moveToBottomItems) { item.Items.Add(x); } items.Add(item); item = new MenuItem { Header = "Bring to front", InputGestureText = "PgUp" }; item.Click += delegate { Selection.Do(c => Program.Game.Table.BringToFront(c), ContextCard); }; items.Add(item); item = new MenuItem { Header = "Send to back", InputGestureText = "PgDn" }; item.Click += delegate { Selection.Do(c => Program.Game.Table.SendToBack(c), ContextCard); }; items.Add(item); return(items); }
public void CenterView() { GroupDef tableDef = Program.Game.Definition.TableDefinition; Offset = new Vector(tableDef.Width / 2, tableDef.Height / 2); }
public Table(GroupDef def) : base(null, def) { }