From 79996ccd346bdbc4de9562a1291dba953a764bfe Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 8 Apr 2023 21:26:08 -0700 Subject: [PATCH] ListBoxes Overhaul * Overhaul the clunky old alpha Edit Level/Doodad menu with a modernized version featuring the new ListBox widget. * The new level loader is a Window that can be spawned from anywhere instead of on a dedicated MenuScene. Updates to doodad scripts: * Actor.IsOnScreen() checks whether an actor's visual sprite box is on-screen in the level viewport. `Self.IsOnScreen()` will check for the current actor. Other changes * PlaySound() to deduplicate the same sound effect from playing at once. --- go.mod | 19 ++-- go.sum | 104 +++++++++++---------- pkg/main_scene.go | 76 ++++++++++++--- pkg/sound/sound_sdl.go | 7 +- pkg/uix/actor.go | 14 ++- pkg/uix/canvas_actors.go | 2 + pkg/uix/magic-form/magic_form.go | 9 +- pkg/uix/scripting.go | 11 ++- pkg/windows/open_drawing.go | 156 +++++++++++++++++++++++++++++++ pkg/windows/open_level_editor.go | 6 ++ pkg/windows/publish_level.go | 8 +- 11 files changed, 321 insertions(+), 91 deletions(-) create mode 100644 pkg/windows/open_drawing.go diff --git a/go.mod b/go.mod index fe89296..6775db1 100644 --- a/go.mod +++ b/go.mod @@ -3,25 +3,24 @@ module git.kirsle.net/SketchyMaze/doodle go 1.16 require ( - git.kirsle.net/go/audio v0.0.0-20201121073642-65068820cbc0 + git.kirsle.net/go/audio v0.0.0-20230310065553-fa6eb3d3a029 git.kirsle.net/go/log v0.0.0-20200902035305-70ac2848949b git.kirsle.net/go/render v0.0.0-20220505053906-129a24300dfa - git.kirsle.net/go/ui v0.0.0-20221010004159-d82ef0b75165 + git.kirsle.net/go/ui v0.0.0-20230409041824-8716c479e90b github.com/aichaos/rivescript-go v0.3.1 - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible - github.com/dop251/goja v0.0.0-20221003171542-5ea1285e6c91 + github.com/dlclark/regexp2 v1.9.0 // indirect + github.com/dop251/goja v0.0.0-20230402114112-623f9dda9079 github.com/fsnotify/fsnotify v1.4.9 github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d + github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect github.com/google/uuid v1.3.0 github.com/gopherjs/gopherjs v1.17.2 // indirect github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f // indirect github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e // indirect - github.com/urfave/cli/v2 v2.19.2 - github.com/veandco/go-sdl2 v0.4.25 - golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect - golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 - golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect - golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect + github.com/urfave/cli/v2 v2.25.1 + github.com/veandco/go-sdl2 v0.4.34 + golang.org/x/crypto v0.8.0 // indirect + golang.org/x/image v0.7.0 ) diff --git a/go.sum b/go.sum index 483b5ff..4da8c0e 100644 --- a/go.sum +++ b/go.sum @@ -37,19 +37,16 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.kirsle.net/go/audio v0.0.0-20201121073642-65068820cbc0 h1:cTJeG7Rf51Uc1LGEc8HfRuSGcN3rDREQiit31NAYMDw= -git.kirsle.net/go/audio v0.0.0-20201121073642-65068820cbc0/go.mod h1:RD2Kyiy2lgayzQYmrh0S0/HLiq4XgAldt7MISCvtX5Y= +git.kirsle.net/go/audio v0.0.0-20230310065553-fa6eb3d3a029 h1:B0JKY/0NlXWlnZdf9dgm/PQpxQaoWyGUhnmv1AquvwQ= +git.kirsle.net/go/audio v0.0.0-20230310065553-fa6eb3d3a029/go.mod h1:RD2Kyiy2lgayzQYmrh0S0/HLiq4XgAldt7MISCvtX5Y= git.kirsle.net/go/log v0.0.0-20200902035305-70ac2848949b h1:TDxEEWOJqMzsu9JW8/QgmT1lgQ9WD2KWlb2lKN/Ql2o= git.kirsle.net/go/log v0.0.0-20200902035305-70ac2848949b/go.mod h1:jl+Qr58W3Op7OCxIYIT+b42jq8xFncJXzPufhrvza7Y= -git.kirsle.net/go/render v0.0.0-20211231003948-9e640ab5c3da/go.mod h1:ss7pvZbGWrMaDuZwyUTjV9+T0AJwAkxZZHwMFsvHrkk= git.kirsle.net/go/render v0.0.0-20220505053906-129a24300dfa h1:Oa99SXkmFGnUNy+toPMQyW/eYotN1nZ9BWAThQ/huiM= git.kirsle.net/go/render v0.0.0-20220505053906-129a24300dfa/go.mod h1:ss7pvZbGWrMaDuZwyUTjV9+T0AJwAkxZZHwMFsvHrkk= -git.kirsle.net/go/ui v0.0.0-20220409211920-3b653e503c5a h1:7pmqBcIfxOxCMCvnCS0XWM9NeXbzKTSQfiJc2IKJW+k= -git.kirsle.net/go/ui v0.0.0-20220409211920-3b653e503c5a/go.mod h1:cWD/tl2OUj0jWUQxW7BcapxiOFmnCPkrfzJt2tOiD1E= -git.kirsle.net/go/ui v0.0.0-20221010004159-d82ef0b75165 h1:/IsRyl4lSsGr3i9IP71HFBQlIGKpwQaDiAlZIqw7bVo= -git.kirsle.net/go/ui v0.0.0-20221010004159-d82ef0b75165/go.mod h1:cWD/tl2OUj0jWUQxW7BcapxiOFmnCPkrfzJt2tOiD1E= +git.kirsle.net/go/ui v0.0.0-20230409041824-8716c479e90b h1:8+TSDXLE8Ts4xwqhGOZrqfDJYgMf4em0TqLfonf4t/E= +git.kirsle.net/go/ui v0.0.0-20230409041824-8716c479e90b/go.mod h1:LZejaASDPvZKdNv/cpvsYIWjJEE09up4ud8z20ULnfw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/aichaos/rivescript-go v0.3.1 h1:MvSssqWAU+oU3yfnanKpK5n+e0pLCA0MEELZE4VXV0g= github.com/aichaos/rivescript-go v0.3.1/go.mod h1:8qm1P1SThiwgbtmO+74QUMlV9HT4MSInWT8ivoO58LQ= @@ -61,8 +58,14 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= +github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= +github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -70,7 +73,6 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -78,17 +80,13 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 h1:Izz0+t1Z5nI16/II7vuEo/nHjodOg0p7+OiDpjX5t1E= github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= -github.com/dlclark/regexp2 v1.4.1-0.20220402034307-55964957c159 h1:76tGhMs2VcMihnjZxTZ64bC6HtSZdSoF+EYwd/Azryg= -github.com/dlclark/regexp2 v1.4.1-0.20220402034307-55964957c159/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= -github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo= github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dlclark/regexp2 v1.9.0 h1:pTK/l/3qYIKaRXuHnEnIf7Y5NxfRPfpb7dis6/gdlVI= +github.com/dlclark/regexp2 v1.9.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= -github.com/dop251/goja v0.0.0-20220501172647-e1eca0b61fa9 h1:BXEAWJOT2C6ex9iOzVnrYWMFjTRccNs7p8fpLCLLcm0= -github.com/dop251/goja v0.0.0-20220501172647-e1eca0b61fa9/go.mod h1:TQJQ+ZNyFVvUtUEtCZxBhfWiH7RJqR3EivNmvD6Waik= -github.com/dop251/goja v0.0.0-20221003171542-5ea1285e6c91 h1:1PfaQuGdeJVnHHQ0tg0Jw7MXagyqaAupJyk35/QM3I4= -github.com/dop251/goja v0.0.0-20221003171542-5ea1285e6c91/go.mod h1:yRkwfj0CBpOGre+TwBsqPV0IH0Pk73e4PXJOeNDboGs= +github.com/dop251/goja v0.0.0-20230402114112-623f9dda9079 h1:xkbJGxVnk5sM8/LXeTKaBOfAZrI+iqvIPyH8oK1c6CQ= +github.com/dop251/goja v0.0.0-20230402114112-623f9dda9079/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4= github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y= github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -102,8 +100,6 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/gen2brain/dlgs v0.0.0-20211108104213-bade24837f0b h1:M0/hjawi9ur15zpqL/h66ga87jlYA7iAuZ4HC6ak08k= -github.com/gen2brain/dlgs v0.0.0-20211108104213-bade24837f0b/go.mod h1:/eFcjDXaU2THSOOqLxOPETIbHETnamk8FA/hMjhg/gU= github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d h1:dHYKX8CBAs1zSGXm3q3M15CLAEwPEkwrK1ed8FCo+Xo= github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d/go.mod h1:/eFcjDXaU2THSOOqLxOPETIbHETnamk8FA/hMjhg/gU= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -173,6 +169,9 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg= +github.com/google/pprof v0.0.0-20230406165453-00490a63f317 h1:hFhpt7CTmR3DX+b4R19ydQFtofxT0Sv3QsKNMVQYTMQ= +github.com/google/pprof v0.0.0-20230406165453-00490a63f317/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= @@ -206,6 +205,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= +github.com/ianlancetaylor/demangle v0.0.0-20220517205856-0058ec4f073c/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -288,16 +289,12 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e h1:Ee+VZw13r9NTOMnwTPs6O5KZ0MJU54hsxu9FpZ4pQ10= github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e/go.mod h1:fSIW/szJHsRts/4U8wlMPhs+YqJC+7NYR+Qqb1uJVpA= -github.com/urfave/cli/v2 v2.6.0 h1:yj2Drkflh8X/zUrkWlWlUjZYHyWN7WMmpVxyxXIUyv8= -github.com/urfave/cli/v2 v2.6.0/go.mod h1:oDzoM7pVwz6wHn5ogWgFUU1s4VJayeQS+aEZDqXIEJs= -github.com/urfave/cli/v2 v2.19.2 h1:eXu5089gqqiDQKSnFW+H/FhjrxRGztwSxlTsVK7IuqQ= -github.com/urfave/cli/v2 v2.19.2/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= +github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw= +github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= github.com/veandco/go-sdl2 v0.4.1/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg= -github.com/veandco/go-sdl2 v0.4.8/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= -github.com/veandco/go-sdl2 v0.4.20 h1:/xEP4SBAcGCo++wKv90mxDDRlVPjZ9HpES82FTd6qkg= -github.com/veandco/go-sdl2 v0.4.20/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= -github.com/veandco/go-sdl2 v0.4.25 h1:J5ac3KKOccp/0xGJA1PaNYKPUcZm19IxhDGs8lJofPI= -github.com/veandco/go-sdl2 v0.4.25/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= +github.com/veandco/go-sdl2 v0.4.33/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= +github.com/veandco/go-sdl2 v0.4.34 h1:dqbUhV/SSJ35grdYTLv3iVxtO1NzNmgzMV//hyCyypY= +github.com/veandco/go-sdl2 v0.4.34/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -305,6 +302,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= @@ -326,10 +324,9 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 h1:NvGWuYG8dkDHFSKksI1P9faiVJ9rayE6l0+ouWVIDs8= -golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 h1:x8vtB3zMecnlqZIwJNUUpwYKYSqCz5jXbiyv0ZJJZeI= -golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= +golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -343,11 +340,9 @@ golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMk golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 h1:LRtI4W37N+KFebI/qV0OFiLUv4GLOWeEW5hn/KEJvxE= -golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY= -golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= +golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0= +golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw= +golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -371,6 +366,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -410,7 +407,9 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -434,6 +433,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -483,15 +484,18 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= -golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20221010170243-090e33056c14 h1:k5II8e6QD8mITdi+okbbmR/cIyEbeXLBhy5Ha4nevyc= -golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 h1:EH1Deb8WZJ0xc0WK//leUHXcX9aLE5SymusoTmMZye8= -golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20220919170432-7a66f970e087 h1:tPwmk4vmvVCMdr98VgL4JH+qZxPL8fqlUOHnyOM8N3w= -golang.org/x/term v0.0.0-20220919170432-7a66f970e087/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -500,8 +504,12 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -558,6 +566,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/main_scene.go b/pkg/main_scene.go index c944c76..1edb7d2 100644 --- a/pkg/main_scene.go +++ b/pkg/main_scene.go @@ -34,14 +34,16 @@ type MainScene struct { canvas *uix.Canvas // UI components. - labelTitle *ui.Label - labelSubtitle *ui.Label - labelVersion *ui.Label - labelHint *ui.Label - frame *ui.Frame // Main button frame - winRegister *ui.Window - winSettings *ui.Window - winLevelPacks *ui.Window + labelTitle *ui.Label + labelSubtitle *ui.Label + labelVersion *ui.Label + labelHint *ui.Label + frame *ui.Frame // Main button frame + winRegister *ui.Window + winSettings *ui.Window + winLevelPacks *ui.Window + winPlayLevel *ui.Window + winOpenDrawing *ui.Window // Update check variables. updateButton *ui.Button @@ -196,8 +198,10 @@ func (s *MainScene) Setup(d *Doodle) error { Style: &balance.ButtonBabyBlue, }, { - Name: "Play a Level", - Func: d.GotoPlayMenu, + Name: "Play a Level", + Func: func() { + s.showOpenDrawing(d, true) + }, Style: &balance.ButtonBabyBlue, }, { @@ -206,8 +210,10 @@ func (s *MainScene) Setup(d *Doodle) error { Style: &balance.ButtonPink, }, { - Name: "Edit Drawing", - Func: d.GotoLoadMenu, + Name: "Edit Drawing", + Func: func() { + s.showOpenDrawing(d, false) + }, Style: &balance.ButtonPink, }, { @@ -298,6 +304,52 @@ func (s *MainScene) Setup(d *Doodle) error { return nil } +// common function to show the "Open Drawing" window for the Play Level/Edit Drawing buttons. +func (s *MainScene) showOpenDrawing(d *Doodle, forPlay bool) { + // Find or create the relevant window. + var window *ui.Window + if forPlay { + window = s.winPlayLevel + if window == nil { + window = windows.NewOpenDrawingWindow(windows.OpenDrawing{ + Supervisor: s.Supervisor, + Engine: shmem.CurrentRenderEngine, + LevelsOnly: true, + OnOpenDrawing: func(filename string) { + d.PlayLevel(filename) + }, + OnCloseWindow: func() { + s.winPlayLevel.Destroy() + s.winPlayLevel = nil + }, + }) + s.winPlayLevel = window + } + } else { + window = s.winOpenDrawing + if window == nil { + window = windows.NewOpenDrawingWindow(windows.OpenDrawing{ + Supervisor: s.Supervisor, + Engine: shmem.CurrentRenderEngine, + OnOpenDrawing: func(filename string) { + d.EditFile(filename) + }, + OnCloseWindow: func() { + s.winOpenDrawing.Destroy() + s.winOpenDrawing = nil + }, + }) + s.winOpenDrawing = window + } + } + + window.MoveTo(render.Point{ + X: (d.width / 2) - (window.Size().W / 2), + Y: (d.height / 2) - (window.Size().H / 2), + }) + window.Show() +} + // setupAsync runs background tasks from setup, e.g. eager load // chunks of the level for cache. func (s *MainScene) setupAsync(d *Doodle) error { diff --git a/pkg/sound/sound_sdl.go b/pkg/sound/sound_sdl.go index 31ff38d..a44259c 100644 --- a/pkg/sound/sound_sdl.go +++ b/pkg/sound/sound_sdl.go @@ -1,4 +1,5 @@ -//+build !js,!wasm +//go:build !js && !wasm +// +build !js,!wasm package sound @@ -99,11 +100,11 @@ func LoadSound(filename string) audio.Playable { return &track } -// PlaySound plays the named sound. +// PlaySound plays the named sound. It will de-duplicate if the same sound is already playing. func PlaySound(filename string) { log.Debug("Play sound: %s", filename) sound := LoadSound(filename) - if sound != nil { + if sound != nil && !sound.Playing() { sound.Play(1) } } diff --git a/pkg/uix/actor.go b/pkg/uix/actor.go index e9bfa3c..0dfed3f 100644 --- a/pkg/uix/actor.go +++ b/pkg/uix/actor.go @@ -25,9 +25,10 @@ import ( // as defined in the map: its spawn coordinate and configuration. // - A uix.Canvas that can present the actor's graphics to the screen. type Actor struct { - Drawing *doodads.Drawing - Actor *level.Actor - Canvas *Canvas + Drawing *doodads.Drawing + Actor *level.Actor + Canvas *Canvas + LevelCanvas *Canvas // the parent Canvas of the level we reside in activeLayer int // active drawing frame for display flagDestroy bool // flag the actor for destruction @@ -57,7 +58,6 @@ type Actor struct { // Mutex. muInventory sync.RWMutex - muData sync.RWMutex } // NewActor sets up a uix.Actor. @@ -157,6 +157,12 @@ func (a *Actor) IsWet() bool { return a.wet } +// IsOnScreen checks whether the actor's visual sprite box is on-screen in the level viewport. +func (a *Actor) IsOnScreen() bool { + var result = a.Position().Inside(a.LevelCanvas.ViewportRelative()) + return result +} + // SetWet updates the state of the actor's wet-ness. func (a *Actor) SetWet(v bool) { a.wet = v diff --git a/pkg/uix/canvas_actors.go b/pkg/uix/canvas_actors.go index 634e0fd..c6a6fa8 100644 --- a/pkg/uix/canvas_actors.go +++ b/pkg/uix/canvas_actors.go @@ -64,6 +64,7 @@ func (w *Canvas) InstallActors(actors level.ActorMap) error { // position to the Point defined in the level data. liveActor := NewActor(id, actor, doodad) liveActor.Canvas.parent = w + liveActor.LevelCanvas = w liveActor.MoveTo(actor.Point) w.actors = append(w.actors, liveActor) @@ -151,6 +152,7 @@ func (w *Canvas) InstallScripts() error { // AddActor injects additional actors into the canvas, such as a Player doodad. func (w *Canvas) AddActor(actor *Actor) error { + actor.LevelCanvas = w w.actors = append(w.actors, actor) return nil } diff --git a/pkg/uix/magic-form/magic_form.go b/pkg/uix/magic-form/magic_form.go index 7e2f902..071b8be 100644 --- a/pkg/uix/magic-form/magic_form.go +++ b/pkg/uix/magic-form/magic_form.go @@ -118,13 +118,10 @@ func (form Form) Create(into *ui.Frame, fields []Field) { // Pager row? if row.Pager != nil { - row.Pager.Compute(form.Engine) - form.Supervisor.Add(row.Pager) + row.Pager.Supervise(form.Supervisor) frame.Pack(row.Pager, ui.Pack{ - Side: ui.W, - Expand: true, + Side: ui.W, }) - } // Buttons row? @@ -284,7 +281,7 @@ func (form Form) Create(into *ui.Frame, fields []Field) { } }) - picker.Center(shmem.CurrentRenderEngine.WindowSize()) + picker.Center(form.Engine.WindowSize()) picker.Show() return nil }) diff --git a/pkg/uix/scripting.go b/pkg/uix/scripting.go index c43be0d..ffab91b 100644 --- a/pkg/uix/scripting.go +++ b/pkg/uix/scripting.go @@ -94,11 +94,8 @@ func (w *Canvas) MakeSelfAPI(actor *Actor) map[string]interface{} { "Title": actor.Doodad().Title, // functions - "ID": actor.ID, - "Size": func() render.Rect { - var size = actor.Doodad().ChunkSize() - return render.NewRect(size, size) - }, + "ID": actor.ID, + "Size": actor.Size, "GetTag": actor.Doodad().Tag, "Options": actor.Options, "GetOption": func(name string) interface{} { @@ -117,6 +114,10 @@ func (w *Canvas) MakeSelfAPI(actor *Actor) map[string]interface{} { actor.MoveBy(p) actor.SetGrounded(false) }, + "IsOnScreen": actor.IsOnScreen, + // // TODO: passing this to actor.IsOnScreen didn't work? + // return actor.Position().Inside(actor.Canvas.ViewportRelative()) + // }, "Grounded": actor.Grounded, "SetHitbox": actor.SetHitbox, "Hitbox": actor.Hitbox, diff --git a/pkg/windows/open_drawing.go b/pkg/windows/open_drawing.go new file mode 100644 index 0000000..62dacb1 --- /dev/null +++ b/pkg/windows/open_drawing.go @@ -0,0 +1,156 @@ +package windows + +import ( + "git.kirsle.net/SketchyMaze/doodle/pkg/balance" + "git.kirsle.net/SketchyMaze/doodle/pkg/log" + "git.kirsle.net/SketchyMaze/doodle/pkg/userdir" + "git.kirsle.net/go/render" + "git.kirsle.net/go/ui" +) + +// OpenDrawing window lets the user open a drawing or play a user level. +type OpenDrawing struct { + Supervisor *ui.Supervisor + Engine render.Engine + LevelsOnly bool + + // Callback functions. + OnOpenDrawing func(filename string) + OnCloseWindow func() + + // Internal variables + window *ui.Window +} + +// NewOpenDrawingWindow initializes the window. +func NewOpenDrawingWindow(config OpenDrawing) *ui.Window { + // Default options. + var ( + title = "Open a drawing" + + // size of the popup window + width = 320 + height = 320 + ) + + window := ui.NewWindow(title) + window.SetButtons(ui.CloseButton) + window.Configure(ui.Config{ + Width: width, + Height: height, + Background: render.Grey, + }) + config.window = window + + frame := ui.NewFrame("Window Body Frame") + window.Pack(frame, ui.Pack{ + Side: ui.N, + Fill: true, + Expand: true, + }) + + // Divide the Levels and Doodads into tabs. + tabs := ui.NewTabFrame("Tabs") + tabs.SetBackground(render.DarkGrey) + config.setupLevelTab(width, height, tabs) + if !config.LevelsOnly { + config.setupDoodadTab(width, height, tabs) + } + tabs.Supervise(config.Supervisor) + + window.Pack(tabs, ui.Pack{ + Side: ui.N, + Expand: true, + }) + + // Close button. + if config.OnCloseWindow != nil { + closeBtn := ui.NewButton("Close Window", ui.NewLabel(ui.Label{ + Text: "Close", + Font: balance.MenuFont, + })) + closeBtn.Handle(ui.Click, func(ed ui.EventData) error { + config.OnCloseWindow() + return nil + }) + config.Supervisor.Add(closeBtn) + window.Place(closeBtn, ui.Place{ + Bottom: 15, + Center: true, + }) + } + + window.Supervise(config.Supervisor) + window.Hide() + return window +} + +func (config OpenDrawing) setupLevelTab(width, height int, tabs *ui.TabFrame) *ui.Frame { + frame := tabs.AddTab("Levels", ui.NewLabel(ui.Label{ + Text: "My Levels", + Font: balance.TabFont, + })) + + // Levels Listbox. + levelList := ui.NewListBox("Levels", ui.ListBox{}) + levelList.Resize(render.NewRect(width-10, height-80)) + frame.Pack(levelList, ui.Pack{ + Side: ui.N, + Expand: true, + }) + + levelList.Handle(ui.Change, func(ed ui.EventData) error { + filename, _ := ed.Value.(string) + log.Info("Clicked on: %s", filename) + if config.OnOpenDrawing != nil { + config.OnOpenDrawing(filename) + } + return nil + }) + + // Get the user's levels. + levels, _ := userdir.ListLevels() + + for _, lvl := range levels { + levelList.AddLabel(lvl, lvl, func() {}) + } + + levelList.Supervise(config.Supervisor) + + return frame +} + +func (config OpenDrawing) setupDoodadTab(width, height int, tabs *ui.TabFrame) *ui.Frame { + frame := tabs.AddTab("Doodads", ui.NewLabel(ui.Label{ + Text: "My Custom Doodads", + Font: balance.TabFont, + })) + + // Doodads Listbox. + doodadList := ui.NewListBox("Doodads", ui.ListBox{}) + doodadList.Resize(render.NewRect(width-10, height-80)) + frame.Pack(doodadList, ui.Pack{ + Side: ui.N, + Expand: true, + }) + + doodadList.Handle(ui.Change, func(ed ui.EventData) error { + filename, _ := ed.Value.(string) + log.Info("Clicked on: %s", filename) + if config.OnOpenDrawing != nil { + config.OnOpenDrawing(filename) + } + return nil + }) + + // Get the user's doodads. + doodads, _ := userdir.ListDoodads() + + for _, lvl := range doodads { + doodadList.AddLabel(lvl, lvl, func() {}) + } + + doodadList.Supervise(config.Supervisor) + + return frame +} diff --git a/pkg/windows/open_level_editor.go b/pkg/windows/open_level_editor.go index 819dbe0..d833511 100644 --- a/pkg/windows/open_level_editor.go +++ b/pkg/windows/open_level_editor.go @@ -16,6 +16,12 @@ import ( ) // OpenLevelEditor is the "Open a Level to Edit It" window +// +// DEPRECATED: in favor of OpenDrawing which has a nicer listbox instead +// of the ugly button grid of this window. +// +// You can invoke this old window by the shell commands +// `$ d.GotoPlayMenu()` or `$ d.GotoLoadMenu()` type OpenLevelEditor struct { Supervisor *ui.Supervisor Engine render.Engine diff --git a/pkg/windows/publish_level.go b/pkg/windows/publish_level.go index 50a284f..f6c2705 100644 --- a/pkg/windows/publish_level.go +++ b/pkg/windows/publish_level.go @@ -34,9 +34,9 @@ func NewPublishWindow(cfg Publish) *ui.Window { windowWidth = 380 windowHeight = 220 page = 1 - perPage = 4 + perPage = 3 // rows of `columns` pages = 1 - maxPageButtons = 8 + maxPageButtons = 12 // columns and sizes to draw the doodad list columns = 3 @@ -218,7 +218,7 @@ func NewPublishWindow(cfg Publish) *ui.Window { Font: balance.UIFont, }, // Pager is broken, Supervisor doesn't pick it up, TODO - /*{ + { Label: "Doodads currently used on this level:", Font: balance.LabelFont, }, @@ -231,7 +231,7 @@ func NewPublishWindow(cfg Publish) *ui.Window { }, { Pager: pager, - },*/ + }, { Buttons: []magicform.Field{ {