Skip to content

Commit 2974fd1

Browse files
committed
feat: scrollable debugconsole history log
1 parent d487379 commit 2974fd1

File tree

6 files changed

+74
-11
lines changed

6 files changed

+74
-11
lines changed

Dialog/English.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ TAS_HELPER_TRACKSPINNER_TRACK= TrackSpinner Track
198198
TAS_HELPER_CAMERA_TARGET= Camera Target
199199
TAS_HELPER_CAMERA_TARGET_VECTOR_OPACITY= Camera-Target Link Opacity
200200
TAS_HELPER_OPEN_CONSOLE_IN_TAS= Allow Opening Console in TAS
201+
TAS_HELPER_SCROLLABLE_HISTORY_LOG= Scrollable Console History Log
201202
TAS_HELPER_ORDER_OF_OPERATION_STEPPING= Order-of-Operation Stepping
202203
TAS_HELPER_ORDER_OF_OPERATION_DESCRIPTION= Just like Frame Advance, but in a subframe scale, thus visualize order of operations.{n}
203204
Use hotkeys to take a step / "fastforward" to end of frame.{n}

Dialog/Fonts/chinese.fnt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<info face="Noto Sans CJK SC Medium" size="64" bold="0" italic="0" charset="" unicode="1" stretchH="100" smooth="1" aa="4" padding="0,0,0,0" spacing="1,1" outline="0"/>
44
<common lineHeight="64" base="51" scaleW="256" scaleH="256" pages="1" packed="0" alphaChnl="0" redChnl="4" greenChnl="4" blueChnl="4"/>
55
<pages>
6-
<page id="0" file="chinese_generated_1698859511718_0.png" />
6+
<page id="0" file="chinese_generated_1701598955522_0.png" />
77
</pages>
88
<chars count="36">
99
<char id="19977" x="201" y="208" width="38" height="33" xoffset="3" yoffset="18" xadvance="43" page="0" chnl="15" />

Dialog/Simplified Chinese.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ TAS_HELPER_TRACKSPINNER_TRACK= 轨道圆刺轨迹
197197
TAS_HELPER_CAMERA_TARGET= 镜头移动目标
198198
TAS_HELPER_CAMERA_TARGET_VECTOR_OPACITY= 镜头-目标 连线的不透明度
199199
TAS_HELPER_OPEN_CONSOLE_IN_TAS= 允许在 TAS 中打开控制台
200+
TAS_HELPER_SCROLLABLE_HISTORY_LOG= 可滚动的控制台历史记录
200201
TAS_HELPER_ORDER_OF_OPERATION_STEPPING= 亚帧步进
201202
TAS_HELPER_ORDER_OF_OPERATION_DESCRIPTION= 正如同逐帧步进, 但是在亚于帧的时间尺度上进行, 从而将一帧以内的运算顺序视觉化.{n}
202203
使用快捷键来步进, 或快进至一帧的结尾.{n}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ A Celeste Mod designed to be a tool in TAS making.
3030

3131
- Allow opening console in TAS.
3232

33+
- Scrollable Console History Log -> Besides holding ctrl + up/down (provided by Everest), you can now use MouseWheel/PageUp/PageDown to scroll over the history logs. Press Ctrl+PageUp/Down to scroll to top/bottom.
34+
3335
- Hotkeys -> you can change some of the settings using hotkeys.
3436

3537
- Main Switch hotkey -> Settings are memorized in a way that, ActualSettings = MainSwitch state && MemorizedSettings (if both sides are boolean. Similar for other types). The Main Switch hotkey just modifies MainSwitch state, and will not modify MemorizedSettings. Editing settings in menu or using other hotkeys will modify MemorizedSettings.

Source/Gameplay/ConsoleEnhancement.cs

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using Celeste.Mod.Core;
22
using Celeste.Mod.TASHelper.Utils;
3+
using Microsoft.Xna.Framework;
34
using Microsoft.Xna.Framework.Input;
45
using Mono.Cecil.Cil;
56
using Monocle;
67
using MonoMod.Cil;
78
using TAS;
9+
using TAS.EverestInterop;
810
using CMCore = Celeste.Mod.Core;
911

1012
namespace Celeste.Mod.TASHelper.Gameplay;
@@ -17,8 +19,13 @@ public static class ConsoleEnhancement {
1719

1820
private static int historyLineShift = 0;
1921

22+
private const int extraExtraHistoryLines = 1000;
23+
2024
private static int origValue;
2125

26+
public static float ScrollBarWidth = 10f;
27+
public static float ScrollBarHeight = 20f;
28+
2229
private static bool historyScrollEnabled => TasHelperSettings.EnableScrollableHistoryLog;
2330
public static void SetOpenConsole() {
2431
if (Manager.Running && !lastOpen) {
@@ -29,16 +36,13 @@ public static bool GetOpenConsole() { // openConsole.getter may not be called (e
2936
return openConsole;
3037
}
3138

32-
public static void GoBackToBottom() {
33-
historyLineShift = 0;
34-
}
35-
3639
[Load]
3740
public static void Load() {
3841
IL.Monocle.Commands.UpdateClosed += ILCommandUpdateClosed;
3942
On.Celeste.Level.BeforeRender += OnLevelBeforeRender;
4043
IL.Monocle.Commands.Render += ILCommandsRender;
4144
On.Monocle.Commands.UpdateOpen += OnCommandUpdateOpen;
45+
IL.Monocle.Commands.Log_object_Color += ILCommandsLog;
4246
}
4347

4448
[Unload]
@@ -47,12 +51,37 @@ public static void Unload() {
4751
On.Celeste.Level.BeforeRender -= OnLevelBeforeRender;
4852
IL.Monocle.Commands.Render -= ILCommandsRender;
4953
On.Monocle.Commands.UpdateOpen -= OnCommandUpdateOpen;
54+
IL.Monocle.Commands.Log_object_Color -= ILCommandsLog;
5055
}
5156

5257
[Initialize]
5358
public static void Initialize() {
5459
typeof(Manager).GetMethod("Update").HookAfter(UpdateCommands);
5560
typeof(Manager).GetMethod("DisableRun").HookAfter(MinorBugFixer);
61+
typeof(CenterCamera).GetMethod("ZoomCamera", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).IlHook(il => {
62+
ILCursor cursor = new ILCursor(il);
63+
if (cursor.TryGotoNext(MoveType.After, ins => ins.MatchCallOrCallvirt(typeof(MouseButtons).FullName, "get_Wheel"))) {
64+
cursor.EmitDelegate(PreventZoomCamera);
65+
cursor.Emit(OpCodes.Mul);
66+
}
67+
});
68+
}
69+
70+
private static int PreventZoomCamera() {
71+
return Engine.Commands.Open && historyScrollEnabled && Engine.Commands.drawCommands.Count > (Engine.ViewHeight - 100) / 30 ? 0 : 1;
72+
}
73+
74+
private static int ExtraExtraHistoryLines() {
75+
return historyScrollEnabled ? extraExtraHistoryLines : 0;
76+
}
77+
78+
private static void ILCommandsLog(ILContext il) {
79+
// allow to store more history logs than default setting of Everest, which is not editable in game (can only be editted in savefile)
80+
ILCursor cursor = new ILCursor(il);
81+
if (cursor.TryGotoNext(MoveType.After, ins => ins.MatchCallOrCallvirt<CoreModuleSettings>("get_ExtraCommandHistoryLines"))) {
82+
cursor.EmitDelegate(ExtraExtraHistoryLines);
83+
cursor.Emit(OpCodes.Add);
84+
}
5685
}
5786

5887
private static void ILCommandsRender(ILContext context) {
@@ -75,34 +104,63 @@ private static void ILCommandsRender(ILContext context) {
75104
}
76105

77106
private static void BeforeAction(Monocle.Commands commands) {
78-
origValue = commands.firstLineIndexToDraw;
79-
commands.firstLineIndexToDraw = Calc.Clamp(commands.firstLineIndexToDraw + historyLineShift, 0, Math.Max(commands.drawCommands.Count - 1, 0));
107+
if (historyScrollEnabled) {
108+
origValue = commands.firstLineIndexToDraw;
109+
commands.firstLineIndexToDraw = Calc.Clamp(commands.firstLineIndexToDraw + historyLineShift, 0, Math.Max(commands.drawCommands.Count - (Engine.ViewHeight - 100) / 30, 0));
110+
}
80111
}
81112

82113
private static void AfterAction(Monocle.Commands commands) {
114+
if (!historyScrollEnabled) {
115+
return;
116+
}
117+
if (commands.drawCommands.Count > (Engine.ViewHeight - 100) / 30) {
118+
int num3 = Math.Min((Engine.ViewHeight - 100) / 30, commands.drawCommands.Count - commands.firstLineIndexToDraw);
119+
float num4 = 10f + 30f * (float)num3;
120+
Draw.Rect((float)Engine.ViewWidth - 15f - ScrollBarWidth, (float)Engine.ViewHeight - num4 - 60f, ScrollBarWidth, num4, Color.Gray * 0.8f);
121+
Draw.Rect((float)Engine.ViewWidth - 15f - ScrollBarWidth + 1f, (float)Engine.ViewHeight - 60f - (float)(num4 - ScrollBarHeight) * (float)commands.firstLineIndexToDraw / (float)Math.Max(commands.drawCommands.Count - (Engine.ViewHeight - 100) / 30, 1) - ScrollBarHeight, ScrollBarWidth - 2f, ScrollBarHeight, Color.Silver * 0.8f);
122+
}
83123
if (commands.drawCommands.Count > 0) {
84124
historyLineShift = commands.firstLineIndexToDraw - origValue; // this automatically bounds our shift
85125
commands.firstLineIndexToDraw = origValue;
86126
}
87127
}
88128

89-
private static int repeatCounter = 0;
90-
91129
private static void OnCommandUpdateOpen(On.Monocle.Commands.orig_UpdateOpen orig, Monocle.Commands commands) {
92130
orig(commands);
93131
if (historyScrollEnabled) {
94132
bool controlPressed = commands.currentState[Keys.LeftControl] == KeyState.Down || commands.currentState[Keys.RightControl] == KeyState.Down;
133+
134+
// btw, mouseScroll is already used by Everest to adjust cursor scale
135+
MouseState mouseState = Mouse.GetState();
136+
int mouseScrollDelta = mouseState.ScrollWheelValue - commands.mouseScroll;
137+
if (mouseScrollDelta / 120 != 0) {
138+
// i dont know how ScrollWheelValue is calculated, for me, it's always a multiple of 120
139+
// in case for other people, it's lower than 120, we provide Math.Sign as a compensation
140+
historyLineShift += mouseScrollDelta / 120;
141+
}
142+
else {
143+
historyLineShift += Math.Sign(mouseScrollDelta);
144+
}
145+
95146
if (commands.currentState[Keys.PageUp] == KeyState.Down && commands.oldState[Keys.PageUp] == KeyState.Up) {
96-
historyLineShift += (Engine.ViewHeight - 100) / 30;
147+
if (controlPressed) {
148+
historyLineShift = 99999;
149+
}
150+
else {
151+
historyLineShift += (Engine.ViewHeight - 100) / 30;
152+
}
97153
}
98154
else if (commands.currentState[Keys.PageDown] == KeyState.Down && commands.oldState[Keys.PageDown] == KeyState.Up) {
99155
if (controlPressed) {
100-
historyLineShift = 0;
156+
historyLineShift = -99999;
101157
}
102158
else {
103159
historyLineShift -= (Engine.ViewHeight - 100) / 30;
104160
}
105161
}
162+
/*
163+
* this already exists
106164
else if (commands.currentState[Keys.Up] == KeyState.Down && controlPressed) {
107165
repeatCounter += 1;
108166
while (repeatCounter >= 6) {
@@ -120,6 +178,7 @@ private static void OnCommandUpdateOpen(On.Monocle.Commands.orig_UpdateOpen orig
120178
else {
121179
repeatCounter = 0;
122180
}
181+
*/
123182
}
124183
}
125184

0 commit comments

Comments
 (0)