Esempio n. 1
0
        private void L_MouseLeave(object sender, EventArgs e)
        {
            // Get back original category color
            if (!(sender is Label l))
            {
                return;
            }

            if (!(l.Tag is CitationCategory))
            {
                l.BackColor = m_LabelDefaultColor;
                return;
            }

            string colorString = Categories.SingleOrDefault(x => x.Id == ((CitationCategory)l.Tag).CategoryId)?.CategoryColor;

            if (string.IsNullOrWhiteSpace(colorString))
            {
                l.BackColor = m_LabelDefaultColor;
                return;
            }

            Color[] colors = ColorStuff.ConvertStringToColors(colorString);
            if (colors.Any())
            {
                l.BackColor = colors[0];
            }
            else
            {
                l.BackColor = m_LabelDefaultColor;
            }
        }
Esempio n. 2
0
        public Label CreateCategoryLabelControl(CitationCategory citCat, Category cat, ContextMenuStrip menu, ToolTip toolTip)
        {
            Label l = new Label();

            Color[] color    = ColorStuff.ConvertStringToColors(cat.CategoryColor);
            Color   catColor = color.Any() ? color[0] : m_LabelDefaultColor;

            Font newFont = new Font("Times New Roman", 10, FontStyle.Regular);

            l.Font             = newFont;
            l.MouseHover      += L_MouseHover;
            l.MouseEnter      += L_MouseEnter;
            l.MouseLeave      += L_MouseLeave;
            l.AutoSize         = true;
            l.BackColor        = catColor;
            l.Text             = $"{cat.Code} [{citCat.Weight}]";
            l.ContextMenuStrip = menu;
            if (citCat.IsMain)
            {
                SetMainStyleOnLabel(l);
            }
            l.Tag = citCat;
            toolTip.SetToolTip(l, cat.Name + Environment.NewLine + cat.Description);
            return(l);
        }
Esempio n. 3
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.RowIndex >= dataGridView1.Rows.Count)
            {
                return;
            }

            if (e.ColumnIndex == 4)
            {
                Id id = (Id)dataGridView1.Rows[e.RowIndex].Cells[0].Value;

                Category cat = m_FilteredCategories.SingleOrDefault(x => x.Id == id);

                ColorDialog dlg    = new ColorDialog();
                Color[]     colors = ColorStuff.ConvertStringToColors(cat.CategoryColor);
                dlg.Color = colors.Any() ? colors[0] : Color.White;
                DialogResult result = dlg.ShowDialog(this);
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                cat.CategoryColor = ColorStuff.ConvertColorsToString(new Color[] { dlg.Color });

                m_CategoryService.InsertOrUpdate(cat);

                FireCategoryChanged(cat);

                dataGridView1.Rows[e.RowIndex].Selected = true;
            }
        }
Esempio n. 4
0
 private void DataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == 4)
     //foreach (DataGridViewRow Myrow in dataGridView1.Rows)
     {
         DataGridViewRow row    = dataGridView1.Rows[e.RowIndex];
         var             colors = ColorStuff.ConvertStringToColors((string)row.Cells[ColorColIdx].Value);
         if (colors.Any())
         {
             row.Cells[ColorColIdx].Style.BackColor          = colors[0];
             row.Cells[ColorColIdx].Style.ForeColor          = colors[0];
             row.Cells[ColorColIdx].Style.SelectionBackColor = colors[0];
             row.Cells[ColorColIdx].Style.SelectionForeColor = colors[0];
         }
         else
         {
             row.Cells[ColorColIdx].Style.BackColor          = Color.White;
             row.Cells[ColorColIdx].Style.ForeColor          = Color.White;
             row.Cells[ColorColIdx].Style.SelectionBackColor = Color.White;
             row.Cells[ColorColIdx].Style.SelectionForeColor = Color.White;
         }
     }
 }
Esempio n. 5
0
        public override void CallHandler(IPlayer player, int groupId, CmdArgs args)
        {
            WaypointUtils.doingConfigAction = true;
            GetEnumFromArgs <EnumCmdArgsFloatyWaypoints>(ref args, out var arg);
            switch (arg)
            {
            case EnumCmdArgsFloatyWaypoints.deathdebug:
                Config.DebugDeathWaypoints = args.PopBool() ?? !Config.DebugDeathWaypoints;
                capi.ShowChatMessage(string.Format("Death waypoint debbuging set to {0}", Config.DebugDeathWaypoints));
                break;

            case EnumCmdArgsFloatyWaypoints.dotrange:
                double?dr = args.PopDouble();
                Config.DotRange = dr != null ? (double)dr : Config.DotRange;
                capi.ShowChatMessage("Dot Range Set To " + Config.DotRange + " Meters.");
                break;

            case EnumCmdArgsFloatyWaypoints.titlerange:
                double?tr = args.PopDouble();
                Config.TitleRange = tr != null ? (double)tr : Config.TitleRange;
                capi.ShowChatMessage("Title Range Set To " + Config.TitleRange + " Meters.");
                break;

            case EnumCmdArgsFloatyWaypoints.perblockwaypoints:
                bool?pb = args.PopBool();
                Config.PerBlockWaypoints = pb != null ? (bool)pb : !Config.PerBlockWaypoints;
                capi.ShowChatMessage("Per Block Waypoints Set To " + Config.PerBlockWaypoints + ".");
                break;

            case EnumCmdArgsFloatyWaypoints.pdw:
                utils.PurgeWaypointsByStrings("Player Death Waypoint", "*Player Death Waypoint*");
                break;

            case EnumCmdArgsFloatyWaypoints.plt:
                utils.PurgeWaypointsByStrings("Limits Test");
                break;

            case EnumCmdArgsFloatyWaypoints.open:
                utils.ViewWaypoints(new KeyCombination());
                break;

            case EnumCmdArgsFloatyWaypoints.waypointprefix:
                bool?wp = args.PopBool();
                Config.WaypointPrefix = wp != null ? (bool)wp : !Config.WaypointPrefix;
                capi.ShowChatMessage("Waypoint Prefix Set To " + Config.WaypointPrefix + ".");
                break;

            case EnumCmdArgsFloatyWaypoints.waypointid:
                bool?wi = args.PopBool();
                Config.WaypointID = wi != null ? (bool)wi : !Config.WaypointID;
                capi.ShowChatMessage("Waypoint ID Set To " + Config.WaypointID + ".");
                break;

            case EnumCmdArgsFloatyWaypoints.purge:
                string s = args.PopWord();
                if (s == "reallyreallyconfirm")
                {
                    utils.Purge();
                }
                else
                {
                    capi.ShowChatMessage(Lang.Get("Are you sure you want to do that? It will remove ALL your waypoints, type \"reallyreallyconfirm\" to confirm."));
                }
                break;

            case EnumCmdArgsFloatyWaypoints.enableall:
                Config.DisabledColors.Clear();
                break;

            case EnumCmdArgsFloatyWaypoints.save:
                break;

            case EnumCmdArgsFloatyWaypoints.export:
                string filePath = Path.Combine(GamePaths.DataPath, args.PopWord() ?? "waypoints");
                MassFileExportSystem.toExport.Push(new ExportableJsonObject(utils.WaypointsRel, filePath));
                break;

            case EnumCmdArgsFloatyWaypoints.import:
                string path1 = Path.Combine(GamePaths.DataPath, args.PopWord() ?? "waypoints") + ".json";
                if (File.Exists(path1))
                {
                    using (TextReader reader = new StreamReader(path1))
                    {
                        DummyWaypoint[] relative = JsonConvert.DeserializeObject <DummyWaypoint[]>(reader.ReadToEnd(), new JsonSerializerSettings()
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        });

                        VSHUDTaskSystem.Actions.Enqueue(new Action(() =>
                        {
                            for (int j = 0; j < relative.Length; j++)
                            {
                                var val = relative[j];
                                if (utils.WaypointsRel.Any(w =>
                                                           val.Position.AsBlockPos.X == w.Position.AsBlockPos.X &&
                                                           val.Position.AsBlockPos.Y == w.Position.AsBlockPos.Y &&
                                                           val.Position.AsBlockPos.Z == w.Position.AsBlockPos.Z
                                                           ))
                                {
                                    continue;
                                }

                                string str = string.Format(CultureInfo.InvariantCulture, "/waypoint addati {0} ={1} ={2} ={3} {4} #{5} {6}", val.Icon, val.Position.X, val.Position.Y, val.Position.Z, val.Pinned, ColorUtil.Int2Hex(val.Color), val.Title);
                                capi.SendChatMessage(str);
                            }

                            //Trick server into sending waypoints to the client even if they don't have their map opened.
                            capi.Event.EnqueueMainThreadTask(() => capi.Event.RegisterCallback(dt => utils.MapManager.GetField <IClientNetworkChannel>("clientChannel").SendPacket(new OnViewChangedPacket()
                            {
                                NowVisible = new List <Vec2i>(), NowHidden = new List <Vec2i>()
                            }), 500), "");
                        }));
                        reader.Close();
                    }
                }
                break;

            case EnumCmdArgsFloatyWaypoints.testlimits:
                int    amount = args.PopInt() ?? 30;
                int    maxY   = args.PopInt() ?? 10;
                double radius = (args.PopInt() ?? 1000);

                VSHUDTaskSystem.Actions.Enqueue(new Action(() =>
                {
                    for (int i = 0; i < amount; i++)
                    {
                        double
                        x = (capi.World.Rand.NextDouble() - 0.5) * radius,
                        z = (capi.World.Rand.NextDouble() - 0.5) * radius,
                        y = capi.World.BlockAccessor.GetRainMapHeightAt((int)x, (int)z);

                        double r = x * x + z * z;
                        if (r <= (radius * 0.5) * (radius * 0.5))
                        {
                            Vec3d pos          = capi.World.Player.Entity.Pos.XYZ.AddCopy(new Vec3d(x, y, z));
                            bool deathWaypoint = capi.World.Rand.NextDouble() > 0.8;

                            string icon  = deathWaypoint ? "rocks" : WaypointUtils.iconKeys[(int)(capi.World.Rand.NextDouble() * (WaypointUtils.iconKeys.Length - 1))];
                            string title = deathWaypoint ? "Limits Test Player Death Waypoint" : "Limits Test Waypoint";

                            string str = string.Format(CultureInfo.InvariantCulture, "/waypoint addati {0} ={1} ={2} ={3} {4} #{5} {6}", icon, pos.X, pos.Y, pos.Z, deathWaypoint, ColorStuff.RandomHexColorVClamp(capi, 0.5, 0.8), title);

                            capi.SendChatMessage(str);
                        }
                        else
                        {
                            i--;
                        }
                    }

                    //Trick server into sending waypoints to the client even if they don't have their map opened.
                    capi.Event.EnqueueMainThreadTask(() => capi.Event.RegisterCallback(dt => utils.MapManager.GetField <IClientNetworkChannel>("clientChannel").SendPacket(new OnViewChangedPacket()
                    {
                        NowVisible = new List <Vec2i>(), NowHidden = new List <Vec2i>()
                    }), 500), "");
                }));
                break;

            case EnumCmdArgsFloatyWaypoints.pillars:
                Config.ShowPillars = args.PopBool() ?? !Config.ShowPillars;
                capi.ShowChatMessage("Waypoint Pillars Set To " + Config.ShowPillars + ".");
                break;

            default:
                capi.ShowChatMessage(GetHelpMessage());
                break;
            }
            base.CallHandler(player, groupId, args);
            WaypointUtils.doingConfigAction = false;

            //Trick server into sending waypoints to the client even if they don't have their map opened.
            capi.Event.RegisterCallback(dt => utils.MapManager.GetField <IClientNetworkChannel>("clientChannel").SendPacket(new OnViewChangedPacket()
            {
                NowVisible = new List <Vec2i>(), NowHidden = new List <Vec2i>()
            }), 500);
        }
Esempio n. 6
0
        public void RecreateTheWholeThing(ModelsForViewing vm, VolumeService volumeService)
        {
            string origFileName    = vm.CurrentStorage.FilePath;
            string storageFilePath = System.IO.Path.Combine(m_UserSettingsService.StorageFolder, vm.CurrentStorage.StorageName);
            string newFileTmp      = m_TempFileService.GetNewTmpFileName(vm.CurrentStorage.StorageName);

            //File.Copy(storageFilePath, tmpFileName, true);
            (int x, int y)offset = (volumeService.CurrentVolume.OffsetX, volumeService.CurrentVolume.OffsetY);

            PdfDocument pdfDoc = new PdfDocument(new PdfReader(origFileName), new PdfWriter(newFileTmp));

            foreach (Citation cit in volumeService.Citations)
            {
                // Yeah, somtimes illegal citations end up in the database.
                if (cit.SelectionRects.Trim().Length < 5)
                {
                    continue;
                }

                var cat    = m_CategoryService.GetMainCategory(cit.Id);
                var citCat = m_CategoryService.GetMainCitationCategory(cit.Id);

                if (cat == null)
                {
                    citCat.CategoryId = Id.Empty;
                }

                List <(int page, int[] rects)> pageRects = ArrayStuff.ConvertStringToPagesAndArrays(cit.SelectionRects);
                int firstPageNo = GetFirstPageFromPageRects(pageRects);

                Color color_highLight, color_underLine, color_margin = new DeviceRgb(n(255), n(255), n(255));;

                if (pageRects.Any())
                {
                    System.Drawing.Color ch, cu, cm;
                    var colors = ColorStuff.ConvertStringToColors(cit.CitationColors);
                    ch = (colors.Length >= 1)
                        ? colors[0]
                        : m_UserSettingsService.PdfHighLightColor;
                    cu = (colors.Length >= 2)
                        ? colors[1]
                        : m_UserSettingsService.PdfUnderlineColor;
                    cm = (colors.Length >= 3)
                        ? colors[2]
                        : m_UserSettingsService.PdfMarginBoxColor;

                    color_highLight = new DeviceRgb(n(ch.R), n(ch.G), n(ch.B));
                    color_underLine = new DeviceRgb(n(cu.R), n(cu.G), n(cu.B));
                    color_margin    = new DeviceRgb(n(cm.R), n(cm.G), n(cm.B));

                    foreach ((int page, int[] rects)pageRect in pageRects)
                    {
                        if (pageRect.rects.Count() < 4) // If no rects, for some reason...
                        {
                            continue;
                        }

                        //int currentPage = pageRects.First().page;
                        int  currentPage = pageRect.page;
                        int  currentRect = 0;
                        bool notDone     = true;
                        do
                        {
                            PdfCanvas canvas1 = new PdfCanvas(
                                pdfDoc.GetPage(currentPage).NewContentStreamBefore(),
                                pdfDoc.GetPage(currentPage).GetResources(), pdfDoc);
                            PdfCanvas canvas2 = new PdfCanvas(
                                pdfDoc.GetPage(currentPage).NewContentStreamAfter(),
                                pdfDoc.GetPage(currentPage).GetResources(), pdfDoc);

                            Rectangle pageSize   = pdfDoc.GetPage(firstPageNo).GetPageSize();
                            int       pageHeight = (int)pageSize.GetHeight();
                            int       pageWidth  = (int)pageSize.GetWidth();

                            //canvas.SaveState();

                            canvas1.SetFillColor(color_highLight);
                            canvas2.SetFillColor(color_underLine);

                            do                                            //(int i = 0; i < rects.Length; i += 4)
                            {
                                if (currentRect >= pageRect.rects.Length) // Sometime this is necessary, page rects are empty or broken.
                                {
                                    break;
                                }

                                int x = pageRect.rects[currentRect] + offset.x;
                                int y = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3] + offset.y;
                                // Below text highlight
                                canvas1.Rectangle(x, y, pageRect.rects[currentRect + 2], pageRect.rects[currentRect + 3]);
                                canvas1.Fill();
                                // Above text underline
                                canvas2.Rectangle(x, y, pageRect.rects[currentRect + 2], 1);
                                canvas2.Fill();

                                if (currentRect + 5 > pageRect.rects.Length)
                                {
                                    notDone = false;
                                    break;
                                }

                                // Detect page break
                                int lastY = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3];
                                currentRect += 4;
                                int newY = pageHeight - pageRect.rects[currentRect + 1] - pageRect.rects[currentRect + 3];
                                if (lastY < newY)
                                {
                                    currentPage++;
                                    break;
                                }
                            } while (true);
                        } while (notDone);
                    }

                    // Add annotation
                    AddMarginBox(pdfDoc, null, firstPageNo, cit.Id.ToString(), cat.Code + $" [{citCat.Weight}]", cit.SelectionRects,
                                 color_margin,
                                 cit.MarginBoxSettings,
                                 offset);
                }// if pagerects.any
            }
            pdfDoc.Close(); // newFileTmp
            m_StorageHelperService.GetNextStorageFileName(vm.CurrentStorage);
            string newStoragePath = System.IO.Path.Combine(m_UserSettingsService.StorageFolder, vm.CurrentStorage.StorageName);

            int retries = 10;

            do
            {
                try
                {
                    //File.Delete(storageFilePath);
                    File.Copy(newFileTmp, newStoragePath);
                    retries = 0;
                }
                catch
                {
                    retries--;
                    Thread.Sleep(500);
                }
            } while (retries > 0);

            File.Delete(newFileTmp);
            m_StorageHelperService.DeleteOldStorageFiles(newStoragePath);
        }