コード例 #1
0
        public void SetTreasure(int index)
        {
            int hIndex = index >> 8;
            int lIndex = index & 0xff;

            int hMax = Treasure.GetNumHighIndices();

            if (hIndex >= hMax)
            {
                hIndex = hMax - 1;
            }

            int lMax = Treasure.GetNumLowIndices(hIndex);

            if (lIndex >= lMax)
            {
                lIndex = lMax - 1;
            }

            highIndexButton.Adjustment.Upper = hMax - 1;
            lowIndexButton.Adjustment.Upper  = lMax - 1;
            highIndexButton.Value            = hIndex;
            lowIndexButton.Value             = lIndex;

            index = hIndex << 8 | lIndex;

            vrContainer.Remove(vrEditor);

            Data           data = Treasure.GetTreasureDataBase(index);
            ValueReference v1   = new ValueReference("Spawn Mode", 0, 4, 6, DataValueType.ByteBits);

            v1.SetData(data);
            ValueReference v5 = new ValueReference("Grab Mode", 0, 0, 2, DataValueType.ByteBits);

            v5.SetData(data);
            ValueReference v6 = new ValueReference("Unknown", 0, 3, 3, DataValueType.ByteBit);

            v6.SetData(data);

            data = data.NextData;
            ValueReference v2 = new ValueReference("Parameter", 0, DataValueType.Byte);

            v2.SetData(data);
            data = data.NextData;
            ValueReference v3 = new ValueReference("Text ID", 0, DataValueType.Byte);

            v3.SetData(data);
            data = data.NextData;
            ValueReference v4 = new ValueReference("Gfx", 0, DataValueType.Byte);

            v4.SetData(data);
            data = data.NextData;

            // Byte 1 is sometimes set to 0x80 for unused treasures?
            v1.SetValue(v1.GetIntValue() & 0x7f);

            ValueReferenceGroup vrGroup = new ValueReferenceGroup(new ValueReference[] { v1, v5, v6, v2, v3, v4 });

            var vr = new ValueReferenceEditor(
                Project,
                vrGroup,
                "Data");

            vr.SetMaxBound(0, 0x7f); // Max bound for Spawn Mode

            vr.AddDataModifiedHandler(() => {
                if (TreasureChangedEvent != null)
                {
                    TreasureChangedEvent();
                }
            });

            vrEditor = vr;
            vrContainer.Add(vrEditor);

            if (TreasureChangedEvent != null)
            {
                TreasureChangedEvent();
            }
        }
コード例 #2
0
        public override void Clicked()
        {
            Treasure.Project = Project;
            Chest.Project    = Project;

            Gtk.Window win = new Window(WindowType.Toplevel);
            Alignment  warningsContainer = new Alignment(0.1f, 0.1f, 0f, 0f);

            VBox vbox = new VBox();

            var chestGui = new ChestEditorGui(manager);

            chestGui.SetRoom(manager.GetActiveRoom().Index);
            chestGui.Destroyed += (sender2, e2) => win.Destroy();

            Frame chestFrame = new Frame();

            chestFrame.Label = "Chest Data";
            chestFrame.Add(chestGui);

            var   treasureGui   = new TreasureEditorGui(manager);
            Frame treasureFrame = new Frame();

            treasureFrame.Label = "Treasure Data";
            treasureFrame.Add(treasureGui);

            System.Action UpdateWarnings = () => {
                VBox warningBox = new VBox();
                warningBox.Spacing = 4;

                System.Action <string> AddWarning = (s) => {
                    Image img = new Image(Stock.DialogWarning, IconSize.Button);
                    HBox  hb  = new HBox();
                    hb.Spacing = 10;
                    hb.Add(img);
                    Gtk.Label l = new Gtk.Label(s);
                    l.LineWrap = true;
                    hb.Add(l);
                    Alignment a = new  Alignment(0, 0, 0, 0);
                    a.Add(hb);
                    warningBox.Add(a);
                };

                foreach (var c in warningsContainer.Children)
                {
                    warningsContainer.Remove(c);
                }

                int index = chestGui.GetTreasureIndex();
                if (index < 0)
                {
                    return;
                }

                if (!Treasure.IndexExists(index))
                {
                    AddWarning("Treasure " + Wla.ToWord(index) + " does not exist.");
                }
                else
                {
                    if (index != treasureGui.Index)
                    {
                        AddWarning("Your treasure index is different\nfrom the chest you're editing.");
                    }

                    int spawnMode = (Treasure.GetTreasureByte(index, 0) >> 4) & 7;

                    if (spawnMode != 3)
                    {
                        AddWarning("Treasure " + Wla.ToWord(index) + " doesn't have spawn\nmode $3 (needed for chests).");
                    }

                    int  yx = Chest.GetChestByte(chestGui.RoomIndex, 0);
                    int  x  = yx & 0xf;
                    int  y  = yx >> 4;
                    Room r  = Project.GetIndexedDataType <Room>(chestGui.RoomIndex);
                    if (x >= r.Width || y >= r.Height || r.GetTile(x, y) != 0xf1)
                    {
                        AddWarning("There is no chest at coordinates (" + x + "," + y + ").");
                    }
                }

                warningsContainer.Add(warningBox);

                win.ShowAll();
            };

            chestGui.SetTreasureEditor(treasureGui);
            chestGui.ChestChangedEvent += () => {
                UpdateWarnings();
            };
            treasureGui.TreasureChangedEvent += () => {
                UpdateWarnings();
            };

            HBox hbox = new Gtk.HBox();

            hbox.Spacing = 6;
            hbox.Add(chestFrame);
            hbox.Add(treasureFrame);

            Button okButton = new Gtk.Button();

            okButton.UseStock = true;
            okButton.Label    = "gtk-ok";
            okButton.Clicked += (a, b) => {
                win.Destroy();
            };

            Alignment buttonAlign = new Alignment(0.5f, 0.5f, 0f, 0f);

            buttonAlign.Add(okButton);

            vbox.Add(hbox);
            vbox.Add(warningsContainer);
            vbox.Add(buttonAlign);

            win.Add(vbox);

            UpdateWarnings();
            win.ShowAll();
        }
コード例 #3
0
        public TreasureEditorGui(PluginManager manager)
            : base(0.5f, 0.0f, 0.0f, 0.0f)
        {
            this.manager = manager;

            highIndexButton               = new SpinButtonHexadecimal(0, 0xff);
            highIndexButton.Digits        = 2;
            highIndexButton.ValueChanged += (a, b) => {
                SetTreasure(Index);
            };

            Button hAddButton = new Gtk.Button();

            hAddButton.Clicked += (a, b) => {
                Treasure.AddHighIndex();
                SetTreasure(0xffff);
            };
            hAddButton.UseStock     = true;
            hAddButton.UseUnderline = true;
            hAddButton.Image        = new Gtk.Image(Gtk.Stock.Add, Gtk.IconSize.Button);

            Button hRemoveButton = new Gtk.Button();

            hRemoveButton.Clicked += (a, b) => {
                Gtk.MessageDialog d = new MessageDialog(null,
                                                        DialogFlags.DestroyWithParent,
                                                        MessageType.Warning,
                                                        ButtonsType.YesNo,
                                                        "This will shift the indices for all treasures starting from " +
                                                        Wla.ToByte((byte)(Index >> 8)) + "! All treasures after this WILL BREAK! " +
                                                        "Are you sure you want to continue?"
                                                        );
                var r = (ResponseType)d.Run();
                d.Destroy();
                if (r != Gtk.ResponseType.Yes)
                {
                    return;
                }
                Treasure.RemoveHighIndex(Index >> 8);
                SetTreasure(Index);
            };
            hRemoveButton.UseStock     = true;
            hRemoveButton.UseUnderline = true;
            hRemoveButton.Image        = new Gtk.Image(Gtk.Stock.Remove, Gtk.IconSize.Button);

            lowIndexButton               = new SpinButtonHexadecimal(0, 0xff);
            lowIndexButton.Digits        = 2;
            lowIndexButton.ValueChanged += (a, b) => {
                SetTreasure(Index);
            };

            Button addButton = new Gtk.Button();

            addButton.Clicked += (a, b) => {
                Treasure.AddSubIndex(Index >> 8);
                SetTreasure((Index & 0xff00) + 0xff);
            };
            addButton.UseStock     = true;
            addButton.UseUnderline = true;
            addButton.Image        = new Gtk.Image(Gtk.Stock.Add, Gtk.IconSize.Button);

            Button removeButton = new Gtk.Button();

            removeButton.Clicked += (a, b) => {
                if ((Index & 0xff) < Treasure.GetNumLowIndices(Index >> 8) - 1)
                {
                    Gtk.MessageDialog d = new MessageDialog(null,
                                                            DialogFlags.DestroyWithParent,
                                                            MessageType.Warning,
                                                            ButtonsType.YesNo,
                                                            "This will shift all sub-indices for treasure " +
                                                            Wla.ToByte((byte)(Index >> 8)) + " starting from sub-index " +
                                                            Wla.ToByte((byte)(Index & 0xff)) + "! Are you sure you want to continue?"
                                                            );
                    var r = (ResponseType)d.Run();
                    d.Destroy();
                    if (r != Gtk.ResponseType.Yes)
                    {
                        return;
                    }
                }
                Treasure.RemoveSubIndex(Index);
                SetTreasure((Index & 0xff00) + 0xff);
            };
            removeButton.UseStock     = true;
            removeButton.UseUnderline = true;
            removeButton.Image        = new Gtk.Image(Gtk.Stock.Remove, Gtk.IconSize.Button);

            var table = new Table(3, 2, false);

            uint y = 0;

            table.Attach(new Gtk.Label("ID1"), 0, 1, y, y + 1);
            table.Attach(highIndexButton, 1, 2, y, y + 1);
            // Disable high add and remove buttons for now, they're not useful
            // yet
//             table.Attach(hAddButton,2,3,y,y+1);
//             table.Attach(hRemoveButton,3,4,y,y+1);
            y++;
            table.Attach(new Gtk.Label("ID2"), 0, 1, y, y + 1);
            table.Attach(lowIndexButton, 1, 2, y, y + 1);
            table.Attach(addButton, 2, 3, y, y + 1);
            table.Attach(removeButton, 3, 4, y, y + 1);

            vrContainer = new Alignment(1.0f, 1.0f, 1.0f, 1.0f);

            VBox vbox = new VBox();

            vbox.Add(table);
            vbox.Add(vrContainer);

            Add(vbox);

            SetTreasure(0);
        }