Example #1
0
        public static new FloatBitmapGtk FromPPM(RawLoader ppm, ProgressReporter callback)
        {
            FloatBitmapGtk fbg = new FloatBitmapGtk();

            if (fbg.LoadDataFromPPM(ppm, callback))
            {
                return(fbg);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
    public static void SplitDFTiles()
    {
        var path  = EditorUtility.OpenFolderPanel("Pick Sprite Folder", "", "SpriteFolder");
        var files = Directory.GetFiles(path, "*.txt");

        foreach (var file in files)
        {
            Debug.Log("Loading Raw File: " + file);
            var tokenList       = RawLoader.SplitRawFileText(File.ReadAllText(file));
            var tokenEnumerator = tokenList.GetEnumerator();
            try
            {
                if (tokenEnumerator.MoveNext()) // Because they always start at -1.
                {
                    if (tokenEnumerator.Current.Token == "OBJECT")
                    {
                        switch (tokenEnumerator.Current.Parameters[0])
                        {
                        case "GRAPHICS":
                            var parser = ParseGraphics(tokenEnumerator, file);
                            while (parser.MoveNext())
                            {
                                ;
                            }
                            break;

                        default:
                            Debug.Log("Unhandled Token: " + tokenEnumerator.Current.Parameters[0]);
                            break;
                        }
                    }
                    else
                    {
                        Debug.Log("Unexpected Token: " + tokenEnumerator.Current.Token);
                    }
                }
            }
            finally
            {
                tokenEnumerator.Dispose();
            }
        }
    }
Example #3
0
    IEnumerator ParseContentRawFile(string path)
    {
        Debug.Log("Loading Raw File: " + path);

        var tokenList       = RawLoader.SplitRawFileText(File.ReadAllText(path));
        var tokenEnumerator = tokenList.GetEnumerator();

        try
        {
            if (tokenEnumerator.MoveNext()) // Because they always start at -1.
            {
                if (tokenEnumerator.Current.Token == "OBJECT")
                {
                    switch (tokenEnumerator.Current.Parameters[0])
                    {
                    case "GRAPHICS":
                        SpriteManager.ParseGraphics(ref tokenEnumerator, path);
                        break;

                    default:
                        Debug.Log("Unhandled Token: " + tokenEnumerator.Current.Parameters[0]);
                        break;
                    }
                }
                else
                {
                    Debug.Log("Unexpected Token: " + tokenEnumerator.Current.Token);
                }
            }
        }
        finally
        {
            tokenEnumerator.Dispose();
        }
        yield return(null);
    }
Example #4
0
        public static void Main(string[] args)
        {
            // Initializing remote control
            mRemoteControlService = new RemoteControlService("localhost", 21985);
            mRemoteControlService.RemoteCommandReceived += HandleRemoteControlServiceRemoteCommandReceived;

            // Parsing command line. Formulating command and it's arguments
            List <string> argslist = new List <string>(args);

            List <string>         commands           = new List <string>();
            List <List <string> > commands_arguments = new List <List <string> >();

            if (argslist.Contains("-q") || argslist.Contains("--queue"))
            {
                argslist.Remove("-q"); argslist.Remove("--queue");
                // Queue launch mode

                // Searching for "--default" option
                int d_inx = -1;
                d_inx = argslist.IndexOf("-d") >= 0 ? argslist.IndexOf("-d") : d_inx;
                d_inx = argslist.IndexOf("--default") >= 0 ? argslist.IndexOf("--default") : d_inx;
                string d_cestage_name = "";

                if (d_inx >= 0)
                {
                    if (d_inx < argslist.Count - 1)
                    {
                        d_cestage_name = argslist[d_inx + 1];
                        // Removing readed "-d"
                        argslist.RemoveRange(d_inx, 2);

                        if (!ReceiptsManager.IsReceipt(d_cestage_name))
                        {
                            Console.WriteLine("Incorrect argument: " + d_cestage_name + " is not a .cestage file.");
                            d_cestage_name = "";
                        }
                    }
                    else if (d_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: .cestage file name should be provided after --default or -d");
                        argslist.RemoveAt(d_inx);
                    }
                }

                // Searching for "--target-type"
                int tt_inx = -1;
                tt_inx = argslist.IndexOf("-t") >= 0 ? argslist.IndexOf("-t") : tt_inx;
                tt_inx = argslist.IndexOf("--target-type") >= 0 ? argslist.IndexOf("--target-type") : tt_inx;
                string target_type = "";

                if (tt_inx >= 0)
                {
                    if (tt_inx < argslist.Count - 1)
                    {
                        target_type = argslist[tt_inx + 1];
                        // Removing readed "-t"
                        argslist.RemoveRange(tt_inx, 2);

                        if (target_type != "jpeg" && target_type != "png" && target_type != "bmp")
                        {
                            Console.WriteLine("Incorrect target type specified: " + target_type + ". It should be \"jpeg\", \"png\" or \"bmp\".");
                            target_type = "";
                        }
                    }
                    else if (tt_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: target type should be provided after --target-type or -t");
                        argslist.RemoveAt(tt_inx);
                    }
                }

                // Searching for "--prescale"
                int p_inx = -1;
                p_inx = argslist.IndexOf("-p") >= 0 ? argslist.IndexOf("-p") : p_inx;
                p_inx = argslist.IndexOf("--prescale") >= 0 ? argslist.IndexOf("--prescale") : p_inx;
                int prescale = 2;

                if (p_inx >= 0)
                {
                    if (p_inx < argslist.Count - 1)
                    {
                        if (!int.TryParse(argslist[p_inx + 1], out prescale) || prescale < 1 || prescale > 8)
                        {
                            Console.WriteLine("Incorrect prescale value specified: " + argslist[p_inx + 1] + ". It should be an integer value from 1 to 8.");
                        }

                        // Removing readed "-t"
                        argslist.RemoveRange(p_inx, 2);
                    }
                    else if (p_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: prescale should be provided after --prescale or -p");
                        argslist.RemoveAt(p_inx);
                    }
                }

                // Now when all the additional parameters are parsed and removed,
                // we're analysing, what's left. The options:
                if (argslist.Count == 2 && ((ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1])) ||
                                            (ReceiptsManager.IsReceipt(argslist[1]) && RawLoader.IsRaw(argslist[0]))))
                {
                    // Two file names: one cestage and one raw

                    string cestage_filename;
                    string raw_filename;
                    if (ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1]))
                    {
                        cestage_filename = argslist[0];
                        raw_filename     = argslist[1];
                    }
                    else                     // if (IsCEStageFile(argslist[1]) && DCRawConnection.IsRaw(argslist[0]))
                    {
                        cestage_filename = argslist[1];
                        raw_filename     = argslist[0];
                    }

                    // Guessing target filename
                    if (target_type == "")
                    {
                        target_type = "jpeg";
                    }
                    string target_name = System.IO.Path.ChangeExtension(raw_filename, target_type);
                    target_name = CheckIfFileExistsAndAddIndex(target_name);

                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("AddToQueue");
                    commands_arguments.Add(new List <string>(new string[]
                    {
                        cestage_filename,
                        raw_filename,
                        target_name,
                        target_type,
                        prescale.ToString()
                    }));
                }
                else
                {
                    // Searching for cestage for each raw and for raws for each cestage
                    for (int i = 0; i < argslist.Count; i++)
                    {
                        if (RawLoader.IsRaw(argslist[i]))
                        {
                            // The current file is a raw

                            // Guessing target filename
                            if (target_type == "")
                            {
                                target_type = "jpeg";
                            }
                            string target_name = System.IO.Path.ChangeExtension(argslist[i], target_type);
                            target_name = CheckIfFileExistsAndAddIndex(target_name);

                            string[] cestages = ReceiptsManager.FindReceiptsForRaw(argslist[i]);
                            if (cestages.Length > 0)
                            {
                                // At least one found

                                // Launching StageEditor with the cestage file and the raw file
                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    cestages[0],
                                    argslist[i],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));
                            }
                            else if (d_cestage_name != "")
                            {
                                // Nothing found, but default name is present
                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    d_cestage_name,
                                    argslist[i],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));
                            }
                            else
                            {
                                Console.WriteLine("Can't open " + argslist[i] + ": can't find it's .cestage file");
                            }
                        }
                        else if (ReceiptsManager.IsReceipt(argslist[i]))
                        {
                            // The current file is a cestage

                            // Guessing target filename
                            if (target_type == "")
                            {
                                target_type = "jpeg";
                            }
                            string target_name = System.IO.Path.ChangeExtension(argslist[i], target_type);
                            target_name = CheckIfFileExistsAndAddIndex(target_name);

                            string[] raws = new string[] {};
                            try
                            {
                                raws = ReceiptsManager.FindRawsForReceipt(argslist[i]);
                            }
                            catch (System.IO.DirectoryNotFoundException dnfe)
                            {
                                Console.WriteLine("Error: " + dnfe.Message);
                            }
                            if (raws.Length > 0)
                            {
                                // At least one found

                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    argslist[i],
                                    raws[0],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));
                            }
                            else
                            {
                                Console.WriteLine("Can't open " + argslist[i] + ": can't find it's raw file");
                            }
                        }
                    }
                }
            }
            else
            {
                // Not a queue launch mode

                // If we don't have 1 cestage and 1 raw, let's open as many windows as possible.

                // But, at first, trying to find "--default" option
                int d_inx = -1;
                d_inx = argslist.IndexOf("-d") >= 0 ? argslist.IndexOf("-d") : d_inx;
                d_inx = argslist.IndexOf("--default") >= 0 ? argslist.IndexOf("--default") : d_inx;
                string d_cestage_name = "";

                if (d_inx >= 0)
                {
                    if (d_inx < argslist.Count - 1)
                    {
                        d_cestage_name = argslist[d_inx + 1];
                        // Removing readed "-d"
                        argslist.RemoveRange(d_inx, 2);

                        if (!ReceiptsManager.IsReceipt(d_cestage_name))
                        {
                            Console.WriteLine("Incorrect argument: " + d_cestage_name + " is not a .cestage file.");
                            d_cestage_name = "";
                        }
                    }
                    else if (d_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: .cestage file name should be provided after --default or -d");
                        argslist.RemoveAt(d_inx);
                    }
                }

                // Searching for "--prescale"
                int p_inx = -1;
                p_inx = argslist.IndexOf("-p") >= 0 ? argslist.IndexOf("-p") : p_inx;
                p_inx = argslist.IndexOf("--prescale") >= 0 ? argslist.IndexOf("--prescale") : p_inx;
                int prescale = 2;

                if (p_inx >= 0)
                {
                    if (p_inx < argslist.Count - 1)
                    {
                        if (!int.TryParse(argslist[p_inx + 1], out prescale) || prescale < 1 || prescale > 8)
                        {
                            Console.WriteLine("Incorrect prescale value specified: " + argslist[p_inx + 1] + ". It should be an integer value from 1 to 8.");
                        }

                        // Removing readed "-p"
                        argslist.RemoveRange(p_inx, 2);
                    }
                    else if (p_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: prescale should be provided after --prescale or -p");
                        argslist.RemoveAt(p_inx);
                    }
                }

                if (argslist.Count == 2 && ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1]))
                {
                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("StageEditor_CEStage_RAW");
                    commands_arguments.Add(new List <string>(new string[]
                    {
                        argslist[0],
                        argslist[1],
                        prescale.ToString()
                    }));
                }
                else
                if (argslist.Count == 2 && ReceiptsManager.IsReceipt(argslist[1]) && RawLoader.IsRaw(argslist[0]))
                {
                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("StageEditor_CEStage_RAW");
                    commands_arguments.Add(new List <string>(new string[]
                    {
                        argslist[1],
                        argslist[0],
                        prescale.ToString()
                    }));
                }
                else
                {
                    // Searching for cestage for each raw and for raws for each cestage
                    for (int i = 0; i < argslist.Count; i++)
                    {
                        if (RawLoader.IsRaw(argslist[i]))
                        {
                            // The current file is a raw

                            if (d_cestage_name != "")
                            {
                                // Nothing found, but default name is present
                                commands.Add("StageEditor_CEStage_RAW");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    d_cestage_name,
                                    argslist[i],
                                    prescale.ToString()
                                }));
                            }
                            else
                            {
                                commands.Add("StageEditor_RAW");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    argslist[i],
                                    prescale.ToString()
                                }));
                            }
                        }
                        else if (ReceiptsManager.IsReceipt(argslist[i]))
                        {
                            // The current file is a cestage

                            string[] raws = ReceiptsManager.FindRawsForReceipt(argslist[i]);
                            if (raws.Length > 0)
                            {
                                // At least one found
                                // Launching StageEditor with the cestage file and the raw file
                                commands.Add("StageEditor_CEStage_RAW");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    argslist[i],
                                    raws[0],
                                    prescale.ToString()
                                }));
                            }
                            else if (raws.Length == 0)
                            {
                                Gtk.MessageDialog md = new Gtk.MessageDialog(
                                    null, DialogFlags.Modal,
                                    MessageType.Error, ButtonsType.Ok,
                                    false, "Can't find raw file for {0}", argslist[i]);

                                md.Title = MainClass.APP_NAME;

                                md.Run();
                                md.Destroy();
                            }
                            else                             // raws.Length > 1
                            {
                                Gtk.MessageDialog md = new Gtk.MessageDialog(
                                    null, DialogFlags.Modal,
                                    MessageType.Error, ButtonsType.Ok,
                                    false, "More than one raw file found for {0}", argslist[i]);

                                md.Title = MainClass.APP_NAME;

                                md.Run();
                                md.Destroy();
                            }
                        }
                    }
                }
            }

            bool ownServerStarted = mRemoteControlService.Start();

            if (ownServerStarted)
            {
                string mylocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location);
                windowsGtkStyle = new WindowsGtkStyle(mylocation +
                                                      Path.DirectorySeparatorChar +
                                                      "res" +
                                                      Path.DirectorySeparatorChar +
                                                      "win-gtkrc");
                Application.Init();

                // Creating render queue and its window
                mRenderingQueue       = new RenderingQueue();
                mRenderingQueueWindow = new RenderingQueueWindow(mRenderingQueue);
                mRenderingQueue.StartThread();
            }

            // No files asked
            if (commands.Count == 0)
            {
                // No command line arguments passed.
                // Sending the "StageEditor" command with no arguments
                commands.Add("StageEditor");
                commands_arguments.Add(new List <string>());
            }

            // Sending the commands
            List <string> packed_commands = new List <string>();

            for (int i = 0; i < commands.Count; i++)
            {
                packed_commands.Add(RemoteControlService.PackCommand(commands[i], commands_arguments[i].ToArray()));
            }
            mRemoteControlService.SendCommands(packed_commands.ToArray());


            if (ownServerStarted)
            {
                GLib.Idle.Add(delegate {
                    // Checking if something is already started
                    if (RenderingQueue.IsProcessingItem || StageEditorWindows.Count > 0)
                    {
                        mLoadedSomethingAlready = true;
                    }

                    // Removing all destroyed
                    StageEditorWindows.RemoveAll(delegate(StageEditorWindow wnd)
                    {
                        return(wnd.IsDestroyed);
                    });

                    // Checking is there any activity or no
                    if (mLoadedSomethingAlready &&
                        StageEditorWindows.Count == 0 &&
                        !RenderingQueue.IsProcessingItem)
                    {
                        RenderingQueue.StopThread();
                        Application.Quit();
                    }
                    return(true);
                });

                Application.Run();
            }
            mRemoteControlService.Stop();
        }
Example #5
0
 public static IBitmapCore FloatBitmapGtkFactory(RawLoader ppl, ProgressReporter callback)
 {
     return(FloatBitmapGtk.FromPPM(ppl, callback));
 }
Example #6
0
    /*
     * public void LoadCEStage(string filename, bool findRawForCEStage)
     * {
     *      try
     *      {
     *              mStage.LoadStage(filename);
     *
     *              string raw_filename; int prescale = 2;
     *              if (mStage.Prescale != 0) prescale = mStage.Prescale;
     *
     *              if (findRawForCEStage && MainClass.FindRawsForCestageAndAskToOpen(filename, out raw_filename, ref prescale))
     *              {
     *                      mStage.AskLoadImage(raw_filename, prescale);
     *              }
     *      }
     *      catch (StageDeserializationException sdex)
     *      {
     *              Gtk.MessageDialog md = new Gtk.MessageDialog(
     *                      this, DialogFlags.Modal,
     *                      MessageType.Error, ButtonsType.Ok,
     *                      false, "Can't load stage from the file \"{0}\".\n{1}", filename, sdex.Message);
     *
     *              md.Title = MainClass.APP_NAME;
     *
     *              md.Run();
     *              md.Destroy();
     *      }
     * }
     */
    public bool ShowLoadImageDialog()
    {
        if (mStage.TheUIState == UIState.Loading)
        {
            Gtk.MessageDialog md = new Gtk.MessageDialog(this, DialogFlags.Modal,
                                                         MessageType.Error, ButtonsType.Ok,
                                                         "Loading is in progress");
            md.Title = MainClass.APP_NAME;
            md.Run();
            md.Destroy();
        }
        else
        {
            Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Open RAW image",
                                                                  this,
                                                                  FileChooserAction.Open,
                                                                  "Cancel", ResponseType.Cancel,
                                                                  "Open", ResponseType.Accept);

            // Filter for RAWs
            FileFilter ff = new FileFilter();

            ff.AddCustom(FileFilterFlags.Filename, delegate(Gtk.FileFilterInfo ffi) {
                return(RawLoader.IsRaw(ffi.Filename));
            });
            ff.Name = "RAW image";

            fcd.AddFilter(ff);

            // Setting current folder to stage file folder or to RAW file folder
            if (mStage.StageFileName != null && mStage.StageFileName != "" &&
                !fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.StageFileName)))
            {
                fcd.SetCurrentFolder(System.IO.Path.GetDirectoryName(mStage.RawFileName));
            }



            // Adding preview widget

            ReceiptSelectorWidget rsw = new ReceiptSelectorWidget();
            RawPreviewWidget      rpw = new RawPreviewWidget();

            // Adding options widget

            PreScaleSelectorWidget pssw = new PreScaleSelectorWidget();
            pssw.Value = 2;
            if (mStage.Prescale != 0)
            {
                pssw.Value = mStage.Prescale;
            }

            VBox preview_box = new VBox(false, 4);
            preview_box.PackStart(rpw, true, true, 0);
            preview_box.ShowAll();
            fcd.PreviewWidget = preview_box;

            HBox options_box = new HBox(false, 20);
            options_box.PackStart(rsw, true, true, 0);
            options_box.PackEnd(pssw, false, true, 0);
            fcd.ExtraWidget = options_box;
            options_box.ShowAll();

            // Adding events

            fcd.UpdatePreview += delegate {
                rpw.Filename = fcd.Filename;
            };
            fcd.SelectionChanged += delegate {
                rpw.Filename    = fcd.Filename;
                rsw.RawFileName = fcd.Filename;
            };
            rpw.FileIsGoodChanged += delegate {
                options_box.Sensitive   = rpw.FileIsGood;
                fcd.PreviewWidgetActive = rpw.FileIsGood;
            };


            if (mStage.RawFileName != null)
            {
                fcd.SetFilename(mStage.RawFileName);
                rpw.Filename            = mStage.RawFileName;
                rsw.RawFileName         = mStage.RawFileName;
                fcd.PreviewWidgetActive = rpw.FileIsGood;
                options_box.Sensitive   = rpw.FileIsGood;
            }

            string filename = ""; int prescale = 2;
            bool   ok = false;

            if (fcd.Run() == (int)Gtk.ResponseType.Accept)
            {
                ok       = true;
                filename = fcd.Filename;
                prescale = pssw.Value;
            }

            fcd.Destroy();

            if (ok)
            {
                if (mStage.RawFileName != filename)
                {
                    mStage.AskLoadImage(filename, prescale);
                }
                mStage.LoadStage(rsw.SelectedReceiptFileName);
                return(true);
            }
        }
        return(false);
    }