Skip to content

Commit 6254660

Browse files
committed
WIP commit for cross model browsing
1 parent 40df374 commit 6254660

File tree

5 files changed

+59
-36
lines changed

5 files changed

+59
-36
lines changed

Editor/Core/UI/LogWindow-Prolog.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
using PrologFrame = Activ.Prolog.Frame;
1111
using PrologLogger = Activ.Prolog.Logger;
1212
using PrologMessage = Activ.Prolog.Message;
13-
using PrologWindowModel = Activ.Prolog.LogWindowModel;
14-
using static Activ.Prolog.LogWindowModel;
1513

1614
namespace Activ.Loggr.UI{
1715
public partial class LogWindow{ // Prolog
1816

19-
Vector2 p_scroll;
17+
public static readonly string[] rtypeOptions = {"any", "void", "status"};
2018

21-
PrologWindowModel model = PrologWindowModel.instance;
22-
PrologFrame selectedFrame; // Last selected frame object
19+
Vector2 p_scroll;
2320

2421
void DrawPrologView(){
2522
DrawPrologHeader();

Editor/Core/UI/LogWindow.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public partial class LogWindow : EditorWindow{
1313
const int FontSize = 13;
1414
const float ScrubberButtonsHeight = 24f;
1515
public static LogWindow instance;
16+
LogWindowModel model = new LogWindowModel();
1617
//
1718
static Font normalButtonFont;
1819
static Font _font;
@@ -94,7 +95,9 @@ void DrawTextView(string text, ref Vector2 scroll){
9495
scroll = BeginScrollView(scroll);
9596
GUI.backgroundColor = Color.black;
9697
ConfigTextAreaStyle();
97-
GL.TextArea(browsing ? selectedFrame.Format() : text,
98+
// TODO this is injecting prolog data into debug chan out
99+
// when browsing
100+
GL.TextArea(browsing ? model.selectedFrame.Format() : text,
98101
GL.ExpandHeight(true));
99102
EndScrollView();
100103
GUI.backgroundColor = Color.white;
@@ -113,7 +116,7 @@ void ConfigTextAreaStyle(){
113116

114117
void DrawScrubber(){
115118
BeginHorizontal();
116-
int frameNo = browsing ? selectedFrame.index : Time.frameCount;
119+
int frameNo = browsing ? model.selectedFrame.index : Time.frameCount;
117120
var style = GUI.skin.button;
118121
normalButtonFont = style.font;
119122
style.font = monofont;
@@ -138,12 +141,12 @@ void ToggleAdvanced(){}
138141
// Ref https://tinyurl.com/yyo8c35g which also demonstrates starting a 2D
139142
// GUI at handles location
140143
void OnSceneGUI(SceneView sceneView){
141-
var sel = PrologHistoryGUI.Draw(model.filtered, selectedFrame);
144+
var sel = PrologHistoryGUI.Draw(model.filtered, model.selectedFrame);
142145
if(Ed.isPaused || !isPlaying){
143-
selectedFrame = sel ?? selectedFrame;
146+
model.selectedFrame = sel ?? model.selectedFrame;
144147
Repaint();
145148
}else{
146-
selectedFrame = null;
149+
model.selectedFrame = null;
147150
}
148151
}
149152

@@ -153,20 +156,18 @@ void OnSelectionChange()
153156
void Clear(){
154157
PrologLogger.Clear();
155158
model.Clear();
156-
selectedFrame = null;
157159
SceneView.RepaintAll();
158160
Repaint();
159161
}
160162

161163
void SelectPrev(){
162-
selectedFrame = model.filtered.Prev(selectedFrame
163-
?? model.filtered.last);
164+
model.selectedFrame = model.Prev(model.selectedFrame);
164165
SceneView.RepaintAll();
165166
}
166167

167168
void SelectNext(){
168-
if(selectedFrame == null) return;
169-
selectedFrame = model.filtered.Next(selectedFrame);
169+
if(model.selectedFrame == null) return;
170+
model.selectedFrame = model.Next(model.selectedFrame);
170171
SceneView.RepaintAll();
171172
}
172173

@@ -187,7 +188,7 @@ static Font monofont{ get{
187188
}}
188189

189190
bool browsing
190-
=> (Ed.isPaused || !isPlaying) && selectedFrame != null;
191+
=> (Ed.isPaused || !isPlaying) && model.selectedFrame != null;
191192

192193
static bool isPlaying => Application.isPlaying;
193194

Editor/Core/UI/LogWindowModel.cs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
11
using UnityEngine;
22
using Activ.Loggr;
3+
using PrologHistory = Activ.Prolog.History;
4+
using PrologFrame = Activ.Prolog.Frame;
5+
using PrologFilter = Activ.Prolog.Filter;
6+
using PrologFormatter = Activ.Prolog.Formatter;
7+
using PrologLogger = Activ.Prolog.Logger;
38

4-
namespace Activ.Prolog{
9+
namespace Activ.Loggr.UI{
510
public class LogWindowModel{
611

7-
public static readonly string[] rtypeOptions = {"any", "void", "status"};
8-
public static LogWindowModel instance = new LogWindowModel();
912
public GameObject current;
10-
public History filtered{ get; private set; }
11-
Filter filter;
13+
public PrologHistory filtered{ get; private set; }
14+
PrologFilter filter;
15+
public PrologFrame selectedFrame; // Last selected frame object
1216

13-
public GameObject selection
14-
=> Config.useSelection ? current : null;
17+
public LogWindowModel(){
18+
PrologLogger.onFrame += OnPrologFrame;
19+
}
20+
21+
public void Clear(){
22+
filtered = null;
23+
current = null;
24+
selectedFrame = null;
25+
}
26+
27+
public PrologFrame Next(PrologFrame current){
28+
return filtered.Next(current);
29+
}
1530

16-
public void Clear(){ filtered = null; current = null; }
31+
public PrologFrame Prev(PrologFrame current){
32+
return filtered.Prev(current ?? filtered.last);
33+
}
1734

1835
public string Output(bool useHistory, string rtype){
19-
filter = new Filter(selection, rtype);
20-
return useHistory ? Formatter.Latest(source)
21-
: Formatter.State(source);
36+
filter = new PrologFilter(selection, rtype);
37+
return useHistory ? PrologFormatter.Latest(source)
38+
: PrologFormatter.State(source);
39+
}
40+
41+
public void OnPrologFrame(PrologFrame frame){
42+
filtered += frame;
43+
Activ.Loggr.UI.LogWindow.instance?.Repaint();
2244
}
2345

24-
public void Log(Frame frame) => filtered += frame;
46+
public GameObject selection
47+
=> Config.useSelection ? current : null;
2548

26-
History source
27-
=> selection ? (filtered /= filter) : Logger.history;
49+
PrologHistory source
50+
=> selection ? (filtered /= filter) : PrologLogger.history;
2851

2952
}}

Editor/DebugChan/LoggingManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ static void OnPlayState(PlayModeStateChange state){
1515
case PlayModeStateChange.EnteredPlayMode:
1616
DebugChan.logger = new Logger<string, object>();
1717
DebugChan.logToConsole = Config.logToConsole;
18-
// TODO - transitional ref
19-
//
2018
DebugChan.maxMessages = Config.maxMessages == 0 ? (int?)null : Config.maxMessages;
2119
Activ.Loggr.UI.LogWindow.cumulatedMessageCount = 0;
2220
break;

Editor/Prolog/Logger.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
using System.Diagnostics;
33
using UnityEngine;
44
using UnityEditor;
5-
//using static UnityEngine.Application;
65
using Activ.Prolog.IL;
76
using Activ.Loggr; // for config keys
87

98
namespace Activ.Prolog{
109
[InitializeOnLoad]
1110
public static class Logger{
1211

12+
public static event FrameEventHandler onFrame;
13+
1314
public static int injectionTimeMs;
1415
public static History history = new History(ConfigKeys.LogPath);
1516
public static List<Frame> frames = new List<Frame>();
17+
1618
static bool isPlaying = false;
1719

1820
private static void OnPlayState(PlayModeStateChange state){
@@ -49,9 +51,7 @@ public static void LogStatic(string type, string message)
4951
static void Process(Message msg){
5052
if(frame + msg) return;
5153
history += frame;
52-
LogWindowModel.instance.Log(frame);
53-
// TODO model-to-view dep
54-
Activ.Loggr.UI.LogWindow.instance?.Repaint();
54+
onFrame?.Invoke(frame);
5555
frame = new Frame(msg);
5656
}
5757

@@ -60,4 +60,8 @@ static Frame frame{
6060
set => frames.Add(value);
6161
}
6262

63+
// -------------------------------------------------------------
64+
65+
public delegate void FrameEventHandler(Frame frame);
66+
6367
}}

0 commit comments

Comments
 (0)