From 0b074e34ff14bd64a6d45d0c69cea3a86dc794d4 Mon Sep 17 00:00:00 2001 From: pregmodfan <pregmodfan@cock.li> Date: Sat, 17 Jun 2017 01:50:39 +0300 Subject: [PATCH] rbutton alternative macro and initial tests on RA screen --- src/js/rbuttonJS.tw | 66 +++++++++++++++++++++++++++++ src/uncategorized/rulesAssistant.tw | 43 +++++++++++++++++++ src/utility/raWidgets.tw | 5 +++ 3 files changed, 114 insertions(+) create mode 100644 src/js/rbuttonJS.tw diff --git a/src/js/rbuttonJS.tw b/src/js/rbuttonJS.tw new file mode 100644 index 00000000000..922857ef4f7 --- /dev/null +++ b/src/js/rbuttonJS.tw @@ -0,0 +1,66 @@ +:: rbuttonJS [script] +/* This is modifed radiobutton macro, for automatic checked state setup*/ + +Macro.add('rbutton', { + handler() { + if (this.args.length < 2) { + const errors = []; + if (this.args.length < 1) { errors.push('variable name'); } + if (this.args.length < 2) { errors.push('checked value'); } + return this.error(`no ${errors.join(' or ')} specified`); + } + + // Ensure that the variable name argument is a string. + if (typeof this.args[0] !== 'string') { + return this.error('variable name argument is not a string'); + } + + const varName = this.args[0].trim(); + + // Try to ensure that we receive the variable's name (incl. sigil), not its value. + if (varName[0] !== '$' && varName[0] !== '_') { + return this.error(`variable name "${this.args[0]}" is missing its sigil ($ or _)`); + } + + const varId = Util.slugify(varName); + const checkValue = this.args[1]; + const el = document.createElement('input'); + + /* + Setup and initialize the group counter. + */ + if (!TempState.hasOwnProperty(this.name)) { + TempState[this.name] = {}; + } + + if (!TempState[this.name].hasOwnProperty(varId)) { + TempState[this.name][varId] = 0; + } + + /* + Setup and append the input element to the output buffer. + */ + jQuery(el) + .attr({ + id : `${this.name}-${varId}-${TempState[this.name][varId]++}`, + name : `${this.name}-${varId}`, + type : 'radio', + tabindex : 0 // for accessiblity + }) + .addClass(`macro-${this.name}`) + .on('change', function () { + if (this.checked) { + Wikifier.setValue(varName, checkValue); + } + }) + .appendTo(this.output); + + /* + Set the story variable to the checked value and the input element to checked, if requested. + */ + if (this.args.length > 2 && this.args[2] == checkValue) { + el.checked = true; + Wikifier.setValue(varName, checkValue); + } + } + }); diff --git a/src/uncategorized/rulesAssistant.tw b/src/uncategorized/rulesAssistant.tw index 378a687b2e4..5b69c9b5978 100644 --- a/src/uncategorized/rulesAssistant.tw +++ b/src/uncategorized/rulesAssistant.tw @@ -1380,6 +1380,8 @@ Growth hormones for healthy slaves: ''as large as will allow a normal life.'' <<elseif $currentRule.growth == "unlimited">> ''no limits.'' +<<elseif $currentRule.growth == "advSelect">> + ''advanced selection of individual body parts.'' <<else>> ''no default setting.'' <</if>> @@ -1420,6 +1422,16 @@ Growth hormones for healthy slaves: <<RAChangeApply>> <</link>> | +<<link "Advanced Selection">> + <<set $currentRule.growth = "advSelect">> + <<RAChangeGrowth>> + <<RAChangeSave>> + <<RAChangeApply>> + <<script>> + document.getElementById("bodySize").style.display = "inline"; + <</script>> +<</link>> +| <<link "None">> <<set $currentRule.growth = "none">> <<RAChangeGrowth>> @@ -1427,8 +1439,39 @@ Growth hormones for healthy slaves: <<RAChangeApply>> <</link>> +<br> +<div id = "bodySize" style = "display:none"> +Please select desired body parts sizes (growth only) <br> +Breasts: +No growth <<rbutton "$currentRule.breastSize" "none" $currentRule.breastSize>> | +Girlish <<rbutton "$currentRule.breastSize" "small" $currentRule.breastSize>> | +Stacked <<rbutton "$currentRule.breastSize" "big" $currentRule.breastSize>> | +Huge <<rbutton "$currentRule.breastSize" "huge" $currentRule.breastSize>> <br> +Butt: +No growth <<rbutton "$currentRule.buttSize" "none" $currentRule.buttSize>> | +Girlish <<rbutton "$currentRule.buttSize" "small" $currentRule.buttSize>> | +Stacked <<rbutton "$currentRule.buttSize" "big" $currentRule.buttSize>> | +Huge <<rbutton "$currentRule.buttSize" "huge" $currentRule.buttSize>> +<br> +/* +Lips: +No growth <<if $currentRule.breastSize == "none">><<radiobutton "$currentRule.breastSize" "none" checked>><<else>><<radiobutton "$currentRule.breastSize" "none">><</if>> | +Girlish <<if $currentRule.breastSize == "small">><<radiobutton "$currentRule.breastSize" "small" checked>><<else>><<radiobutton "$currentRule.breastSize" "small">><</if>> | +Stacked <<if $currentRule.breastSize == "big">><<radiobutton "$currentRule.breastSize" "big" checked>><<else>><<radiobutton "$currentRule.breastSize" "big">><</if>> | +Huge <<if $currentRule.breastSize == "huge">><<radiobutton "$currentRule.breastSize" "huge" checked>><<else>><<radiobutton "$currentRule.breastSize" "huge">><</if>> +<br> +*/ + +</div> +<<timed 40ms>> + <<if $currentRule.growth == "advSelect">> + <<script>> + document.getElementById("bodySize").style.display = "inline"; + <</script>> + <</if>> +<</timed>> Health drugs: <span id = "curatives"> diff --git a/src/utility/raWidgets.tw b/src/utility/raWidgets.tw index 52a603f78c5..527feed0966 100644 --- a/src/utility/raWidgets.tw +++ b/src/utility/raWidgets.tw @@ -2021,12 +2021,17 @@ Growth hormones for healthy slaves: ''as large as will allow a normal life.'' <<elseif $currentRule.growth == "unlimited">> ''no limits.'' +<<elseif $currentRule.growth == "advSelect">> + ''advanced selection of individual body parts.'' <<elseif $currentRule.growth == "none">> ''none.'' <<else>> ''no default setting.'' <</if>> <</replace>> +<<script>> + document.getElementById("bodySize").style.display = "none"; +<</script>> <</widget>> /% -- GitLab