Make the getters of the 6 ToolFormBase props protected

and it only cost a callback and a `public new` hack
This commit is contained in:
YoshiRulz 2020-11-30 20:52:02 +10:00
parent 85faec638a
commit 1a020ba0f5
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 21 additions and 11 deletions

View File

@ -127,7 +127,7 @@ namespace BizHawk.Client.EmuHawk
Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top
}; };
var mdf = new MultiDiskFileSelector(this) var mdf = new MultiDiskFileSelector(this, () => MainForm.CurrentlyOpenRom)
{ {
Location = UIHelper.Scale(new Point(7, 12)), Location = UIHelper.Scale(new Point(7, 12)),
Width = groupBox.ClientSize.Width - UIHelper.ScaleX(13), Width = groupBox.ClientSize.Width - UIHelper.ScaleX(13),

View File

@ -9,6 +9,8 @@ namespace BizHawk.Client.EmuHawk
{ {
public partial class MultiDiskFileSelector : UserControl public partial class MultiDiskFileSelector : UserControl
{ {
private readonly Func<string> _getLoadedRomNameCallback;
private readonly ToolFormBase _parent; private readonly ToolFormBase _parent;
public string SystemString { get; set; } = ""; public string SystemString { get; set; } = "";
@ -26,8 +28,9 @@ namespace BizHawk.Client.EmuHawk
OnNameChanged(EventArgs.Empty); OnNameChanged(EventArgs.Empty);
} }
public MultiDiskFileSelector(ToolFormBase parent) public MultiDiskFileSelector(ToolFormBase parent, Func<string> getLoadedRomNameCallback)
{ {
_getLoadedRomNameCallback = getLoadedRomNameCallback;
_parent = parent; _parent = parent;
InitializeComponent(); InitializeComponent();
PathBox.TextChanged += HandleLabelTextChanged; PathBox.TextChanged += HandleLabelTextChanged;
@ -123,7 +126,7 @@ namespace BizHawk.Client.EmuHawk
private void UseCurrentRomButton_Click(object sender, EventArgs e) private void UseCurrentRomButton_Click(object sender, EventArgs e)
{ {
PathBox.Text = _parent.MainForm.CurrentlyOpenRom; PathBox.Text = _getLoadedRomNameCallback();
} }
private void DualGBFileSelector_Load(object sender, EventArgs e) private void DualGBFileSelector_Load(object sender, EventArgs e)
@ -133,9 +136,10 @@ namespace BizHawk.Client.EmuHawk
public void UpdateValues() public void UpdateValues()
{ {
var loadedRomName = _getLoadedRomNameCallback();
UseCurrentRomButton.Enabled = UseCurrentRomButton.Enabled =
!string.IsNullOrEmpty(_parent.MainForm.CurrentlyOpenRom) !string.IsNullOrEmpty(loadedRomName)
&& !_parent.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml && !loadedRomName.Contains(".xml"); // Can't already be an xml
} }
private void PathBox_TextChanged(object sender, EventArgs e) private void PathBox_TextChanged(object sender, EventArgs e)

View File

@ -17,6 +17,10 @@ namespace BizHawk.Client.EmuHawk
{ {
public override bool BlocksInputWhenFocused => IsInMenuLoop; public override bool BlocksInputWhenFocused => IsInMenuLoop;
public new IMainFormForTools MainForm => base.MainForm;
public new IMovieSession MovieSession => base.MovieSession;
// TODO: UI flow that conveniently allows to start from savestate // TODO: UI flow that conveniently allows to start from savestate
public ITasMovie CurrentTasMovie => MovieSession.Movie as ITasMovie; public ITasMovie CurrentTasMovie => MovieSession.Movie as ITasMovie;

View File

@ -10,15 +10,17 @@ namespace BizHawk.Client.EmuHawk
{ {
public class ToolFormBase : FormBase, IToolForm public class ToolFormBase : FormBase, IToolForm
{ {
public ToolManager Tools { get; set; } public ToolManager Tools { protected get; set; }
public DisplayManager DisplayManager { get; set; } public DisplayManager DisplayManager { protected get; set; }
public InputManager InputManager { get; set; } public InputManager InputManager { protected get; set; }
public IMainFormForTools MainForm { get; set; }
public IMovieSession MovieSession { get; set; } public IMainFormForTools MainForm { protected get; set; }
public IGameInfo Game { get; set; }
public IMovieSession MovieSession { protected get; set; }
public IGameInfo Game { protected get; set; }
public virtual bool AskSaveChanges() => true; public virtual bool AskSaveChanges() => true;