private static Boolean Prefix(ref ScrollCanvas ___scrollLoadCanvas, ref GuiElement ___popupLoad, ref bool ___popupActive, ref SaveEntry ___focusedSave)
        {
            DeleteWorldSaves.MyRootMenuRev2.MyscrollLoadCanvas = ___scrollLoadCanvas;
            ___popupActive = true;
            ___scrollLoadCanvas.elementList.Clear();
            bool flag = !Directory.Exists(Directory.GetCurrentDirectory() + "\\worldsaves\\");

            if (flag)
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\worldsaves\\");
            }
            DirectoryInfo directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory() + "\\worldsaves\\");
            var           extensions    = new[] { "*.wdb", "*.wsav" }; // to make this patch compatible with 0.8 and 0.9 versions of the game we search for save files in the old and the new format
            var           files         = extensions.SelectMany(ext => directoryInfo.GetFiles(ext));

            foreach (FileInfo fileInfo in files)
            {
                string date = fileInfo.LastWriteTime.ToString("f", CONFIG.culture_en_US);
                // we have to replace RootMenuRev2.selectEntry method with our own, as we can not patch a private method with prefix or postfix patch. A reverse-patch would be an option if this method would not use any instance variables.
                // since it uses "this.focusedSave" "this." would be referring to an instance of our own class in a reverse-patch, which obviously would not work.
                MyRootMenuRev2.MyscrollLoadCanvas.AddSaveEntry(Path.GetFileNameWithoutExtension(fileInfo.Name), date, SCREEN_MANAGER.white, 0, 4, 436, 52, SortType.vertical, new SaveEntry.ClickJournalEvent(DeleteWorldSaves.MyRootMenuRev2.MyselectEntry), null);
            }
            ___popupLoad.isVisible = true;

            return(false); // returning "false" in a prefix patch is an instruction for Harmony to supress execution of the original method, so only our replacement will be executed-
        }
예제 #2
0
 private void MainCanvasMouseUp(object sender, MouseButtonEventArgs e)
 {
     if (Artist.SelectedTool != Artist.Tools[6])
     {
         Artist.AddCondition();
     }
     Artist.SelectedTool.MouseUp(e.GetPosition(MainCanvas));
     if (Artist.SelectedTool == Artist.Tools[6])
     {
         MainCanvas.LayoutTransform = new ScaleTransform(Artist.ScaleRateX, Artist.ScaleRateY);
         ScrollCanvas.ScrollToVerticalOffset(Artist.DistanceToPointY * Artist.ScaleRateY);
         ScrollCanvas.ScrollToHorizontalOffset(Artist.DistanceToPointX * Artist.ScaleRateX);
     }
     Invalidate();
 }
        // we use a postfix patch on RootMenuRev2.createElements to find and resize all parts of the "open game" dialogue to fit the new delete button, after that we clear out the original button container and replace them with our own buttons.
        private static void Postfix(RootMenuRev2 __instance, ref GuiElement ___popupLoad, ref ScrollCanvas ___scrollLoadCanvas, ref List <GuiElement> ___popupCanvas)
        {
            int   num3      = 300;
            Color fontColor = new Color(226, 252, 255, 210);

            ___popupLoad.width = 450;
            bool openMP2 = CONFIG.openMP; // a check if we have the multiplayer version of the game is probably redundant at this point, but it will do no harm.

            if (!openMP2)
            {
                foreach (var entry in ___popupLoad.elementList)
                {
                    if (entry.name == "load scroll")
                    {
                        entry.width = 450;
                        foreach (var entry2 in ___scrollLoadCanvas.elementList)
                        {
                            entry2.width = 436;
                        }
                    }
                    else
                    {
                        entry.elementList.Clear();
                        entry.width = 450;
                        entry.AddButton("Load", SCREEN_MANAGER.white, 2, 2, num3 / 2 - 2 - 1, 36, new BasicButton.ClickEvent(DeleteWorldSaves.MyRootMenuRev2.loadGame), SCREEN_MANAGER.FF16, fontColor);               // calling "DeleteWorldSaves.MyRootMenuRev2.loadGame" instead of RootMenuRev2.loadGame, private delegated methods have to be replaced by our own, not sure if it is posible to call and modify them with reflections, at this point this is the only solution a could think of.
                        entry.AddButton("Close", SCREEN_MANAGER.white, 2, 2, num3 / 2 - 2 - 1, 36, new BasicButton.ClickEvent(__instance.actionCloseLoad), SCREEN_MANAGER.FF16, fontColor);                            // we can use the original RootMenuRev2.actionCloseLoad method bacause it is public and can be accessed by harmony via instance of "RootMenuRev2"
                        entry.AddButton("Delete", SCREEN_MANAGER.white, 2, 2, num3 / 2 - 2 - 1, 36, new BasicButton.ClickEvent(DeleteWorldSaves.MyRootMenuRev2.deleteSave), SCREEN_MANAGER.FF16, CONFIG.textColorRed); // this is our new delete button with red text
                    }
                }
                // adding a confirmation dialogue
                ___popupCanvas.Add(new Canvas("confirm delete worldsave", SCREEN_MANAGER.white, 600, 600, 0, 0, 300, 80, SortType.vertical, new Color(14, 18, 19, 245)));
                DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete = ___popupCanvas.Last <GuiElement>();
                DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete.addLabel("Confirm delete", SCREEN_MANAGER.FF20, 70, 0, 150, 40, CONFIG.textBrightColor);
                DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete.AddCanvas("confirm delete worldsave buttons", SCREEN_MANAGER.white, 0, 0, 300, 40, SortType.horizontal);
                GuiElement guiElement6 = DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete.elementList.Last <GuiElement>();
                guiElement6.AddButton("Confirm", SCREEN_MANAGER.white, 0, 0, 150, 40, new BasicButton.ClickEvent(DeleteWorldSaves.MyRootMenuRev2.actionConfirmDelete), SCREEN_MANAGER.FF16, CONFIG.textColorRed);
                guiElement6.AddButton("Cancel", SCREEN_MANAGER.white, 0, 0, 150, 40, new BasicButton.ClickEvent(DeleteWorldSaves.MyRootMenuRev2.actionCancelDelete), SCREEN_MANAGER.FF16, CONFIG.textBrightColor);
                DeleteWorldSaves.MyRootMenuRev2.popupConfirmDelete.isVisible = false;
            }
        }
        public void move_to_update_position(object sender, MouseEventArgs m)
        {
            if (isDragged == true && m.LeftButton == MouseButtonState.Pressed && (Support.IsVirtualObject == true || Support.IsJump == true || Support.IsVirtualWater == true))
            {
                if (rect != null)
                {
                    WorkspaceWorking.Children.Remove(rect);
                }

                endPosition = m.GetPosition(WorkspaceWorking);

                #region Scroll SrollViewer of Canvas
                if (endPosition.X > 800 + ScrollCanvas.HorizontalOffset)
                {
                    ScrollCanvas.ScrollToHorizontalOffset(ScrollCanvas.HorizontalOffset + 1);
                    ScrollCanvas.UpdateLayout();
                }
                #endregion

                endPosition.X = ((int)endPosition.X / Support.WIDHT_OF_VIRTUALOBJECT) * Support.WIDHT_OF_VIRTUALOBJECT;
                endPosition.Y = ((int)endPosition.Y / Support.HEIGHT_OF_VIRTUALOBJECT) * Support.HEIGHT_OF_VIRTUALOBJECT;

                if ((int)endPosition.X % Support.WIDHT_OF_VIRTUALOBJECT > 0 || (endPosition.X - startPosition.X) / Support.WIDHT_OF_VIRTUALOBJECT < 1)
                {
                    endPosition.X += Support.WIDHT_OF_VIRTUALOBJECT;
                }

                if ((int)endPosition.Y % Support.HEIGHT_OF_VIRTUALOBJECT > 0 || (endPosition.Y - startPosition.Y) / Support.HEIGHT_OF_VIRTUALOBJECT < 1)
                {
                    endPosition.Y += Support.HEIGHT_OF_VIRTUALOBJECT;
                }


                rect        = new Rectangle();
                rect.Tag    = Support.virtualObject;
                rect.Width  = (double)Math.Abs(endPosition.X - startPosition.X);
                rect.Height = (double)Math.Abs(endPosition.Y - startPosition.Y);
                if (Support.IsVirtualWater == true)
                {
                    rect.Stroke = new SolidColorBrush(Colors.Blue);
                }
                else if (Support.IsJump == false)
                {
                    rect.Stroke = new SolidColorBrush(Colors.Red);
                }
                else if (Support.IsJump == true)
                {
                    rect.Stroke = new SolidColorBrush(Colors.Green);
                }
                rect.StrokeThickness = 3;

                if (endPosition.X > startPosition.X)
                {
                    Canvas.SetLeft(rect, startPosition.X);
                    finalPosition.X = startPosition.X;
                }
                else
                {
                    Canvas.SetLeft(rect, endPosition.X);
                    finalPosition.X = endPosition.X;
                }

                if (startPosition.Y < endPosition.Y)
                {
                    Canvas.SetTop(rect, startPosition.Y);
                    finalPosition.Y = startPosition.Y;
                }
                else
                {
                    Canvas.SetTop(rect, endPosition.Y);
                    finalPosition.Y = endPosition.Y;
                }
                Canvas.SetZIndex(rect, 2);
                WorkspaceWorking.Children.Add(rect);
            }
            else
            {
                if (isDragged == true && m.LeftButton == MouseButtonState.Released)
                {
                    isDragged = false;
                    if (rect != null)
                    {
                        ++Support.Count;
                        if (Support.IsVirtualWater == false && Support.IsJump == false)
                        {
                            OBJECT   temp         = new OBJECT((int)ObjectType.VIRTUAL_OBJECT, 0, Support.Count, new VECTOR2D((float)finalPosition.X, (float)finalPosition.Y), new RECTANGLE((float)finalPosition.X, (float)finalPosition.Y, (int)rect.Width, (int)rect.Height));
                            VECTOR2D tempPosition = Support.ConvertCoordination(temp);


                            OBJECT obj = new OBJECT((int)ObjectType.VIRTUAL_OBJECT, 0, Support.Count, new VECTOR2D((float)tempPosition.cX, (float)tempPosition.cY), new RECTANGLE((float)tempPosition.cX, (float)tempPosition.cY, (int)rect.Width, (int)rect.Height));

                            if (Support.listObject == null)
                            {
                                Support.listObject = new List <OBJECT>();
                            }
                            if (obj.Bound.width != 0 && obj.Bound.height != 0)
                            {
                                Support.listObject.Add(obj);
                            }

                            obj = null;
                        }
                        else if (Support.IsVirtualWater == true)
                        {
                            OBJECT   temp         = new OBJECT((int)ObjectType.VIRTUAL_OBJECT, 0, Support.Count, new VECTOR2D((float)finalPosition.X, (float)finalPosition.Y), new RECTANGLE((float)finalPosition.X, (float)finalPosition.Y, (int)rect.Width, (int)rect.Height));
                            VECTOR2D tempPosition = Support.ConvertCoordination(temp);

                            EditPosition form = new EditPosition((int)tempPosition.cX, (int)tempPosition.cY);
                            form.ShowDialog();
                            tempPosition = new VECTOR2D(EditPosition.finalLocationX, EditPosition.finalLocationY);

                            OBJECT obj = new OBJECT((int)ObjectType.VIRTUAL_OBJECT, (int)ObjectID.VIRTUAL_OBJECT_WATER, Support.Count, new VECTOR2D((float)tempPosition.cX, (float)tempPosition.cY), new RECTANGLE((float)tempPosition.cX, (float)tempPosition.cY, (int)rect.Width, (int)rect.Height));

                            if (Support.listObject == null)
                            {
                                Support.listObject = new List <OBJECT>();
                            }
                            if (obj.Bound.width != 0 && obj.Bound.height != 0)
                            {
                                Support.listObject.Add(obj);
                            }

                            obj = null;
                        }
                        else if (Support.IsJump == true)
                        {
                            OBJECT   temp         = new OBJECT((int)ObjectType.VIRTUAL_OBJECT, 0, Support.Count, new VECTOR2D((float)finalPosition.X, (float)finalPosition.Y), new RECTANGLE((float)finalPosition.X, (float)finalPosition.Y, (int)rect.Width, (int)rect.Height));
                            VECTOR2D tempPosition = Support.ConvertCoordination(temp);

                            EditPosition form = new EditPosition((int)tempPosition.cX, (int)tempPosition.cY);
                            form.ShowDialog();
                            tempPosition = new VECTOR2D(EditPosition.finalLocationX, EditPosition.finalLocationY);

                            OBJECT obj = new OBJECT((int)ObjectType.VIRTUAL_OBJECT, (int)ObjectID.VIRTUAL_OBJECT_JUMP, Support.Count, new VECTOR2D((float)tempPosition.cX, (float)tempPosition.cY), new RECTANGLE((float)tempPosition.cX, (float)tempPosition.cY, (int)rect.Width, (int)rect.Height));

                            if (Support.listObject == null)
                            {
                                Support.listObject = new List <OBJECT>();
                            }
                            if (obj.Bound.width != 0 && obj.Bound.height != 0)
                            {
                                Support.listObject.Add(obj);
                            }

                            obj = null;
                        }
                    }
                    rect          = null;
                    startPosition = endPosition;
                }
            }

            // Update coordination for tb
            if (this.tbX != null && this.tbY != null)
            {
                this.tbX.Text = m.GetPosition(WorkspaceWorking).X.ToString();
                this.tbY.Text = (Support.HEIGHT_MAP - m.GetPosition(WorkspaceWorking).Y).ToString();
            }

            if (Support.IsEraser == false)
            {
                #region .For to create enemyobject

                if (selectedItemFromListbox != null && m.LeftButton != MouseButtonState.Pressed)
                {
                    isAdded = false;
                    WorkspaceWorking.Children.Remove(tempSelectedItem);

                    Image cursorImage = new Image();
                    cursorImage.Tag     = selectedItemFromListbox.Tag;
                    cursorImage.Source  = selectedItemFromListbox.Source;
                    cursorImage.Width   = selectedItemFromListbox.Width;
                    cursorImage.Height  = selectedItemFromListbox.Height;
                    cursorImage.Opacity = 0.8f;

                    positionTempOfSelectedFromListbox = m.GetPosition(WorkspaceWorking);

                    tempSelectedItem = cursorImage;

                    if (Support.IsAlign == true)
                    {
                        #region .Collision between rambo & virtualobject
                        for (int i = 0; i < WorkspaceWorking.Children.Count; ++i)
                        {
                            RECTANGLE cursor = new RECTANGLE((float)positionTempOfSelectedFromListbox.X, (float)positionTempOfSelectedFromListbox.Y, (int)cursorImage.Width, (int)cursorImage.Height);

                            if (WorkspaceWorking.Children[i] is Rectangle)
                            {
                                Rectangle convertingObject = (Rectangle)(WorkspaceWorking.Children[i]);
                                if (convertingObject.Tag == Support.virtualObject && ((int)cursorImage.Tag == (int)ObjectID.RAMBO ||
                                                                                      (int)cursorImage.Tag == (int)ObjectID.SNIPER_STANDING) || (int)cursorImage.Tag == (int)ObjectID.TANK ||
                                    (int)cursorImage.Tag == (int)ObjectID.ENEMY_BIG_GUN_SHOOTING || (int)cursorImage.Tag == (int)ObjectID.ENEMY_RUN)
                                {
                                    RECTANGLE tempRect      = new RECTANGLE((float)Canvas.GetLeft(WorkspaceWorking.Children[i]), (float)Canvas.GetTop(WorkspaceWorking.Children[i]), (int)convertingObject.Width, (int)convertingObject.Height);
                                    RECTANGLE collisionRect = RECTANGLE.IntersectCanvas(tempRect, cursor);
                                    if (collisionRect.width != 0 && collisionRect.height != 0)
                                    {
                                        positionTempOfSelectedFromListbox.Y = tempRect.cY - cursorImage.Height;
                                    }
                                }
                                else if (convertingObject.Tag == Support.gridLine && ((int)cursorImage.Tag == (int)ObjectID.GUN_ROTATING ||
                                                                                      (int)cursorImage.Tag == (int)ObjectID.BIG_GUN_ROTATING) || (int)cursorImage.Tag == (int)ObjectID.BRIDGE ||
                                         (int)cursorImage.Tag == (int)ObjectID.WEAPON_SENSOR || (int)cursorImage.Tag == (int)ObjectID.FIRE_BRIDGE || (int)cursorImage.Tag == (int)ObjectID.BIG_BOSS_1 || (int)cursorImage.Tag == (int)ObjectID.BIG_CAPSULE_BOSS)
                                {
                                    RECTANGLE tempRect      = new RECTANGLE((float)Canvas.GetLeft(WorkspaceWorking.Children[i]), (float)Canvas.GetTop(WorkspaceWorking.Children[i]), (int)convertingObject.Width, (int)convertingObject.Height);
                                    RECTANGLE collisionRect = RECTANGLE.IntersectCanvas(tempRect, cursor);
                                    if (collisionRect.width != 0 && collisionRect.height != 0)
                                    {
                                        positionTempOfSelectedFromListbox.X = tempRect.cX;
                                        positionTempOfSelectedFromListbox.Y = tempRect.cY;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    Canvas.SetLeft(cursorImage, (double)(positionTempOfSelectedFromListbox.X));
                    Canvas.SetTop(cursorImage, (double)(positionTempOfSelectedFromListbox.Y));
                    WorkspaceWorking.Children.Add(cursorImage);
                    #endregion
                }

                if (m.LeftButton == MouseButtonState.Pressed && selectedItemFromListbox != null && isAdded == false)
                {
                    WorkspaceWorking.Children.Remove(tempSelectedItem);
                    Image finalSelectedItem = new Image();
                    finalSelectedItem.Tag    = selectedItemFromListbox.Tag;
                    finalSelectedItem.Source = selectedItemFromListbox.Source;
                    finalSelectedItem.Width  = selectedItemFromListbox.Width;
                    finalSelectedItem.Height = selectedItemFromListbox.Height;

                    Canvas.SetLeft(finalSelectedItem, (double)(positionTempOfSelectedFromListbox.X));
                    Canvas.SetTop(finalSelectedItem, (double)(positionTempOfSelectedFromListbox.Y));
                    WorkspaceWorking.Children.Add(finalSelectedItem);
                    isAdded = true;

                    if ((int)finalSelectedItem.Tag == (int)ObjectID.WEAPON_CAPSULE || (int)finalSelectedItem.Tag == (int)ObjectID.WEAPON_SENSOR)
                    {
                        ItemList itemList = new ItemList(WorkspaceWorking, positionTempOfSelectedFromListbox);
                        itemList.ShowDialog();
                    }
                }
            }
            else
            {
                for (int i = 0; i < WorkspaceWorking.Children.Count; ++i)
                {
                    if (WorkspaceWorking.Children[i] is Image)
                    {
                        Image tempSelected = (Image)(WorkspaceWorking.Children[i]);
                        if ((int)tempSelected.Tag != (int)ObjectType.TILE_MAP)
                        {
                            RECTANGLE            rect      = new RECTANGLE((float)Canvas.GetLeft(WorkspaceWorking.Children[i]), (float)Canvas.GetTop(WorkspaceWorking.Children[i]), (int)tempSelected.Width, (int)tempSelected.Height);
                            System.Windows.Point tempPoint = new System.Windows.Point(m.GetPosition(WorkspaceWorking).X, m.GetPosition(WorkspaceWorking).Y);
                            if (rect.IsContain(tempPoint) == true)
                            {
                                WorkspaceWorking.Children.Remove(WorkspaceWorking.Children[i]);
                            }
                        }
                    }
                    else if (WorkspaceWorking.Children[i] is Rectangle)
                    {
                        Rectangle tempRect = (Rectangle)(WorkspaceWorking.Children[i]);
                        if (tempRect.Tag == Support.virtualObject && tempRect.Tag != Support.gridLine)
                        {
                            RECTANGLE            rect      = new RECTANGLE((float)Canvas.GetLeft(WorkspaceWorking.Children[i]), (float)Canvas.GetTop(WorkspaceWorking.Children[i]), (int)tempRect.Width, (int)tempRect.Height);
                            System.Windows.Point tempPoint = new System.Windows.Point(m.GetPosition(WorkspaceWorking).X, m.GetPosition(WorkspaceWorking).Y);
                            if (rect.IsContain(tempPoint) == true)
                            {
                                WorkspaceWorking.Children.Remove(WorkspaceWorking.Children[i]);
                            }
                        }
                    }
                }
            }
            #endregion
        }