示例#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)

	var args []string
	algorithm.Map2(tags.RoomSizes, &args, func(a RoomSize) string { return a.String() })
	fp.room_size = gui.MakeComboTextBox(args, 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
}
示例#2
0
文件: house.go 项目: genbattle/haunts
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())
}
示例#3
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())
}
示例#4
0
文件: house.go 项目: genbattle/haunts
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
}