예제 #1
0
func (c *Chooser) Respond(g *gui.Gui, group gui.EventGroup) bool {
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		c.mx, c.my = cursor.Point()
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		buttons := c.buttons
		if c.optionsHeight() <= c.layout.Options.Dy {
			buttons = c.non_scroll_buttons
		}
		for _, button := range buttons {
			if button.handleClick(c.mx, c.my, nil) {
				return true
			}
			clicked := false
			c.doOnOptions(func(index int, opt Option, data doOnOptionData) {
				if clicked {
					return
				}
				if data.hovered {
					c.selector(index, c.selected, true)
					clicked = true
				}
			})
		}
	}
	return false
}
예제 #2
0
파일: console.go 프로젝트: dgthunder/magnus
func (c *Console) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	if found, event := group.FindEvent(GetDefaultKeyMap()["console"].Id()); found && event.Type == gin.Press {
		if group.Focus {
			ui.DropFocus()
		} else {
			ui.TakeFocus(c)
		}
		return true
	}
	if group.Focus {
		// if found, event := group.FindEvent(gin.Left); found && event.Type == gin.Press {
		//   c.xscroll += 250
		// }
		// if found, event := group.FindEvent(gin.Right); found && event.Type == gin.Press {
		//   c.xscroll -= 250
		// }
	}
	if c.xscroll > 0 {
		c.xscroll = 0
	}
	if found, event := group.FindEvent(gin.AnySpace); found && event.Type == gin.Press {
		c.xscroll = 0
	}

	return group.Focus
}
예제 #3
0
파일: summon.go 프로젝트: FlyingCar/haunts
func (a *SummonAction) HandleInput(group gui.EventGroup, g *game.Game) (bool, game.ActionExec) {
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		bx, by := g.GetViewer().WindowToBoard(cursor.Point())
		bx += 0.5
		by += 0.5
		if bx < 0 {
			bx--
		}
		if by < 0 {
			by--
		}
		a.cx = int(bx)
		a.cy = int(by)
	}

	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		if g.IsCellOccupied(a.cx, a.cy) {
			return true, nil
		}
		if a.Personal_los && !a.ent.HasLos(a.cx, a.cy, 1, 1) {
			return true, nil
		}
		if a.ent.Stats.ApCur() >= a.Ap {
			var exec summonExec
			exec.SetBasicData(a.ent, a)
			exec.Pos = a.ent.Game().ToVertex(a.cx, a.cy)
			return true, &exec
		}
		return true, nil
	}
	return false, nil
}
예제 #4
0
func (sm *StartMenu) Respond(g *gui.Gui, group gui.EventGroup) bool {
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		sm.mx, sm.my = cursor.Point()
	}

	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		hit := false
		for _, button := range sm.buttons {
			if button.handleClick(sm.mx, sm.my, nil) {
				hit = true
			}
		}
		if hit {
			return true
		}
	} else {
		hit := false
		for _, button := range sm.buttons {
			if button.Respond(group, nil) {
				hit = true
			}
		}
		if hit {
			return true
		}
	}
	return false
}
예제 #5
0
func (a *Interact) HandleInput(group gui.EventGroup, g *game.Game) (bool, game.ActionExec) {
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		bx, by := g.GetViewer().WindowToBoard(gin.In().GetCursor("Mouse").Point())
		room_num := a.ent.CurrentRoom()
		room := g.House.Floors[0].Rooms[room_num]
		for door_num, door := range room.Doors {
			rect := makeRectForDoor(room, door)
			if rect.Contains(float64(bx), float64(by)) {
				var exec interactExec
				exec.Toggle_door = true
				exec.SetBasicData(a.ent, a)
				exec.Room = room_num
				exec.Door = door_num
				return true, &exec
			}
		}
	}
	target := g.HoveredEnt()
	if target == nil {
		return false, nil
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		for i := range a.targets {
			if a.targets[i] == target && distBetweenEnts(a.ent, target) <= a.Range {
				var exec interactExec
				exec.SetBasicData(a.ent, a)
				exec.Target = target.Id
				return true, &exec
			}
		}
		return true, nil
	}
	return false, nil
}
예제 #6
0
func (sw *SaveWidget) Respond(ui *gui.Gui, event_group gui.EventGroup) bool {
	if found, event := event_group.FindEvent(gin.Return); found && event.Type == gin.Press {
		sw.on_save(sw.filename.GetText())
		return true
	}
	sw.VerticalTable.Respond(ui, event_group)
	return true
}
예제 #7
0
func (w *WallPanel) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	if w.VerticalTable.Respond(ui, group) {
		return true
	}

	if found, event := group.FindEvent(gin.DeleteOrBackspace); found && event.Type == gin.Press {
		algorithm.Choose2(&w.room.WallTextures, func(wt *WallTexture) bool {
			return wt != w.wall_texture
		})
		w.wall_texture = nil
		w.prev_wall_texture = nil
		return true
	}

	if found, event := group.FindEvent(gin.Escape); found && event.Type == gin.Press {
		w.onEscape()
		return true
	}

	if found, event := group.FindEvent(base.GetDefaultKeyMap()["flip"].Id()); found && event.Type == gin.Press {
		if w.wall_texture != nil {
			w.wall_texture.Flip = !w.wall_texture.Flip
		}
		return true
	}
	if found, event := group.FindEvent(gin.MouseWheelVertical); found {
		if w.wall_texture != nil && gin.In().GetKey(gin.Space).CurPressAmt() == 0 {
			w.wall_texture.Rot += float32(event.Key.CurPressAmt() / 100)
		}
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		if w.wall_texture != nil {
			w.wall_texture.temporary = false
			w.wall_texture = nil
		} else if w.wall_texture == nil {
			w.wall_texture = w.textureNear(event.Key.Cursor().Point())
			if w.wall_texture != nil {
				w.prev_wall_texture = new(WallTexture)
				*w.prev_wall_texture = *w.wall_texture
				w.wall_texture.temporary = true

				wx, wy := w.viewer.BoardToWindowf(w.wall_texture.X, w.wall_texture.Y)
				px, py := event.Key.Cursor().Point()
				w.drag_anchor.X = float32(px) - wx
				w.drag_anchor.Y = float32(py) - wy
			}
		}
		return true
	}
	return false
}
예제 #8
0
func (sm *OnlineMenu) Respond(g *gui.Gui, group gui.EventGroup) bool {
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		sm.mx, sm.my = cursor.Point()
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		for _, button := range sm.buttons {
			if button.handleClick(sm.mx, sm.my, nil) {
				return true
			}
		}
		for _, glb := range []*gameListBox{&sm.layout.Active, &sm.layout.Unstarted} {
			inside := gui.Point{sm.mx, sm.my}.Inside(glb.Scroll.Region())
			if cursor == nil || inside {
				for _, game := range glb.games {
					if game.join.handleClick(sm.mx, sm.my, nil) {
						return true
					}
					if game.delete != nil && game.delete.handleClick(sm.mx, sm.my, nil) {
						return true
					}
				}
			}
		}
	}

	hit := false
	for _, button := range sm.buttons {
		if button.Respond(group, nil) {
			hit = true
		}
	}
	for _, glb := range []*gameListBox{&sm.layout.Active, &sm.layout.Unstarted} {
		inside := gui.Point{sm.mx, sm.my}.Inside(glb.Scroll.Region())
		if cursor == nil || inside {
			for _, game := range glb.games {
				if game.join.Respond(group, nil) {
					hit = true
				}
				if game.delete != nil && game.delete.Respond(group, nil) {
					hit = true
				}
			}
		}
	}
	if hit {
		return true
	}
	return false
}
예제 #9
0
func (m *MainBar) Respond(g *gui.Gui, group gui.EventGroup) bool {
	if g.FocusWidget() != nil {
		return false
	}
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		m.mx, m.my = cursor.Point()
		if m.my > m.layout.Background.Data().Dy() {
			return false
		}
	}

	buttons := m.no_actions_buttons
	if m.ent != nil && len(m.ent.Actions) > m.layout.Actions.Count {
		buttons = m.all_buttons
	}
	for _, button := range buttons {
		if button.Respond(group, m) {
			return true
		}
	}

	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		for _, button := range buttons {
			if button.handleClick(m.mx, m.my, m) {
				return true
			}
		}
		if m.ent != nil {
			index := m.pointInsideAction(m.mx, m.my)
			if index != -1 {
				m.state.Actions.clicked = m.ent.Actions[index]
			}
		}
	}

	if found, event := group.FindEvent(gin.MouseWheelVertical); found {
		x := int(m.layout.Conditions.X)
		y := int(m.layout.Conditions.Y)
		x2 := int(m.layout.Conditions.X + m.layout.Conditions.Width)
		y2 := int(m.layout.Conditions.Y + m.layout.Conditions.Height)
		if m.mx >= x && m.my >= y && m.mx < x2 && m.my < y2 {
			m.state.Conditions.scroll_pos += event.Key.FramePressAmt()
		}
	}

	return cursor != nil
}
예제 #10
0
파일: ui_credits.go 프로젝트: koomee/haunts
func (cm *CreditsMenu) Respond(g *gui.Gui, group gui.EventGroup) bool {
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		cm.mx, cm.my = cursor.Point()
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		for _, button := range cm.buttons {
			if button.handleClick(cm.mx, cm.my, nil) {
				return true
			}
		}
	}

	hit := false
	for _, button := range cm.buttons {
		if button.Respond(group, nil) {
			hit = true
		}
	}
	return hit
}
예제 #11
0
func (a *AoeAttack) HandleInput(group gui.EventGroup, g *game.Game) (bool, game.ActionExec) {
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil && cursor.Name() == "Mouse" {
		bx, by := g.GetViewer().WindowToBoard(cursor.Point())
		a.tx = int(bx)
		a.ty = int(by)
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		ex, ey := a.ent.Pos()
		if dist(ex, ey, a.tx, a.ty) <= a.Range && a.ent.HasLos(a.tx, a.ty, 1, 1) {
			var exec aoeExec
			exec.SetBasicData(a.ent, a)
			exec.X, exec.Y = a.tx, a.ty
			return true, &exec
		} else {
			return true, nil
		}
		return true, nil
	}
	return false, nil
}
예제 #12
0
파일: move.go 프로젝트: hilerchyn/haunts
func (a *Move) HandleInput(group gui.EventGroup, g *game.Game) (bool, game.ActionExec) {
	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		fx, fy := g.GetViewer().WindowToBoard(cursor.Point())
		a.findPath(a.ent, int(fx), int(fy))
	}
	if found, _ := group.FindEvent(gin.MouseLButton); found {
		if len(a.path) > 0 {
			if a.cost <= a.ent.Stats.ApCur() {
				var exec moveExec
				exec.SetBasicData(a.ent, a)
				algorithm.Map2(a.path, &exec.Path, func(v [2]int) int {
					return g.ToVertex(v[0], v[1])
				})
				return true, &exec
			}
			return true, nil
		} else {
			return false, nil
		}
	}
	return false, nil
}
예제 #13
0
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")
			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
}
예제 #14
0
파일: house.go 프로젝트: FlyingCar/haunts
func (hdt *houseRelicsTab) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	if hdt.VerticalTable.Respond(ui, group) {
		return true
	}

	if found, event := group.FindEvent(gin.Escape); found && event.Type == gin.Press {
		hdt.onEscape()
		return true
	}

	if found, event := group.FindEvent(gin.DeleteOrBackspace); found && event.Type == gin.Press {
		algorithm.Choose2(&hdt.house.Floors[0].Spawns, func(s *SpawnPoint) bool {
			return s != hdt.temp_relic
		})
		hdt.temp_relic = nil
		hdt.prev_relic = nil
		return true
	}

	cursor := group.Events[0].Key.Cursor()
	floor := hdt.house.Floors[hdt.current_floor]
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		if hdt.temp_relic != nil {
			if !hdt.temp_relic.invalid {
				hdt.temp_relic.temporary = false
				hdt.temp_relic = nil
			}
		} else {
			for _, sp := range floor.Spawns {
				fbx, fby := hdt.viewer.WindowToBoard(cursor.Point())
				bx, by := roundDown(fbx), roundDown(fby)
				x, y := sp.Pos()
				dx, dy := sp.Dims()
				if bx >= x && bx < x+dx && by >= y && by < y+dy {
					hdt.temp_relic = sp
					hdt.prev_relic = new(SpawnPoint)
					*hdt.prev_relic = *hdt.temp_relic
					hdt.temp_relic.temporary = true
					hdt.drag_anchor.x = fbx - float32(hdt.temp_relic.X)
					hdt.drag_anchor.y = fby - float32(hdt.temp_relic.Y)
					break
				}
			}
		}
	}
	return false
}
예제 #15
0
func (rc *RosterChooser) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	base.Log().Printf("RosterChooser.Respond")
	if found, event := group.FindEvent('l'); found && event.Type == gin.Press {
		rc.focus += rc.layout.Num_options
		return true
	}
	if found, event := group.FindEvent('o'); found && event.Type == gin.Press {
		rc.focus -= rc.layout.Num_options
		return true
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		x, y := event.Key.Cursor().Point()
		gp := gui.Point{x, y}
		if gp.Inside(rc.render.down) {
			rc.focus += rc.layout.Num_options
			return true
		} else if gp.Inside(rc.render.up) {
			rc.focus -= rc.layout.Num_options
			return true
		} else if gp.Inside(rc.render.all_options) {
			for i := range rc.render.options {
				if gp.Inside(rc.render.options[i]) {
					rc.selector(i, rc.selected, true)
					return true
				}
			}
		} else if gp.Inside(rc.render.done) {
			if rc.selector(-1, rc.selected, false) {
				base.Log().Printf("calling on-complete")
				rc.on_complete(rc.selected)
			}
			return true
		} else if rc.on_undo != nil && gp.Inside(rc.render.undo) {
			rc.on_undo()
			return true
		}
	}
	return false
}
예제 #16
0
func (w *FurniturePanel) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	if w.VerticalTable.Respond(ui, group) {
		return true
	}

	// On escape we want to revert the furniture we're moving back to where it was
	// and what state it was in before we selected it.  If we don't have any
	// furniture selected then we don't do anything.
	if found, event := group.FindEvent(gin.Escape); found && event.Type == gin.Press {
		w.onEscape()
		return true
	}

	// If we hit delete then we want to remove the furniture we're moving around
	// from the room.  If we're not moving anything around then nothing happens.
	if found, event := group.FindEvent(gin.DeleteOrBackspace); found && event.Type == gin.Press {
		algorithm.Choose2(&w.Room.Furniture, func(f *Furniture) bool {
			return f != w.furniture
		})
		w.furniture = nil
		w.prev_object = nil
		return true
	}

	if found, event := group.FindEvent(w.key_map["rotate left"].Id()); found && event.Type == gin.Press {
		if w.furniture != nil {
			w.furniture.RotateLeft()
		}
	}
	if found, event := group.FindEvent(w.key_map["rotate right"].Id()); found && event.Type == gin.Press {
		if w.furniture != nil {
			w.furniture.RotateRight()
		}
	}
	if found, event := group.FindEvent(w.key_map["flip"].Id()); found && event.Type == gin.Press {
		if w.furniture != nil {
			w.furniture.Flip = !w.furniture.Flip
		}
	}
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		if w.furniture != nil {
			if !w.furniture.invalid {
				w.furniture.temporary = false
				w.furniture = nil
			}
		} else if w.furniture == nil {
			bx, by := w.RoomViewer.WindowToBoard(event.Key.Cursor().Point())
			for i := range w.Room.Furniture {
				x, y := w.Room.Furniture[i].Pos()
				dx, dy := w.Room.Furniture[i].Dims()
				if int(bx) >= x && int(bx) < x+dx && int(by) >= y && int(by) < y+dy {
					w.furniture = w.Room.Furniture[i]
					w.prev_object = new(Furniture)
					*w.prev_object = *w.furniture
					w.furniture.temporary = true
					px, py := w.furniture.Pos()
					w.drag_anchor.x = bx - float32(px)
					w.drag_anchor.y = by - float32(py)
					break
				}
			}
		}
		return true
	}
	return false
}
예제 #17
0
파일: game.go 프로젝트: RickDakan/haunts
func (gp *GamePanel) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	if gp.AnchorBox.Respond(ui, group) {
		return true
	}
	if !gp.Active() {
		return false
	}

	if group.Events[0].Type == gin.Release {
		return false
	}

	cursor := group.Events[0].Key.Cursor()
	if cursor != nil {
		if gp.game.hovered_ent != nil {
			gp.game.hovered_ent.hovered = false
		}
		gp.game.hovered_ent = nil
		mx, my := cursor.Point()
		for i := range gp.game.Ents {
			fx, fy := gp.game.Ents[i].FPos()
			wx, wy := gp.game.viewer.BoardToWindow(float32(fx), float32(fy))
			if gp.game.Ents[i].Stats != nil && gp.game.Ents[i].Stats.HpCur() <= 0 {
				continue // Don't bother showing dead units
			}
			x := wx - int(gp.game.Ents[i].last_render_width/2)
			y := wy
			x2 := wx + int(gp.game.Ents[i].last_render_width/2)
			y2 := wy + int(150*gp.game.Ents[i].last_render_width/100)
			if mx >= x && mx <= x2 && my >= y && my <= y2 {
				if gp.game.hovered_ent != nil {
					gp.game.hovered_ent.hovered = false
				}
				gp.game.hovered_ent = gp.game.Ents[i]
				gp.game.hovered_ent.hovered = true
			}
		}
	}

	if found, event := group.FindEvent(gin.Escape); found && event.Type == gin.Press {
		if gp.game.selected_ent != nil {
			switch gp.game.Action_state {
			case noAction:
				gp.game.selected_ent.selected = false
				gp.game.selected_ent.hovered = false
				gp.game.selected_ent = nil
				return true

			case preppingAction:
				gp.game.SetCurrentAction(nil)
				return true

			case doingAction:
				// Do nothing - we don't cancel an action that's in progress
			}
		}
	}

	if gp.game.Action_state == noAction {
		if found, _ := group.FindEvent(gin.MouseLButton); found {
			if gp.game.hovered_ent != nil && gp.game.hovered_ent.Side() == gp.game.Side {
				if gp.game.selected_ent != nil {
					gp.game.selected_ent.selected = false
				}
				gp.game.selected_ent = gp.game.hovered_ent
				gp.game.selected_ent.selected = true
			}
			return true
		}
	}

	if gp.game.Action_state == preppingAction {
		consumed, exec := gp.game.current_action.HandleInput(group, gp.game)
		if consumed {
			if exec != nil {
				gp.game.current_exec = exec
				// TODO: Should send the exec across the wire here
			}
			return true
		}
	}

	// After this point all events that we check for require that we have a
	// selected entity
	if gp.game.selected_ent == nil {
		return false
	}
	if gp.game.Action_state == noAction || gp.game.Action_state == preppingAction {
		if len(group.Events) == 1 && group.Events[0].Key.Id() >= '1' && group.Events[0].Key.Id() <= '9' {
			index := int(group.Events[0].Key.Id() - '1')
			if index >= 0 && index < len(gp.game.selected_ent.Actions) {
				action := gp.game.selected_ent.Actions[index]
				if action != gp.game.current_action && action.Prep(gp.game.selected_ent, gp.game) {
					gp.game.SetCurrentAction(action)
				}
			}
		}
	}

	return false
}
예제 #18
0
파일: house.go 프로젝트: FlyingCar/haunts
func (hdt *houseDoorTab) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	if hdt.VerticalTable.Respond(ui, group) {
		return true
	}

	if found, event := group.FindEvent(gin.Escape); found && event.Type == gin.Press {
		hdt.onEscape()
		return true
	}

	if found, event := group.FindEvent(gin.DeleteOrBackspace); found && event.Type == gin.Press {
		algorithm.Choose2(&hdt.temp_room.Doors, func(d *Door) bool {
			return d != hdt.temp_door
		})
		hdt.temp_room = nil
		hdt.temp_door = nil
		hdt.prev_room = nil
		hdt.prev_door = nil
		return true
	}

	cursor := group.Events[0].Key.Cursor()
	var bx, by float32
	if cursor != nil {
		bx, by = hdt.viewer.WindowToBoard(cursor.Point())
	}
	if cursor != nil && hdt.temp_door != nil {
		room := hdt.viewer.FindClosestDoorPos(hdt.temp_door, bx, by)
		if room != hdt.temp_room {
			algorithm.Choose2(&hdt.temp_room.Doors, func(d *Door) bool {
				return d != hdt.temp_door
			})
			hdt.temp_room = room
			hdt.temp_door.invalid = (hdt.temp_room == nil)
			hdt.temp_room.Doors = append(hdt.temp_room.Doors, hdt.temp_door)
		}
		if hdt.temp_room == nil {
			hdt.temp_door.invalid = true
		} else {
			other_room, _ := hdt.house.Floors[0].findRoomForDoor(hdt.temp_room, hdt.temp_door)
			hdt.temp_door.invalid = (other_room == nil)
		}
	}

	floor := hdt.house.Floors[hdt.current_floor]
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		if hdt.temp_door != nil {
			other_room, other_door := floor.findRoomForDoor(hdt.temp_room, hdt.temp_door)
			if other_room != nil {
				other_room.Doors = append(other_room.Doors, other_door)
				hdt.temp_door.temporary = false
				hdt.temp_door = nil
				hdt.prev_door = nil
			}
		} else {
			hdt.temp_room, hdt.temp_door = hdt.viewer.FindClosestExistingDoor(bx, by)
			if hdt.temp_door != nil {
				hdt.prev_door = new(Door)
				*hdt.prev_door = *hdt.temp_door
				hdt.prev_room = hdt.temp_room
				hdt.temp_door.temporary = true
				room, door := hdt.house.Floors[0].FindMatchingDoor(hdt.temp_room, hdt.temp_door)
				if room != nil {
					algorithm.Choose2(&room.Doors, func(d *Door) bool {
						return d != door
					})
				}
			}
		}
		return true
	}

	return false
}
예제 #19
0
파일: house.go 프로젝트: FlyingCar/haunts
func (hdt *houseDataTab) Respond(ui *gui.Gui, group gui.EventGroup) bool {
	if hdt.VerticalTable.Respond(ui, group) {
		return true
	}

	if found, event := group.FindEvent(gin.Escape); found && event.Type == gin.Press {
		hdt.onEscape()
		return true
	}

	if found, event := group.FindEvent(gin.DeleteOrBackspace); found && event.Type == gin.Press {
		if hdt.temp_room != nil {
			spawns := make(map[*SpawnPoint]bool)
			for i := range hdt.temp_spawns {
				spawns[hdt.temp_spawns[i]] = true
			}
			algorithm.Choose2(&hdt.house.Floors[0].Spawns, func(s *SpawnPoint) bool {
				return !spawns[s]
			})
			algorithm.Choose2(&hdt.house.Floors[0].Rooms, func(r *Room) bool {
				return r != hdt.temp_room
			})
			hdt.temp_room = nil
			hdt.prev_room = nil
			hdt.viewer.SetBounds()
		}
		return true
	}

	floor := hdt.house.Floors[hdt.current_floor]
	if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
		if hdt.temp_room != nil {
			if !hdt.temp_room.invalid {
				hdt.temp_room.temporary = false
				floor.removeInvalidDoors()
				hdt.temp_room = nil
				hdt.prev_room = nil
				hdt.viewer.SetBounds()
			}
		} else {
			cx, cy := event.Key.Cursor().Point()
			bx, by := hdt.viewer.WindowToBoard(cx, cy)
			for i := range floor.Rooms {
				x, y := floor.Rooms[i].Pos()
				dx, dy := floor.Rooms[i].Dims()
				if int(bx) >= x && int(bx) < x+dx && int(by) >= y && int(by) < y+dy {
					hdt.temp_room = floor.Rooms[i]
					hdt.prev_room = new(Room)
					*hdt.prev_room = *hdt.temp_room
					hdt.temp_room.temporary = true
					hdt.drag_anchor.x = bx - float32(x)
					hdt.drag_anchor.y = by - float32(y)
					break
				}
			}
			if hdt.temp_room != nil {
				hdt.temp_spawns = hdt.temp_spawns[0:0]
				for _, sp := range hdt.house.Floors[0].Spawns {
					x, y := sp.Pos()
					rx, ry := hdt.temp_room.Pos()
					rdx, rdy := hdt.temp_room.Dims()
					if x >= rx && x < rx+rdx && y >= ry && y < ry+rdy {
						hdt.temp_spawns = append(hdt.temp_spawns, sp)
					}
				}
			}
		}
		return true
	}

	return false
}