Don't pointlessly recreate chat textures when attempting to scroll past end or before top of chat log in GUI. (Thanks Cheesse)

This commit is contained in:
UnknownShadow200 2017-12-10 11:25:21 +11:00
parent d4f045e2c4
commit 14607ffeea

View File

@ -356,15 +356,13 @@ namespace ClassicalSharp.Gui.Screens {
// Do we need to move all chat down?
int resetIndex = game.Chat.Log.Count - chatLines;
if (chatIndex != resetIndex) {
chatIndex = resetIndex;
ScrollHistory();
chatIndex = ClampIndex(resetIndex);
ResetChat();
}
} else if (key == Key.PageUp) {
chatIndex -= chatLines;
ScrollHistory();
ScrollHistoryBy(-chatLines);
} else if (key == Key.PageDown) {
chatIndex += chatLines;
ScrollHistory();
ScrollHistoryBy(chatLines);
} else if (game.Server.SupportsFullCP437 && key == game.Input.Keys[KeyBind.ExtInput]) {
altText.SetActive(!altText.Active);
} else {
@ -388,8 +386,7 @@ namespace ClassicalSharp.Gui.Screens {
public override bool HandlesMouseScroll(float delta) {
if (!HandlesAllInput) return false;
int steps = Utils.AccumulateWheelDelta(ref chatAcc, delta);
chatIndex -= steps;
ScrollHistory();
ScrollHistoryBy(-steps);
return true;
}
@ -447,10 +444,18 @@ namespace ClassicalSharp.Gui.Screens {
input.Append(urlOverlay.Metadata);
}
void ScrollHistory() {
int ClampIndex(int index) {
int maxIndex = game.Chat.Log.Count - chatLines;
int minIndex = Math.Min(0, maxIndex);
Utils.Clamp(ref chatIndex, minIndex, maxIndex);
Utils.Clamp(ref index, minIndex, maxIndex);
return index;
}
void ScrollHistoryBy(int delta) {
int newIndex = ClampIndex(chatIndex + delta);
if (newIndex == chatIndex) return;
chatIndex = newIndex;
ResetChat();
}