diff options
author | ame <[email protected]> | 2024-07-06 00:35:24 -0500 |
---|---|---|
committer | ame <[email protected]> | 2024-07-06 00:35:24 -0500 |
commit | cc3768e1509c22fa52ec7bf895390407a0ce0435 (patch) | |
tree | 70489029d0ae183aff3de32dbeb87118635a6a34 /src |
Diffstat (limited to 'src')
-rw-r--r-- | src/Blank.cs | 6 | ||||
-rw-r--r-- | src/PKBank.cs | 51 | ||||
-rw-r--r-- | src/PKMSlot.cs | 103 | ||||
-rw-r--r-- | src/PKSlot.cs | 90 | ||||
-rw-r--r-- | src/PKUISlot.cs | 44 | ||||
-rw-r--r-- | src/UI.cs | 124 |
6 files changed, 418 insertions, 0 deletions
diff --git a/src/Blank.cs b/src/Blank.cs new file mode 100644 index 0000000..1019089 --- /dev/null +++ b/src/Blank.cs @@ -0,0 +1,6 @@ +using Gtk; +class Blank : Box { + public Blank(int width, int height) : base(Orientation.Horizontal, 0) { + SetSizeRequest(width, height); + } +}
\ No newline at end of file diff --git a/src/PKBank.cs b/src/PKBank.cs new file mode 100644 index 0000000..4b31a58 --- /dev/null +++ b/src/PKBank.cs @@ -0,0 +1,51 @@ +using System; +using PKHeX.Core; + +public class PKBank : PKSlot { + public const int BOX_SIZE = 40; + public PKM?[] Box; + + public PKBank(){ + this.Box = new PKM?[BOX_SIZE]; + } + + override public void SetBox(PKM pk, int box_index, int index){ + if(index >= BOX_SIZE) throw new Exception("index larger than BOX_SIZE("+BOX_SIZE+")"); + + int target = box_index * BOX_SIZE + index; + + if(target >= this.Box.Length){ + int next_box = BOX_SIZE * (int)Math.Ceiling((double)target / BOX_SIZE); + if(next_box == target) next_box += BOX_SIZE; + Array.Resize<PKM?>(ref this.Box, next_box); + + } + + this.Box[target] = pk.Species == 0 ? null : pk; + } + + override public PKM GetBox(int box_index, int index){ + int target = box_index * BOX_SIZE + index; + + if(target >= this.Box.Length) return BlankPKM; + + return this.Box[target] ?? BlankPKM; + } + + public void _print(){ + for(int i = 0; i != this.Box.Length; i++){ + if(i%BOX_SIZE == 0){ + Console.WriteLine("\n---- box "+i/BOX_SIZE); + } + + Console.Write((this.Box[i] ?? BlankPKM).Species.ToString() + ":"); + Console.Write((Species)(this.Box[i] ?? BlankPKM).Species); + if((this.Box[i] ?? BlankPKM).IsShiny) Console.Write("*"); + Console.Write(" "); + + } + } + + public override void SetParty(PKM pkm, int index) => throw new NotImplementedException(); + public override PKM GetParty(int index) => throw new NotImplementedException(); +}
\ No newline at end of file diff --git a/src/PKMSlot.cs b/src/PKMSlot.cs new file mode 100644 index 0000000..243363e --- /dev/null +++ b/src/PKMSlot.cs @@ -0,0 +1,103 @@ +using Gtk; +using PKHeX.Core; +public class PKMSlot : Button { + public static int height = 56; + public static int width = 68; + public PKUISlot parent; + public PKM pk; + public Gdk.Pixbuf? pixbuf; + public bool source; + public int index; + public TargetEntry [] target_table = new TargetEntry [] { + new TargetEntry ("STRING", 0, 0 ), + new TargetEntry ("text/plain", 0, 0), + new TargetEntry ("application/x-rootwindow-drop", 0, 1) + }; + static public string Img(PKM pk){ + string awa = ((Species)pk.Species).ToString().ToLower(); + return "pokesprite/pokemon-gen8/regular/" + awa + ".png"; + } + public void DoDrag(){ + if(source){ + Gtk.Drag.SourceUnset(this); + Gtk.Drag.SourceSet(this, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask, target_table, Gdk.DragAction.Move); + Gtk.Drag.SourceSetIconPixbuf(this, pixbuf); + void beg(object o, DragBeginArgs args){ + // + //Console.WriteLine("get " + this.index); + } + void drag_data(object o, DragDataGetArgs args){ + //use for cross-proc + Console.WriteLine("get data " + this.index); + //https://www.rabbitmq.com/tutorials/tutorial-six-dotnet + //args.SelectionData.Set(args.SelectionData.Target, 8, System.Text.Encoding.UTF8.GetBytes()); + //args.Context.Data.Add("hi", "bye"); + //string[] aa = new string[1]; + //aa[0] = "hello"; + //args.SelectionData.SetUris(aa); + //TreePath a = new TreePath(); + //args.SelectionData.Set(new Gdk.Atom(5), 5, new byte[5]); + //args.SelectionData. + } + //this.DragDataGet -= drag_data; + //this.DragDataGet += drag_data; + this.DragBegin -= beg; + this.DragBegin += beg; + } + + Gtk.Drag.DestUnset(this); + Gtk.Drag.DestSet(this, DestDefaults.All, target_table, Gdk.DragAction.Move); + + void drop(object evm, DragDropArgs o){ + (Drag.GetSourceWidget(o.Context) as PKMSlot ?? throw new Exception("meow")).Swap(this); + //this.Swap(Drag.GetSourceWidget(o.Context) as PKMSlot); + //Console.WriteLine(o.Context.Data["hi"]); + //PKMSlot p = new PKMSlot(o.) + + } + void drop_data(object ev, DragDataReceivedArgs o){ + //Console.WriteLine(System.Text.Encoding.UTF8.GetString(o.SelectionData.Data)); + //Console.WriteLine(o.SelectionData.Uris[0]); + //Console.WriteLine(((Image)(ev as Button).Child).Pixbuf.ByteLength); + //im.Pixbuf = ((Image)(ev as Button).Child).Pixbuf;//new Gdk.Pixbuf("pokesprite/pokemon-gen8/shiny/" + ((Species)slot.save.PartyData[cop].Species).ToString().ToLower() + ".png"); + //((Image)(ev as Button).Child).Pixbuf = new Gdk.Pixbuf(shiny_file, 68, 56); + //(Drag.GetSourceWidget(o.Context) as Button).Child.Destroy(); + //(Drag.GetSourceWidget(o.Context) as Button).Child = new Blank(68, 56); + //(Drag.GetSourceWidget(o.Context) as Button).Child.Show(); + //((PKMSlot)ev).Swap(Drag.GetSourceWidget(o.Context) as PKMSlot); + //Drag.GetData((Widget)ev, o.Context, o.Context.ListTargets()[0], o.Time); + //((Image)(ev as Button ?? throw new Exception()).Child).Destroy(); + }; + //this.DragDataReceived -= drop_data; + //this.DragDataReceived += drop_data; + this.DragDrop -= drop; + this.DragDrop += drop; + + + } + + + + public PKMSlot(PKUISlot parent, PKM pk, int index) : base() { + SetSizeRequest(width, height); + this.WidthRequest = width; + this.HeightRequest = height; + this.parent = parent; + this.pk = pk; + this.index = index; + this.Update(pk); + } + + public void Update(PKM pk){ + this.pk = pk; + if(this.source = (pk.Species != 0)) this.Child = new Image(this.pixbuf = new Gdk.Pixbuf(Img(pk), width, height)); + else this.Child = new Blank(width, height); + DoDrag(); + } + + public void Swap(PKMSlot oper){ + this.parent.slot.Transfer(oper.parent.slot, this.index, this.parent.box_index, oper.index, oper.parent.box_index); + this.parent.Update(); + oper.parent.Update(); + } +}
\ No newline at end of file diff --git a/src/PKSlot.cs b/src/PKSlot.cs new file mode 100644 index 0000000..4a28662 --- /dev/null +++ b/src/PKSlot.cs @@ -0,0 +1,90 @@ +using System; +using System.IO; +using PKHeX.Core; +public class PKSlot { + + public SaveFile save; + + //pk5 is arbitrary + public PKM BlankPKM = new PK3(); + public PKSlot(){ + this.save = new FakeSaveFile(); + } + public PKSlot(String loc){ + this.save = (SaveFile)(FileUtil.GetSupportedFile(loc) ?? throw new Exception("Save file broken or not found")); + this.BlankPKM = this.save.BlankPKM; + } + + public PKSlot(SaveFile save){ + this.save = save; + this.BlankPKM = this.save.BlankPKM; + } + + virtual public void SetBox(PKM pkm, int box_index, int index) => + this.save.SetBoxSlotAtIndex(pkm, box_index, index); + virtual public PKM GetBox(int box_index, int index){ + return this.save.GetBoxSlotAtIndex(box_index, index); + } + + virtual public void SetParty(PKM pkm, int index){ + if(pkm.Species == 0) this.Remove(index, -1); + else this.save.SetPartySlotAtIndex(pkm, index); + this.FixShift(); + } + virtual public PKM GetParty(int index){ + if(index > this.save.PartyCount) return this.BlankPKM; + return this.save.GetPartySlotAtIndex(index); + } + + public PKM Get(int index, int box_index){ + return box_index < 0 ? this.GetParty(index) : this.GetBox(box_index, index); + } + public void Set(PKM s, int index, int box_index){ + if(box_index < 0) this.SetParty(s, index); + else this.SetBox(s, box_index, index); + } + + public void FixShift(){ + for(int i = 6; i != -1; i--){ + if(this.GetParty(i).Species == 0) this.Remove(i, -1); + } + } + + public void Save(string loc){ + File.WriteAllBytes(loc, this.save.Write()); + } + + public void Remove(int index, int box_index){ + if(box_index<0) this.save.DeletePartySlot(index); + else this.SetBox(BlankPKM, box_index, index); + } + + public void Transfer(PKSlot dest, int src_index, int src_box_index, int dest_index, int dest_box_index, bool remove = true){ + PKM pokemon1 = this.Get(src_index, src_box_index); + PKM pokemon2 = dest.Get(dest_index, dest_box_index); + + if(src_index > dest_index){ + dest.Set(pokemon1, dest_index, dest_box_index); + this.Set(pokemon2, src_index, src_box_index); + } else { + this.Set(pokemon2, src_index, src_box_index); + dest.Set(pokemon1, dest_index, dest_box_index); + } + + /*if(src_box_index<0) pokemon1 = this.GetParty(src_index); + else pokemon1 = this.GetBox(src_box_index, src_index); + + if(dest_box_index<0) dest.SetParty(pokemon, dest_index); + else dest.SetBox(pokemon, dest_box_index, dest_index);*/ + + //if(remove) this.Remove(src_index, src_box_index); + + } + + public string getImg(int index, int box_index){ + string awa = ((Species)this.Get(index, box_index).Species).ToString().ToLower(); + if(awa == "none") throw new Exception("blank slot"); + return "pokesprite/pokemon-gen8/regular/" + awa + ".png"; + } + +} diff --git a/src/PKUISlot.cs b/src/PKUISlot.cs new file mode 100644 index 0000000..85c80f6 --- /dev/null +++ b/src/PKUISlot.cs @@ -0,0 +1,44 @@ +using Gtk; +public class PKUISlot : Grid { + public bool party; + public PKSlot slot; + public int box_index; + public int box_count => box_index < 0 ? 6 : this.slot.save.BoxSlotCount; + + public PKUISlot(PKSlot slot, int box_index) : base() { + this.party = box_index < 0; + this.slot = slot; + this.box_index = box_index; + this.Update(); + + } + public PKUISlot(PKSlot slot) : this(slot, -1) {} + + public int RowLen(){ + if(this.party) return 6; + if(this.box_count % 6 == 0) return 6; + if(this.box_count % 5 == 0) return 5; + return 8; + } + public void Update(){ + for(;this.GetChildAt(0, 0) != null; this.RemoveRow(0)); + int row_brk = RowLen(); + + PKMSlot ?last = null; + for(int i, i2 = i = 0; i != this.box_count; i++, i2++){ + PKMSlot a = new PKMSlot(this, this.slot.Get(i, box_index), i); + a.Margin = 2; + a.MarginStart = a.MarginEnd = 1; + if(row_brk == i2) { + this.AttachNextTo(a, null, PositionType.Bottom, 80, 80); + i2 = 0; + } else this.AttachNextTo(a, last, PositionType.Right, 80, 80); + + last = a; + } + + this.ShowAll(); + //this.Update(null, null); + this.slot.Save("leafgreen.sav"); + } +}
\ No newline at end of file diff --git a/src/UI.cs b/src/UI.cs new file mode 100644 index 0000000..a88b914 --- /dev/null +++ b/src/UI.cs @@ -0,0 +1,124 @@ +using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.CompilerServices;
+using PKHeX.Core;
+using System.Reflection;
+using Gtk;
+
+public class Awa
+{
+
+ public static void Main(string[] args) {
+
+ Application.Init();
+
+ Window window = new Window("meow");
+ window.KeepAbove = true;
+
+
+ PKSlot slot = new PKSlot("leafgreen.sav3");
+ PKBank bank = new PKBank();
+ /*for(int i = 0; i != 6; i++){
+ //slot.getImg(i, -1);
+ //string file = "pokesprite/pokemon-gen8/regular/" + ((Species)slot.save.PartyData[i].Species).ToString().ToLower() + ".png";
+ //string shiny_file = "pokesprite/pokemon-gen8/shiny/" + ((Species)slot.save.PartyData[i].Species).ToString().ToLower() + ".png";
+ //PKSlot_slot meow;
+ //meow = new PKSlot_slot(slot, i, -1);
+ PKMSlot meow = new PKMSlot(new(), slot.Get(i, -1));
+ //meow.DragDataReceived
+
+ g.AttachNextTo(meow, null, PositionType.Right, 68, 56);
+ }*/
+ //DynamicGrid g = new DynamicGrid();
+ //slot.Transfer(bank, 1, -1, 1, 1);
+ //PKUISlot awa = new PKUISlot(slot);
+ //PKUISlot bawa = new PKUISlot(bank, 1);
+
+ //g.Add(awa);
+ //g.Add(bawa);
+ //g.Add(new PKMSlot(null, slot.GetParty(0), 5));
+ //g.Add(new PKMSlot(null, slot.GetParty(1), 5));
+ VBox vbox = new VBox(false, 1);
+ //grid.Add();
+ //g.Add(grid);
+ PKUISlot top = new PKUISlot(slot);
+ PKUISlot bottom = new PKUISlot(slot, 1);
+ top.MarginBottom = bottom.MarginTop = 4;
+
+ Separator seper = new Separator(Orientation.Horizontal);
+ seper.HeightRequest = 2;
+
+ vbox.PackStart(top, false, false, 0);
+ vbox.PackStart(seper, false, false, 0);
+ vbox.PackStart(bottom, false, false, 0);
+
+ window.Add(vbox);
+ //window.Add(g);
+
+ //.Update();
+
+ window.ShowAll();
+
+ Application.Run();
+ /*
+ PKSlot bank = new PKBank();
+
+ /*var a = FileUtil.GetSupportedFile("leafgreen.sav");
+ if(a is null) return;
+ SAV3 awa = (SAV3)(SaveFile)a;
+ System.Console.WriteLine(awa.PlayTimeString);*/
+
+ //PKSlot slot2 = new PKSlot("firered.sav");
+
+ //slot2.save.SetPartySlotAtIndex(slot.save.PartyData[0], 3, PKMImportSetting.UseDefault, PKMImportSetting.UseDefault);
+
+ /*foreach(PKM p in slot.save.PartyData){
+ //Console.WriteLine(ind);
+ slot.Transfer(slot2, ind, -1, ind, -1);
+
+ Console.WriteLine(slot.save.PartyData[ind].Species.ToString());
+ ind++;
+
+ }*/
+ /*
+ for(int i = 0; i != 6; i++){
+ PKM tmp = slot.save.GetPartySlotAtIndex(0);
+ tmp.SetIsShiny(true);
+ slot.save.SetPartySlotAtIndex(tmp, 0);
+ slot.Transfer(bank, 0, -1, i, 4);
+ }
+
+ ((PKBank)bank)._print();
+
+ for(int i = 0; i != 6; i++){
+ bank.Transfer(slot, i, 4, i, -1);
+ }
+
+ ((PKBank)bank)._print();
+
+ slot.Save("leafgreen.sav");
+ /*for(int i = 0; i!=6; i++){
+ slot.Transfer(slot, i, 2, i, -1);
+ }
+
+ foreach(PKM a in slot.save.BoxData){
+ if(a.Species!=0)Console.WriteLine(a.Species);
+ }*/
+
+ //slot2.Save("firered.sav");
+ //slot.Save("leafgreen.sav");
+ /*var table = new Table();
+ table.Title("Party");
+ table.AddColumn("pokemon");
+ table.HideHeaders();
+ foreach(PKM pokemon in awa.PartyData){
+ if(pokemon.Species == 0) continue;
+ table.AddRow(pokemon.Species.ToString());
+
+ }
+ table.AddEmptyRow();
+ AnsiConsole.Write(table);*/
+ }
+}
|