mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
More fixes III
This commit is contained in:
parent
946e5075ac
commit
0121a1820f
@ -46,6 +46,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
protected override void ContextLost() {
|
||||
if (widgets == null) return;
|
||||
|
||||
for (int i = 0; i < widgets.Length; i++) {
|
||||
if (widgets[i] == null) continue;
|
||||
widgets[i].Dispose();
|
||||
|
@ -25,9 +25,9 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
string title, lastTitle;
|
||||
string[] body, lastBody;
|
||||
bool confirmNo, confirmMode, showAlways;
|
||||
string title;
|
||||
string[] body;
|
||||
bool confirmNo, confirmingMode, showAlways;
|
||||
int alwaysIndex = 100;
|
||||
|
||||
public override void Init() {
|
||||
@ -35,15 +35,14 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
titleFont = new Font(game.FontName, 16, FontStyle.Bold);
|
||||
regularFont = new Font(game.FontName, 16, FontStyle.Regular);
|
||||
backCol.A = 210;
|
||||
|
||||
if (game.Graphics.LostContext) return;
|
||||
InitStandardButtons();
|
||||
SetText(title, body);
|
||||
RedrawText();
|
||||
}
|
||||
|
||||
public void SetText(string title, params string[] body) {
|
||||
lastTitle = title;
|
||||
lastBody = body;
|
||||
|
||||
if (confirmMode) {
|
||||
public void RedrawText() {
|
||||
if (confirmingMode) {
|
||||
SetTextImpl("&eYou might be missing out.",
|
||||
"Texture packs can play a vital role in the look and feel of maps.",
|
||||
"", "Sure you don't want to download the texture pack?");
|
||||
@ -57,8 +56,6 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
for (int i = 0; i < labels.Length; i++)
|
||||
labels[i].Dispose();
|
||||
}
|
||||
this.title = title;
|
||||
this.body = body;
|
||||
|
||||
labels = new TextWidget[body.Length + 1];
|
||||
labels[0] = TextWidget.Create(game, title, titleFont)
|
||||
@ -96,28 +93,35 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
for (int i = 0; i < labels.Length; i++)
|
||||
labels[i].CalculatePosition();
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
|
||||
protected override void ContextLost() {
|
||||
base.ContextLost();
|
||||
if (labels == null) return;
|
||||
|
||||
for (int i = 0; i < labels.Length; i++)
|
||||
labels[i].Dispose();
|
||||
}
|
||||
|
||||
protected override void ContextLost()
|
||||
{
|
||||
base.ContextLost();
|
||||
}
|
||||
|
||||
protected override void ContextRecreated()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
protected override void ContextRecreated() {
|
||||
InitStandardButtons();
|
||||
RedrawText();
|
||||
}
|
||||
|
||||
|
||||
void InitStandardButtons() {
|
||||
widgets = new ButtonWidget[showAlways ? 4 : 2];
|
||||
base.ContextLost();
|
||||
alwaysIndex = 100;
|
||||
|
||||
if (confirmingMode) {
|
||||
widgets = new ButtonWidget[2];
|
||||
widgets[0] = ButtonWidget.Create(game, 160, 35, "I'm sure", titleFont, OnNoClick)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, -110, 30);
|
||||
widgets[1] = ButtonWidget.Create(game, 160, 35, "Go back", titleFont, GoBackClick)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 110, 30);
|
||||
return;
|
||||
}
|
||||
|
||||
widgets = new ButtonWidget[showAlways ? 4 : 2];
|
||||
widgets[0] = ButtonWidget.Create(game, 160, 35, "Yes", titleFont, OnYesClick)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, -110, 30);
|
||||
widgets[1] = ButtonWidget.Create(game, 160, 35, "No", titleFont, OnNoClick)
|
||||
@ -146,8 +150,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
if (btn != MouseButton.Left) return;
|
||||
bool always = Array.IndexOf<Widget>(widgets, w) >= alwaysIndex;
|
||||
|
||||
if (confirmNo && !confirmMode) {
|
||||
InitConfirmButtons(always); return;
|
||||
if (confirmNo && !confirmingMode) {
|
||||
confirmingMode = true;
|
||||
ContextRecreated();
|
||||
return;
|
||||
}
|
||||
|
||||
if (noClick != null) noClick(this, always);
|
||||
@ -155,23 +161,11 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
CloseScreen();
|
||||
}
|
||||
|
||||
void InitConfirmButtons(bool always) {
|
||||
alwaysIndex = always ? 0 : 100;
|
||||
widgets = new ButtonWidget[] {
|
||||
ButtonWidget.Create(game, 160, 35, "I'm sure", titleFont, OnNoClick)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, -110, 30),
|
||||
ButtonWidget.Create(game, 160, 35, "Go back", titleFont, GoBackClick)
|
||||
.SetLocation(Anchor.Centre, Anchor.Centre, 110, 30),
|
||||
};
|
||||
confirmMode = true;
|
||||
SetText(lastTitle, lastBody);
|
||||
}
|
||||
|
||||
void GoBackClick(Game g, Widget w, MouseButton btn, int x, int y) {
|
||||
if (btn != MouseButton.Left) return;
|
||||
InitStandardButtons();
|
||||
confirmMode = false;
|
||||
SetText(lastTitle, lastBody);
|
||||
|
||||
confirmingMode = false;
|
||||
ContextRecreated();
|
||||
}
|
||||
}
|
||||
}
|
@ -74,6 +74,8 @@ namespace ClassicalSharp.Entities {
|
||||
|
||||
public virtual void ContextLost() { }
|
||||
|
||||
public virtual void ContextRecreated() { }
|
||||
|
||||
|
||||
/// <summary> Gets the position of the player's eye in the world. </summary>
|
||||
public Vector3 EyePosition {
|
||||
|
@ -28,6 +28,7 @@ namespace ClassicalSharp.Entities {
|
||||
public EntityList(Game game) {
|
||||
this.game = game;
|
||||
game.Graphics.ContextLost += ContextLost;
|
||||
game.Graphics.ContextRecreated += ContextRecreated;
|
||||
game.Events.ChatFontChanged += ChatFontChanged;
|
||||
game.Events.TextureChanged += TextureChanged;
|
||||
|
||||
@ -108,6 +109,13 @@ namespace ClassicalSharp.Entities {
|
||||
}
|
||||
}
|
||||
|
||||
void ContextRecreated() {
|
||||
for (int i = 0; i < Entities.Length; i++) {
|
||||
if (Entities[i] == null) continue;
|
||||
Entities[i].ContextRecreated();
|
||||
}
|
||||
}
|
||||
|
||||
void TextureChanged(object sender, TextureEventArgs e) {
|
||||
if (e.Name != "char.png") return;
|
||||
for (int i = 0; i < Entities.Length; i++) {
|
||||
@ -132,8 +140,10 @@ namespace ClassicalSharp.Entities {
|
||||
}
|
||||
|
||||
game.Graphics.ContextLost -= ContextLost;
|
||||
game.Graphics.ContextRecreated -= ContextRecreated;
|
||||
game.Events.ChatFontChanged -= ChatFontChanged;
|
||||
game.Events.TextureChanged -= TextureChanged;
|
||||
|
||||
if (ShadowComponent.shadowTex > 0)
|
||||
game.Graphics.DeleteTexture(ref ShadowComponent.shadowTex);
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ namespace ClassicalSharp.Entities {
|
||||
game.Graphics.DeleteTexture(ref nameTex.ID);
|
||||
}
|
||||
|
||||
public override void ContextRecreated() { UpdateName(); }
|
||||
|
||||
protected void MakeNameTexture() {
|
||||
using (Font font = new Font(game.FontName, 24)) {
|
||||
DrawTextArgs args = new DrawTextArgs(DisplayName, font, false);
|
||||
@ -58,6 +60,7 @@ namespace ClassicalSharp.Entities {
|
||||
|
||||
public void UpdateName() {
|
||||
ContextLost();
|
||||
if (game.Graphics.LostContext) return;
|
||||
MakeNameTexture();
|
||||
}
|
||||
|
||||
|
@ -72,9 +72,11 @@ namespace ClassicalSharp {
|
||||
string address = url;
|
||||
if (url.StartsWith("https://")) address = url.Substring(8);
|
||||
if (url.StartsWith("http://")) address = url.Substring(7);
|
||||
screen.SetText("Do you want to download the server's texture pack?",
|
||||
|
||||
screen.SetTextData("Do you want to download the server's texture pack?",
|
||||
"Texture pack url:", address,
|
||||
"Download size: " + contentLengthMB.ToString("F3") + " MB");
|
||||
screen.RedrawText();
|
||||
}
|
||||
|
||||
protected internal void RetrieveTexturePack(string url) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user