123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- (include "button.ddh")
- # create tile facing front
- (class_function Button void create (group)
- (group
- (dd_matrix_identity this)
- (= this.width 0)
- (= this.height 0)
- (= this.x 0)
- (= this.y 0)
- (= this.z 0)
- # idle animation
- (= this.idleRot 0)
- (= this.idleRotTarget 7)
- (= this.idleCol 0)
- (= this.pX 0)
- (= this.pY 0)
- (= this.pW 0.1)
- (= this.pSize -5)
- )
- )
- (class_function Button void setSize (group float sizeX float sizeY)
- (group
- (= this.width sizeX)
- (= this.height sizeY)
- )
- )
- (class_function Button void setPosition (group float posX float posY float posZ)
- (group
- (= this.x posX)
- (= this.y posY)
- (= this.z posZ)
- )
- )
- (class_function Button void setProportionalPosition (group float propX float propY)
- (group
- (= this.pX propX)
- (= this.pY propY)
- (this.resize)
- )
- )
- (class_function Button void setProportionalWidth (group float propW)
- (group
- (= this.pW propW)
- (this.resize)
- )
- )
- (class_function Button void setProportionalSize (group float propSize)
- (group
- (= this.pSize (/ -5 propSize))
- (this.resize)
- )
- )
- # animate the tiles to the current side
- (class_function Button void update (group int isSelected int isClicked)
- (group
- # animate to target if clicked
- (if isClicked
- (group
- (= this.idleRot (dd_math_ease_linear 0.2 this.idleRot this.idleRotTarget))
- (= this.idleCol (dd_math_ease_linear 0.2 this.idleCol 2))
- )
- # animate to target if selected
- isSelected
- (group
- (= this.idleRot (dd_math_ease_linear 0.2 this.idleRot this.idleRotTarget))
- (= this.idleCol (dd_math_ease_linear 0.2 this.idleCol 1))
- )
- # animate to idle
- (group
- (= this.idleRot (dd_math_ease_linear 0.2 this.idleRot 0))
- (= this.idleCol (dd_math_ease_linear 0.2 this.idleCol 0))
- )
- )
- # flip animation when reached the target
- (if (< (dd_math_abs (- this.idleRot this.idleRotTarget)) 0.15)
- (= this.idleRotTarget (* this.idleRotTarget -1))
- )
- )
- ) # update
- # draw tile based on its side
- (class_function Button void applyTransform (group)
- (group
- (dd_translatef this.x this.y this.z)
- )
- )
- # draw tile based on its side
- (class_function Button void applyMatrixTransform (group)
- (group
- (dd_multMatrixf this)
- (dd_rotatef this.idleRot 0 0 1)
- (dd_scalef
- (+ 1.0 (* this.idleCol 0.2))
- (+ 1.0 (* this.idleCol 0.2))
- (+ 1.0 (* this.idleCol 0.2))
- )
- )
- )
- # draw tile based on its side
- (class_function Button void drawRaw (group)
- (group
- (this.mesh.draw)
- )
- )
- # draw tile based on its side
- (class_function Button void draw (group)
- (group
- (dd_pushMatrix)
- (this.applyTransform)
- (this.applyMatrixTransform)
- (this.drawRaw)
- (dd_popMatrix)
- )
- )
- (class_function Button void clean (group)
- (group
- )
- )
- (class_function Button int hasMouseCollided (group)
- (group
- # get mouse's proportioned position
- (def float screenProportionX)
- (= screenProportionX (- (dd_mouse_xProportion) 0.5))
- (def float screenProportionY)
- (= screenProportionY (- (dd_mouse_yProportion) 0.5))
- # get x and y of the plane where the button is
- (def float planeX)
- (= planeX (* screenProportionX (dd_screen_width_get (* this.z -1))))
- (def float planeY)
- (= planeY (* screenProportionY (dd_screen_height_get this.z)))
- # check collision
- (if (&&
- (>= planeX (- this.x (/ this.width 2)))
- (<= planeX (+ this.x (/ this.width 2)))
- (>= planeY (- this.y (/ this.height 2)))
- (<= planeY (+ this.y (/ this.height 2)))
- )
- (return 1)
- (return 0)
- )
- )
- )
- (class_function Button void resize (group)
- (group
- # figure out if button should be smaller
- (def float objScale (dd_math_minf (* (dd_screen_width_get 5) this.pW) 1.0))
- (= this.z (/ this.pSize objScale))
- # place the button on the screen based on the proportions
- (= this.x (* (dd_screen_width_get (* this.z -1)) (- this.pX 0.5)))
- (= this.y (* (dd_screen_height_get (* this.z -1)) (- this.pY 0.5)))
- )
- )
|