Ejemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.SpellTraining);

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

            SetUpSpellButtons();

            // See if the current focus is already in our (local, for now) library, and load it if so.  Otherwise, take us to calibration.
            var focusString = Res.SpecificTags.Get(InteractionLibrary.CurrentSpecificTag);

            if (focusString != null && focusString.Length > 0)
            {
                ThePlayersFocus = Focus.FromString(focusString, InteractionLibrary.CurrentSpecificTag);
            }
            else if (InteractionLibrary.CurrentSpecificTag == InteractionLibrary.SpellTeaching.Name + "0000")
            {
                Focus.InitMasterFocus();
                InteractionLibrary.CurrentSpecificTag = Focus.MasterFocus.TagID;
                Log.Info("Training", "Using master focus.");
                ThePlayersFocus = Focus.MasterFocus;
            }
            else
            {
                ThePlayersFocus = new Focus(InteractionLibrary.CurrentSpecificTag);
            }

            CurrentStage = GestureRecognizerStage.NullStage;
        }
Ejemplo n.º 2
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            Log.Info("Motion", "{0} // {1} // {2} // {3}", e.ActionMasked.ToString(), e.Action.ToString(), e.ActionIndex, e.PointerCount);
            if (e.Action == MotionEventActions.Down || (int)e.ActionMasked == (int)MotionEventActions.PointerDown)
            {
                var ind = e.Action == MotionEventActions.Down ? 0 : e.ActionIndex;
                pointers [ind] = new PointF {
                    X = e.GetX(ind), Y = e.GetY(ind)
                };
            }
            else if (e.Action == MotionEventActions.Up ||
                     (int)e.ActionMasked == (int)MotionEventActions.PointerUp)
            {
                if (e.Action == MotionEventActions.Up)
                {
                    for (int i = 0; i < pointers.Length; ++i)
                    {
                        pointers [i] = null;
                    }
                }
                else
                {
                    var id = e.GetPointerId(e.ActionIndex);
                    pointers [id] = null;
                    generator.SetFingerCoefficient(id, 0);
                }
            }
            else if (e.Action == MotionEventActions.Move)
            {
                for (int i = 0; i < e.PointerCount; ++i)
                {
                    var pointerIndex = e.GetPointerId(i);
                    pointers[pointerIndex] = new PointF {
                        X = e.GetX(i), Y = e.GetY(i)
                    };
                }
            }

            generator.CarrierFrequency = (e.GetY() / Height) * (600 - 80) + 80;
            for (int i = 0; i < pointers.Length; i++)
            {
                var amp = pointers [i] == null ? 0 : 6 * (pointers [i].Value.X / Width);
                generator.SetFingerCoefficient(i, amp);
                Log.Info("NewAmp", "{0} -> {1}", i, amp);
            }

            if (!played)
            {
                player.Play();
                played = true;
            }

            Invalidate();
            return(true);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException("logEvent");
            }
            var renderSpace = new StringWriter();

            _textFormatter.Format(logEvent, renderSpace);

            var tag = logEvent.Properties.Where(x => x.Key == Constants.SourceContextPropertyName).Select(x => x.Value.ToString("l", null)).FirstOrDefault() ?? "";

            switch (logEvent.Level)
            {
            case LogEventLevel.Debug:
                AndroidLog.Debug(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Information:
                AndroidLog.Info(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Verbose:
                AndroidLog.Verbose(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Warning:
                AndroidLog.Warn(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Error:
                AndroidLog.Error(tag, renderSpace.ToString());
                break;

            case LogEventLevel.Fatal:
                AndroidLog.Wtf(tag, renderSpace.ToString());
                break;

            default:
                AndroidLog.WriteLine(LogPriority.Assert, tag, renderSpace.ToString());
                break;
            }
        }
Ejemplo n.º 5
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();
                }
            };
        }
Ejemplo n.º 6
0
        private void SetUpSpellButtons()
        {
            var layoutpanel = FindViewById <LinearLayout>(Resource.Id.Spell_casting_layoutpane);

            foreach (var spB in spellButtons)
            {
                spB.Visibility = ViewStates.Gone;
            }
            spellButtons.Clear();

            foreach (string spellName in MasterSpellLibrary.spellNames?.DefaultIfEmpty() ?? new List <string>())
            {
                if (spellName == Spell.None.SpellName)
                {
                    continue;
                }
                var spell       = MasterSpellLibrary.Get(spellName);
                var spellButton = new Button(this);
                spellButtons.Add(spellButton);
                spellButton.SetText(spellName + " (Retrain)", TextView.BufferType.Normal);
                spellButton.SetPadding(20, 20, 20, 20);
                layoutpanel.AddView(spellButton);

                spellButton.Click += (o, e) =>
                {
                    if (SpellBeingTrained != null)
                    {
                        return;                            // Debouncing, basically.
                    }
                    SpellBeingRetrained = spell;
                    SpellBeingTrained   = new Spell(spellName);
                    foreach (Button btn in spellButtons)
                    {
                        btn.Visibility = ViewStates.Gone;
                    }
                    setSpellNameButton.Text    = "Erase spell";
                    spellNameTextbox.Text      = spellName;
                    spellNameTextbox.Focusable = false;
                    CheckGlyphCount();
                    Speech.Say($"Retraining {spellName}.");
                    CurrentStage = new Spell_Training_TutorialStage($"Retraining {spellName}", ThePlayersFocus, true);
                };
            }

            spellNameTextbox   = FindViewById <EditText>(Resource.Id.spell_name_textbox);
            setSpellNameButton = FindViewById <Button>(Resource.Id.Set_spell_name_button);
            glyphCountDisplay  = FindViewById <TextView>(Resource.Id.glyph_count_display);
            undoGlyphButton    = FindViewById <Button>(Resource.Id.undo_glyph_button);
            inscribeButton     = FindViewById <Button>(Resource.Id.inscribe_spell_button);

            spellNameTextbox.KeyPress += (object sender, View.KeyEventArgs e) =>
            {
                e.Handled = false;
                if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter && spellNameTextbox.Text.Length > 0)
                {
                    setSpellNameButton.CallOnClick();
                }
                if (spellNameTextbox.Text.Length > 0)
                {
                    setSpellNameButton.Text = "Train";
                }
                else
                {
                    setSpellNameButton.Text = "Random";
                }
            };
            spellNameTextbox.ClearFocus(); // Not working, dunno why.

            setSpellNameButton.Click += async(o, e) =>
            {
                if (SpellBeingRetrained != null)
                {
                    if (setSpellNameButton.Text == "Erase spell")
                    {
                        setSpellNameButton.Text = "Confirm erasure"; return;
                    }
                    else if (setSpellNameButton.Text == "Confirm erasure")
                    {
                        MasterSpellLibrary.Erase(SpellBeingRetrained.SpellName);
                        ThePlayersFocus.ForgetSpell(SpellBeingRetrained.SpellName);
                        CurrentStage.Deactivate();
                        await Speech.SayAllOf($"Deleting {SpellBeingRetrained.SpellName} from the master library.");

                        CurrentStage = GestureRecognizerStage.NullStage;
                        //SetUpSpellButtons();
                        Current.Finish();
                        return;
                    }
                }
                SpellBeingRetrained = null;
                if (spellNameTextbox.Text.Length == 0)
                {
                    spellNameTextbox.Text = GenerateRandomSpellName();
                }
                Current.HideKeyboard();
                await Task.Delay(100); // Let the screen update.

                SpellBeingTrained = new Spell(spellNameTextbox.Text);
                foreach (Button btn in spellButtons)
                {
                    btn.Visibility = ViewStates.Gone;
                }
                //spellNameTextbox.Focusable = false;
                CheckGlyphCount();
                await Speech.SayAllOf($"Training {SpellBeingTrained.SpellName}.");

                CurrentStage = new Spell_Training_TutorialStage($"Init training for {SpellBeingTrained.SpellName}", ThePlayersFocus, true);
            };

            FindViewById <Button>(Resource.Id.glyph_training_btn).Click += async(o, e) =>
            {
                var glyphText = Res.Storage.Get(NewGlyphTrainingStage.GlyphKey);
                if (glyphText != null)
                {
                    Log.Debug("SpellTraining", "\n" + glyphText);
                }

                Current.HideKeyboard();
                await Task.Delay(100); // Let the screen update.

                foreach (Button btn in spellButtons)
                {
                    btn.Visibility = ViewStates.Gone;
                }
                await Speech.SayAllOf($"Training core glyphs.");

                //CurrentStage = new Spell_Training_TutorialStage($"Init training for {SpellBeingTrained.SpellName}", ThePlayersFocus, true);

                var provider = new GravityOrientationProvider();
                provider.Activate();
                Task.Delay(50)
                .ContinueWith(async _ => await SensorProvider.EnsureIsReady(provider))
                .ContinueWith(_ => CurrentStage = new NewGlyphTrainingStage(0, ThePlayersFocus, provider))
                .LaunchAsOrphan();
            };

            undoGlyphButton.Click += async(o, e) =>
            {
                if (SpellBeingTrained.Glyphs.Count == 0)
                {
                    foreach (Button btn in spellButtons)
                    {
                        btn.Enabled = true;
                    }
                    spellNameTextbox.Text      = "";
                    spellNameTextbox.Focusable = true;
                    setSpellNameButton.Enabled = true;
                    setSpellNameButton.Text    = "Random";
                    SpellBeingRetrained        = null;
                    SpellBeingTrained          = null;
                    CurrentStage.Deactivate();
                    CurrentStage = GestureRecognizerStage.NullStage;
                    SetUpSpellButtons();
                    await Speech.SayAllOf("Aborting spell training.");
                }
                else
                {
                    SpellBeingTrained.UndoAddGlyph();
                    await Speech.SayAllOf("Removing most recent glyph.");
                }
                CheckGlyphCount();
            };

            var feedbackSFXbtn = FindViewById <Button>(Resource.Id.spell_feedback_sfx_button);
            var progressSFXbtn = FindViewById <Button>(Resource.Id.spell_progress_sfx_button);
            var successSFXbtn  = FindViewById <Button>(Resource.Id.spell_success_sfx_button);

            if (!MasterSpellLibrary.GetSFXReadyTask().Wait(5000))
            {
                Log.Error("Spell training", "Can't prep the buttons (as is, anyway) without our SFX loaded, which doesn't seem to be happening.");
            }
            var feedbackSFXoptions = new SimpleCircularList <string>("Magic.Ethereal",
                                                                     "Magic.Aura", "Magic.DeepVenetian", "Magic.InfiniteAubergine", "Magic.Ommm", "Magic.AfricanDrums",
                                                                     "Magic.Rommble", "Magic.MidtonePianesque", "Magic.FemReverbDSharp", "Magic.FemReverbCSharp",
                                                                     "Magic.FemReverbF", "Magic.FemReverbE", "Magic.AlienTheremin",
                                                                     "Magic.TrompingBuzzPulse", "Magic.GrittyDrone", "Magic.Galewinds", "Magic.NanobladeLoop",
                                                                     "Magic.ViolinLoop", "Magic.StrongerThanTheDark", "Magic.MelodicPad");
            var progressSFXoptions = new SimpleCircularList <string>(MasterSpellLibrary.SpellSFX.Keys.Where(sfx => !feedbackSFXoptions.Contains(sfx)).DefaultIfEmpty().ToArray());
            var successSFXoptions  = new SimpleCircularList <string>(MasterSpellLibrary.CastingResults.Keys.ToArray());

            while (progressSFXoptions.Next != MasterSpellLibrary.defaultProgressSFXName)
            {
            }                                                                                // Cycle the list to the correct starting point.
            while (successSFXoptions.Next != "Play " + MasterSpellLibrary.defaultSuccessSFXName)
            {
            }                                                                                        // Cycle the list to the correct starting point.

            inscribeButton.Click += async(o, e) =>
            {
                if (inscribeButton.Text == "Inscribe Spell")
                {
                    // Halt ongoing processeses
                    MasterSpellLibrary.SpellFeedbackSFX.Deactivate();
                    CurrentStage.Deactivate();
                    CurrentStage = GestureRecognizerStage.NullStage;

                    // Display SFX modification buttons
                    feedbackSFXbtn.Visibility = ViewStates.Visible;
                    progressSFXbtn.Visibility = ViewStates.Visible;
                    successSFXbtn.Visibility  = ViewStates.Visible;

                    IEffect sampleSFX = null;
                    Func <SimpleCircularList <string>, Button, string, EventHandler> HandlerFactory
                        = (circList, btn, label) =>
                        {
                        return((ob, ev) =>
                        {
                            sampleSFX?.Stop();
                            btn.Text = $"{label} ('{circList.Next}')";
                            if (MasterSpellLibrary.SpellSFX.ContainsKey(circList.Current.Split(' ').Last()))
                            {
                                sampleSFX = MasterSpellLibrary.SpellSFX[circList.Current.Split(' ').Last()];
                                sampleSFX.Play();
                            }
                            else
                            {
                            }
                        });
                        };
                    feedbackSFXbtn.Click += HandlerFactory(feedbackSFXoptions, feedbackSFXbtn, "Feedback SFX");
                    progressSFXbtn.Click += HandlerFactory(progressSFXoptions, progressSFXbtn, "Progress SFX");
                    successSFXbtn.Click  += HandlerFactory(successSFXoptions, successSFXbtn, "Success Func");

                    inscribeButton.Text = "Finish Inscribing";
                }
                else
                {
                    feedbackSFXbtn.Visibility = ViewStates.Gone;
                    progressSFXbtn.Visibility = ViewStates.Gone;
                    successSFXbtn.Visibility  = ViewStates.Gone;

                    SpellBeingTrained.CastingResult = MasterSpellLibrary.CastingResults[successSFXoptions.Current];
                    foreach (var glyph in SpellBeingTrained.Glyphs)
                    {
                        glyph.FeedbackSFXName = feedbackSFXoptions.Current;
                        glyph.ProgressSFXName = progressSFXoptions.Current;
                    }
                    MasterSpellLibrary.Inscribe(SpellBeingTrained);
                    ThePlayersFocus.LearnSpell(SpellBeingTrained);

                    //ResetSpell();
                    if (SpellBeingRetrained == null)
                    {
                        await Speech.SayAllOf($"Adding {SpellBeingTrained.SpellName} to the master library.");
                    }
                    else
                    {
                        await Speech.SayAllOf($"Updating spell listing for {SpellBeingTrained.SpellName}.");
                    }
                    Log.Info("SpellTraining", $"Here's the spell string for copy-and-pasting as a constant: {SpellBeingTrained.ToString()}");
                    Current.Finish();
                }
            };
        }