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(); }
public void SetTreasureEditor(TreasureEditorGui gui) { friend = gui; SyncTreasureEditor(); }
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(); }