Ejemplo n.º 1
0
        public static Widget SerializeTest()
        {
            var result = new Widget();

            result.Add(CommonWidgets.Button("serialize", new RectangleF(10, 10, 100, 40)), out var button);
            result.Add(CommonWidgets.Label("Native:", new RectangleF(20, 70, 200, 200), DrawText.XTextPositioningPolicy.left, DrawText.YTextPositioningPolicy.top));
            result.Add(CommonWidgets.Label("Loaded from XML:", new RectangleF(20, 220, 200, 200), DrawText.XTextPositioningPolicy.left, DrawText.YTextPositioningPolicy.top));

            button.OnClick += (s, a) => {
                //var test = new TestSerializeClass() { NameProperty = "property name", name_field = "name field" };
                //test.w_list.Add(new Widget());
                //XmlHelper.ToXmlFile(test, @"C:\Users\jamie\Desktop\New folder\test.xml");
                var unserialized = new Widget(170, 70, 140, 140);
                unserialized.Add(new Widget(40, 40, 100, 40), out var added_widget);
                added_widget.UserResizePolicy = Widget.UserResizePolicyType.allow;
                added_widget.Behaviors.Add(new GridFormat(2, 2), out var grid);
                grid[0, 1].Behaviors.Add(new DrawText("stuff"));
                unserialized.Behaviors.Add(new DrawText("Serialize this"));
                unserialized.SaveToXML(@"C:\Users\jamie\Desktop\New folder\test.xml");
                var deserialized = Widget.LoadFromXML(@"C:\Users\jamie\Desktop\New folder\test.xml");
                result.Add(deserialized);
                result.Add(unserialized);
                deserialized.Position = new Point2(170, 220);
            };

            return(result);
        }
Ejemplo n.º 2
0
        public static Widget LoginLayout(
            Action <LoginSignal> handle_login,
            Action <CreateAccountSignal> handle_account_creation = null
            )
        {
            var layout = new Widget {
            };

            layout.VisualSettings.ChangeColorOnMouseOver = false;
            layout.VisualSettings.DrawBackground         = false;

            var login_button = CommonWidgets.Button("Login");

            login_button.Position = new Point2(20, 20);
            login_button.Size     = new Point2(100, 40);
            login_button.OnClick += (s, a) => {
                if (layout["Login Window"] == null)
                {
                    layout.Add(LoginWindow(handle_login, handle_account_creation));
                }
            };

            layout.Add(login_button);
            layout.Behaviors.Add(new Neurons());
            layout.Behaviors.Add(ShadingBehavior.GlowingGreen);

            return(layout);
        }
Ejemplo n.º 3
0
        public static Widget WindowHandle(Widget handle)
        {
            var bar = new Widget();

            bar.Behaviors.GroupBehaviors.AcceptancePolicy.DisallowedIDs.Add(DownUnderBehaviorIDs.SCROLL_FUNCTION);

            var x_button     = CommonWidgets.ImageButton("DownUnder Native Content/Images/Window X", 0.5f);
            var __button     = CommonWidgets.ImageButton("DownUnder Native Content/Images/Window _", 0.5f);
            var rect_button  = CommonWidgets.ImageButton("DownUnder Native Content/Images/Window Rect", 0.5f);
            var control_grid = new Widget {
                Size = new MonoGame.Extended.Point2(70, 70)
            };

            control_grid.Add(__button);
            control_grid.Add(rect_button);
            control_grid.Add(x_button);

            control_grid.Behaviors.Add(new GridFormat(3, 1));
            control_grid.Size = new MonoGame.Extended.Point2(180, 40);

            __button.VisualSettings.DrawOutline     = false;
            rect_button.VisualSettings.DrawOutline  = false;
            x_button.VisualSettings.DrawOutline     = false;
            control_grid.VisualSettings.DrawOutline = false;

            __button.VisualSettings.DrawBackground     = false;
            rect_button.VisualSettings.DrawBackground  = false;
            x_button.VisualSettings.DrawBackground     = false;
            control_grid.VisualSettings.DrawBackground = false;

            var back_button = CommonWidgets.Button("Back");

            back_button.OnClick += (s, a) => back_button.ParentDWindow.Navigation.NavigateBack();
            bar.Add(back_button);

            bar.Add(control_grid);
            var text = new DrawText(handle.Window.Title ?? $"{nameof(DownUnder)} Window");

            handle.Window.ScreenDeviceNameChanged += (s, a) => text.Text = handle.Window.Title ?? $"{nameof(DownUnder)} Window";
            text.SideSpacing      = 8f;
            text.YTextPositioning = DrawText.YTextPositioningPolicy.center;
            bar.Behaviors.Add(text);

            bar.MinimumHeight = 40;

            x_button.OnClick += (s, a) => { handle.Delete(); };
            rect_button.Behaviors.Add(new TriggerWidgetAction(nameof(Widget.OnClick), new ToggleWindowFullscreen()));
            control_grid.Behaviors.Add(new PinWidget {
                Pin = InnerWidgetLocation.InsideTopRight
            });
            bar.Behaviors.Add(new TriggerWidgetAction(nameof(Widget.OnDoubleClick), new ToggleWindowFullscreen()));

            return(bar);
        }
Ejemplo n.º 4
0
        public static Widget WidgetTransitionTest()
        {
            var result      = new Widget();
            var button      = CommonWidgets.Button("Send to container");
            var test_widget = new Widget {
                Area = new RectangleF(10, 40, 200, 200)
            };

            test_widget.Behaviors.Add(new GridFormat(2, 2));

            button.OnClick += (s, a) => test_widget.Actions.Add(new ReplaceWidget(new Widget().WithAddedBehavior(new DrawText("New Widget")), InnerWidgetLocation.OutsideLeft, InnerWidgetLocation.OutsideRight));

            result.Add(button);
            result.Add(test_widget);
            return(result);
        }
Ejemplo n.º 5
0
        public static Widget LoginWindow(
            Action <LoginSignal> confirm_handle,
            Action <CreateAccountSignal> handle_account_creation = null
            )
        {
            const int login_create_spacing = 8 / 2;

            var window = new Widget {
                Size = new Point2(400, 300), Name = "Login Window"
            };

            window.VisualSettings.VisualRole = GeneralVisualSettings.VisualRoleType.pop_up;

            window.Behaviors.Add(new CenterContent());
            window.Behaviors.Add(new PinWidget {
                Pin = InnerWidgetLocation.Centered
            });
            window.Behaviors.Add(new PopInOut(RectanglePart.Uniform(0.975f), RectanglePart.Uniform(0.5f))
            {
                OpeningMotion = InterpolationSettings.Fast, ClosingMotion = InterpolationSettings.Fast
            });

            var username_entry = CommonWidgets.SingleLineTextEntry("", DrawText.XTextPositioningPolicy.left, DrawText.YTextPositioningPolicy.center, 8f);
            var password_entry = CommonWidgets.SingleLineTextEntry("", DrawText.XTextPositioningPolicy.left, DrawText.YTextPositioningPolicy.center, 8f);

            username_entry.Area = new RectangleF(100, 0, 150, 40);
            password_entry.Area = new RectangleF(100, 60, 150, 40);

            var username_label = CommonWidgets.Label("Username:"******"Password:"******"Login");

            login_button.Area = handle_account_creation != null
                ? new RectangleF(125 + login_create_spacing, 120, 125 - login_create_spacing, 40)
                : new RectangleF(100, 120, 150, 40);

            window.Add(username_label);
            window.Add(password_label);
            window.Add(username_entry);
            window.Add(password_entry);
            window.Add(login_button);

            void handleResponse(WidgetResponse response)
            {
                if (response.Reply != WidgetResponse.ResponseType.reject)
                {
                    return;
                }

                window.ParentDWindow.ShowPopUpMessage("Could not log in.\n\nError: " + response.Message);
            }

            login_button.OnClick += (s, a) =>
                                    confirm_handle.Invoke(new LoginSignal(
                                                              username_entry.Behaviors.Common.DrawText.Text,
                                                              password_entry.Behaviors.Common.DrawText.Text,
                                                              handleResponse
                                                              ));

            if (handle_account_creation == null)
            {
                return(window);
            }

            var create_account_button = CommonWidgets.Button("Create Account");

            create_account_button.Area = new RectangleF(0, 120, 125 - login_create_spacing, 40);

            void handleCreationResponse(WidgetResponse r)
            {
                if (r.Reply != WidgetResponse.ResponseType.reject)
                {
                    return;
                }

                window.ParentDWindow.ShowPopUpMessage("Error creating account: " + r.Message);
            }

            create_account_button.OnClick += (s, a) =>
                                             handle_account_creation.Invoke(
                new CreateAccountSignal(
                    username_entry.Behaviors.Common.DrawText.Text,
                    password_entry.Behaviors.Common.DrawText.Text,
                    "",
                    handleCreationResponse
                    )
                );

            window.Add(create_account_button);

            return(window);
        }