예제 #1
0
파일: EraProgram.cs 프로젝트: Riey/EraCS
        protected void Wait(InputRequest req, Action <long> tickAction = null)
        {
            long target = req.EndTime + CurrentTime;

            lock (inputLock)
            {
                currentInputReq = req;
            }

            while (true)
            {
                Task.Delay(WAIT_TIMEOUT).Wait();

                if (!IsWaiting)
                {
                    break;
                }

                tickAction?.Invoke(target - CurrentTime);

                if (currentInputReq.HasTimeout && target <= CurrentTime)
                {
                    OnTextEntered(currentInputReq.DefaultValue);
                    break;
                }
            }

            Console.DeActiveButtons();
        }
예제 #2
0
파일: EraProgram.cs 프로젝트: Riey/EraCS
        public void OnTextEntered(string value)
        {
            if (!IsWaiting)
            {
                return;
            }

            lock (inputLock)
            {
                if (currentInputReq.IsOneInput)
                {
                    value = value?[0].ToString();
                }

                switch (currentInputReq.InputType)
                {
                case InputType.ANYKEY:
                    LastInputValue = null;
                    break;

                case InputType.INT:
                    if (!int.TryParse(value, out var num))
                    {
                        return;
                    }
                    LastInputValue  = value;
                    LastInputNumber = num;
                    break;

                case InputType.STR:
                    if (value == null)
                    {
                        return;
                    }
                    LastInputValue = value;
                    break;

                default:
                    throw new ArgumentException("Invalid InputType");
                }

                currentInputReq = null;
            }
        }