Beispiel #1
0
 //Shows an upgrade available message after login if the server provides a upload available message string
 internal void show_upgrade_available_message(string message)
 {
     if (!String.IsNullOrEmpty(message))
     {
         DryDialog dialog = show_dialog((d) => {
             v_section(w => {
                 label("A new version of the KerbalXAPI is available");
                 label(message);
                 section("dialog.section", () => {
                     button("visit KerbalX to download the latest version", "hyperlink", () => {
                         Application.OpenURL(api.url_to("KXAPI"));
                     });
                 });
                 section(w2 => {
                     button("Remind me later", close_dialog);
                     button("Don't notify me about this update", () => {
                         api.dismiss_current_update_notification();
                         close_dialog();
                     });
                 });
             });
         });
         dialog.window_title = "KerbalX API - Update Available";
         dialog.window_pos   = new Rect(window_pos.x + window_pos.width + 10, window_pos.y, 400f, 5);
     }
 }
Beispiel #2
0
        private void post_login_message()
        {
            DryDialog dialog = show_dialog((d) => {
                string message = "The KerbalX.key file is a token that is used to authenticate you with KerbalX.com." +
                                 "\nIt will persist your login, so next time you start KSP you won't need to login again." +
                                 "\nIf you want to login to KerbalX from multiple KSP installs, copy the KerbalX.key file into each install.";
                label(message);
                button("OK", close_dialog);
            });

            dialog.window_title = "KerbalX Token File";
            dialog.window_pos   = new Rect(window_pos.x + window_pos.width + 10, window_pos.y, 350f, 5);
        }
Beispiel #3
0
        private void show_usage()
        {
            DryDialog dialog = show_dialog((d) => {
                label("The following mods have requested KerbalX access", "h3");
                label("note: this only shows the mods that have requested KerbalX access so far, as you play KSP other mods may request access", "small");
                foreach (KeyValuePair <string, KerbalXAPI> api_instance in KerbalXAPI.instances)
                {
                    label(api_instance.Key, "compact");
                }
                fspace();
                button("close", close_dialog);
            });

            dialog.window_title = "KerbalX API Usage";
            dialog.window_pos   = new Rect(window_pos.x + window_pos.width + 10, window_pos.y, 450f, 5);
        }
        protected DryDialog show_dialog(string title, string heading, float top, float left, float dialog_width, bool modal, InnerDialogContent content)
        {
            close_dialog();
            string response    = "";
            string err_msg     = "";
            int    focus_count = 5;
            //wrapper for the given content which adds some of the common functionality
            DialogContent dc = new DialogContent(d => {
                //close on escape key press
                Event e = Event.current;
                if (e.type == EventType.KeyDown && e.keyCode == KeyCode.Escape)
                {
                    close_dialog();
                }

                //main dialog
                style_override = "dialog.section";
                v_section(() => {
                    if (!String.IsNullOrEmpty(heading))
                    {
                        label(heading, "h2");
                    }
                    if (!String.IsNullOrEmpty(err_msg))
                    {
                        label(err_msg, "error");
                    }                                                               //display error message if any
                    response = content(d);                                          //render main dialog content which will return a response string.
                    if (!String.IsNullOrEmpty(response) && response != "200")       //collect any error message returned (as next pass response will be empty again).
                    {
                        err_msg = response;
                    }
                });

                //autofocus on textfield/area - the reason for the focous_count countdown is because we only want to focus on the field just after creating the dialog
                //but one the first (few) passes it doesn't appear to be ready, so this slightly hacky solution keeps setting the focus for first 5 passes.
                if (focus_count > 0)
                {
                    auto_focus_field = "dialog_focus_field";
                    focus_count--;
                }
                //close dialog on OK response
                if (response == "200")
                {
                    close_dialog();
                }
            });

            if (modal)
            {
                ModalDialog dialog = gameObject.AddOrGetComponent <ModalDialog>();
                dialog.dialog_pos   = new Rect(left, top, dialog_width, 80f);
                dialog.window_title = title;
                dialog.content      = dc;
                dialog.skin         = CraftManager.skin;
                return(dialog);
            }
            else
            {
                DryDialog dialog = gameObject.AddOrGetComponent <DryDialog>();
                dialog.window_pos   = new Rect(left, top, dialog_width, 80f);
                dialog.window_title = title;
                dialog.content      = dc;
                dialog.skin         = CraftManager.skin;
                return(dialog);
            }
        }