Skip to content

Commit

Permalink
Merge pull request #183 from redweller/fix/new-ui-bugs
Browse files Browse the repository at this point in the history
Fix page toolbar bug
  • Loading branch information
TheGiddyLimit authored Jan 18, 2024
2 parents 6c673b6 + f7eae1f commit 5684c21
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 62 deletions.
115 changes: 56 additions & 59 deletions js/base-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ function d20plusEngine () {
};

d20plus.engine.swapTemplates = () => {
const oldToolbar = document.getElementById("floatingtoolbar");
d20plus.isOptedInNewUI = !oldToolbar;
const $betaSwitch = $("#new-toolbar-toggle");
d20plus.betaFeaturesEnabled = $betaSwitch.prop("checked");

d20plus.ut.log("Swapping templates...");
$("#tmpl_charactereditor").html($(d20plus.html.characterEditor).html());
Expand Down Expand Up @@ -199,7 +199,8 @@ function d20plusEngine () {
}).addTouch();
}

if (!d20plus.isOptedInNewUI) {
if (!d20plus.betaFeaturesEnabled) { // Jan 2024 beta features include the new Page Toolbar
// this should be executed only for the old Page Toolbar
overwriteDraggables();
$(`#page-toolbar`).css("top", "calc(-90vh + 40px)");

Expand All @@ -217,7 +218,7 @@ function d20plusEngine () {
debouncedOverwrite();
}
} else {
$(`#page-toolbar`).hide();
$(`#page-toolbar`).hide(); // hide the old Page Toolbar that pops with b20 styling
}

$(`body`).on("mouseup", "li.dl", (evt) => {
Expand All @@ -243,7 +244,7 @@ function d20plusEngine () {
}).on("click", ".pagedetails_navigation .nav-tabs--beta", () => {
d20plus.engine._populatePageCustomOptions();
}).on("click keyup", ".weather input, .weather .slider", () => {
d20plus.engine._updateCustomOptions();
d20plus.engine._updatePageCustomOptions();
});
};

Expand Down Expand Up @@ -333,17 +334,17 @@ function d20plusEngine () {
$overlay.remove();
}
$saveBtn.before(templateApply);
$(`.btn-apply`).on("click", d20plus.engine.applySettings);
$(`.btn-apply`).on("click", d20plus.engine.applyPageSettings);
}
// process options within open dialog
if ($dialog[0]) {
const $pageTitle = $dialog.find(`.ui-dialog-title:visible`);
d20plus.engine._preserveCustomOptions(page);
d20plus.engine._populateCustomOptions(page, $dialog.find(`.dialog .tab-content`));
d20plus.engine._preservePageCustomOptions(page);
d20plus.engine._populatePageCustomOptions(page, $dialog.find(`.dialog .tab-content`));
if ($pageTitle[0] && !$(".ui-dialog-pagename:visible")[0]) {
$pageTitle.after(`<span class="ui-dialog-pagename">${page.get("name")}</span>`);
$saveBtn.off("click");
$saveBtn.on("click", d20plus.engine.applySettings);
$saveBtn.on("click", d20plus.engine.applyPageSettings);
// closed editors behave strangely, so replace Close with Cancel
$dialog.find(`.ui-dialog-titlebar-close:visible`).on("mousedown", () => {
$dialog.find(`.ui-dialog-buttonpane .btn:not(.btn-apply):not(.btn-primary)`).click();
Expand All @@ -362,7 +363,7 @@ function d20plusEngine () {
}
}

d20plus.engine.applySettings = (evt) => {
d20plus.engine.applyPageSettings = (evt) => {
evt.stopPropagation();
evt.preventDefault();
const page = d20.Campaign.pages.get(d20plus.engine._lastSettingsPageId);
Expand All @@ -375,8 +376,8 @@ function d20plusEngine () {
const activeTabScroll = $dialog.find(`.ui-dialog-content`).scrollTop();
const $settings = $dialog.find(`.dialog .tab-content`);

d20plus.engine._saveCustomOptions(page);
d20plus.engine._saveNativeOptions(page, $settings);
d20plus.engine._savePageCustomOptions(page);
d20plus.engine._savePageNativeOptions(page, $settings);

page.save();

Expand All @@ -387,7 +388,7 @@ function d20plusEngine () {
// page.save resets current dialog, so we need to restore status quo
$(`.nav-tabs:visible [data-tab=${activeTab}]`).click();
$(`.ui-dialog-content:visible`).scrollTop(activeTabScroll);
d20plus.engine._populateCustomOptions();
d20plus.engine._populatePageCustomOptions();
}
}

Expand Down Expand Up @@ -427,7 +428,7 @@ function d20plusEngine () {
lightglobalillum: {class: ".lightglobalillum"},
};

d20plus.engine._saveNativeOptions = (page, dialog) => {
d20plus.engine._savePageNativeOptions = (page, dialog) => {
if (!page || !page.get) return;
const getSlider = (el) => {
if (el.style.left?.search("%") > 0) return el.style.left.slice(0, -1) / 100;
Expand All @@ -452,23 +453,23 @@ function d20plusEngine () {
});
}

d20plus.engine._preserveCustomOptions = (page) => {
d20plus.engine._preservePageCustomOptions = (page) => {
if (!page || !page.get) return;
d20plus.engine._customOptions = d20plus.engine._customOptions || {};
d20plus.engine._customOptions[page.id] = { _defaults: {} };
d20plus.engine._customPageOptions = d20plus.engine._customPageOptions || {};
d20plus.engine._customPageOptions[page.id] = { _defaults: {} };
[
"weather",
].forEach(category => Object.entries(d20plus[category].props).forEach(([name, deflt]) => {
d20plus.engine._customOptions[page.id][name] = page.get(`bR20cfg_${name}`) || deflt;
d20plus.engine._customOptions[page.id]._defaults[name] = deflt;
d20plus.engine._customPageOptions[page.id][name] = page.get(`bR20cfg_${name}`) || deflt;
d20plus.engine._customPageOptions[page.id]._defaults[name] = deflt;
}));
}

d20plus.engine._populatePageCustomOptions = (page, dialog) => {
dialog = dialog || $(`.pagedetails_navigation:visible`).closest(".ui-dialog");
page = page || d20.Campaign.pages.get(d20plus.engine._lastSettingsPageId);
if (!d20plus.engine._customOptions[page.id]) return;
Object.entries(d20plus.engine._customOptions[page.id]).forEach(([name, val]) => {
if (!d20plus.engine._customPageOptions[page.id]) return;
Object.entries(d20plus.engine._customPageOptions[page.id]).forEach(([name, val]) => {
dialog.find(`[name="${name}"]`).each((i, e) => {
const $e = $(e);
if ($e.is(":checkbox")) {
Expand All @@ -482,24 +483,24 @@ function d20plusEngine () {
});
});
// ensure all Select elements will update options on change
$(".weather select").each((a, b) => { b.onchange = () => d20plus.engine._updateCustomOptions() });
$(".weather select").each((a, b) => { b.onchange = () => d20plus.engine._updatePageCustomOptions() });
}

d20plus.engine._updateCustomOptions = (page, dialog) => {
d20plus.engine._updatePageCustomOptions = (page, dialog) => {
dialog = dialog || $(`.pagedetails_navigation:visible`).closest(".ui-dialog");
page = page || d20.Campaign.pages.get(d20plus.engine._lastSettingsPageId);
if (!d20plus.engine._customOptions[page.id]) return;
Object.entries(d20plus.engine._customOptions[page.id]).forEach(([name, val]) => {
if (!d20plus.engine._customPageOptions[page.id]) return;
Object.entries(d20plus.engine._customPageOptions[page.id]).forEach(([name, val]) => {
dialog.find(`[name="${name}"]`).each((i, e) => {
const $e = $(e);
const val = $e.is(":checkbox") ? !!$e.prop("checked") : $e.val();
d20plus.engine._customOptions[page.id][name] = val;
d20plus.engine._customPageOptions[page.id][name] = val;
});
});
}

d20plus.engine._saveCustomOptions = (page) => {
const values = d20plus.engine._customOptions[page.id];
d20plus.engine._savePageCustomOptions = (page) => {
const values = d20plus.engine._customPageOptions[page.id];
Object.entries(values).forEach(([name, val]) => {
if (name === "_defaults") return;
if (val && val !== values._defaults[name]) {
Expand Down Expand Up @@ -693,43 +694,39 @@ function d20plusEngine () {
/* eslint-disable */

// BEGIN ROLL20 CODE
window.Markdown.parse = function(e) {
{
var t = e
, n = []
, i = [];
-1 != t.indexOf("\r\n") ? "\r\n" : -1 != t.indexOf("\n") ? "\n" : ""
}
return t = t.replace(/{{{([\s\S]*?)}}}/g, function(e) {
return n.push(e.substring(3, e.length - 3)),
"{{{}}}"
window.Markdown.parse = function(x) {
var g = x, l, t = [], m = [], v = g.indexOf(`\r\n`) != -1 ? `\r\n` : g.indexOf(`\n`) != -1 ? `\n` : "";
return g = g.replace(/{{{([\s\S]*?)}}}/g, function(h) {
return t.push(h.substring(3, h.length - 3)),
"{{{}}}"
}),
t = t.replace(new RegExp("<pre>([\\s\\S]*?)</pre>","gi"), function(e) {
return i.push(e.substring(5, e.length - 6)),
"<pre></pre>"
}),
// BEGIN MOD
t = t.replace(/~~(.*?)~~/g, OUT_STRIKE),
// END MOD
t = t.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>"),
t = t.replace(/\*(.*?)\*/g, "<em>$1</em>"),
t = t.replace(/``(.*?)``/g, "<code>$1</code>"),
t = t.replace(/\[([^\]]+)\]\(([^)]+(\.png|\.gif|\.jpg|\.jpeg))\)/g, '<a href="$2"><img src="$2" alt="$1" /></a>'),
t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>'),
t = t.replace(new RegExp("<pre></pre>","g"), function() {
return "<pre>" + i.shift() + "</pre>"
}),
t = t.replace(/{{{}}}/g, function() {
return n.shift()
})
};
g = g.replace(new RegExp("<pre>([\\s\\S]*?)</pre>","gi"), function(h) {
return m.push(h.substring(5, h.length - 6)),
"<pre></pre>"
}),
// BEGIN MOD
g = g.replace(/~~(.*?)~~/g, OUT_STRIKE),
// END MOD
g = g.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>"),
g = g.replace(/\*(.*?)\*/g, "<em>$1</em>"),
g = g.replace(/``(.*?)``/g, "<code>$1</code>"),
g = g.replace(/\[([^\]]+)\]\(([^)]+(\.png|\.gif|\.jpg|\.jpeg))\)/g, '<a href="$2"><img src="$2" alt="$1" /></a>'),
g = g.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>'),
g = g.replace(new RegExp("<pre></pre>","g"), function(h) {
return "<pre>" + m.shift() + "</pre>"
}),
g = g.replace(/{{{}}}/g, function(h) {
return t.shift()
}),
g
},
// END ROLL20 CODE

/* eslint-enable */

// after a short delay, replace any old content in the chat
setTimeout(() => {
$(`.message`).each(function () {
$(`.message.general`).each(function () {
$(this).html($(this).html().replace(/~~(.*?)~~/g, OUT_STRIKE))
})
}, 2500);
Expand Down Expand Up @@ -846,7 +843,7 @@ function d20plusEngine () {
};

d20plus.engine.fixPolygonTool = () => {
if (d20plus.isOptedInNewUI) return;
if (!d20plus.newUIDisabled) return; // as of January 2024 newUI is always ON, so the below block is not needed
$("#editor-wrapper").on("pointerdown", x => { d20plus.engine.leftClicked = x.which === 1 });
$("#editor-wrapper").on("pointerup", x => { d20plus.engine.leftClicked = false });
d20plus.ut.injectCode(d20.engine, "finishCurrentPolygon", (finishDrawing, params) => {
Expand Down
7 changes: 4 additions & 3 deletions js/base-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ function baseUtil () {
} else {
d20plus.ut.showHardDickMessage(scriptName);
}
d20plus.isOptedInNewUI && !isStreamer && d20plus.ut.sendHackerChat(`
betteR20 does not support the new UI preview at this moment!
Using it will make some betteR20 functionality unavailable.
d20plus.betaFeaturesEnabled && !isStreamer && d20plus.ut.sendHackerChat(`
betteR20 does not support the beta UI preview at this moment!
Using it will make some betteR20 or roll20 functionality unavailable.
If you experience problems with Page Settings, disable roll20 Beta Features.
`);
$boringProgress
.before(`<span><span>&gt;</span>all systems operational</span>`)
Expand Down

0 comments on commit 5684c21

Please sign in to comment.