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
|
||||
# 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
|
||||
|
||||
{
|
||||
first,
|
||||
last
|
||||
} = require '/Users/kodi/s/ko/js/tools/tools'
|
||||
Camera = require './camera'
|
||||
Action = require './action'
|
||||
Timer = require './timer'
|
||||
|
@ -19,8 +22,8 @@ class ScreenText extends Actor
|
|||
constructor: (text) ->
|
||||
super
|
||||
|
||||
@addAction new Action @, Action.SHOW, "show", 500
|
||||
@addAction new Action @, Action.HIDE, "hide", 500
|
||||
@addAction new Action @, Action.SHOW, "show", 500
|
||||
@addAction new Action @, Action.HIDE, "hide", 500
|
||||
|
||||
@scene = new THREE.Scene()
|
||||
|
||||
|
@ -40,10 +43,14 @@ class ScreenText extends Actor
|
|||
@addText text
|
||||
@show()
|
||||
|
||||
del: ->
|
||||
@scene.remove @mesh
|
||||
Timer.removeActionsOfObject @
|
||||
world.text = null
|
||||
|
||||
show: -> @startTimedAction @getActionWithId Action.SHOW
|
||||
|
||||
addText: (str, scaleFactor) ->
|
||||
@height += 1
|
||||
geom = new THREE.TextGeometry str,
|
||||
font: ScreenText.font
|
||||
size: 1
|
||||
|
@ -52,17 +59,20 @@ class ScreenText extends Actor
|
|||
bevelThickness: 0.1
|
||||
bevelSize: 0.04
|
||||
|
||||
@width = Math.max str.length, @width
|
||||
@width = Math.max str.length, @width
|
||||
geom.computeBoundingBox()
|
||||
geom.normalize()
|
||||
min = geom.boundingBox.min
|
||||
max = geom.boundingBox.max
|
||||
mesh = new THREE.Mesh geom, Material.text
|
||||
mesh.translateX -(max.x-min.x)/2
|
||||
mesh.translateY -@height
|
||||
@mesh.add mesh
|
||||
@mesh.position.set 0, @height/2*0.9, 0
|
||||
|
||||
# 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
|
||||
@height += 1
|
||||
|
||||
resized: (w,h) ->
|
||||
@aspect = w/h
|
||||
|
@ -79,7 +89,7 @@ class ScreenText extends Actor
|
|||
actionFinished: (action) ->
|
||||
switch action.id
|
||||
when Action.HIDE
|
||||
@emit 'hidden'
|
||||
@del()
|
||||
when Action.SHOW
|
||||
Material.text.opacity = 1
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ Timer = require './timer'
|
|||
Actor = require './actor'
|
||||
Item = require './item'
|
||||
Action = require './action'
|
||||
Menu = require './menu'
|
||||
ScreenText = require './screentext'
|
||||
TmpObject = require './tmpobject'
|
||||
Pushable = require './pushable'
|
||||
|
@ -693,6 +694,7 @@ class World extends Actor
|
|||
@renderer.autoClearColor = false
|
||||
@renderer.render @scene, camera
|
||||
@renderer.render @text.scene, @text.camera if @text
|
||||
@renderer.render @menu.scene, @menu.camera if @menu
|
||||
|
||||
# 000000000 000 00 00 00000000
|
||||
# 000 000 000 000 000
|
||||
|
@ -732,6 +734,7 @@ class World extends Actor
|
|||
@renderer?.setSize w,h
|
||||
@screenSize = new Size w,h
|
||||
@text?.resized w,h
|
||||
@menu?.resized w,h
|
||||
|
||||
getNearestValidPos: (pos) ->
|
||||
new Pos Math.min(@size.x-1, Math.max(pos.x, 0)),
|
||||
|
@ -844,32 +847,18 @@ class World extends Actor
|
|||
# 000 000 000
|
||||
# 00000000 0000000 0000000
|
||||
|
||||
localizedString: (str) -> str
|
||||
|
||||
escape: (self) -> # handles an ESC key event
|
||||
|
||||
@resetProjection()
|
||||
|
||||
if "escape" in @dict
|
||||
if _.isFunction @dict["escape"]
|
||||
@dict["escape"]()
|
||||
else
|
||||
exec @dict["escape"] in globals()
|
||||
return
|
||||
|
||||
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)
|
||||
@text?.del()
|
||||
@menu = new Menu()
|
||||
@menu.addItem @localizedString("help"), @help
|
||||
@menu.addItem @localizedString("restart"), @restart
|
||||
@menu.addItem @localizedString("load level"), @levelSelection
|
||||
@menu.addItem @localizedString("setup"), @quickSetup
|
||||
@menu.addItem @localizedString("about"), @displayAbout
|
||||
@menu.addItem @localizedString("quit"), @quit
|
||||
@menu.show()
|
||||
|
||||
# 000 000 0000000 000 000
|
||||
# 000 0 000 000 000 000 000
|
||||
|
@ -918,9 +907,13 @@ class World extends Actor
|
|||
# 000 000 00000000 000
|
||||
|
||||
modKeyComboEventDown: (mod, key, combo, event) ->
|
||||
if @menu?
|
||||
@menu.modKeyComboEvent mod, key, combo, event
|
||||
return
|
||||
@text?.fadeOut()
|
||||
return if @player?.modKeyComboEventDown mod, key, combo, event
|
||||
switch combo
|
||||
when 'esc' then @escape()
|
||||
when '=' then @speed = Math.min 10, @speed+1
|
||||
when '-' then @speed = Math.max 1, @speed-1
|
||||
when 'r' then @restart()
|
||||
|
|
Loading…
Reference in New Issue
Block a user