cleanup OSDManager

This commit is contained in:
adelikat 2019-11-26 19:36:04 -06:00
parent 1b8b4b4926
commit f926142921
8 changed files with 72 additions and 97 deletions

View File

@ -158,7 +158,7 @@ namespace BizHawk.Client.EmuHawk
public void ClearText() public void ClearText()
{ {
GlobalWin.OSD.ClearGUIText(); GlobalWin.OSD.ClearGuiText();
} }
public void SetDefaultForegroundColor(Color color) public void SetDefaultForegroundColor(Color color)
@ -650,7 +650,7 @@ namespace BizHawk.Client.EmuHawk
y -= Emulator.CoreComm.ScreenLogicalOffsetY; y -= Emulator.CoreComm.ScreenLogicalOffsetY;
} }
GlobalWin.OSD.AddGUIText(message, x, y, Color.Black, forecolor ?? Color.White, a); GlobalWin.OSD.AddGuiText(message, x, y, Color.Black, forecolor ?? Color.White, a);
} }
} }
} }

View File

@ -8,7 +8,6 @@ using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Client.Common.InputAdapterExtensions; using BizHawk.Client.Common.InputAdapterExtensions;
using BizHawk.Bizware.BizwareGL;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -43,25 +42,16 @@ namespace BizHawk.Client.EmuHawk
public class OSDManager public class OSDManager
{ {
public string FPS { get; set; } public string Fps { get; set; }
public IBlitterFont MessageFont; public IBlitterFont MessageFont;
public void Dispose()
{
}
public void Begin(IBlitter blitter) public void Begin(IBlitter blitter)
{ {
MessageFont = blitter.GetFontType(nameof(MessageFont)); MessageFont = blitter.GetFontType(nameof(MessageFont));
} }
public Color FixedMessagesColor { get { return Color.FromArgb(Global.Config.MessagesColor); } } public Color FixedMessagesColor => Color.FromArgb(Global.Config.MessagesColor);
public Color FixedAlertMessageColor { get { return Color.FromArgb(Global.Config.AlertMessageColor); } } public Color FixedAlertMessageColor => Color.FromArgb(Global.Config.AlertMessageColor);
public OSDManager()
{
}
private float GetX(IBlitter g, int x, int anchor, string message) private float GetX(IBlitter g, int x, int anchor, string message)
{ {
@ -127,17 +117,17 @@ namespace BizHawk.Client.EmuHawk
return Global.Emulator.Frame.ToString(); return Global.Emulator.Frame.ToString();
} }
private List<UIMessage> messages = new List<UIMessage>(5); private readonly List<UIMessage> _messages = new List<UIMessage>(5);
private List<UIDisplay> GUITextList = new List<UIDisplay>(); private readonly List<UIDisplay> _guiTextList = new List<UIDisplay>();
public void AddMessage(string message) public void AddMessage(string message)
{ {
messages.Add(new UIMessage { Message = message, ExpireAt = DateTime.Now + TimeSpan.FromSeconds(2) }); _messages.Add(new UIMessage { Message = message, ExpireAt = DateTime.Now + TimeSpan.FromSeconds(2) });
} }
public void AddGUIText(string message, int x, int y, Color backGround, Color foreColor, int anchor) public void AddGuiText(string message, int x, int y, Color backGround, Color foreColor, int anchor)
{ {
GUITextList.Add(new UIDisplay _guiTextList.Add(new UIDisplay
{ {
Message = message, Message = message,
X = x, X = x,
@ -148,9 +138,9 @@ namespace BizHawk.Client.EmuHawk
}); });
} }
public void ClearGUIText() public void ClearGuiText()
{ {
GUITextList.Clear(); _guiTextList.Clear();
} }
public void DrawMessages(IBlitter g) public void DrawMessages(IBlitter g)
@ -160,58 +150,55 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
messages.RemoveAll(m => DateTime.Now > m.ExpireAt); _messages.RemoveAll(m => DateTime.Now > m.ExpireAt);
int line = 1; int line = 1;
if (Global.Config.StackOSDMessages) if (Global.Config.StackOSDMessages)
{ {
for (int i = messages.Count - 1; i >= 0; i--, line++) for (int i = _messages.Count - 1; i >= 0; i--, line++)
{ {
float x = GetX(g, Global.Config.DispMessagex, Global.Config.DispMessageanchor, messages[i].Message); float x = GetX(g, Global.Config.DispMessagex, Global.Config.DispMessageanchor, _messages[i].Message);
float y = GetY(g, Global.Config.DispMessagey, Global.Config.DispMessageanchor, messages[i].Message); float y = GetY(g, Global.Config.DispMessagey, Global.Config.DispMessageanchor, _messages[i].Message);
if (Global.Config.DispMessageanchor < 2) if (Global.Config.DispMessageanchor < 2)
{ {
y += ((line - 1) * 18); y += (line - 1) * 18;
} }
else else
{ {
y -= ((line - 1) * 18); y -= (line - 1) * 18;
} }
//g.DrawString(messages[i].Message, MessageFont, Color.Black, x + 2, y + 2); g.DrawString(_messages[i].Message, MessageFont, FixedMessagesColor, x, y);
g.DrawString(messages[i].Message, MessageFont, FixedMessagesColor, x, y);
} }
} }
else else
{ {
if (messages.Any()) if (_messages.Any())
{ {
int i = messages.Count - 1; int i = _messages.Count - 1;
float x = GetX(g, Global.Config.DispMessagex, Global.Config.DispMessageanchor, messages[i].Message); float x = GetX(g, Global.Config.DispMessagex, Global.Config.DispMessageanchor, _messages[i].Message);
float y = GetY(g, Global.Config.DispMessagey, Global.Config.DispMessageanchor, messages[i].Message); float y = GetY(g, Global.Config.DispMessagey, Global.Config.DispMessageanchor, _messages[i].Message);
if (Global.Config.DispMessageanchor < 2) if (Global.Config.DispMessageanchor < 2)
{ {
y += ((line - 1) * 18); y += (line - 1) * 18;
} }
else else
{ {
y -= ((line - 1) * 18); y -= (line - 1) * 18;
} }
//g.DrawString(messages[i].Message, MessageFont, Color.Black, x + 2, y + 2); g.DrawString(_messages[i].Message, MessageFont, FixedMessagesColor, x, y);
g.DrawString(messages[i].Message, MessageFont, FixedMessagesColor, x, y);
} }
} }
foreach (var text in GUITextList) foreach (var text in _guiTextList)
{ {
try try
{ {
float posx = GetX(g, text.X, text.Anchor, text.Message); float posX = GetX(g, text.X, text.Anchor, text.Message);
float posy = GetY(g, text.Y, text.Anchor, text.Message); float posY = GetY(g, text.Y, text.Anchor, text.Message);
//g.DrawString(text.Message, MessageFont, text.BackGround, posx + 2, posy + 2); g.DrawString(text.Message, MessageFont, text.ForeColor, posX, posY);
g.DrawString(text.Message, MessageFont, text.ForeColor, posx, posy);
} }
catch (Exception) catch (Exception)
{ {
@ -266,17 +253,6 @@ namespace BizHawk.Client.EmuHawk
return lg.GenerateInputDisplay(); return lg.GenerateInputDisplay();
} }
public string InputStrSticky()
{
var stickyOr = new StickyOrAdapter
{
Source = Global.StickyXORAdapter,
SourceStickyOr = Global.AutofireStickyXORAdapter
};
return MakeStringFor(stickyOr);
}
private string MakeStringFor(IController controller) private string MakeStringFor(IController controller)
{ {
var lg = Global.MovieSession.LogGeneratorInstance(); var lg = Global.MovieSession.LogGeneratorInstance();
@ -302,17 +278,13 @@ namespace BizHawk.Client.EmuHawk
public string MakeRerecordCount() public string MakeRerecordCount()
{ {
if (Global.MovieSession.Movie.IsActive) return Global.MovieSession.Movie.IsActive
{ ? Global.MovieSession.Movie.Rerecords.ToString()
return Global.MovieSession.Movie.Rerecords.ToString(); : "";
}
return "";
} }
private void DrawOsdMessage(IBlitter g, string message, Color color, float x, float y) private void DrawOsdMessage(IBlitter g, string message, Color color, float x, float y)
{ {
//g.DrawString(message, MessageFont, Color.Black, x + 1, y + 1);
g.DrawString(message, MessageFont, color, x, y); g.DrawString(message, MessageFont, color, x, y);
} }
@ -344,7 +316,6 @@ namespace BizHawk.Client.EmuHawk
var x = GetX(g, Global.Config.DispInpx, Global.Config.DispInpanchor, input); var x = GetX(g, Global.Config.DispInpx, Global.Config.DispInpanchor, input);
var y = GetY(g, Global.Config.DispInpy, Global.Config.DispInpanchor, input); var y = GetY(g, Global.Config.DispInpy, Global.Config.DispInpanchor, input);
Color c = Color.FromArgb(Global.Config.MovieInput); Color c = Color.FromArgb(Global.Config.MovieInput);
//g.DrawString(input, MessageFont, Color.Black, x + 1, y + 1);
g.DrawString(input, MessageFont, c, x, y); g.DrawString(input, MessageFont, c, x, y);
} }
@ -360,25 +331,25 @@ namespace BizHawk.Client.EmuHawk
var x = GetX(g, Global.Config.DispInpx, Global.Config.DispInpanchor, bgStr); var x = GetX(g, Global.Config.DispInpx, Global.Config.DispInpanchor, bgStr);
var y = GetY(g, Global.Config.DispInpy, Global.Config.DispInpanchor, bgStr); var y = GetY(g, Global.Config.DispInpy, Global.Config.DispInpanchor, bgStr);
//now, we're going to render these repeatedly, with higher-priority things overriding // now, we're going to render these repeatedly, with higher-priority things overriding
//first display previous frame's input. // first display previous frame's input.
//note: that's only available in case we're working on a movie // note: that's only available in case we're working on a movie
var previousStr = InputPrevious(); var previousStr = InputPrevious();
g.DrawString(previousStr, MessageFont, previousColor, x, y); g.DrawString(previousStr, MessageFont, previousColor, x, y);
//next, draw the immediate input. // next, draw the immediate input.
//that is, whatever's being held down interactively right this moment even if the game is paused // that is, whatever is being held down interactively right this moment even if the game is paused
//this includes things held down due to autohold or autofire // this includes things held down due to autohold or autofire
//I know, this is all really confusing // I know, this is all really confusing
var immediate = InputStrImmediate(); var immediate = InputStrImmediate();
g.DrawString(immediate, MessageFont, immediateColor, x, y); g.DrawString(immediate, MessageFont, immediateColor, x, y);
//next draw anything that's pressed because it's sticky. // next draw anything that's pressed because it's sticky.
//this applies to autofire and autohold both. somehow. I dont understand it. // this applies to autofire and autohold both. somehow. I don't understand it.
//basically we're tinting whatever's pressed because it's sticky specially // basically we're tinting whatever is pressed because it's sticky specially
//in order to achieve this we want to avoid drawing anything pink that isnt actually held down right now // in order to achieve this we want to avoid drawing anything pink that isn't actually held down right now
//so we make an AND adapter and combine it using immediate & sticky // so we make an AND adapter and combine it using immediate & sticky
var autoString = MakeStringFor(Global.StickyXORAdapter.Source.Xor(Global.AutofireStickyXORAdapter).And(Global.AutofireStickyXORAdapter)); var autoString = MakeStringFor(Global.StickyXORAdapter.Source.Xor(Global.AutofireStickyXORAdapter).And(Global.AutofireStickyXORAdapter));
g.DrawString(autoString, MessageFont, autoColor, x, y); g.DrawString(autoString, MessageFont, autoColor, x, y);
@ -396,12 +367,12 @@ namespace BizHawk.Client.EmuHawk
DrawOsdMessage(g, Global.MovieSession.MultiTrack.Status, FixedMessagesColor, x, y); DrawOsdMessage(g, Global.MovieSession.MultiTrack.Status, FixedMessagesColor, x, y);
} }
if (Global.Config.DisplayFPS && FPS != null) if (Global.Config.DisplayFPS && Fps != null)
{ {
float x = GetX(g, Global.Config.DispFPSx, Global.Config.DispFPSanchor, FPS); float x = GetX(g, Global.Config.DispFPSx, Global.Config.DispFPSanchor, Fps);
float y = GetY(g, Global.Config.DispFPSy, Global.Config.DispFPSanchor, FPS); float y = GetY(g, Global.Config.DispFPSy, Global.Config.DispFPSanchor, Fps);
DrawOsdMessage(g, FPS, FixedMessagesColor, x, y); DrawOsdMessage(g, Fps, FixedMessagesColor, x, y);
} }
if (Global.Config.DisplayLagCounter && Global.Emulator.CanPollInput()) if (Global.Config.DisplayLagCounter && Global.Emulator.CanPollInput())
@ -415,31 +386,31 @@ namespace BizHawk.Client.EmuHawk
if (Global.Config.DisplayRerecordCount) if (Global.Config.DisplayRerecordCount)
{ {
string rerec = MakeRerecordCount(); string rerecordCount = MakeRerecordCount();
float x = GetX(g, Global.Config.DispRecx, Global.Config.DispRecanchor, rerec); float x = GetX(g, Global.Config.DispRecx, Global.Config.DispRecanchor, rerecordCount);
float y = GetY(g, Global.Config.DispRecy, Global.Config.DispRecanchor, rerec); float y = GetY(g, Global.Config.DispRecy, Global.Config.DispRecanchor, rerecordCount);
DrawOsdMessage(g, rerec, FixedMessagesColor, x, y); DrawOsdMessage(g, rerecordCount, FixedMessagesColor, x, y);
} }
if (Global.ClientControls["Autohold"] || Global.ClientControls["Autofire"]) if (Global.ClientControls["Autohold"] || Global.ClientControls["Autofire"])
{ {
var disp = new StringBuilder("Held: "); var sb = new StringBuilder("Held: ");
foreach (string sticky in Global.StickyXORAdapter.CurrentStickies) foreach (string sticky in Global.StickyXORAdapter.CurrentStickies)
{ {
disp.Append(sticky).Append(' '); sb.Append(sticky).Append(' ');
} }
foreach (string autoSticky in Global.AutofireStickyXORAdapter.CurrentStickies) foreach (string autoSticky in Global.AutofireStickyXORAdapter.CurrentStickies)
{ {
disp sb
.Append("Auto-") .Append("Auto-")
.Append(autoSticky) .Append(autoSticky)
.Append(' '); .Append(' ');
} }
var message = disp.ToString(); var message = sb.ToString();
g.DrawString( g.DrawString(
message, message,
@ -460,5 +431,4 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
} }

View File

@ -2842,7 +2842,7 @@ namespace BizHawk.Client.EmuHawk
_lastFastForwardingOrRewinding = isFastForwardingOrRewinding; _lastFastForwardingOrRewinding = isFastForwardingOrRewinding;
// client input-related duties // client input-related duties
GlobalWin.OSD.ClearGUIText(); GlobalWin.OSD.ClearGuiText();
Global.CheatList.Pulse(); Global.CheatList.Pulse();
@ -3032,7 +3032,7 @@ namespace BizHawk.Client.EmuHawk
" >>"; " >>";
} }
GlobalWin.OSD.FPS = fpsString; GlobalWin.OSD.Fps = fpsString;
// need to refresh window caption in this case // need to refresh window caption in this case
if (Global.Config.DispSpeedupFeatures == 0) if (Global.Config.DispSpeedupFeatures == 0)
@ -3954,7 +3954,7 @@ namespace BizHawk.Client.EmuHawk
if (SavestateManager.LoadStateFile(path, userFriendlyStateName)) if (SavestateManager.LoadStateFile(path, userFriendlyStateName))
{ {
GlobalWin.OSD.ClearGUIText(); GlobalWin.OSD.ClearGuiText();
ClientApi.OnStateLoaded(this, userFriendlyStateName); ClientApi.OnStateLoaded(this, userFriendlyStateName);
if (GlobalWin.Tools.Has<LuaConsole>()) if (GlobalWin.Tools.Has<LuaConsole>())

View File

@ -147,7 +147,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethod("cleartext", "clears all text created by gui.text()")] [LuaMethod("cleartext", "clears all text created by gui.text()")]
public static void ClearText() public static void ClearText()
{ {
GlobalWin.OSD.ClearGUIText(); GlobalWin.OSD.ClearGuiText();
} }
[LuaMethodExample("gui.defaultForeground( 0x000000FF );")] [LuaMethodExample("gui.defaultForeground( 0x000000FF );")]
@ -702,7 +702,7 @@ namespace BizHawk.Client.EmuHawk
y -= Emulator.CoreComm.ScreenLogicalOffsetY; y -= Emulator.CoreComm.ScreenLogicalOffsetY;
} }
GlobalWin.OSD.AddGUIText(message, x, y, Color.Black, forecolor ?? Color.White, a); GlobalWin.OSD.AddGuiText(message, x, y, Color.Black, forecolor ?? Color.White, a);
} }
[LuaMethodExample("local nlguicre = gui.createcanvas( 77, 99, 2, 48 );")] [LuaMethodExample("local nlguicre = gui.createcanvas( 77, 99, 2, 48 );")]

View File

@ -854,7 +854,7 @@ namespace BizHawk.Client.EmuHawk
// Shenanigans // Shenanigans
// We want any gui.text messages from a script to immediately update even when paused // We want any gui.text messages from a script to immediately update even when paused
GlobalWin.OSD.ClearGUIText(); GlobalWin.OSD.ClearGuiText();
GlobalWin.Tools.UpdateToolsAfter(); GlobalWin.Tools.UpdateToolsAfter();
LuaImp.EndLuaDrawing(); LuaImp.EndLuaDrawing();
LuaImp.StartLuaDrawing(); LuaImp.StartLuaDrawing();

View File

@ -1480,6 +1480,10 @@ namespace BizHawk.Client.EmuHawk
{ {
EditAnalogProgrammatically(e); EditAnalogProgrammatically(e);
} }
else if (!e.Control && !e.Shift && !e.Alt)
{
}
RefreshDialog(); RefreshDialog();
} }

View File

@ -241,7 +241,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
GlobalWin.OSD.ClearGUIText(); GlobalWin.OSD.ClearGuiText();
if (_watches.Any()) if (_watches.Any())
{ {
_watches.UpdateValues(); _watches.UpdateValues();
@ -251,7 +251,7 @@ namespace BizHawk.Client.EmuHawk
for (var i = 0; i < _watches.Count; i++) for (var i = 0; i < _watches.Count; i++)
{ {
var frozen = !_watches[i].IsSeparator && Global.CheatList.IsActive(_watches[i].Domain, _watches[i].Address); var frozen = !_watches[i].IsSeparator && Global.CheatList.IsActive(_watches[i].Domain, _watches[i].Address);
GlobalWin.OSD.AddGUIText( GlobalWin.OSD.AddGuiText(
_watches[i].ToDisplayString(), _watches[i].ToDisplayString(),
Global.Config.DispRamWatchx, Global.Config.DispRamWatchx,
Global.Config.DispRamWatchy + (i * 14), Global.Config.DispRamWatchy + (i * 14),
@ -291,7 +291,7 @@ namespace BizHawk.Client.EmuHawk
for (var i = 0; i < _watches.Count; i++) for (var i = 0; i < _watches.Count; i++)
{ {
var frozen = !_watches[i].IsSeparator && Global.CheatList.IsActive(_watches[i].Domain, _watches[i].Address); var frozen = !_watches[i].IsSeparator && Global.CheatList.IsActive(_watches[i].Domain, _watches[i].Address);
GlobalWin.OSD.AddGUIText( GlobalWin.OSD.AddGuiText(
_watches[i].ToDisplayString(), _watches[i].ToDisplayString(),
Global.Config.DispRamWatchx, Global.Config.DispRamWatchx,
Global.Config.DispRamWatchy + (i * 14), Global.Config.DispRamWatchy + (i * 14),
@ -1005,7 +1005,7 @@ namespace BizHawk.Client.EmuHawk
if (!Global.Config.DisplayRamWatch) if (!Global.Config.DisplayRamWatch)
{ {
GlobalWin.OSD.ClearGUIText(); GlobalWin.OSD.ClearGuiText();
} }
else else
{ {

View File

@ -188,6 +188,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Autosave/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Autosave/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=backcolor/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=backcolor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bezier/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Bezier/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=blitter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bools/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Bools/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=botting/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=botting/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bsnes/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=bsnes/@EntryIndexedValue">True</s:Boolean>