Skip to content

Commit

Permalink
medallion + songs + gossip
Browse files Browse the repository at this point in the history
added compatibility for medallions & songs for both the broadcast view and load/save states. also fixed the gossip stone compatibility for broadcast that i didnt know that i broke at some point
  • Loading branch information
jxjacob committed May 21, 2023
1 parent 7dfda2b commit 30e9921
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 90 deletions.
2 changes: 1 addition & 1 deletion GSTHD/CollectedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CollectedItem(ObjectPointCollectedItem data, Settings settings, bool isBr
CollectedItems = System.Math.Min(System.Math.Max(CollectedItemMin, CollectedItemDefault), CollectedItemMax);
Step = data.Step == 0 ? 1 : data.Step;
CollectedItemSize = data.Size;
isBroadcastable = data.isBroadcastable;
isBroadcastable = data.isBroadcastable && !isBroadcast;

if (ImageNames.Length > 0)
{
Expand Down
51 changes: 51 additions & 0 deletions GSTHD/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,30 @@ public void SaveState()
}
}
}
foreach (Medallion x in this.Controls[0].Controls.OfType<Medallion>())
{
if (x.Name != "")
{
MedallionState state = x.GetState();
string conv = state.ToString();
if (conv != "0,0")
{
thejson.Add(x.Name, conv);
}
}
}
foreach (Song x in this.Controls[0].Controls.OfType<Song>())
{
if (x.Name != "")
{
SongState state = x.GetWholeState();
string conv = state.ToString();
if (conv != "0,False,,0")
{
thejson.Add(x.Name, conv);
}
}
}
foreach (PanelWothBarren x in this.Controls[0].Controls.OfType<PanelWothBarren>())
{
if (x.Name != "")
Expand Down Expand Up @@ -282,6 +306,33 @@ public void LoadState()
};
((GossipStone)found).SetState(newstate);
}
else if (found is Medallion)
{
string conv = (string)x.Value;
string[] words = conv.Split(',');
MedallionState newstate = new MedallionState()
{
DungeonIndex = int.Parse(words[0]),
ImageIndex = int.Parse(words[1]),
};
((Medallion)found).SetState(newstate);
}
else if (found is Song)
{
string conv = (string)x.Value;
string[] words = conv.Split(',');
SongState newstate = new SongState()
{
ImageIndex = int.Parse(words[0]),
MarkerState = new SongMarkerState()
{
HoldsImage = Boolean.Parse(words[1]),
HeldImageName = words[2],
ImageIndex = int.Parse(words[3]),
},
};
((Song)found).SetWholeState(newstate);
}
else if (found is PanelWothBarren)
{
if (((PanelWothBarren)found).isWotH){
Expand Down
44 changes: 20 additions & 24 deletions GSTHD/GossipStone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class GossipStone : PictureBox, ProgressibleElement<GossipStoneState>, Dr

Size GossipStoneSize;

public GossipStone(ObjectPoint data, Settings settings)
: this(settings, data.Name, data.X, data.Y, data.ImageCollection, data.Size, data.isScrollable, data.SizeMode, data.isBroadcastable) { }
public GossipStone(ObjectPoint data, Settings settings, bool isOnBroadcast = false)
: this(settings, data.Name, data.X, data.Y, data.ImageCollection, data.Size, data.isScrollable, data.SizeMode, data.isBroadcastable, isOnBroadcast) { }

public GossipStone(Settings settings, string name, int x, int y, string[] imageCollection, Size imageSize, bool isScrollable, PictureBoxSizeMode SizeMode, bool isBroadcastable)
public GossipStone(Settings settings, string name, int x, int y, string[] imageCollection, Size imageSize, bool isScrollable, PictureBoxSizeMode SizeMode, bool isBroadcastable, bool isOnBroadcast = false)
{
Settings = settings;

Expand Down Expand Up @@ -65,16 +65,19 @@ public GossipStone(Settings settings, string name, int x, int y, string[] imageC
this.isBroadcastable = isBroadcastable;


if (!isOnBroadcast)
{
this.MouseUp += DragBehaviour.Mouse_ClickUp;
this.MouseDown += ProgressBehaviour.Mouse_ClickDown;
this.MouseDown += DragBehaviour.Mouse_ClickDown;
this.MouseMove += Mouse_Move;
this.DragEnter += Mouse_DragEnter;
this.DragDrop += Mouse_DragDrop;
this.MouseWheel += Mouse_Wheel;
this.MouseEnter += Panel_MouseEnter;
this.MouseLeave += Panel_MouseLeave;
}

this.MouseUp += DragBehaviour.Mouse_ClickUp;
this.MouseDown += ProgressBehaviour.Mouse_ClickDown;
this.MouseDown += DragBehaviour.Mouse_ClickDown;
this.MouseMove += Mouse_Move;
this.DragEnter += Mouse_DragEnter;
this.DragDrop += Mouse_DragDrop;
this.MouseWheel += Mouse_Wheel;
this.MouseEnter += Panel_MouseEnter;
this.MouseLeave += Panel_MouseLeave;
}

// both of these functions are for when the stone is in a WOTH panel, so that it can be scrolled without the whole WOTH panle scrolling as well
Expand All @@ -98,10 +101,6 @@ private void Mouse_Wheel(object sender, MouseEventArgs e)
if (ImageIndex < 0) ImageIndex = 0;
else if (ImageIndex >= ImageNames.Length) ImageIndex = ImageNames.Length - 1;
UpdateImage();
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((GossipStone)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).Mouse_Wheel(sender, e);
};
}
}

Expand Down Expand Up @@ -150,6 +149,7 @@ private void UpdateImage()
Image = Image.FromFile(@"Resources/" + ImageNames[ImageIndex]);
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((GossipStone)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).HoldsImage = false;
((GossipStone)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).ImageIndex = ImageIndex;
((GossipStone)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).UpdateImage();
}
Expand Down Expand Up @@ -189,26 +189,22 @@ public void IncrementState()
RemoveImage = true;
if (ImageIndex < ImageNames.Length - 1) ImageIndex += 1;
UpdateImage();
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((GossipStone)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).IncrementState();
};
}

public void DecrementState()
{
RemoveImage = true;
if (ImageIndex > 0) ImageIndex -= 1;
UpdateImage();
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((GossipStone)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).DecrementState();
};
}

public void ResetState()
{
RemoveImage = true;
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((GossipStone)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).RemoveImage = true;
}
ImageIndex = 0;
UpdateImage();
}
Expand Down
2 changes: 1 addition & 1 deletion GSTHD/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Item(ObjectPoint data, Settings settings, bool isBroadcast = false)

Name = data.Name;
BackColor = data.BackColor;
this.isBroadcastable = data.isBroadcastable;
this.isBroadcastable = data.isBroadcastable && !isBroadcast;

this.isDraggable = data.isDraggable;

Expand Down
10 changes: 6 additions & 4 deletions GSTHD/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ public void LoadBroadcastLayout(Panel panelLayout, Settings settings, SortedSet<
{
if (song.Visible)
{
var s = new Song(song, settings);
var s = new Song(song, settings, true);
panelLayout.Controls.Add(s);
ListUpdatables.Add(s);
}
Expand Down Expand Up @@ -865,7 +865,7 @@ public void LoadBroadcastLayout(Panel panelLayout, Settings settings, SortedSet<
{
if (medallion.Visible)
{
var element = new Medallion(medallion, settings);
var element = new Medallion(medallion, settings, true);
panelLayout.Controls.Add(element);
panelLayout.Controls.Add(element.SelectedDungeon);
ListUpdatables.Add(element);
Expand All @@ -889,7 +889,7 @@ public void LoadBroadcastLayout(Panel panelLayout, Settings settings, SortedSet<
foreach (var item in ListGossipStones)
{
if (item.Visible)
panelLayout.Controls.Add(new GossipStone(item, settings));
panelLayout.Controls.Add(new GossipStone(item, settings, true));
}
}

Expand All @@ -915,7 +915,7 @@ public void LoadBroadcastLayout(Panel panelLayout, Settings settings, SortedSet<
Visible = item.Visible,
SizeMode= item.SizeMode
};
panelLayout.Controls.Add(new GossipStone(gs, settings));
panelLayout.Controls.Add(new GossipStone(gs, settings, true));
}
}
}
Expand Down Expand Up @@ -1051,6 +1051,7 @@ public class ObjectPointSong
public string[] TinyImageCollection { get; set; }
public string ActiveSongImage { get; set; }
public string ActiveTinySongImage { get; set; }
public bool isBroadcastable { get; set; } = false;
}

public class MedallionLabel
Expand All @@ -1072,6 +1073,7 @@ public class ObjectPointMedallion
public bool Visible { get; set; }
public string[] ImageCollection { get; set; }
public MedallionLabel Label { get; set; }
public bool isBroadcastable { get; set; } = false;
}

public class ObjectPointGrid
Expand Down
91 changes: 71 additions & 20 deletions GSTHD/Medallion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@

namespace GSTHD
{
public class Medallion : PictureBox, UpdatableFromSettings, ProgressibleElement<int>, DraggableAutocheckElement<int>
public struct MedallionState
{
public int DungeonIndex;
public int ImageIndex;

public override string ToString() => $"{DungeonIndex},{ImageIndex}";
}

public class Medallion : PictureBox, UpdatableFromSettings, ProgressibleElement<MedallionState>, DraggableElement<MedallionState>
{
private readonly Settings Settings;
private readonly ProgressibleElementBehaviour<int> ProgressBehaviour;
private readonly DraggableAutocheckElementBehaviour<int> DragBehaviour;
private readonly ProgressibleElementBehaviour<MedallionState> ProgressBehaviour;
private readonly DraggableElementBehaviour<MedallionState> DragBehaviour;

private string[] ImageNames;
private string[] DungeonNames;
Expand All @@ -21,7 +29,9 @@ public class Medallion : PictureBox, UpdatableFromSettings, ProgressibleElement<

public Label SelectedDungeon;

public Medallion(ObjectPointMedallion data, Settings settings)
private bool isBroadcastable;

public Medallion(ObjectPointMedallion data, Settings settings, bool isBroadcast = false)
{
Settings = settings;

Expand Down Expand Up @@ -52,6 +62,7 @@ public Medallion(ObjectPointMedallion data, Settings settings)
DefaultDungeonIndex = data.Label.DefaultValue.Value;
DungeonIndex = DefaultDungeonIndex;
Wraparound = data.Label.Wraparound.Value;
isBroadcastable = data.isBroadcastable && !isBroadcast;

Name = data.Name;
BackColor = Color.Transparent;
Expand All @@ -63,16 +74,20 @@ public Medallion(ObjectPointMedallion data, Settings settings)
Size = data.Size;
}

ProgressBehaviour = new ProgressibleElementBehaviour<int>(this, Settings);
DragBehaviour = new DraggableAutocheckElementBehaviour<int>(this, Settings);
ProgressBehaviour = new ProgressibleElementBehaviour<MedallionState>(this, Settings);
DragBehaviour = new DraggableElementBehaviour<MedallionState>(this, Settings);

Location = new Point(data.X, data.Y);
TabStop = false;
AllowDrop = false;
MouseUp += DragBehaviour.Mouse_ClickUp;
MouseDown += ProgressBehaviour.Mouse_ClickDown;
MouseDown += DragBehaviour.Mouse_ClickDown;
MouseMove += DragBehaviour.Mouse_Move_WithAutocheck;
if (!isBroadcast)
{
MouseUp += DragBehaviour.Mouse_ClickUp;
MouseDown += ProgressBehaviour.Mouse_ClickDown;
MouseDown += DragBehaviour.Mouse_ClickDown;
MouseMove += DragBehaviour.Mouse_Move;
}


SelectedDungeon = new Label
{
Expand All @@ -85,12 +100,16 @@ public Medallion(ObjectPointMedallion data, Settings settings)

SelectedDungeon.Location = new Point(Location.X + Size.Width / 2, (int)(Location.Y + Size.Height * 0.75));

SelectedDungeon.MouseUp += DragBehaviour.Mouse_ClickUp;
SelectedDungeon.MouseDown += ProgressBehaviour.Mouse_ClickDown;
SelectedDungeon.MouseDown += DragBehaviour.Mouse_ClickDown;
SelectedDungeon.MouseMove += DragBehaviour.Mouse_Move_WithAutocheck;
if (!isBroadcast)
{
SelectedDungeon.MouseUp += DragBehaviour.Mouse_ClickUp;
SelectedDungeon.MouseDown += ProgressBehaviour.Mouse_ClickDown;
SelectedDungeon.MouseDown += DragBehaviour.Mouse_ClickDown;
SelectedDungeon.MouseMove += DragBehaviour.Mouse_Move;

UpdateFromSettings();
UpdateFromSettings();
}

}

public void UpdateFromSettings()
Expand Down Expand Up @@ -127,6 +146,11 @@ private void Mouse_Wheel(object sender, MouseEventArgs e)
else if (DungeonIndex >= DungeonNames.Length) DungeonIndex = DungeonNames.Length - 1;
SelectedDungeon.Text = DungeonNames[DungeonIndex];
SetSelectedDungeonLocation();
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).SelectedDungeon.Text = DungeonNames[DungeonIndex];
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).SetSelectedDungeonLocation();
}
}
}

Expand All @@ -139,23 +163,45 @@ private void Mouse_Wheel_WithWraparound(object sender, MouseEventArgs e)
DungeonIndex = Math.EMod(newIndex, DungeonNames.Length);
SelectedDungeon.Text = DungeonNames[DungeonIndex];
SetSelectedDungeonLocation();
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).SelectedDungeon.Text = DungeonNames[DungeonIndex];
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).SetSelectedDungeonLocation();
}
}
}

private void UpdateImage()
{
Image = Image.FromFile(@"Resources/" + ImageNames[ImageIndex]);
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).ImageIndex = ImageIndex;
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).UpdateImage();
}
}

public int GetState()
public MedallionState GetState()
{
return ImageIndex;
return new MedallionState()
{
DungeonIndex = DungeonIndex,
ImageIndex = ImageIndex,
};
}

public void SetState(int state)
public void SetState(MedallionState state)
{
ImageIndex = state;
ImageIndex = state.ImageIndex;
UpdateImage();
DungeonIndex = state.DungeonIndex;
SelectedDungeon.Text = DungeonNames[DungeonIndex];
SetSelectedDungeonLocation();
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).SelectedDungeon.Text = DungeonNames[DungeonIndex];
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).SetSelectedDungeonLocation();
}
}

public void IncrementState()
Expand All @@ -175,11 +221,16 @@ public void ResetState()
DungeonIndex = DefaultDungeonIndex;
SelectedDungeon.Text = DungeonNames[DungeonIndex];
SetSelectedDungeonLocation();
if (isBroadcastable && Application.OpenForms["GSTHD_DK64 Broadcast View"] != null)
{
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).SelectedDungeon.Text = DungeonNames[DungeonIndex];
((Medallion)Application.OpenForms["GSTHD_DK64 Broadcast View"].Controls.Find(this.Name, true)[0]).SetSelectedDungeonLocation();
}
}

public void StartDragDrop()
{
var dropContent = new DragDropContent(DragBehaviour.AutocheckDragDrop, ImageNames[1]);
var dropContent = new DragDropContent(false, ImageNames[1]);
DoDragDrop(dropContent, DragDropEffects.Copy);
}

Expand Down
Loading

0 comments on commit 30e9921

Please sign in to comment.