Esempio n. 1
0
func (kb KeyBinds) MakeKeyMap() KeyMap {
	key_map := make(KeyMap)
	for key, val := range kb {
		fmt.Printf("Keymapping %v -> %v\n", key, val)
		parts := strings.Split(val, ",")
		var binds []gin.Key
		for i, part := range parts {
			kids := getKeysFromString(part)

			if len(kids) == 1 {
				binds = append(binds, gin.In().GetKey(kids[0]))
			} else {
				// The last kid is the main kid and the rest are modifiers
				main := kids[len(kids)-1]
				kids = kids[0 : len(kids)-1]
				var down []bool
				for _ = range kids {
					down = append(down, true)
				}
				binds = append(binds, gin.In().BindDerivedKey(fmt.Sprintf("%s:%d", key, i), gin.In().MakeBinding(main, kids, down)))
			}
		}
		if len(binds) == 1 {
			key_map[key] = binds[0]
		} else {
			var actual_binds []gin.Binding
			for i := range binds {
				actual_binds = append(actual_binds, gin.In().MakeBinding(binds[i].Id(), nil, nil))
			}
			key_map[key] = gin.In().BindDerivedKey("name", actual_binds...)
		}
	}
	return key_map
}
Esempio n. 2
0
func (l *LocalData) handleEventGroupInvaders(group gin.EventGroup) {
	if l.mode != LocalModeMoba {
		panic("Need to implement controls for multiple players on a single screen")
	}
	k0 := gin.In().GetKeyFlat(gin.Key6, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	k1 := gin.In().GetKeyFlat(gin.Key7, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	k2 := gin.In().GetKeyFlat(gin.Key8, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	k3 := gin.In().GetKeyFlat(gin.Key9, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	if found, event := group.FindEvent(k0.Id()); found {
		l.activateAbility(&l.moba.currentPlayer.abs, l.moba.currentPlayer.gid, 0, event.Type == gin.Press)
		return
	}
	if found, event := group.FindEvent(k1.Id()); found {
		l.activateAbility(&l.moba.currentPlayer.abs, l.moba.currentPlayer.gid, 1, event.Type == gin.Press)
		return
	}
	if found, event := group.FindEvent(k2.Id()); found {
		l.activateAbility(&l.moba.currentPlayer.abs, l.moba.currentPlayer.gid, 2, event.Type == gin.Press)
		return
	}
	if found, event := group.FindEvent(k3.Id()); found {
		l.activateAbility(&l.moba.currentPlayer.abs, l.moba.currentPlayer.gid, 3, event.Type == gin.Press)
		return
	}
	if l.moba.currentPlayer.abs.activeAbility != nil {
		if l.moba.currentPlayer.abs.activeAbility.Respond(l.moba.currentPlayer.gid, group) {
			return
		}
	}
}
Esempio n. 3
0
func (camera *cameraInfo) doArchitectFocusRegion(g *Game, sys system.System) {
	if camera.limit.mid.X == 0 && camera.limit.mid.Y == 0 {
		// On the very first frame the limit midpoint will be (0,0), which should
		// never happen after the game begins.  We use this as an opportunity to
		// init the data now that we know the region we're working with.
		rdx := float64(g.Levels[GidInvadersStart].Room.Dx)
		rdy := float64(g.Levels[GidInvadersStart].Room.Dy)
		if camera.regionDims.X/camera.regionDims.Y > rdx/rdy {
			camera.limit.dims.Y = rdy
			camera.limit.dims.X = rdy * camera.regionDims.X / camera.regionDims.Y
		} else {
			camera.limit.dims.X = rdx
			camera.limit.dims.Y = rdx * camera.regionDims.Y / camera.regionDims.X
		}
		camera.limit.mid.X = rdx / 2
		camera.limit.mid.Y = rdy / 2
		camera.current = camera.limit
		camera.zoom = 0
		base.Log().Printf("Region Dims: %2.2v", camera.regionDims)
		base.Log().Printf("Room Dims: %2.2v %2.2v", rdx, rdy)
		base.Log().Printf("Limit Dims: %2.2v", camera.limit.dims)
	}
	wheel := gin.In().GetKeyFlat(gin.MouseWheelVertical, gin.DeviceTypeAny, gin.DeviceIndexAny)
	camera.zoom += wheel.FramePressAmt() / 500
	if camera.zoom < 0 {
		camera.zoom = 0
	}
	if camera.zoom > 2 {
		camera.zoom = 2
	}
	zoom := 1 / math.Exp(camera.zoom)
	camera.current.dims = camera.limit.dims.Scale(zoom)
	if gin.In().GetKey(gin.AnySpace).CurPressAmt() > 0 {
		if !camera.cursorHidden {
			sys.HideCursor(true)
			camera.cursorHidden = true
		}
		x := gin.In().GetKey(gin.AnyMouseXAxis).FramePressAmt()
		y := gin.In().GetKey(gin.AnyMouseYAxis).FramePressAmt()
		camera.current.mid.X -= float64(x) * 2
		camera.current.mid.Y -= float64(y) * 2
	} else {
		if camera.cursorHidden {
			sys.HideCursor(false)
			camera.cursorHidden = false
		}
	}
}
Esempio n. 4
0
func (a *Move) Prep(ent *game.Entity, g *game.Game) bool {
	a.ent = ent
	fx, fy := g.GetViewer().WindowToBoard(gin.In().GetCursor("Mouse").Point())
	a.findPath(ent, int(fx), int(fy))
	a.threshold = a.ent.Stats.ApCur()
	return true
}
Esempio n. 5
0
func main() {
	runtime.GOMAXPROCS(2)
	sys := system.Make(gos.GetSystemInterface())
	sys.Startup()

	game := Game{}
	var lb LevelBlueprint
	loadJson(filepath.Join(base.DataDir(), "1p_basic_level.json"), &lb)
	if len(lb.Players) == 0 || len(lb.Walls) == 0 {
		panic(fmt.Sprintf("Invalid level config: %d players and %d walls.",
			len(lb.Players), len(lb.Walls)))
	}
	engine, _ := cgf.NewLocalEngine(&game, int(Config.FrameTime*1000), nil)
	engine.ApplyEvent(&NewLevelEvent{&lb})

	render.Init()
	render.Queue(func() {
		initWindow(sys, Config.WindowWidth, Config.WindowHeight)
	})
	render.Purge()

	ticker := time.Tick(time.Millisecond * time.Duration(Config.FrameTime*1000))
	for true {
		<-ticker
		LocalThink(sys, engine, &game)
		if gin.In().GetKey(gin.AnyEscape).FramePressCount() > 0 {
			break
		}
	}
}
Esempio n. 6
0
func (hdt *houseDataTab) Think(ui *gui.Gui, t int64) {
	if hdt.temp_room != nil {
		mx, my := gin.In().GetCursor("Mouse").Point()
		bx, by := hdt.viewer.WindowToBoard(mx, my)
		cx, cy := hdt.temp_room.Pos()
		hdt.temp_room.X = int(bx - hdt.drag_anchor.x)
		hdt.temp_room.Y = int(by - hdt.drag_anchor.y)
		dx := hdt.temp_room.X - cx
		dy := hdt.temp_room.Y - cy
		for i := range hdt.temp_spawns {
			hdt.temp_spawns[i].X += dx
			hdt.temp_spawns[i].Y += dy
		}
		hdt.temp_room.invalid = !hdt.house.Floors[0].canAddRoom(hdt.temp_room)
	}
	hdt.VerticalTable.Think(ui, t)
	num_floors := hdt.num_floors.GetComboedIndex() + 1
	if len(hdt.house.Floors) != num_floors {
		for len(hdt.house.Floors) < num_floors {
			hdt.house.Floors = append(hdt.house.Floors, &Floor{})
		}
		if len(hdt.house.Floors) > num_floors {
			hdt.house.Floors = hdt.house.Floors[0:num_floors]
		}
	}
	hdt.house.Name = hdt.name.GetText()
	hdt.house.Icon.Path = base.Path(hdt.icon.GetPath())
}
Esempio n. 7
0
func getKeysFromString(str string) []gin.KeyId {
	parts := strings.Split(str, "+")
	var kids []gin.KeyId
	for _, part := range parts {
		part = osSpecifyKey(part)
		var kid gin.KeyId
		switch {
		case len(part) == 1: // Single character - should be ascii
			kid = gin.KeyId(part[0])

		case part == "ctrl":
			kid = gin.EitherControl

		case part == "shift":
			kid = gin.EitherShift

		case part == "alt":
			kid = gin.EitherAlt

		case part == "gui":
			kid = gin.EitherGui

		default:
			key := gin.In().GetKeyByName(part)
			if key == nil {
				panic(fmt.Sprintf("Unknown key '%s'", part))
			}
			kid = key.Id()
		}
		kids = append(kids, kid)
	}
	return kids
}
Esempio n. 8
0
func main() {
	sys := system.Make(gos.GetSystemInterface())
	sys.Startup()

	render.Init()
	render.Queue(func() {
		initWindow(sys, 800, 600)
	})

	font := loadDictionary("skia.dict")
	fmt.Fprintf(log, "Font: %v", font)
	for true {
		sys.Think()
		render.Queue(func() {
			// gl.Color4ub(0, 255, 255, 255)
			// gl.Begin(gl.QUADS)
			// gl.Vertex2d(100, 100)
			// gl.Vertex2d(500, 100)
			// gl.Vertex2d(500, 150)
			// gl.Vertex2d(100, 150)
			// gl.End()
			font.SetFontColor(1, 1, 1)
			font.RenderString("TEST", 100, 100, 100)
			sys.SwapBuffers()
		})
		render.Purge()
		if gin.In().GetKey(gin.AnyEscape).FramePressCount() > 0 {
			break
		}
	}
}
Esempio n. 9
0
func (ep *EntityPlacer) Think(g *gui.Gui, t int64) {
	if ep.last_t == 0 {
		ep.last_t = t
		return
	}
	dt := t - ep.last_t
	ep.last_t = t
	if ep.mx == 0 && ep.my == 0 {
		ep.mx, ep.my = gin.In().GetCursor("Mouse").Point()
	}
	for _, button := range ep.buttons {
		button.Think(ep.region.X, ep.region.Y, ep.mx, ep.my, dt)
	}

	hovered := false
	for i, button := range ep.ent_buttons {
		if button.Over(ep.mx, ep.my) {
			hovered = true
			if ep.hovered == nil || ep.roster_names[i] != ep.hovered.Name {
				ep.hovered = MakeEntity(ep.roster_names[i], ep.game)
			}
		}
	}
	if hovered == false {
		ep.hovered = nil
	}
	if ep.hovered != nil {
		ep.hovered.Think(dt)
	}
}
Esempio n. 10
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
}
Esempio n. 11
0
func (te *TextEntry) Think(x, y, mx, my int, dt int64) {
	if te.Entry.Default != "" {
		te.Entry.text = te.Entry.Default
		te.Entry.Default = ""
	}
	te.Button.Think(x, y, mx, my, dt)
	te.setCursor(gin.In().GetCursor("Mouse").Point())
}
Esempio n. 12
0
func getPlayers(console *base.Console) []gin.DeviceId {
	var ct controllerTracker
	gin.In().RegisterEventListener(&ct)
	defer gin.In().UnregisterEventListener(&ct)
	ticker := time.Tick(time.Millisecond * 17)
	start := time.Time{}
	readyDuration := time.Second * 2
	for start.IsZero() || time.Now().Sub(start) < readyDuration {
		<-ticker
		sys.Think()
		if ct.Ready() && start.IsZero() {
			start = time.Now()
		}
		if !ct.Ready() {
			start = time.Time{}
		}
		render.Queue(func() {
			defer console.Draw(0, 0, wdx, wdy)
			gl.Clear(gl.COLOR_BUFFER_BIT)
			gl.Disable(gl.DEPTH_TEST)
			gui.SetFontColor(1, 1, 1, 1)
			gl.Disable(gl.TEXTURE_2D)
			gl.MatrixMode(gl.PROJECTION)
			gl.LoadIdentity()
			gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000)
			gl.ClearColor(0, 0, 0, 1)
			gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
			gl.MatrixMode(gl.MODELVIEW)
			gl.LoadIdentity()
			base.GetDictionary("crackin").RenderString(fmt.Sprintf("Num players: %d", len(ct.ids)), float64(wdx)/2, 300, 0, 100, gui.Center)
			base.GetDictionary("crackin").RenderString(fmt.Sprintf("Num ready: %d", ct.NumReady()), float64(wdx)/2, 400, 0, 100, gui.Center)
			if !start.IsZero() {
				base.GetDictionary("crackin").RenderString(fmt.Sprintf("Starting in %2.2f", (readyDuration-time.Now().Sub(start)).Seconds()), float64(wdx)/2, 500, 0, 100, gui.Center)
			}
		})
		render.Queue(func() {
			sys.SwapBuffers()
		})
		render.Purge()
	}
	var devices []gin.DeviceId
	for id := range ct.ids {
		devices = append(devices, id)
	}
	return devices
}
Esempio n. 13
0
func (sys *sysObj) thinkInternal() {
	sys.os.Think()
	events, horizon := sys.os.GetInputEvents()
	for i := range events {
		events[i].Timestamp -= sys.start_ms
	}
	sys.events = gin.In().Think(horizon-sys.start_ms, sys.os.HasFocus(), events)
}
Esempio n. 14
0
func Make(x, y, dx, dy int) *Gui {
	var g Gui
	g.region = Region{Pos{x, y}, Dims{dx, dy}}
	g.root = &RootWidget{region: g.region}
	g.sys = system.Make(gos.GetSystemInterface())
	gin.In().RegisterEventListener(&g)
	return &g
}
Esempio n. 15
0
func (rv *RoomViewer) Think(*gui.Gui, int64) {
	if rv.size != rv.room.Size {
		rv.size = rv.room.Size
		rv.makeMat()
	}
	mx, my := rv.WindowToBoard(gin.In().GetCursor("Mouse").Point())
	rv.mx = int(mx)
	rv.my = int(my)
}
Esempio n. 16
0
func (a *AoeAttack) Prep(ent *game.Entity, g *game.Game) bool {
	if !a.Preppable(ent, g) {
		return false
	}
	a.ent = ent
	bx, by := g.GetViewer().WindowToBoard(gin.In().GetCursor("Mouse").Point())
	a.tx = int(bx)
	a.ty = int(by)
	return true
}
Esempio n. 17
0
func (kb KeyBinds) MakeKeyMap() KeyMap {
	key_map := make(KeyMap)
	for key, val := range kb {
		kids := getKeysFromString(val)

		if len(kids) == 1 {
			key_map[key] = gin.In().GetKey(kids[0])
		} else {
			// The last kid is the main kid and the rest are modifiers
			main := kids[len(kids)-1]
			kids = kids[0 : len(kids)-1]
			var down []bool
			for _ = range kids {
				down = append(down, true)
			}
			key_map[key] = gin.In().BindDerivedKey(key, gin.In().MakeBinding(main, kids, down))
		}
	}
	return key_map
}
Esempio n. 18
0
func (w *WallPanel) Think(ui *gui.Gui, t int64) {
	if w.wall_texture != nil {
		px, py := gin.In().GetCursor("Mouse").Point()
		tx := float32(px) - w.drag_anchor.X
		ty := float32(py) - w.drag_anchor.Y
		bx, by := w.viewer.WindowToBoardf(tx, ty)
		w.wall_texture.X = bx
		w.wall_texture.Y = by
	}
	w.VerticalTable.Think(ui, t)
}
Esempio n. 19
0
func (g *Game) HandleEventGroupGame(group gin.EventGroup) {
	g.local.RLock()
	defer g.local.RUnlock()

	if found, event := group.FindEvent(control.editor.Id()); found && event.Type == gin.Press {
		g.editor.Toggle()
		return
	}

	if found, _ := group.FindEvent(control.any.Id()); found {
		dir := getControllerDirection(gin.DeviceId{gin.DeviceTypeController, gin.DeviceIndexAny})
		g.local.Engine.ApplyEvent(&Move{
			Gid:       g.local.Gid,
			Angle:     dir.Angle(),
			Magnitude: dir.Mag(),
		})
	}

	// ability0Key := gin.In().GetKeyFlat(gin.ControllerButton0+2, gin.DeviceTypeController, gin.DeviceIndexAny)
	// abilityTrigger := gin.In().GetKeyFlat(gin.ControllerButton0+1, gin.DeviceTypeController, gin.DeviceIndexAny)
	buttons := []gin.Key{
		gin.In().GetKeyFlat(gin.ControllerButton0+2, gin.DeviceTypeController, gin.DeviceIndexAny),
		gin.In().GetKeyFlat(gin.ControllerButton0+3, gin.DeviceTypeController, gin.DeviceIndexAny),
		gin.In().GetKeyFlat(gin.ControllerButton0+4, gin.DeviceTypeController, gin.DeviceIndexAny),
		gin.In().GetKeyFlat(gin.ControllerButton0+5, gin.DeviceTypeController, gin.DeviceIndexAny),
	}
	abilityTrigger := gin.In().GetKeyFlat(gin.ControllerButton0+6, gin.DeviceTypeController, gin.DeviceIndexAny)
	for i, button := range buttons {
		foundButton, _ := group.FindEvent(button.Id())
		foundTrigger, triggerEvent := group.FindEvent(abilityTrigger.Id())
		// TODO: Check if any abilities are Active before sending events to other abilities.
		if foundButton || foundTrigger {
			g.local.Engine.ApplyEvent(UseAbility{
				Gid:     g.local.Gid,
				Index:   i,
				Button:  button.CurPressAmt(),
				Trigger: foundTrigger && triggerEvent.Type == gin.Press,
			})
		}
	}
}
Esempio n. 20
0
func (te *TextEntry) Respond(group gui.EventGroup, data interface{}) bool {
	if te.Button.Respond(group, data) {
		return true
	}
	if !te.Entry.entering {
		return false
	}
	for _, event := range group.Events {
		if event.Type == gin.Press {
			id := event.Key.Id()
			if id <= 255 && valid_keys[byte(id)] {
				b := byte(id)
				if gin.In().GetKey(gin.EitherShift).CurPressAmt() > 0 {
					b = shift_keys[b]
				}
				t := te.Entry.text
				index := te.Entry.cursor.index
				t = t[0:index] + string([]byte{b}) + t[index:]
				te.Entry.text = t
				te.Entry.cursor.index++
			} else if event.Key.Id() == gin.DeleteOrBackspace {
				if te.Entry.cursor.index > 0 {
					index := te.Entry.cursor.index
					t := te.Entry.text
					te.Entry.text = t[0:index-1] + t[index:]
					te.Entry.cursor.index--
				}
			} else if event.Key.Id() == gin.Left {
				if te.Entry.cursor.index > 0 {
					te.Entry.cursor.index--
				}
			} else if event.Key.Id() == gin.Right {
				if te.Entry.cursor.index < len(te.Entry.text) {
					te.Entry.cursor.index++
				}
			} else if event.Key.Id() == gin.Return {
				te.Entry.entering = false
				if te.Button.f != nil {
					te.Button.f(nil)
				}
			} else if event.Key.Id() == gin.Escape {
				te.Entry.entering = false
				te.Entry.text = te.Entry.prev
				te.Entry.prev = ""
				te.Entry.cursor.index = 0
			}
			d := base.GetDictionary(te.Button.Text.Size)
			te.Entry.cursor.offset = int(d.StringWidth(te.Entry.text[0:te.Entry.cursor.index]))
		}
	}
	return false
}
Esempio n. 21
0
func (l *LocalData) Setup(g *Game) {
	if len(l.engine.Ids()) > 0 {
		if gin.In().GetKey(gin.AnyUp).FramePressCount() > 0 {
			l.setup.index--
			if l.setup.index < 0 {
				l.setup.index = 0
			}
		}
		if gin.In().GetKey(gin.AnyDown).FramePressCount() > 0 {
			l.setup.index++
			if l.setup.index > len(g.Setup.EngineIds) {
				l.setup.index = len(g.Setup.EngineIds)
			}
		}
	} else {
		for i, v := range g.Setup.EngineIds {
			if v == l.engine.Id() {
				l.setup.index = i
			}
		}
	}
	if gin.In().GetKey(gin.AnyLeft).FramePressCount() > 0 {
		l.engine.ApplyEvent(SetupChampSelect{l.engine.Id(), -1})
	}
	if gin.In().GetKey(gin.AnyRight).FramePressCount() > 0 {
		l.engine.ApplyEvent(SetupChampSelect{l.engine.Id(), 1})
	}
	if gin.In().GetKey(gin.AnyReturn).FramePressCount() > 0 {
		if l.setup.index < len(g.Setup.EngineIds) {
			id := g.Setup.EngineIds[l.setup.index]
			side := (g.Setup.Sides[id].Side + 1) % 2
			l.engine.ApplyEvent(SetupChangeSides{id, side})
		} else {
			if len(l.engine.Ids()) > 0 {
				l.engine.ApplyEvent(SetupComplete{time.Now().UnixNano()})
			}
		}
	}
}
Esempio n. 22
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
}
Esempio n. 23
0
func (tsm *ThunderSubMenu) Respond(eventGroup gin.EventGroup) {
	var up, down bool
	for _, keyIndex := range tsm.downs {
		id := gin.In().GetKeyFlat(keyIndex, gin.DeviceTypeAny, gin.DeviceIndexAny).Id()
		if found, event := eventGroup.FindEvent(id); found && event.Type == gin.Press {
			down = true
		}
	}
	for _, keyIndex := range tsm.ups {
		id := gin.In().GetKeyFlat(keyIndex, gin.DeviceTypeAny, gin.DeviceIndexAny).Id()
		if found, event := eventGroup.FindEvent(id); found && event.Type == gin.Press {
			up = true
		}
	}
	if down {
		tsm.selected++
	}
	if up {
		if tsm.selected == -1 {
			tsm.selected = len(tsm.Options) - 1
		} else {
			tsm.selected--
		}
	}
	if tsm.selected >= len(tsm.Options) || tsm.selected < 0 {
		tsm.selected = -1
	}
	if eventGroup.Events[0].Key.Id().Device.Type != gin.DeviceTypeMouse {
		if tsm.selected >= 0 && tsm.selected < len(tsm.Options) {
			tsm.Options[tsm.selected].Respond(eventGroup)
		}
	} else {
		for _, option := range tsm.Options {
			option.Respond(eventGroup)
		}
	}
}
Esempio n. 24
0
func (cm *CreditsMenu) Think(g *gui.Gui, t int64) {
	if cm.last_t == 0 {
		cm.last_t = t
		return
	}
	dt := t - cm.last_t
	cm.last_t = t
	if cm.mx == 0 && cm.my == 0 {
		cm.mx, cm.my = gin.In().GetCursor("Mouse").Point()
	}
	cm.layout.Credits.Scroll.Think(dt)
	for _, button := range cm.buttons {
		button.Think(cm.region.X, cm.region.Y, cm.mx, cm.my, dt)
	}
}
Esempio n. 25
0
func (sm *StartMenu) Think(g *gui.Gui, t int64) {
	if sm.last_t == 0 {
		sm.last_t = t
		return
	}
	dt := t - sm.last_t
	sm.last_t = t

	if sm.mx == 0 && sm.my == 0 {
		sm.mx, sm.my = gin.In().GetCursor("Mouse").Point()
	}
	for _, button := range sm.buttons {
		button.Think(sm.region.X, sm.region.Y, sm.mx, sm.my, dt)
	}
}
Esempio n. 26
0
func mainLoop(client sgf.ClientEngine, controllers []gin.DeviceId, console *base.Console) {
	client.MakeRequest(game.Join{Rebels: make([]*game.RebelPlayer, 2)})
	ticker := time.Tick(time.Millisecond * 17)
	render.Queue(func() {
		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	})
	for {
		<-ticker
		if gin.In().GetKey(gin.AnyEscape).FramePressCount() != 0 {
			return
		}
		sys.Think()
		render.Queue(func() {
			gl.Clear(gl.COLOR_BUFFER_BIT)
			gl.Disable(gl.DEPTH_TEST)
			gui.SetFontColor(1, 1, 1, 1)
			gl.Disable(gl.TEXTURE_2D)
			gl.MatrixMode(gl.PROJECTION)
			gl.LoadIdentity()
			gl.Ortho(gl.Double(0), gl.Double(wdx), gl.Double(wdy), gl.Double(0), 1000, -1000)
			gl.ClearColor(0, 0, 0, 1)
			gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
			gl.MatrixMode(gl.MODELVIEW)
			gl.LoadIdentity()
			base.GetDictionary("crackin").RenderString("Waiting on some nubs", float64(wdx)/2, 300, 0, 100, gui.Center)
		})

		client.RLock()
		g := client.Game().(*game.Game)
		mode := g.Mode
		client.RUnlock()
		if mode == game.ModeWaiting {
		} else if mode == game.ModeProgram {
			programLoop(client, controllers, console)
		} else if mode == game.ModeRun {

		}

		render.Queue(func() {
			sys.SwapBuffers()
		})
		render.Purge()
	}
}
Esempio n. 27
0
func (rc *RosterChooser) Think(ui *gui.Gui, t int64) {
	var dt int64
	if rc.last_think != 0 {
		dt = t - rc.last_think
	}
	rc.last_think = t
	for i := range rc.options {
		rc.options[i].Think(dt)
	}

	max := len(rc.options) - rc.layout.Num_options
	if rc.focus > max {
		rc.focus = max
	}
	if rc.focus < 0 {
		rc.focus = 0
	}
	rc.focus_pos = (1-rc.layout.Speed)*rc.focus_pos + rc.layout.Speed*float64(rc.focus)

	rc.mouse.X, rc.mouse.Y = gin.In().GetCursor("Mouse").Point()
}
Esempio n. 28
0
func (w *FurniturePanel) Think(ui *gui.Gui, t int64) {
	if w.furniture != nil {
		mx, my := gin.In().GetCursor("Mouse").Point()
		bx, by := w.RoomViewer.WindowToBoard(mx, my)
		f := w.furniture
		f.X = roundDown(bx - w.drag_anchor.x + 0.5)
		f.Y = roundDown(by - w.drag_anchor.y + 0.5)
		fdx, fdy := f.Dims()
		f.invalid = false
		if f.X < 0 {
			f.invalid = true
		}
		if f.Y < 0 {
			f.invalid = true
		}
		if f.X+fdx > w.Room.Size.Dx {
			f.invalid = true
		}
		if f.Y+fdy > w.Room.Size.Dy {
			f.invalid = true
		}
		for _, t := range w.Room.Furniture {
			if t == f {
				continue
			}
			tdx, tdy := t.Dims()
			r1 := image.Rect(t.X, t.Y, t.X+tdx, t.Y+tdy)
			r2 := image.Rect(f.X, f.Y, f.X+fdx, f.Y+fdy)
			if r1.Overlaps(r2) {
				f.invalid = true
			}
		}
	}

	w.VerticalTable.Think(ui, t)
	w.Room.Resize(tags.RoomSizes[w.room_size.GetComboedIndex()])
	w.Room.Name = w.name.GetText()
	w.Room.Floor.Path = base.Path(w.floor_path.GetPath())
	w.Room.Wall.Path = base.Path(w.wall_path.GetPath())
}
Esempio n. 29
0
func (l *LocalData) localThinkInvaders(g *Game) {
	if l.mode != LocalModeMoba {
		panic("Need to implement controls for multiple players on a single screen")
	}
	if l.setup != nil {
		l.setupMobaData(g)
	}
	l.thinkAbility(g, &l.moba.currentPlayer.abs, l.moba.currentPlayer.gid)
	down_axis := gin.In().GetKeyFlat(gin.ControllerAxis0Positive+1, gin.DeviceTypeController, l.moba.deviceIndex)
	up_axis := gin.In().GetKeyFlat(gin.ControllerAxis0Negative+1, gin.DeviceTypeController, l.moba.deviceIndex)
	right_axis := gin.In().GetKeyFlat(gin.ControllerAxis0Positive, gin.DeviceTypeController, l.moba.deviceIndex)
	left_axis := gin.In().GetKeyFlat(gin.ControllerAxis0Negative, gin.DeviceTypeController, l.moba.deviceIndex)
	down_axis = gin.In().GetKeyFlat(gin.KeyS, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	up_axis = gin.In().GetKeyFlat(gin.KeyW, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	right_axis = gin.In().GetKeyFlat(gin.KeyD, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	left_axis = gin.In().GetKeyFlat(gin.KeyA, gin.DeviceTypeKeyboard, gin.DeviceIndexAny)
	up := axisControl(up_axis.CurPressAmt())
	down := axisControl(down_axis.CurPressAmt())
	left := axisControl(left_axis.CurPressAmt())
	right := axisControl(right_axis.CurPressAmt())
	if up-down != 0 {
		l.engine.ApplyEvent(Accelerate{l.moba.currentPlayer.gid, 300 * (up - down)})
	}
	if left-right != 0 {
		l.engine.ApplyEvent(Turn{l.moba.currentPlayer.gid, (right - left)})
	}

	// Ais
	if l.engine.Ids() != nil {
		for _, engineData := range g.Engines {
			if engineData.Ai != nil {
				l.engine.ApplyEvent(Accelerate{engineData.PlayerGid, 300})
			}
		}
	}
}
Esempio n. 30
0
func (c *Chooser) Think(g *gui.Gui, t int64) {
	if c.last_t == 0 {
		c.last_t = t
		return
	}
	dt := t - c.last_t
	c.last_t = t
	c.layout.Options.Height = c.optionsHeight()
	c.layout.Options.Think(dt)
	if c.mx == 0 && c.my == 0 {
		c.mx, c.my = gin.In().GetCursor("Mouse").Point()
	}
	buttons := c.buttons
	if c.optionsHeight() <= c.layout.Options.Dy {
		buttons = c.non_scroll_buttons
	}
	for _, button := range buttons {
		button.Think(c.region.X, c.region.Y, c.mx, c.my, dt)
	}
	c.doOnOptions(func(index int, opt Option, data doOnOptionData) {
		opt.Think(data.hovered, data.selected, data.selectable, dt)
	})
}