-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathIntroTextModule.cs
More file actions
126 lines (120 loc) · 4.92 KB
/
IntroTextModule.cs
File metadata and controls
126 lines (120 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace Hacknet
{
internal class IntroTextModule : Module
{
private static readonly float FLASH_TIME = 3.5f;
private static readonly float STAY_ONSCREEN_TIME = 3f;
private static readonly float MODULE_FLASH_TIME = 2f;
private static readonly float CHAR_TIME = 0.048f;
private static readonly float LINE_TIME = 0.28f;
private static readonly float DELAY_FROM_START_MUSIC_TIMER = Settings.isConventionDemo ? 6.2f : 15.06f;
private static readonly float DEMO_DELAY_FROM_START_MUSIC_TIMER = 5.18f;
private static readonly string[] delims = new string[1]
{
"\r\n"
};
private int charIndex;
private float charTimer;
public bool complete;
private bool finishedText;
private Rectangle fullscreen;
private float lineTimer;
private readonly string[] text;
private int textIndex;
private float timer;
public IntroTextModule(Rectangle location, OS operatingSystem)
: base(location, operatingSystem)
{
bounds = location;
timer = 0.0f;
complete = false;
textIndex = 0;
finishedText = false;
fullscreen = new Rectangle(0, 0, spriteBatch.GraphicsDevice.Viewport.Width,
spriteBatch.GraphicsDevice.Viewport.Height);
text =
new StreamReader(
TitleContainer.OpenStream(os.multiplayer
? "Content/MultiplayerIntroText.txt"
: "Content/BitSpeech.txt")).ReadToEnd().Split(delims, StringSplitOptions.RemoveEmptyEntries);
}
public override void Update(float t)
{
base.Update(t);
var num1 = timer;
timer += t;
var num2 = Settings.isDemoMode ? DEMO_DELAY_FROM_START_MUSIC_TIMER : DELAY_FROM_START_MUSIC_TIMER;
if (num1 < (double) num2 && timer >= (double) num2)
MusicManager.playSong();
if (finishedText)
{
if (timer <= (double) STAY_ONSCREEN_TIME || timer <= STAY_ONSCREEN_TIME + (double) MODULE_FLASH_TIME)
return;
complete = true;
}
else if (timer > (double) FLASH_TIME)
{
charTimer += t;
if (charTimer < (double) CHAR_TIME)
return;
charTimer = Settings.isConventionDemo
? CHAR_TIME*(GuiData.getKeyboadState().IsKeyDown(Keys.LeftShift) ? 0.99f : 0.5f)
: 0.0f;
++charIndex;
if (charIndex < text[textIndex].Length)
return;
charIndex = text[textIndex].Length - 1;
lineTimer += t;
if (lineTimer < (double) LINE_TIME)
return;
lineTimer = Settings.isConventionDemo
? LINE_TIME*(GuiData.getKeyboadState().IsKeyDown(Keys.LeftShift) ? 0.99f : 0.2f)
: 0.0f;
++textIndex;
charIndex = 0;
if (textIndex < text.Length)
return;
if (!MusicManager.isPlaying)
MusicManager.playSong();
finishedText = true;
timer = 0.0f;
}
else
{
if (!Settings.isConventionDemo || !GuiData.getKeyboadState().IsKeyDown(Keys.LeftShift))
return;
timer += t + t;
}
}
public override void Draw(float t)
{
base.Draw(t);
spriteBatch.Draw(Utils.white, bounds, os.darkBackgroundColor);
if (Utils.random.NextDouble() < timer/(double) FLASH_TIME || timer > (double) FLASH_TIME || finishedText)
os.drawBackground();
var color = os.terminalTextColor*(finishedText ? (float) (1.0 - timer/(double) STAY_ONSCREEN_TIME) : 1f);
var position = new Vector2(120f, 100f);
if (timer > (double) FLASH_TIME || finishedText)
{
for (var index = 0; index < textIndex; ++index)
{
spriteBatch.DrawString(GuiData.smallfont, text[index], position, color);
position.Y += 16f;
}
if (!finishedText)
{
var text = this.text[textIndex].Substring(0, charIndex + 1);
spriteBatch.DrawString(GuiData.smallfont, text, position, color);
}
}
if (finishedText && timer > (double) STAY_ONSCREEN_TIME &&
Utils.random.NextDouble() < (timer - (double) STAY_ONSCREEN_TIME)/MODULE_FLASH_TIME)
os.drawModules(os.lastGameTime);
os.drawScanlines();
}
}
}