public static GetNumLowIndices ( int hIndex ) : int | ||
hIndex | int | |
Результат | int |
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(); } }
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); }