ゲームっぽく一文字ずつ文字を表示するメッセージウィンドウ。 メッセージ再生中にクリックで読み飛ばす。
-
-
Save 44uk/71cf02f4893d7d6b0e6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.message-container { | |
width: 80%; | |
position: absolute; | |
bottom: 50px; | |
left: 30px; | |
margin: 26px auto; | |
// margin-bottom: 30px; | |
.text-container { | |
border-radius: 3px; | |
padding: 10px; | |
height: 100px; | |
background-color: white; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ = React.createElement | |
# script: {messages: string[]} | |
# resolve: Function | |
module.exports = React.createClass | |
getInitialState: -> | |
page: 0 | |
visibleCursor: 0 | |
getCurrentText: -> | |
@props.script.messages[@state.page] | |
onVisibleProgress: -> | |
@state.visibleCursor < @getCurrentText().length - 1 | |
componentDidMount: -> | |
@startMessage() | |
componentDidUpdate: -> | |
@startMessage() | |
startMessage: -> | |
text = @getCurrentText() | |
# if @state.visibleCursor | |
currentLineText = @getCurrentText() | |
if @state.visibleCursor is 0 and currentLineText.length > 0 | |
targetPage = @state.page | |
do f = => | |
# @state.visibleCursor++ | |
setTimeout => | |
if @onVisibleProgress() and targetPage is @state.page | |
@setState visibleCursor: @state.visibleCursor + 1 | |
f() | |
, 60 | |
onClickNext: -> | |
if @onVisibleProgress() | |
@setState visibleCursor: @getCurrentText().length - 1 | |
else if @state.page < @props.script.messages.length - 1 | |
@setState | |
page: @state.page + 1 | |
visibleCursor: 0 | |
else | |
@props.resolve() | |
render: -> | |
$ 'div', { | |
className: 'message-container' | |
onClick: @onClickNext | |
}, [ | |
$ 'div', className: 'text-container', [ | |
$ 'span', {}, @props.script.messages[@state.page][0..@state.visibleCursor] | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment