menu
This commit is contained in:
parent
e5853e8765
commit
8a3e6e43f9
27
coffee/menu.coffee
Normal file
27
coffee/menu.coffee
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
# 00 00 00000000 000 000 000 000
|
||||||
|
# 000 000 000 0000 000 000 000
|
||||||
|
# 000000000 0000000 000 0 000 000 000
|
||||||
|
# 000 0 000 000 000 0000 000 000
|
||||||
|
# 000 000 00000000 000 000 0000000
|
||||||
|
|
||||||
|
ScreenText = require './screentext'
|
||||||
|
|
||||||
|
class Menu extends ScreenText
|
||||||
|
|
||||||
|
constructor: ->
|
||||||
|
super
|
||||||
|
|
||||||
|
del: ->
|
||||||
|
world.menu = null
|
||||||
|
super
|
||||||
|
|
||||||
|
addItem: (text, cb) ->
|
||||||
|
@addText text
|
||||||
|
|
||||||
|
modKeyComboEvent: (mod, key, combo, event) ->
|
||||||
|
switch key
|
||||||
|
when 'esc'
|
||||||
|
@fadeOut()
|
||||||
|
|
||||||
|
module.exports = Menu
|
|
@ -4,7 +4,10 @@
|
||||||
# 0000000 000 0000000 0000000 0000000 000 0 000 000 0000000 00000 000
|
# 0000000 000 0000000 0000000 0000000 000 0 000 000 0000000 00000 000
|
||||||
# 000 000 000 000 000 000 000 0000 000 000 000 000 000
|
# 000 000 000 000 000 000 000 0000 000 000 000 000 000
|
||||||
# 0000000 0000000 000 000 00000000 00000000 000 000 000 00000000 000 000 000
|
# 0000000 0000000 000 000 00000000 00000000 000 000 000 00000000 000 000 000
|
||||||
|
{
|
||||||
|
first,
|
||||||
|
last
|
||||||
|
} = require '/Users/kodi/s/ko/js/tools/tools'
|
||||||
Camera = require './camera'
|
Camera = require './camera'
|
||||||
Action = require './action'
|
Action = require './action'
|
||||||
Timer = require './timer'
|
Timer = require './timer'
|
||||||
|
@ -40,10 +43,14 @@ class ScreenText extends Actor
|
||||||
@addText text
|
@addText text
|
||||||
@show()
|
@show()
|
||||||
|
|
||||||
|
del: ->
|
||||||
|
@scene.remove @mesh
|
||||||
|
Timer.removeActionsOfObject @
|
||||||
|
world.text = null
|
||||||
|
|
||||||
show: -> @startTimedAction @getActionWithId Action.SHOW
|
show: -> @startTimedAction @getActionWithId Action.SHOW
|
||||||
|
|
||||||
addText: (str, scaleFactor) ->
|
addText: (str, scaleFactor) ->
|
||||||
@height += 1
|
|
||||||
geom = new THREE.TextGeometry str,
|
geom = new THREE.TextGeometry str,
|
||||||
font: ScreenText.font
|
font: ScreenText.font
|
||||||
size: 1
|
size: 1
|
||||||
|
@ -54,15 +61,18 @@ class ScreenText extends Actor
|
||||||
|
|
||||||
@width = Math.max str.length, @width
|
@width = Math.max str.length, @width
|
||||||
geom.computeBoundingBox()
|
geom.computeBoundingBox()
|
||||||
geom.normalize()
|
|
||||||
min = geom.boundingBox.min
|
min = geom.boundingBox.min
|
||||||
max = geom.boundingBox.max
|
max = geom.boundingBox.max
|
||||||
mesh = new THREE.Mesh geom, Material.text
|
mesh = new THREE.Mesh geom, Material.text
|
||||||
|
mesh.translateX -(max.x-min.x)/2
|
||||||
|
mesh.translateY -@height
|
||||||
@mesh.add mesh
|
@mesh.add mesh
|
||||||
|
@mesh.position.set 0, @height/2*0.9, 0
|
||||||
|
|
||||||
# adjust projection
|
# adjust projection
|
||||||
@camera.position.copy new Vector 0,0,6*@height
|
@camera.position.copy new Vector 0,0,12+5*@height
|
||||||
@camera.lookAt new Vector 0,0,0
|
@camera.lookAt new Vector 0,0,0
|
||||||
|
@height += 1
|
||||||
|
|
||||||
resized: (w,h) ->
|
resized: (w,h) ->
|
||||||
@aspect = w/h
|
@aspect = w/h
|
||||||
|
@ -79,7 +89,7 @@ class ScreenText extends Actor
|
||||||
actionFinished: (action) ->
|
actionFinished: (action) ->
|
||||||
switch action.id
|
switch action.id
|
||||||
when Action.HIDE
|
when Action.HIDE
|
||||||
@emit 'hidden'
|
@del()
|
||||||
when Action.SHOW
|
when Action.SHOW
|
||||||
Material.text.opacity = 1
|
Material.text.opacity = 1
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ Timer = require './timer'
|
||||||
Actor = require './actor'
|
Actor = require './actor'
|
||||||
Item = require './item'
|
Item = require './item'
|
||||||
Action = require './action'
|
Action = require './action'
|
||||||
|
Menu = require './menu'
|
||||||
ScreenText = require './screentext'
|
ScreenText = require './screentext'
|
||||||
TmpObject = require './tmpobject'
|
TmpObject = require './tmpobject'
|
||||||
Pushable = require './pushable'
|
Pushable = require './pushable'
|
||||||
|
@ -693,6 +694,7 @@ class World extends Actor
|
||||||
@renderer.autoClearColor = false
|
@renderer.autoClearColor = false
|
||||||
@renderer.render @scene, camera
|
@renderer.render @scene, camera
|
||||||
@renderer.render @text.scene, @text.camera if @text
|
@renderer.render @text.scene, @text.camera if @text
|
||||||
|
@renderer.render @menu.scene, @menu.camera if @menu
|
||||||
|
|
||||||
# 000000000 000 00 00 00000000
|
# 000000000 000 00 00 00000000
|
||||||
# 000 000 000 000 000
|
# 000 000 000 000 000
|
||||||
|
@ -732,6 +734,7 @@ class World extends Actor
|
||||||
@renderer?.setSize w,h
|
@renderer?.setSize w,h
|
||||||
@screenSize = new Size w,h
|
@screenSize = new Size w,h
|
||||||
@text?.resized w,h
|
@text?.resized w,h
|
||||||
|
@menu?.resized w,h
|
||||||
|
|
||||||
getNearestValidPos: (pos) ->
|
getNearestValidPos: (pos) ->
|
||||||
new Pos Math.min(@size.x-1, Math.max(pos.x, 0)),
|
new Pos Math.min(@size.x-1, Math.max(pos.x, 0)),
|
||||||
|
@ -844,32 +847,18 @@ class World extends Actor
|
||||||
# 000 000 000
|
# 000 000 000
|
||||||
# 00000000 0000000 0000000
|
# 00000000 0000000 0000000
|
||||||
|
|
||||||
|
localizedString: (str) -> str
|
||||||
|
|
||||||
escape: (self) -> # handles an ESC key event
|
escape: (self) -> # handles an ESC key event
|
||||||
|
@text?.del()
|
||||||
@resetProjection()
|
@menu = new Menu()
|
||||||
|
@menu.addItem @localizedString("help"), @help
|
||||||
if "escape" in @dict
|
@menu.addItem @localizedString("restart"), @restart
|
||||||
if _.isFunction @dict["escape"]
|
@menu.addItem @localizedString("load level"), @levelSelection
|
||||||
@dict["escape"]()
|
@menu.addItem @localizedString("setup"), @quickSetup
|
||||||
else
|
@menu.addItem @localizedString("about"), @displayAbout
|
||||||
exec @dict["escape"] in globals()
|
@menu.addItem @localizedString("quit"), @quit
|
||||||
return
|
@menu.show()
|
||||||
|
|
||||||
menu = new Menu()
|
|
||||||
menu.getEventWithName("hide").addAction once @resetProjection
|
|
||||||
|
|
||||||
# if Controller.isDebugVersion()
|
|
||||||
# menu.addItem (Controller.getLocalizedString("next level"), once(lambda w=self: w.performAction("exit 0",0)))
|
|
||||||
# if "help" in @dict
|
|
||||||
# menu.addItem (Controller.getLocalizedString("help"), once(@help))
|
|
||||||
menu.addItem(Controller.getLocalizedString("restart"), once(@restart))
|
|
||||||
|
|
||||||
esc_menu_action = once @escape
|
|
||||||
log "level_index #{world.level_index}"
|
|
||||||
menu.addItem(Controller.getLocalizedString("load level"), (i=world.level_index,a=esc_menu_action) -> levelSelection(i, a))
|
|
||||||
menu.addItem(Controller.getLocalizedString("setup"), once @quickSetup)
|
|
||||||
menu.addItem(Controller.getLocalizedString("about"), once @display_about)
|
|
||||||
menu.addItem(Controller.getLocalizedString("quit"), once world.quit)
|
|
||||||
|
|
||||||
# 000 000 0000000 000 000
|
# 000 000 0000000 000 000
|
||||||
# 000 0 000 000 000 000 000
|
# 000 0 000 000 000 000 000
|
||||||
|
@ -918,9 +907,13 @@ class World extends Actor
|
||||||
# 000 000 00000000 000
|
# 000 000 00000000 000
|
||||||
|
|
||||||
modKeyComboEventDown: (mod, key, combo, event) ->
|
modKeyComboEventDown: (mod, key, combo, event) ->
|
||||||
|
if @menu?
|
||||||
|
@menu.modKeyComboEvent mod, key, combo, event
|
||||||
|
return
|
||||||
@text?.fadeOut()
|
@text?.fadeOut()
|
||||||
return if @player?.modKeyComboEventDown mod, key, combo, event
|
return if @player?.modKeyComboEventDown mod, key, combo, event
|
||||||
switch combo
|
switch combo
|
||||||
|
when 'esc' then @escape()
|
||||||
when '=' then @speed = Math.min 10, @speed+1
|
when '=' then @speed = Math.min 10, @speed+1
|
||||||
when '-' then @speed = Math.max 1, @speed-1
|
when '-' then @speed = Math.max 1, @speed-1
|
||||||
when 'r' then @restart()
|
when 'r' then @restart()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user