Skip to content

Commit

Permalink
By default, don't allow multiple saves in the same drawing session
Browse files Browse the repository at this point in the history
Update UI to offer "post oekaki" option instead of "save oekaki" in that situation.
  • Loading branch information
thenickdude committed Oct 24, 2017
1 parent c4329a1 commit 5d5ba5e
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 13 deletions.
19 changes: 18 additions & 1 deletion js/ChickenPaint.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ function createDrawingTools() {
* loadImageUrl - URL of PNG/JPEG image to load for editing (optional)
* loadChibiFileUrl - URL of .chi file to load for editing (optional). Used in preference to loadImage.
* loadSwatchesUrl - URL of an .aco palette to load (optional)
*
*
* allowMultipleSends - Allow the drawing to be sent to the server multiple times (saving does not immediately end drawing session).
* allowDownload - Allow the drawing to be saved to the user's computer
* allowFullScreen - Allow the drawing tool to enter "full screen" mode, where the rest of the page contents will be hidden
*
Expand Down Expand Up @@ -674,6 +675,13 @@ export default function ChickenPaint(options) {
},
modifies: {document: true}
},
CPContinue: {
action: function() {
},
isSupported: function() {
return !!options.allowMultipleSends;
}
},
CPExit: {
action: function () {
// Exit the drawing session without posting the drawing to the forum
Expand Down Expand Up @@ -867,6 +875,10 @@ export default function ChickenPaint(options) {
}

function sendDrawing() {
if (!that.isActionSupported("CPContinue") && !confirm('Are you sure you want to send your drawing to the server and finish drawing now?')) {
return;
}

var
saver = new CPResourceSaver({
artwork: that.getArtwork(),
Expand All @@ -878,6 +890,11 @@ export default function ChickenPaint(options) {

saver.on("savingComplete", function() {
that.artwork.setHasUnsavedChanges(false);

// If we're not allowed to keep editing, we can only go straight to viewing the new post
if (!that.isActionSupported("CPContinue") && that.isActionSupported("CPPost")) {
that.actionPerformed({action: "CPPost"});
}
});

// Allow the dialog to show before we begin serialization
Expand Down
6 changes: 6 additions & 0 deletions js/gui/CPMainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ export default function CPMainMenu(controller, mainGUI) {
if (entry.action && !controller.isActionSupported(entry.action)) {
return;
}

if (entry.action == "CPSend" && !controller.isActionSupported("CPContinue")) {
// User won't be able to come back after saving, so make it sound more final
entry.name = "Post Oekaki";
entry.shortcut = "ctrl+p";
}

if (entry.children) {
entryElem = $(
Expand Down
5 changes: 5 additions & 0 deletions js/gui/CPMiscPalette.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export default function CPMiscPalette(cpController) {
button = buttons[i],
buttonElem = document.createElement("li");

if (button.command == 'CPSend' && !cpController.isActionSupported("CPContinue")) {
button.toolTip = "Send picture to server";
button.className = "chickenpaint-tool-send-and-end";
}

buttonElem.className = "chickenpaint-toolbar-button " + button.className;
buttonElem.setAttribute("data-buttonIndex", i);

Expand Down
41 changes: 29 additions & 12 deletions js/gui/CPSendDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function CPSendDialog(controller, parent, resourceSaver) {
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary chickenpaint-post-drawing" data-dismiss="modal">Yes, post it now</button>
<button type="button" class="btn btn-default" data-dismiss="modal">No, keep drawing</button>
<button type="button" class="btn btn-default chickenpaint-continue-drawing" data-dismiss="modal">No, keep drawing</button>
<button type="button" class="btn btn-default chickenpaint-exit" data-dismiss="modal">No, quit and I'll finish it later</button>
</div>
</div>
Expand All @@ -72,7 +72,18 @@ export default function CPSendDialog(controller, parent, resourceSaver) {
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary chickenpaint-post-drawing" data-dismiss="modal">Yes, view the post</button>
<button type="button" class="btn btn-default" data-dismiss="modal">No, keep drawing</button>
<button type="button" class="btn btn-default chickenpaint-continue-drawing" data-dismiss="modal">No, keep drawing</button>
</div>
</div>
<div class="modal-content" data-stage="success-redirect" style="display:none">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Drawing saved!</h4>
</div>
<div class="modal-body">
<p>Your drawing has been saved, redirecting you to view your new post now...</p>
</div>
</div>
</div>
Expand All @@ -94,13 +105,17 @@ export default function CPSendDialog(controller, parent, resourceSaver) {
.css("width", progress + "%");
});

resourceSaver.on("savingComplete", function(progress) {
resourceSaver.on("savingComplete", function() {
$(".modal-content[data-stage='saving']", dialog).hide();

if (controller.isActionSupported("CPExit")) {
$(".modal-content[data-stage='success-not-previously-posted']", dialog).show();

if (controller.isActionSupported("CPContinue")) {
if (controller.isActionSupported("CPExit")) {
$(".modal-content[data-stage='success-not-previously-posted']", dialog).show();
} else {
$(".modal-content[data-stage='success-already-posted']", dialog).show();
}
} else {
$(".modal-content[data-stage='success-already-posted']", dialog).show();
$(".modal-content[data-stage='success-redirect']", dialog).show();
}
});

Expand Down Expand Up @@ -130,11 +145,13 @@ export default function CPSendDialog(controller, parent, resourceSaver) {
controller.actionPerformed({action: "CPPost"});
});

$(".chickenpaint-exit", dialog).click(function() {
alert("When you want to come back and finish your drawing, just click the 'new drawing' button again and "
+ "you can choose to continue this drawing.");
controller.actionPerformed({action: "CPExit"});
});
$(".chickenpaint-exit", dialog)
.toggle(controller.isActionSupported("CPExit"))
.click(function() {
alert("When you want to come back and finish your drawing, just click the 'new drawing' button again and "
+ "you can choose to continue this drawing.");
controller.actionPerformed({action: "CPExit"});
});

$(".chickenpaint-send-cancel", dialog).click(function() {
resourceSaver.cancel();
Expand Down
3 changes: 3 additions & 0 deletions resources/css/chickenpaint.css
Original file line number Diff line number Diff line change
Expand Up @@ -9205,6 +9205,9 @@ body.chickenpaint-full-screen {
.chickenpaint-tool-send {
background-position: 0 -384px;
}
.chickenpaint-tool-send-and-end {
background-position: 0 -992px;
}
.chickenpaint-tool-freehand {
background-position: 0 -608px;
}
Expand Down
3 changes: 3 additions & 0 deletions resources/css/chickenpaint.less
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ body.chickenpaint-full-screen {
.chickenpaint-tool-send {
background-position:0 -384px;
}
.chickenpaint-tool-send-and-end {
background-position:0 -992px;
}

.chickenpaint-tool-freehand {
background-position:0 -608px;
Expand Down
Binary file modified resources/gfx/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/gfx/icons.psd
Binary file not shown.
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $(document).ready(function() {
postUrl: "posting.php",
exitUrl: "forum.php",
allowSave: true,
allowMultipleSends: true,
resourcesRoot: "../resources/"
});
});

0 comments on commit 5d5ba5e

Please sign in to comment.