diff --git a/lib/cyberarm_engine.rb b/lib/cyberarm_engine.rb index 29704dc..b040af1 100644 --- a/lib/cyberarm_engine.rb +++ b/lib/cyberarm_engine.rb @@ -1,9 +1,8 @@ CYBERARM_ENGINE_ROOT_PATH = File.expand_path("..", __dir__) -begin - require File.expand_path("../../ffi-gosu/lib/gosu", File.dirname(__FILE__)) -rescue LoadError => e - pp e +if ARGV.join.include?("--ffi-gosu") + require File.expand_path("../../ffi-gosu/lib/gosu", __dir__) +else require "gosu" end require "json" diff --git a/lib/cyberarm_engine/common.rb b/lib/cyberarm_engine/common.rb index 108f7c6..6e1ed30 100644 --- a/lib/cyberarm_engine/common.rb +++ b/lib/cyberarm_engine/common.rb @@ -70,6 +70,7 @@ module CyberarmEngine else klass.new(path) end + hash[path] = instance asset = instance end diff --git a/lib/cyberarm_engine/game_state.rb b/lib/cyberarm_engine/game_state.rb index 5d64833..bce0ace 100644 --- a/lib/cyberarm_engine/game_state.rb +++ b/lib/cyberarm_engine/game_state.rb @@ -17,6 +17,11 @@ module CyberarmEngine def setup end + # Called immediately after setup returns. + # GuiState uses this to set current_theme for ToolTip + def post_setup + end + def draw @game_objects.each(&:draw) end diff --git a/lib/cyberarm_engine/ui/gui_state.rb b/lib/cyberarm_engine/ui/gui_state.rb index 53004ef..0271427 100644 --- a/lib/cyberarm_engine/ui/gui_state.rb +++ b/lib/cyberarm_engine/ui/gui_state.rb @@ -26,12 +26,15 @@ module CyberarmEngine @dragging_element = nil @pending_recalculate_request = false - @tip = Element::ToolTip.new("", parent: @root_container, z: Float::INFINITY) @menu = nil @min_drag_distance = 0 @mouse_pos = Vector.new end + def post_setup + @tip = Element::ToolTip.new("", parent: @root_container, z: Float::INFINITY, theme: current_theme) + end + # throws :blur event to focused element and sets GuiState focused element # Does NOT throw :focus event at element or set element as focused def focus=(element) @@ -103,7 +106,7 @@ module CyberarmEngine @tip.x = window.mouse_x - @tip.width / 2 @tip.x = 0 if @tip.x < 0 @tip.x = window.width - @tip.width if @tip.x + @tip.width > window.width - @tip.y = window.mouse_y - @tip.height + @tip.y = window.mouse_y - (@tip.height + 5) @tip.y = 0 if @tip.y < 0 @tip.y = window.height - @tip.height if @tip.y + @tip.height > window.height @tip.update diff --git a/lib/cyberarm_engine/window.rb b/lib/cyberarm_engine/window.rb index 9c98ffe..cf4a929 100644 --- a/lib/cyberarm_engine/window.rb +++ b/lib/cyberarm_engine/window.rb @@ -77,10 +77,12 @@ module CyberarmEngine if klass.instance_of?(klass.class) && defined?(klass.options) @states << klass klass.setup if options[:setup] + klass.post_setup if options[:setup] else @states << klass.new(options) if child_of?(klass, GameState) @states << klass.new if child_of?(klass, Element::Container) current_state.setup if current_state.instance_of?(klass) && options[:setup] + current_state.post_setup if current_state.instance_of?(klass) && options[:setup] end end