summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE18
-rw-r--r--biome_infos.go60
-rw-r--r--colorbox.go36
-rw-r--r--listmaps.go54
-rw-r--r--main.go236
5 files changed, 404 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..c11fdc0
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,18 @@
+Copyright (c) 2013 Kevin Chabowski
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/biome_infos.go b/biome_infos.go
new file mode 100644
index 0000000..2d50c67
--- /dev/null
+++ b/biome_infos.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "github.com/kch42/gomcmap/mcmap"
+ "github.com/kch42/kagus"
+)
+
+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.BioUncalculated,
+}
+
+var bioColors = map[mcmap.Biome]kagus.RGB0x{
+ mcmap.BioOcean: 0x0000ff,
+ mcmap.BioPlains: 0x9fe804,
+ mcmap.BioDesert: 0xf5ff58,
+ mcmap.BioExtremeHills: 0xa75300,
+ mcmap.BioForest: 0x006f2a,
+ mcmap.BioTaiga: 0x05795a,
+ mcmap.BioSwampland: 0x6a7905,
+ mcmap.BioRiver: 0x196eff,
+ mcmap.BioHell: 0xd71900,
+ mcmap.BioSky: 0x871eb3,
+ mcmap.BioFrozenOcean: 0xd6f0ff,
+ mcmap.BioFrozenRiver: 0x8fb6cd,
+ mcmap.BioIcePlains: 0xfbfbfb,
+ mcmap.BioIceMountains: 0xc6bfb1,
+ mcmap.BioMushroomIsland: 0x9776a4,
+ mcmap.BioMushroomIslandShore: 0x9e8ebc,
+ mcmap.BioBeach: 0xfffdc9,
+ mcmap.BioDesertHills: 0xadb354,
+ mcmap.BioForestHills: 0x40694f,
+ mcmap.BioTaigaHills: 0x5b8578,
+ mcmap.BioExtremeHillsEdge: 0xa77748,
+ mcmap.BioJungle: 0x22db04,
+ mcmap.BioJungleHills: 0x63bf54,
+ mcmap.BioUncalculated: 0x333333,
+}
diff --git a/colorbox.go b/colorbox.go
new file mode 100644
index 0000000..a9d1583
--- /dev/null
+++ b/colorbox.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+ "fmt"
+ "github.com/mattn/go-gtk/gdk"
+ "github.com/mattn/go-gtk/gtk"
+ "image/color"
+)
+
+func colorBox(c color.Color) *gtk.DrawingArea {
+ r, g, b, _ := c.RGBA()
+ colstring := fmt.Sprintf("#%02x%02x%02x", (r>>8)&0xff, (g>>8)&0xff, (b>>8)&0xff)
+
+ dArea := gtk.NewDrawingArea()
+ var pixmap *gdk.Pixmap
+ var gc *gdk.GC
+
+ dArea.Connect("configure-event", func() {
+ if pixmap != nil {
+ pixmap.Unref()
+ }
+ alloc := dArea.GetAllocation()
+ pixmap = gdk.NewPixmap(dArea.GetWindow().GetDrawable(), alloc.Width, alloc.Height, 24)
+ gc = gdk.NewGC(pixmap.GetDrawable())
+ gc.SetRgbFgColor(gdk.NewColor(colstring))
+ pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
+ })
+
+ dArea.Connect("expose-event", func() {
+ if pixmap != nil {
+ dArea.GetWindow().GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
+ }
+ })
+
+ return dArea
+}
diff --git a/listmaps.go b/listmaps.go
new file mode 100644
index 0000000..ea43890
--- /dev/null
+++ b/listmaps.go
@@ -0,0 +1,54 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "path"
+ "runtime"
+)
+
+func allMaps() map[string]string {
+ savesDir := ""
+ switch runtime.GOOS {
+ case "linux":
+ savesDir = fmt.Sprintf("%s/.minecraft/saves", os.Getenv("HOME"))
+ case "darwin":
+ savesDir = fmt.Sprintf("%s/Library/Application Support/minecraft/saves", os.Getenv("HOME"))
+ case "windows":
+ savesDir = fmt.Sprintf(`%s\.minecraft`, os.Getenv("appdata"))
+ default:
+ return nil
+ }
+
+ f, err := os.Open(savesDir)
+ if err != nil {
+ return nil
+ }
+ defer f.Close()
+ fi, err := f.Stat()
+ if (err != nil) || (!fi.IsDir()) {
+ return nil
+ }
+
+ infos, err := f.Readdir(-1)
+ if err != nil {
+ return nil
+ }
+
+ maps := make(map[string]string)
+ for _, info := range infos {
+ if !info.IsDir() {
+ continue
+ }
+ p := path.Join(savesDir, info.Name())
+
+ fi, err := os.Stat(path.Join(p, "level.dat"))
+ if (err != nil) || (!fi.Mode().IsRegular()) {
+ continue
+ }
+
+ maps[info.Name()] = path.Join(p, "region")
+ }
+
+ return maps
+}
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..13f9ccf
--- /dev/null
+++ b/main.go
@@ -0,0 +1,236 @@
+package main
+
+import (
+ "fmt"
+ "github.com/kch42/gomcmap/mcmap"
+ "github.com/mattn/go-gtk/glib"
+ "github.com/mattn/go-gtk/gtk"
+)
+
+type tool int
+
+const (
+ ToolDraw tool = iota
+ ToolFill
+)
+
+type GUI struct {
+ window *gtk.Window
+ statusbar *gtk.Statusbar
+ showbiomes *gtk.CheckButton
+}
+
+func (g *GUI) openWorldDlg() {
+ dlg := gtk.NewFileChooserDialog("Open World (region directory)", g.window, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, "Open Region dir", gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL)
+ if dlg.Run() == gtk.RESPONSE_OK {
+ g.openWorld(dlg.GetFilename())
+ }
+ dlg.Destroy()
+}
+
+func (g *GUI) openWorld(path string) {
+ fmt.Println(path)
+}
+
+func (g *GUI) aboutDlg() {
+ dlg := gtk.NewAboutDialog()
+ dlg.SetName("biome-editor")
+ dlg.SetVersion("α")
+ dlg.SetCopyright("© 2013 by Kevin Chabowski")
+ dlg.SetAuthors([]string{"Kevin Chabowski <kevin@kch42.de>"})
+ dlg.SetLicense(`Copyright (c) 2013 Kevin Chabowski
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+`)
+ dlg.Run()
+ dlg.Destroy()
+}
+
+func (g *GUI) mkMenuBar() *gtk.MenuBar {
+ menubar := gtk.NewMenuBar()
+
+ fileMenu := gtk.NewMenu()
+
+ open := gtk.NewMenuItemWithLabel("Open")
+ open.Connect("activate", g.openWorldDlg)
+ fileMenu.Append(open)
+
+ if quickopen, ok := g.mkQuickOpen(); ok {
+ quickopenItem := gtk.NewMenuItemWithLabel("Open Map")
+ quickopenItem.SetSubmenu(quickopen)
+ fileMenu.Append(quickopenItem)
+ }
+
+ save := gtk.NewMenuItemWithLabel("Save")
+ fileMenu.Append(save)
+
+ quit := gtk.NewMenuItemWithLabel("Quit")
+ quit.Connect("activate", g.exitApp)
+ fileMenu.Append(quit)
+
+ fileMenuItem := gtk.NewMenuItemWithLabel("File")
+ fileMenuItem.SetSubmenu(fileMenu)
+ menubar.Append(fileMenuItem)
+
+ helpMenu := gtk.NewMenu()
+
+ about := gtk.NewMenuItemWithLabel("About")
+ about.Connect("activate", g.aboutDlg)
+ helpMenu.Append(about)
+
+ helpMenuItem := gtk.NewMenuItemWithLabel("Help")
+ helpMenuItem.SetSubmenu(helpMenu)
+ menubar.Append(helpMenuItem)
+
+ return menubar
+}
+
+func (g *GUI) mkQuickOpen() (*gtk.Menu, bool) {
+ maps := allMaps()
+ if (maps == nil) || (len(maps) == 0) {
+ return nil, false
+ }
+
+ menu := gtk.NewMenu()
+ for name, p := range maps {
+ mitem := gtk.NewMenuItemWithLabel(name)
+ p2 := p
+ mitem.Connect("activate", func() { g.openWorld(p2) })
+ menu.Append(mitem)
+ }
+
+ return menu, true
+}
+
+func labelCustomFont(text, font string) *gtk.Label {
+ label := gtk.NewLabel(text)
+ label.ModifyFontEasy(font)
+ return label
+}
+
+func (g *GUI) mkToolbox() *gtk.ScrolledWindow {
+ vbox := gtk.NewVBox(false, 0)
+
+ vbox.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)
+
+ fill := gtk.NewRadioButtonWithLabel(nil, "Fill")
+ draw := gtk.NewRadioButtonWithLabel(fill.GetGroup(), "Draw")
+ fill.SetActive(true)
+ fill.Connect("toggled", g.mkUpdateToolFx(fill, ToolFill))
+ draw.Connect("toggled", g.mkUpdateToolFx(draw, ToolDraw))
+ vbox.PackStart(fill, false, false, 3)
+ vbox.PackStart(draw, false, false, 3)
+
+ vbox.PackStart(gtk.NewHSeparator(), false, false, 3)
+ vbox.PackStart(labelCustomFont("Biomes", "Sans Bold 14"), false, false, 3)
+
+ var grp *glib.SList
+ for _, bio := range bioList {
+ biohbox := gtk.NewHBox(false, 0)
+ cbox := colorBox(bioColors[bio])
+ cbox.SetSizeRequest(20, 20)
+ biohbox.PackStart(cbox, false, false, 3)
+ rbutton := gtk.NewRadioButtonWithLabel(grp, bio.String())
+ grp = rbutton.GetGroup()
+ rbutton.Connect("toggled", g.mkUpdateBiomeFx(rbutton, bio))
+ 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
+}
+
+func (g *GUI) Init() {
+ g.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
+ g.window.SetTitle("Biome Editor")
+
+ menubar := g.mkMenuBar()
+ vbox := gtk.NewVBox(false, 0)
+ vbox.PackStart(menubar, false, false, 3)
+
+ hbox := gtk.NewHBox(false, 0)
+
+ // TODO: Drawing area thing missing...
+
+ toolbox := g.mkToolbox()
+ hbox.PackEnd(toolbox, false, false, 3)
+
+ vbox.PackStart(hbox, true, true, 3)
+
+ g.statusbar = gtk.NewStatusbar()
+ vbox.PackEnd(g.statusbar, false, false, 3)
+
+ g.window.Add(vbox)
+ g.window.SetDefaultSize(800, 600)
+
+ g.window.Connect("destroy", g.exitApp)
+}
+
+func (g *GUI) mkUpdateToolFx(rb *gtk.RadioButton, t tool) func() {
+ return func() {
+ if rb.GetActive() {
+ g.setTool(t)
+ }
+ }
+}
+
+func (g *GUI) mkUpdateBiomeFx(rb *gtk.RadioButton, bio mcmap.Biome) func() {
+ return func() {
+ if rb.GetActive() {
+ g.setBiome(bio)
+ }
+ }
+}
+
+func (g *GUI) setTool(t tool) {
+ fmt.Printf("Tool %d\n", t)
+}
+
+func (g *GUI) setBiome(bio mcmap.Biome) {
+ fmt.Println(bio)
+}
+
+func (g *GUI) showbiomesToggled() {
+ fmt.Printf("Show biomes: %v\n", g.showbiomes.GetActive())
+}
+
+func (g *GUI) Show() {
+ g.window.ShowAll()
+}
+
+func (g *GUI) exitApp() {
+ gtk.MainQuit()
+}
+
+func main() {
+ gtk.Init(nil)
+
+ gui := new(GUI)
+ gui.Init()
+ gui.Show()
+
+ gtk.Main()
+}