コード例 #1
0
ファイル: script.go プロジェクト: FlyingCar/haunts
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
	}
}
コード例 #2
0
ファイル: ui_select_map.go プロジェクト: RickDakan/haunts
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
}