Class: AuthorEngine::Editor
- Defined in:
- lib/author_engine/containers/editor.rb
Constant Summary
Constants included from Part::Colors
Instance Attribute Summary collapse
-
#header_height ⇒ Object
readonly
Returns the value of attribute header_height.
-
#savefile ⇒ Object
readonly
Returns the value of attribute savefile.
Instance Method Summary collapse
- #add_buttons ⇒ Object
- #button_down(id) ⇒ Object
- #button_up(id) ⇒ Object
- #close ⇒ Object
- #draw ⇒ Object
-
#initialize(savefile) ⇒ Editor
constructor
A new instance of Editor.
- #lock ⇒ Object
- #position_buttons ⇒ Object
- #setup ⇒ Object
- #unlock ⇒ Object
- #update ⇒ Object
Methods included from Part::Colors
#black, #blue, #brown, #dark_blue, #dark_gray, #dark_green, #dark_purple, #green, #indigo, #light_gray, #orange, #peach, #pink, #red, #rgb, #white, #xml_color, #yellow
Methods included from Support
#code_editor, #mouse_over?, #sprite_editor, #window
Constructor Details
#initialize(savefile) ⇒ Editor
Returns a new instance of Editor.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/author_engine/containers/editor.rb', line 5 def initialize(savefile) @savefile = savefile @scale_x = window.scale_x @scale_y = window.scale_y @active_view = nil @header_height= (16 * @scale_y)+(@scale_y*2) @header_color = Gosu::Color.rgba(dark_green.red, dark_green.green, dark_green.blue, 100)#Gosu::Color.rgba(25, 255, 25, 100) @title = Text.new(message: "AuthorEngine", x: (1.0*@scale_x)) @title.y = @header_height/2 - @title.height/2 @views = [] @buttons = [] @locked = false end |
Instance Attribute Details
#header_height ⇒ Object (readonly)
Returns the value of attribute header_height.
3 4 5 |
# File 'lib/author_engine/containers/editor.rb', line 3 def header_height @header_height end |
#savefile ⇒ Object (readonly)
Returns the value of attribute savefile.
3 4 5 |
# File 'lib/author_engine/containers/editor.rb', line 3 def savefile @savefile end |
Instance Method Details
#add_buttons ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/author_engine/containers/editor.rb', line 26 def @play_viewer = PlayViewer.new(x: 0, y: @header_height+1, width: window.width, height: window.height-@header_height, background: dark_purple) @sprite_editor = SpriteEditor.new(x: 0, y: @header_height+1, width: window.width, height: window.height-@header_height, background: indigo) @level_editor = LevelEditor.new(x: 0, y: @header_height+1, width: window.width, height: window.height-@header_height, background: brown) @code_editor = CodeEditor.new(x: 0, y: @header_height+1, width: window.width, height: window.height-@header_height, background: black) @buttons << Button.new(image: "assets/ui/play_icon.png", tooltip: "Play", tag: :play_viewer, color: @header_color) {@active_view = @play_viewer; @active_view.focus; @code_editor.blur} @buttons << Button.new(image: "assets/ui/sprite_icon.png", tooltip: "Sprite Editor", tag: :sprite_editor, color: @header_color) {@active_view = @sprite_editor; @active_view.focus; @code_editor.blur} @buttons << Button.new(image: "assets/ui/level_icon.png", tooltip: "Level Editor", tag: :level_editor, color: @header_color) {@active_view = @level_editor; @active_view.focus; @code_editor.blur} @buttons << Button.new(image: "assets/ui/code_icon.png", tooltip: "Code Editor", tag: :code_editor, color: @header_color) {@active_view = @code_editor; @active_view.focus} @active_view = @play_viewer # @active_view.focus end |
#button_down(id) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/author_engine/containers/editor.rb', line 81 def (id) @savefile.save if window. && id == Gosu::KbS if window. && id == Gosu::KbO @savefile.save window.container = Loader.new end @active_view.(id) if @active_view end |
#button_up(id) ⇒ Object
91 92 93 94 95 |
# File 'lib/author_engine/containers/editor.rb', line 91 def (id) @buttons.each {|b| b.(id)} unless @locked @active_view.(id) if @active_view end |
#close ⇒ Object
75 76 77 78 79 |
# File 'lib/author_engine/containers/editor.rb', line 75 def close @savefile.save window.close! end |
#draw ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/author_engine/containers/editor.rb', line 61 def draw unless @locked Gosu.draw_rect(0, 0, window.width, @header_height, @header_color) @title.draw @buttons.each(&:draw) end @active_view.draw if @active_view end |
#lock ⇒ Object
58 |
# File 'lib/author_engine/containers/editor.rb', line 58 def lock; @locked = true; end |
#position_buttons ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/author_engine/containers/editor.rb', line 42 def total_width = 0 @buttons.each do |b| total_width+=b.width end raise "Header buttons are to wide (#{total_width})" if total_width > window.width origin = window.width - total_width x_offset = 0 @buttons.each_with_index do |b, i| b.x = origin + x_offset x_offset+=b.width end end |
#setup ⇒ Object
22 23 24 |
# File 'lib/author_engine/containers/editor.rb', line 22 def setup end |
#unlock ⇒ Object
59 |
# File 'lib/author_engine/containers/editor.rb', line 59 def unlock; @locked = false; end |
#update ⇒ Object
71 72 73 |
# File 'lib/author_engine/containers/editor.rb', line 71 def update @active_view.update if @active_view end |