From 9397f953a5c1c390c9454b50027fd5a447556ea8 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 8 Nov 2021 09:01:15 +0100 Subject: [PATCH] Fix --- src/app.rb | 2 ++ src/lib/ui.rb | 31 ++----------------------------- src/ui/mainmenu.rb | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 src/ui/mainmenu.rb diff --git a/src/app.rb b/src/app.rb index 92241b1..782e18a 100755 --- a/src/app.rb +++ b/src/app.rb @@ -12,6 +12,8 @@ require_relative "lib/objects.rb" require_relative "lib/controller.rb" require_relative "lib/world.rb" +require_relative "ui/mainmenu.rb" + class Window < Gosu::Window attr_accessor :caption, :ui, :world, :mainmenu attr_reader :width, :height, :fonts diff --git a/src/lib/ui.rb b/src/lib/ui.rb index 5b6f172..7636f41 100644 --- a/src/lib/ui.rb +++ b/src/lib/ui.rb @@ -69,6 +69,8 @@ class Button < UI default: 0xaa_aaaaaa } } + + @events = {} end def hover? @@ -96,32 +98,3 @@ class Button < UI self.draw_text(self.text, self.font, self.width/2 - self.text_width/2, self.height/2 - self.text_height/2, self.colors[:text][sel]) end end - - -class MainMenu < UI - attr_accessor :show, :playbtn, :quitbtn - def initialize(window, show=false) - super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99 - @show = show - - @playbtn = Button.new(self.window, self, "Play", self.window.fonts[:button]) - @playbtn.add_event(:onclick, method(:quit_game)) - @playbtn.x, @playbtn.y = self.width/2 - @playbtn.width/2, self.height/2 - @playbtn.height/2 - - @quitbtn = Button.new(self.window, self, "Quit", self.window.fonts[:button]) - @quitbtn.x, @quitbtn.y = self.width/2 - @quitbtn.width/2, @quitbtn.height + @playbtn.y + 16 - end - - - def render - if( @show ) then - self.draw_rect(0, 0, self.width, self.height, 0xaa_111015) - - titletext = "Hohmann Miner" - titlewidth = self.window.fonts[:title].text_width(titletext) - self.draw_text(titletext, self.window.fonts[:title], self.width/2 - titlewidth/2, self.height/4) - @playbtn.render - @quitbtn.render - end - end -end diff --git a/src/ui/mainmenu.rb b/src/ui/mainmenu.rb new file mode 100644 index 0000000..f9371ae --- /dev/null +++ b/src/ui/mainmenu.rb @@ -0,0 +1,31 @@ +def quit_game + puts "QUIT" +end + +class MainMenu < UI + attr_accessor :show, :playbtn, :quitbtn + def initialize(window, show=false) + super window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 99 + @show = show + + @playbtn = Button.new(self.window, self, "Play", self.window.fonts[:button]) + @playbtn.add_event(:onclick, method(:quit_game)) + @playbtn.x, @playbtn.y = self.width/2 - @playbtn.width/2, self.height/2 - @playbtn.height/2 + + @quitbtn = Button.new(self.window, self, "Quit", self.window.fonts[:button]) + @quitbtn.x, @quitbtn.y = self.width/2 - @quitbtn.width/2, @quitbtn.height + @playbtn.y + 16 + end + + + def render + if( @show ) then + self.draw_rect(0, 0, self.width, self.height, 0xaa_111015) + + titletext = "Hohmann Miner" + titlewidth = self.window.fonts[:title].text_width(titletext) + self.draw_text(titletext, self.window.fonts[:title], self.width/2 - titlewidth/2, self.height/4) + @playbtn.render + @quitbtn.render + end + end +end