From 2d55d25eaa27227c306c97928f8ca5205a7e63e3 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Thu, 31 Oct 2013 21:07:34 +0100 Subject: Preparing editable biomes. Most stuff doesnt update correctly now... --- biome_infos.go | 367 +++++++++++++++++++++++++----------------------------- colbuf.go | 17 +++ main.go | 88 ++++++++----- mapwidget.go | 10 +- region_wrapper.go | 16 +-- test.biomes | 3 + 6 files changed, 264 insertions(+), 237 deletions(-) create mode 100644 colbuf.go create mode 100644 test.biomes diff --git a/biome_infos.go b/biome_infos.go index c45294c..b552328 100644 --- a/biome_infos.go +++ b/biome_infos.go @@ -1,206 +1,185 @@ package main import ( + "bufio" + "fmt" "github.com/kch42/gomcmap/mcmap" "github.com/mattn/go-gtk/gdk" + "io" + "strconv" + "strings" ) -var bioList = []mcmap.Biome{ - mcmap.BioOcean, - mcmap.BioPlains, - mcmap.BioDesert, - mcmap.BioExtremeHills, - mcmap.BioForest, - mcmap.BioTaiga, - mcmap.BioSwampland, - mcmap.BioRiver, - mcmap.BioHell, - mcmap.BioSky, - mcmap.BioFrozenOcean, - mcmap.BioFrozenRiver, - mcmap.BioIcePlains, - mcmap.BioIceMountains, - mcmap.BioMushroomIsland, - mcmap.BioMushroomIslandShore, - mcmap.BioBeach, - mcmap.BioDesertHills, - mcmap.BioForestHills, - mcmap.BioTaigaHills, - mcmap.BioExtremeHillsEdge, - mcmap.BioJungle, - mcmap.BioJungleHills, - mcmap.BioJungleEdge, - mcmap.BioDeepOcean, - mcmap.BioStoneBeach, - mcmap.BioColdBeach, - mcmap.BioBirchForest, - mcmap.BioBirchForestHills, - mcmap.BioRoofedForest, - mcmap.BioColdTaiga, - mcmap.BioColdTaigaHills, - mcmap.BioMegaTaiga, - mcmap.BioMegaTaigaHills, - mcmap.BioExtremeHillsPlus, - mcmap.BioSavanna, - mcmap.BioSavannaPlateau, - mcmap.BioMesa, - mcmap.BioMesaPlateauF, - mcmap.BioMesaPlateau, - mcmap.BioSunflowerPlains, - mcmap.BioDesertM, - mcmap.BioExtremeHillsM, - mcmap.BioFlowerForest, - mcmap.BioTaigaM, - mcmap.BioSwamplandM, - mcmap.BioIcePlainsSpikes, - mcmap.BioIceMountainsSpikes, - mcmap.BioJungleM, - mcmap.BioJungleEdgeM, - mcmap.BioBirchForestM, - mcmap.BioBirchForestHillsM, - mcmap.BioRoofedForestM, - mcmap.BioColdTaigaM, - mcmap.BioMegaSpruceTaiga, - mcmap.BioMegaSpruceTaigaHills, - mcmap.BioExtremeHillsPlusM, - mcmap.BioSavannaM, - mcmap.BioSavannaPlateauM, - mcmap.BioMesaBryce, - mcmap.BioMesaPlateauFM, - mcmap.BioMesaPlateauM, - mcmap.BioUncalculated, +type BiomeInfo struct { + ID mcmap.Biome + SnowLine int + Color string + Name string } -var bioColors = map[mcmap.Biome]*gdk.Color{ - mcmap.BioOcean: gdk.NewColor("#0000ff"), - mcmap.BioPlains: gdk.NewColor("#9fe804"), - mcmap.BioDesert: gdk.NewColor("#f5ff58"), - mcmap.BioExtremeHills: gdk.NewColor("#a75300"), - mcmap.BioForest: gdk.NewColor("#006f2a"), - mcmap.BioTaiga: gdk.NewColor("#05795a"), - mcmap.BioSwampland: gdk.NewColor("#6a7905"), - mcmap.BioRiver: gdk.NewColor("#196eff"), - mcmap.BioHell: gdk.NewColor("#d71900"), - mcmap.BioSky: gdk.NewColor("#871eb3"), - mcmap.BioFrozenOcean: gdk.NewColor("#d6f0ff"), - mcmap.BioFrozenRiver: gdk.NewColor("#8fb6cd"), - mcmap.BioIcePlains: gdk.NewColor("#fbfbfb"), - mcmap.BioIceMountains: gdk.NewColor("#c6bfb1"), - mcmap.BioMushroomIsland: gdk.NewColor("#9776a4"), - mcmap.BioMushroomIslandShore: gdk.NewColor("#9e8ebc"), - mcmap.BioBeach: gdk.NewColor("#fffdc9"), - mcmap.BioDesertHills: gdk.NewColor("#adb354"), - mcmap.BioForestHills: gdk.NewColor("#40694f"), - mcmap.BioTaigaHills: gdk.NewColor("#5b8578"), - mcmap.BioExtremeHillsEdge: gdk.NewColor("#a77748"), - mcmap.BioJungle: gdk.NewColor("#22db04"), - mcmap.BioJungleHills: gdk.NewColor("#63bf54"), - mcmap.BioJungleEdge: gdk.NewColor("#40ba2c"), - mcmap.BioDeepOcean: gdk.NewColor("#0000b3"), - mcmap.BioStoneBeach: gdk.NewColor("#9292a6"), - mcmap.BioColdBeach: gdk.NewColor("#c7c7e8"), - mcmap.BioBirchForest: gdk.NewColor("#1d964b"), - mcmap.BioBirchForestHills: gdk.NewColor("#498045"), - mcmap.BioRoofedForest: gdk.NewColor("#075a26"), - mcmap.BioColdTaiga: gdk.NewColor("#1b948e"), - mcmap.BioColdTaigaHills: gdk.NewColor("#1d7a76"), - mcmap.BioMegaTaiga: gdk.NewColor("#1f8f68"), - mcmap.BioMegaTaigaHills: gdk.NewColor("#217a5c"), - mcmap.BioExtremeHillsPlus: gdk.NewColor("#d76a00"), - mcmap.BioSavanna: gdk.NewColor("#b2bc0f"), - mcmap.BioSavannaPlateau: gdk.NewColor("#aba60e"), - mcmap.BioMesa: gdk.NewColor("#ff6c00"), - mcmap.BioMesaPlateauF: gdk.NewColor("#d9691e"), - mcmap.BioMesaPlateau: gdk.NewColor("#d95b07"), - mcmap.BioSunflowerPlains: gdk.NewColor("#ffd504"), - mcmap.BioDesertM: gdk.NewColor("#f4ff3f"), - mcmap.BioExtremeHillsM: gdk.NewColor("#8c4500"), - mcmap.BioFlowerForest: gdk.NewColor("#e02f4a"), - mcmap.BioTaigaM: gdk.NewColor("#0a6148"), - mcmap.BioSwamplandM: gdk.NewColor("#58630e"), - mcmap.BioIcePlainsSpikes: gdk.NewColor("#ace8e8"), - mcmap.BioIceMountainsSpikes: gdk.NewColor("#91cccc"), - mcmap.BioJungleM: gdk.NewColor("#30ba07"), - mcmap.BioJungleEdgeM: gdk.NewColor("#3e9130"), - mcmap.BioBirchForestM: gdk.NewColor("#228548"), - mcmap.BioBirchForestHillsM: gdk.NewColor("#2b7547"), - mcmap.BioRoofedForestM: gdk.NewColor("#1a5428"), - mcmap.BioColdTaigaM: gdk.NewColor("#0f706b"), - mcmap.BioMegaSpruceTaiga: gdk.NewColor("#198058"), - mcmap.BioMegaSpruceTaigaHills: gdk.NewColor("#156e4c"), - mcmap.BioExtremeHillsPlusM: gdk.NewColor("#ba5c00"), - mcmap.BioSavannaM: gdk.NewColor("#858111"), - mcmap.BioSavannaPlateauM: gdk.NewColor("#87830b"), - mcmap.BioMesaBryce: gdk.NewColor("#ff5100"), - mcmap.BioMesaPlateauFM: gdk.NewColor("#ba5a1a"), - mcmap.BioMesaPlateauM: gdk.NewColor("#ba4e06"), - mcmap.BioUncalculated: gdk.NewColor("#333333"), +func ReadBiomeInfos(r io.Reader) ([]BiomeInfo, error) { + var biomes []BiomeInfo + + sc := bufio.NewScanner(r) + for i := 1; sc.Scan(); i++ { + line := sc.Text() + if line == "" { + continue + } + parts := strings.SplitN(line, "\t", 4) + + if len(parts) != 4 { + return nil, fmt.Errorf("Line %d corrupted: Not enough parts", i) + } + + id, err := strconv.ParseUint(parts[0], 10, 8) + if err != nil { + return nil, fmt.Errorf("Line %d corrupted: %s", i, err) + } + + snow, err := strconv.ParseInt(parts[1], 10, 32) + if err != nil { + return nil, fmt.Errorf("Line %d corrupted: %s", i, err) + } + if (snow >= mcmap.ChunkSizeY) || (snow < 0) { + snow = mcmap.ChunkSizeY + } + + info := BiomeInfo{ + ID: mcmap.Biome(id), + SnowLine: int(snow), + Color: parts[2], + Name: parts[3], + } + fmt.Println(info) + biomes = append(biomes, info) + } + + if err := sc.Err(); err != nil { + return nil, err + } + + return biomes, nil } -// snowLines maps a biome to the lowest y coordinate that can have snow naturally. -// TODO: Get the actual values that Minecraft uses (could not find them). -var snowLines = map[mcmap.Biome]int{ - mcmap.BioOcean: mcmap.ChunkSizeY, - mcmap.BioPlains: mcmap.ChunkSizeY, - mcmap.BioDesert: mcmap.ChunkSizeY, - mcmap.BioExtremeHills: 95, - mcmap.BioForest: mcmap.ChunkSizeY, - mcmap.BioTaiga: mcmap.ChunkSizeY, - mcmap.BioSwampland: mcmap.ChunkSizeY, - mcmap.BioRiver: mcmap.ChunkSizeY, - mcmap.BioHell: mcmap.ChunkSizeY, - mcmap.BioSky: mcmap.ChunkSizeY, - mcmap.BioFrozenOcean: 0, - mcmap.BioFrozenRiver: 0, - mcmap.BioIcePlains: 0, - mcmap.BioIceMountains: 0, - mcmap.BioMushroomIsland: mcmap.ChunkSizeY, - mcmap.BioMushroomIslandShore: mcmap.ChunkSizeY, - mcmap.BioBeach: mcmap.ChunkSizeY, - mcmap.BioDesertHills: mcmap.ChunkSizeY, - mcmap.BioForestHills: mcmap.ChunkSizeY, - mcmap.BioTaigaHills: 0, - mcmap.BioExtremeHillsEdge: 95, - mcmap.BioJungle: mcmap.ChunkSizeY, - mcmap.BioJungleHills: mcmap.ChunkSizeY, - mcmap.BioJungleEdge: mcmap.ChunkSizeY, - mcmap.BioDeepOcean: mcmap.ChunkSizeY, - mcmap.BioStoneBeach: mcmap.ChunkSizeY, - mcmap.BioColdBeach: 0, - mcmap.BioBirchForest: mcmap.ChunkSizeY, - mcmap.BioBirchForestHills: mcmap.ChunkSizeY, - mcmap.BioRoofedForest: mcmap.ChunkSizeY, - mcmap.BioColdTaiga: 0, - mcmap.BioColdTaigaHills: 0, - mcmap.BioMegaTaiga: mcmap.ChunkSizeY, - mcmap.BioMegaTaigaHills: mcmap.ChunkSizeY, - mcmap.BioExtremeHillsPlus: 95, - mcmap.BioSavanna: mcmap.ChunkSizeY, - mcmap.BioSavannaPlateau: mcmap.ChunkSizeY, - mcmap.BioMesa: mcmap.ChunkSizeY, - mcmap.BioMesaPlateauF: mcmap.ChunkSizeY, - mcmap.BioMesaPlateau: mcmap.ChunkSizeY, - mcmap.BioSunflowerPlains: mcmap.ChunkSizeY, - mcmap.BioDesertM: mcmap.ChunkSizeY, - mcmap.BioExtremeHillsM: 95, - mcmap.BioFlowerForest: mcmap.ChunkSizeY, - mcmap.BioTaigaM: mcmap.ChunkSizeY, - mcmap.BioSwamplandM: mcmap.ChunkSizeY, - mcmap.BioIcePlainsSpikes: 0, - mcmap.BioIceMountainsSpikes: 0, - mcmap.BioJungleM: mcmap.ChunkSizeY, - mcmap.BioJungleEdgeM: mcmap.ChunkSizeY, - mcmap.BioBirchForestM: mcmap.ChunkSizeY, - mcmap.BioBirchForestHillsM: mcmap.ChunkSizeY, - mcmap.BioRoofedForestM: mcmap.ChunkSizeY, - mcmap.BioColdTaigaM: 0, - mcmap.BioMegaSpruceTaiga: mcmap.ChunkSizeY, - mcmap.BioMegaSpruceTaigaHills: mcmap.ChunkSizeY, - mcmap.BioExtremeHillsPlusM: 95, - mcmap.BioSavannaM: mcmap.ChunkSizeY, - mcmap.BioSavannaPlateauM: mcmap.ChunkSizeY, - mcmap.BioMesaBryce: mcmap.ChunkSizeY, - mcmap.BioMesaPlateauFM: mcmap.ChunkSizeY, - mcmap.BioMesaPlateauM: mcmap.ChunkSizeY, - mcmap.BioUncalculated: mcmap.ChunkSizeY, +func WriteBiomeInfos(biomes []BiomeInfo, w io.Writer) error { + for _, bio := range biomes { + if _, err := fmt.Fprintf(w, "%d\t%d\t%s\t%s\n", bio.ID, bio.SnowLine, bio.Color, bio.Name); err != nil { + return err + } + } + + return nil +} + +type BiomeLookup map[mcmap.Biome]BiomeInfo + +var colBlack = gdk.NewColor("#000000") +var colBuf = make(ColorBuffer) + +func (bl BiomeLookup) Color(bio mcmap.Biome) *gdk.Color { + if info, ok := bl[bio]; ok { + return colBuf.Color(info.Color) + } + + fmt.Println("FAIL") + return colBlack +} + +func (bl BiomeLookup) SnowLine(bio mcmap.Biome) int { + if info, ok := bl[bio]; ok { + return info.SnowLine + } + + return mcmap.ChunkSizeY +} + +func (bl BiomeLookup) Name(bio mcmap.Biome) string { + if info, ok := bl[bio]; ok { + return info.Name + } + + return "?" +} + +func MkBiomeLookup(biomes []BiomeInfo) BiomeLookup { + lookup := make(BiomeLookup) + for _, biome := range biomes { + lookup[biome.ID] = biome + } + return lookup +} + +var defaultBiomes = `0 -1 #0000ff Ocean +1 -1 #9fe804 Plains +2 -1 #f5ff58 Desert +3 95 #a75300 Extreme Hills +4 -1 #006f2a Forest +5 -1 #05795a Taiga +6 -1 #6a7905 Swampland +7 -1 #196eff River +8 -1 #d71900 Hell +9 -1 #871eb3 Sky +10 0 #d6f0ff Frozen Ocean +11 0 #8fb6cd Frozen River +12 0 #fbfbfb Ice Plains +13 0 #c6bfb1 Ice Mountains +14 -1 #9776a4 Mushroom Island +15 -1 #9e8ebc Mushroom Island Shore +16 -1 #fffdc9 Beach +17 -1 #adb354 Desert Hills +18 -1 #40694f Forest Hills +19 0 #5b8578 Taiga Hills +20 95 #a77748 Extreme Hills Edge +21 -1 #22db04 Jungle +22 -1 #63bf54 Jungle Hills +23 -1 #40ba2c Jungle Edge +24 -1 #0000b3 Deep Ocean +25 -1 #9292a6 Stone Beach +26 0 #c7c7e8 Cold Beach +27 -1 #1d964b Birch Forest +28 -1 #498045 Birch Forest Hills +29 -1 #075a26 Roofed Forest +30 0 #1b948e Cold Taiga +31 0 #1d7a76 Cold Taiga Hills +32 -1 #1f8f68 Mega Taiga +33 -1 #217a5c Mega Taiga Hills +34 95 #d76a00 Extreme Hills+ +35 -1 #b2bc0f Savanna +36 -1 #aba60e Savanna Plateau +37 -1 #ff6c00 Mesa +38 -1 #d9691e Mesa Plateau F +39 -1 #d95b07 Mesa Plateau +40 -1 #ffd504 Sunflower Plains +41 -1 #f4ff3f Desert M +42 95 #8c4500 Extreme Hills M +43 -1 #e02f4a Flower Forest +44 -1 #0a6148 Taiga M +45 -1 #58630e Swampland M +46 0 #ace8e8 Ice Plains Spikes +47 0 #91cccc Ice Mountains Spikes +48 -1 #30ba07 Jungle M +49 -1 #3e9130 JungleEdge M +50 -1 #228548 Birch Forest M +51 -1 #2b7547 Birch Forest Hills M +52 -1 #1a5428 Roofed Forest M +53 0 #0f706b Cold Taiga M +54 -1 #198058 Mega Spruce Taiga +55 -1 #156e4c Mega Spruce Taiga Hills +56 95 #ba5c00 Extreme Hills+ M +57 -1 #858111 Savanna M +58 -1 #87830b Savanna Plateau M +59 -1 #ff5100 Mesa (Bryce) +60 -1 #ba5a1a Mesa Plateau F M +61 -1 #ba4e06 Mesa Plateau M +255 -1 #333333 (Uncalculated) +` + +func ReadDefaultBiomes() []BiomeInfo { + r := strings.NewReader(defaultBiomes) + biomes, err := ReadBiomeInfos(r) + if err != nil { + panic(err) + } + return biomes } diff --git a/colbuf.go b/colbuf.go new file mode 100644 index 0000000..429bf6c --- /dev/null +++ b/colbuf.go @@ -0,0 +1,17 @@ +package main + +import ( + "github.com/mattn/go-gtk/gdk" +) + +type ColorBuffer map[string]*gdk.Color + +func (cb ColorBuffer) Color(name string) *gdk.Color { + if col, ok := cb[name]; ok { + return col + } + + col := gdk.NewColor(name) + cb[name] = col + return col +} diff --git a/main.go b/main.go index 1351c27..11468b8 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,11 @@ type GUI struct { statusContext uint lastStatus string + sbVBox *gtk.VBox + + biomes []BiomeInfo + bioVBox *gtk.VBox + mapw *MapWidget } @@ -99,20 +104,23 @@ func (g *GUI) mkMenuBar() *gtk.MenuBar { quit.Connect("activate", g.exitApp) fileMenu.Append(quit) + foo := gtk.NewMenuItemWithLabel("Foo") + foo.Connect("activate", func() { + f, _ := os.Open("test.biomes") + defer f.Close() + biomes, err := ReadBiomeInfos(f) + if err != nil { + panic(err) + } + g.biomes = biomes + g.updateBiomeInfo() + }) + fileMenu.Append(foo) + fileMenuItem := gtk.NewMenuItemWithLabel("File") fileMenuItem.SetSubmenu(fileMenu) menubar.Append(fileMenuItem) - /*editMenu := gtk.NewMenu() - - undo := gtk.NewMenuItemWithLabel("Undo") - undo.Connect("activate", g.undo) - editMenu.Append(undo) - - editMenuItem := gtk.NewMenuItemWithLabel("Edit") - editMenuItem.SetSubmenu(editMenu) - menubar.Append(editMenuItem)*/ - helpMenu := gtk.NewMenu() controls := gtk.NewMenuItemWithLabel("Controls") @@ -174,19 +182,19 @@ func labelCustomFont(text, font string) *gtk.Label { } func (g *GUI) mkSidebar() *gtk.ScrolledWindow { - vbox := gtk.NewVBox(false, 0) + g.sbVBox = gtk.NewVBox(false, 0) - vbox.PackStart(labelCustomFont("Tools", "Sans Bold 14"), false, false, 3) + g.sbVBox.PackStart(labelCustomFont("Tools", "Sans Bold 14"), false, false, 3) g.showbiomes = gtk.NewCheckButtonWithLabel("Show Biomes") g.showbiomes.SetActive(true) g.showbiomes.Connect("toggled", g.showbiomesToggled) - vbox.PackStart(g.showbiomes, false, false, 3) + g.sbVBox.PackStart(g.showbiomes, false, false, 3) g.fixSnowIce = gtk.NewCheckButtonWithLabel("Fix Snow/Ice") g.fixSnowIce.SetTooltipText("Add Snow/Ice for Taiga/Ice Plains. Remove Snow/Ice for other biomes.") g.fixSnowIce.Connect("toggled", g.fixSnowIceToggled) - vbox.PackStart(g.fixSnowIce, false, false, 3) + g.sbVBox.PackStart(g.fixSnowIce, false, false, 3) fill := gtk.NewRadioButtonWithLabel(nil, "Fill") fill.SetActive(true) @@ -200,32 +208,50 @@ func (g *GUI) mkSidebar() *gtk.ScrolledWindow { drawHBox.PackEnd(drawRadius, false, false, 3) draw.Connect("toggled", g.mkUpdateToolFx(draw, NewDrawTool(func() int { return drawRadius.GetValueAsInt() }))) - vbox.PackStart(fill, false, false, 3) - vbox.PackStart(drawHBox, false, false, 3) + g.sbVBox.PackStart(fill, false, false, 3) + g.sbVBox.PackStart(drawHBox, false, false, 3) - vbox.PackStart(gtk.NewHSeparator(), false, false, 3) - vbox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), false, false, 3) + g.sbVBox.PackStart(gtk.NewHSeparator(), false, false, 3) + g.sbVBox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), false, false, 3) + + g.bioVBox = gtk.NewVBox(false, 0) + g.sbVBox.PackStart(g.bioVBox, true, false, 3) + g.updateBiomeInfo() + + scrolled := gtk.NewScrolledWindow(nil, nil) + scrolled.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + scrolled.AddWithViewPort(g.sbVBox) + return scrolled +} +func (g *GUI) updateBiomeInfo() { + vbox := gtk.NewVBox(false, 0) var grp *glib.SList - for _, bio := range bioList { + + for _, biome := range g.biomes { biohbox := gtk.NewHBox(false, 0) - cbox := colorBox(bioColors[bio]) + cbox := colorBox(gdk.NewColor(biome.Color)) cbox.SetSizeRequest(20, 20) biohbox.PackStart(cbox, false, false, 3) - rbutton := gtk.NewRadioButtonWithLabel(grp, bio.String()) + rbutton := gtk.NewRadioButtonWithLabel(grp, biome.Name) grp = rbutton.GetGroup() - rbutton.Connect("toggled", g.mkUpdateBiomeFx(rbutton, bio)) + rbutton.Connect("toggled", g.mkUpdateBiomeFx(rbutton, biome.ID)) biohbox.PackEnd(rbutton, true, true, 3) vbox.PackStart(biohbox, false, false, 3) } - scrolled := gtk.NewScrolledWindow(nil, nil) - scrolled.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - scrolled.AddWithViewPort(vbox) - return scrolled + g.sbVBox.Remove(g.bioVBox) + g.bioVBox.Destroy() + + g.sbVBox.PackStart(vbox, true, false, 3) + g.bioVBox = vbox + + // TODO: Update mapwidget } func (g *GUI) Init() { + g.biomes = ReadDefaultBiomes() + g.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL) g.window.SetTitle("biomed") @@ -235,7 +261,7 @@ func (g *GUI) Init() { hbox := gtk.NewHBox(false, 0) - g.mapw = NewMapWidget(GUICallbacks{g.reportError, g.updateInfo, g.setBusy}) + g.mapw = NewMapWidget(GUICallbacks{g.reportError, g.updateInfo, g.setBusy}, MkBiomeLookup(g.biomes)) hbox.PackStart(g.mapw.DArea(), true, true, 3) sidebar := g.mkSidebar() @@ -273,8 +299,8 @@ func (g *GUI) reportError(msg string) { os.Exit(1) } -func (g *GUI) updateInfo(x, z int, bio mcmap.Biome) { - g.lastStatus = fmt.Sprintf("X:%d, Z:%d, Biome:%s", x, z, bio) +func (g *GUI) updateInfo(x, z int, bio mcmap.Biome, name string) { + g.lastStatus = fmt.Sprintf("X:%d, Z:%d, Biome: %s(%d)", x, z, name, bio) g.statusbar.Pop(g.statusContext) g.statusbar.Push(g.statusContext, g.lastStatus) } @@ -311,10 +337,6 @@ func (g *GUI) fixSnowIceToggled() { g.mapw.SetFixSnowIce(g.fixSnowIce.GetActive()) } -/*func (g *GUI) undo() { - fmt.Println("Undo") -}*/ - func (g *GUI) Show() { g.window.ShowAll() g.betaWarning() diff --git a/mapwidget.go b/mapwidget.go index cb8c874..116f069 100644 --- a/mapwidget.go +++ b/mapwidget.go @@ -16,7 +16,7 @@ const ( type GUICallbacks struct { reportFail func(msg string) - updateInfo func(x, z int, bio mcmap.Biome) + updateInfo func(x, z int, bio mcmap.Biome, name string) setBusy func(bool) } @@ -41,6 +41,8 @@ type MapWidget struct { bg *gdk.Pixmap regWrap *RegionWrapper + + bioLookup BiomeLookup } func (mw *MapWidget) calcChunkRect() { @@ -89,7 +91,7 @@ func (mw *MapWidget) movement(ctx *glib.CallbackContext) { if _bio, ok := mw.regWrap.GetBiomeAt(x, z); ok { bio = _bio } - mw.guicbs.updateInfo(x, z, bio) + mw.guicbs.updateInfo(x, z, bio, mw.bioLookup.Name(bio)) if mw.panning { if (mw.mx1 != -1) && (mw.my1 != -1) { @@ -231,7 +233,7 @@ func (mw *MapWidget) updateGUI() { mw.dArea.GetWindow().Invalidate(nil, false) } -func NewMapWidget(guicbs GUICallbacks) *MapWidget { +func NewMapWidget(guicbs GUICallbacks, bioLookup BiomeLookup) *MapWidget { dArea := gtk.NewDrawingArea() mw := &MapWidget{ @@ -240,9 +242,11 @@ func NewMapWidget(guicbs GUICallbacks) *MapWidget { showBiomes: true, mx1: -1, my1: -1, + bioLookup: bioLookup, } mw.regWrap = NewRegionWrapper(mw.updateGUI, guicbs) + mw.regWrap.bioLookup = bioLookup dArea.Connect("configure-event", mw.configure) dArea.Connect("expose-event", mw.expose) diff --git a/region_wrapper.go b/region_wrapper.go index bf23913..9a4d958 100644 --- a/region_wrapper.go +++ b/region_wrapper.go @@ -28,9 +28,11 @@ type RegionWrapper struct { bio mcmap.Biome startX, startZ, endX, endZ int + + bioLookup BiomeLookup } -func renderTile(chunk *mcmap.Chunk) (maptile, biotile *gdk.Pixmap, biocache []mcmap.Biome) { +func (rw *RegionWrapper) renderTile(chunk *mcmap.Chunk) (maptile, biotile *gdk.Pixmap, biocache []mcmap.Biome) { maptile = emptyPixmap(tileSize, tileSize, 24) mtDrawable := maptile.GetDrawable() mtGC := gdk.NewGC(mtDrawable) @@ -46,7 +48,7 @@ func renderTile(chunk *mcmap.Chunk) (maptile, biotile *gdk.Pixmap, biocache []mc scanX: for x := 0; x < mcmap.ChunkSizeXZ; x++ { bio := chunk.Biome(x, z) - btGC.SetRgbFgColor(bioColors[bio]) + btGC.SetRgbFgColor(rw.bioLookup.Color(bio)) btDrawable.DrawRectangle(btGC, true, x*zoom, z*zoom, zoom, zoom) biocache[i] = bio @@ -115,7 +117,7 @@ func (rw *RegionWrapper) tileUpdater() { return } - rw.Maptiles[pos], rw.Biotiles[pos], rw.bioCache[pos] = renderTile(chunk) + rw.Maptiles[pos], rw.Biotiles[pos], rw.bioCache[pos] = rw.renderTile(chunk) chunk.MarkUnused() rw.redraw() @@ -242,8 +244,8 @@ func (rw *RegionWrapper) GetBiomeAt(x, z int) (mcmap.Biome, bool) { return chunk.Biome(bx, bz), true } -func fixWeather(bio mcmap.Biome, bx, bz int, chunk *mcmap.Chunk) (newcol *gdk.Color) { - snowLine := snowLines[bio] +func (rw *RegionWrapper) fixWeather(bio mcmap.Biome, bx, bz int, chunk *mcmap.Chunk) (newcol *gdk.Color) { + snowLine := rw.bioLookup.SnowLine(bio) for y := mcmap.ChunkSizeY; y >= 0; y-- { blk := chunk.Block(bx, y, bz) @@ -306,7 +308,7 @@ func (rw *RegionWrapper) SetBiomeAt(x, z int, bio mcmap.Biome) { var newcol *gdk.Color if rw.fixSnowIce { - newcol = fixWeather(bio, bx, bz, chunk) + newcol = rw.fixWeather(bio, bx, bz, chunk) } chunk.MarkModified() @@ -322,7 +324,7 @@ func (rw *RegionWrapper) SetBiomeAt(x, z int, bio mcmap.Biome) { drawable := biotile.GetDrawable() gc := gdk.NewGC(drawable) - gc.SetRgbFgColor(bioColors[bio]) + gc.SetRgbFgColor(rw.bioLookup.Color(bio)) drawable.DrawRectangle(gc, true, bx*zoom, bz*zoom, zoom, zoom) if newcol != nil { diff --git a/test.biomes b/test.biomes new file mode 100644 index 0000000..07dcf6f --- /dev/null +++ b/test.biomes @@ -0,0 +1,3 @@ +0 10 #ff0000 Foo +1 20 #00ff00 Bar +2 30 #0000ff Baz -- cgit v1.2.3-70-g09d2 From 03eaf07bee24bb12319e53e090a19f2c2a05ad23 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 2 Nov 2013 14:26:18 +0100 Subject: New Biomes are now displayed in the sidebar. --- main.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 11468b8..288b59d 100644 --- a/main.go +++ b/main.go @@ -21,10 +21,9 @@ type GUI struct { statusContext uint lastStatus string - sbVBox *gtk.VBox - biomes []BiomeInfo bioVBox *gtk.VBox + bioVBoxWrap *gtk.VBox mapw *MapWidget } @@ -182,19 +181,19 @@ func labelCustomFont(text, font string) *gtk.Label { } func (g *GUI) mkSidebar() *gtk.ScrolledWindow { - g.sbVBox = gtk.NewVBox(false, 0) + sbVBox := gtk.NewVBox(false, 0) - g.sbVBox.PackStart(labelCustomFont("Tools", "Sans Bold 14"), false, false, 3) + sbVBox.PackStart(labelCustomFont("Tools", "Sans Bold 14"), false, false, 3) g.showbiomes = gtk.NewCheckButtonWithLabel("Show Biomes") g.showbiomes.SetActive(true) g.showbiomes.Connect("toggled", g.showbiomesToggled) - g.sbVBox.PackStart(g.showbiomes, false, false, 3) + sbVBox.PackStart(g.showbiomes, false, false, 3) g.fixSnowIce = gtk.NewCheckButtonWithLabel("Fix Snow/Ice") g.fixSnowIce.SetTooltipText("Add Snow/Ice for Taiga/Ice Plains. Remove Snow/Ice for other biomes.") g.fixSnowIce.Connect("toggled", g.fixSnowIceToggled) - g.sbVBox.PackStart(g.fixSnowIce, false, false, 3) + sbVBox.PackStart(g.fixSnowIce, false, false, 3) fill := gtk.NewRadioButtonWithLabel(nil, "Fill") fill.SetActive(true) @@ -208,19 +207,21 @@ func (g *GUI) mkSidebar() *gtk.ScrolledWindow { drawHBox.PackEnd(drawRadius, false, false, 3) draw.Connect("toggled", g.mkUpdateToolFx(draw, NewDrawTool(func() int { return drawRadius.GetValueAsInt() }))) - g.sbVBox.PackStart(fill, false, false, 3) - g.sbVBox.PackStart(drawHBox, false, false, 3) + sbVBox.PackStart(fill, false, false, 3) + sbVBox.PackStart(drawHBox, false, false, 3) - g.sbVBox.PackStart(gtk.NewHSeparator(), false, false, 3) - g.sbVBox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), false, false, 3) + sbVBox.PackStart(gtk.NewHSeparator(), false, false, 3) + sbVBox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), false, false, 3) + g.bioVBoxWrap = gtk.NewVBox(false, 0) g.bioVBox = gtk.NewVBox(false, 0) - g.sbVBox.PackStart(g.bioVBox, true, false, 3) + g.bioVBoxWrap.PackStart(g.bioVBox, false, false, 0) + sbVBox.PackStart(g.bioVBoxWrap, false, false, 3) g.updateBiomeInfo() scrolled := gtk.NewScrolledWindow(nil, nil) scrolled.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - scrolled.AddWithViewPort(g.sbVBox) + scrolled.AddWithViewPort(sbVBox) return scrolled } @@ -240,10 +241,9 @@ func (g *GUI) updateBiomeInfo() { vbox.PackStart(biohbox, false, false, 3) } - g.sbVBox.Remove(g.bioVBox) - g.bioVBox.Destroy() - - g.sbVBox.PackStart(vbox, true, false, 3) + g.bioVBoxWrap.Remove(g.bioVBox) + g.bioVBoxWrap.PackStart(vbox, false, false, 3) + vbox.ShowAll() g.bioVBox = vbox // TODO: Update mapwidget -- cgit v1.2.3-70-g09d2 From 63b964614135f6381b5d55828714efb3783dfd04 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 2 Nov 2013 14:47:26 +0100 Subject: New biome infos are now passed to mapwidget --- main.go | 6 +++--- mapwidget.go | 10 ++++++++++ region_wrapper.go | 8 ++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 288b59d..ba60c97 100644 --- a/main.go +++ b/main.go @@ -21,8 +21,8 @@ type GUI struct { statusContext uint lastStatus string - biomes []BiomeInfo - bioVBox *gtk.VBox + biomes []BiomeInfo + bioVBox *gtk.VBox bioVBoxWrap *gtk.VBox mapw *MapWidget @@ -246,7 +246,7 @@ func (g *GUI) updateBiomeInfo() { vbox.ShowAll() g.bioVBox = vbox - // TODO: Update mapwidget + g.mapw.updateBioLookup(MkBiomeLookup(g.biomes)) } func (g *GUI) Init() { diff --git a/mapwidget.go b/mapwidget.go index 116f069..e04b5eb 100644 --- a/mapwidget.go +++ b/mapwidget.go @@ -233,6 +233,16 @@ func (mw *MapWidget) updateGUI() { mw.dArea.GetWindow().Invalidate(nil, false) } +func (mw *MapWidget) updateBioLookup(lookup BiomeLookup) { + mw.bioLookup = lookup + mw.regWrap.bioLookup = lookup + + if mw.regWrap.RegionLoaded() { + mw.regWrap.FlushTiles() + mw.regWrap.UpdateTiles() + } +} + func NewMapWidget(guicbs GUICallbacks, bioLookup BiomeLookup) *MapWidget { dArea := gtk.NewDrawingArea() diff --git a/region_wrapper.go b/region_wrapper.go index 9a4d958..d27d1ad 100644 --- a/region_wrapper.go +++ b/region_wrapper.go @@ -131,11 +131,11 @@ func (rw *RegionWrapper) tileUpdater() { func (rw *RegionWrapper) SetRegion(region *mcmap.Region) { if rw.RegionLoaded() { - rw.flushTiles() + rw.FlushTiles() } rw.region = NewCachedRegion(region, cacheSize) - rw.tileUpdates <- true + rw.UpdateTiles() } func (rw *RegionWrapper) SetChunkBounds(startX, startZ, endX, endZ int) { @@ -152,7 +152,7 @@ func (rw *RegionWrapper) SetFixSnowIce(b bool) { rw.fixSnowIce = b } func (rw *RegionWrapper) RegionLoaded() bool { return rw.region != nil } func (rw *RegionWrapper) ToolSingleClick() bool { return rw.tool.SingleClick() } -func (rw *RegionWrapper) flushTiles() { +func (rw *RegionWrapper) FlushTiles() { if err := rw.region.Flush(); err != nil { rw.guicbs.reportFail(fmt.Sprintf("Error while flushing cache: %s", err)) return @@ -171,7 +171,7 @@ func (rw *RegionWrapper) flushTiles() { } func (rw *RegionWrapper) Save() { - rw.flushTiles() + rw.FlushTiles() if err := rw.region.Flush(); err != nil { rw.guicbs.reportFail(fmt.Sprintf("Error while flushing cache: %s", err)) -- cgit v1.2.3-70-g09d2 From 2ac5529a8973c262ddc5674f5846a6b293ca0ce1 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 2 Nov 2013 16:27:28 +0100 Subject: Removed some debug code. --- biome_infos.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/biome_infos.go b/biome_infos.go index b552328..4c137af 100644 --- a/biome_infos.go +++ b/biome_infos.go @@ -44,14 +44,13 @@ func ReadBiomeInfos(r io.Reader) ([]BiomeInfo, error) { if (snow >= mcmap.ChunkSizeY) || (snow < 0) { snow = mcmap.ChunkSizeY } - + info := BiomeInfo{ ID: mcmap.Biome(id), SnowLine: int(snow), Color: parts[2], Name: parts[3], } - fmt.Println(info) biomes = append(biomes, info) } @@ -82,7 +81,6 @@ func (bl BiomeLookup) Color(bio mcmap.Biome) *gdk.Color { return colBuf.Color(info.Color) } - fmt.Println("FAIL") return colBlack } -- cgit v1.2.3-70-g09d2 From 613c8855cd8fcace4b7ba4f6662bd0486e9ad5f1 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 2 Nov 2013 17:54:32 +0100 Subject: New menu items --- main.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index ba60c97..75409e1 100644 --- a/main.go +++ b/main.go @@ -103,23 +103,23 @@ func (g *GUI) mkMenuBar() *gtk.MenuBar { quit.Connect("activate", g.exitApp) fileMenu.Append(quit) - foo := gtk.NewMenuItemWithLabel("Foo") - foo.Connect("activate", func() { - f, _ := os.Open("test.biomes") - defer f.Close() - biomes, err := ReadBiomeInfos(f) - if err != nil { - panic(err) - } - g.biomes = biomes - g.updateBiomeInfo() - }) - fileMenu.Append(foo) - fileMenuItem := gtk.NewMenuItemWithLabel("File") fileMenuItem.SetSubmenu(fileMenu) menubar.Append(fileMenuItem) + prefMenu := gtk.NewMenu() + + confbiomes := gtk.NewMenuItemWithLabel("Configure Biomes") + confbiomes.Connect("activate", func() { + // TODO: Display awesome biome editor dialog thing. + fmt.Println("(...)") + }) + prefMenu.Append(confbiomes) + + prefMenuItem := gtk.NewMenuItemWithLabel("Preferences") + prefMenuItem.SetSubmenu(prefMenu) + menubar.Append(prefMenuItem) + helpMenu := gtk.NewMenu() controls := gtk.NewMenuItemWithLabel("Controls") -- cgit v1.2.3-70-g09d2 From 01ccc633dce5cf9880bebe5f4ffe655386b73a34 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sun, 3 Nov 2013 15:36:19 +0100 Subject: Started working on the biome info editor --- biome_info_editor.go | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 9 ++- 2 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 biome_info_editor.go diff --git a/biome_info_editor.go b/biome_info_editor.go new file mode 100644 index 0000000..9768f61 --- /dev/null +++ b/biome_info_editor.go @@ -0,0 +1,159 @@ +package main + +import ( + "fmt" + "github.com/kch42/gomcmap/mcmap" + "github.com/kch42/kagus" + "github.com/mattn/go-gtk/gdk" + "github.com/mattn/go-gtk/gtk" + "strconv" + "unicode" +) + +type biomeEditFrame struct { + *gtk.Frame + applyBtn *gtk.Button + idInput, snowLineInput, nameInput *gtk.Entry + colorInput *gtk.ColorButton +} + +func newBiomeEditFrame() *biomeEditFrame { + frm := &biomeEditFrame{ + Frame: gtk.NewFrame("Edit Biome"), + applyBtn: gtk.NewButtonWithLabel("Apply"), + idInput: gtk.NewEntry(), + snowLineInput: gtk.NewEntry(), + nameInput: gtk.NewEntry(), + colorInput: gtk.NewColorButton(), + } + + frm.idInput.SetSizeRequest(40, -1) + frm.snowLineInput.SetSizeRequest(40, -1) + + frm.idInput.Connect("changed", frm.unlockApply) + frm.nameInput.Connect("changed", frm.unlockApply) + frm.snowLineInput.Connect("changed", frm.unlockApply) + frm.applyBtn.SetSensitive(false) + + vbox := gtk.NewVBox(false, 0) + hbox := gtk.NewHBox(false, 0) + + hbox.PackStart(gtk.NewLabel("Color:"), false, false, 0) + hbox.PackStart(frm.colorInput, false, false, 3) + hbox.PackStart(gtk.NewLabel("ID:"), false, false, 0) + hbox.PackStart(frm.idInput, false, false, 3) + hbox.PackStart(gtk.NewLabel("Snowline:"), false, false, 0) + hbox.PackStart(frm.snowLineInput, false, false, 3) + hbox.PackStart(gtk.NewLabel("Name:"), false, false, 0) + hbox.PackStart(frm.nameInput, true, true, 3) + + vbox.PackStart(hbox, false, false, 0) + vbox.PackStart(frm.applyBtn, false, false, 3) + frm.Add(vbox) + + return frm +} + +func (frm *biomeEditFrame) setBiomeInfo(info BiomeInfo) { + frm.colorInput.SetColor(gdk.NewColor(info.Color)) + frm.idInput.SetText(strconv.FormatInt(int64(info.ID), 10)) + frm.snowLineInput.SetText(strconv.FormatInt(int64(info.SnowLine), 10)) + frm.nameInput.SetText(info.Name) +} + +func (frm *biomeEditFrame) getBiomeInfo() (BiomeInfo, bool) { + id, err := strconv.ParseUint(frm.idInput.GetText(), 10, 8) + if err != nil { + return BiomeInfo{}, false + } + + snow, err := strconv.ParseInt(frm.snowLineInput.GetText(), 10, 32) + if err != nil { + return BiomeInfo{}, false + } + if (snow > mcmap.ChunkSizeY) || (snow < 0) { + snow = mcmap.ChunkSizeY + } + + name := frm.nameInput.GetText() + if name != "" { + return BiomeInfo{}, false + } + + col := frm.colorInput.GetColor() + + return BiomeInfo{ + ID: mcmap.Biome(id), + SnowLine: int(snow), + Name: name, + Color: fmt.Sprintf("#%02x%02x%02x", col.Red()<<8, col.Green()<<8, col.Blue()<<8), + }, true +} + +func (frm *biomeEditFrame) checkOK() bool { + if id := frm.idInput.GetText(); (id == "") || (!kagus.StringConsistsOf(id, unicode.IsNumber)) { + return false + } + + if snow := frm.snowLineInput.GetText(); (snow == "") || (!kagus.StringConsistsOf(snow, unicode.IsNumber)) { + return false + } + + return frm.nameInput.GetText() != "" +} + +func (frm *biomeEditFrame) unlockApply() { + frm.applyBtn.SetSensitive(frm.checkOK()) +} + +type BiomeInfoEditor struct { + *gtk.Dialog + biomes []BiomeInfo +} + +func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor { + ed := &BiomeInfoEditor{ + Dialog: gtk.NewDialog(), + biomes: biomes, + } + + ed.SetModal(true) + vbox := ed.GetVBox() + + btnHBox := gtk.NewHBox(true, 0) + + resetBtn := gtk.NewButtonWithLabel("Reset to defaults") + resetBtn.Connect("clicked", ed.reset) + loadBtn := gtk.NewButtonWithLabel("Load from file ...") + loadBtn.Connect("clicked", ed.load) + saveBtn := gtk.NewButtonWithLabel("Save to file ...") + saveBtn.Connect("clicked", ed.save) + + btnHBox.PackStart(resetBtn, true, true, 3) + btnHBox.PackStart(loadBtn, true, true, 3) + btnHBox.PackStart(saveBtn, true, true, 3) + vbox.PackStart(btnHBox, false, false, 3) + + editFrame := newBiomeEditFrame() + vbox.PackStart(editFrame, false, false, 3) + + ed.AddButton("Cancel", gtk.RESPONSE_CANCEL) + ed.AddButton("OK", gtk.RESPONSE_OK) + ed.ShowAll() + return ed +} + +func (ed *BiomeInfoEditor) reset() { + ed.biomes = ReadDefaultBiomes() + // TODO: Update view +} + +func (ed *BiomeInfoEditor) load() { + // TODO +} + +func (ed *BiomeInfoEditor) save() { + // TODO +} + +func (ed *BiomeInfoEditor) Biomes() []BiomeInfo { return ed.biomes } diff --git a/main.go b/main.go index 75409e1..e4c3767 100644 --- a/main.go +++ b/main.go @@ -111,8 +111,13 @@ func (g *GUI) mkMenuBar() *gtk.MenuBar { confbiomes := gtk.NewMenuItemWithLabel("Configure Biomes") confbiomes.Connect("activate", func() { - // TODO: Display awesome biome editor dialog thing. - fmt.Println("(...)") + ed := NewBiomeInfoEditor(g.biomes) + rv := ed.Run() + ed.Destroy() + if rv == gtk.RESPONSE_OK { + g.biomes = ed.Biomes() + g.updateBiomeInfo() + } }) prefMenu.Append(confbiomes) -- cgit v1.2.3-70-g09d2 From 6e630d91c25f8fe4767fc94d2b301b640a2fc219 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sun, 3 Nov 2013 19:47:19 +0100 Subject: Loading partially implemented --- biome_info_editor.go | 62 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index 9768f61..1ae98c3 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -3,11 +3,10 @@ package main import ( "fmt" "github.com/kch42/gomcmap/mcmap" - "github.com/kch42/kagus" "github.com/mattn/go-gtk/gdk" "github.com/mattn/go-gtk/gtk" + "os" "strconv" - "unicode" ) type biomeEditFrame struct { @@ -29,7 +28,7 @@ func newBiomeEditFrame() *biomeEditFrame { frm.idInput.SetSizeRequest(40, -1) frm.snowLineInput.SetSizeRequest(40, -1) - + frm.idInput.Connect("changed", frm.unlockApply) frm.nameInput.Connect("changed", frm.unlockApply) frm.snowLineInput.Connect("changed", frm.unlockApply) @@ -76,7 +75,7 @@ func (frm *biomeEditFrame) getBiomeInfo() (BiomeInfo, bool) { } name := frm.nameInput.GetText() - if name != "" { + if name == "" { return BiomeInfo{}, false } @@ -91,15 +90,8 @@ func (frm *biomeEditFrame) getBiomeInfo() (BiomeInfo, bool) { } func (frm *biomeEditFrame) checkOK() bool { - if id := frm.idInput.GetText(); (id == "") || (!kagus.StringConsistsOf(id, unicode.IsNumber)) { - return false - } - - if snow := frm.snowLineInput.GetText(); (snow == "") || (!kagus.StringConsistsOf(snow, unicode.IsNumber)) { - return false - } - - return frm.nameInput.GetText() != "" + _, ok := frm.getBiomeInfo() + return ok } func (frm *biomeEditFrame) unlockApply() { @@ -118,6 +110,7 @@ func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor { } ed.SetModal(true) + vbox := ed.GetVBox() btnHBox := gtk.NewHBox(true, 0) @@ -148,8 +141,49 @@ func (ed *BiomeInfoEditor) reset() { // TODO: Update view } +func mkBioFFilters() (*gtk.FileFilter, *gtk.FileFilter) { + f1 := gtk.NewFileFilter() + f1.AddPattern("*.biomes") + f1.SetName("Biome Infos (.biomes)") + + f2 := gtk.NewFileFilter() + f2.AddPattern("*") + f2.SetName("All files") + + return f1, f2 +} + +func errdlg(msg string, params ...interface{}) { + dlg := gtk.NewMessageDialog(nil, gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg, params...) + dlg.Run() + dlg.Destroy() +} + func (ed *BiomeInfoEditor) load() { - // TODO + f1, f2 := mkBioFFilters() + dlg := gtk.NewFileChooserDialog("Load", nil, gtk.FILE_CHOOSER_ACTION_OPEN, "OK", gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL) + dlg.AddFilter(f1) + dlg.AddFilter(f2) + defer dlg.Destroy() + if dlg.Run() == gtk.RESPONSE_OK { + path := dlg.GetFilename() + + f, err := os.Open(path) + if err != nil { + errdlg("Could not load biome infos %s:\n%s", path, err.Error()) + return + } + defer f.Close() + + infos, err := ReadBiomeInfos(f) + if err != nil { + errdlg("Could not load biome infos %s:\n%s", path, err.Error()) + return + } + + ed.biomes = infos + // TODO: Update view + } } func (ed *BiomeInfoEditor) save() { -- cgit v1.2.3-70-g09d2 From cecd4ca589ec3de1d22727fb265f0fbe50689acd Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sun, 3 Nov 2013 20:40:48 +0100 Subject: Saving biome infos implemented --- biome_info_editor.go | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index 1ae98c3..53c8a03 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -160,25 +160,23 @@ func errdlg(msg string, params ...interface{}) { } func (ed *BiomeInfoEditor) load() { - f1, f2 := mkBioFFilters() dlg := gtk.NewFileChooserDialog("Load", nil, gtk.FILE_CHOOSER_ACTION_OPEN, "OK", gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL) - dlg.AddFilter(f1) - dlg.AddFilter(f2) defer dlg.Destroy() +askFilename: if dlg.Run() == gtk.RESPONSE_OK { path := dlg.GetFilename() f, err := os.Open(path) if err != nil { errdlg("Could not load biome infos %s:\n%s", path, err.Error()) - return + goto askFilename } defer f.Close() infos, err := ReadBiomeInfos(f) if err != nil { errdlg("Could not load biome infos %s:\n%s", path, err.Error()) - return + goto askFilename } ed.biomes = infos @@ -187,7 +185,34 @@ func (ed *BiomeInfoEditor) load() { } func (ed *BiomeInfoEditor) save() { - // TODO + dlg := gtk.NewFileChooserDialog("Save", nil, gtk.FILE_CHOOSER_ACTION_SAVE, "OK", gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL) + defer dlg.Destroy() +askFilename: + if dlg.Run() == gtk.RESPONSE_OK { + path := dlg.GetFilename() + + if _, err := os.Stat(path); err == nil { + qdlg := gtk.NewMessageDialog(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "File %s already exists. Overwrite?", path) + resp := qdlg.Run() + qdlg.Destroy() + + if resp != gtk.RESPONSE_YES { + goto askFilename + } + } + + f, err := os.Create(path) + if err != nil { + errdlg("Could not save biome infos %s:\n%s", path, err.Error()) + goto askFilename + } + defer f.Close() + + if err := WriteBiomeInfos(ed.biomes, f); err != nil { + errdlg("Could not save biome infos %s:\n%s", path, err.Error()) + goto askFilename + } + } } func (ed *BiomeInfoEditor) Biomes() []BiomeInfo { return ed.biomes } -- cgit v1.2.3-70-g09d2 From 034dcea37e494fb6b27f78fb0c47b29388a8faac Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sun, 3 Nov 2013 22:33:04 +0100 Subject: Added biome list to biome editor --- biome_info_editor.go | 86 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 9 deletions(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index 53c8a03..0109068 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -4,6 +4,8 @@ import ( "fmt" "github.com/kch42/gomcmap/mcmap" "github.com/mattn/go-gtk/gdk" + "github.com/mattn/go-gtk/gdkpixbuf" + "github.com/mattn/go-gtk/glib" "github.com/mattn/go-gtk/gtk" "os" "strconv" @@ -98,15 +100,80 @@ func (frm *biomeEditFrame) unlockApply() { frm.applyBtn.SetSensitive(frm.checkOK()) } +type biomeList struct { + *gtk.HBox + treeview *gtk.TreeView + lStore *gtk.ListStore + biomes []BiomeInfo +} + +func newBiomeList() *biomeList { + bl := &biomeList{ + HBox: gtk.NewHBox(false, 0), + treeview: gtk.NewTreeView(), + lStore: gtk.NewListStore(gdkpixbuf.GetType(), glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_STRING), + } + + scroll := gtk.NewScrolledWindow(nil, nil) + scroll.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + scroll.Add(bl.treeview) + bl.PackStart(scroll, true, true, 3) + + bl.treeview.SetModel(bl.lStore) + bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Color", gtk.NewCellRendererPixbuf(), "pixbuf", 0)) + bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("ID", gtk.NewCellRendererText(), "text", 1)) + bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Snowline", gtk.NewCellRendererText(), "text", 2)) + bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "text", 3)) + + bl.PackStart(bl.treeview, true, true, 3) + + vbox := gtk.NewVBox(false, 0) + + addBtn := gtk.NewButton() + addBtn.Add(gtk.NewImageFromStock(gtk.STOCK_ADD, gtk.ICON_SIZE_SMALL_TOOLBAR)) + delBtn := gtk.NewButton() + delBtn.Add(gtk.NewImageFromStock(gtk.STOCK_DELETE, gtk.ICON_SIZE_SMALL_TOOLBAR)) + upBtn := gtk.NewButton() + upBtn.Add(gtk.NewImageFromStock(gtk.STOCK_GO_UP, gtk.ICON_SIZE_SMALL_TOOLBAR)) + downBtn := gtk.NewButton() + downBtn.Add(gtk.NewImageFromStock(gtk.STOCK_GO_DOWN, gtk.ICON_SIZE_SMALL_TOOLBAR)) + + addBtn.Connect("clicked", bl.onAdd) + delBtn.Connect("clicked", bl.onDel) + upBtn.Connect("clicked", bl.onUp) + downBtn.Connect("clicked", bl.onDown) + + vbox.PackStart(addBtn, false, false, 3) + vbox.PackStart(delBtn, false, false, 3) + vbox.PackStart(upBtn, false, false, 3) + vbox.PackStart(downBtn, false, false, 3) + + bl.PackStart(vbox, false, false, 0) + + return bl +} + +func (bl *biomeList) SetBiomes(biomes []BiomeInfo) { + bl.biomes = biomes + // TODO: Update View +} + +func (bl *biomeList) Biomes() []BiomeInfo { return bl.biomes } + +func (bl *biomeList) onAdd() {} // TODO +func (bl *biomeList) onDel() {} // TODO +func (bl *biomeList) onUp() {} // TODO +func (bl *biomeList) onDown() {} // TODO + type BiomeInfoEditor struct { *gtk.Dialog - biomes []BiomeInfo + biolist *biomeList } func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor { ed := &BiomeInfoEditor{ - Dialog: gtk.NewDialog(), - biomes: biomes, + Dialog: gtk.NewDialog(), + biolist: newBiomeList(), } ed.SetModal(true) @@ -127,6 +194,9 @@ func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor { btnHBox.PackStart(saveBtn, true, true, 3) vbox.PackStart(btnHBox, false, false, 3) + ed.biolist.SetBiomes(biomes) + vbox.PackStart(ed.biolist, false, false, 3) + editFrame := newBiomeEditFrame() vbox.PackStart(editFrame, false, false, 3) @@ -137,8 +207,7 @@ func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor { } func (ed *BiomeInfoEditor) reset() { - ed.biomes = ReadDefaultBiomes() - // TODO: Update view + ed.biolist.SetBiomes(ReadDefaultBiomes()) } func mkBioFFilters() (*gtk.FileFilter, *gtk.FileFilter) { @@ -179,8 +248,7 @@ askFilename: goto askFilename } - ed.biomes = infos - // TODO: Update view + ed.biolist.SetBiomes(infos) } } @@ -208,11 +276,11 @@ askFilename: } defer f.Close() - if err := WriteBiomeInfos(ed.biomes, f); err != nil { + if err := WriteBiomeInfos(ed.biolist.Biomes(), f); err != nil { errdlg("Could not save biome infos %s:\n%s", path, err.Error()) goto askFilename } } } -func (ed *BiomeInfoEditor) Biomes() []BiomeInfo { return ed.biomes } +func (ed *BiomeInfoEditor) Biomes() []BiomeInfo { return ed.biolist.Biomes() } -- cgit v1.2.3-70-g09d2 From 1a9da3d899699a2d76116454f7daa2f179b0c109 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 11:24:09 +0100 Subject: We don't need to pack the treeview here Is already in a scrolled window --- biome_info_editor.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index 0109068..cb24058 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -125,8 +125,6 @@ func newBiomeList() *biomeList { bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Snowline", gtk.NewCellRendererText(), "text", 2)) bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "text", 3)) - bl.PackStart(bl.treeview, true, true, 3) - vbox := gtk.NewVBox(false, 0) addBtn := gtk.NewButton() -- cgit v1.2.3-70-g09d2 From 69902644f31689a3f9e19c950718ced8a462494b Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 12:35:52 +0100 Subject: TreeView is working :) --- biome_info_editor.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index cb24058..27c18ef 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/kch42/gomcmap/mcmap" "github.com/mattn/go-gtk/gdk" - "github.com/mattn/go-gtk/gdkpixbuf" "github.com/mattn/go-gtk/glib" "github.com/mattn/go-gtk/gtk" "os" @@ -111,7 +110,7 @@ func newBiomeList() *biomeList { bl := &biomeList{ HBox: gtk.NewHBox(false, 0), treeview: gtk.NewTreeView(), - lStore: gtk.NewListStore(gdkpixbuf.GetType(), glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_STRING), + lStore: gtk.NewListStore(glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_STRING), } scroll := gtk.NewScrolledWindow(nil, nil) @@ -120,11 +119,13 @@ func newBiomeList() *biomeList { bl.PackStart(scroll, true, true, 3) bl.treeview.SetModel(bl.lStore) - bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Color", gtk.NewCellRendererPixbuf(), "pixbuf", 0)) + bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Color", gtk.NewCellRendererText(), "background", 0)) bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("ID", gtk.NewCellRendererText(), "text", 1)) bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Snowline", gtk.NewCellRendererText(), "text", 2)) bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "text", 3)) + bl.treeview.Connect("cursor-changed", bl.onCursorChanged) + vbox := gtk.NewVBox(false, 0) addBtn := gtk.NewButton() @@ -151,13 +152,27 @@ func newBiomeList() *biomeList { return bl } +func (bl *biomeList) setBiome(iter *gtk.TreeIter, biome BiomeInfo) { + bl.lStore.Set(iter, biome.Color, strconv.FormatInt(int64(biome.ID), 10), strconv.FormatInt(int64(biome.SnowLine), 10), biome.Name) +} + func (bl *biomeList) SetBiomes(biomes []BiomeInfo) { bl.biomes = biomes - // TODO: Update View + + bl.lStore.Clear() + var iter gtk.TreeIter + for _, bio := range biomes { + bl.lStore.Append(&iter) + bl.setBiome(&iter, bio) + } } func (bl *biomeList) Biomes() []BiomeInfo { return bl.biomes } +func (bl *biomeList) onCursorChanged() { + // TODO +} + func (bl *biomeList) onAdd() {} // TODO func (bl *biomeList) onDel() {} // TODO func (bl *biomeList) onUp() {} // TODO @@ -193,7 +208,7 @@ func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor { vbox.PackStart(btnHBox, false, false, 3) ed.biolist.SetBiomes(biomes) - vbox.PackStart(ed.biolist, false, false, 3) + vbox.PackStart(ed.biolist, true, true, 3) editFrame := newBiomeEditFrame() vbox.PackStart(editFrame, false, false, 3) -- cgit v1.2.3-70-g09d2 From c14bae386dc7a8db6dc1dd81facce8e317aa45f9 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 13:20:13 +0100 Subject: Adding, deleting and modifying biomes works! --- biome_info_editor.go | 83 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index 27c18ef..80f893c 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -15,6 +15,7 @@ type biomeEditFrame struct { applyBtn *gtk.Button idInput, snowLineInput, nameInput *gtk.Entry colorInput *gtk.ColorButton + bList *biomeList } func newBiomeEditFrame() *biomeEditFrame { @@ -51,6 +52,8 @@ func newBiomeEditFrame() *biomeEditFrame { vbox.PackStart(frm.applyBtn, false, false, 3) frm.Add(vbox) + frm.applyBtn.Connect("clicked", frm.doApply) + return frm } @@ -61,6 +64,15 @@ func (frm *biomeEditFrame) setBiomeInfo(info BiomeInfo) { frm.nameInput.SetText(info.Name) } +func (frm *biomeEditFrame) doApply() { + biome, ok := frm.getBiomeInfo() + if !ok { + return + } + + frm.bList.setCurrentBiome(biome) +} + func (frm *biomeEditFrame) getBiomeInfo() (BiomeInfo, bool) { id, err := strconv.ParseUint(frm.idInput.GetText(), 10, 8) if err != nil { @@ -86,7 +98,7 @@ func (frm *biomeEditFrame) getBiomeInfo() (BiomeInfo, bool) { ID: mcmap.Biome(id), SnowLine: int(snow), Name: name, - Color: fmt.Sprintf("#%02x%02x%02x", col.Red()<<8, col.Green()<<8, col.Blue()<<8), + Color: fmt.Sprintf("#%02x%02x%02x", col.Red()>>8, col.Green()>>8, col.Blue()>>8), }, true } @@ -104,6 +116,7 @@ type biomeList struct { treeview *gtk.TreeView lStore *gtk.ListStore biomes []BiomeInfo + editfrm *biomeEditFrame } func newBiomeList() *biomeList { @@ -124,6 +137,7 @@ func newBiomeList() *biomeList { bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Snowline", gtk.NewCellRendererText(), "text", 2)) bl.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "text", 3)) + bl.treeview.GetSelection().SetMode(gtk.SELECTION_SINGLE) bl.treeview.Connect("cursor-changed", bl.onCursorChanged) vbox := gtk.NewVBox(false, 0) @@ -156,6 +170,15 @@ func (bl *biomeList) setBiome(iter *gtk.TreeIter, biome BiomeInfo) { bl.lStore.Set(iter, biome.Color, strconv.FormatInt(int64(biome.ID), 10), strconv.FormatInt(int64(biome.SnowLine), 10), biome.Name) } +func (bl *biomeList) setCurrentBiome(biome BiomeInfo) { + idx, iter := bl.treeviewIdx() + if idx < 0 { + return + } + bl.biomes[idx] = biome + bl.setBiome(iter, biome) +} + func (bl *biomeList) SetBiomes(biomes []BiomeInfo) { bl.biomes = biomes @@ -169,15 +192,66 @@ func (bl *biomeList) SetBiomes(biomes []BiomeInfo) { func (bl *biomeList) Biomes() []BiomeInfo { return bl.biomes } +func (bl *biomeList) treeviewIdx() (int, *gtk.TreeIter) { + var path *gtk.TreePath + var column *gtk.TreeViewColumn + bl.treeview.GetCursor(&path, &column) + + idxs := path.GetIndices() + if len(idxs) != 1 { + return -1, nil + } + var iter gtk.TreeIter + bl.lStore.GetIter(&iter, path) + + return idxs[0], &iter +} + func (bl *biomeList) onCursorChanged() { - // TODO + idx, _ := bl.treeviewIdx() + if idx < 0 { + return + } + + bl.editfrm.setBiomeInfo(bl.biomes[idx]) +} + +func (bl *biomeList) onAdd() { + bio := BiomeInfo{ + Color: "#000000", + ID: 0, + SnowLine: 255, + Name: "(new)", + } + bl.biomes = append(bl.biomes, bio) + + var iter gtk.TreeIter + bl.lStore.Append(&iter) + bl.setBiome(&iter, bio) + path := gtk.NewTreePath() + path.AppendIndex(len(bl.biomes) - 1) + bl.treeview.SetCursor(path, nil, false) } -func (bl *biomeList) onAdd() {} // TODO -func (bl *biomeList) onDel() {} // TODO +func (bl *biomeList) onDel() { + idx, iter := bl.treeviewIdx() + if idx < 0 { + return + } + + copy(bl.biomes[idx:], bl.biomes[idx+1:]) + bl.biomes = bl.biomes[:len(bl.biomes)-1] + + bl.lStore.Remove(iter) +} func (bl *biomeList) onUp() {} // TODO func (bl *biomeList) onDown() {} // TODO +func connectBiomeListEditFrame(bl *biomeList, frm *biomeEditFrame) { + bl.editfrm = frm + frm.bList = bl +} + type BiomeInfoEditor struct { *gtk.Dialog biolist *biomeList @@ -211,6 +285,7 @@ func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor { vbox.PackStart(ed.biolist, true, true, 3) editFrame := newBiomeEditFrame() + connectBiomeListEditFrame(ed.biolist, editFrame) vbox.PackStart(editFrame, false, false, 3) ed.AddButton("Cancel", gtk.RESPONSE_CANCEL) -- cgit v1.2.3-70-g09d2 From fd2bd4a1379c5b030bfab933678fa933d9c05245 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 13:49:00 +0100 Subject: Biomes can be moved around --- biome_info_editor.go | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index 80f893c..8b47308 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -171,7 +171,7 @@ func (bl *biomeList) setBiome(iter *gtk.TreeIter, biome BiomeInfo) { } func (bl *biomeList) setCurrentBiome(biome BiomeInfo) { - idx, iter := bl.treeviewIdx() + idx, iter, _ := bl.treeviewIdx() if idx < 0 { return } @@ -192,23 +192,23 @@ func (bl *biomeList) SetBiomes(biomes []BiomeInfo) { func (bl *biomeList) Biomes() []BiomeInfo { return bl.biomes } -func (bl *biomeList) treeviewIdx() (int, *gtk.TreeIter) { +func (bl *biomeList) treeviewIdx() (int, *gtk.TreeIter, *gtk.TreePath) { var path *gtk.TreePath var column *gtk.TreeViewColumn bl.treeview.GetCursor(&path, &column) idxs := path.GetIndices() if len(idxs) != 1 { - return -1, nil + return -1, nil, nil } var iter gtk.TreeIter bl.lStore.GetIter(&iter, path) - return idxs[0], &iter + return idxs[0], &iter, path } func (bl *biomeList) onCursorChanged() { - idx, _ := bl.treeviewIdx() + idx, _, _ := bl.treeviewIdx() if idx < 0 { return } @@ -234,7 +234,7 @@ func (bl *biomeList) onAdd() { } func (bl *biomeList) onDel() { - idx, iter := bl.treeviewIdx() + idx, iter, _ := bl.treeviewIdx() if idx < 0 { return } @@ -244,8 +244,35 @@ func (bl *biomeList) onDel() { bl.lStore.Remove(iter) } -func (bl *biomeList) onUp() {} // TODO -func (bl *biomeList) onDown() {} // TODO +func (bl *biomeList) onUp() { + idx, iter, path := bl.treeviewIdx() + if idx <= 0 { + return + } + + path.Prev() + var iter2 gtk.TreeIter + bl.lStore.GetIter(&iter2, path) + + bl.lStore.MoveBefore(iter, &iter2) + + bl.biomes[idx], bl.biomes[idx-1] = bl.biomes[idx-1], bl.biomes[idx] +} + +func (bl *biomeList) onDown() { + idx, iter, path := bl.treeviewIdx() + if (idx < 0) || (idx >= len(bl.biomes)-1) { + return + } + + path.Next() + var iter2 gtk.TreeIter + bl.lStore.GetIter(&iter2, path) + + bl.lStore.MoveAfter(iter, &iter2) + + bl.biomes[idx], bl.biomes[idx+1] = bl.biomes[idx+1], bl.biomes[idx] +} func connectBiomeListEditFrame(bl *biomeList, frm *biomeEditFrame) { bl.editfrm = frm -- cgit v1.2.3-70-g09d2 From 25135a163aeb6891614fd18e1a9316955ec3920a Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 13:58:02 +0100 Subject: onDel re-selects the current entry --- biome_info_editor.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index 8b47308..f4f23cd 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -234,7 +234,7 @@ func (bl *biomeList) onAdd() { } func (bl *biomeList) onDel() { - idx, iter, _ := bl.treeviewIdx() + idx, iter, path := bl.treeviewIdx() if idx < 0 { return } @@ -243,6 +243,9 @@ func (bl *biomeList) onDel() { bl.biomes = bl.biomes[:len(bl.biomes)-1] bl.lStore.Remove(iter) + if len(bl.biomes) > 0 { + bl.treeview.SetCursor(path, nil, false) + } } func (bl *biomeList) onUp() { idx, iter, path := bl.treeviewIdx() -- cgit v1.2.3-70-g09d2 From bb8ec813d87a15519749c44aa6f9e8b7b85a443d Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 13:58:54 +0100 Subject: Buttons of biome list are now (de)activated, depending on index --- biome_info_editor.go | 60 +++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/biome_info_editor.go b/biome_info_editor.go index f4f23cd..5d10320 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -113,10 +113,11 @@ func (frm *biomeEditFrame) unlockApply() { type biomeList struct { *gtk.HBox - treeview *gtk.TreeView - lStore *gtk.ListStore - biomes []BiomeInfo - editfrm *biomeEditFrame + treeview *gtk.TreeView + lStore *gtk.ListStore + biomes []BiomeInfo + editfrm *biomeEditFrame + addBtn, delBtn, upBtn, downBtn *gtk.Button } func newBiomeList() *biomeList { @@ -124,6 +125,10 @@ func newBiomeList() *biomeList { HBox: gtk.NewHBox(false, 0), treeview: gtk.NewTreeView(), lStore: gtk.NewListStore(glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_STRING, glib.G_TYPE_STRING), + addBtn: gtk.NewButton(), + delBtn: gtk.NewButton(), + upBtn: gtk.NewButton(), + downBtn: gtk.NewButton(), } scroll := gtk.NewScrolledWindow(nil, nil) @@ -142,24 +147,24 @@ func newBiomeList() *biomeList { vbox := gtk.NewVBox(false, 0) - addBtn := gtk.NewButton() - addBtn.Add(gtk.NewImageFromStock(gtk.STOCK_ADD, gtk.ICON_SIZE_SMALL_TOOLBAR)) - delBtn := gtk.NewButton() - delBtn.Add(gtk.NewImageFromStock(gtk.STOCK_DELETE, gtk.ICON_SIZE_SMALL_TOOLBAR)) - upBtn := gtk.NewButton() - upBtn.Add(gtk.NewImageFromStock(gtk.STOCK_GO_UP, gtk.ICON_SIZE_SMALL_TOOLBAR)) - downBtn := gtk.NewButton() - downBtn.Add(gtk.NewImageFromStock(gtk.STOCK_GO_DOWN, gtk.ICON_SIZE_SMALL_TOOLBAR)) - - addBtn.Connect("clicked", bl.onAdd) - delBtn.Connect("clicked", bl.onDel) - upBtn.Connect("clicked", bl.onUp) - downBtn.Connect("clicked", bl.onDown) - - vbox.PackStart(addBtn, false, false, 3) - vbox.PackStart(delBtn, false, false, 3) - vbox.PackStart(upBtn, false, false, 3) - vbox.PackStart(downBtn, false, false, 3) + bl.addBtn.Add(gtk.NewImageFromStock(gtk.STOCK_ADD, gtk.ICON_SIZE_SMALL_TOOLBAR)) + bl.delBtn.Add(gtk.NewImageFromStock(gtk.STOCK_DELETE, gtk.ICON_SIZE_SMALL_TOOLBAR)) + bl.upBtn.Add(gtk.NewImageFromStock(gtk.STOCK_GO_UP, gtk.ICON_SIZE_SMALL_TOOLBAR)) + bl.downBtn.Add(gtk.NewImageFromStock(gtk.STOCK_GO_DOWN, gtk.ICON_SIZE_SMALL_TOOLBAR)) + + bl.addBtn.Connect("clicked", bl.onAdd) + bl.delBtn.Connect("clicked", bl.onDel) + bl.upBtn.Connect("clicked", bl.onUp) + bl.downBtn.Connect("clicked", bl.onDown) + + bl.delBtn.SetSensitive(false) + bl.upBtn.SetSensitive(false) + bl.downBtn.SetSensitive(false) + + vbox.PackStart(bl.addBtn, false, false, 3) + vbox.PackStart(bl.delBtn, false, false, 3) + vbox.PackStart(bl.upBtn, false, false, 3) + vbox.PackStart(bl.downBtn, false, false, 3) bl.PackStart(vbox, false, false, 0) @@ -209,11 +214,14 @@ func (bl *biomeList) treeviewIdx() (int, *gtk.TreeIter, *gtk.TreePath) { func (bl *biomeList) onCursorChanged() { idx, _, _ := bl.treeviewIdx() - if idx < 0 { - return - } - bl.editfrm.setBiomeInfo(bl.biomes[idx]) + bl.delBtn.SetSensitive(idx >= 0) + bl.upBtn.SetSensitive(idx >= 1) + bl.downBtn.SetSensitive((idx >= 0) && (idx < len(bl.biomes)-1)) + + if idx >= 0 { + bl.editfrm.setBiomeInfo(bl.biomes[idx]) + } } func (bl *biomeList) onAdd() { -- cgit v1.2.3-70-g09d2 From 568116b8644255e04759190d3ad764f858398646 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 14:40:18 +0100 Subject: Biome editor is now opened by a button in the sidebar --- main.go | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index e4c3767..b1ae1ad 100644 --- a/main.go +++ b/main.go @@ -79,6 +79,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dlg.Destroy() } +func (g *GUI) biomeEditor() { + ed := NewBiomeInfoEditor(g.biomes) + rv := ed.Run() + ed.Destroy() + if rv == gtk.RESPONSE_OK { + g.biomes = ed.Biomes() + g.updateBiomeInfo() + } +} + func (g *GUI) mkMenuBar() *gtk.MenuBar { menubar := gtk.NewMenuBar() @@ -107,24 +117,6 @@ func (g *GUI) mkMenuBar() *gtk.MenuBar { fileMenuItem.SetSubmenu(fileMenu) menubar.Append(fileMenuItem) - prefMenu := gtk.NewMenu() - - confbiomes := gtk.NewMenuItemWithLabel("Configure Biomes") - confbiomes.Connect("activate", func() { - ed := NewBiomeInfoEditor(g.biomes) - rv := ed.Run() - ed.Destroy() - if rv == gtk.RESPONSE_OK { - g.biomes = ed.Biomes() - g.updateBiomeInfo() - } - }) - prefMenu.Append(confbiomes) - - prefMenuItem := gtk.NewMenuItemWithLabel("Preferences") - prefMenuItem.SetSubmenu(prefMenu) - menubar.Append(prefMenuItem) - helpMenu := gtk.NewMenu() controls := gtk.NewMenuItemWithLabel("Controls") @@ -216,7 +208,14 @@ func (g *GUI) mkSidebar() *gtk.ScrolledWindow { sbVBox.PackStart(drawHBox, false, false, 3) sbVBox.PackStart(gtk.NewHSeparator(), false, false, 3) - sbVBox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), false, false, 3) + bioHeaderHBox := gtk.NewHBox(false, 0) + bioHeaderHBox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), true, false, 0) + editBiomesBtn := gtk.NewButton() + editBiomesBtn.Add(gtk.NewImageFromStock(gtk.STOCK_EDIT, gtk.ICON_SIZE_SMALL_TOOLBAR)) + editBiomesBtn.Connect("clicked", g.biomeEditor) + editBiomesBtn.SetTooltipText("Configure Biomes") + bioHeaderHBox.PackStart(editBiomesBtn, false, false, 0) + sbVBox.PackStart(bioHeaderHBox, false, false, 3) g.bioVBoxWrap = gtk.NewVBox(false, 0) g.bioVBox = gtk.NewVBox(false, 0) -- cgit v1.2.3-70-g09d2 From 037fc4ff36521c19626e79ce40990ecf420ce4f6 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 14:40:27 +0100 Subject: Added some tooltips --- biome_info_editor.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/biome_info_editor.go b/biome_info_editor.go index 5d10320..61a1d7e 100644 --- a/biome_info_editor.go +++ b/biome_info_editor.go @@ -39,6 +39,9 @@ func newBiomeEditFrame() *biomeEditFrame { vbox := gtk.NewVBox(false, 0) hbox := gtk.NewHBox(false, 0) + frm.idInput.SetTooltipText("The data value of the Biome [0-255]") + frm.snowLineInput.SetTooltipText(fmt.Sprintf("Height (Y coordinate) at which snowfall starts (-1 or %d for no snowfall, 0 for always snowy)", mcmap.ChunkSizeY)) + hbox.PackStart(gtk.NewLabel("Color:"), false, false, 0) hbox.PackStart(frm.colorInput, false, false, 3) hbox.PackStart(gtk.NewLabel("ID:"), false, false, 0) -- cgit v1.2.3-70-g09d2 From 9b006397c30d49e4843b4e5479670a645f435dd9 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 4 Nov 2013 14:43:07 +0100 Subject: Removed test.biomes --- test.biomes | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 test.biomes diff --git a/test.biomes b/test.biomes deleted file mode 100644 index 07dcf6f..0000000 --- a/test.biomes +++ /dev/null @@ -1,3 +0,0 @@ -0 10 #ff0000 Foo -1 20 #00ff00 Bar -2 30 #0000ff Baz -- cgit v1.2.3-70-g09d2