Class: Chingu::GameStates::Edit
- Inherits:
-
Chingu::GameState
- Object
- Chingu::GameState
- Chingu::GameStates::Edit
- Defined in:
- lib/chingu/game_states/edit.rb
Overview
Premade game state for chingu - simple level editing. Start editing in a gamestate with:
push_game_state(Chingu::GameStates::Edit)
requires the global $window set to the instance of Gosu::Window (automaticly handled if you use Chingu::Window)
Edit will only edit game objects created with the editor itself or that's been loaded with load_game_objects. This makes mixing of loaded game objects and code create game objects possible, in the game, and in the editor.
Various shortcuts are available in the editor
1-5: create object 1..5 shown in toolbar DEL: delete selected objects CTRL+A: select all objects (not code-created ones though) S: Save E: Save and Quit Right Mouse Button Click: Copy object that was clicked on for fast duplication Arrows: Scroll within a viewport Page up/down: Modify the zorder of selected game objects
Constant Summary collapse
- CENTER_TO_FACTOR =
{ 0 => -1, 0.5 => 0, 1 => 1 }
Constants included from Helpers::GFX
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#exclude ⇒ Object
readonly
Returns the value of attribute exclude.
-
#file ⇒ Object
Returns the value of attribute file.
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#hud_color ⇒ Object
Returns the value of attribute hud_color.
Attributes inherited from Chingu::GameState
#game_objects, #game_state_manager, #options, #previous_game_state
Attributes included from Helpers::InputDispatcher
Instance Method Summary collapse
-
#bounding_box(game_object) ⇒ Object
(also: #bb)
Returns a bounding box (Rect-class) for any gameobject It will take into considerations rotation_center and scaling.
- #copy_game_object(template) ⇒ Object
- #create_object_1 ⇒ Object
- #create_object_2 ⇒ Object
- #create_object_3 ⇒ Object
- #create_object_4 ⇒ Object
- #create_object_5 ⇒ Object
- #create_object_nr(number) ⇒ Object
- #dec_alpha ⇒ Object
- #dec_zorder ⇒ Object
- #deselect_selected_game_objects ⇒ Object
-
#destroy_selected_game_objects ⇒ Object
Call destroy on all selected game objects.
- #display_help ⇒ Object
-
#draw ⇒ Object
DRAW.
- #draw_grid ⇒ Object
-
#draw_selections ⇒ Object
Draw a red rectangle around all selected objects.
-
#editable_game_objects ⇒ Object
Returns a list of game objects the editor can create.
- #empty_area_at_cursor ⇒ Object
- #esc ⇒ Object
- #finalize ⇒ Object
-
#game_object_at(x, y) ⇒ Object
Get editable object at X/Y ..
-
#game_object_classes ⇒ Object
Get all classes based on GameObject except Chingus internal classes.
- #game_object_icon_at(x, y) ⇒ Object
- #inc_alpha ⇒ Object
- #inc_zorder ⇒ Object
-
#initialize(options = {}) ⇒ Edit
constructor
A new instance of Edit.
- #inside_window?(x = $window.mouse_x, y = $window.mouse_y) ⇒ Boolean
-
#left_mouse_button ⇒ Object
CLICKED LEFT MOUSE BUTTON.
-
#method_missing(symbol, *args) ⇒ Object
If we're editing a game state with automaticly called special methods, the following takes care of those.
- #mouse_wheel_down ⇒ Object
- #mouse_wheel_up ⇒ Object
- #mouse_x ⇒ Object
- #mouse_y ⇒ Object
- #move_down ⇒ Object
- #move_left ⇒ Object
- #move_right ⇒ Object
- #move_up ⇒ Object
- #page_down ⇒ Object
- #page_up ⇒ Object
- #quit ⇒ Object
-
#released_left_mouse_button ⇒ Object
RELASED LEFT MOUSE BUTTON.
- #released_right_mouse_button ⇒ Object
-
#reset_selected_game_objects ⇒ Object
Resets selected game objects defaults, angle=0, scale=1.
- #right_mouse_button ⇒ Object
- #save ⇒ Object
- #save_and_quit ⇒ Object
- #scale_down ⇒ Object
- #scale_down_x ⇒ Object
- #scale_down_y ⇒ Object
- #scale_up ⇒ Object
- #scale_up_x ⇒ Object
- #scale_up_y ⇒ Object
- #scroll_down(amount = 10) ⇒ Object
- #scroll_left(amount = 10) ⇒ Object
- #scroll_right(amount = 10) ⇒ Object
- #scroll_up(amount = 10) ⇒ Object
-
#selected_game_objects ⇒ Object
Returns a list of selected game objects.
-
#setup ⇒ Object
SETUP.
- #tilt_left ⇒ Object
- #tilt_right ⇒ Object
- #try_save ⇒ Object
- #try_scroll_down ⇒ Object
- #try_scroll_left ⇒ Object
- #try_scroll_right ⇒ Object
- #try_scroll_up ⇒ Object
- #try_select_all ⇒ Object
-
#update ⇒ Object
UPDATE.
Methods inherited from Chingu::GameState
#button_down, #button_up, #close, #close_game, #draw_trait, #filename, #setup_trait, #to_s, #to_sym, trait, #trait_options, traits, #update_trait
Methods included from Helpers::ClassInheritableAccessor
Methods included from Helpers::InputClient
#add_inputs, #holding?, #holding_all?, #holding_any?, #input, #input=, #on_input
Methods included from Helpers::InputDispatcher
#add_input_client, #dispatch_button_down, #dispatch_button_up, #dispatch_input_for, #remove_input_client
Methods included from Helpers::GameObject
#add_game_object, #game_objects, #game_objects_of_class, #hide_game_object, #load_game_objects, #pause_game_object, #remove_game_object, #save_game_objects, #show_game_object, #unpause_game_object
Methods included from Helpers::GameState
#clear_game_states, #current_game_state, #game_states, #pop_game_state, #push_game_state, #switch_game_state, #transitional_game_state
Methods included from Helpers::GFX
#draw_circle, #draw_rect, #fill, #fill_gradient, #fill_rect
Constructor Details
#initialize(options = {}) ⇒ Edit
Returns a new instance of Edit.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/chingu/game_states/edit.rb', line 50 def initialize( = {}) super = {:draw_grid => true, :snap_to_grid => true, :resize_to_grid => true}.merge() @grid = [:grid] || [8,8] @grid_color = [:grid_color] || Gosu::Color.new(0xaa222222) @draw_grid = [:draw_grid] @snap_to_grid = [:snap_to_grid] # todo @resize_to_grid = [:resize_to_grid] # todo @classes = Array([:classes] || game_object_classes) @except = [:except] || [] @classes -= Array(@except) @debug = [:debug] @attributes = [:attributes] || [:x, :y, :angle, :zorder, :factor_x, :factor_y, :alpha] # # Turn on cursor + turn it back to its original value in finalize() # @original_cursor = $window.cursor $window.cursor = true p @classes if @debug @hud_color = Gosu::Color.new(200,70,70,70) @selected_game_object = nil self.input = { :f1 => :display_help, :left_mouse_button => :left_mouse_button, :released_left_mouse_button => :released_left_mouse_button, :right_mouse_button => :right_mouse_button, :released_right_mouse_button => :released_right_mouse_button, :delete => :destroy_selected_game_objects, :d => :destroy_selected_game_objects, :backspace => :reset_selected_game_objects, :holding_numpad_7 => :scale_down, :holding_numpad_9 => :scale_up, :holding_numpad_4 => :tilt_left, :holding_numpad_8 => :tilt_right, :holding_numpad_1 => :dec_alpha, :holding_numpad_3 => :inc_alpha, :r => :scale_up, :f => :scale_down, :t => :tilt_left, :g => :tilt_right, :y => :inc_zorder, :h => :dec_zorder, :u => :inc_alpha, :j => :dec_alpha, :page_up => :inc_zorder, :page_down => :dec_zorder, :s => :try_save, :a => :try_select_all, :e => :save_and_quit, :esc => :esc, :q => :quit, :up_arrow => :move_up, :down_arrow => :move_down, :left_arrow => :move_left, :right_arrow => :move_right, :holding_up_arrow => :try_scroll_up, :holding_down_arrow => :try_scroll_down, :holding_left_arrow => :try_scroll_left, :holding_right_arrow => :try_scroll_right, :plus => :scale_up, :minus => :scale_down, :mouse_wheel_up => :mouse_wheel_up, :mouse_wheel_down => :mouse_wheel_down, :"1" => :create_object_1, :"2" => :create_object_2, :"3" => :create_object_3, :"4" => :create_object_4, :"5" => :create_object_5, } @hud_height = 140 = [32,32] x = 20 y = 60 @classes.each do |klass| puts "Creating a #{klass}" if @debug # We initialize x,y,zorder,rotation_center after creation # so they're not overwritten by the class initialize/setup or simular begin game_object = klass.create(:paused => true) game_object.x = x + 10 game_object.y = y game_object.[:toolbar] = true game_object.rotation_center = :center_center # Scale down object to fit our toolbar if game_object.image Text.create("#{klass.to_s[0..9]}\n#{game_object.width.to_i}x#{game_object.height.to_i}", :size => 12, :x=>x-16, :y=>y+18, :max_width => 55, :rotation_center => :top_left, :align => :center, :factor => 1) game_object.size = x += 50 else puts "Skipping #{klass} - no image" if @debug game_object.destroy end rescue puts "Couldn't use #{klass} in editor: #{$!}" end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
If we're editing a game state with automaticly called special methods, the following takes care of those.
671 672 673 674 675 |
# File 'lib/chingu/game_states/edit.rb', line 671 def method_missing(symbol, *args) if symbol != :button_down || symbol != :button_up previous_game_state.__send__(symbol, *args) end end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
48 49 50 |
# File 'lib/chingu/game_states/edit.rb', line 48 def classes @classes end |
#debug ⇒ Object
Returns the value of attribute debug.
47 48 49 |
# File 'lib/chingu/game_states/edit.rb', line 47 def debug @debug end |
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
48 49 50 |
# File 'lib/chingu/game_states/edit.rb', line 48 def exclude @exclude end |
#file ⇒ Object
Returns the value of attribute file.
47 48 49 |
# File 'lib/chingu/game_states/edit.rb', line 47 def file @file end |
#grid ⇒ Object
Returns the value of attribute grid.
47 48 49 |
# File 'lib/chingu/game_states/edit.rb', line 47 def grid @grid end |
#hud_color ⇒ Object
Returns the value of attribute hud_color.
47 48 49 |
# File 'lib/chingu/game_states/edit.rb', line 47 def hud_color @hud_color end |
Instance Method Details
#bounding_box(game_object) ⇒ Object Also known as: bb
Returns a bounding box (Rect-class) for any gameobject It will take into considerations rotation_center and scaling
656 657 658 659 660 661 662 663 |
# File 'lib/chingu/game_states/edit.rb', line 656 def bounding_box(game_object) width, height = game_object.width, game_object.height x = game_object.x - width * game_object.center_x y = game_object.y - height * game_object.center_y x += width * CENTER_TO_FACTOR[game_object.center_x] if game_object.factor_x < 0 y += height * CENTER_TO_FACTOR[game_object.center_y] if game_object.factor_y < 0 return Rect.new(x, y, width, height) end |
#copy_game_object(template) ⇒ Object
636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/chingu/game_states/edit.rb', line 636 def copy_game_object(template) game_object = template.class.create(:parent => previous_game_state) # If we don't create it from the toolbar, we're cloning another object # When cloning we wan't the cloned objects attributes game_object.attributes = template.attributes unless template.[:toolbar] game_object.x = self.mouse_x game_object.y = self.mouse_y game_object.[:created_with_editor] = true game_object.[:mouse_x_offset] = (game_object.x - self.mouse_x) rescue 0 game_object.[:mouse_y_offset] = (game_object.y - self.mouse_y) rescue 0 return game_object end |
#create_object_1 ⇒ Object
448 |
# File 'lib/chingu/game_states/edit.rb', line 448 def create_object_1; create_object_nr(0); end |
#create_object_2 ⇒ Object
449 |
# File 'lib/chingu/game_states/edit.rb', line 449 def create_object_2; create_object_nr(1); end |
#create_object_3 ⇒ Object
450 |
# File 'lib/chingu/game_states/edit.rb', line 450 def create_object_3; create_object_nr(2); end |
#create_object_4 ⇒ Object
451 |
# File 'lib/chingu/game_states/edit.rb', line 451 def create_object_4; create_object_nr(3); end |
#create_object_5 ⇒ Object
452 |
# File 'lib/chingu/game_states/edit.rb', line 452 def create_object_5; create_object_nr(4); end |
#create_object_nr(number) ⇒ Object
441 442 443 444 445 446 |
# File 'lib/chingu/game_states/edit.rb', line 441 def create_object_nr(number) c = @classes[number].create(:x => self.mouse_x, :y => self.mouse_y, :parent => previous_game_state) if @classes[number] c.[:created_with_editor] = true c.update #@text.text = "Created a #{c.class} @ #{c.x} / #{c.y}" end |
#dec_alpha ⇒ Object
581 582 583 |
# File 'lib/chingu/game_states/edit.rb', line 581 def dec_alpha selected_game_objects.each { |game_object| game_object.alpha -= 1 } end |
#dec_zorder ⇒ Object
575 576 577 |
# File 'lib/chingu/game_states/edit.rb', line 575 def dec_zorder selected_game_objects.each { |game_object| game_object.zorder -= 1 } end |
#deselect_selected_game_objects ⇒ Object
423 424 425 |
# File 'lib/chingu/game_states/edit.rb', line 423 def deselect_selected_game_objects selected_game_objects.each { |object| object.[:selected] = nil } end |
#destroy_selected_game_objects ⇒ Object
Call destroy on all selected game objects
419 420 421 |
# File 'lib/chingu/game_states/edit.rb', line 419 def destroy_selected_game_objects selected_game_objects.each { |game_object| game_object.destroy } end |
#display_help ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/chingu/game_states/edit.rb', line 168 def display_help text = " F1: This help screen\n ESC: Return to Edit\n \n 1-5: create object 1..5 shown in toolbar at mousecursor\n CTRL+A: select all objects (not in-code-created ones though)\n CTRL+S: Save\n E: Save and Quit\n Q: Quit (without saving)\n ESC: Deselect all objects\n Right Mouse Button Click: Copy object bellow cursor for fast duplication\n Arrow-keys (with selected objects): Move objects 1 pixel at the time\n Arrow-keys (with no selected objects): Scroll within a viewport\n \n\n Bellow keys operates on all currently selected game objects\n -----------------------------------------------------------------------------------\n DEL: delete selected objects\n BACKSPACE: reset angle and scale to default values\n Page Up: Increase zorder\n Page Down: Decrease zorder\n \n R: scale up\n F: scale down\n T: tilt left\n G: tilt right\n Y: inc zorder\n H: dec zorder\n U: less transparency\n J: more transparencty\n\n Mouse Wheel (with no selected objects): Scroll viewport up/down\n Mouse Wheel: Scale up/down\n SHIFT + Mouse Wheel: Tilt left/right\n CTRL + Mouse Wheel: Zorder up/down\n ALT + Mouse Wheel: Transparency less/more\n" push_game_state( GameStates::Popup.new(:text => text) ) end |
#draw ⇒ Object
DRAW
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/chingu/game_states/edit.rb', line 286 def draw # Draw prev game state onto screen (the level we're editing) previous_game_state.draw # Restart z-ordering, everything after this will be drawn on top $window.flush draw_grid if @draw_grid # # Draw an edit HUD # $window.draw_quad( 0,0,@hud_color, $window.width,0,@hud_color, $window.width,@hud_height,@hud_color,0,@hud_height,@hud_color) # # Draw gameobjects # super # # Draw red rectangles/circles around all selected game objects # if defined?(previous_game_state.) previous_game_state..apply { draw_selections } else draw_selections end @cursor_game_object.draw_at($window.mouse_x, $window.mouse_y) if @cursor_game_object end |
#draw_grid ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/chingu/game_states/edit.rb', line 210 def draw_grid return unless @grid start_x, start_y = 0,0 if defined?(previous_game_state.) start_x = -previous_game_state..x % @grid.first start_y = -previous_game_state..y % @grid.last end (start_x .. $window.width).step(@grid.first).each do |x| $window.draw_line(x, 1, @grid_color, x, $window.height, @grid_color, 0, :additive) end (start_y .. $window.height).step(@grid.last).each do |y| $window.draw_line(1, y, @grid_color, $window.width, y, @grid_color, 0, :additive) end end |
#draw_selections ⇒ Object
Draw a red rectangle around all selected objects
321 322 323 |
# File 'lib/chingu/game_states/edit.rb', line 321 def draw_selections selected_game_objects.each { |game_object| draw_rect(bounding_box(game_object), Color::RED, 10000) } end |
#editable_game_objects ⇒ Object
Returns a list of game objects the editor can create. 2 types of object gets this flag:
- An object loaded with load_game_objects
- An object created from within the editor
This helps us mix code-created with editor-created objects inside the editor and not muck around with the code-created ones.
405 406 407 |
# File 'lib/chingu/game_states/edit.rb', line 405 def editable_game_objects previous_game_state.game_objects.select { |o| o.[:created_with_editor] } end |
#empty_area_at_cursor ⇒ Object
427 428 429 430 |
# File 'lib/chingu/game_states/edit.rb', line 427 def empty_area_at_cursor game_object_at(self.mouse_x, self.mouse_y)==nil && game_object_icon_at($window.mouse_x, $window.mouse_y) == nil end |
#esc ⇒ Object
597 598 599 600 |
# File 'lib/chingu/game_states/edit.rb', line 597 def esc deselect_selected_game_objects @cursor_game_object = nil end |
#finalize ⇒ Object
500 501 502 503 504 505 |
# File 'lib/chingu/game_states/edit.rb', line 500 def finalize if defined?(previous_game_state.) previous_game_state..game_area = @game_area_backup end $window.cursor = @original_cursor end |
#game_object_at(x, y) ⇒ Object
Get editable object at X/Y .. if there's many objects at the same coordinate.. .. get the one with highest zorder.
476 477 478 479 480 481 |
# File 'lib/chingu/game_states/edit.rb', line 476 def game_object_at(x, y) editable_game_objects.select do |game_object| next if game_object.is_a? Text bounding_box(game_object).collide_point?(x,y) end.sort {|x,y| y.zorder <=> x.zorder }.first end |
#game_object_classes ⇒ Object
Get all classes based on GameObject except Chingus internal classes.
435 436 437 438 439 |
# File 'lib/chingu/game_states/edit.rb', line 435 def game_object_classes ObjectSpace.enum_for(:each_object, class << GameObject; self; end).to_a.select do |game_class| game_class.instance_methods && !game_class.to_s.include?("Chingu::") end end |
#game_object_icon_at(x, y) ⇒ Object
464 465 466 467 468 469 470 |
# File 'lib/chingu/game_states/edit.rb', line 464 def game_object_icon_at(x, y) game_objects.select do |game_object| next if game_object.is_a? Text next unless game_object.image bounding_box(game_object).collide_point?(x,y) end.first end |
#inc_alpha ⇒ Object
578 579 580 |
# File 'lib/chingu/game_states/edit.rb', line 578 def inc_alpha selected_game_objects.each { |game_object| game_object.alpha += 1 } end |
#inc_zorder ⇒ Object
572 573 574 |
# File 'lib/chingu/game_states/edit.rb', line 572 def inc_zorder selected_game_objects.each { |game_object| game_object.zorder += 1 } end |
#inside_window?(x = $window.mouse_x, y = $window.mouse_y) ⇒ Boolean
632 633 634 |
# File 'lib/chingu/game_states/edit.rb', line 632 def inside_window?(x = $window.mouse_x, y = $window.mouse_y) x >= 0 && x <= $window.width && y >= 0 && y <= $window.height end |
#left_mouse_button ⇒ Object
CLICKED LEFT MOUSE BUTTON
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/chingu/game_states/edit.rb', line 328 def = true @selected_game_object = false if defined?(self.previous_game_state.) @left_mouse_click_at = [self.previous_game_state..x + $window.mouse_x, self.previous_game_state..y + $window.mouse_y] else @left_mouse_click_at = [$window.mouse_x, $window.mouse_y] end # Put out a new game object in the editor window and select it right away @selected_game_object = copy_game_object(@cursor_game_object) if @cursor_game_object # Check if user clicked on anything in the icon-toolbar of available game objects @cursor_game_object = game_object_icon_at($window.mouse_x, $window.mouse_y) # Get editable game object that was clicked at (if any) @selected_game_object ||= game_object_at(self.mouse_x, self.mouse_y) if @selected_game_object && defined?(self.previous_game_state.) self.previous_game_state..center_around(@selected_game_object) if @left_double_click end if @selected_game_object # # If clicking on a new object that's wasn't previosly selected # --> deselect all objects unless holding left_ctrl # if @selected_game_object.[:selected] == nil selected_game_objects.each { |object| object.[:selected] = nil } unless holding?(:left_ctrl) end if holding?(:left_ctrl) @selected_game_object.[:selected] = !@selected_game_object.[:selected] else @selected_game_object.[:selected] = true end if holding?(:left_shift) previous_game_state.game_objects.select { |x| x.class == @selected_game_object.class }.each do |game_object| game_object.[:selected] = true end end # # Re-align all objects x/y offset in relevance to the cursor # selected_game_objects.each do |selected_game_object| selected_game_object.[:mouse_x_offset] = selected_game_object.x - self.mouse_x selected_game_object.[:mouse_y_offset] = selected_game_object.y - self.mouse_y end else deselect_selected_game_objects unless holding?(:left_ctrl) end end |
#mouse_wheel_down ⇒ Object
548 549 550 551 552 553 554 555 556 557 |
# File 'lib/chingu/game_states/edit.rb', line 548 def mouse_wheel_down if selected_game_objects.empty? scroll_down(40) else tilt_right && return if holding?(:left_shift) dec_zorder && return if holding?(:left_ctrl) dec_alpha && return if holding?(:left_alt) scale_down end end |
#mouse_wheel_up ⇒ Object
537 538 539 540 541 542 543 544 545 546 |
# File 'lib/chingu/game_states/edit.rb', line 537 def mouse_wheel_up if selected_game_objects.empty? scroll_up(40) else tilt_left && return if holding?(:left_shift) inc_zorder && return if holding?(:left_ctrl) inc_alpha && return if holding?(:left_alt) scale_up end end |
#mouse_x ⇒ Object
620 621 622 623 624 |
# File 'lib/chingu/game_states/edit.rb', line 620 def mouse_x x = $window.mouse_x x += self.previous_game_state..x if defined?(self.previous_game_state.) return x end |
#mouse_y ⇒ Object
626 627 628 629 630 |
# File 'lib/chingu/game_states/edit.rb', line 626 def mouse_y y = $window.mouse_y y += self.previous_game_state..y if defined?(self.previous_game_state.) return y end |
#move_down ⇒ Object
519 520 521 522 |
# File 'lib/chingu/game_states/edit.rb', line 519 def move_down scroll_down && return if selected_game_objects.empty? selected_game_objects.each { |game_object| game_object.y += 1 } end |
#move_left ⇒ Object
507 508 509 510 |
# File 'lib/chingu/game_states/edit.rb', line 507 def move_left scroll_left && return if selected_game_objects.empty? selected_game_objects.each { |game_object| game_object.x -= 1 } end |
#move_right ⇒ Object
511 512 513 514 |
# File 'lib/chingu/game_states/edit.rb', line 511 def move_right scroll_right && return if selected_game_objects.empty? selected_game_objects.each { |game_object| game_object.x += 1 } end |
#move_up ⇒ Object
515 516 517 518 |
# File 'lib/chingu/game_states/edit.rb', line 515 def move_up scroll_up && return if selected_game_objects.empty? selected_game_objects.each { |game_object| game_object.y -= 1 } end |
#page_down ⇒ Object
604 605 606 |
# File 'lib/chingu/game_states/edit.rb', line 604 def page_down self.previous_game_state..y += $window.height if defined?(self.previous_game_state.) end |
#page_up ⇒ Object
601 602 603 |
# File 'lib/chingu/game_states/edit.rb', line 601 def page_up self.previous_game_state..y -= $window.height if defined?(self.previous_game_state.) end |
#quit ⇒ Object
489 490 491 |
# File 'lib/chingu/game_states/edit.rb', line 489 def quit pop_game_state end |
#released_left_mouse_button ⇒ Object
RELASED LEFT MOUSE BUTTON
393 394 395 |
# File 'lib/chingu/game_states/edit.rb', line 393 def = false end |
#released_right_mouse_button ⇒ Object
387 388 |
# File 'lib/chingu/game_states/edit.rb', line 387 def end |
#reset_selected_game_objects ⇒ Object
Resets selected game objects defaults, angle=0, scale=1.
457 458 459 460 461 462 |
# File 'lib/chingu/game_states/edit.rb', line 457 def reset_selected_game_objects selected_game_objects.each do |game_object| game_object.angle = 0 game_object.scale = 1 end end |
#right_mouse_button ⇒ Object
384 385 386 |
# File 'lib/chingu/game_states/edit.rb', line 384 def @cursor_game_object = @cursor_game_object ? nil : game_object_at(mouse_x, mouse_y) end |
#save ⇒ Object
492 493 494 |
# File 'lib/chingu/game_states/edit.rb', line 492 def save save_game_objects(:game_objects => editable_game_objects, :file => @file, :classes => @classes, :attributes => @attributes) end |
#save_and_quit ⇒ Object
495 496 497 498 |
# File 'lib/chingu/game_states/edit.rb', line 495 def save_and_quit save unless holding?(:left_ctrl) quit end |
#scale_down ⇒ Object
568 569 570 |
# File 'lib/chingu/game_states/edit.rb', line 568 def scale_down scale_down_x && scale_down_y end |
#scale_down_x ⇒ Object
590 591 592 |
# File 'lib/chingu/game_states/edit.rb', line 590 def scale_down_x selected_game_objects.each { |game_object| game_object.width -= grid[0] if game_object.width > grid[0] } end |
#scale_down_y ⇒ Object
593 594 595 |
# File 'lib/chingu/game_states/edit.rb', line 593 def scale_down_y selected_game_objects.each { |game_object| game_object.height -= grid[1] if game_object.height > grid[1] } end |
#scale_up ⇒ Object
565 566 567 |
# File 'lib/chingu/game_states/edit.rb', line 565 def scale_up scale_up_x && scale_up_y end |
#scale_up_x ⇒ Object
584 585 586 |
# File 'lib/chingu/game_states/edit.rb', line 584 def scale_up_x selected_game_objects.each { |game_object| game_object.width += grid[0] } end |
#scale_up_y ⇒ Object
587 588 589 |
# File 'lib/chingu/game_states/edit.rb', line 587 def scale_up_y selected_game_objects.each { |game_object| game_object.height += grid[1] } end |
#scroll_down(amount = 10) ⇒ Object
610 611 612 |
# File 'lib/chingu/game_states/edit.rb', line 610 def scroll_down(amount = 10) self.previous_game_state..y += amount if defined?(self.previous_game_state.) end |
#scroll_left(amount = 10) ⇒ Object
613 614 615 |
# File 'lib/chingu/game_states/edit.rb', line 613 def scroll_left(amount = 10) self.previous_game_state..x -= amount if defined?(self.previous_game_state.) end |
#scroll_right(amount = 10) ⇒ Object
616 617 618 |
# File 'lib/chingu/game_states/edit.rb', line 616 def scroll_right(amount = 10) self.previous_game_state..x += amount if defined?(self.previous_game_state.) end |
#scroll_up(amount = 10) ⇒ Object
607 608 609 |
# File 'lib/chingu/game_states/edit.rb', line 607 def scroll_up(amount = 10) self.previous_game_state..y -= amount if defined?(self.previous_game_state.) end |
#selected_game_objects ⇒ Object
Returns a list of selected game objects
412 413 414 |
# File 'lib/chingu/game_states/edit.rb', line 412 def selected_game_objects editable_game_objects.select { |o| o.[:selected] } end |
#setup ⇒ Object
SETUP
230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/chingu/game_states/edit.rb', line 230 def setup @scroll_border_thickness = 30 @file = [:file] || previous_game_state.filename + ".yml" @title = Text.create("File: #{@file}", :x => 5, :y => 2, :factor => 1, :size => 16) @title.text += " - Grid: #{@grid}" if @grid @text = Text.create("", :x => 300, :y => 20, :factor => 1, :size => 16) @status_text = Text.create("-", :x => 5, :y => 20, :factor => 1, :size => 16) if defined?(previous_game_state.) @game_area_backup = previous_game_state..game_area.dup previous_game_state..game_area.x -= @hud_height previous_game_state..game_area.y -= @hud_height end end |
#tilt_left ⇒ Object
559 560 561 |
# File 'lib/chingu/game_states/edit.rb', line 559 def tilt_left selected_game_objects.each { |game_object| game_object.angle -= 5 } end |
#tilt_right ⇒ Object
562 563 564 |
# File 'lib/chingu/game_states/edit.rb', line 562 def tilt_right selected_game_objects.each { |game_object| game_object.angle += 5 } end |
#try_save ⇒ Object
486 487 488 |
# File 'lib/chingu/game_states/edit.rb', line 486 def try_save save if holding?(:left_ctrl) end |
#try_scroll_down ⇒ Object
533 534 535 |
# File 'lib/chingu/game_states/edit.rb', line 533 def try_scroll_down scroll_down if selected_game_objects.empty? end |
#try_scroll_left ⇒ Object
524 525 526 |
# File 'lib/chingu/game_states/edit.rb', line 524 def try_scroll_left scroll_left if selected_game_objects.empty? end |
#try_scroll_right ⇒ Object
527 528 529 |
# File 'lib/chingu/game_states/edit.rb', line 527 def try_scroll_right scroll_right if selected_game_objects.empty? end |
#try_scroll_up ⇒ Object
530 531 532 |
# File 'lib/chingu/game_states/edit.rb', line 530 def try_scroll_up scroll_up if selected_game_objects.empty? end |
#try_select_all ⇒ Object
483 484 485 |
# File 'lib/chingu/game_states/edit.rb', line 483 def try_select_all editable_game_objects.each { |x| x.[:selected] = true } if holding?(:left_ctrl) end |
#update ⇒ Object
UPDATE
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/chingu/game_states/edit.rb', line 248 def update super @status_text.text = "#{self.mouse_x.to_i} / #{self.mouse_y.to_i}" @text.text = @selected_game_object.to_s # # We got a selected game object and the left mouse button is held down # if && @selected_game_object selected_game_objects.each do |selected_game_object| selected_game_object.x = self.mouse_x + selected_game_object.[:mouse_x_offset] selected_game_object.y = self.mouse_y + selected_game_object.[:mouse_y_offset] if @snap_to_grid selected_game_object.x -= selected_game_object.x % @grid[0] selected_game_object.y -= selected_game_object.y % @grid[1] end end elsif if defined?(self.previous_game_state.) self.previous_game_state..x = @left_mouse_click_at[0] - $window.mouse_x self.previous_game_state..y = @left_mouse_click_at[1] - $window.mouse_y end end if inside_window?($window.mouse_x, $window.mouse_y) scroll_right if $window.mouse_x > $window.width - @scroll_border_thickness scroll_left if $window.mouse_x < @scroll_border_thickness scroll_up if $window.mouse_y < @scroll_border_thickness scroll_down if $window.mouse_y > $window.height - @scroll_border_thickness end end |