Skip to content

Commit

Permalink
feat: opening crawl improvements
Browse files Browse the repository at this point in the history
* add font size option
* move opening crawl inputs to a dedicated window

#24
  • Loading branch information
Wrycu committed May 27, 2021
1 parent 2e391ac commit 4edea77
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 8 deletions.
5 changes: 5 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-image-right-hint": "Percentage of the screen to move the image to the left by",
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-image-bottom": "Image offset (from the bottom)",
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-image-bottom-right": "Number of pixels to move the image up by",
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-font-size": "Intro crawl font size",
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-font-size-hint": "Percent font size",
"ffg-star-wars-enhancements.opening-crawl.ui.name": "Opening Crawl settings",
"ffg-star-wars-enhancements.opening-crawl.ui.hint": "Configure opening crawl",
"ffg-star-wars-enhancements.opening-crawl.ui.label": "Open Configuration",
"ffg-star-wars-enhancements.datapads.datapad-template": "Datapad Template",
"ffg-star-wars-enhancements.datapads.datapad": "Datapad",
"ffg-star-wars-enhancements.datapads.bounty": "Bounty",
Expand Down
157 changes: 151 additions & 6 deletions scripts/opening_crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,70 @@ import { log_msg as log } from './util.js'
*/
export function init() {
log('opening-crawl', 'Initializing');
game.settings.registerMenu("ffg-star-wars-enhancements", "opening-crawl_UISettings", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.ui.name'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.ui.hint'),
label: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.ui.label'),
icon: "fas fa-cut",
type: opening_crawl_UISettings,
restricted: true,
});
game.settings.register("ffg-star-wars-enhancements", "opening-crawl-folder", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-folder'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-folder-hint'),
scope: "world",
config: true,
config: false,
type: String,
default: "Opening Crawls",
});
game.settings.register("ffg-star-wars-enhancements", "opening-crawl-music", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-music'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-music-hint'),
scope: "world",
config: true,
config: false,
type: setting_audio,
default: "",
});
game.settings.register("ffg-star-wars-enhancements", "opening-crawl-logo", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-logo'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-logo-hint'),
scope: "world",
config: true,
config: false,
type: setting_image,
default: "",
});
game.settings.register("ffg-star-wars-enhancements", "opening-crawl-music-delay", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-music-delay'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-music-delay-hint'),
scope: "world",
config: true,
config: false,
type: Number,
default: 0.0,
});
game.settings.register("ffg-star-wars-enhancements", "opening-crawl-image-right", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-image-right'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-image-right-hint'),
scope: "world",
config: true,
config: false,
type: Number,
default: 0,
});
game.settings.register("ffg-star-wars-enhancements", "opening-crawl-image-bottom", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-image-bottom'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-image-bottom-hint'),
scope: "world",
config: true,
config: false,
type: Number,
default: 1300,
});
game.settings.register("ffg-star-wars-enhancements", "opening-crawl-font-size", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-font-size'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-font-size-hint'),
scope: "world",
config: false,
type: Number,
default: 850,
});
log('opening-crawl', 'Initialized');
}

Expand Down Expand Up @@ -100,6 +116,7 @@ class OpeningCrawlApplication extends Application {
data.img = {};
data.img.bottom = game.settings.get("ffg-star-wars-enhancements", "opening-crawl-image-bottom");
data.img.right = game.settings.get("ffg-star-wars-enhancements", "opening-crawl-image-right");
data.size = game.settings.get("ffg-star-wars-enhancements", "opening-crawl-font-size");
return data;
}

Expand Down Expand Up @@ -332,3 +349,131 @@ export async function create_opening_crawl() {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

// noinspection DuplicatedCode
class opening_crawl_UISettings extends FormApplication {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
id: "data-importer",
classes: ["starwarsffg", "data-import"],
title: `${game.i18n.localize("SWFFG.UISettingsLabel")}`,
template: "modules/ffg-star-wars-enhancements/templates/settings_opening_crawl.html",
});
}

// noinspection JSDeprecatedSymbols
getData(options) {
const gs = game.settings;
const canConfigure = game.user.can("SETTINGS_MODIFY");

const data = {
system: {title: game.system.data.title, menus: [], settings: []},
};

// Classify all settings
// noinspection JSUnusedLocalSymbols
for (let setting of gs.settings.values()) {
// Exclude settings the user cannot change
if ((!setting.config && !setting.key.includes("opening-crawl-")) || (!canConfigure && setting.scope !== "client")) continue;

// Update setting data
const s = duplicate(setting);
s.name = game.i18n.localize(s.name);
s.hint = game.i18n.localize(s.hint);
s.value = game.settings.get(s.module, s.key);
s.type = setting.type instanceof Function ? setting.type.name : "String";
s.isCheckbox = setting.type === Boolean;
s.isSelect = s.choices !== undefined;
s.isRange = setting.type === Number && s.range;
s.isFilePicker = setting.valueType === "FilePicker";

// Classify setting
const name = s.module;
if (s.key.includes("opening-crawl-")) data.system.settings.push(s);
}

// Return data
return {
user: game.user,
canConfigure: canConfigure,
systemTitle: game.system.data.title,
data: data,
};
}

activateListeners(html) {
super.activateListeners(html);
html.find(".submenu button").click(this._onClickSubmenu.bind(this));
html.find('button[name="reset"]').click(this._onResetDefaults.bind(this));
html.find("button.filepicker").click(this._onFilePicker.bind(this));
}

/**
* Handle activating the button to configure User Role permissions
* @param event {Event} The initial button click event
* @private
*/
_onClickSubmenu(event) {
event.preventDefault();
const menu = game.settings.menus.get(event.currentTarget.dataset.key);
if (!menu) return ui.notifications.error("No submenu found for the provided key");
const app = new menu.type();
return app.render(true);
}

/* -------------------------------------------- */

/**
* Handle button click to reset default settings
* @param event {Event} The initial button click event
* @private
*/
_onResetDefaults(event) {
event.preventDefault();
const button = event.currentTarget;
const form = button.form;
for (let [k, v] of game.settings.settings.entries()) {
if (!v.config) {
let input = form[k];
if (input && input.type === "checkbox") {
input.checked = v.default;
}
else if (input) {
input.value = v.default;
}
}
}
}

/* -------------------------------------------- */

_onFilePicker(event) {
event.preventDefault();

const fp = new FilePicker({
type: "image",
callback: (path) => {
$(event.currentTarget).prev().val(path);
//this._onSubmit(event);
},
top: this.position.top + 40,
left: this.position.left + 10,
});
return fp.browse();
}

/* -------------------------------------------- */

// noinspection JSUnusedGlobalSymbols
/** @override */
async _updateObject(event, formData) {
for (let [k, v] of Object.entries(flattenObject(formData))) {
let s = game.settings.settings.get(k);
let current = game.settings.get(s.module, s.key);
if (v !== current) {
await game.settings.set(s.module, s.key, v);
}
}
}
}
1 change: 0 additions & 1 deletion styles/opening_crawl.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
height: 50em;
text-align: justify;
word-wrap: break-word;
font-size: 350%;
transform-origin: 50% 100%;
transform: perspective(300px) rotateX(25deg);
}
Expand Down
2 changes: 1 addition & 1 deletion templates/opening_crawl.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{/if}}
</div>
</div>
<div class="titles noselect">
<div class="titles noselect" style="font-size: {{size}}%;">
<div>
<p class="episode tcenter">
{{episode}}
Expand Down
64 changes: 64 additions & 0 deletions templates/settings_opening_crawl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{#*inline "settingPartial"}}
<div class="form-group">
<label>
{{#iff this.type '==' 'setting_image'}}
<i class="fas fa-video"></i>
{{/iff}}
{{#iff this.type '==' 'setting_audio'}}
<i class="fas fa-volume-up"></i>
{{/iff}}
&nbsp;{{this.name}}
</label>
<div class="form-fields">
{{#if this.isCheckbox}}
<input data-dtype="Boolean" name="{{this.module}}.{{this.key}}" this.value}} type="checkbox" {{checked/>

{{else if this.isSelect}}
<select name="{{this.module}}.{{this.key}}">
{{#select this.value}} {{#each this.choices as |name k|}}
<option value="{{k}}">{{localize name}}</option>
{{/each}} {{/select}}
</select>

{{else if this.isRange}}
<input data-dtype="Number" max="{{ this.range.max }}" min="{{ this.range.min }}" name="{{this.module}}.{{this.key}}"
step="{{ this.range.step }}" type="range" value="{{ this.value }}"/>
<span class="range-value">{{this.value}}</span>

{{else if this.isFilePicker}}
<input data-dtype="{{this.type}}" name="{{this.module}}.{{this.key}}" type="text" value="{{this.value}}"/>
<button class="filepicker" type="button">...</button>
{{else}}
<input data-dtype="{{this.type}}" name="{{this.module}}.{{this.key}}" type="text" value="{{this.value}}"/>
{{#iff this.type '==' 'setting_image'}}
<button class="file-picker" data-target="{{this.module}}.{{this.key}}" data-type="image" type="button">
<i class="fas fa-file-import"></i>
</button>
{{/iff}}
{{#iff this.type '==' 'setting_audio'}}
<button class="file-picker" data-target="{{this.module}}.{{this.key}}" data-type="audio" type="button">
<i class="fas fa-file-import"></i>
</button>
{{/iff}}
{{/if}}
</div>

<p class="notes">{{this.hint}}</p>
</div>
{{/inline}}

<form autocomplete="off" class="flexcol">
<section class="content" id="config-tabs">
<div class="settings-list">
<h2 class="module-header">{{ localize data.system.title }}</h2>
{{#each data.system.menus}} {{> menuPartial}} {{/each}} {{#each data.system.settings}} {{> settingPartial}}
{{else}}
<p class="notes">{{localize 'SETTINGS.None'}}</p>
{{/each}}
</div>
</section>
<footer class="sheet-footer flexrow">
<button name="submit" type="submit"><i class="far fa-save"></i> {{localize 'SETTINGS.Save'}}</button>
<button name="reset" type="button"><i class="fas fa-undo"></i> {{localize 'SETTINGS.Reset'}}</button>
</footer>
</form>

0 comments on commit 4edea77

Please sign in to comment.