public void AddDynamicActionInfo(IButtonContext buttonContex, ICardInfo cardInfo)
        {
            DynamicActionInfo changedAction;

            lock (_cacheLock) {
                var itemExistsAtLocation = _dynamicActionInfoList.FirstOrDefaultWithContext(buttonContex) != null;
                if (itemExistsAtLocation)
                {
                    //make room for the item we are inserting by shifting the index of everything else up
                    foreach (var dynamicActioninfo in _dynamicActionInfoList)
                    {
                        if (dynamicActioninfo.IsAtSameIndexOrAfter(buttonContex))
                        {
                            dynamicActioninfo.Index++;
                        }
                    }
                }

                changedAction = new DynamicActionInfo(buttonContex);
                changedAction.UpdateFromCardInfo(cardInfo);
                _dynamicActionInfoList.Add(changedAction);
            }

            //we only have to change the one action that changed, as the handler is smart enough to refresh everything else around
            PublishChangeEventsForChangedActions(changedAction);
        }
 /// <summary>
 /// Create DynamicActionOption with a reference to the original dynamic action requesting the menu and the menu option to display
 /// </summary>
 /// <param name="buttonContext">Button context for the button that requires the menu</param>
 /// <param name="option">Option to pass to the right click request if this dynamic action is selected</param>
 /// <param name="text">Text to display for the menu</param>
 /// <param name="image">Image to display for the menu- will use a blank image if null or empty</param>
 public DynamicActionOption(IButtonContext buttonContext, ButtonOption option = null, string text = null, string image = null)
 {
     ButtonContext = buttonContext;
     Option        = option;
     Text          = text;
     Image         = string.IsNullOrEmpty(image) ? ImageUtils.BlankImage() : image;
 }
        public void UpdateDynamicActionInfo(IButtonContext buttonContex, ICardInfo cardInfo)
        {
            DynamicActionInfo dynamicActionInfo;

            lock (_cacheLock) {
                dynamicActionInfo = _dynamicActionInfoList.FirstOrDefaultWithContext(buttonContex);
                if (dynamicActionInfo != null)
                {
                    if (!dynamicActionInfo.CardInfoHasChanged(cardInfo))
                    {
                        return;
                    }
                    dynamicActionInfo.UpdateFromCardInfo(cardInfo);
                }
            }

            if (dynamicActionInfo == null)
            {
                AddDynamicActionInfo(buttonContex, cardInfo);
            }
            else
            {
                PublishChangeEventsForChangedActions(dynamicActionInfo);
            }
        }
Ejemplo n.º 4
0
 public DynamicActionInfo(IButtonContext buttonContex)
 {
     CardGroupId   = buttonContex.CardGroupId;
     ButtonMode    = buttonContex.ButtonMode;
     ZoneIndex     = buttonContex.ZoneIndex;
     Index         = buttonContex.Index;
     ButtonOptions = new List <ButtonOption>();
 }
        /// <summary>
        /// Create a dynamic action option, resolving placeholders from a button option
        /// </summary>
        /// <param name="buttonOption">The button option that is the basis for this dynamic action option</param>
        /// <param name="buttonContext">The button context that is the source of the menu</param>
        /// <returns>A Dynamic action option with resovled text and possibly an image, if appicable</returns>
        private DynamicActionOption CreateDynamicActionOption(ButtonOption buttonOption, IButtonContext buttonContext)
        {
            var text = buttonOption.GetText(this);

            if (string.IsNullOrEmpty(text))
            {
                return(default);
 public IDynamicActionInfo GetDynamicActionInfo(IButtonContext buttonContext)
 {
     lock (_cacheLock) {
         return(_dynamicActionInfoList.FirstOrDefaultWithContext(buttonContext));
     }
 }
        private IButton GetCardButton(IButtonContext context)
        {
            var cardGroup = _appData.Game.GetCardGroup(context.CardGroupId);

            return(cardGroup.GetButton(context));
        }
Ejemplo n.º 8
0
 public static T FirstOrDefaultWithContext <T>(this IEnumerable <T> list, IButtonContext context) where T : IButtonContext
 {
     return(list.FirstOrDefault(x => x.HasSameContext(context)));
 }
Ejemplo n.º 9
0
 public static IEnumerable <T> FindAllWithContext <T>(this IEnumerable <T> list, IButtonContext context) where T : IButtonContext
 {
     return(from potentialContext in list
            where potentialContext.HasSameContext(context)
            select potentialContext);
 }
Ejemplo n.º 10
0
 public static bool IsAtSameIndexOrAfter(this IButtonContext a, IButtonContext b)
 {
     return(a.CardGroupId == b.CardGroupId && a.ButtonMode == b.ButtonMode && a.ZoneIndex == b.ZoneIndex && a.Index >= b.Index);
 }
Ejemplo n.º 11
0
 public static bool HasSameContext(this IButtonContext a, IButtonContext b)
 {
     return(a.CardGroupId == b.CardGroupId && a.ButtonMode == b.ButtonMode && a.ZoneIndex == b.ZoneIndex && a.Index == b.Index);
 }