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__)
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"

View File

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

View File

@@ -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

View File

@@ -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

View File

@@ -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