private void addImages(
            JsonFileData jsonFileData,
            Dictionary <string, string> imgPaths,
            ImageList imgList,
            ListViewItem listItem,
            KeyValuePair <string, JsonFileData> jsonEntry,
            ref int index)
        {
            foreach (FileData openedFile in jsonFileData.OpenedFiles)
            {
                if (imgPaths.ContainsKey(jsonEntry.Key))
                {
                    continue;
                }

                foreach (KeyValuePair <string, FileData> linkedFile in openedFile.LinkedFileData)
                {
                    if (linkedFile.Value is ImageFileData)
                    {
                        if (System.IO.File.Exists(linkedFile.Value.Path))
                        {
                            imgPaths[jsonEntry.Key] = linkedFile.Value.Path;
                            imgList.Images.Add(ThumbnailCache.GetThumbnail(linkedFile.Value.Path));
                            imgList.ImageSize   = new Size(32, 32);
                            listItem.ImageIndex = index;
                            index++;
                            break;
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public void Initialize()
 {
     ThumbnailCache.ClearCache();
     new ModuleDataManager(MainForm.kModsDirectoryPath);
     ModuleDataManager.GetInstance().Load();
     ModuleDataManager.GetInstance().FilterAliasTree(treeView, null);
     if (ModuleDataManager.GetInstance().HasErrors)
     {
         toolStripStatusLabel1.Text      = "Errors were encountered while loading manifests";
         toolStripStatusLabel1.ForeColor = Color.Red;
     }
     else
     {
         toolStripStatusLabel1.Text      = "Successfully loaded manifests";
         toolStripStatusLabel1.ForeColor = Color.Black;
     }
 }
        private void canvas_Paint(object sender, PaintEventArgs e)
        {
            Graphics graphics       = e.Graphics;
            int      cellSizeZoomed = (int)Math.Round(kCellSize * mZoom);

            int maxCols           = Math.Min(mMaxNetWorth, kMaxRows);
            int maxRows           = Math.Min(mItemCount, kMaxRows);
            int canvasWidth       = maxCols * (cellSizeZoomed + 1);
            int canvasHeightLimit = maxRows * (cellSizeZoomed + 1);
            int canvasHeight      = (maxRows * (cellSizeZoomed + 1)) + kBottomOffset;

            canvas.Width  = canvasWidth;
            canvas.Height = canvasHeight;

            for (int i = 0; i < maxCols; ++i)
            {
                if (mZoom > 0.25f || (mZoom == 0.25f && ((i + 1) % 10) == 0))
                {
                    string colName  = "" + (i + 1);
                    Point  position = new Point(i * cellSizeZoomed, canvasHeight - kStringOffset);
                    graphics.DrawString(colName, SystemFonts.DefaultFont, Brushes.Black, position);
                }
                else
                {
                }

                List <JsonFileData> list;
                if (mNetWorthValues.TryGetValue(i + 1, out list))
                {
                    int count = Math.Min(maxRows, list.Count);
                    for (int j = 0; j < count; j++)
                    {
                        JsonFileData data      = list[j];
                        string       imageFile = FindImageForFile(data);
                        if (string.IsNullOrEmpty(imageFile))
                        {
                            Console.WriteLine("file " + data.FileName + " has no icon!");
                        }
                        else
                        {
                            Image thumbnail = ThumbnailCache.GetThumbnail(imageFile);

                            int       ylocation = canvasHeight - ((j + 1) * cellSizeZoomed) - maxRows - kBottomOffset - 1;
                            Rectangle location  = new Rectangle(i * cellSizeZoomed, ylocation, cellSizeZoomed, cellSizeZoomed);
                            graphics.DrawImage(thumbnail, location);

                            if (data.RecommendedMaxNetWorth > 0)
                            {
                                int    cost       = i + 1;
                                bool   shouldWarn = false;
                                JToken sellable   = data.Json.SelectToken("entity_data.stonehearth:net_worth.shop_info.sellable");
                                if (sellable != null && sellable.ToString() == "False")
                                {
                                    shouldWarn = true;
                                }

                                if (cost < data.RecommendedMinNetWorth * kMinRecommendedMultiplier)
                                {
                                    shouldWarn = true;
                                }

                                if (cost > ((data.RecommendedMaxNetWorth * kMaxRecommendedMultiplier) + 1))
                                {
                                    shouldWarn = true;
                                }

                                if (shouldWarn)
                                {
                                    Pen semiRed = new Pen(Color.FromArgb(100, Color.Red));
                                    graphics.FillRectangle(semiRed.Brush, location);
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < canvasWidth; i += cellSizeZoomed)
            {
                graphics.DrawLine(System.Drawing.Pens.Black, new Point(i, 0), new Point(i, canvasHeightLimit));
            }

            for (int j = 0; j < canvasHeightLimit; j += cellSizeZoomed)
            {
                graphics.DrawLine(System.Drawing.Pens.Black, new Point(0, j), new Point(canvasWidth, j));
            }
        }
        private void OnJsonFileDataSelected()
        {
            JsonFileData fileData = mSelectedFileData as JsonFileData;

            if (fileData.TreeNode != null)
            {
                treeView.SelectedNode = fileData.TreeNode;
            }

            List <string> addedOpenFiles = new List <string>();
            bool          hasImage       = false;

            foreach (FileData openedFile in fileData.OpenedFiles)
            {
                TabPage newTabPage = new TabPage();
                newTabPage.Text = openedFile.FileName;
                if (ModuleDataManager.GetInstance().ModifiedFiles.Contains(openedFile))
                {
                    newTabPage.Text = newTabPage.Text + "*";
                }

                if (openedFile.HasErrors)
                {
                    newTabPage.ImageIndex  = 0;
                    newTabPage.ToolTipText = openedFile.Errors;
                }

                FilePreview filePreview = new FilePreview(this, openedFile);
                filePreview.Dock = DockStyle.Fill;
                newTabPage.Controls.Add(filePreview);
                filePreviewTabs.TabPages.Add(newTabPage);

                foreach (KeyValuePair <string, FileData> linkedFile in openedFile.LinkedFileData)
                {
                    if (addedOpenFiles.Contains(linkedFile.Key))
                    {
                        continue;
                    }

                    addedOpenFiles.Add(linkedFile.Key);

                    if (linkedFile.Value is QubicleFileData)
                    {
                        QubicleFileData qbFileData     = linkedFile.Value as QubicleFileData;
                        string          fileName       = qbFileData.FileName;
                        Button          openFileButton = new Button();
                        openFileButton.Name                    = qbFileData.GetOpenFilePath();
                        openFileButton.BackgroundImage         = global::StonehearthEditor.Properties.Resources.qmofileicon_small;
                        openFileButton.BackgroundImageLayout   = ImageLayout.None;
                        openFileButton.Text                    = Path.GetFileName(openFileButton.Name);
                        openFileButton.TextAlign               = System.Drawing.ContentAlignment.MiddleRight;
                        openFileButton.UseVisualStyleBackColor = true;
                        openFileButton.Click                  += new System.EventHandler(openFileButton_Click);
                        openFileButton.Padding                 = new Padding(22, 2, 2, 2);
                        openFileButton.AutoSize                = true;
                        openFileButtonPanel.Controls.Add(openFileButton);
                    }
                    else if (linkedFile.Value is ImageFileData)
                    {
                        string imageFilePath = linkedFile.Value.Path;
                        if (System.IO.File.Exists(imageFilePath))
                        {
                            if (!hasImage)
                            {
                                iconView.ImageLocation = imageFilePath;
                                hasImage = true;
                            }

                            Button openFileButton = new Button();
                            openFileButton.Name = imageFilePath;
                            Image thumbnail = ThumbnailCache.GetThumbnail(imageFilePath);

                            openFileButton.BackgroundImage       = thumbnail;
                            openFileButton.BackgroundImageLayout = ImageLayout.None;
                            openFileButton.Text      = Path.GetFileName(openFileButton.Name);
                            openFileButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                            openFileButton.UseVisualStyleBackColor = true;
                            openFileButton.Click   += new System.EventHandler(openFileButton_Click);
                            openFileButton.Padding  = new Padding(22, 2, 2, 2);
                            openFileButton.AutoSize = true;
                            openFileButtonPanel.Controls.Add(openFileButton);
                        }
                    }
                }
            }
        }