func MakeHouseEditorPanel() Editor { var he HouseEditor he.house = *MakeHouseDef() he.HorizontalTable = gui.MakeHorizontalTable() he.viewer = MakeHouseViewer(&he.house, 62) he.viewer.Edit_mode = true he.HorizontalTable.AddChild(he.viewer) he.widgets = append(he.widgets, makeHouseDataTab(&he.house, he.viewer)) he.widgets = append(he.widgets, makeHouseDoorTab(&he.house, he.viewer)) he.widgets = append(he.widgets, makeHouseRelicsTab(&he.house, he.viewer)) var tabs []gui.Widget for _, w := range he.widgets { tabs = append(tabs, w.(gui.Widget)) } he.tab = gui.MakeTabFrame(tabs) he.HorizontalTable.AddChild(he.tab) return &he }
func MakeRoomEditorPanel() Editor { var rep RoomEditorPanel rep.HorizontalTable = gui.MakeHorizontalTable() rep.viewer = MakeRoomViewer(&rep.room, 65) rep.AddChild(rep.viewer) var tabs []gui.Widget rep.panels.furniture = makeFurniturePanel(&rep.room, rep.viewer) tabs = append(tabs, rep.panels.furniture) rep.widgets = append(rep.widgets, rep.panels.furniture) rep.panels.wall = MakeWallPanel(&rep.room, rep.viewer) tabs = append(tabs, rep.panels.wall) rep.widgets = append(rep.widgets, rep.panels.wall) rep.tab = gui.MakeTabFrame(tabs) rep.AddChild(rep.tab) rep.viewer.SetEditMode(editFurniture) return &rep }
func main() { sys = system.Make(gos.GetSystemInterface()) sys.Startup() wdx := 1000 wdy := 500 render.Init() var ui *gui.Gui render.Queue(func() { sys.CreateWindow(50, 150, wdx, wdy) sys.EnableVSync(true) err := gl.Init() if err != nil { f, err2 := os.Create(filepath.Join(datadir, "gl_log.txt")) if err2 != nil { fmt.Printf("Unable to write log to a file:%v\n%v\v", err, err2) } else { fmt.Fprintf(f, "%v\n", err) f.Close() } } ui, _ = gui.Make(gin.In(), gui.Dims{wdx, wdy}, filepath.Join(datadir, "fonts", "luxisr.ttf")) font, err := loadFont() if err != nil { panic(err.Error()) } dict = gui.MakeDictionary(font, 15) }) render.Purge() anchor := gui.MakeAnchorBox(gui.Dims{wdx, wdy}) ui.AddChild(anchor) var event_handler handler gin.In().RegisterEventListener(&event_handler) actions_list := gui.MakeVerticalTable() keyname_list := gui.MakeVerticalTable() both_lists := gui.MakeHorizontalTable() both_lists.AddChild(actions_list) both_lists.AddChild(keyname_list) anchor.AddChild(both_lists, gui.Anchor{1, 0.5, 1, 0.5}) var actions []string for action := range action_map { actions = append(actions, action) } sort.Strings(actions) for _, action := range actions { actions_list.AddChild(gui.MakeTextLine("standard", action, 150, 1, 1, 1, 1)) keyname_list.AddChild(gui.MakeTextLine("standard", commands[action].Cmd, 100, 1, 1, 1, 1)) } current_anim := gui.MakeTextLine("standard", "", 300, 1, 1, 1, 1) current_state := gui.MakeTextLine("standard", "", 300, 1, 1, 1, 1) frame_data := gui.MakeVerticalTable() frame_data.AddChild(current_anim) frame_data.AddChild(current_state) anchor.AddChild(frame_data, gui.Anchor{0, 1, 0, 1}) speed := 100 speed_text := gui.MakeTextLine("standard", "Speed: 100%", 150, 1, 1, 1, 1) anchor.AddChild(speed_text, gui.Anchor{0, 0, 0, 0}) var box1, box2 boxdata box1.name = "box1" box1.sb = makeSpriteBox(nil) anchor.AddChild(box1.sb, gui.Anchor{0.5, 0.5, 0.25, 0.5}) box1.load(GetStoreVal("box1")) box := box1 box2.name = "box2" box2.sb = makeSpriteBox(nil) anchor.AddChild(box2.sb, gui.Anchor{0.5, 0.5, 0.45, 0.5}) box2.load(GetStoreVal("box2")) box2.sb.top = true box_other := box2 box2.sb.r, box2.sb.g, box2.sb.b = 0.2, 0.1, 0.4 box1.sb.r, box1.sb.g, box1.sb.b = 0.4, 0.2, 0.8 error_msg = gui.MakeTextLine("standard", "", wdx, 1, 0.5, 0.5, 1) anchor.AddChild(error_msg, gui.Anchor{0, 0, 0, 0.1}) var chooser gui.Widget // curdir := GetStoreVal("curdir") // if curdir == "" { // curdir = "." // } else { // _,err := os.Stat(filepath.Join(datadir, curdir)) // if err == nil { // go func() { // anim, err := sprite.LoadSprite(filepath.Join(datadir, curdir)) // loaded <- loadResult{ anim, err } // } () // } else { // curdir = "." // } // } // var profile_output *os.File then := time.Now() sys.Think() for key_map["quit"].FramePressCount() == 0 { event_handler.box1 = &box event_handler.box2 = &box_other now := time.Now() dt := (now.Nanosecond() - then.Nanosecond()) / 1000000 then = now render.Queue(func() { sys.Think() if box1.sb.s != nil { box1.sb.s.Think(int64(float64(dt) * float64(speed) / 100)) } if box2.sb.s != nil { box2.sb.s.Think(int64(float64(dt) * float64(speed) / 100)) } gl.ClearColor(1, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT) ui.Draw() sys.SwapBuffers() }) render.Purge() select { case load := <-loaded: if load.err != nil { error_msg.SetText(load.err.Error()) current_anim.SetText("") } else { box.sb.s = load.anim error_msg.SetText("") } default: } // if box.sb.s != nil { // box.sb.s.Think() // current_anim.SetText(fmt.Sprintf("%d: %s", box.sb.s.Facing(), box.sb.s.Anim())) // current_state.SetText(box.sb.s.AnimState()) // } if box.sb.s != nil { if key_map["reset"].FramePressCount() > 0 { box.load(box.dir) box_other.load(box_other.dir) } } // if key_map["profile"].FramePressCount() > 0 { // if profile_output == nil { // var err error // profile_output, err = os.Create(filepath.Join(datadir, "cpu.prof")) // if err == nil { // err = pprof.StartCPUProfile(profile_output) // if err != nil { // fmt.Printf("Unable to start CPU profile: %v\n", err) // profile_output.Close() // profile_output = nil // } // fmt.Printf("profout: %v\n", profile_output) // } else { // fmt.Printf("Unable to open CPU profile: %v\n", err) // } // } else { // pprof.StopCPUProfile() // profile_output.Close() // profile_output = nil // } // } if key_map["load"].FramePressCount() > 0 && chooser == nil { anch := gui.MakeAnchorBox(gui.Dims{wdx, wdy}) file_chooser := gui.MakeFileChooser(filepath.Join(datadir, box.dir), func(path string, err error) { if err == nil && len(path) > 0 { curpath, _ := filepath.Split(path) box.load(curpath) } ui.RemoveChild(chooser) chooser = nil }, func(path string, is_dir bool) bool { return true }) anch.AddChild(file_chooser, gui.Anchor{0.5, 0.5, 0.5, 0.5}) chooser = anch ui.AddChild(chooser) } delta := key_map["speed up"].FramePressAmt() - key_map["slow down"].FramePressAmt() if delta != 0 { speed += int(delta) if speed < 1 { speed = 1 } if speed > 100 { speed = 100 } speed_text.SetText(fmt.Sprintf("Speed: %d%%", speed)) } if key_map["select1"].FramePressCount() > 0 { box2.sb.r, box2.sb.g, box2.sb.b = 0.2, 0.1, 0.4 box1.sb.r, box1.sb.g, box1.sb.b = 0.4, 0.2, 0.8 box = box1 box_other = box2 } if key_map["select2"].FramePressCount() > 0 { box2.sb.r, box2.sb.g, box2.sb.b = 0.4, 0.2, 0.8 box1.sb.r, box1.sb.g, box1.sb.b = 0.2, 0.1, 0.4 box = box2 box_other = box1 } } }