Added flags to use ffi-gosu optionally instead of always trying, made tooltip affected by theme (the last set theme in setup will be used to style the tooltip)

This commit is contained in:
2021-03-12 08:33:16 -06:00
parent 1e0d2004b5
commit abb989f842
5 changed files with 16 additions and 6 deletions

View File

@@ -1,9 +1,8 @@
CYBERARM_ENGINE_ROOT_PATH = File.expand_path("..", __dir__) CYBERARM_ENGINE_ROOT_PATH = File.expand_path("..", __dir__)
begin if ARGV.join.include?("--ffi-gosu")
require File.expand_path("../../ffi-gosu/lib/gosu", File.dirname(__FILE__)) require File.expand_path("../../ffi-gosu/lib/gosu", __dir__)
rescue LoadError => e else
pp e
require "gosu" require "gosu"
end end
require "json" require "json"

View File

@@ -70,6 +70,7 @@ module CyberarmEngine
else else
klass.new(path) klass.new(path)
end end
hash[path] = instance hash[path] = instance
asset = instance asset = instance
end end

View File

@@ -17,6 +17,11 @@ module CyberarmEngine
def setup def setup
end end
# Called immediately after setup returns.
# GuiState uses this to set current_theme for ToolTip
def post_setup
end
def draw def draw
@game_objects.each(&:draw) @game_objects.each(&:draw)
end end

View File

@@ -26,12 +26,15 @@ module CyberarmEngine
@dragging_element = nil @dragging_element = nil
@pending_recalculate_request = false @pending_recalculate_request = false
@tip = Element::ToolTip.new("", parent: @root_container, z: Float::INFINITY)
@menu = nil @menu = nil
@min_drag_distance = 0 @min_drag_distance = 0
@mouse_pos = Vector.new @mouse_pos = Vector.new
end 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 # throws :blur event to focused element and sets GuiState focused element
# Does NOT throw :focus event at element or set element as focused # Does NOT throw :focus event at element or set element as focused
def focus=(element) def focus=(element)
@@ -103,7 +106,7 @@ module CyberarmEngine
@tip.x = window.mouse_x - @tip.width / 2 @tip.x = window.mouse_x - @tip.width / 2
@tip.x = 0 if @tip.x < 0 @tip.x = 0 if @tip.x < 0
@tip.x = window.width - @tip.width if @tip.x + @tip.width > window.width @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 = 0 if @tip.y < 0
@tip.y = window.height - @tip.height if @tip.y + @tip.height > window.height @tip.y = window.height - @tip.height if @tip.y + @tip.height > window.height
@tip.update @tip.update

View File

@@ -77,10 +77,12 @@ module CyberarmEngine
if klass.instance_of?(klass.class) && defined?(klass.options) if klass.instance_of?(klass.class) && defined?(klass.options)
@states << klass @states << klass
klass.setup if options[:setup] klass.setup if options[:setup]
klass.post_setup if options[:setup]
else else
@states << klass.new(options) if child_of?(klass, GameState) @states << klass.new(options) if child_of?(klass, GameState)
@states << klass.new if child_of?(klass, Element::Container) @states << klass.new if child_of?(klass, Element::Container)
current_state.setup if current_state.instance_of?(klass) && options[:setup] 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
end end