Permalink
Browse files

Show 0.30 version when in classic mode

  • Loading branch information...
UnknownShadow200 committed Dec 1, 2018
1 parent a3b8cd4 commit 4c019f900ac946979b8df31055f9ddb394d7f92b
Showing with 72 additions and 45 deletions.
  1. +35 −21 ClassicalSharp/2D/Screens/StatusScreen.cs
  2. +2 −3 src/LWidgets.c
  3. +35 −21 src/Screens.c
@@ -13,8 +13,8 @@ namespace ClassicalSharp.Gui.Screens {
public class StatusScreen : Screen, IGameComponent {
Font font;
StringBuffer statusBuffer;
TextWidget status, hackStates;
StringBuffer statusBuffer;
TextWidget line1, line2;
TextAtlas posAtlas;
public StatusScreen(Game game) : base(game) {
@@ -27,7 +27,7 @@ public class StatusScreen : Screen, IGameComponent {
void IGameComponent.Reset(Game game) { }
void IGameComponent.OnNewMap(Game game) { }
void IGameComponent.OnNewMapLoaded(Game game) { }
public override void Init() {
font = new Font(game.FontName, 16);
ContextRecreated();
@@ -39,14 +39,17 @@ public class StatusScreen : Screen, IGameComponent {
public override void Render(double delta) {
UpdateStatus(delta);
if (game.HideGui || !game.ShowFPS) return;
if (game.HideGui) return;
game.Graphics.Texturing = true;
status.Render(delta);
if (game.ShowFPS) line1.Render(delta);
if (!game.ClassicMode && game.Gui.activeScreen == null) {
if (game.ClassicMode) {
line2.Render(delta);
} else if (game.Gui.activeScreen == null && game.ShowFPS) {
if (HacksChanged()) { UpdateHackState(); }
DrawPosition();
hackStates.Render(delta);
line2.Render(delta);
}
game.Graphics.Texturing = false;
}
@@ -87,34 +90,45 @@ public class StatusScreen : Screen, IGameComponent {
}
}
status.Set(statusBuffer.ToString(), font);
line1.Set(statusBuffer.ToString(), font);
accumulator = 0;
frames = 0;
game.ChunkUpdates = 0;
}
protected override void ContextLost() {
status.Dispose();
line1.Dispose();
posAtlas.Dispose();
hackStates.Dispose();
line2.Dispose();
}
protected override void ContextRecreated() {
status = new TextWidget(game)
line1 = new TextWidget(game)
.SetLocation(Anchor.Min, Anchor.Min, 2, 2);
status.ReducePadding = true;
line1.ReducePadding = true;
string msg = statusBuffer.Length > 0 ? statusBuffer.ToString() : "FPS: no data yet";
status.Set(msg, font);
line1.Set(msg, font);
posAtlas = new TextAtlas(game, 16);
posAtlas.Pack("0123456789-, ()", font, "Position: ");
posAtlas.tex.Y = (short)(status.Height + 2);
posAtlas.tex.Y = (short)(line1.Height + 2);
int yOffset = status.Height + posAtlas.tex.Height + 2;
hackStates = new TextWidget(game)
int yOffset = line1.Height + posAtlas.tex.Height + 2;
line2 = new TextWidget(game)
.SetLocation(Anchor.Min, Anchor.Min, 2, yOffset);
hackStates.ReducePadding = true;
UpdateHackState();
line2.ReducePadding = true;
if (game.ClassicMode) {
// Swap around so 0.30 version is at top
line2.YOffset = 2;
line1.YOffset = posAtlas.tex.Y;
line2.Set("0.30", font);
line1.Reposition();
line2.Reposition();
} else {
UpdateHackState();
}
}
void ChatFontChanged() { Recreate(); }
@@ -147,12 +161,12 @@ public class StatusScreen : Screen, IGameComponent {
bool HacksChanged() {
HacksComponent hacks = game.LocalPlayer.Hacks;
return hacks.Speeding != speed || hacks.HalfSpeeding != halfSpeed || hacks.Flying != fly
|| hacks.Noclip != noclip || game.Fov != lastFov || hacks.CanSpeed != canSpeed;
|| hacks.Noclip != noclip || game.Fov != lastFov || hacks.CanSpeed != canSpeed;
}
void UpdateHackState() {
HacksComponent hacks = game.LocalPlayer.Hacks;
speed = hacks.Speeding; halfSpeed = hacks.HalfSpeeding; fly = hacks.Flying;
speed = hacks.Speeding; halfSpeed = hacks.HalfSpeeding; fly = hacks.Flying;
noclip = hacks.Noclip; lastFov = game.Fov; canSpeed = hacks.CanSpeed;
statusBuffer.Clear();
@@ -162,7 +176,7 @@ public class StatusScreen : Screen, IGameComponent {
bool speeding = (speed || halfSpeed) && hacks.CanSpeed;
if (speeding) statusBuffer.Append("Speed ON ");
if (noclip) statusBuffer.Append("Noclip ON ");
hackStates.Set(statusBuffer.ToString(), font);
line2.Set(statusBuffer.ToString(), font);
}
}
}
@@ -38,7 +38,7 @@ void LWidget_Reset(void* widget) {
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
*#########################################################################################################################*/
#define BTN_BORDER 1
static BitmapCol Expand(BitmapCol a, int amount) {
static BitmapCol LButton_Expand(BitmapCol a, int amount) {
int r, g, b;
r = a.R + amount; Math_Clamp(r, 0, 255); a.R = r;
g = a.G + amount; Math_Clamp(g, 0, 255); a.G = g;
@@ -58,8 +58,7 @@ static void LButton_DrawBackground(struct LButton* w) {
w->Width - 2 * BTN_BORDER, w->Height - 2 * BTN_BORDER);
} else {
col = w->Active ? Launcher_ButtonForeActiveCol : Launcher_ButtonForeCol;
BitmapCol top = Expand(col, 8), bottom = Expand(col, -8);
Gradient_Vertical(&Launcher_Framebuffer, top, bottom,
Gradient_Vertical(&Launcher_Framebuffer, LButton_Expand(col, 8), LButton_Expand(col, -8),
w->X + BTN_BORDER, w->Y + BTN_BORDER,
w->Width - 2 * BTN_BORDER, w->Height - 2 * BTN_BORDER);
}
@@ -30,7 +30,7 @@ struct InventoryScreen {
struct StatusScreen {
Screen_Layout
FontDesc Font;
struct TextWidget Status, HackStates;
struct TextWidget Line1, Line2;
struct TextAtlas PosAtlas;
double Accumulator;
int Frames, FPS;
@@ -343,7 +343,7 @@ static void StatusScreen_UpdateHackState(struct StatusScreen* s) {
if (speeding) String_AppendConst(&status, "Speed ON ");
if (hacks->Noclip) String_AppendConst(&status, "Noclip ON ");
TextWidget_Set(&s->HackStates, &status, &s->Font);
TextWidget_Set(&s->Line2, &status, &s->Font);
}
static void StatusScreen_Update(struct StatusScreen* s, double delta) {
@@ -356,7 +356,7 @@ static void StatusScreen_Update(struct StatusScreen* s, double delta) {
String_InitArray(status, statusBuffer);
StatusScreen_MakeText(s, &status);
TextWidget_Set(&s->Status, &status, &s->Font);
TextWidget_Set(&s->Line1, &status, &s->Font);
s->Accumulator = 0.0;
s->Frames = 0;
Game_ChunkUpdates = 0;
@@ -371,34 +371,46 @@ static void StatusScreen_FontChanged(void* screen) {
static void StatusScreen_ContextLost(void* screen) {
struct StatusScreen* s = screen;
TextAtlas_Free(&s->PosAtlas);
Elem_TryFree(&s->Status);
Elem_TryFree(&s->HackStates);
Elem_TryFree(&s->Line1);
Elem_TryFree(&s->Line2);
}
static void StatusScreen_ContextRecreated(void* screen) {
static String chars = String_FromConst("0123456789-, ()");
static String prefix = String_FromConst("Position: ");
static String chars = String_FromConst("0123456789-, ()");
static String prefix = String_FromConst("Position: ");
static String version = String_FromConst("0.30");
struct StatusScreen* s = screen;
struct TextWidget* status = &s->Status;
struct TextWidget* hacks = &s->HackStates;
struct TextWidget* line1 = &s->Line1;
struct TextWidget* line2 = &s->Line2;
int y;
y = 2;
TextWidget_Make(status);
Widget_SetLocation(status, ANCHOR_MIN, ANCHOR_MIN, 2, y);
status->ReducePadding = true;
TextWidget_Make(line1);
Widget_SetLocation(line1, ANCHOR_MIN, ANCHOR_MIN, 2, y);
line1->ReducePadding = true;
StatusScreen_Update(s, 1.0);
y += status->Height;
y += line1->Height;
TextAtlas_Make(&s->PosAtlas, &chars, &s->Font, &prefix);
s->PosAtlas.Tex.Y = y;
y += s->PosAtlas.Tex.Height;
TextWidget_Make(hacks);
Widget_SetLocation(hacks, ANCHOR_MIN, ANCHOR_MIN, 2, y);
hacks->ReducePadding = true;
StatusScreen_UpdateHackState(s);
TextWidget_Make(line2);
Widget_SetLocation(line2, ANCHOR_MIN, ANCHOR_MIN, 2, y);
line2->ReducePadding = true;
if (Game_ClassicMode) {
/* Swap around so 0.30 version is at top */
line2->YOffset = 2;
line1->YOffset = s->PosAtlas.Tex.Y;
TextWidget_Set(line2, &version, &s->Font);
Widget_Reposition(line1);
Widget_Reposition(line2);
} else {
StatusScreen_UpdateHackState(s);
}
}
static bool StatusScreen_Key(void* elem, Key key) { return false; }
@@ -415,15 +427,17 @@ static void StatusScreen_Init(void* screen) {
static void StatusScreen_Render(void* screen, double delta) {
struct StatusScreen* s = screen;
StatusScreen_Update(s, delta);
if (Game_HideGui || !Game_ShowFPS) return;
if (Game_HideGui) return;
Gfx_SetTexturing(true);
Elem_Render(&s->Status, delta);
if (Game_ShowFPS) Elem_Render(&s->Line1, delta);
if (!Game_ClassicMode && !Gui_Active) {
if (Game_ClassicMode) {
Elem_Render(&s->Line2, delta);
} else if (!Gui_Active && Game_ShowFPS) {
if (StatusScreen_HacksChanged(s)) { StatusScreen_UpdateHackState(s); }
StatusScreen_DrawPosition(s);
Elem_Render(&s->HackStates, delta);
Elem_Render(&s->Line2, delta);
}
Gfx_SetTexturing(false);
}

0 comments on commit 4c019f9

Please sign in to comment.