Fix colours tab in alt menu not applying colour code changes when not visible

This commit is contained in:
UnknownShadow200 2018-09-15 23:24:55 +10:00
parent 972f51f454
commit c213e84770
6 changed files with 21 additions and 9 deletions

View File

@ -19,7 +19,10 @@ namespace ClassicalSharp.Gui.Widgets {
public void UpdateCols() { public void UpdateCols() {
elements[0].Contents = GetColString(); elements[0].Contents = GetColString();
if (!Active || selectedIndex != 0) return; if (selectedIndex != 0) return;
// defer updating colours tab until visible
if (!Active) { pendingRedraw = true; return; }
Redraw(); Redraw();
} }
@ -27,10 +30,12 @@ namespace ClassicalSharp.Gui.Widgets {
readonly Font font; readonly Font font;
InputWidget input; InputWidget input;
Size elementSize; Size elementSize;
bool pendingRedraw;
public void SetActive(bool active) { public void SetActive(bool active) {
Active = active; Active = active;
Height = active ? (int)texture.Height : 0; Height = active ? (int)texture.Height : 0;
if (active && pendingRedraw) Redraw();
} }
public override void Render(double delta) { public override void Render(double delta) {
@ -48,6 +53,7 @@ namespace ClassicalSharp.Gui.Widgets {
Make(elements[selectedIndex], font); Make(elements[selectedIndex], font);
Width = texture.Width; Width = texture.Width;
Height = texture.Height; Height = texture.Height;
pendingRedraw = false;
} }
unsafe void Make(SpecialInputTab e, Font font) { unsafe void Make(SpecialInputTab e, Font font) {

View File

@ -77,7 +77,7 @@ namespace ClassicalSharp {
bool insideMap = game.World.IsValidPos(pOrigin); bool insideMap = game.World.IsValidPos(pOrigin);
Vector3 coords; Vector3 coords;
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 25000; i++) {
int x = t.X, y = t.Y, z = t.Z; int x = t.X, y = t.Y, z = t.Z;
coords.X = x; coords.Y = y; coords.Z = z; coords.X = x; coords.Y = y; coords.Z = z;
t.Block = insideMap ? t.Block = insideMap ?
@ -97,7 +97,7 @@ namespace ClassicalSharp {
t.Step(); t.Step();
} }
throw new InvalidOperationException("did over 10000 iterations in CalculatePickedBlock(). " + throw new InvalidOperationException("did over 25000 iterations in CalculatePickedBlock(). " +
"Something has gone wrong. (dir: " + dir + ")"); "Something has gone wrong. (dir: " + dir + ")");
} }

View File

@ -149,7 +149,7 @@ static bool Picking_RayTrace(Vector3 origin, Vector3 dir, Real32 reach, struct P
Int32 i; Int32 i;
Vector3 coords; Vector3 coords;
for (i = 0; i < 10000; i++) { for (i = 0; i < 25000; i++) {
Int32 x = tracer.X, y = tracer.Y, z = tracer.Z; Int32 x = tracer.X, y = tracer.Y, z = tracer.Z;
coords.X = (Real32)x; coords.Y = (Real32)y; coords.Z = (Real32)z; coords.X = (Real32)x; coords.Y = (Real32)y; coords.Z = (Real32)z;
tracer.Block = insideMap ? tracer.Block = insideMap ?
@ -170,7 +170,7 @@ static bool Picking_RayTrace(Vector3 origin, Vector3 dir, Real32 reach, struct P
RayTracer_Step(&tracer); RayTracer_Step(&tracer);
} }
ErrorHandler_Fail("Something went wrong, did over 10,000 iterations in Picking_RayTrace()"); ErrorHandler_Fail("Something went wrong, did over 25,000 iterations in Picking_RayTrace()");
return false; return false;
} }

View File

@ -64,8 +64,8 @@ int main(int argc, char** argv) {
String args[PROGRAM_MAX_CMDARGS]; String args[PROGRAM_MAX_CMDARGS];
Int32 argsCount = Platform_GetCommandLineArgs(argc, argv, args); Int32 argsCount = Platform_GetCommandLineArgs(argc, argv, args);
/* NOTE: Make sure to comment this out before pushing a commit */ /* NOTE: Make sure to comment this out before pushing a commit */
// String rawArgs = String_FromConst("UnknownShadow200 fff 127.0.0.1 25565"); String rawArgs = String_FromConst("UnknownShadow200 fff 127.0.0.1 25565");
// argsCount = 4; String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount); argsCount = 4; String_UNSAFE_Split(&rawArgs, ' ', args, &argsCount);
if (argsCount == 0) { if (argsCount == 0) {
String name = String_FromConst("Singleplayer"); String name = String_FromConst("Singleplayer");

View File

@ -2751,6 +2751,7 @@ static void SpecialInputWidget_Redraw(struct SpecialInputWidget* w) {
SpecialInputWidget_Make(w, &w->Tabs[w->SelectedIndex]); SpecialInputWidget_Make(w, &w->Tabs[w->SelectedIndex]);
w->Width = w->Tex.Width; w->Width = w->Tex.Width;
w->Height = w->Tex.Height; w->Height = w->Tex.Height;
w->PendingRedraw = false;
} }
static void SpecialInputWidget_Init(void* widget) { static void SpecialInputWidget_Init(void* widget) {
@ -2787,13 +2788,17 @@ static bool SpecialInputWidget_MouseDown(void* widget, Int32 x, Int32 y, MouseBu
void SpecialInputWidget_UpdateCols(struct SpecialInputWidget* w) { void SpecialInputWidget_UpdateCols(struct SpecialInputWidget* w) {
SpecialInputWidget_UpdateColString(w); SpecialInputWidget_UpdateColString(w);
w->Tabs[0].Contents = w->ColString; w->Tabs[0].Contents = w->ColString;
if (!w->Active || w->SelectedIndex != 0) return; if (w->SelectedIndex != 0) return;
/* defer updating colours tab until visible */
if (!w->Active) { w->PendingRedraw = true; return; }
SpecialInputWidget_Redraw(w); SpecialInputWidget_Redraw(w);
} }
void SpecialInputWidget_SetActive(struct SpecialInputWidget* w, bool active) { void SpecialInputWidget_SetActive(struct SpecialInputWidget* w, bool active) {
w->Active = active; w->Active = active;
w->Height = active ? w->Tex.Height : 0; w->Height = active ? w->Tex.Height : 0;
if (active && w->PendingRedraw) SpecialInputWidget_Redraw(w);
} }
struct WidgetVTABLE SpecialInputWidget_VTABLE = { struct WidgetVTABLE SpecialInputWidget_VTABLE = {

View File

@ -202,6 +202,7 @@ struct SpecialInputWidget {
Widget_Layout Widget_Layout
Size2D ElementSize; Size2D ElementSize;
Int32 SelectedIndex; Int32 SelectedIndex;
bool PendingRedraw;
struct InputWidget* AppendObj; struct InputWidget* AppendObj;
struct Texture Tex; struct Texture Tex;
FontDesc Font; FontDesc Font;