Skip to content

Commit

Permalink
fix: Reinstate buttons to overwrite popup
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Jul 29, 2024
1 parent 13c831b commit 244f6e6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 41 deletions.
43 changes: 28 additions & 15 deletions game/static/game/js/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,28 +1039,31 @@ ocargo.Drawing.startPopup = function (
title,
subtitle,
message,
mascot,
showMascot,
buttons
) {
$('#myModal-title').html(title)
$('#myModal-lead').html(subtitle)
$('#myModal-mainText').html(message)

$('#modal-mascot').hide()
$('#modal-mascot--brain').hide()
const mascot = $('#modal-mascot')
const brain = $('#modal-mascot--brain')

if (mascot) {
mascot.hide()
brain.hide()

if (showMascot) {
if (EPISODE === 9) {
$('#modal-mascot--brain').show()
brain.show()
}
else {
$('#modal-mascot').show()
mascot.show()
}
}

const youtubeVideo = $("iframe")
if (youtubeVideo[0]) {
$("#modal-mascot").hide()
mascot.hide()
}

// create a wrapper for the buttons that will be appended
Expand All @@ -1084,7 +1087,7 @@ ocargo.Drawing.startPopup = function (

const regexID = /id=\"*\w+_\w+\"/

// Close the video on pressing the top right close button
// Close the video on pressing the top right close button
$("#close-modal").click(function () {
stopVideo();
});
Expand All @@ -1097,7 +1100,7 @@ ocargo.Drawing.startPopup = function (
let classToBeAdded = currentID === "play_button" ? "navigation_button_portal long_button rapid-router-welcome" : "navigation_button_portal_secondary long_button rapid-router-welcome button--icon"

currentButton.removeClass().addClass(classToBeAdded)
if (currentID != "play_button") {
if (currentID !== "play_button") {
// adding links to buttons
currentButton.append(icons[i])
let currentLink = links[i] === "" ? "" : `window.location.replace('${links[i]}')`
Expand Down Expand Up @@ -1128,6 +1131,14 @@ ocargo.Drawing.startPopup = function (
editButton.removeClass().addClass("navigation_button_portal long_button rapid-router-welcome")
buttonDiv.append(editButton)

let yesButton = $("#yes_button")
yesButton.removeClass().addClass("navigation_button_portal long_button rapid-router-welcome")
buttonDiv.append(yesButton)

let noButton = $("#no_button")
noButton.removeClass().addClass("navigation_button_portal long_button rapid-router-welcome")
buttonDiv.append(noButton)

let nextLevelButton = $("#next_level_button")
nextLevelButton.removeClass().addClass("navigation_button_portal_secondary long_button rapid-router-welcome button--icon")
nextLevelButton.append(icons[2])
Expand Down Expand Up @@ -1166,13 +1177,15 @@ ocargo.Drawing.startYesNoPopup = function (
message,
yesFunction,
noFunction,
mascot
showMascot
) {
let buttonHtml =
'<button id="modal-yesBtn" class="navigation_button long_button">Yes</button> <button id="modal-noBtn" class="navigation_button long_button">No</button>'
ocargo.Drawing.startPopup(title, subtitle, message, mascot, buttonHtml)
$('#modal-yesBtn').click(yesFunction)
$('#modal-noBtn').click(noFunction)
let buttons = '';
buttons += ocargo.button.dismissButtonHtml("yes_button", "Yes");
buttons += ocargo.button.dismissButtonHtml("no_button", "No");

ocargo.Drawing.startPopup(title, subtitle, message, showMascot, buttons)
$('#yes_button').click(yesFunction)
$('#no_button').click(noFunction)
}

// This is the function that starts the pop-up when there is no internet connection while playing the game
Expand Down
66 changes: 40 additions & 26 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,17 +630,27 @@ ocargo.LevelEditor = function(levelId) {
return;
}

var newName = $('#levelNameInput').val();
const nameInput = $('#levelNameInput')
const newName = nameInput.val();
if (!newName || newName === "") {
// TODO error message?
ocargo.Drawing.startPopup(
"Oh no!",
"No level title!",
"Sorry, you need to specify a title for your" +
" level to be saved.",
);
return;
}

var regex = /^(\w?[ ]?)*$/;
var validString = regex.exec($('#levelNameInput').val());
const regex = /^(\w?[ ]?)*$/;
const validString = regex.exec(nameInput.val());
if (!validString) {
ocargo.Drawing.startPopup(gettext('Oh no!'), gettext('You used some invalid characters.'),
gettext('Try saving your level again using only letters and numbers.'));
ocargo.Drawing.startPopup(
"Oh no!",
"You used some invalid characters.",
"Try saving your level again using only" +
" letters and numbers."
);
return;
}

Expand All @@ -649,33 +659,37 @@ ocargo.LevelEditor = function(levelId) {
}

// Test to see if we already have the level saved
var table = $("#saveLevelTable");
var existingId = -1;
const table = $("#saveLevelTable");
let existingId = -1;

for (var i = 0; i < table[0].rows.length; i++) {
var row = table[0].rows[i];
var existingName = row.cells[0].innerHTML;
for (let i = 0; i < table[0].rows.length; i++) {
const row = table[0].rows[i];
const existingName = row.cells[0].innerHTML;
if (existingName === newName) {
existingId = row.getAttribute('value');
break;
}
}

if (existingId != -1) {
if (existingId !== -1) {
if (!saveState.isCurrentLevel(existingId)) {
var onYes = function(){
const onYes = function(){
saveLevelLocal(existingId);
$("#myModal").hide()
$("#ocargo-modal").hide()
};
var onNo = function(){
const onNo = function(){
$("#myModal").hide()
$("#ocargo-modal").hide()
};
ocargo.Drawing.startYesNoPopup(gettext('Overwriting'), gettext('Warning'),
interpolate(gettext('Level %(level_name)s already exists. Are you sure you want to overwrite it?'), {
level_name: newName
}, true), onYes, onNo);
ocargo.Drawing.startYesNoPopup(
"Overwriting",
"Warning",
`Level ${newName} already exists. Are
you sure you want to overwrite it?`,
onYes,
onNo
);
} else {
saveLevelLocal(existingId);
}
Expand Down Expand Up @@ -1327,7 +1341,7 @@ ocargo.LevelEditor = function(levelId) {
nodes[0] = temp;
originNode = nodes[0];
} else if (mode === modes.ADD_HOUSE_MODE && existingNode) {
// Check if same as starting node
// Check if same as starting node
if (isOriginCoordinate(coordMap)) {
originNode = null;
}
Expand Down Expand Up @@ -1373,11 +1387,11 @@ ocargo.LevelEditor = function(levelId) {
mark(coordMap, 'blue', 0.3, true);
} else if (mode === modes.MARK_ORIGIN_MODE && canPlaceCFC(node)) {
mark(coordMap, 'red', 0.5, true);
}
}
} else if (node && houseNodes.includes(node) && mode === modes.DELETE_HOUSE_MODE) {
mark(coordMap, 'blue', 0.3, true);
}
}
}
};
}

Expand Down Expand Up @@ -1454,11 +1468,11 @@ ocargo.LevelEditor = function(levelId) {
}
};
}

function draggedObjectOnGrid(e, dragged_object) {
// object location is relative to the whole page, so need to factor in paper and padding size, grid canvas scroll amount, width of toolbar, etc.
return e.pageX >= (TAB_PANE_WIDTH + PAPER_PADDING)
&& (e.pageY + paper.scrollTop() + dragged_object.height / 2) <= (PAPER_HEIGHT + PAPER_PADDING)
return e.pageX >= (TAB_PANE_WIDTH + PAPER_PADDING)
&& (e.pageY + paper.scrollTop() + dragged_object.height / 2) <= (PAPER_HEIGHT + PAPER_PADDING)
&& (e.pageX + paper.scrollLeft() + dragged_object.width / 2) <= (TAB_PANE_WIDTH + PAPER_WIDTH + PAPER_PADDING)
}

Expand Down Expand Up @@ -1706,7 +1720,7 @@ ocargo.LevelEditor = function(levelId) {
}

image.transform('t' + cowX + ',' + cowY);
}
}
adjustCowGroupMinMaxFields(cow);

image.attr({'cursor':'pointer'});
Expand Down Expand Up @@ -3065,7 +3079,7 @@ $(function() {
} else {
let buttons = '';
buttons += ocargo.button.dismissButtonHtml("edit_button", "Edit");
buttons += ocargo.button.redirectButtonHtml("play_button", Urls.levels() + "custom/" + LEVEL,"Play");
buttons += ocargo.button.redirectButtonHtml("play_button", Urls.levels() + "custom/" + LEVEL, "Play");

ocargo.Drawing.startPopup(
gettext('Welcome back!'),
Expand Down

0 comments on commit 244f6e6

Please sign in to comment.