From 049c0c22f386a1d295e627f3cae688719a383742 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 5 Apr 2021 12:05:51 +0200 Subject: [PATCH] feat: add save selection menu Fixes #72 --- sonic-radiance.love/assets/gui/emeralds.png | Bin 0 -> 1792 bytes sonic-radiance.love/game/modules/gui/init.lua | 31 ++++++++ .../scenes/menus/titlescreen/menu.lua | 66 ++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 sonic-radiance.love/assets/gui/emeralds.png create mode 100644 sonic-radiance.love/scenes/menus/titlescreen/menu.lua diff --git a/sonic-radiance.love/assets/gui/emeralds.png b/sonic-radiance.love/assets/gui/emeralds.png new file mode 100644 index 0000000000000000000000000000000000000000..6a603dff0469f4e59ca63b03c3d3cbe37b6c2477 GIT binary patch literal 1792 zcmV+b2mknqP)EX>4Tx04R}tk-JO7P!z_$rY$W}aZpgCLx$EtEQo?QxLCy^R0y?#RR{CvLrBt) zq_{W=t_26t#n+&JfavPrDhPrih`9I<_*$gIbCW=ev|hNJU%s64aqo8l?p&2MD>Mpd zx^3n%X@0q|!bjc^LKso>BPq(3F)avLbX?yL2(WseVqTs5+OBS;Xvsi;C!UiH(5|8vjLR-_QO0IIH$xmJ=F2TCwXj? z&#il`Fy3aYsWsU@C%a*+s4p#29i|;e1}Zk7!GMJ#cu1(xw+b66syZnaa@3WkY}@+` zx;_HUNv@YnGqb3Yr|3F>y~W>*tu~R=pWi$dApG0oC-@7+jdY_9$b?}4000JJOGiWi{{a60|De66 zlK=n!32;bRa{vG?BLDy{BLR4&KXw2B00(qQO+^Rg1O*5%5QO0YOaK4?9CSrkbVF}# zZDnqB07G(RVRU6=Aa`kWXdp*yX>D+GW$sQG2LJ#B%1J~)RA}Dqn!RfqNf^eT&0i3A zDz#Td-AR??&P@;s7f5698PX`YuuTvc3<7hNeF1X^CMZ4#)*ToULm)8(qFW9Ub&=s< zRmyPSHKb8z_gBmnyR$o=yR&i*r zrpcGurS@0Vc67qMUe8$Z=;+8K`BvyD+|JC}-;KQsL^r+D6~ z=AL!yV`STeRPmr7Xye;imE8{xIUCp@jU74Y(DbBiWFoN4J@P z?du<3g|xBhhHwMG8nLR~*$m+Z0CH+M??(~b0PxTRC^4fp~afKK?{^*AKdLu=TO}j3`Eon=T(+aJMGse$We-z=Cv_;5ig;vEL zTZEieXjQx$CqBGhbw#-4yhX?>OZvRWOl7UPBHWU; z2zeuglp#Y(9d!$)5>P>#E-sCMw3fz2OtiY2X{4fMDwwmbS z=K5j<9?bx(2-+*rcsAU8U#!5F5xfv!zBGcH>x&gQ2m;iq6<)epK@bEcaPxh!0?%&% z_bxx?-VMjI;pX}Rr10URC48AJ)ZsIvsNhaD`KFaT18$|Z&-m(YQ(m}zVFb6@%dL?F z;!Q=x+C4CVTm9m5nn2vyR8;Q`Be>Ohzh@wRlydr$4!2T!@bXm*ac8BaczJzo0=GKv zH#Z5ys;B1fpG@FZYJY|wL%fBq!m@6s!p**9qDUpr0XH|to{UTduRYBVH$QjgBpW>y z&mWN&ZvM#WF=J1}H~VpJxcRwOi#3AYw;gx3Y& z*4q{OIG9F&=Z9NsSE%>KI0U=^+@U&7XU-iILgCu%Kg@AUV{$G<+3o&LW4yq{kY{7u5vvi1Ncgn*C%PHbt*klPey zwS0SU%bUJN7N$*37nt|q; number) then + emerald = love.graphics.newQuad(0,0,23,17,23*8, 17) + else + emerald = love.graphics.newQuad((i*23),0,23,17,23*8, 17) + --emerald = love.graphics.newQuad((i*23),0,23,17,23*7, 17) + end + + local isPair = (i%2 == 0) + local y = 0 + if (isPair == true) then + y = 14 + end + love.graphics.draw(emeralds, emerald,x,y) + emerald:release() + end + + love.graphics.setCanvas( ) + local imagedata = canvas:newImageData() + local texture = love.graphics.newImage( imagedata ) + imagedata:release() + canvas:release() + return texture +end + return gui diff --git a/sonic-radiance.love/scenes/menus/titlescreen/menu.lua b/sonic-radiance.love/scenes/menus/titlescreen/menu.lua new file mode 100644 index 0000000..f45cf58 --- /dev/null +++ b/sonic-radiance.love/scenes/menus/titlescreen/menu.lua @@ -0,0 +1,66 @@ +local RadianceMenu = require "game.modules.menus.parents.menu" +local RadianceWidget = require "game.modules.menus.parents.widget" +local SaveMenu = RadianceMenu:extend() +local SaveWidget = RadianceWidget:extend() + +local gui = require "game.modules.gui" +local charutils = require "game.utils.characters" + + +local HPADDING = 68 +local VPADDING = 28 + +function SaveMenu:new(scene) + local w, h = 424 - (HPADDING * 2), 240 - (VPADDING * 2) + + SaveMenu.super.new(self, scene, "save", HPADDING, VPADDING + 1, w, h, 3) + local metadata = game:getMetadata() + for i, save in ipairs(metadata) do + SaveWidget(self.scene, i, save) + end + self.textBox = gui.newTextBox("assets/gui/dialogbox.png", w - 8, (h / 3)) +end + +function SaveMenu:cancelAction() + self.scene.menusystem:reset() + self.scene.haveMenu = false +end + +function SaveWidget:new(scene, saveid, savedata) + SaveWidget.super.new(self, scene, "save") + self.scene.menusystem:switchMenu("save") + self.saveid = saveid + self.savedata = savedata + self.emeralds = gui.getEmeraldsTexture(self.savedata.emeralds) +end + +function SaveWidget:drawCanvas() + local basex, basey = 4, 2 + love.graphics.draw(self.menu.textBox, basex, basey) + if (self.savedata.exist) then + local str = "Save " .. self.saveid + str = str .. "(" .. utils.math.numberToString(self.savedata.completion,3) .. "%)" + str = str .. " - " .. utils.time.toString(self.savedata.gametime) + str = str .. "\n" + str = str .. self.savedata.location .. "\n" + str = str .. "Rings: " .. self.savedata.rings + self.font:draw(str, basex + 8, basey + 4) + + for i, charName in ipairs(self.savedata.team) do + local data = charutils.getCharacterData(charName) + local x = 18*(#self.savedata.team - i + 1) + 4 + basex + self.scene.assets.tileset["charicons"]:drawTile(data.icon,self.width - x, basey + 4) + end + + love.graphics.draw(self.emeralds, basex + 168, basey + 21) + else + self.font:draw("New save", basex + 8, basey + 4) + end +end + +function SaveWidget:action() + game:read(self.saveid) + scenes.debug.menu() +end + +return SaveMenu