Ejemplo n.º 1
0
 public void AddKey(Keys key)
 {
     if (!ValidKeys.Contains(key))
     {
         ValidKeys.Add(key);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Erzeugt ein neues ConfirmDialog-Objekt und initialisiert dieses mit dem zugehörigen IGameScreen-Objekt.
        /// Zudem ist die Angabe der Zeichenreihenfolge Pflicht.
        /// </summary>
        public ComboBox(IScreen screen, DisplayLayer drawOrder, string text)
            : base(screen, drawOrder, String.Empty)
        {
            dropdown = new Menu(screen: screen, drawOrder: Index + DisplayLayer.Menu);
            dropdown.Bounds.Position     = ValueBounds.Position;
            dropdown.Bounds.Size         = new ScreenPoint(Screen, () => ValueBounds.Size.OnlyX + ValueBounds.Size.OnlyY * 10);
            dropdown.ItemForegroundColor = Design.ComboBoxItemForegroundColorFunc; // (s) => Container.ItemForegroundColor (s);
            dropdown.ItemBackgroundColor = Design.ComboBoxItemBackgroundColorFunc; // (s) => Design.WidgetBackground;
            dropdown.BackgroundColorFunc = (s) => Design.WidgetBackground;
            dropdown.ItemAlignX          = HorizontalAlignment.Left;
            dropdown.ItemAlignY          = VerticalAlignment.Center;
            dropdown.IsVisible           = false;
            dropdownBorder = new Border(
                screen: screen,
                drawOrder: Index + DisplayLayer.Menu,
                widget: dropdown,
                lineWidth: 2,
                padding: 2
                );

            currentValue        = new InputItem(screen: screen, drawOrder: Index, text: text, inputText: String.Empty);
            currentValue.Bounds = Bounds;
            currentValue.ForegroundColorFunc      = (s) => ForegroundColor;
            currentValue.BackgroundColorFunc      = (s) => Color.Transparent;
            currentValue.IsVisible                = IsVisible;
            currentValue.IsMouseClickEventEnabled = false;

            ValidKeys.Add(Keys.Escape);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Erzeugt ein neues InputItem-Objekt und initialisiert dieses mit dem zugehörigen IGameScreen-Objekt.
 /// Zudem sind Angaben zur Zeichenreihenfolge und für evtl. bereits vor-eingetragenen Text Pflicht.
 /// </summary>
 public InputItem(IScreen screen, DisplayLayer drawOrder, string text, string inputText)
     : base(screen, drawOrder, text)
 {
     InputText = inputText;
     ValidKeys.AddRange(TextHelper.ValidKeys);
     ValidKeys.Add(Keys.Enter);
     IsInputEnabled = false;
 }
Ejemplo n.º 4
0
        public GameObject SpawnWeighted(Vector3 position, Quaternion rotation, params string[] ValidKeys)
        {
            int ChooseIndex(float[] probs)
            {
                float total = 0;

                foreach (float elem in probs)
                {
                    total += elem;
                }

                float randomPoint = Random.value * total;

                for (int i = 0; i < probs.Length; i++)
                {
                    if (randomPoint < probs[i])
                    {
                        return(i);
                    }
                    else
                    {
                        randomPoint -= probs[i];
                    }
                }
                return(probs.Length - 1);
            }

            RecycleBin[] validBins = runtimeRecycleBins.Where((KeyValuePair <string, RecycleBin> recycleBinItem)
                                                              => ValidKeys.Any((string key) => key.Equals(recycleBinItem.Key))).
                                     Select((KeyValuePair <string, RecycleBin> recycleBinItem) => recycleBinItem.Value).ToArray();

            if (validBins == null || validBins.Length <= 0)
            {
                Debug.LogError($"[{GetType().Name}] No Valid ObjectPool found with the given keys.");
                return(null);
            }

            int[] priorities  = validBins.Select((RecycleBin bb) => bb.Priority).ToArray();
            int   total_value = priorities.Sum();

            float[] probabilities = priorities.Select((int priority) => (priority / (float)total_value)).ToArray();

            RecycleBin selected_bin = validBins[ChooseIndex(probabilities)];

            GameObject clone = selected_bin.Spawn(position, rotation);

            if (clone != null)
            {
                int _id = clone.GetInstanceID();

                if (!ObjectPoolData.ContainsKey(_id))
                {
                    ObjectPoolData.Add(_id, selected_bin.Label);
                }
            }

            return(clone);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Erzeugt ein neues ConfirmDialog-Objekt und initialisiert dieses mit dem zugehörigen IGameScreen-Objekt.
        /// Zudem sind Angaben zur Zeichenreihenfolge, einer Zeichenkette für den Titel und für den eingeblendeten Text Pflicht.
        /// [base=screen, drawOrder, title, text]
        /// </summary>
        public ConfirmDialog(IScreen screen, DisplayLayer drawOrder, string title)
            : base(screen, drawOrder, title)
        {
            // Der Titel-Text ist mittig ausgerichtet
            AlignX = HorizontalAlignment.Center;

            Cancel = (time) => {
                Close(time);
            };
            Submit = (time) => {
                Close(time);
            };

            // Keys
            ValidKeys.AddRange(new Keys[] { Keys.Enter, Keys.Escape });

            // Menü, in dem die Textanzeige angezeigt wird
            menu        = new Menu(Screen, Index + DisplayLayer.Menu);
            menu.Bounds = ContentBounds;
            menu.ItemForegroundColor = (s) => Color.White;
            menu.ItemBackgroundColor = (s) => Color.Transparent;
            menu.ItemAlignX          = HorizontalAlignment.Left;
            menu.ItemAlignY          = VerticalAlignment.Center;

            // Button-Container
            buttons                     = new Container(screen, Index + DisplayLayer.Menu);
            buttons.ItemAlignX          = HorizontalAlignment.Center;
            buttons.ItemBackgroundColor = (s) => Design.DialogBackground;

            // Button zum Canceln
            Action <GameTime> cancelAction = (time) => {
                Cancel(time);
            };
            MenuEntry cancelButton = new MenuEntry(
                screen: Screen,
                drawOrder: Index + DisplayLayer.MenuItem,
                name: "Cancel",
                onClick: cancelAction
                );

            cancelButton.Bounds.Size     = new ScreenPoint(screen, () => ContentBounds.Size.Relative.X / 2, () => 0.05f);
            cancelButton.Bounds.Position = ContentBounds.Position + ContentBounds.Size.OnlyY
                                           - cancelButton.Bounds.Size.OnlyY;
            buttons.Add(cancelButton);

            // Button zum Submitten
            Action <GameTime> submitAction = (time) => {
                Submit(time);
            };
            MenuEntry submitButton = new MenuEntry(
                screen: Screen,
                drawOrder: Index + DisplayLayer.MenuItem,
                name: "Confirm",
                onClick: submitAction
                );

            submitButton.Bounds.Size     = new ScreenPoint(screen, () => ContentBounds.Size.Relative.X / 2, () => 0.05f);
            submitButton.Bounds.Position = ContentBounds.Position + ContentBounds.Size.OnlyY
                                           - submitButton.Bounds.Size.OnlyY + ContentBounds.Size.OnlyX / 2;
            buttons.Add(submitButton);

            // Buttons zum Menü hinzufügen
            menu.Add(buttons);
        }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerDocument(config => config.PostProcess = document =>
            {
                document.Info.Version     = "v1.0.0";
                document.Info.Title       = "Status Monitor API";
                document.Info.Description = "An API to record status updates and manage configuration for status monitors";
                document.Info.Contact     = new OpenApiContact()
                {
                    Name = "Oregon Youth Authority"
                };
            });

            services.AddControllers();
            services.AddRazorPages();
            services.Configure <StatusMonitorDatabaseSettings>(Configuration.GetSection(nameof(StatusMonitorDatabaseSettings)));
            services.AddSingleton <IStatusMonitorDatabaseSettings>(sp => sp.GetRequiredService <IOptions <StatusMonitorDatabaseSettings> >().Value);

            services.AddTransient <IStatusRepository <StatusMonitorReply>, StatusMonitorMongoRepository <StatusMonitorReply> >();
            services.AddTransient <IMonitorConfigurationRepository <MonitorConfiguration>, MonitorConfigurationMongoRepository <MonitorConfiguration> >();

            services.AddHostedService <DataCleanupBackgroundService>();
            services.AddHostedService <OfflineMonitorsBackgroundService>();

            services.AddIdentityMongoDbProvider <AppUser, AppRole>(identityOptions =>
            {
                identityOptions.SignIn.RequireConfirmedAccount  = false;
                identityOptions.Password.RequiredLength         = 6;
                identityOptions.Password.RequireLowercase       = false;
                identityOptions.Password.RequireUppercase       = false;
                identityOptions.Password.RequireNonAlphanumeric = false;
                identityOptions.Password.RequireDigit           = false;
            }, mongoIdentityOptions =>
            {
                mongoIdentityOptions.UseDefaultIdentity = true;
                mongoIdentityOptions.ConnectionString   = Configuration["StatusMonitorDatabaseSettings:ConnectionString"];
            })
            .AddRoleManager <RoleManager <AppRole> >()
            .AddDefaultUI();

            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme;
                options.DefaultChallengeScheme    = IdentityConstants.ApplicationScheme;
                options.DefaultSignInScheme       = IdentityConstants.ExternalScheme;
            })
            .AddGoogle(options =>
            {
                IConfigurationSection googleConfig = Configuration.GetSection("Authentication:Google");
                options.ClientId     = googleConfig["ClientId"];
                options.ClientSecret = googleConfig["ClientSecret"];
            })
            .AddLinkedIn(options =>
            {
                var linkedinConfig   = Configuration.GetSection("Authentication:LinkedIn");
                options.ClientId     = linkedinConfig["ClientId"];
                options.ClientSecret = linkedinConfig["ClientSecret"];
            })
            //.AddMicrosoftAccount(microsoftOptions =>
            //{
            //   microsoftOptions.ClientId = Configuration["Authentication:Microsoft:ClientId"];
            //   microsoftOptions.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
            //})
            .AddApiKey(options =>
            {
                options.Header    = "X-API-KEY";
                options.HeaderKey = String.Empty;
                options.Events    = new ApiKeyEvents
                {
                    OnAuthenticationFailed = context =>
                    {
                        var ex = context.Exception;

                        Trace.TraceError(ex.Message);

                        context.Fail(ex);

                        return(Task.CompletedTask);
                    },
                    OnApiKeyValidated = context =>
                    {
                        if (!ValidKeys.Contains(context.ApiKey))
                        {
                            return(Task.CompletedTask);
                        }

                        context.Success();

                        return(Task.CompletedTask);
                    }
                };
            });
        }