Beispiel #1
0
func (sm *SystemMenu) 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()
	}
	if sm.focus {
		for _, button := range sm.buttons {
			button.Think(sm.region.X, sm.region.Y, sm.mx, sm.my, dt)
		}
		// This makes it so that the button lights up while the menu
		sm.layout.Main.Think(0, 0, sm.layout.Main.bounds.x+1, sm.layout.Main.bounds.y+1, dt)
	} else {
		sm.layout.Main.Think(sm.region.X, sm.region.Y, sm.mx, sm.my, dt)
	}

	if sm.saved_time != (time.Time{}) && time.Now().Sub(sm.saved_time).Seconds() > 3 {
		sm.saved_alpha = doApproach(sm.saved_alpha, 0.0, dt)
	}

	sm.focus = (g.FocusWidget() == sm)
}
Beispiel #2
0
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)
		}
	}
}
Beispiel #3
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
}
Beispiel #4
0
func (sm *SystemMenu) 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 {
		if sm.layout.Main.handleClick(sm.mx, sm.my, g) {
			if sm.focus {
				g.DropFocus()
			} else {
				g.TakeFocus(sm)
			}
			sm.focus = true
			base.Log().Printf("focus: %v %v", sm, g.FocusWidget())
			return true
		}
		if sm.focus {
			hit := false
			for _, button := range sm.buttons {
				if button.handleClick(sm.mx, sm.my, g) {
					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 (g.FocusWidget() == sm)
}
Beispiel #5
0
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()
	}
}
Beispiel #6
0
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)
	}
}