mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-03-22 03:56:13 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 250e51ef0c | |||
| 3102bbe4c3 | |||
| 530e01d939 |
@@ -3,11 +3,12 @@ module CyberarmEngine
|
|||||||
include Common
|
include Common
|
||||||
|
|
||||||
attr_accessor :options, :global_pause
|
attr_accessor :options, :global_pause
|
||||||
attr_reader :game_objects
|
attr_reader :game_objects, :timers
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
@game_objects = []
|
@game_objects = []
|
||||||
|
@timers = []
|
||||||
@global_pause = false
|
@global_pause = false
|
||||||
window.text_input = nil unless options[:preserve_text_input]
|
window.text_input = nil unless options[:preserve_text_input]
|
||||||
|
|
||||||
@@ -28,6 +29,8 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
@game_objects.each(&:update)
|
@game_objects.each(&:update)
|
||||||
|
@timers.each(&:update)
|
||||||
|
@timers.delete_if(&:dead?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def needs_redraw?
|
def needs_redraw?
|
||||||
@@ -120,5 +123,9 @@ module CyberarmEngine
|
|||||||
def add_game_object(object)
|
def add_game_object(object)
|
||||||
@game_objects << object
|
@game_objects << object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_timer(timer)
|
||||||
|
@timers << timer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,5 +19,9 @@ module CyberarmEngine
|
|||||||
@block.call if @block
|
@block.call if @block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dead?
|
||||||
|
@triggered && !@looping
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
module DSL
|
module DSL
|
||||||
|
def every(milliseconds, &block)
|
||||||
|
element_parent.gui_state.add_timer(
|
||||||
|
CyberarmEngine::Timer.new(milliseconds, true, &block)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after(milliseconds, &block)
|
||||||
|
element_parent.gui_state.add_timer(
|
||||||
|
CyberarmEngine::Timer.new(milliseconds, false, &block)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def flow(options = {}, &block)
|
def flow(options = {}, &block)
|
||||||
container(CyberarmEngine::Element::Flow, options, &block)
|
container(CyberarmEngine::Element::Flow, options, &block)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -79,7 +79,19 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def caret_position_under_mouse(mouse_x, mouse_y)
|
def caret_position_under_mouse(mouse_x, mouse_y)
|
||||||
active_line = row_at(mouse_y)
|
# get y scroll offset of element to get EditBox's selected row
|
||||||
|
y_scroll_offset = 0
|
||||||
|
e = parent
|
||||||
|
while (e)
|
||||||
|
if e.is_a?(Container)
|
||||||
|
y_scroll_offset += e.scroll_position.y
|
||||||
|
|
||||||
|
# root element has no parent so loop will terminate
|
||||||
|
e = e.parent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
active_line = row_at(mouse_y - y_scroll_offset)
|
||||||
right_offset = column_at(mouse_x, mouse_y)
|
right_offset = column_at(mouse_x, mouse_y)
|
||||||
|
|
||||||
buffer = @text_input.text.lines[0..active_line].join if active_line != 0
|
buffer = @text_input.text.lines[0..active_line].join if active_line != 0
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module CyberarmEngine
|
|||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
@game_objects = []
|
@game_objects = []
|
||||||
|
@timers = []
|
||||||
@global_pause = false
|
@global_pause = false
|
||||||
|
|
||||||
@down_keys = {}
|
@down_keys = {}
|
||||||
@@ -271,10 +272,14 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def redirect_scroll_jump_to(edge)
|
def redirect_scroll_jump_to(edge)
|
||||||
|
return if window.text_input
|
||||||
|
|
||||||
@mouse_over.publish(:"scroll_jump_to_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
|
@mouse_over.publish(:"scroll_jump_to_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_scroll_page(edge)
|
def redirect_scroll_page(edge)
|
||||||
|
return if window.text_input
|
||||||
|
|
||||||
@mouse_over.publish(:"scroll_page_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
|
@mouse_over.publish(:"scroll_page_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user