コード例 #1
0
        void HandleConditionMenuItemClicked(object sender, ButtonStringPopover.PopoverEventArgs e)
        {
            ButtonStringPopover p  = (ButtonStringPopover)sender;
            ActiveCondition     ac = (ActiveCondition)p.Data;

            if (e.Tag is int)
            {
                int turns = (int)e.Tag;

                if (turns > 0)
                {
                    _CombatState.AddConditionTurns(_Character, ac, turns);
                }
                else
                {
                    _CombatState.RemoveConditionTurns(_Character, ac, -turns);
                }
            }
            else if (e.Tag is string)
            {
                string text = (string)e.Tag;
                if (text == "delete")
                {
                    _Character.Monster.RemoveCondition(ac);
                }
                else if (text == "deleteall")
                {
                    foreach (Character ch in _CombatState.Characters)
                    {
                        ch.RemoveConditionByName(ac.Condition.Name);
                    }
                }
            }
        }
コード例 #2
0
        private void UpdateConditions(View v, Character c, ViewGroup parent)
        {
            LinearLayout conditionsLayout = v.FindViewById <LinearLayout>(Resource.Id.conditionsLayout);

            conditionsLayout.RemoveAllViews();


            List <string> options = new List <string>()
            {
                "Add 5 Turns",
                "Add Turn",
                "Remove Turn",
                "Remove 5 Turns",
                "Delete",
                "Delete From All Characters"
            };

            foreach (ActiveCondition ac in c.Monster.ActiveConditions)
            {
                int      resID = v.Context.Resources.GetIdentifier(ac.Condition.Image.Replace("-", "").ToLower() + "16", "drawable", v.Context.PackageName);
                Drawable d     = ContextCompat.GetDrawable(v.Context, resID);

                View button;
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, 60);
                if (ac.Turns == null)
                {
                    ImageButton b = new ImageButton(v.Context);
                    b.SetImageDrawable(d);
                    b.LayoutParameters = lp;
                    conditionsLayout.AddView(b);
                    button = b;
                }
                else
                {
                    Button b = new Button(v.Context);
                    b.Text = ac.Turns.ToString();
                    b.SetCompoundDrawablesWithIntrinsicBounds(d, null, null, null);;
                    b.LayoutParameters = lp;
                    conditionsLayout.AddView(b);
                    button = b;
                }


                ConditionButtonChangedHandler cbch = new ConditionButtonChangedHandler(v, button, c, ac, this, parent);
                _ButtonHandlers.Add(cbch);

                button.Click += (object sender, EventArgs e) => {
                    AlertDialog.Builder builderSingle = new AlertDialog.Builder(parent.Context);

                    builderSingle.SetTitle(c.Name + " - " + ac.Condition.Name);
                    ArrayAdapter <String> arrayAdapter = new ArrayAdapter <String>(parent.Context,
                                                                                   Android.Resource.Layout.SelectDialogItem);
                    arrayAdapter.AddAll(options);


                    builderSingle.SetAdapter(arrayAdapter, (se, ev) => {
                        switch (ev.Which)
                        {
                        case 0:
                            _State.AddConditionTurns(c, ac, 5);
                            break;

                        case 1:
                            _State.AddConditionTurns(c, ac, 1);
                            break;

                        case 2:
                            _State.RemoveConditionTurns(c, ac, 1);
                            break;

                        case 3:
                            _State.RemoveConditionTurns(c, ac, 5);
                            break;

                        case 4:
                            c.Stats.RemoveCondition(ac);
                            break;

                        case 5:
                            foreach (Character chr in _State.Characters)
                            {
                                c.RemoveConditionByName(ac.Condition.Name);
                            }
                            break;
                        }
                    });


                    builderSingle.Show();
                };
            }
        }