Skip to content

Commit

Permalink
Corrected an issue with scrolling textbox answers
Browse files Browse the repository at this point in the history
This solution probably isn’t perfect, as it locks minor responses to
the bottom, but it’s certainly an improvement on the previous
behaviour. This closes #201.
  • Loading branch information
varkor committed Feb 27, 2016
1 parent 8ae712d commit 8505177
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions battle/battle.html
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@
Interface.clearIssues();
});

window.addEventListener("keydown", function (event) {
if (event.keyCode === 38 || event.keyCode === 40) {
event.preventDefault();
}
});

document.body.appendChild(Widgets.Party.interface.canvas);
document.body.appendChild(Widgets.Bag.interface.canvas);
}
Expand Down
11 changes: 7 additions & 4 deletions battle/scripts/objects/unique/Textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,13 +787,16 @@ const Textbox = FunctionObject.new({
if (majorResponses > maxResponses) {
responseOffset = Math.max(0, Math.ceil(Math.min(majorResponses - maxResponses, Math.floor(Textbox.response - maxResponses / 2)) / style.responsesPerRow) * style.responsesPerRow);
}
for (var response = responseOffset, responsesOfKind, relativeResponse, selected, hovered, isMajor; (response - responseOffset < maxResponses || response >= majorResponses) && response < responses; ++ response) {
for (var response = responseOffset, responsesOfKind, relativeResponse, selected, hovered, isMajor; response < responses; ++ response) {
isMajor = response < majorResponses;
if (!(response - responseOffset < maxResponses || response >= majorResponses) && isMajor) {
continue;
}
responsesOfKind = isMajor ? majorResponses : minorResponses;
relativeResponse = (response - responseOffset) - (isMajor ? 0 : majorResponses);
relativeResponse = isMajor ? response - responseOffset : response - majorResponses;
responseMetrics.width = Math.ceil(metrics.width / (responsesOfKind % style.responsesPerRow !== 0 && relativeResponse >= responsesOfKind - (responsesOfKind % style.responsesPerRow) ? responsesOfKind % style.responsesPerRow : style.responsesPerRow));
responseMetrics.x = Math.ceil(metrics.left + (relativeResponse % style.responsesPerRow) * responseMetrics.width);
responseMetrics.y = metrics.top + metrics.height + (isMajor ? Math.floor(relativeResponse / style.responsesPerRow) * metrics.response.major.height : Math.ceil(majorResponses / style.responsesPerRow) * metrics.response.major.height + Math.floor(relativeResponse / style.responsesPerRow) * metrics.response.minor.height);
responseMetrics.y = metrics.top + metrics.height + (isMajor ? Math.floor(relativeResponse / style.responsesPerRow) * metrics.response.major.height : Math.min(Math.ceil(majorResponses / style.responsesPerRow), style.maxRows) * metrics.response.major.height + Math.floor(relativeResponse / style.responsesPerRow) * metrics.response.minor.height);
responseMetrics.height = (isMajor ? metrics.response.major : metrics.response.minor).height;
selected = (hovered = Cursor.inArea(canvas, responseMetrics.x * Game.zoom, responseMetrics.y * Game.zoom, responseMetrics.width * Game.zoom, responseMetrics.height * Game.zoom) && Input.priority === "mouse") || (Input.controlScheme === "keyboard" && Textbox.response === response && (!cursorIsOverAResponse || Input.priority === "keyboard"));
context.fillStyle = (selected ? "hsla(0, 0%, 100%, 0.8)" : "hsla(0, 0%, 0%, 0.6)");
Expand Down Expand Up @@ -824,7 +827,7 @@ const Textbox = FunctionObject.new({
context.fill();
}
if (responseOffset + maxResponses < majorResponses) {
var responseHeight = Math.ceil(Math.min(majorResponses, style.maxRows * style.responsesPerRow) / style.responsesPerRow) * metrics.response.major.height + Math.ceil(minorResponses / style.responsesPerRow) * metrics.response.minor.height;
var responseHeight = Math.ceil(Math.min(majorResponses, style.maxRows * style.responsesPerRow) / style.responsesPerRow) * metrics.response.major.height;
context.beginPath();
context.moveToHD((metrics.left + metrics.width / 2) * Game.zoom, (metrics.top + metrics.height + responseHeight + triangleHeight / 2 - bob) * Game.zoom);
context.lineToHD((metrics.left + metrics.width / 2 + triangleWidth / 2) * Game.zoom, (metrics.top + metrics.height + responseHeight - triangleHeight / 2 - bob) * Game.zoom);
Expand Down

0 comments on commit 8505177

Please sign in to comment.