示例#1
0
func loadHouse(gp *GamePanel) lua.GoFunction {
	return func(L *lua.State) int {
		if !LuaCheckParamsOk(L, "LoadHouse", LuaString) {
			return 0
		}
		gp.script.syncStart()
		defer gp.script.syncEnd()

		name := L.ToString(-1)
		def := house.MakeHouseFromName(name)
		if def == nil || len(def.Floors) == 0 {
			base.Error().Printf("No house exists with the name '%s'.", name)
			return 0
		}
		gp.game = makeGame(def)
		gp.game.viewer.Edit_mode = true
		gp.game.script = gp.script
		base.Log().Printf("script = %p", gp.game.script)

		gp.AnchorBox = gui.MakeAnchorBox(gui.Dims{1024, 768})
		gp.AnchorBox.AddChild(gp.game.viewer, gui.Anchor{0.5, 0.5, 0.5, 0.5})
		gp.AnchorBox.AddChild(MakeOverlay(gp.game), gui.Anchor{0.5, 0.5, 0.5, 0.5})

		base.Log().Printf("Done making stuff")
		return 0
	}
}
示例#2
0
func MakeUiSelectMap(gp *GamePanel) (gui.Widget, <-chan string, error) {
	var ui UiSelectMap

	datadir := base.GetDataDir()
	err := base.LoadAndProcessObject(filepath.Join(datadir, "ui", "select_map", "config.json"), "json", &ui.layout)
	if err != nil {
		return nil, nil, err
	}

	ui.region.Dx = 1024
	ui.region.Dy = 768
	var options []hui.Option
	// TODO: may want to reload the registry on this one?  If we want to pik up
	// new changes to files that is.
	for _, name := range base.GetAllNamesInRegistry("houses") {
		var mo MapOption
		mo.house_def = house.MakeHouseFromName(name)
		mo.layout = &ui.layout
		options = append(options, &mo)
	}
	out := make(chan string, 2)
	chooser := hui.MakeRosterChooser(options, hui.SelectExactlyOne, func(m map[int]bool) {
		var index int
		base.Log().Printf("On complete: %v", m)
		for index = range m {
			out <- options[index].(*MapOption).house_def.Name
			base.Log().Printf("Sent '%s'", options[index].(*MapOption).house_def.Name)
			break
		}
		base.Log().Printf("Closing")
		close(out)
	},
		nil)
	ui.chooser = chooser

	return &ui, out, nil
}