Spaces:
Sleeping
Sleeping
File size: 12,116 Bytes
c390d22 81fff76 c390d22 81fff76 c390d22 81fff76 c390d22 81fff76 c390d22 81fff76 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
import classNames from 'classnames';
import { defineMessages, FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';
import React from 'react';
import Box from '../box/box.jsx';
import Modal from '../../containers/modal.jsx';
import styles from './prompt.css';
import { SCRATCH_MAX_CLOUD_VARIABLES } from '../../lib/tw-cloud-limits.js';
const messages = defineMessages({
forAllSpritesMessage: {
defaultMessage: 'For all sprites',
description: 'Option message when creating a variable for making it available to all sprites',
id: 'gui.gui.variableScopeOptionAllSprites'
},
forThisSpriteMessage: {
defaultMessage: 'For this sprite only',
description: 'Option message when creating a varaible for making it only available to the current sprite',
id: 'gui.gui.variableScopeOptionSpriteOnly'
},
cloudVarOptionMessage: {
defaultMessage: 'Cloud variable (stored on server)',
description: 'Option message when creating a variable for making it a cloud variable, a variable that is stored on the server', /* eslint-disable-line max-len */
id: 'gui.gui.cloudVariableOption'
},
availableToAllSpritesMessage: {
defaultMessage: 'This variable will be available to all sprites.',
description: 'A message that displays in a variable modal when the stage is selected indicating ' +
'that the variable being created will available to all sprites.',
id: 'gui.gui.variablePromptAllSpritesMessage'
},
listAvailableToAllSpritesMessage: {
defaultMessage: 'This list will be available to all sprites.',
description: 'A message that displays in a list modal when the stage is selected indicating ' +
'that the list being created will available to all sprites.',
id: 'gui.gui.listPromptAllSpritesMessage'
}
});
const customButtonStyle = (button) => {
// if class is manually specified, dont try to guess the intended style
if (button.class) {
switch (button.class) {
case "ok":
return styles.okButton;
case "cancel":
return styles.cancelButton;
default:
return styles.cancelButton;
}
}
// assume intended style from role
if (button.role) {
switch (button.role) {
case "ok":
return styles.okButton;
case "close":
return styles.cancelButton;
}
}
return styles.cancelButton;
};
const PromptComponent = props => props.isCustom ? (
<Modal
className={styles.modalContent}
contentLabel={props.title}
id="customModal"
onRequestClose={props.onCancel}
componentRef={props.ref}
boxRef={props.boxRef}
styleContent={props.styleContent}
styleOverlay={props.styleOverlay}
scrollable={props.config.scrollable}
>
<Box className={styles.body}>
<Box componentRef={props.customRef}>
</Box>
{(props.customButtons && props.customButtons.length > 0 ? <Box className={styles.buttonRow}>
{/* slice then reverse to avoid mutating the array. reversing cause scratch modals put OK on the right & usually you define OK button first */}
{props.customButtons.slice().reverse().map(button => (
<button
className={customButtonStyle(button)}
style={button.style}
onClick={() => props.onCustomButton(button)}
>
{button.name}
</button>
))}
</Box> : null)}
</Box>
</Modal>
) : (
<Modal
className={styles.modalContent}
contentLabel={props.title}
id="variableModal"
onRequestClose={props.onCancel}
componentRef={props.componentRef}
boxRef={props.boxRef}
styleContent={props.styleContent}
styleOverlay={props.styleOverlay}
>
<Box className={styles.body}>
<Box className={styles.label}>
{props.label}
</Box>
<Box>
<input
autoFocus
className={styles.variableNameTextInput}
defaultValue={props.defaultValue}
name={props.label}
onChange={props.onChange}
onFocus={props.onFocus}
onKeyPress={props.onKeyPress}
/>
</Box>
{props.showVariableOptions ?
<div>
{props.isStage ?
<div className={styles.infoMessage}>
{props.showListMessage ? (
<FormattedMessage
{...messages.listAvailableToAllSpritesMessage}
/>
) : (
<FormattedMessage
{...messages.availableToAllSpritesMessage}
/>
)}
</div> :
<Box className={styles.optionsRow}>
<label>
<input
checked={props.globalSelected}
name="variableScopeOption"
type="radio"
value="global"
onChange={props.onScopeOptionSelection}
/>
<FormattedMessage
{...messages.forAllSpritesMessage}
/>
</label>
<label
className={classNames({ [styles.disabledLabel]: props.cloudSelected })}
>
<input
checked={!props.globalSelected}
disabled={props.cloudSelected}
name="variableScopeOption"
type="radio"
value="local"
onChange={props.onScopeOptionSelection}
/>
<FormattedMessage
{...messages.forThisSpriteMessage}
/>
</label>
</Box>}
{props.showCloudOption ?
<Box className={classNames(styles.cloudOption)}>
<label
className={classNames({ [styles.disabledLabel]: !props.canAddCloudVariable })}
>
<input
checked={props.cloudSelected && props.canAddCloudVariable}
disabled={!props.canAddCloudVariable}
type="checkbox"
onChange={props.onCloudVarOptionChange}
/>
<FormattedMessage
{...messages.cloudVarOptionMessage}
/>
</label>
</Box> : null}
</div> : null}
{props.cloudSelected && !props.isAddingCloudVariableScratchSafe && (
<Box className={styles.infoMessage}>
<FormattedMessage
// eslint-disable-next-line max-len
defaultMessage="If you make this cloud variable, the project will exceed Scratch's limit of {number} variables, and some variables will not function if you upload the project to Scratch."
// eslint-disable-next-line max-len
description="Warning that appears when adding a new cloud variable will make it exceeded Scratch's cloud variable limit. number will be 10."
id="tw.scratchUnsafeCloud"
values={{
number: SCRATCH_MAX_CLOUD_VARIABLES
}}
/>
</Box>
)}
{props.cloudSelected && props.canAddCloudVariable && (
<Box className={styles.infoMessage}>
<FormattedMessage
/* eslint-disable-next-line max-len */
defaultMessage="Although you can create cloud variables, they won't work until this project is uploaded or until this project is converted using a tool like the {packager}."
description="Reminder that cloud variables may not work when the editor is open"
values={{
packager: (
<a
href="https://studio.penguinmod.com/PenguinMod-Packager"
target="_blank"
rel="noopener noreferrer"
>
{/* Should not be translated */}
{'PenguinMod Packager'}
</a>
)
}}
id="tw.cantUseCloud"
/>
</Box>
)}
<Box className={styles.buttonRow}>
<button
className={styles.cancelButton}
onClick={props.onCancel}
>
<FormattedMessage
defaultMessage="Cancel"
description="Button in prompt for cancelling the dialog"
id="gui.prompt.cancel"
/>
</button>
<button
className={styles.okButton}
onClick={props.onOk}
>
<FormattedMessage
defaultMessage="OK"
description="Button in prompt for confirming the dialog"
id="gui.prompt.ok"
/>
</button>
</Box>
</Box>
</Modal>
);
PromptComponent.propTypes = {
title: PropTypes.string.isRequired,
onCancel: PropTypes.func.isRequired,
onKeyPress: PropTypes.func.isRequired,
onOk: PropTypes.func.isRequired,
isAddingCloudVariableScratchSafe: PropTypes.bool,
canAddCloudVariable: PropTypes.bool,
cloudSelected: PropTypes.bool,
defaultValue: PropTypes.string,
globalSelected: PropTypes.bool,
isStage: PropTypes.bool,
showListMessage: PropTypes.bool,
label: PropTypes.string,
onChange: PropTypes.func,
onCloudVarOptionChange: PropTypes.func,
onFocus: PropTypes.func,
onScopeOptionSelection: PropTypes.func,
showCloudOption: PropTypes.bool,
showVariableOptions: PropTypes.bool,
componentRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({ current: PropTypes.instanceOf(Element) })
]),
boxRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({ current: PropTypes.instanceOf(Element) })
]),
styleContent: PropTypes.object,
styleOverlay: PropTypes.object,
/* custom modals */
isCustom: PropTypes.bool,
config: PropTypes.object,
onCustomButton: PropTypes.func,
customButtons: PropTypes.arrayOf(PropTypes.object),
customRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({ current: PropTypes.instanceOf(Element) })
]),
};
export default PromptComponent; |