コード例 #1
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (Mouse.LButtonPressed && !IsHoldingItem)
            {
                Point offset = Mouse.LDroppedOffset;

                if (Math.Abs(offset.X) > Constants.MIN_PICKUP_DRAG_DISTANCE || Math.Abs(offset.Y) > Constants.MIN_PICKUP_DRAG_DISTANCE)
                {
                    GameObject obj = _dragginObject;

                    switch (obj)
                    {
                    case Mobile mobile:
                        GameActions.RequestMobileStatus(mobile);

                        Engine.UI.GetByLocalSerial <HealthBarGump>(mobile)?.Dispose();

                        if (mobile == World.Player)
                        {
                            StatusGumpBase.GetStatusGump()?.Dispose();
                        }

                        Rectangle     rect = FileManager.Gumps.GetTexture(0x0804).Bounds;
                        HealthBarGump currentHealthBarGump;
                        Engine.UI.Add(currentHealthBarGump = new HealthBarGump(mobile)
                        {
                            X = Mouse.Position.X - (rect.Width >> 1), Y = Mouse.Position.Y - (rect.Height >> 1)
                        });
                        Engine.UI.AttemptDragControl(currentHealthBarGump, Mouse.Position, true);


                        break;

                    case Item item:
                        PickupItemBegin(item, _dragOffset.X, _dragOffset.Y);

                        break;
                    }

                    _dragginObject = null;
                }
            }
        }
コード例 #2
0
        private void OnMouseDragBegin(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButton.Left)
            {
                if (!IsHoldingItem)
                {
                    GameObject obj = _dragginObject;

                    switch (obj)
                    {
                    case Mobile mobile:
                        GameActions.RequestMobileStatus(mobile);

                        Engine.UI.GetByLocalSerial <HealthBarGump>(mobile)?.Dispose();

                        if (mobile == World.Player)
                        {
                            StatusGumpBase.GetStatusGump()?.Dispose();
                        }

                        Rectangle     rect = FileManager.Gumps.GetTexture(0x0804).Bounds;
                        HealthBarGump currentHealthBarGump;
                        Engine.UI.Add(currentHealthBarGump = new HealthBarGump(mobile)
                        {
                            X = Mouse.Position.X - (rect.Width >> 1), Y = Mouse.Position.Y - (rect.Height >> 1)
                        });
                        Engine.UI.AttemptDragControl(currentHealthBarGump, Mouse.Position, true);


                        break;

                    case Item item:
                        PickupItemBegin(item, _dragOffset.X, _dragOffset.Y);

                        break;
                    }

                    _dragginObject = null;
                }
            }
        }
コード例 #3
0
        public List <Gump> ReadGumps(string path)
        {
            List <Gump> gumps = new List <Gump>();

            // load skillsgroup
            SkillsGroupManager.Load();

            // load gumps
            string gumpsXmlPath = Path.Combine(path, "gumps.xml");

            if (File.Exists(gumpsXmlPath))
            {
                XmlDocument doc = new XmlDocument();

                try
                {
                    doc.Load(gumpsXmlPath);
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());

                    return(gumps);
                }

                XmlElement root = doc["gumps"];

                if (root != null)
                {
                    foreach (XmlElement xml in root.ChildNodes /*.GetElementsByTagName("gump")*/)
                    {
                        if (xml.Name != "gump")
                        {
                            continue;
                        }

                        try
                        {
                            GumpType type   = (GumpType)int.Parse(xml.GetAttribute(nameof(type)));
                            int      x      = int.Parse(xml.GetAttribute(nameof(x)));
                            int      y      = int.Parse(xml.GetAttribute(nameof(y)));
                            uint     serial = uint.Parse(xml.GetAttribute(nameof(serial)));

                            Gump gump = null;

                            switch (type)
                            {
                            case GumpType.Buff:
                                gump = new BuffGump();

                                break;

                            case GumpType.Container:
                                gump = new ContainerGump();

                                break;

                            case GumpType.CounterBar:
                                gump = new CounterBarGump();

                                break;

                            case GumpType.HealthBar:
                                if (CustomBarsToggled)
                                {
                                    gump = new HealthBarGumpCustom();
                                }
                                else
                                {
                                    gump = new HealthBarGump();
                                }

                                break;

                            case GumpType.InfoBar:
                                gump = new InfoBarGump();

                                break;

                            case GumpType.Journal:
                                gump = new JournalGump();

                                break;

                            case GumpType.MacroButton:
                                gump = new MacroButtonGump();

                                break;

                            case GumpType.MiniMap:
                                gump = new MiniMapGump();

                                break;

                            case GumpType.PaperDoll:
                                gump = new PaperDollGump();

                                break;

                            case GumpType.SkillMenu:
                                if (StandardSkillsGump)
                                {
                                    gump = new StandardSkillsGump();
                                }
                                else
                                {
                                    gump = new SkillGumpAdvanced();
                                }

                                break;

                            case GumpType.SpellBook:
                                gump = new SpellbookGump();

                                break;

                            case GumpType.StatusGump:
                                gump = StatusGumpBase.AddStatusGump(0, 0);

                                break;

                            //case GumpType.TipNotice:
                            //    gump = new TipNoticeGump();
                            //    break;
                            case GumpType.AbilityButton:
                                gump = new UseAbilityButtonGump();

                                break;

                            case GumpType.SpellButton:
                                gump = new UseSpellButtonGump();

                                break;

                            case GumpType.SkillButton:
                                gump = new SkillButtonGump();

                                break;

                            case GumpType.RacialButton:
                                gump = new RacialAbilityButton();

                                break;

                            case GumpType.WorldMap:
                                gump = new WorldMapGump();

                                break;

                            case GumpType.Debug:
                                gump = new DebugGump(100, 100);

                                break;

                            case GumpType.NetStats:
                                gump = new NetworkStatsGump(100, 100);

                                break;
                            }

                            if (gump == null)
                            {
                                continue;
                            }

                            gump.LocalSerial = serial;
                            gump.Restore(xml);
                            gump.X = x;
                            gump.Y = y;

                            if (gump.LocalSerial != 0)
                            {
                                UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                            }

                            if (!gump.IsDisposed)
                            {
                                gumps.Add(gump);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                        }
                    }

                    foreach (XmlElement group in root.GetElementsByTagName("anchored_group_gump"))
                    {
                        int matrix_width  = int.Parse(group.GetAttribute("matrix_w"));
                        int matrix_height = int.Parse(group.GetAttribute("matrix_h"));

                        AnchorManager.AnchorGroup ancoGroup = new AnchorManager.AnchorGroup();
                        ancoGroup.ResizeMatrix(matrix_width, matrix_height, 0, 0);

                        foreach (XmlElement xml in group.GetElementsByTagName("gump"))
                        {
                            try
                            {
                                GumpType type   = (GumpType)int.Parse(xml.GetAttribute("type"));
                                int      x      = int.Parse(xml.GetAttribute("x"));
                                int      y      = int.Parse(xml.GetAttribute("y"));
                                uint     serial = uint.Parse(xml.GetAttribute("serial"));

                                int matrix_x = int.Parse(xml.GetAttribute("matrix_x"));
                                int matrix_y = int.Parse(xml.GetAttribute("matrix_y"));

                                AnchorableGump gump = null;

                                switch (type)
                                {
                                case GumpType.SpellButton:
                                    gump = new UseSpellButtonGump();

                                    break;

                                case GumpType.SkillButton:
                                    gump = new SkillButtonGump();

                                    break;

                                case GumpType.HealthBar:
                                    if (CustomBarsToggled)
                                    {
                                        gump = new HealthBarGumpCustom();
                                    }
                                    else
                                    {
                                        gump = new HealthBarGump();
                                    }

                                    break;

                                case GumpType.AbilityButton:
                                    gump = new UseAbilityButtonGump();

                                    break;

                                case GumpType.MacroButton:
                                    gump = new MacroButtonGump();

                                    break;
                                }

                                if (gump != null)
                                {
                                    gump.LocalSerial = serial;
                                    gump.Restore(xml);
                                    gump.X = x;
                                    gump.Y = y;

                                    if (!gump.IsDisposed)
                                    {
                                        if (UIManager.AnchorManager[gump] == null && ancoGroup.IsEmptyDirection(matrix_x, matrix_y))
                                        {
                                            gumps.Add(gump);
                                            UIManager.AnchorManager[gump] = ancoGroup;
                                            ancoGroup.AddControlToMatrix(matrix_x, matrix_y, gump);
                                        }
                                        else
                                        {
                                            gump.Dispose();
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex.ToString());
                            }
                        }
                    }
                }
            }

            return(gumps);
        }
コード例 #4
0
ファイル: Profile.cs プロジェクト: zerodowned/ClassicUO
        public List <Gump> ReadGumps()
        {
            string      path  = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username.Trim(), ServerName.Trim(), CharacterName.Trim());
            List <Gump> gumps = new List <Gump>();



            // #########################################################
            // [FILE_FIX]
            // TODO: this code is a workaround to port old macros to the new xml system.
            string skillsGroupsPath = Path.Combine(path, "skillsgroups.bin");

            if (File.Exists(skillsGroupsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(skillsGroupsPath)))
                    {
                        int version = reader.ReadInt32();

                        int groupCount = reader.ReadInt32();

                        for (int i = 0; i < groupCount; i++)
                        {
                            int    entriesCount = reader.ReadInt32();
                            string groupName    = reader.ReadUTF8String(reader.ReadInt32());

                            SkillsGroup g = new SkillsGroup();
                            g.Name = groupName;

                            for (int j = 0; j < entriesCount; j++)
                            {
                                byte idx = (byte)reader.ReadInt32();
                                g.Add(idx);
                            }

                            g.Sort();

                            SkillsGroupManager.Add(g);
                        }
                    }
                }
                catch (Exception e)
                {
                    SkillsGroupManager.MakeDefault();
                    Log.Error(e.StackTrace);
                }


                SkillsGroupManager.Save();

                try
                {
                    File.Delete(skillsGroupsPath);
                }
                catch { }
            }

            string binpath = Path.Combine(path, "gumps.bin");

            if (File.Exists(binpath))
            {
                using (BinaryReader reader = new BinaryReader(File.OpenRead(binpath)))
                {
                    if (reader.BaseStream.Position + 12 < reader.BaseStream.Length)
                    {
                        GumpsVersion = reader.ReadUInt32();
                        uint empty = reader.ReadUInt32();

                        int count = reader.ReadInt32();

                        for (int i = 0; i < count; i++)
                        {
                            try
                            {
                                int    typeLen  = reader.ReadUInt16();
                                string typeName = reader.ReadUTF8String(typeLen);
                                int    x        = reader.ReadInt32();
                                int    y        = reader.ReadInt32();

                                Type type = Type.GetType(typeName, true);
                                Gump gump = (Gump)Activator.CreateInstance(type);
                                gump.Restore(reader);
                                gump.X = x;
                                gump.Y = y;

                                //gump.SetInScreen();

                                if (gump.LocalSerial != 0)
                                {
                                    UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                                }

                                if (!gump.IsDisposed)
                                {
                                    gumps.Add(gump);
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Error(e.StackTrace);
                            }
                        }
                    }
                }

                SaveGumps(path, gumps);

                gumps.Clear();

                try
                {
                    File.Delete(binpath);
                }
                catch
                {
                }
            }
            // #########################################################



            // load skillsgroup
            //SkillsGroupManager.Load();
            SkillsGroupManager.Load();

            // load gumps
            string gumpsXmlPath = Path.Combine(path, "gumps.xml");

            if (File.Exists(gumpsXmlPath))
            {
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(gumpsXmlPath);
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());

                    return(gumps);
                }

                XmlElement root = doc["gumps"];

                if (root != null)
                {
                    foreach (XmlElement xml in root.GetElementsByTagName("gump"))
                    {
                        try
                        {
                            GUMP_TYPE type   = (GUMP_TYPE)int.Parse(xml.GetAttribute("type"));
                            int       x      = int.Parse(xml.GetAttribute("x"));
                            int       y      = int.Parse(xml.GetAttribute("y"));
                            uint      serial = uint.Parse(xml.GetAttribute("serial"));

                            Gump gump = null;
                            switch (type)
                            {
                            case GUMP_TYPE.GT_BUFF:
                                gump = new BuffGump();
                                break;

                            case GUMP_TYPE.GT_CONTAINER:
                                gump = new ContainerGump();
                                break;

                            case GUMP_TYPE.GT_COUNTERBAR:
                                gump = new CounterBarGump();
                                break;

                            case GUMP_TYPE.GT_HEALTHBAR:
                                if (CustomBarsToggled)
                                {
                                    gump = new HealthBarGumpCustom();
                                }
                                else
                                {
                                    gump = new HealthBarGump();
                                }
                                break;

                            case GUMP_TYPE.GT_INFOBAR:
                                gump = new InfoBarGump();
                                break;

                            case GUMP_TYPE.GT_JOURNAL:
                                gump = new JournalGump();
                                break;

                            case GUMP_TYPE.GT_MACROBUTTON:
                                gump = new MacroButtonGump();
                                break;

                            case GUMP_TYPE.GT_MINIMAP:
                                gump = new MiniMapGump();
                                break;

                            case GUMP_TYPE.GT_PAPERDOLL:
                                gump = new PaperDollGump();
                                break;

                            case GUMP_TYPE.GT_SKILLMENU:
                                if (StandardSkillsGump)
                                {
                                    gump = new StandardSkillsGump();
                                }
                                else
                                {
                                    gump = new SkillGumpAdvanced();
                                }
                                break;

                            case GUMP_TYPE.GT_SPELLBOOK:
                                gump = new SpellbookGump();
                                break;

                            case GUMP_TYPE.GT_STATUSGUMP:
                                switch (Settings.GlobalSettings.ShardType)
                                {
                                default:
                                case 0:         // modern

                                    gump = new StatusGumpModern();

                                    break;

                                case 1:         // old

                                    gump = new StatusGumpOld();

                                    break;

                                case 2:         // outlands

                                    gump = new StatusGumpOutlands();

                                    break;
                                }
                                break;

                            //case GUMP_TYPE.GT_TIPNOTICE:
                            //    gump = new TipNoticeGump();
                            //    break;
                            case GUMP_TYPE.GT_ABILITYBUTTON:
                                gump = new UseAbilityButtonGump();
                                break;

                            case GUMP_TYPE.GT_SPELLBUTTON:
                                gump = new UseSpellButtonGump();
                                break;

                            case GUMP_TYPE.GT_SKILLBUTTON:
                                gump = new SkillButtonGump();
                                break;

                            case GUMP_TYPE.GT_RACIALBUTTON:
                                gump = new RacialAbilityButton();
                                break;

                            case GUMP_TYPE.GT_WORLDMAP:
                                gump = new WorldMapGump();
                                break;
                            }

                            if (gump == null)
                            {
                                continue;
                            }

                            gump.LocalSerial = serial;
                            gump.Restore(xml);
                            gump.X = x;
                            gump.Y = y;

                            if (gump.LocalSerial != 0)
                            {
                                UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                            }

                            if (!gump.IsDisposed)
                            {
                                gumps.Add(gump);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                        }
                    }
                }
            }


            // load anchors
            string anchorsPath = Path.Combine(path, "anchors.bin");

            if (File.Exists(anchorsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(anchorsPath)))
                        UIManager.AnchorManager.Restore(reader, gumps);
                }
                catch (Exception e)
                {
                    Log.Error(e.StackTrace);
                }
            }


            return(gumps);
        }
コード例 #5
0
ファイル: PartyManager.cs プロジェクト: canterberry/ClassicUO
        public void ParsePacket(Packet p)
        {
            byte code = p.ReadByte();

            switch (code)
            {
            case 1:
            case 2:
                byte count = p.ReadByte();

                if (count <= 1)
                {
                    Leader  = 0;
                    Inviter = 0;

                    for (int i = 0; i < Members.Length; i++)
                    {
                        if (Members[i] == null || Members[i].Serial == 0)
                        {
                            break;
                        }

                        HealthBarGump gump = Engine.UI.GetControl <HealthBarGump>(Members[i].Serial);


                        if (gump != null)
                        {
                            if (code == 2)
                            {
                                Members[i].Serial = 0;
                            }

                            gump.Update();
                        }
                    }

                    Clear();
                    Engine.UI.GetControl <PartyGumpAdvanced>()?.Update();

                    break;
                }

                Clear();

                for (int i = 0; i < count; i++)
                {
                    Serial serial = p.ReadUInt();
                    Members[i] = new PartyMember(serial);

                    if (i == 0)
                    {
                        Leader = serial;
                    }


                    HealthBarGump gump = Engine.UI.GetControl <HealthBarGump>(serial);

                    if (gump != null)
                    {
                        GameActions.RequestMobileStatus(serial);
                        gump.Update();
                    }
                    else
                    {
                        if (serial == World.Player)
                        {
                        }
                    }
                }

                Engine.UI.GetControl <PartyGumpAdvanced>()?.Update();

                break;

            case 3:
            case 4:
                Serial ser  = p.ReadUInt();
                string name = p.ReadUnicode();

                for (int i = 0; i < Members.Length; i++)
                {
                    if (Members[i] == null)
                    {
                        break;
                    }

                    if (Members[i].Serial == ser)
                    {
                        Mobile m = Members[i].Mobile;

                        if (m != null)
                        {
                            Chat.HandleMessage(null, name, m.Name, Engine.Profile.Current.PartyMessageHue, MessageType.Party, 3);
                        }

                        break;
                    }
                }

                break;

            case 7:
                Inviter = p.ReadUInt();

                break;
            }
        }
コード例 #6
0
        private void DoDragSelect()
        {
            if (_selectionStart.X > Mouse.Position.X)
            {
                _selectionEnd.X   = _selectionStart.X;
                _selectionStart.X = Mouse.Position.X;
            }
            else
            {
                _selectionEnd.X = Mouse.Position.X;
            }

            if (_selectionStart.Y > Mouse.Position.Y)
            {
                _selectionEnd.Y   = _selectionStart.Y;
                _selectionStart.Y = Mouse.Position.Y;
            }
            else
            {
                _selectionEnd.Y = Mouse.Position.Y;
            }


            _rectangleObj.X      = _selectionStart.X - Camera.Bounds.X;
            _rectangleObj.Y      = _selectionStart.Y - Camera.Bounds.Y;
            _rectangleObj.Width  = _selectionEnd.X - Camera.Bounds.X - _rectangleObj.X;
            _rectangleObj.Height = _selectionEnd.Y - Camera.Bounds.Y - _rectangleObj.Y;

            int finalX = 100;
            int finalY = 100;

            bool useCHB = ProfileManager.CurrentProfile.CustomBarsToggled;

            Rectangle rect = useCHB ? new Rectangle(0, 0, HealthBarGumpCustom.HPB_BAR_WIDTH, HealthBarGumpCustom.HPB_HEIGHT_MULTILINE) : GumpsLoader.Instance.GetTexture(0x0804).Bounds;

            foreach (Mobile mobile in World.Mobiles)
            {
                if (ProfileManager.CurrentProfile.DragSelectHumanoidsOnly && !mobile.IsHuman)
                {
                    continue;
                }

                Point p = mobile.RealScreenPosition;

                p.X += (int)mobile.Offset.X + 22 + 5;
                p.Y += (int)(mobile.Offset.Y - mobile.Offset.Z) + 22 + 5;
                p.X -= mobile.FrameInfo.X;
                p.Y -= mobile.FrameInfo.Y;

                Point size = new Point(p.X + mobile.FrameInfo.Width, p.Y + mobile.FrameInfo.Height);

                p = Camera.WorldToScreen(p);
                _rectanglePlayer.X = p.X;
                _rectanglePlayer.Y = p.Y;


                size = Camera.WorldToScreen(size);
                _rectanglePlayer.Width  = size.X - p.X;
                _rectanglePlayer.Height = size.Y - p.Y;

                if (_rectangleObj.Intersects(_rectanglePlayer))
                {
                    if (mobile != World.Player)
                    {
                        if (UIManager.GetGump <BaseHealthBarGump>(mobile) != null)
                        {
                            continue;
                        }

                        BaseHealthBarGump hbgc;

                        if (useCHB)
                        {
                            hbgc = new HealthBarGumpCustom(mobile);
                        }
                        else
                        {
                            hbgc = new HealthBarGump(mobile);
                        }

                        if (finalY >= ProfileManager.CurrentProfile.GameWindowPosition.Y + ProfileManager.CurrentProfile.GameWindowSize.Y - 100)
                        {
                            finalY  = 100;
                            finalX += rect.Width + 2;
                        }

                        if (finalX >= ProfileManager.CurrentProfile.GameWindowPosition.X + ProfileManager.CurrentProfile.GameWindowSize.X - 100)
                        {
                            finalX = 100;
                        }

                        hbgc.X = finalX;
                        hbgc.Y = finalY;


                        foreach (BaseHealthBarGump bar in UIManager.Gumps.OfType <BaseHealthBarGump>()
                                 //.OrderBy(s => mobile.NotorietyFlag)
                                 //.OrderBy(s => s.ScreenCoordinateX) ///testing placement SYRUPZ SYRUPZ SYRUPZ
                                 .OrderBy(s => s.ScreenCoordinateX)
                                 .ThenBy(s => s.ScreenCoordinateY))
                        {
                            if (bar.Bounds.Intersects(hbgc.Bounds))
                            {
                                finalY = bar.Bounds.Bottom + 2;

                                if (finalY >= ProfileManager.CurrentProfile.GameWindowPosition.Y + ProfileManager.CurrentProfile.GameWindowSize.Y - 100)
                                {
                                    finalY = 100;
                                    finalX = bar.Bounds.Right + 2;
                                }

                                if (finalX >= ProfileManager.CurrentProfile.GameWindowPosition.X + ProfileManager.CurrentProfile.GameWindowSize.X - 100)
                                {
                                    finalX = 100;
                                }

                                hbgc.X = finalX;
                                hbgc.Y = finalY;
                            }
                        }


                        finalY += rect.Height + 2;


                        UIManager.Add(hbgc);

                        hbgc.SetInScreen();
                    }
                }
            }

            _isSelectionActive = false;
        }
コード例 #7
0
ファイル: Profile.cs プロジェクト: perpetualy/ClassicUO
        public List <Gump> ReadGumps(string path)
        {
            List <Gump> gumps = new List <Gump>();


            // #########################################################
            // [FILE_FIX]
            // TODO: this code is a workaround to port old macros to the new xml system.
            string skillsGroupsPath = Path.Combine(path, "skillsgroups.bin");

            if (File.Exists(skillsGroupsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(skillsGroupsPath)))
                    {
                        int version = reader.ReadInt32();

                        int groupCount = reader.ReadInt32();

                        for (int i = 0; i < groupCount; i++)
                        {
                            int    entriesCount = reader.ReadInt32();
                            string groupName    = reader.ReadUTF8String(reader.ReadInt32());

                            SkillsGroup g = new SkillsGroup();
                            g.Name = groupName;

                            for (int j = 0; j < entriesCount; j++)
                            {
                                byte idx = (byte)reader.ReadInt32();
                                g.Add(idx);
                            }

                            g.Sort();

                            SkillsGroupManager.Add(g);
                        }
                    }
                }
                catch (Exception e)
                {
                    SkillsGroupManager.MakeDefault();
                    Log.Error(e.StackTrace);
                }


                SkillsGroupManager.Save();

                try
                {
                    File.Delete(skillsGroupsPath);
                }
                catch
                {
                }
            }

            string binpath = Path.Combine(path, "gumps.bin");

            if (File.Exists(binpath))
            {
                using (BinaryReader reader = new BinaryReader(File.OpenRead(binpath)))
                {
                    if (reader.BaseStream.Position + 12 < reader.BaseStream.Length)
                    {
                        GumpsVersion = reader.ReadUInt32();
                        uint empty = reader.ReadUInt32();

                        int count = reader.ReadInt32();

                        for (int i = 0; i < count; i++)
                        {
                            try
                            {
                                int    typeLen  = reader.ReadUInt16();
                                string typeName = reader.ReadUTF8String(typeLen);
                                int    x        = reader.ReadInt32();
                                int    y        = reader.ReadInt32();

                                Type type = Type.GetType(typeName, true);
                                Gump gump = (Gump)Activator.CreateInstance(type);
                                gump.Restore(reader);
                                gump.X = x;
                                gump.Y = y;

                                //gump.SetInScreen();

                                if (gump.LocalSerial != 0)
                                {
                                    UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                                }

                                if (!gump.IsDisposed)
                                {
                                    gumps.Add(gump);
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Error(e.StackTrace);
                            }
                        }
                    }
                }

                SaveGumps(path);

                gumps.Clear();

                try
                {
                    File.Delete(binpath);
                }
                catch
                {
                }
            }
            // #########################################################


            // load skillsgroup
            //SkillsGroupManager.Load();
            SkillsGroupManager.Load();

            // load gumps
            string gumpsXmlPath = Path.Combine(path, "gumps.xml");

            if (File.Exists(gumpsXmlPath))
            {
                XmlDocument doc = new XmlDocument();

                try
                {
                    doc.Load(gumpsXmlPath);
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());

                    return(gumps);
                }

                XmlElement root = doc["gumps"];

                if (root != null)
                {
                    foreach (XmlElement xml in root.ChildNodes /*.GetElementsByTagName("gump")*/)
                    {
                        if (xml.Name != "gump")
                        {
                            continue;
                        }

                        try
                        {
                            GumpType type   = (GumpType)int.Parse(xml.GetAttribute(nameof(type)));
                            int      x      = int.Parse(xml.GetAttribute(nameof(x)));
                            int      y      = int.Parse(xml.GetAttribute(nameof(y)));
                            uint     serial = uint.Parse(xml.GetAttribute(nameof(serial)));

                            Gump gump = null;

                            switch (type)
                            {
                            case GumpType.Buff:
                                gump = new BuffGump();

                                break;

                            case GumpType.Container:
                                gump = new ContainerGump();

                                break;

                            case GumpType.CounterBar:
                                gump = new CounterBarGump();

                                break;

                            case GumpType.HealthBar:
                                if (CustomBarsToggled)
                                {
                                    gump = new HealthBarGumpCustom();
                                }
                                else
                                {
                                    gump = new HealthBarGump();
                                }

                                break;

                            case GumpType.InfoBar:
                                gump = new InfoBarGump();

                                break;

                            case GumpType.Journal:
                                gump = new JournalGump();

                                break;

                            case GumpType.MacroButton:
                                gump = new MacroButtonGump();

                                break;

                            case GumpType.MiniMap:
                                gump = new MiniMapGump();

                                break;

                            case GumpType.PaperDoll:
                                gump = new PaperDollGump();

                                break;

                            case GumpType.SkillMenu:
                                if (StandardSkillsGump)
                                {
                                    gump = new StandardSkillsGump();
                                }
                                else
                                {
                                    gump = new SkillGumpAdvanced();
                                }

                                break;

                            case GumpType.SpellBook:
                                gump = new SpellbookGump();

                                break;

                            case GumpType.StatusGump:
                                gump = StatusGumpBase.AddStatusGump(0, 0);

                                break;

                            //case GumpType.TipNotice:
                            //    gump = new TipNoticeGump();
                            //    break;
                            case GumpType.AbilityButton:
                                gump = new UseAbilityButtonGump();

                                break;

                            case GumpType.SpellButton:
                                gump = new UseSpellButtonGump();

                                break;

                            case GumpType.SkillButton:
                                gump = new SkillButtonGump();

                                break;

                            case GumpType.RacialButton:
                                gump = new RacialAbilityButton();

                                break;

                            case GumpType.WorldMap:
                                gump = new WorldMapGump();

                                break;

                            case GumpType.Debug:
                                gump = new DebugGump(100, 100);

                                break;

                            case GumpType.NetStats:
                                gump = new NetworkStatsGump(100, 100);

                                break;
                            }

                            if (gump == null)
                            {
                                continue;
                            }

                            gump.LocalSerial = serial;
                            gump.Restore(xml);
                            gump.X = x;
                            gump.Y = y;

                            if (gump.LocalSerial != 0)
                            {
                                UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                            }

                            if (!gump.IsDisposed)
                            {
                                gumps.Add(gump);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                        }
                    }

                    foreach (XmlElement group in root.GetElementsByTagName("anchored_group_gump"))
                    {
                        int matrix_width  = int.Parse(group.GetAttribute("matrix_w"));
                        int matrix_height = int.Parse(group.GetAttribute("matrix_h"));

                        AnchorManager.AnchorGroup ancoGroup = new AnchorManager.AnchorGroup();
                        ancoGroup.ResizeMatrix(matrix_width, matrix_height, 0, 0);

                        foreach (XmlElement xml in group.GetElementsByTagName("gump"))
                        {
                            try
                            {
                                GumpType type   = (GumpType)int.Parse(xml.GetAttribute("type"));
                                int      x      = int.Parse(xml.GetAttribute("x"));
                                int      y      = int.Parse(xml.GetAttribute("y"));
                                uint     serial = uint.Parse(xml.GetAttribute("serial"));

                                int matrix_x = int.Parse(xml.GetAttribute("matrix_x"));
                                int matrix_y = int.Parse(xml.GetAttribute("matrix_y"));

                                AnchorableGump gump = null;

                                switch (type)
                                {
                                case GumpType.SpellButton:
                                    gump = new UseSpellButtonGump();

                                    break;

                                case GumpType.SkillButton:
                                    gump = new SkillButtonGump();

                                    break;

                                case GumpType.HealthBar:
                                    if (CustomBarsToggled)
                                    {
                                        gump = new HealthBarGumpCustom();
                                    }
                                    else
                                    {
                                        gump = new HealthBarGump();
                                    }

                                    break;

                                case GumpType.AbilityButton:
                                    gump = new UseAbilityButtonGump();

                                    break;

                                case GumpType.MacroButton:
                                    gump = new MacroButtonGump();

                                    break;
                                }

                                if (gump != null)
                                {
                                    gump.LocalSerial = serial;
                                    gump.Restore(xml);
                                    gump.X = x;
                                    gump.Y = y;

                                    if (!gump.IsDisposed)
                                    {
                                        if (UIManager.AnchorManager[gump] == null && ancoGroup.IsEmptyDirection(matrix_x, matrix_y))
                                        {
                                            gumps.Add(gump);
                                            UIManager.AnchorManager[gump] = ancoGroup;
                                            ancoGroup.AddControlToMatrix(matrix_x, matrix_y, gump);
                                        }
                                        else
                                        {
                                            gump.Dispose();
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex.ToString());
                            }
                        }
                    }
                }
            }

            return(gumps);
        }
コード例 #8
0
ファイル: PartyManager.cs プロジェクト: sadoseja/ClassicUO
        public void ParsePacket(Packet p)
        {
            byte code = p.ReadByte();

            bool add = false;

            switch (code)
            {
            case 1:
                add = true;
                goto case 2;

            case 2:
                byte count = p.ReadByte();

                if (count <= 1)
                {
                    Leader  = 0;
                    Inviter = 0;

                    for (int i = 0; i < PARTY_SIZE; i++)
                    {
                        if (Members[i] == null || Members[i].Serial == 0)
                        {
                            break;
                        }

                        HealthBarGump gump = Engine.UI.GetGump <HealthBarGump>(Members[i].Serial);


                        if (gump != null)
                        {
                            if (code == 2)
                            {
                                Members[i].Serial = 0;
                            }

                            gump.Update();
                        }
                    }

                    Clear();
                    Engine.UI.GetGump <PartyGumpAdvanced>()?.Update();

                    break;
                }

                Clear();

                if (!add)
                {
                    Engine.UI.GetGump <HealthBarGump>(p.ReadUInt())?.Update();
                }

                for (int i = 0; i < count; i++)
                {
                    Serial serial = p.ReadUInt();
                    Members[i] = new PartyMember(serial);

                    if (i == 0)
                    {
                        Leader = serial;
                    }

                    HealthBarGump gump = Engine.UI.GetGump <HealthBarGump>(serial);

                    if (gump != null)
                    {
                        GameActions.RequestMobileStatus(serial);
                        gump.Update();
                    }
                    else
                    {
                        if (serial == World.Player)
                        {
                        }
                    }
                }

                Engine.UI.GetGump <PartyGumpAdvanced>()?.Update();

                break;

            case 3:
            case 4:
                Serial ser  = p.ReadUInt();
                string name = p.ReadUnicode();

                for (int i = 0; i < PARTY_SIZE; i++)
                {
                    if (Members[i] != null && Members[i].Serial == ser)
                    {
                        Chat.HandleMessage(null, name, Members[i].Name, Engine.Profile.Current.PartyMessageHue, MessageType.Party, 3);

                        break;
                    }
                }

                break;

            case 7:
                Inviter = p.ReadUInt();

                if (Engine.Profile.Current.PartyInviteGump)
                {
                    Engine.UI.Add(new PartyInviteGump(Inviter));
                }
                break;
            }
        }