예제 #1
0
        public UIDesigner(int id, int width, int height, UIComponent[] comps)
        {
            form = this;

            this.id     = id;
            this.width  = width;
            this.height = height;
            if (comps != null)
            {
                _components = comps.ToList();
            }

            InitializeComponent();

            //Add the form events
            form.Activated   += Form_Activated;
            form.FormClosing += Form_FormClosing;
            form.Load        += UIDesigner_Load;

            UIPanel.Size = new Size(width, height);

            #region RenderScript Core
            browser = new ChromiumWebBrowser("");

            form.Controls.Add(browser);
            browser.Dock = DockStyle.Fill;

            browser.LoadingStateChanged += (object s, LoadingStateChangedEventArgs er) =>
            {
                if (!er.IsLoading && browser.Address != FAKE_ADDR)
                {
                    if (queueCallback.Count > 0)
                    {
                        queueCallback[0](Crop(new Bitmap(Base64ToImage(browser.Address.Replace("data:image/png;base64,", "")))), queueCallback.Count - 1 > 0 ? queueCallback.Count - 1 : 0);
                        if (queueCallback.Count > 0)
                        {
                            queueCallback.RemoveAt(0);
                        }
                        if (queueScript.Count > 0)
                        {
                            browser.LoadHtml(queueScript[0], FAKE_ADDR);
                            queueScript.RemoveAt(0);
                        }
                    }
                }
            };
            #endregion

            #region Load the templates
            steps = 0;

            //Load the templates
            if (templates == null)
            {
                templates = new List <ComponentTemplate>();
                if (Directory.Exists(Application.StartupPath + @"\Resources\Templates"))
                {
                    string[] files = Directory.GetFiles(Application.StartupPath + @"\Resources\Templates", "*.js");
                    loadingForm = new LoadingForm("Load in progress: ", "%");
                    foreach (string file in files)
                    {
                        steps++;
                        ComponentTemplate cT = new ComponentTemplate();
                        cT.Name = Path.GetFileNameWithoutExtension(file);
                        cT.Path = file;
                        cT.Data = File.ReadAllText(file);
                        RenderScript(cT.Data, (Image i, int count) => {
                            cT.Image = i;
                            LoadingForm.ProgressStep(form.steps, loadingForm);
                            if (count == 0)
                            {
                                loadingForm.SafeClose();
                                loadingForm = null;
                            }
                            ReloadImages();
                        });
                        templates.Add(cT);
                    }
                }
            }

            //Create Buttons
            for (int i = 0; i < templates.Count; i++)
            {
                ComponentTemplate t   = templates[i];
                Button            btn = new Button();
                btn.Size = new Size(80, 30);
                btn.Text = t.Image == null ? t.Name : "";
                if (t.Image != null)
                {
                    btn.BackgroundImage           = t.Image;
                    btn.FlatStyle                 = FlatStyle.Flat;
                    btn.FlatAppearance.BorderSize = 0;
                    btn.Text = "";
                    btn.Size = t.Image.Size;
                    if (t.Image.Size.Width > splitContainer1.Panel1.Width)
                    {
                        if (t.Image.Size.Width <= 200)
                        {
                            splitContainer1.SplitterDistance = t.Image.Size.Width + 6;
                        }
                        else
                        {
                            splitContainer1.SplitterDistance = 200;
                        }
                    }
                }
                btn.Parent    = flowLayoutPanel1;
                btn.BackColor = Color.Transparent;
                btn.Tag       = i.ToString();
                t.button      = btn;
                flowLayoutPanel1.Controls.Add(btn);
            }

            #endregion

            //Align
            FlowCenter();
            UICenter();
            ResetFocus();

            #region Load the Components
            if (_components.Count > 0 && loadingForm == null)
            {
                steps       = 0;
                loadingForm = new LoadingForm("Load in progress: ", "%");
            }
            //Load the Components
            for (int i = 0; i < _components.Count; i++)
            {
                UIComponent  u   = _components[i];
                CustomButton btn = new CustomButton();
                btn.Location = new Point(u.x, u.y);
                btn.Size     = new Size(80, 30);
                string name = UI.GetComponentNameFromScript(u.data);
                btn.Text      = name != null ? name : "Loading...";
                btn.Parent    = UIPanel;
                btn.BackColor = Color.Transparent;
                btn.Tag       = i.ToString();

                if (!string.IsNullOrWhiteSpace(u.data))
                {
                    string _width = UI.GetVariableFromScript(u.data, "width");
                    string _height = UI.GetVariableFromScript(u.data, "height");
                    string x = UI.GetVariableFromScript(u.data, "x");
                    string y = UI.GetVariableFromScript(u.data, "y");
                    int    w, h, _x, _y;
                    if (!string.IsNullOrWhiteSpace(_width) && !string.IsNullOrWhiteSpace(_height) &&
                        int.TryParse(_width, out w) && int.TryParse(_height, out h))
                    {
                        btn.Size = new Size(w, h);
                    }
                    if (!string.IsNullOrWhiteSpace(x) && !string.IsNullOrWhiteSpace(y) &&
                        int.TryParse(x, out _x) && int.TryParse(y, out _y))
                    {
                        btn.Location = new Point(_x, _y);
                    }
                }

                btn.Component = u;
                btn.BringToFront();
                #region Events
                btn.MouseDown += CustomButton_MouseDown;
                btn.MouseUp   += (object _sender, MouseEventArgs _e) =>
                {
                    CustomButton_UpdatePosition(btn);
                    btn.Moving = false;
                };
                btn.MouseMove   += CustomButton_MouseMove;
                btn.MouseLeave  += CustomButton_MouseLeave;
                btn.DoubleClick += CustomButton_DoubleClick;
                btn.GotFocus    += CustomButton_GotFocus;
                btn.LostFocus   += CustomButton_LostFocus;
                btn.MouseClick  += CustomButton_MouseClick;
                #endregion
                cButtons.Add(btn);
                UIPanel.Controls.Add(btn);
                form.steps++;
                RenderScript(u.data, (Image _i, int _count) => {
                    btn.BackgroundImage = _i;
                    LoadingForm.ProgressStep(form.steps, loadingForm);
                    if (_count == 0)
                    {
                        loadingForm.SafeClose();
                        loadingForm = null;
                    }
                    ReloadImages();
                });
            }

            #endregion

            #region Add the Templates' Events
            foreach (Control c in flowLayoutPanel1.Controls)
            {
                if (typeof(Button) == c.GetType())
                {
                    c.MouseDown += (object sender, MouseEventArgs e) => {
                        CustomButton b = CloneButton((Button)c);
                        b.Parent = form;
                        b.BringToFront();

                        b.Focus();
                        b.Moving = true;
                        Point _mp = form.PointToClient(Cursor.Position);
                        b.Location = new Point(_mp.X - b.Size.Width / 2, _mp.Y - b.Size.Height / 2);

                        #region Events
                        b.MouseUp += (object _sender, MouseEventArgs _e) =>
                        {
                            if (b.Parent != UIPanel)
                            {
                                Point bL  = b.Parent.PointToScreen(b.Location);
                                Point UIL = UIPanel.Parent.PointToScreen(UIPanel.Location);
                                if (bL.X > UIL.X && bL.X < UIL.X + UIPanel.Size.Width &&
                                    bL.Y > UIL.Y && bL.Y < UIL.Y + UIPanel.Size.Height)
                                {
                                    b.Parent   = UIPanel;
                                    b.Location = UIPanel.PointToClient(bL);
                                    cButtons.Add(b);
                                    if (b.Component == null)
                                    {
                                        UIComponent comp = new UIComponent();
                                        comp.x    = b.Location.X;
                                        comp.y    = b.Location.Y;
                                        comp.data = templates[int.Parse(b.Tag.ToString())].Data;
                                        comp.id   = _components.Count;
                                        _components.Add(comp);
                                        b.Component = comp;

                                        string path = GameConfig.path + @"\Codes\UIs\ui" + form.id + @"\components\component" + comp.id + ".js";
                                        Directory.CreateDirectory(Path.GetDirectoryName(path));
                                        using (StreamWriter w = new StreamWriter(path))
                                        {
                                            w.Write(comp.data);
                                        }
                                    }
                                }
                                else
                                {
                                    b.Parent.Controls.Remove(b);
                                    b.Dispose();
                                }
                            }
                            CustomButton_UpdatePosition(b);
                            b.Moving = false;
                        };
                        b.MouseDown   += CustomButton_MouseDown;
                        b.MouseMove   += CustomButton_MouseMove;
                        b.MouseLeave  += CustomButton_MouseLeave;
                        b.DoubleClick += CustomButton_DoubleClick;
                        b.GotFocus    += CustomButton_GotFocus;
                        b.LostFocus   += CustomButton_LostFocus;
                        b.MouseClick  += CustomButton_MouseClick;
                        #endregion
                    };
                }
            }
            #endregion
        }
예제 #2
0
        //Reload Stuff
        private void Form_Activated(object sender, EventArgs e)
        {
            if (browser.IsBrowserInitialized && loadingForm == null)
            {
                browser.Stop();
                queueCallback.Clear();
                queueScript.Clear();
                loadingForm = new LoadingForm("Load in progress: ", "%");
                steps       = 0;
                foreach (CustomButton b in cButtons)
                {
                    if (!IDEConfig.IsDefaultEditor)
                    {
                        string path = GameConfig.path + @"\Codes\UIs\ui" + form.id + @"\components\component" + b.Component.id + ".js";
                        if (File.Exists(path))
                        {
                            string r = File.ReadAllText(path);
                            if (r != b.Component.data || b.BackgroundImage == null)
                            {
                                if (r != b.Component.data)
                                {
                                    //Update the position from Code
                                    string x = UI.GetVariableFromScript(r, "x");
                                    string y = UI.GetVariableFromScript(r, "y");
                                    int    _x, _y;
                                    if (!string.IsNullOrWhiteSpace(x) && !string.IsNullOrWhiteSpace(y) &&
                                        int.TryParse(x, out _x) && int.TryParse(y, out _y))
                                    {
                                        form.Invoke(new MethodInvoker(() => { b.Location = new Point(_x, _y); }));
                                    }
                                }

                                b.Component.data = r;

                                form.steps++;
                                RenderScript(b.Component.data, (Image i, int count) =>
                                {
                                    b.BackgroundImage = i;
                                    LoadingForm.ProgressStep(form.steps, loadingForm);
                                    if (count == 0)
                                    {
                                        loadingForm.SafeClose();
                                        loadingForm = null;
                                    }
                                    ReloadImages();
                                });
                            }
                        }
                    }
                }
                if (steps > 0)
                {
                    loadingForm.Show();
                }
                else
                {
                    loadingForm.Dispose();
                    loadingForm = null;
                }
            }
            else if (loadingForm != null)
            {
                loadingForm.Focus();
            }
            ReloadImages();
        }
예제 #3
0
        public static void Build()
        {
            Find();
            if (!string.IsNullOrWhiteSpace(Path) && File.Exists(Path))
            {
                using (LoadingForm buildForm = new LoadingForm("Build in progress: ", "%"))
                {
                    Thread buildThread = new Thread(() =>
                    {
                        int steps = 10;
                        try
                        {
                            Directory.Delete(GameConfig.path + @"\Build\Win", true);
                        }
                        catch { }
                        LoadingForm.ProgressStep(steps, buildForm);
                        if (Builder.Build(true, GameConfig.path + @"\Build\Win\Resources"))
                        {
                            try
                            {
                                LoadingForm.ProgressStep(steps, buildForm);
                                string SDKPath = Application.StartupPath + @"\SDK";

                                //Meta information
                                string temp = File.ReadAllText(SDKPath + @"\JSGameIDE-Player\Properties\AssemblyInfo.cs");
                                temp        = MetaInfoChanger(temp, "[assembly: AssemblyTitle(\"", "\")]", GameConfig.name);
                                temp        = MetaInfoChanger(temp, "[assembly: AssemblyDescription(\"", "\")]", GameConfig.name);
                                temp        = MetaInfoChanger(temp, "[assembly: AssemblyProduct(\"", "\")]", GameConfig.name);
                                temp        = MetaInfoChanger(temp, "[assembly: AssemblyCompany(\"", "\")]", GameConfig.author);
                                temp        = MetaInfoChanger(temp, "[assembly: AssemblyCopyright(\"", "\")]", GameConfig.copyright);
                                LoadingForm.ProgressStep(steps, buildForm);

                                //Copy the icon
                                try
                                {
                                    File.Copy(GameConfig.path + @"\Resources\icon.ico", SDKPath + @"\JSGameIDE-Player\icon.ico", true);
                                }
                                catch { }
                                LoadingForm.ProgressStep(steps, buildForm);
                                using (StreamWriter w = new StreamWriter(SDKPath + @"\JSGameIDE-Player\Properties\AssemblyInfo.cs"))
                                {
                                    w.Write(temp);
                                }
                                LoadingForm.ProgressStep(steps, buildForm);

                                System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
                                info.FileName         = Path;
                                info.Arguments        = @"/p:Platform=x86 JSGameIDE-Player.sln";
                                info.WorkingDirectory = SDKPath;
                                info.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
                                System.Diagnostics.Process process = System.Diagnostics.Process.Start(info);
                                process.WaitForExit();
                                LoadingForm.ProgressStep(steps, buildForm);
                                DirectoryExtension.Copy(SDKPath + @"\JSGameIDE-Player\bin\x86\Debug", GameConfig.path + @"\Build\Win", true);
                                LoadingForm.ProgressStep(steps, buildForm);

                                //Cleans some trash
                                File.Delete(GameConfig.path + @"\Build\Win\JSGameIDE-Player.exe.config");
                                File.Delete(GameConfig.path + @"\Build\Win\JSGameIDE-Player.pdb");
                                File.Delete(GameConfig.path + @"\Build\Win\CefSharp.Core.xml");
                                File.Delete(GameConfig.path + @"\Build\Win\CefSharp.WinForms.xml");
                                File.Delete(GameConfig.path + @"\Build\Win\CefSharp.xml");
                                File.Delete(GameConfig.path + @"\Build\Win\devtools_resources.pak");
                                LoadingForm.ProgressStep(steps, buildForm);
                                try
                                {
                                    File.Move(GameConfig.path + @"\Build\Win\JSGameIDE-Player.exe", GameConfig.path + @"\Build\Win\" + GameConfig.name.Replace(' ', '-') + ".exe");
                                }
                                catch { }
                                LoadingForm.ProgressStep(steps, buildForm);
                                Directory.Delete(SDKPath + @"\JSGameIDE-Player\bin\x86", true);
                                LoadingForm.ProgressStep(steps, buildForm);

                                Thread.Sleep(200);

                                buildForm.SafeClose();
                                SystemSounds.Beep.Play();
                                MessageBox.Show("Build success", "Windows Builder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            catch
                            {
                                buildForm.SafeClose();
                                SystemSounds.Exclamation.Play();
                                MessageBox.Show("Build failure", "Windows Builder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            buildForm.SafeClose();
                            SystemSounds.Exclamation.Play();
                            MessageBox.Show("Build failure", "Windows Builder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    });
                    buildThread.Start();
                    buildForm.ShowDialog();
                }
            }
            else
            {
                SystemSounds.Asterisk.Play();
                MessageBox.Show("Build failure. Please ensure that the SDK is properly installed.", "Windows Builder", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }