Exemplo n.º 1
0
        private static void PopulateSearch(string searchText, CurrentInput inputType)
        {
            bool active = false;

            lock (sync)
            {
                active = currentlySearching;
            }

            if (active)
            {
                return;         // Already a thread doing the computation
            }
            switch (inputType)
            {
            case CurrentInput.Method:
            case CurrentInput.InternalMethod:
            case CurrentInput.MethodHarmony:
                searchThread = new Thread(() => PopulateSearchMethod(searchText));
                break;

            case CurrentInput.Type:
            case CurrentInput.TypeHarmony:
            case CurrentInput.SubClasses:
                searchThread = new Thread(() => PopulateSearchType(searchText));
                break;

            default:
                searchThread = new Thread(() => PopulateSearchAssembly(searchText));
                break;
            }

            searchThread.IsBackground = true;
            searchThread.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a new key to the manager
        /// </summary>
        /// <param name="key">The key to add</param>
        /// <returns>The task</returns>
        public static async Task AddKeyAsync(Key key)
        {
            // Lock the method
            using (await AsyncLock.LockAsync())
            {
                // Check if it's the following key in any of the available codes
                if (Codes.All(x => x.Key.Length <= CurrentInput.Count || x.Key[CurrentInput.Count] != key))
                {
                    if (CurrentInput.Any())
                    {
                        CurrentInput.Clear();
                        RL.Logger?.LogDebugSource("The secret code inputs were reset due to an invalid key being pressed");
                    }

                    return;
                }

                // Add the key to the list
                CurrentInput.Add(key);

                // Attempt to get a completed code
                var task = Codes.FindItem(x => x.Key.SequenceEqual(CurrentInput)).Value;

                if (task == null)
                {
                    return;
                }

                CurrentInput.Clear();
                RL.Logger?.LogDebugSource("The secret code inputs were reset due to a valid code having been entered");

                // Run the task
                await task();
            }
        }
Exemplo n.º 3
0
        public static void DrawButtons(Listing_Standard listing)
        {
            var i = 0;
            var r = new Rect();

            DrawInputIcon(ResourceCache.Strings.devoptions_input_method, CurrentInput.Method);
            DrawInputIcon(ResourceCache.Strings.devoptions_input_methodinternal, CurrentInput.InternalMethod);
            DrawInputIcon(ResourceCache.Strings.devoptions_input_methodharmony, CurrentInput.MethodHarmony);
            DrawInputIcon(ResourceCache.Strings.devoptions_input_type, CurrentInput.Type);
            DrawInputIcon(ResourceCache.Strings.devoptions_input_subclasses, CurrentInput.SubClasses);
            DrawInputIcon(ResourceCache.Strings.devoptions_input_typeharmony, CurrentInput.TypeHarmony);
            DrawInputIcon(ResourceCache.Strings.devoptions_input_assembly, CurrentInput.Assembly);

            void DrawInputIcon(string key, CurrentInput inputType)
            {
                if (i++ % 2 == 0)
                {
                    r    = listing.GetRect(Text.LineHeight + 3).LeftPart(.49f);
                    r.x += listing.ColumnWidth * .01f;
                }
                else
                {
                    r.x += listing.ColumnWidth / 2;
                }

                DubGUI.OptionalBox(r, key, () => input = inputType, input == inputType);
            }
        }
Exemplo n.º 4
0
 void IInput.KeyInputted(ConsoleKeyInfo key)
 {
     if (key.Key == ConsoleKey.Enter)
     {
         if (Suggestion != null)
         {
             LastInput.Enqueue(Suggestion);
         }
         else
         {
             LastInput.Enqueue(CurrentInput);
         }
         CurrentInput      = "";
         Suggestion        = null;
         currentSuggestion = -1;
     }
     else if (key.Key == ConsoleKey.Escape)
     {
         CurrentInput      = "";
         Suggestion        = null;
         currentSuggestion = -1;
     }
     else if (key.Key == ConsoleKey.Backspace)
     {
         if (CurrentInput.Length > 0)
         {
             CurrentInput = CurrentInput.Substring(0, CurrentInput.Length - 1);
             suggestions  = AutoCompleteWordList.Where(x => x.StartsWith(CurrentInput)).ToList();
         }
         Suggestion        = null;
         currentSuggestion = -1;
     }
     else if (key.Key == ConsoleKey.Tab)
     {
         currentSuggestion++;
         if (currentSuggestion > suggestions.Count - 1)
         {
             currentSuggestion = -1;
             Suggestion        = null;
         }
         else
         {
             Suggestion = suggestions[currentSuggestion];
         }
     }
     else
     {
         if (Suggestion != null)
         {
             CurrentInput = Suggestion += key.KeyChar;
         }
         else
         {
             CurrentInput += key.KeyChar;
         }
         suggestions       = AutoCompleteWordList.Where(x => x.StartsWith(CurrentInput)).ToList();
         Suggestion        = null;
         currentSuggestion = -1;
     }
 }
Exemplo n.º 5
0
                public static void PopulateSearch(Rect rect, string searchText, CurrentInput inputType)
                {
                    bool active = false;

                    lock (sync)
                    {
                        active = curSearching;
                    }

                    if (!active && prevInput != currentInput)
                    {
                        switch (inputType)
                        {
                        case CurrentInput.Method:
                        case CurrentInput.InternalMethod:
                        case CurrentInput.MethodHarmony:
                            searchThread = new Thread(() => PopulateSearchMethod(searchText));
                            break;

                        case CurrentInput.Type:
                        case CurrentInput.TypeHarmony:
                            searchThread = new Thread(() => PopulateSearchType(searchText));
                            break;

                        default:
                            searchThread = new Thread(() => PopulateSearchAssembly(searchText));
                            break;
                        }
                        searchThread.IsBackground = true;
                        prevInput = currentInput;
                        searchThread.Start();
                    }
                    searchBoxRect = rect;
                }
Exemplo n.º 6
0
 public void UpgradeConverterOutputResource(string resource)
 {
     if (InputOutputMapping.ContainsKey(resource))
     {
         return;
     }
     InputOutputMapping.Add(resource, new List <ResourceAmount>());
     CurrentInput.Add(new ResourceAmount(resource, 0));
 }
Exemplo n.º 7
0
        public static void ExecutePatch(CurrentInput mode, string strinput, Category cat)
        {
            try
            {
                var entry = cat == Category.Tick ? typeof(CustomProfilersTick) : typeof(CustomProfilersUpdate);
                List <MethodInfo> methods = null;

                var temp = mode switch
                {
                    CurrentInput.Method => Utility.GetMethods(strinput),
                    CurrentInput.Type => Utility.GetTypeMethods(AccessTools.TypeByName(strinput)),
                    CurrentInput.MethodHarmony => Utility.GetMethodsPatching(strinput),
                    CurrentInput.SubClasses => Utility.SubClassImplementationsOf(AccessTools.TypeByName(strinput), m => true),
                    CurrentInput.TypeHarmony => Utility.GetMethodsPatchingType(AccessTools.TypeByName(strinput)),
                    _ => null,
                };

                if (temp is null)
                {
                    if (mode == CurrentInput.InternalMethod)
                    {
                        Utility.PatchInternalMethod(strinput, cat);
                    }
                    else
                    {
                        Utility.PatchAssembly(strinput, cat);
                    }

                    return;
                }

                methods = temp.ToList();

                if (methods.Count == 0)
                {
                    Messages.Message($"Failed to find the method(s) represented by {strinput}", MessageTypeDefOf.CautionInput, false);
                    return;
                }

                Messages.Message(methods.Count != 1 ? $"Patching {methods.Count} methods in the category {cat}" : $"Patching {Utility.GetSignature(methods[0])} in the category {cat}", MessageTypeDefOf.CautionInput, false);

                MethodTransplanting.UpdateMethods(entry, methods.ToList());
                GUIController.Tab(cat).collapsed = false;

                var entryName = (cat == Category.Tick) ? "Custom Tick" : "Custom Update";
                GUIController.SwapToEntry(entryName);
            }
            catch (Exception e)
            {
                ThreadSafeLogger.ReportException(e, $"Failed to process search bar input");
            }
        }
Exemplo n.º 8
0
    public void Init(InputManager _input)
    {
        if (_input.Horizontal == null)
        {
            _input.Horizontal += HandleHorizontalMovement;
        }
        if (_input.Vertical == null)
        {
            _input.Vertical += HandleVerticalMovement;
        }

        currentInput = _input.GetCurrentInput();
    }
Exemplo n.º 9
0
        /// <summary>
        /// Performs the initialisation of the state of the game being interpreted. Usually called whenever
        /// the game starts or restarts.
        /// </summary>
        public void Init()
        {
            ClearVars();
            Vars[Defines.MACHINE_TYPE] = 0;  // IBM PC
            Vars[Defines.MONITOR_TYPE] = 3;  // EGA
            Vars[Defines.INPUTLEN]     = Defines.MAXINPUT + 1;
            Vars[Defines.NUM_VOICES]   = 3;

            // The game would usually set this, but no harm doing it here (2 = NORMAL).
            Vars[Defines.ANIMATION_INT] = 2;

            // Set to the maximum memory amount as recognised by AGI.
            Vars[Defines.MEMLEFT] = 255;

            ClearFlags();
            Flags[Defines.HAS_NOISE] = true;
            Flags[Defines.INITLOGS]  = true;
            Flags[Defines.SOUNDON]   = true;

            // Set the text attribute to default (black on white), and display the input line.
            ForegroundColour = 15;
            BackgroundColour = 0;

            Horizon     = Defines.HORIZON;
            UserControl = true;
            Blocking    = false;

            ClearVisualPixels();
            GraphicsMode   = true;
            AcceptInput    = false;
            ShowStatusLine = false;
            CurrentLogNum  = 0;
            CurrentInput.Clear();
            LastInput  = "";
            SimpleName = "";
            KeyToControllerMap.Clear();
            MenuEnabled = true;
            HoldKey     = false;

            foreach (AnimatedObject aniObj in AnimatedObjects)
            {
                aniObj.Reset(true);
            }

            StoppedObjectList.Clear();
            UpdateObjectList.Clear();

            this.Objects = new Objects(game.Objects);
        }
Exemplo n.º 10
0
        public static void SetCurrentInput(CurrentInput inputType)
        {
            if (inputType == currentInput)
            {
                return;
            }

            lock (sync)
            {
                cachedEntries = new HashSet <string>();
            }

            currentInput   = inputType;
            requiresUpdate = true;
        }
        private void OutputInput(int totalWidth)
        {
            const string Prefix = "> ";
            var          row    = Console.WindowHeight - 1;

            if (SetCursorPosition(0, row))
            {
                WriteText(Prefix, ConsoleColor.Gray, ConsoleColor.DarkGray);
                if (SetCursorPosition(Prefix.Length, row))
                {
                    var width = totalWidth - Prefix.Length - (isWindows ? 1 : 0);
                    var text  = CurrentInput.TrimStart().FitRight(width);
                    WriteText(text, ConsoleColor.White, ConsoleColor.DarkGray);
                }
            }
        }
Exemplo n.º 12
0
    void Update()
    {
        horizontal    = Input.GetAxisRaw("Horizontal");
        vertical      = Input.GetAxisRaw("Vertical");
        forward       = Camera.main.transform.TransformDirection(Vector3.forward);
        right         = Camera.main.transform.TransformDirection(Vector3.right);
        walkInput     = Input.GetButton("Walk");
        jumpInput     = Input.GetButton("Jump");
        nextMoveInput = Input.GetButtonDown("Next");
        lastMoveInput = Input.GetButtonDown("Last");
        attackInput   = Input.GetMouseButton(1);
        swapToInput   = Input.GetButtonDown("Swap To Trainer");
        targetInput   = Input.GetMouseButtonDown(0);

        curInput = new CurrentInput
        {
            movement      = (horizontal * right + vertical * forward),
            walk          = walkInput,
            jump          = jumpInput,
            swapToTrainer = swapToInput,
            nextMove      = nextMoveInput,
            lastMove      = lastMoveInput,
            attack        = attackInput,
            target        = targetInput
        };

        if (!components.pokemon.Trainer.components.controller.TrainerControl)
        {
            if (nextMoveInput)
            {
                components.pokemon.NextMove();
            }

            if (lastMoveInput)
            {
                components.pokemon.LastMove();
            }

            if (attackInput && !attacking)
            {
                components.pokemon.Attack();
                attacking = true;
            }
            else if (!attackInput && attacking)
            {
                components.pokemon.EndAttack();
                attacking = false;
            }

            if (swapToInput)
            {
                components.pokemon.Trainer.components.controller.SwitchControl();
            }

            //if(currentInput.targetInput)
            //{
            //    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //    RaycastHit hit;

            //    if(Physics.Raycast(ray, out hit, Camera.main.farClipPlane))
            //    {
            //        if(hit.transform.gameObject.CompareTag("Pokemon") && hit.transform.gameObject != gameObject)
            //        {
            //            if(!hit.transform.gameObject.GetComponent<Pokemon>().isCaptured)
            //            {
            //                components.trainer.hud.DisplayWildPokemonPanel(hit.transform.gameObject);
            //                components.trainer.hud.wildPokemonPanel.transform.position = Input.mousePosition;
            //            }
            //        }
            //    }
            //}
        }
    }
Exemplo n.º 13
0
 void Start()
 {
     curInput = new CurrentInput();
 }
    void Update()
    {
        horizontal            = Input.GetAxisRaw("Horizontal");
        vertical              = Input.GetAxisRaw("Vertical");
        forward               = Camera.main.transform.TransformDirection(Vector3.forward);
        right                 = Camera.main.transform.TransformDirection(Vector3.right);
        walkInput             = Input.GetButton("Walk");
        jumpInput             = Input.GetButtonDown("Jump");
        nextSlotInput         = Input.GetButtonDown("Next");
        lastSlotInput         = Input.GetButtonDown("Last");
        throwPokemonBallInput = Input.GetButtonDown("Throw Pokemon Ball");
        swapToInput           = Input.GetButtonDown("Swap To Pokemon");
        returnInput           = Input.GetButtonDown("Pokemon Return");
        captureInput          = Input.GetButtonDown("Capture");
        targetInput           = Input.GetMouseButtonDown(0);

        curInput = new CurrentInput
        {
            movement      = (horizontal * right + vertical * forward),
            walk          = walkInput,
            jump          = jumpInput,
            swapToPokemon = swapToInput
        };

        if (components.controller.TrainerControl)
        {
            if (nextSlotInput)
            {
                components.trainer.NextSlot();
            }

            if (lastSlotInput)
            {
                components.trainer.LastSlot();
            }

            if (!throwing && !returning && throwPokemonBallInput && !components.trainer.Pokemon)
            {
                components.controller.canMove = false;
                throwing = true;
                components.anim.ThrowPokemonBall(true);
            }

            if (swapToInput)
            {
                components.controller.SwitchControl();
            }

            if (targetInput)
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, Camera.main.farClipPlane))
                {
                    if (hit.transform.gameObject.CompareTag("Trainer") && hit.transform.gameObject != gameObject)
                    {
                        components.trainer.hud.DisplayOtherTrainerPanel(hit.transform.gameObject);
                        components.trainer.hud.otherTrainerPanel.transform.position = Input.mousePosition;
                    }
                }
            }

            if (!throwing && !returning && captureInput)
            {
                Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
                RaycastHit targetHit;

                if (Physics.Raycast(ray, out targetHit, 100.0f))
                {
                    throwing = true;
                    components.trainer.Capture(targetHit.point);
                    return;
                }
            }

            if (!returning && !throwing && returnInput && components.trainer.Pokemon != null)
            {
                components.trainer.RecallPokemon();
                return;
            }
        }
    }
Exemplo n.º 15
0
        private void ProcessOtherButtons(string button)
        {
            switch (button)
            {
            case "C":
                ClearDisplay();
                break;

            case "CE":
                CurrentInput = "0";
                break;

            case "±":
                if (!CurrentInput.Contains('-'))
                {
                    CurrentInput = "-" + CurrentInput;
                }
                else
                {
                    CurrentInput = CurrentInput.Substring(1);
                }
                break;

            case "<-":
                if (CurrentInput.Length == 0 || CurrentInput == "-" || CurrentInput == "Error" || CurrentInput == "NaN")
                {
                    CurrentInput = "0";
                }
                else
                {
                    CurrentInput = CurrentInput.Remove(CurrentInput.Length - 1);
                }
                break;

            case "x^2":
                NCalc.Expression powExp = new NCalc.Expression("Round(Pow(" + CurrentInput + ", 2), 3)");
                CurrentInput = powExp.Evaluate().ToString();
                break;

            case "√":
                NCalc.Expression sqrtExp = new NCalc.Expression("Round(Sqrt(" + CurrentInput + "), 3)");
                CurrentInput = sqrtExp.Evaluate().ToString();
                break;

            case "1/x":
                CurrentInput = new NCalc.Expression($"Round(1/{CurrentInput}, 3)").Evaluate().ToString();
                break;

            case "MS":
                calcmemory = CurrentInput;
                break;

            case "M+":
                calcmemory = new NCalc.Expression(calcmemory + "+" + CurrentInput).Evaluate().ToString();
                break;

            case "M-":
                calcmemory = new NCalc.Expression(calcmemory + "-" + CurrentInput).Evaluate().ToString();
                break;

            case "MR":
                if (!String.IsNullOrEmpty(calcmemory))
                {
                    CurrentInput = calcmemory;
                }
                break;

            case "MC":
                calcmemory = "0";
                break;

            case ".":
                if (!CurrentInput.Contains("."))
                {
                    CurrentInput += ".";
                }
                break;

            case "=":
                NCalc.Expression exp = new NCalc.Expression(TextExpression + CurrentInput);
                TextExpression = string.Empty;
                CurrentInput   = exp.Evaluate().ToString();
                break;

            default:
                if (binaryOperationPressed)
                {
                    // if previous operation is bin operation to clear old input values
                    CurrentInput           = button;
                    binaryOperationPressed = false;
                }
                else
                {
                    CurrentInput = CurrentInput.TrimStart('0') + button;                             // add new value to display and remove start 0
                }
                break;
            }
        }
Exemplo n.º 16
0
 // it may be useful to store the current input, maybe...
 public void UpdateInput(T input)
 {
     CurrentInput.Clear();
     input.ForEach(e => CurrentInput.Add(e));
 }
Exemplo n.º 17
0
        public Task <CDataResult <CurrentDto> > GetCurrentInfo(CurrentInput input)
        {
            //throw new NotImplementedException();

            string sql = "select top 1 * from ViewCurrent";

            sql += " where StationName = '" + input.station_name + "'";
            sql += " order by time desc";
            var list = _sqlExecuter.SqlQuery <CurrentDataDto>(sql);

            var        dbResult = list.ToList();
            CurrentDto result   = new CurrentDto();

            if (dbResult.Count > 0)
            {
                var tempData = dbResult[0];
                result.Time        = tempData.Time;
                result.StationName = tempData.StationName;
                result.t2          = new CurrentItemDto()
                {
                    speed = tempData.t2_speed, direct = tempData.t2_direct
                };
                result.t4 = new CurrentItemDto()
                {
                    speed = tempData.t4_speed, direct = tempData.t4_direct
                };
                result.t6 = new CurrentItemDto()
                {
                    speed = tempData.t6_speed, direct = tempData.t6_direct
                };
                result.t8 = new CurrentItemDto()
                {
                    speed = tempData.t8_speed, direct = tempData.t8_direct
                };
                result.t10 = new CurrentItemDto()
                {
                    speed = tempData.t10_speed, direct = tempData.t10_direct
                };
                result.t12 = new CurrentItemDto()
                {
                    speed = tempData.t12_speed, direct = tempData.t12_direct
                };
                result.t14 = new CurrentItemDto()
                {
                    speed = tempData.t14_speed, direct = tempData.t14_direct
                };
                result.t16 = new CurrentItemDto()
                {
                    speed = tempData.t16_speed, direct = tempData.t16_direct
                };
                result.t18 = new CurrentItemDto()
                {
                    speed = tempData.t18_speed, direct = tempData.t18_direct
                };
                result.t20 = new CurrentItemDto()
                {
                    speed = tempData.t20_speed, direct = tempData.t20_direct
                };
                result.t22 = new CurrentItemDto()
                {
                    speed = tempData.t22_speed, direct = tempData.t22_direct
                };
                result.t24 = new CurrentItemDto()
                {
                    speed = tempData.t24_speed, direct = tempData.t24_direct
                };
                result.t26 = new CurrentItemDto()
                {
                    speed = tempData.t26_speed, direct = tempData.t26_direct
                };
                result.t28 = new CurrentItemDto()
                {
                    speed = tempData.t28_speed, direct = tempData.t28_direct
                };
                result.t30 = new CurrentItemDto()
                {
                    speed = tempData.t30_speed, direct = tempData.t30_direct
                };
                result.t32 = new CurrentItemDto()
                {
                    speed = tempData.t32_speed, direct = tempData.t32_direct
                };
                result.t34 = new CurrentItemDto()
                {
                    speed = tempData.t34_speed, direct = tempData.t34_direct
                };
                result.t36 = new CurrentItemDto()
                {
                    speed = tempData.t36_speed, direct = tempData.t36_direct
                };
                result.t38 = new CurrentItemDto()
                {
                    speed = tempData.t38_speed, direct = tempData.t38_direct
                };
                result.t40 = new CurrentItemDto()
                {
                    speed = tempData.t40_speed, direct = tempData.t40_direct
                };
                result.t42 = new CurrentItemDto()
                {
                    speed = tempData.t42_speed, direct = tempData.t42_direct
                };
                result.t44 = new CurrentItemDto()
                {
                    speed = tempData.t44_speed, direct = tempData.t44_direct
                };
                result.t46 = new CurrentItemDto()
                {
                    speed = tempData.t46_speed, direct = tempData.t46_direct
                };
                result.t48 = new CurrentItemDto()
                {
                    speed = tempData.t48_speed, direct = tempData.t48_direct
                };
                result.t50 = new CurrentItemDto()
                {
                    speed = tempData.t50_speed, direct = tempData.t50_direct
                };
                result.t52 = new CurrentItemDto()
                {
                    speed = tempData.t52_speed, direct = tempData.t52_direct
                };
                result.t54 = new CurrentItemDto()
                {
                    speed = tempData.t54_speed, direct = tempData.t54_direct
                };
                result.t56 = new CurrentItemDto()
                {
                    speed = tempData.t56_speed, direct = tempData.t56_direct
                };
                result.t58 = new CurrentItemDto()
                {
                    speed = tempData.t58_speed, direct = tempData.t58_direct
                };
                result.t60 = new CurrentItemDto()
                {
                    speed = tempData.t60_speed, direct = tempData.t60_direct
                };
            }

            return(Task.FromResult(new CDataResult <CurrentDto>()
            {
                IsSuccess = true,
                ErrorMessage = null,
                Data = result
            }));
        }
Exemplo n.º 18
0
            public static void DrawPatches(Rect left)
            {
                var lListing = new Listing_Standard();

                lListing.Begin(left);

                DubGUI.CenterText(() => lListing.Label("ProfilePatchMethod".Translate()));

                lListing.GapLine(6);
                DubGUI.OptionalBox(lListing.GetRect(Text.LineHeight + 3), "input.method".Translate(), () => input         = CurrentInput.Method, input == CurrentInput.Method);
                DubGUI.OptionalBox(lListing.GetRect(Text.LineHeight + 3), "input.type".Translate(), () => input           = CurrentInput.Type, input == CurrentInput.Type);
                DubGUI.OptionalBox(lListing.GetRect(Text.LineHeight + 3), "input.methodharmony".Translate(), () => input  = CurrentInput.MethodHarmony, input == CurrentInput.MethodHarmony);
                DubGUI.OptionalBox(lListing.GetRect(Text.LineHeight + 3), "input.typeharmony".Translate(), () => input    = CurrentInput.TypeHarmony, input == CurrentInput.TypeHarmony);
                DubGUI.OptionalBox(lListing.GetRect(Text.LineHeight + 3), "input.methodinternal".Translate(), () => input = CurrentInput.InternalMethod, input == CurrentInput.InternalMethod);
                DubGUI.OptionalBox(lListing.GetRect(Text.LineHeight + 3), "input.assembly".Translate(), () => input       = CurrentInput.Assembly, input == CurrentInput.Assembly);
                lListing.curY += 2;

                DisplayInputField(lListing);
                lListing.curY += 2;

                var box = lListing.GetRect(Text.LineHeight + 3);

                DubGUI.OptionalBox(box.LeftPart(.3f), "patch.type.tick".Translate(), () => patchType = UpdateMode.Tick, patchType == UpdateMode.Tick);
                box = box.RightPart(.65f);
                DubGUI.OptionalBox(box.LeftPart(.4f), "patch.type.update".Translate(), () => patchType = UpdateMode.Update, patchType == UpdateMode.Update);

                if (Widgets.ButtonText(box.RightPart(.5f), "patch".Translate()))
                {
                    if (currentInput != null)
                    {
                        ExecutePatch();
                    }
                }

                lListing.End();
            }
Exemplo n.º 19
0
        /// <summary>
        /// Read keyboard of user
        /// </summary>
        private void ReadUserInput()
        {
            while (true)
            {
                //Refresh input (here we should have nickname with empty input as it was reset at the end of the loop)
                RefreshUserInput();

                //Listen user keys
                ConsoleKeyInfo keyInfo;
                CurrentInput = "";
                do
                {
                    keyInfo = Console.ReadKey();

                    //If backspace, remove last character
                    if (keyInfo.Key == ConsoleKey.Backspace)
                    {
                        if (CurrentInput.Length > 0)
                        {
                            CurrentInput = CurrentInput.Remove(CurrentInput.Length - 1);
                            RefreshUserInput();
                        }
                        else
                        {
                            //if backspace and no user input, prevent cursor to be before beginning of input
                            // + 2 are for : and space character after nickname
                            Console.SetCursorPosition(NickName.Length + 2, Console.CursorTop);
                        }

                        continue;
                    }

                    //Don't allow control + any character
                    if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0)
                    {
                        continue;
                    }
                    if (char.IsControl(keyInfo.KeyChar))
                    {
                        continue;
                    }

                    //If different from enter, add it to current input
                    if (keyInfo.Key != ConsoleKey.Enter)
                    {
                        CurrentInput += keyInfo.KeyChar;
                    }
                }while (keyInfo.Key != ConsoleKey.Enter);

                //Clear current line (typed message will be displayed once the server got it and send it back to the client)
                ClearCurrentConsoleLine();

                //Handle chat command & exit if command stops the user input to be read
                if (InputIsCommand(CurrentInput))
                {
                    if (!HandleChatCommand(CurrentInput))
                    {
                        break;
                    }

                    //Clear current input after command handling
                    CurrentInput = "";
                    continue;
                }

                //Don't send empty messages
                if (CurrentInput.Length == 0)
                {
                    continue;
                }

                //Send message to the server
                ClientSocket.SendPacket(new ClientSendMessage(
                                            new ChatMessage
                {
                    Author  = NickName,
                    Message = CurrentInput
                }));

                //Reset current input
                CurrentInput = "";
            }
        }
Exemplo n.º 20
0
        public static void ExecutePatch(CurrentInput mode, string strinput, Category cat)
        {
            try
            {
                if (cat == Category.Tick)
                {
                    switch (mode)
                    {
                    case CurrentInput.Method:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersTick),
                                                          Utility.GetMethods(strinput));
                        break;

                    case CurrentInput.Type:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersTick),
                                                          Utility.GetTypeMethods(AccessTools.TypeByName(strinput)));
                        break;

                    case CurrentInput.MethodHarmony:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersTick),
                                                          Utility.GetMethodsPatching(strinput));
                        break;

                    case CurrentInput.SubClasses:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersTick),
                                                          Utility.SubClassImplementationsOf(AccessTools.TypeByName(strinput), m => true));
                        break;

                    case CurrentInput.TypeHarmony:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersTick),
                                                          Utility.GetMethodsPatchingType(AccessTools.TypeByName(strinput)));
                        break;

                    case CurrentInput.InternalMethod:
                        Utility.PatchInternalMethod(strinput, Category.Tick);
                        return;

                    case CurrentInput.Assembly:
                        Utility.PatchAssembly(strinput, Category.Tick);
                        return;
                    }

                    GUIController.Tab(Category.Tick).collapsed = false;
                    GUIController.SwapToEntry("Custom Tick");
                }
                else
                {
                    switch (mode)
                    {
                    case CurrentInput.Method:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersUpdate),
                                                          Utility.GetMethods(strinput));
                        break;

                    case CurrentInput.Type:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersUpdate),
                                                          Utility.GetTypeMethods(AccessTools.TypeByName(strinput)));
                        break;

                    case CurrentInput.MethodHarmony:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersUpdate),
                                                          Utility.GetMethodsPatching(strinput));
                        break;

                    case CurrentInput.SubClasses:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersUpdate),
                                                          Utility.SubClassImplementationsOf(AccessTools.TypeByName(strinput), m => true));
                        break;

                    case CurrentInput.TypeHarmony:
                        MethodTransplanting.UpdateMethods(typeof(CustomProfilersUpdate),
                                                          Utility.GetMethodsPatchingType(AccessTools.TypeByName(strinput)));
                        break;

                    case CurrentInput.InternalMethod:
                        Utility.PatchInternalMethod(strinput, Category.Update);
                        return;

                    case CurrentInput.Assembly:
                        Utility.PatchAssembly(strinput, Category.Update);
                        return;
                    }
                    GUIController.Tab(Category.Update).collapsed = false;
                    GUIController.SwapToEntry("Custom Update");
                }
            }
            catch (Exception e)
            {
                ThreadSafeLogger.Error($"Failed to process input, failed with the error {e.Message}");
            }
        }
Exemplo n.º 21
0
        public static Rect DisplayInputField(Listing_Standard listing)
        {
            string FieldDescription = null;

            switch (input)
            {
            case CurrentInput.Method:
                FieldDescription = "Type:Method";
                break;

            case CurrentInput.Type:
                FieldDescription = "Type";
                break;

            case CurrentInput.MethodHarmony:
                FieldDescription = "Type:Method";
                break;

            case CurrentInput.TypeHarmony:
                FieldDescription = "Type";
                break;

            case CurrentInput.InternalMethod:
                FieldDescription = "Type:Method";
                break;

            case CurrentInput.SubClasses:
                FieldDescription = "Type";
                break;

            case CurrentInput.Assembly:
                FieldDescription = "Mod or PackageId";
                break;
            }

            var descWidth = FieldDescription.GetWidthCached() + 20f;
            var rect      = listing.GetRect(Text.LineHeight + 8);
            var modeButt  = rect.LeftPartPixels(descWidth);
            var patchButt = rect.RightPartPixels(100f);
            var inputRect = rect;

            inputRect.width -= modeButt.width + patchButt.width;
            inputRect.x      = modeButt.xMax;

            if (Widgets.ButtonText(modeButt, FieldDescription))
            {
                var list = new List <FloatMenuOption>
                {
                    new FloatMenuOption(Strings.devoptions_input_method, () => input         = CurrentInput.Method),
                    new FloatMenuOption(Strings.devoptions_input_methodinternal, () => input = CurrentInput.InternalMethod),
                    new FloatMenuOption(Strings.devoptions_input_methodharmony, () => input  = CurrentInput.MethodHarmony),
                    new FloatMenuOption(Strings.devoptions_input_type, () => input           = CurrentInput.Type),
                    new FloatMenuOption(Strings.devoptions_input_subclasses, () => input     = CurrentInput.SubClasses),
                    new FloatMenuOption(Strings.devoptions_input_typeharmony, () => input    = CurrentInput.TypeHarmony),
                    new FloatMenuOption(Strings.devoptions_input_assembly, () => input       = CurrentInput.Assembly)
                };
                Find.WindowStack.Add(new FloatMenu(list));
            }

            DubGUI.InputField(inputRect, "profileinput", ref currentInput);

            if (input == CurrentInput.Method)
            {
                if (Widgets.ButtonText(patchButt.LeftHalf(), "Patch"))
                {
                    if (!string.IsNullOrEmpty(currentInput))
                    {
                        ExecutePatch(input, currentInput, patchType);
                    }
                }
                if (Widgets.ButtonText(patchButt.RightHalf(), "Save"))
                {
                    if (!string.IsNullOrEmpty(currentInput))
                    {
                        if (patchType == Category.Tick)
                        {
                            Settings.SavedPatches_Tick.Add(currentInput);
                        }
                        else
                        {
                            Settings.SavedPatches_Update.Add(currentInput);
                        }
                        Modbase.Settings.Write();
                        ExecutePatch(input, currentInput, patchType);
                    }
                }
            }
            else
            {
                if (Widgets.ButtonText(patchButt, "Patch"))
                {
                    if (!string.IsNullOrEmpty(currentInput))
                    {
                        ExecutePatch(input, currentInput, patchType);
                    }
                }
            }


            return(inputRect);
        }
Exemplo n.º 22
0
        private void Init()
        {
            ResetStatus();
            if (IsInDesignMode)
            {
                CurrentInput = "CurrentInput.TEXT55555555555555555555555555555555";
                LeftNumber   = "LeftNumber.TEXT88888888888888888888";
                RightNumber  = "RightNumber.TEXTTEXT55555555555555555555555555555555";
                Sign         = "+";
            }


            this.GetValueContainer(x => x.CurrentInput)
            .GetNewValueObservable()
            .Subscribe
            (
                nvp =>
            {
                switch (this.State)
                {
                case CalculatorState.InputingLeft:
                    this.LeftNumber = decimal.Parse(nvp.EventArgs).ToString();
                    break;

                case CalculatorState.InputingRight:
                    this.RightNumber = decimal.Parse(nvp.EventArgs).ToString();
                    break;

                default:
                    break;
                }
            }
            ).DisposeWith(this);

            this.CommandInputNumber
            .CommandCore
            .Where(e => e.EventArgs.Parameter.ToString() != ".")
            .Subscribe(
                e =>
            {
                if (State == CalculatorState.Finished)
                {
                    ResetStatus();
                }
                else if (State == CalculatorState.InputedSign)
                {
                    State = CalculatorState.InputingRight;
                    ResetPropertyValue(_IsPointed);
                    ResetPropertyValue(_CurrentInput);
                }
                string output = null;
                if (IsPointed)
                {
                    output = CurrentInput + e.EventArgs.Parameter.ToString();
                }
                else
                {
                    output = CurrentInput.TrimEnd('.') + e.EventArgs.Parameter.ToString() + '.';
                }

                if (!output.StartsWith("0."))
                {
                    CurrentInput = output.TrimStart('0');
                }
            }
                )
            .DisposeWith(this);


            this.CommandInputNumber
            .CommandCore
            .Where(e => e.EventArgs.Parameter.ToString() == ".")
            .Subscribe(e => IsPointed = true)
            .DisposeWith(this);


            this.CommandBackspace
            .CommandCore
            .Where(e => IsPointed && CurrentInput.EndsWith("."))
            .Subscribe(_ => IsPointed = false)
            .DisposeWith(this);

            this.CommandBackspace
            .CommandCore
            .Where(e => !(IsPointed && CurrentInput.EndsWith(".")))
            .Subscribe(
                e =>
            {
                var tempv = CurrentInput;
                if (tempv.Trim('-').Length > 2)
                {
                    CurrentInput = tempv.Substring(tempv.Length - 1);
                }
                else
                {
                    ResetPropertyValue(_CurrentInput);
                }
            }
                );

            this.CommandInputSign
            .CommandCore
            .Subscribe(
                e =>
            {
                this.Sign = e.EventArgs.Parameter.ToString();
                if (State == CalculatorState.Finished)
                {
                    LeftNumber  = CurrentInput;
                    RightNumber = "0.";
                }
                State = CalculatorState.InputedSign;
            }
                )
            .DisposeWith(this);

            this.CommandClear
            .CommandCore
            .Subscribe(
                e =>
            {
                ResetStatus();
            }
                )
            .DisposeWith(this);
            this.CommandCalculate.CommandCore
            .Where(
                e => State == CalculatorState.InputingRight || State == CalculatorState.Finished
                )
            .Subscribe
            (
                e =>
            {
                if (State == CalculatorState.Finished)
                {
                    LeftNumber = Result;
                }
                State          = CalculatorState.Calculating;
                var left       = decimal.Parse(LeftNumber);
                var right      = decimal.Parse(RightNumber);
                decimal result = 0;
                switch (Sign)
                {
                case "+":

                    result = left + right;
                    break;

                case "-":

                    result = left - right;
                    break;

                case "*":

                    result = left * right;
                    break;

                case "/":
                    result = left / right;
                    break;

                default:
                    break;
                }
                Result = result.ToString();

                IsPointed    = Result.Contains(".");
                CurrentInput = IsPointed ? Result : Result + ".";
                State        = CalculatorState.Finished;
            }

            )
            .DisposeWith(this);

            this.CommandChangeSignOfCurrentInput
            .CommandCore
            .Subscribe(
                e =>
            {
                var tmpv = (-decimal.Parse(CurrentInput)).ToString();

                if (State == CalculatorState.Finished)
                {
                    ResetStatus();
                }
                CurrentInput = tmpv.Contains(".") ? tmpv : tmpv + '.';
            }
                )
            .DisposeWith(this);
        }