Esempio n. 1
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.MeleeTraining);

            currentSignalsDisplay = FindViewById <TextView>(Resource.Id.current_signals_text);
            bestSignalsDisplay    = FindViewById <TextView>(Resource.Id.best_signals_text);
            resultsDisplay        = FindViewById <TextView>(Resource.Id.result_text);

            SetUpFormButtons();

            // See if the current sword is already in our (local, for now) library, and load it if so.  Otherwise, create one.
            var swordString = Res.SpecificTags.Get(InteractionLibrary.CurrentSpecificTag);

            if (swordString != null && swordString.Length > 0)
            {
                ThePlayersSword = Sword.FromString(swordString, InteractionLibrary.CurrentSpecificTag);
                CurrentStage    = GestureRecognizerStage.NullStage;
                return;
            }
            else if (InteractionLibrary.CurrentSpecificTag == InteractionLibrary.MeleeTeaching.Name + "0000")
            {
                Sword.InitMasterSword();
                InteractionLibrary.CurrentSpecificTag = Sword.MasterSword.TagID;
                Log.Info("Training", "Using master sword.");
                ThePlayersSword = Sword.MasterSword;
            }
            else
            {
                ThePlayersSword = new Sword(InteractionLibrary.CurrentSpecificTag);
            }

            if (ThePlayersSword.EnGardeOrientation == null || ThePlayersSword.EnGardeOrientation.Average.AngleTo(Quaternion.Identity) < 1)
            {
                await Speech.SayAllOf("No pre-existing ahn garde stance found.  Please take and hold your ahn garde stance to begin.");

                CurrentStage = new DefineEnGardeStage("Defining new en garde", true);
            }
            else
            {
                await Speech.SayAllOf("Confirm your saved ahn garde stance to begin.");

                setFormNameButton.Text = RetrainEnGardeText;
                CurrentStage           = new EnGardeStage("Confirm en garde", "Okay. Use onscreen buttons to train specific forms.", GestureRecognizerStage.NullStage, true);
            }
        }
Esempio n. 2
0
        private void SetUpFormButtons()
        {
            var layoutpanel = FindViewById <LinearLayout>(Resource.Id.Form_list_layoutpane);

            formNameTextbox    = FindViewById <EditText>(Resource.Id.form_name_textbox);
            setFormNameButton  = FindViewById <Button>(Resource.Id.Set_form_name_button);
            strokeCountDisplay = FindViewById <TextView>(Resource.Id.stroke_count_display);
            reassessButton     = FindViewById <Button>(Resource.Id.reassess_button);
            pauseButton        = FindViewById <Button>(Resource.Id.pause_button);
            finalizeButton     = FindViewById <Button>(Resource.Id.finalize_button);
            paramAbox          = FindViewById <EditText>(Resource.Id.parameterAtextbox);
            paramBbox          = FindViewById <EditText>(Resource.Id.parameterBtextbox);
            paramCbox          = FindViewById <EditText>(Resource.Id.parameterCtextbox);

            foreach (string formName in MasterFechtbuch.formNames?.DefaultIfEmpty() ?? new string[0])
            {
                var form       = MasterFechtbuch.Get(formName);
                var formButton = new Button(this);
                var codicil    = (form != null && form != Form.None) ? "" : " (Unknown)";
                formButton.SetText(formName + codicil, TextView.BufferType.Normal);
                formButton.SetPadding(20, 20, 20, 20);
                layoutpanel.AddView(formButton);
                formButtons.Add(formButton);

                formButton.Click += async(o, e) =>
                {
                    if (FormBeingTrained != null)
                    {
                        return;                            // Debouncing, basically.
                    }
                    if (form != null && form != Form.None) // The target form does already exist in more than theory.
                    {
                        AppendMode         = true;
                        FormBeingRetrained = form;
                        FormBeingTrained   = form;
                        foreach (Button btn in formButtons)
                        {
                            btn.Enabled = false;
                        }
                        setFormNameButton.Text    = "Retrain Instead";
                        formNameTextbox.Text      = formName;
                        formNameTextbox.Focusable = false;
                        CheckStrokeCount();
                        await Speech.SayAllOf($"Adding more training for {formName}. Ahn garde!");

                        CurrentStage = new EnGardeStage($"En Garde for rep {FormBeingTrained.Strokes.Count}", "Setting up another recording. Wait for the cue...",
                                                        new StrokeTrainingStage($"{Current.FormBeingTrained.FormName} stroke, rep {FormBeingTrained.Strokes.Count}"), true);
                    }
                    else // It only existed as a theory - treat it as if the user had typed in the name.
                    {
                        formNameTextbox.Text = formName;
                        setFormNameButton.CallOnClick();
                    }
                };
            }

            formNameTextbox.KeyPress += (object sender, View.KeyEventArgs e) =>
            {
                e.Handled = false;
                if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter && formNameTextbox.Text.Length > 0)
                {
                    setFormNameButton.CallOnClick();
                }
                if (formNameTextbox.Text.Length > 0)
                {
                    setFormNameButton.Text = "Train";
                }
                else
                {
                    setFormNameButton.Text = "Random";
                }
            };

            setFormNameButton.Click += async(o, e) =>
            {
                if (setFormNameButton.Text == RetrainEnGardeText)
                {
                    CurrentStage.Deactivate();
                    setFormNameButton.Text = "Random";
                    CurrentStage           = new DefineEnGardeStage("Redefining en garde", true);
                    return;
                }
                if (FormBeingRetrained != null)
                {
                    if (AppendMode == true)
                    {
                        AppendMode             = false;
                        FormBeingTrained       = new Form(FormBeingRetrained.FormName, FormBeingRetrained.IsOffense);
                        setFormNameButton.Text = "Erase form";
                        await Speech.SayAllOf("Retraining from start.");

                        return;
                    }
                    else if (setFormNameButton.Text == "Erase form")
                    {
                        setFormNameButton.Text = "Confirm erasure";
                        return;
                    }
                    else if (setFormNameButton.Text == "Confirm erasure")
                    {
                        MasterFechtbuch.Erase(FormBeingRetrained.FormName);
                        ThePlayersSword.ForgetForm(FormBeingRetrained.FormName);
                        await Speech.SayAllOf($"Deleting {FormBeingRetrained.FormName} from the master library.");

                        CurrentStage.Deactivate();
                        CurrentStage = GestureRecognizerStage.NullStage;
                        Finish();
                        return;
                    }
                }
                FormBeingRetrained = null;
                AppendMode         = null;
                if (formNameTextbox.Text.Length == 0)
                {
                    formNameTextbox.Text = GenerateRandomFormName();
                }
                await Task.Delay(100); // Let the screen update.

                FormBeingTrained = new Form(formNameTextbox.Text, !(formNameTextbox.Text.EndsWith("Parry")));
                foreach (Button btn in formButtons)
                {
                    btn.Enabled = false;
                }
                formNameTextbox.Focusable = false;
                await Speech.SayAllOf($"Training {FormBeingTrained.FormName}.  Ahn garde!");

                CheckStrokeCount();
                CurrentStage = new EnGardeStage("EnGarde pre-Form Setup", "", new FormSetupStage($"Init training for {FormBeingTrained.FormName}"), true);
            };

            reassessButton.Click += (o, e) =>
            {
            };

            pauseButton.Click += async(o, e) =>
            {
                if (pauseButton.Text == "Pause Sensors")
                {
                    pauseButton.Text = "Resume Sensors";
                    Res.SFX.StopAll();
                    CurrentStage.Deactivate();
                    await Speech.SayAllOf($"Pausing sensors.  Take your time and play with the parameter buttons.");

                    CurrentStage = GestureRecognizerStage.NullStage;
                }
                else
                {
                    pauseButton.Text = "Pause Sensors";
                    await Speech.SayAllOf($"Resume training for {FormBeingTrained.FormName}. Ahn garde!");

                    CurrentStage = new EnGardeStage($"En Garde for rep {FormBeingTrained.Strokes.Count}", "Setting up another recording. Wait for the cue...",
                                                    new StrokeTrainingStage($"{Current.FormBeingTrained.FormName} stroke, rep {FormBeingTrained.Strokes.Count}"), true);
                }
            };

            finalizeButton.Click += async(o, e) =>
            {
                if (finalizeButton.Text == "Finalize")
                {
                    // Halt ongoing processeses (if not already done via the Pause button).
                    Res.SFX.StopAll();
                    CurrentStage.Deactivate();
                    CurrentStage        = GestureRecognizerStage.NullStage;
                    finalizeButton.Text = "Commit to Fechtbuch";
                }
                else
                {
                    // TODO: Stuff.
                    MasterFechtbuch.Inscribe(FormBeingTrained);
                    ThePlayersSword.LearnForm(FormBeingTrained);

                    if (FormBeingRetrained == null)
                    {
                        await Speech.SayAllOf($"Adding {FormBeingTrained.FormName} to the master fechtbuch.");
                    }
                    else
                    {
                        await Speech.SayAllOf($"Updating form listing for {FormBeingTrained.FormName}.");
                    }
                    Log.Info("MeleeTraining", $"Here's the form string for copy-and-pasting as a constant: {FormBeingTrained.ToString()}");
                    Finish();
                }
            };
        }