Skip to content

Commit

Permalink
Added playback controls; persist options
Browse files Browse the repository at this point in the history
  • Loading branch information
qkmaxware committed Jul 20, 2024
1 parent 12e6c55 commit 67c0cbf
Show file tree
Hide file tree
Showing 20 changed files with 1,176 additions and 165 deletions.
18 changes: 18 additions & 0 deletions Gameboy.Player.Godot/LcdColorTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,23 @@ public class LcdColorTheme {
Obj0Black = new Color("004A00"),
Obj1Black = new Color("000000"),
},
new LcdColorTheme {
Name = "Super Donkey Kong",
BgWhite = new Color("FFFF9C"),
Obj0White = new Color("FFC542"),
Obj1White = new Color("FFFFFF"),

BgLightGrey = new Color("94B5FF"),
Obj0LightGrey = new Color("FFD600"),
Obj1LightGrey = new Color("FF8484"),

BgDarkGrey = new Color("639473"),
Obj0DarkGrey = new Color("943A00"),
Obj1DarkGrey = new Color("943A3A"),

BgBlack = new Color("003A3A"),
Obj0Black = new Color("4A0000"),
Obj1Black = new Color("000000"),
},
};
}
4 changes: 4 additions & 0 deletions Gameboy.Player.Godot/Prefabs/GodotBoy/BorderContainer.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[gd_resource type="Theme" format=3 uid="uid://chyyqvccs2as3"]

[resource]
VBoxContainer/constants/separation = 4
60 changes: 29 additions & 31 deletions Gameboy.Player.Godot/Prefabs/GodotBoy/GodotBoy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,18 @@ public enum ControlState {
public bool IsPlaying => State == ControlState.Playing;

[Export] public Control CartControl;
[Export] public Control PlaybackControl;
[Export] public OptionButton SaveSlot;
[Export] public OnscreenControls[] OnscreenControls;

public Screen Screen {get; private set;}
public Gameboy Console {get; init;} = new Gameboy();

private LcdBitmap intro;
private LcdBitmap blank;

// Called when the node enters the scene tree for the first time.
public override void _Ready() {
if (OnscreenControls is null) {
OnscreenControls = new OnscreenControls[0];
}
var intro = new LcdBitmap(Gpu.LCD_WIDTH, Gpu.LCD_HEIGHT);
this.intro = intro;
intro.Fill(ColourPallet.BackgroundDark);

blank = new LcdBitmap(Gpu.LCD_WIDTH, Gpu.LCD_HEIGHT);
blank.Fill(ColourPallet.BackgroundDark);

var text = new LcdBitmap[]{ LcdBitmap.StampB, LcdBitmap.StampL, LcdBitmap.StampA, LcdBitmap.StampZ, LcdBitmap.StampO, LcdBitmap.StampR, LcdBitmap.StampB, LcdBitmap.StampO, LcdBitmap.StampY }.Select(stamp => stamp.Invert().Enlarge(4)).ToArray();
var width = text.Select(stamp => stamp.Width + 1).Sum();
var height = text.Select(stamp => stamp.Height).Max();

var startX = (intro.Width / 2) - (width / 2);
var startY = (intro.Height / 2) - (height / 2);
foreach (var stamp in text) {
intro.Stamp(startX, startY, stamp);
startX += stamp.Width + 1;
}

this.Screen = this.GetNode<Screen>("Screen Layouts");
const int DesktopLayout = 0;
Expand All @@ -59,15 +40,23 @@ string s when s.Contains("ios") => SkinnedLayout,
_ => DesktopLayout
}
};
this.Screen.Redraw(intro);
}

// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) {
if (State == ControlState.Stopped) {
CartControl.Visible = true;
} else {
CartControl.Visible = false;
if (CartControl is not null) {
if (State == ControlState.Stopped) {
CartControl.Visible = true;
} else {
CartControl.Visible = false;
}
}
if (PlaybackControl is not null) {
if (State == ControlState.Stopped) {
PlaybackControl.Visible = false;
} else {
PlaybackControl.Visible = true;
}
}

if (State == ControlState.Playing) {
Expand Down Expand Up @@ -155,9 +144,7 @@ public void Start() {
}
}

if (blank is not null) {
this.Screen.Redraw(blank);
}
this.Screen.Blank();
this.State = ControlState.Playing;
} else {
GD.PushError("No cartridge loaded");
Expand All @@ -178,6 +165,14 @@ public void Pause() {
}
}

public void TogglePause() {
if (State == ControlState.Playing) {
State = ControlState.Paused;
} else if (State == ControlState.Paused) {
State = ControlState.Playing;
}
}

public void Stop() {
if (this.Console is not null && this.Console.IsCartridgeLoaded()) {
this.State = ControlState.Stopped;
Expand All @@ -189,10 +184,13 @@ public void Stop() {
}
}
this.Console.Reset();
if (intro is not null) {
this.Screen.Redraw(intro);
}
this.Screen.ShowIntro();
}
}

public void Restart() {
Stop();
Play();
}

}
Loading

0 comments on commit 67c0cbf

Please sign in to comment.