// If x,y is inside the button's region then it will run its function and // return true, otherwise it does nothing and returns false. func (b *Button) handleClick(x, y int, data interface{}) bool { in := pointInsideRect(x, y, b.bounds.x, b.bounds.y, b.bounds.dx, b.bounds.dy) if in && b.valid { b.f(data) sound.PlaySound("Haunts/SFX/UI/Select", 0.75) } return in }
func (ob *OptionBasic) Think(hovered, selected, selectable bool, dt int64) { if selectable && hovered && !ob.was_over { sound.PlaySound("Haunts/SFX/UI/Tick", 0.75) } ob.was_over = hovered if ob.was_selected != selected { sound.PlaySound("Haunts/SFX/UI/Select", 0.75) } ob.was_selected = selected switch { case selected: ob.alpha = 255 case selectable && hovered: ob.alpha = 200 case selectable && !hovered: ob.alpha = 150 default: ob.alpha = 50 } }
// Does some basic setup that is common to both creating a new entity and to // loading one from a saved game. func (e *Entity) Load(g *Game) { e.sprite.Load(e.Sprite_path.String()) e.Sprite().SetTriggerFunc(func(s *sprite.Sprite, name string) { x, y := e.Pos() dx, dy := e.Dims() volume := 1.0 if e.Side() == SideExplorers || e.Side() == SideHaunt { volume = e.Game().ViewFrac(x, y, dx, dy) } if e.current_action != nil { if sound_name, ok := e.current_action.SoundMap()[name]; ok { sound.PlaySound(sound_name, volume) return } } if e.Sounds != nil { if sound_name, ok := e.Sounds[name]; ok { sound.PlaySound(sound_name, volume) } } }) if e.Side() == SideHaunt || e.Side() == SideExplorers { e.los = &losData{} full_los := make([]bool, house.LosTextureSizeSquared) e.los.grid = make([][]bool, house.LosTextureSize) for i := range e.los.grid { e.los.grid[i] = full_los[i*house.LosTextureSize : (i+1)*house.LosTextureSize] } } g.all_ents_in_memory[e] = true g.viewer.RemoveDrawable(e) g.viewer.AddDrawable(e) e.game = g e.LoadAi() }
func (b *Button) Think(x, y, mx, my int, dt int64) { if b.valid_func != nil { b.valid = b.valid_func() } else { b.valid = true } in := b.valid && pointInsideRect(mx, my, b.bounds.x, b.bounds.y, b.bounds.dx, b.bounds.dy) if in && !b.was_in { sound.PlaySound("Haunts/SFX/UI/Tick", 0.75) } b.was_in = in b.shade = doShading(b.shade, in, dt) }
func (ep *EntityPlacer) Respond(g *gui.Gui, group gui.EventGroup) bool { cursor := group.Events[0].Key.Cursor() if cursor != nil { ep.mx, ep.my = cursor.Point() } // If we're dragging around an ent then we'll update its position here. if ep.game.new_ent != nil { bx, by := DiscretizePoint32(ep.game.viewer.WindowToBoard(ep.mx, ep.my)) ep.game.new_ent.X, ep.game.new_ent.Y = float64(bx), float64(by) } if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press { for _, button := range ep.buttons { if button.handleClick(ep.mx, ep.my, nil) { return true } } } if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press { if pointInsideRect(ep.mx, ep.my, ep.region.X, ep.region.Y, ep.region.Dx, ep.region.Dy) { return true } } if ep.game.new_ent == nil { return false } if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press { ent := ep.game.new_ent if ep.game.placeEntity(ep.pattern) { cost := ep.roster[ent.Name] ep.points -= cost ep.ents = append(ep.ents, ent) sound.PlaySound("Haunts/SFX/UI/Place", 1.0) if cost <= ep.points { ep.game.new_ent = MakeEntity(ent.Name, ep.game) ep.game.viewer.AddDrawable(ep.game.new_ent) } return true } } return false }