Exemplo n.º 1
0
        public ObjectSlotsManager(ObjectSlotManagerGui gui, TabControl tabControlMain)
        {
            _gui = gui;

            // Add SortMethods adn LabelMethods
            _gui.SortMethodComboBox.DataSource      = Enum.GetValues(typeof(SortMethodType));
            _gui.LabelMethodComboBox.DataSource     = Enum.GetValues(typeof(SlotLabelType));
            _gui.SelectionMethodComboBox.DataSource = Enum.GetValues(typeof(SelectionMethodType));

            _gui.TabControl.Selected += TabControl_Selected;
            TabControl_Selected(this, new TabControlEventArgs(_gui.TabControl.SelectedTab, -1, TabControlAction.Selected));

            // Create and setup object slots
            ObjectSlots = new List <ObjectSlot>();
            foreach (int i in Enumerable.Range(0, ObjectSlotsConfig.MaxSlots))
            {
                var objectSlot = new ObjectSlot(this, i, _gui, new Size(DefaultSlotSize, DefaultSlotSize));
                objectSlot.Click += (sender, e) => OnSlotClick(sender, e);
                ObjectSlots.Add(objectSlot);
                _gui.FlowLayoutContainer.Controls.Add(objectSlot);
            }
            ;

            SlotLabelsForObjects = new ReadOnlyDictionary <ObjectDataModel, string>(_slotLabels);
        }
Exemplo n.º 2
0
        public ObjectSlotsManager(ObjectSlotManagerGui managerGui, TabControl tabControlMain)
        {
            ManagerGui = managerGui;

            // Add SortMethods
            ManagerGui.SortMethodComboBox.DataSource = Enum.GetValues(typeof(ObjectSlotsManager.SortMethodType));

            // Add LabelMethods
            ManagerGui.LabelMethodComboBox.DataSource = Enum.GetValues(typeof(ObjectSlotsManager.SlotLabelType));

            ManagerGui.TabControl.Selected += TabControl_Selected;
            TabControl_Selected(this, new TabControlEventArgs(ManagerGui.TabControl.SelectedTab, -1, TabControlAction.Selected));

            // Create and setup object slots
            ObjectSlot.tabControlMain = tabControlMain;
            ObjectSlots = new ObjectSlot[ObjectSlotsConfig.MaxSlots];
            for (int i = 0; i < ObjectSlotsConfig.MaxSlots; i++)
            {
                var objectSlot = new ObjectSlot(i, this, ManagerGui, new Size(DefaultSlotSize, DefaultSlotSize));
                ObjectSlots[i]    = objectSlot;
                objectSlot.Click += (sender, e) => OnSlotClick(sender, e);
                ManagerGui.FlowLayoutContainer.Controls.Add(objectSlot);
            }

            // Change default
            ChangeSlotSize(DefaultSlotSize);
        }
Exemplo n.º 3
0
        public ObjectSlotsManager(ProcessStream stream, ObjectAssociations objAssoc,
                                  ObjectManager objManager, ObjectSlotManagerGui managerGui, MapManager mapManager, MiscManager miscManager)
        {
            ObjectAssoc  = objAssoc;
            _stream      = stream;
            _objManager  = objManager;
            ManagerGui   = managerGui;
            _mapManager  = mapManager;
            _miscManager = miscManager;

            // Add MapToggleModes
            ManagerGui.MapObjectToggleModeComboBox.DataSource   = Enum.GetValues(typeof(MapToggleModeType));
            ManagerGui.MapObjectToggleModeComboBox.SelectedItem = MapToggleModeType.Single;

            // Add SortMethods
            ManagerGui.SortMethodComboBox.DataSource   = Enum.GetValues(typeof(ObjectSlotsManager.SortMethodType));
            ManagerGui.SortMethodComboBox.SelectedItem = SortMethodType.ProcessingOrder;

            // Add LabelMethods
            ManagerGui.LabelMethodComboBox.DataSource   = Enum.GetValues(typeof(ObjectSlotsManager.SlotLabelType));
            ManagerGui.LabelMethodComboBox.SelectedItem = SlotLabelType.Recommended;

            // Create and setup object slots
            ObjectSlots = new ObjectSlot[Config.ObjectSlots.MaxSlots];
            for (int i = 0; i < Config.ObjectSlots.MaxSlots; i++)
            {
                var objectSlot = new ObjectSlot(i, this, ManagerGui, new Size(DefaultSlotSize, DefaultSlotSize));
                ObjectSlots[i]    = objectSlot;
                objectSlot.Click += (sender, e) => OnClick(sender, e);
                ManagerGui.FlowLayoutContainer.Controls.Add(objectSlot);
            }

            // Change default
            ChangeSlotSize(DefaultSlotSize);
        }
Exemplo n.º 4
0
        public ObjectSlot(int index, ObjectSlotsManager manager, ObjectSlotManagerGui gui, Size size)
        {
            Index    = index;
            _manager = manager;
            _gui     = gui;
            Size     = size;
            Font     = new Font(FontFamily.GenericSansSerif, 6);

            this.MouseDown  += OnDrag;
            this.MouseUp    += (s, e) => { MouseState = MouseStateType.None; UpdateColors(); };
            this.MouseEnter += (s, e) =>
            {
                ObjectSlotsConfig.HoverObjectSlot = this;
                MouseState = MouseStateType.Over;
                UpdateColors();
            };
            this.MouseLeave += (s, e) =>
            {
                ObjectSlotsConfig.HoverObjectSlot = null;
                MouseState = MouseStateType.None;
                UpdateColors();
            };
            this.Cursor         = Cursors.Hand;
            this.DoubleBuffered = true;

            SetUpContextMenuStrip();
        }
Exemplo n.º 5
0
        public ObjectSlot(int index, ObjectSlotsManager manager, ObjectSlotManagerGui gui, Size size)
        {
            Index    = index;
            _manager = manager;
            _gui     = gui;
            Size     = size;
            Font     = new Font(FontFamily.GenericSansSerif, 6);

            this.AllowDrop   = true;
            this.MouseDown  += OnDrag;
            this.MouseUp    += (s, e) => { MouseState = MouseStateType.None; UpdateColors(); };
            this.MouseEnter += (s, e) => { MouseState = MouseStateType.Over; UpdateColors(); };
            this.MouseLeave += (s, e) => { MouseState = MouseStateType.None; UpdateColors(); };

            this.DragEnter     += OnDragEnter;
            this.DragDrop      += OnDrop;
            this.Cursor         = Cursors.Hand;
            this.DoubleBuffered = true;
        }
Exemplo n.º 6
0
        public static ObjectAssociations OpenObjectAssoc(string path, ObjectSlotManagerGui objectSlotManagerGui)
        {
            var assoc    = new ObjectAssociations();
            var assembly = Assembly.GetExecutingAssembly();

            // Create schema set
            var schemaSet = new XmlSchemaSet()
            {
                XmlResolver = new ResourceXmlResolver()
            };

            schemaSet.Add("http://tempuri.org/ReusableTypes.xsd", "ReusableTypes.xsd");
            schemaSet.Add("http://tempuri.org/ObjectAssociationsSchema.xsd", "ObjectAssociationsSchema.xsd");
            schemaSet.Compile();

            // Load and validate document
            var doc = XDocument.Load(path);

            doc.Validate(schemaSet, Validation);

            // Create Behavior-ImagePath list
            string defaultImagePath = "", emptyImagePath = "", imageDir = "", mapImageDir = "", overlayImageDir = "",
                   marioImagePath = "", holpMapImagePath = "", hudImagePath = "", debugImagePath = "",
                   miscImagePath = "", cameraImagePath = "", marioMapImagePath = "", cameraMapImagePath = "",
                   selectedOverlayImagePath = "", standingOnOverlayImagePath = "", holdingOverlayImagePath = "",
                   interactingOverlayImagePath = "", usingOverlayImagePath = "", closestOverlayImagePath = "";
            uint ramToBehaviorOffset = 0;
            uint marioBehavior = 0;

            foreach (XElement element in doc.Root.Elements())
            {
                switch (element.Name.ToString())
                {
                case "Config":
                    foreach (XElement subElement in element.Elements())
                    {
                        switch (subElement.Name.ToString())
                        {
                        case "ImageDirectory":
                            imageDir = subElement.Value;
                            break;

                        case "DefaultImage":
                            defaultImagePath = subElement.Value;
                            break;

                        case "MapImageDirectory":
                            mapImageDir = subElement.Value;
                            break;

                        case "OverlayImageDirectory":
                            overlayImageDir = subElement.Value;
                            break;

                        case "EmptyImage":
                            emptyImagePath = subElement.Value;
                            break;

                        case "RamToBehaviorOffset":
                            ramToBehaviorOffset = ParsingUtilities.ParseHex(subElement.Value);
                            assoc.RamOffset     = ramToBehaviorOffset;
                            break;
                        }
                    }
                    break;

                case "Mario":
                    marioImagePath    = element.Element(XName.Get("Image")).Attribute(XName.Get("path")).Value;
                    marioMapImagePath = element.Element(XName.Get("MapImage")) != null?
                                        element.Element(XName.Get("MapImage")).Attribute(XName.Get("path")).Value : null;

                    assoc.MarioColor = ColorTranslator.FromHtml(element.Element(XName.Get("Color")).Value);
                    marioBehavior    = ParsingUtilities.ParseHex(element.Attribute(XName.Get("behaviorScriptAddress")).Value);
                    break;

                case "Hud":
                    hudImagePath   = element.Element(XName.Get("Image")).Attribute(XName.Get("path")).Value;
                    assoc.HudColor = ColorTranslator.FromHtml(element.Element(XName.Get("Color")).Value);
                    break;

                case "Debug":
                    debugImagePath   = element.Element(XName.Get("Image")).Attribute(XName.Get("path")).Value;
                    assoc.DebugColor = ColorTranslator.FromHtml(element.Element(XName.Get("Color")).Value);
                    break;

                case "Misc":
                    miscImagePath   = element.Element(XName.Get("Image")).Attribute(XName.Get("path")).Value;
                    assoc.MiscColor = ColorTranslator.FromHtml(element.Element(XName.Get("Color")).Value);
                    break;

                case "Camera":
                    cameraImagePath    = element.Element(XName.Get("Image")).Attribute(XName.Get("path")).Value;
                    assoc.CameraColor  = ColorTranslator.FromHtml(element.Element(XName.Get("Color")).Value);
                    cameraMapImagePath = element.Element(XName.Get("MapImage")).Attribute(XName.Get("path")).Value;
                    break;

                case "Holp":
                    holpMapImagePath = element.Element(XName.Get("MapImage")).Attribute(XName.Get("path")).Value;
                    break;

                case "Overlays":
                    foreach (XElement subElement in element.Elements())
                    {
                        switch (subElement.Name.ToString())
                        {
                        case "Selected":
                            selectedOverlayImagePath = subElement.Element(XName.Get("OverlayImage")).Attribute(XName.Get("path")).Value;
                            break;

                        case "StandingOn":
                            standingOnOverlayImagePath = subElement.Element(XName.Get("OverlayImage")).Attribute(XName.Get("path")).Value;
                            break;

                        case "Holding":
                            holdingOverlayImagePath = subElement.Element(XName.Get("OverlayImage")).Attribute(XName.Get("path")).Value;
                            break;

                        case "Interacting":
                            interactingOverlayImagePath = subElement.Element(XName.Get("OverlayImage")).Attribute(XName.Get("path")).Value;
                            break;

                        case "Using":
                            usingOverlayImagePath = subElement.Element(XName.Get("OverlayImage")).Attribute(XName.Get("path")).Value;
                            break;

                        case "Closest":
                            closestOverlayImagePath = subElement.Element(XName.Get("OverlayImage")).Attribute(XName.Get("path")).Value;
                            break;
                        }
                    }
                    break;

                case "Object":
                    uint behaviorAddress = (ParsingUtilities.ParseHex(element.Attribute(XName.Get("behaviorScriptAddress")).Value)
                                            - ramToBehaviorOffset) & 0x00FFFFFF;
                    uint?gfxId = null;
                    int? subType = null, appearance = null;
                    if (element.Attribute(XName.Get("gfxId")) != null)
                    {
                        gfxId = ParsingUtilities.ParseHex(element.Attribute(XName.Get("gfxId")).Value) | 0x80000000U;
                    }
                    if (element.Attribute(XName.Get("subType")) != null)
                    {
                        subType = ParsingUtilities.TryParseInt(element.Attribute(XName.Get("subType")).Value);
                    }
                    if (element.Attribute(XName.Get("appearance")) != null)
                    {
                        appearance = ParsingUtilities.TryParseInt(element.Attribute(XName.Get("appearance")).Value);
                    }
                    string imagePath    = element.Element(XName.Get("Image")).Attribute(XName.Get("path")).Value;
                    string mapImagePath = null;
                    bool   rotates      = false;
                    if (element.Element(XName.Get("MapImage")) != null)
                    {
                        mapImagePath = element.Element(XName.Get("MapImage")).Attribute(XName.Get("path")).Value;
                        rotates      = bool.Parse(element.Element(XName.Get("MapImage")).Attribute(XName.Get("rotates")).Value);
                    }
                    string name      = element.Attribute(XName.Get("name")).Value;
                    var    watchVars = new List <WatchVariable>();
                    foreach (var subElement in element.Elements().Where(x => x.Name == "Data"))
                    {
                        var watchVar = GetWatchVariableFromElement(subElement);
                        watchVar.OtherOffset = (subElement.Attribute(XName.Get("objectOffset")) != null) ?
                                               bool.Parse(subElement.Attribute(XName.Get("objectOffset")).Value) : false;

                        watchVars.Add(watchVar);
                    }

                    var newBehavior = new ObjectBehaviorAssociation()
                    {
                        BehaviorCriteria = new BehaviorCriteria()
                        {
                            BehaviorAddress = behaviorAddress,
                            GfxId           = gfxId,
                            SubType         = subType,
                            Appearance      = appearance
                        },
                        ImagePath      = imagePath,
                        MapImagePath   = mapImagePath,
                        Name           = name,
                        RotatesOnMap   = rotates,
                        WatchVariables = watchVars
                    };

                    if (!assoc.AddAssociation(newBehavior))
                    {
                        throw new Exception("More than one behavior address was defined.");
                    }

                    break;
                }
            }

            // Load Images
            // TODO: Exceptions
            assoc.DefaultImage   = Bitmap.FromFile(imageDir + defaultImagePath);
            assoc.EmptyImage     = Bitmap.FromFile(imageDir + emptyImagePath);
            assoc.MarioImage     = Bitmap.FromFile(imageDir + marioImagePath);
            assoc.CameraImage    = Bitmap.FromFile(imageDir + cameraImagePath);
            assoc.MarioMapImage  = marioMapImagePath == "" ? assoc.MarioImage : Bitmap.FromFile(mapImageDir + marioMapImagePath);
            assoc.HudImage       = Bitmap.FromFile(imageDir + hudImagePath);
            assoc.DebugImage     = Bitmap.FromFile(imageDir + debugImagePath);
            assoc.MiscImage      = Bitmap.FromFile(imageDir + miscImagePath);
            assoc.HolpImage      = Bitmap.FromFile(mapImageDir + holpMapImagePath);
            assoc.CameraMapImage = Bitmap.FromFile(mapImageDir + cameraMapImagePath);
            assoc.MarioBehavior  = marioBehavior - ramToBehaviorOffset;
            objectSlotManagerGui.SelectedObjectOverlayImage    = Bitmap.FromFile(overlayImageDir + selectedOverlayImagePath);
            objectSlotManagerGui.StandingOnObjectOverlayImage  = Bitmap.FromFile(overlayImageDir + standingOnOverlayImagePath);
            objectSlotManagerGui.HoldingObjectOverlayImage     = Bitmap.FromFile(overlayImageDir + holdingOverlayImagePath);
            objectSlotManagerGui.InteractingObjectOverlayImage = Bitmap.FromFile(overlayImageDir + interactingOverlayImagePath);
            objectSlotManagerGui.UsingObjectOverlayImage       = Bitmap.FromFile(overlayImageDir + usingOverlayImagePath);
            objectSlotManagerGui.ClosestObjectOverlayImage     = Bitmap.FromFile(overlayImageDir + closestOverlayImagePath);

            foreach (var obj in assoc.BehaviorAssociations)
            {
                if (obj.ImagePath == null || obj.ImagePath == "")
                {
                    continue;
                }

                using (var preLoad = Bitmap.FromFile(imageDir + obj.ImagePath))
                {
                    float scale = Math.Max(preLoad.Height / 128f, preLoad.Width / 128f);
                    obj.Image = new Bitmap(preLoad, new Size((int)(preLoad.Width / scale), (int)(preLoad.Height / scale)));
                }
                if (obj.MapImagePath == "" || obj.MapImagePath == null)
                {
                    obj.MapImage = obj.Image;
                }
                else
                {
                    using (var preLoad = Bitmap.FromFile(mapImageDir + obj.MapImagePath))
                    {
                        float scale = Math.Max(preLoad.Height / 128f, preLoad.Width / 128f);
                        obj.MapImage = new Bitmap(preLoad, new Size((int)(preLoad.Width / scale), (int)(preLoad.Height / scale)));
                    }
                }
                obj.TransparentImage    = obj.Image.GetOpaqueImage(0.5f);
                obj.TransparentMapImage = obj.Image.GetOpaqueImage(0.5f);
            }

            return(assoc);
        }