From 3203a70b57bf00ea7c2fbdf5416076c8c3d50c1f Mon Sep 17 00:00:00 2001 From: Minizbot2012 Date: Thu, 26 Mar 2020 18:48:48 -0400 Subject: [PATCH] Now sidebindings --- orbbind.go | 4 ++++ ui/mainpage/main.go | 3 +-- ui/side/sidepage.go | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 ui/side/sidepage.go diff --git a/orbbind.go b/orbbind.go index 0a01ac6..b596dbb 100644 --- a/orbbind.go +++ b/orbbind.go @@ -9,6 +9,7 @@ import ( "fyne.io/fyne/widget" "github.com/Minizbot2012/orbbind/keymap/orbweaver" "github.com/Minizbot2012/orbbind/ui/mainpage" + sidepage "github.com/Minizbot2012/orbbind/ui/side" ) func main() { @@ -17,7 +18,9 @@ func main() { window.Resize(fyne.NewSize(480, 480)) omap := &orbweaver.PKM{} nmp := mainpage.NewMainPage(window, omap) + nsp := sidepage.NewSidePage(window, omap) tabs := widget.NewTabContainer(nmp.Create()) + tabs.Append(nsp.Create()) tabs.Resize(window.Content().Size()) window.SetMainMenu(fyne.NewMainMenu(fyne.NewMenu("File", fyne.NewMenuItem("Save", func() { dialog.ShowFileSave(func(p string) { @@ -27,6 +30,7 @@ func main() { dialog.ShowFileOpen(func(p string) { omap = orbweaver.LoadFile(p) nmp.SetBindings(omap) + nsp.SetBindings(omap) }, window) })))) window.SetContent(tabs) diff --git a/ui/mainpage/main.go b/ui/mainpage/main.go index 75f10fd..a00f444 100644 --- a/ui/mainpage/main.go +++ b/ui/mainpage/main.go @@ -24,7 +24,7 @@ func (mp *Page) createButtons() { for i := 0; i < 4; i++ { for j := 0; j < 5; j++ { id := (j + i*5 + 1) - mp.dev["B"+strconv.Itoa(id)] = widget.NewButton(strconv.Itoa((j+i*5)+1), func() { + mp.dev["B"+strconv.Itoa(id)] = widget.NewButton(strconv.Itoa(id), func() { popup := bind.NewBindPage(id, mp.parent, mp.binds.MIP[id-1]) dialog.ShowCustomConfirm("Binding", "Set", "Cancel", popup.Create(string(id)), func(b bool) { if b { @@ -33,7 +33,6 @@ func (mp *Page) createButtons() { }, mp.parent) }) mp.dev["V"].(*fyne.Container).AddObject(mp.dev["B"+strconv.Itoa(id)]) - } } } diff --git a/ui/side/sidepage.go b/ui/side/sidepage.go new file mode 100644 index 0000000..f6d3e9b --- /dev/null +++ b/ui/side/sidepage.go @@ -0,0 +1,53 @@ +package sidepage + +import ( + "strconv" + + "fyne.io/fyne" + "fyne.io/fyne/dialog" + "fyne.io/fyne/layout" + "fyne.io/fyne/widget" + "github.com/Minizbot2012/orbbind/keymap/orbweaver" + "github.com/Minizbot2012/orbbind/ui/baseui" + "github.com/Minizbot2012/orbbind/ui/bind" +) + +//Page Overweave side button configs +type Page struct { + baseui.PageWithBindings + binds *orbweaver.PKM + dev map[string]fyne.CanvasObject + parent fyne.Window +} + +//SetBindings Loads bindings from SIP +func (p *Page) SetBindings(o *orbweaver.PKM) { + p.binds = o +} + +//Create Creates the page +func (p *Page) Create() *widget.TabItem { + p.dev = make(map[string]fyne.CanvasObject) + strs := []string{"Upper Button", "Dpad Up", "Dpad Right", "Dpad Down", "Dpad Left", "Lower Button"} + for j := 0; j < 6; j++ { + id := j + 1 + p.dev["B"+strconv.Itoa(id)] = widget.NewButton(strs[j], func() { + popup := bind.NewBindPage(id, p.parent, p.binds.SIP[id-1]) + dialog.ShowCustomConfirm("Binding", "Set", "Cancel", popup.Create(string(id)), func(b bool) { + if b { + p.binds.SIP[popup.Bind.Bindid-1] = popup.Bind.Bound + } + }, p.parent) + }) + } + cont := fyne.NewContainerWithLayout(layout.NewBorderLayout(p.dev["B2"], p.dev["B4"], p.dev["B5"], p.dev["B3"]), p.dev["B2"], p.dev["B4"], p.dev["B5"], p.dev["B3"], widget.NewVBox(p.dev["B1"], p.dev["B6"])) + return widget.NewTabItem("Side Config", cont) +} + +//NewSidePage Creates a new side configuration page +func NewSidePage(parent fyne.Window, pkm *orbweaver.PKM) *Page { + p := &Page{} + p.binds = pkm + p.parent = parent + return p +}