Example #1
0
func makeFurniturePanel(room *roomDef, viewer *RoomViewer) *FurniturePanel {
	var fp FurniturePanel
	fp.Room = room
	fp.RoomViewer = viewer
	fp.key_map = base.GetDefaultKeyMap()
	if room.Name == "" {
		room.Name = "name"
	}
	fp.name = gui.MakeTextEditLine("standard", room.Name, 300, 1, 1, 1, 1)

	if room.Floor.Path == "" {
		room.Floor.Path = base.Path(datadir)
	}
	fp.floor_path = gui.MakeFileWidget(room.Floor.Path.String(), imagePathFilter)

	if room.Wall.Path == "" {
		room.Wall.Path = base.Path(datadir)
	}
	fp.wall_path = gui.MakeFileWidget(room.Wall.Path.String(), imagePathFilter)

	fp.room_size = gui.MakeComboTextBox(algorithm.Map(tags.RoomSizes, []string{}, func(a interface{}) interface{} { return a.(RoomSize).String() }).([]string), 300)
	for i := range tags.RoomSizes {
		if tags.RoomSizes[i].String() == room.Size.String() {
			fp.room_size.SetSelectedIndex(i)
			break
		}
	}
	fp.VerticalTable = gui.MakeVerticalTable()
	fp.VerticalTable.Params().Spacing = 3
	fp.VerticalTable.Params().Background.R = 0.3
	fp.VerticalTable.Params().Background.B = 1
	fp.VerticalTable.AddChild(fp.name)
	fp.VerticalTable.AddChild(fp.floor_path)
	fp.VerticalTable.AddChild(fp.wall_path)
	fp.VerticalTable.AddChild(fp.room_size)

	furn_table := gui.MakeVerticalTable()
	fnames := GetAllFurnitureNames()
	for i := range fnames {
		name := fnames[i]
		furn_table.AddChild(gui.MakeButton("standard", name, 300, 1, 1, 1, 1, func(t int64) {
			f := MakeFurniture(name)
			if f == nil {
				return
			}
			fp.furniture = f
			fp.furniture.temporary = true
			fp.Room.Furniture = append(fp.Room.Furniture, fp.furniture)
			dx, dy := fp.furniture.Dims()
			fp.drag_anchor.x = float32(dx) / 2
			fp.drag_anchor.y = float32(dy) / 2
		}))
	}
	fp.VerticalTable.AddChild(gui.MakeScrollFrame(furn_table, 300, 600))

	return &fp
}
Example #2
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())
}
Example #3
0
func pickFromN(gp *GamePanel) lua.GoFunction {
	return func(L *lua.State) int {
		if !LuaCheckParamsOk(L, "PickFromN", LuaInteger, LuaInteger, LuaTable) {
			return 0
		}
		min := L.ToInteger(-3)
		max := L.ToInteger(-2)
		var options []hui.Option
		var option_names []string
		L.PushNil()
		for L.Next(-2) != 0 {
			name := L.ToString(-2)
			option_names = append(option_names, name)
			path := L.ToString(-1)
			if !filepath.IsAbs(path) {
				path = filepath.Join(base.GetDataDir(), path)
			}
			option := iconWithText{
				Name: name,
				Icon: texture.Object{Path: base.Path(path)},
			}
			options = append(options, &option)
			L.Pop(1)
		}
		var selector hui.Selector
		if min == 1 && max == 1 {
			selector = hui.SelectExactlyOne
		} else {
			selector = hui.SelectInRange(min, max)
		}
		var chooser *hui.RosterChooser
		done := make(chan struct{})
		on_complete := func(m map[int]bool) {
			gp.RemoveChild(chooser)
			L.NewTable()
			count := 0
			for i := range options {
				if m[i] {
					count++
					L.PushInteger(count)
					L.PushString(option_names[i])
					L.SetTable(-3)
				}
			}
			done <- struct{}{}
		}
		chooser = hui.MakeRosterChooser(options, selector, on_complete, nil)
		gp.script.syncStart()
		gp.AddChild(chooser, gui.Anchor{0.5, 0.5, 0.5, 0.5})
		gp.script.syncEnd()
		<-done
		return 1
	}
}
Example #4
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())
}
Example #5
0
func makeHouseDataTab(house *HouseDef, viewer *HouseViewer) *houseDataTab {
	var hdt houseDataTab
	hdt.VerticalTable = gui.MakeVerticalTable()
	hdt.house = house
	hdt.viewer = viewer

	hdt.name = gui.MakeTextEditLine("standard", "name", 300, 1, 1, 1, 1)
	num_floors_options := []string{"1 Floor", "2 Floors", "3 Floors", "4 Floors"}
	hdt.num_floors = gui.MakeComboTextBox(num_floors_options, 300)
	if hdt.house.Icon.Path == "" {
		hdt.house.Icon.Path = base.Path(filepath.Join(datadir, "houses", "icons"))
	}
	hdt.icon = gui.MakeFileWidget(string(hdt.house.Icon.Path), imagePathFilter)

	hdt.VerticalTable.AddChild(hdt.name)
	hdt.VerticalTable.AddChild(hdt.num_floors)
	hdt.VerticalTable.AddChild(hdt.icon)

	names := GetAllRoomNames()
	room_buttons := gui.MakeVerticalTable()
	for _, name := range names {
		n := name
		room_buttons.AddChild(gui.MakeButton("standard", name, 300, 1, 1, 1, 1, func(int64) {
			if hdt.temp_room != nil {
				return
			}
			hdt.temp_room = &Room{Defname: n}
			base.GetObject("rooms", hdt.temp_room)
			hdt.temp_room.temporary = true
			hdt.temp_room.invalid = true
			hdt.house.Floors[0].Rooms = append(hdt.house.Floors[0].Rooms, hdt.temp_room)
			hdt.drag_anchor.x = float32(hdt.temp_room.Size.Dx / 2)
			hdt.drag_anchor.y = float32(hdt.temp_room.Size.Dy / 2)
		}))
	}
	scroller := gui.MakeScrollFrame(room_buttons, 300, 700)
	hdt.VerticalTable.AddChild(scroller)
	return &hdt
}
Example #6
0
// bindAi(target, source)
// bindAi("denizen", "denizen.lua")
// bindAi("intruder", "intruder.lua")
// bindAi("minions", "minions.lua")
// bindAi(ent, "fudgecake.lua")
// special sources: "human", "inactive", and in the future: "net"
// special targets: "denizen", "intruder", "minions", or an entity table
func bindAi(gp *GamePanel) lua.GoFunction {
	return func(L *lua.State) int {
		if !LuaCheckParamsOk(L, "BindAi", LuaAnything, LuaString) {
			return 0
		}
		gp.script.syncStart()
		defer gp.script.syncEnd()
		source := L.ToString(-1)
		if L.IsTable(-2) {
			L.PushString("id")
			L.GetTable(-3)
			target := EntityId(L.ToInteger(-1))
			L.Pop(1)
			ent := gp.game.EntityById(target)
			if ent == nil {
				base.Error().Printf("Referenced an entity with id == %d which doesn't exist.", target)
				return 0
			}
			ent.Ai_file_override = base.Path(filepath.Join(base.GetDataDir(), "ais", filepath.FromSlash(L.ToString(-1))))
			ent.LoadAi()
			return 0
		}
		target := L.ToString(-2)
		switch target {
		case "denizen":
			switch source {
			case "human":
				gp.game.Ai.denizens = inactiveAi{}
			case "net":
				base.Error().Printf("bindAi('denizen', 'net') is not implemented.")
				return 0
			default:
				gp.game.Ai.denizens = nil
				path := filepath.Join(base.GetDataDir(), "ais", source)
				gp.game.Ai.Path.Denizens = path
				ai_maker(path, gp.game, nil, &gp.game.Ai.denizens, DenizensAi)
				if gp.game.Ai.denizens == nil {
					gp.game.Ai.denizens = inactiveAi{}
				}
			}
		case "intruder":
			switch source {
			case "human":
				gp.game.Ai.intruders = inactiveAi{}
			case "net":
				base.Error().Printf("bindAi('intruder', 'net') is not implemented.")
				return 0
			default:
				gp.game.Ai.intruders = nil
				path := filepath.Join(base.GetDataDir(), "ais", source)
				gp.game.Ai.Path.Intruders = path
				ai_maker(path, gp.game, nil, &gp.game.Ai.intruders, IntrudersAi)
				if gp.game.Ai.intruders == nil {
					gp.game.Ai.intruders = inactiveAi{}
				}
			}
		case "minions":
			gp.game.Ai.minions = nil
			path := filepath.Join(base.GetDataDir(), "ais", source)
			gp.game.Ai.Path.Minions = path
			ai_maker(path, gp.game, nil, &gp.game.Ai.minions, MinionsAi)
			if gp.game.Ai.minions == nil {
				gp.game.Ai.minions = inactiveAi{}
			}
		default:
			base.Error().Printf("Specified unknown Ai target '%s'", target)
			return 0
		}

		return 0
	}
}