コード例 #1
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
}
コード例 #2
0
ファイル: game.go プロジェクト: RickDakan/haunts
func (gp *GamePanel) Think(ui *gui.Gui, t int64) {
	gp.scriptThinkOnce()
	gp.AnchorBox.Think(ui, t)
	if !gp.Active() {
		return
	}
	if gp.game != nil {
		gp.game.modal = (ui.FocusWidget() != nil)
	}

	if gp.last_think == 0 {
		gp.last_think = t
	}
	dt := t - gp.last_think
	gp.last_think = t
	gp.game.Think(dt)

	if gp.main_bar != nil {
		if gp.game.selected_ent != nil {
			gp.main_bar.SelectEnt(gp.game.selected_ent)
		} else {
			gp.main_bar.SelectEnt(gp.game.hovered_ent)
		}
	}
}
コード例 #3
0
ファイル: ui_main_bar.go プロジェクト: RickDakan/haunts
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
}
コード例 #4
0
ファイル: house.go プロジェクト: FlyingCar/haunts
func (hdt *houseRelicsTab) Think(ui *gui.Gui, t int64) {
	defer hdt.VerticalTable.Think(ui, t)
	rbx, rby := hdt.viewer.WindowToBoard(gin.In().GetCursor("Mouse").Point())
	bx := roundDown(rbx - hdt.drag_anchor.x + 0.5)
	by := roundDown(rby - hdt.drag_anchor.y + 0.5)
	if hdt.temp_relic != nil {
		hdt.temp_relic.X = bx
		hdt.temp_relic.Y = by
		hdt.temp_relic.Dx += gin.In().GetKey(gin.Right).FramePressCount()
		hdt.temp_relic.Dx -= gin.In().GetKey(gin.Left).FramePressCount()
		if hdt.temp_relic.Dx < 1 {
			hdt.temp_relic.Dx = 1
		}
		if hdt.temp_relic.Dx > 10 {
			hdt.temp_relic.Dx = 10
		}
		hdt.temp_relic.Dy += gin.In().GetKey(gin.Up).FramePressCount()
		hdt.temp_relic.Dy -= gin.In().GetKey(gin.Down).FramePressCount()
		if hdt.temp_relic.Dy < 1 {
			hdt.temp_relic.Dy = 1
		}
		if hdt.temp_relic.Dy > 10 {
			hdt.temp_relic.Dy = 10
		}
		hdt.markTempSpawnValidity()
	} else {
		_, _, spawn_at := hdt.house.Floors[0].RoomFurnSpawnAtPos(roundDown(rbx), roundDown(rby))
		if spawn_at != nil {
			hdt.spawn_name.SetText(spawn_at.Name)
		} else if hdt.spawn_name.IsBeingEdited() {
			hdt.typed_name = hdt.spawn_name.GetText()
		} else {
			hdt.spawn_name.SetText(hdt.typed_name)
		}
	}

	if hdt.temp_relic == nil && gin.In().GetKey('n').FramePressCount() > 0 && ui.FocusWidget() == nil {
		hdt.newSpawn()
	}
}
コード例 #5
0
ファイル: main.go プロジェクト: runningwild/tester
func main() {
	sys = system.Make(gos.GetSystemInterface())
	sys.Startup()
	wdx := 1000
	wdy := 500
	render.Init()
	var ui *gui.Gui
	render.Queue(func() {
		sys.CreateWindow(50, 150, wdx, wdy)
		sys.EnableVSync(true)
		err := gl.Init()
		if err != nil {
			f, err2 := os.Create(filepath.Join(datadir, "gl_log.txt"))
			if err2 != nil {
				fmt.Printf("Unable to write log to a file:%v\n%v\v", err, err2)
			} else {
				fmt.Fprintf(f, "%v\n", err)
				f.Close()
			}
		}
		ui, _ = gui.Make(gin.In(), gui.Dims{wdx, wdy}, filepath.Join(datadir, "fonts", "luxisr.ttf"))
		font, err := loadFont()
		if err != nil {
			panic(err.Error())
		}
		dict = gui.MakeDictionary(font, 15)
	})
	render.Purge()

	anchor := gui.MakeAnchorBox(gui.Dims{wdx, wdy})
	ui.AddChild(anchor)
	var event_handler handler
	gin.In().RegisterEventListener(&event_handler)
	actions_list := gui.MakeVerticalTable()
	keyname_list := gui.MakeVerticalTable()
	both_lists := gui.MakeHorizontalTable()
	both_lists.AddChild(actions_list)
	both_lists.AddChild(keyname_list)
	anchor.AddChild(both_lists, gui.Anchor{1, 0.5, 1, 0.5})
	var actions []string
	for action := range action_map {
		actions = append(actions, action)
	}
	sort.Strings(actions)
	for _, action := range actions {
		actions_list.AddChild(gui.MakeTextLine("standard", action, 150, 1, 1, 1, 1))
		keyname_list.AddChild(gui.MakeTextLine("standard", commands[action].Cmd, 100, 1, 1, 1, 1))
	}

	current_anim := gui.MakeTextLine("standard", "", 300, 1, 1, 1, 1)
	current_state := gui.MakeTextLine("standard", "", 300, 1, 1, 1, 1)
	frame_data := gui.MakeVerticalTable()
	frame_data.AddChild(current_anim)
	frame_data.AddChild(current_state)
	anchor.AddChild(frame_data, gui.Anchor{0, 1, 0, 1})

	speed := 100
	speed_text := gui.MakeTextLine("standard", "Speed: 100%", 150, 1, 1, 1, 1)
	anchor.AddChild(speed_text, gui.Anchor{0, 0, 0, 0})

	var box1, box2 boxdata

	box1.name = "box1"
	box1.sb = makeSpriteBox(nil)
	anchor.AddChild(box1.sb, gui.Anchor{0.5, 0.5, 0.25, 0.5})
	box1.load(GetStoreVal("box1"))
	box := box1

	box2.name = "box2"
	box2.sb = makeSpriteBox(nil)
	anchor.AddChild(box2.sb, gui.Anchor{0.5, 0.5, 0.45, 0.5})
	box2.load(GetStoreVal("box2"))
	box2.sb.top = true
	box_other := box2

	box2.sb.r, box2.sb.g, box2.sb.b = 0.2, 0.1, 0.4
	box1.sb.r, box1.sb.g, box1.sb.b = 0.4, 0.2, 0.8

	error_msg = gui.MakeTextLine("standard", "", wdx, 1, 0.5, 0.5, 1)
	anchor.AddChild(error_msg, gui.Anchor{0, 0, 0, 0.1})

	var chooser gui.Widget
	// curdir := GetStoreVal("curdir")
	// if curdir == "" {
	//   curdir = "."
	// } else {
	//   _,err := os.Stat(filepath.Join(datadir, curdir))
	//   if err == nil {
	//     go func() {
	//       anim, err := sprite.LoadSprite(filepath.Join(datadir, curdir))
	//       loaded <- loadResult{ anim, err }
	//     } ()
	//   } else {
	//     curdir = "."
	//   }
	// }
	// var profile_output *os.File
	then := time.Now()
	sys.Think()
	for key_map["quit"].FramePressCount() == 0 {
		event_handler.box1 = &box
		event_handler.box2 = &box_other
		now := time.Now()
		dt := (now.Nanosecond() - then.Nanosecond()) / 1000000
		then = now
		render.Queue(func() {
			sys.Think()
			if box1.sb.s != nil {
				box1.sb.s.Think(int64(float64(dt) * float64(speed) / 100))
			}
			if box2.sb.s != nil {
				box2.sb.s.Think(int64(float64(dt) * float64(speed) / 100))
			}
			gl.ClearColor(1, 0, 0, 1)
			gl.Clear(gl.COLOR_BUFFER_BIT)
			ui.Draw()
			sys.SwapBuffers()
		})
		render.Purge()
		select {
		case load := <-loaded:
			if load.err != nil {
				error_msg.SetText(load.err.Error())
				current_anim.SetText("")
			} else {
				box.sb.s = load.anim
				error_msg.SetText("")
			}
		default:
		}
		// if box.sb.s != nil {
		//   box.sb.s.Think()
		//   current_anim.SetText(fmt.Sprintf("%d: %s", box.sb.s.Facing(), box.sb.s.Anim()))
		//   current_state.SetText(box.sb.s.AnimState())
		// }

		if box.sb.s != nil {
			if key_map["reset"].FramePressCount() > 0 {
				box.load(box.dir)
				box_other.load(box_other.dir)
			}
		}

		// if key_map["profile"].FramePressCount() > 0 {
		//   if profile_output == nil {
		//     var err error
		//     profile_output, err = os.Create(filepath.Join(datadir, "cpu.prof"))
		//     if err == nil {
		//       err = pprof.StartCPUProfile(profile_output)
		//       if err != nil {
		//         fmt.Printf("Unable to start CPU profile: %v\n", err)
		//         profile_output.Close()
		//         profile_output = nil
		//       }
		//       fmt.Printf("profout: %v\n", profile_output)
		//     } else {
		//       fmt.Printf("Unable to open CPU profile: %v\n", err)
		//     }
		//   } else {
		//     pprof.StopCPUProfile()
		//     profile_output.Close()
		//     profile_output = nil
		//   }
		// }

		if key_map["load"].FramePressCount() > 0 && chooser == nil {
			anch := gui.MakeAnchorBox(gui.Dims{wdx, wdy})
			file_chooser := gui.MakeFileChooser(filepath.Join(datadir, box.dir),
				func(path string, err error) {
					if err == nil && len(path) > 0 {
						curpath, _ := filepath.Split(path)
						box.load(curpath)
					}
					ui.RemoveChild(chooser)
					chooser = nil
				},
				func(path string, is_dir bool) bool {
					return true
				})
			anch.AddChild(file_chooser, gui.Anchor{0.5, 0.5, 0.5, 0.5})
			chooser = anch
			ui.AddChild(chooser)
		}
		delta := key_map["speed up"].FramePressAmt() - key_map["slow down"].FramePressAmt()
		if delta != 0 {
			speed += int(delta)
			if speed < 1 {
				speed = 1
			}
			if speed > 100 {
				speed = 100
			}
			speed_text.SetText(fmt.Sprintf("Speed: %d%%", speed))
		}

		if key_map["select1"].FramePressCount() > 0 {
			box2.sb.r, box2.sb.g, box2.sb.b = 0.2, 0.1, 0.4
			box1.sb.r, box1.sb.g, box1.sb.b = 0.4, 0.2, 0.8
			box = box1
			box_other = box2
		}
		if key_map["select2"].FramePressCount() > 0 {
			box2.sb.r, box2.sb.g, box2.sb.b = 0.4, 0.2, 0.8
			box1.sb.r, box1.sb.g, box1.sb.b = 0.2, 0.1, 0.4
			box = box2
			box_other = box1
		}
	}
}
コード例 #6
0
ファイル: ui_main_bar.go プロジェクト: RickDakan/haunts
func (m *MainBar) Think(g *gui.Gui, t int64) {
	if g.FocusWidget() != nil {
		return
	}
	if m.ent != nil {
		// If an action is selected and we can't see it then we scroll just enough
		// so that we can.
		min := 0.0
		max := float64(len(m.ent.Actions) - m.layout.Actions.Count)
		selected_index := -1
		for i := range m.ent.Actions {
			if m.ent.Actions[i] == m.state.Actions.selected {
				selected_index = i
				break
			}
		}
		if selected_index != -1 {
			if min < float64(selected_index-m.layout.Actions.Count+1) {
				min = float64(selected_index - m.layout.Actions.Count + 1)
			}
			if max > float64(selected_index) {
				max = float64(selected_index)
			}
		}
		m.state.Actions.selected = m.game.current_action
		if m.state.Actions.scroll_target > max {
			m.state.Actions.scroll_target = max
		}
		if m.state.Actions.scroll_target < min {
			m.state.Actions.scroll_target = min
		}

		if m.state.Actions.clicked != nil {
			if m.state.Actions.selected != m.state.Actions.clicked {
				if m.state.Actions.clicked.Preppable(m.ent, m.game) {
					m.state.Actions.clicked.Prep(m.ent, m.game)
					m.game.SetCurrentAction(m.state.Actions.clicked)
				}
			}
			m.state.Actions.clicked = nil
		}

		// We similarly need to scroll through conditions
		c := m.layout.Conditions
		d := base.GetDictionary(int(c.Size))
		max_scroll := d.MaxHeight() * float64(len(m.ent.Stats.ConditionNames()))
		max_scroll -= m.layout.Conditions.Height
		// This might end up with a max that is negative, but we'll cap it at zero
		if m.state.Conditions.scroll_pos > max_scroll {
			m.state.Conditions.scroll_pos = max_scroll
		}
		if m.state.Conditions.scroll_pos < 0 {
			m.state.Conditions.scroll_pos = 0
		}
	} else {
		m.state.Conditions.scroll_pos = 0
		m.state.Actions.scroll_pos = 0
		m.state.Actions.scroll_target = 0
	}

	// Do a nice scroll motion towards the target position
	m.state.Actions.scroll_pos *= 0.8
	m.state.Actions.scroll_pos += 0.2 * m.state.Actions.scroll_target

	// Handle mouseover stuff after doing all of the scroll stuff since we don't
	// want to give a mouseover for something that the mouse isn't over after
	// scrolling something.
	m.state.MouseOver.active = false
	if m.ent != nil {
		c := m.layout.Conditions
		if pointInsideRect(m.mx, m.my, int(c.X), int(c.Y), int(c.Width), int(c.Height)) {
			pos := c.Y + c.Height + m.state.Conditions.scroll_pos - float64(m.my)
			index := int(pos / base.GetDictionary(int(c.Size)).MaxHeight())
			if index >= 0 && index < len(m.ent.Stats.ConditionNames()) {
				m.state.MouseOver.active = true
				m.state.MouseOver.text = m.ent.Stats.ConditionNames()[index]
				m.state.MouseOver.location = mouseOverConditions
			}
		}

		if index := m.pointInsideAction(m.mx, m.my); index != -1 {
			m.state.MouseOver.active = true
			m.state.MouseOver.text = m.ent.Actions[index].String()
			m.state.MouseOver.location = mouseOverActions
		}
	}

	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 {
		button.Think(m.region.X, m.region.Y, m.mx, m.my, t)
	}
}