Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Editor
- # This is the main Window class where all the magic happens
- class Window < Gosu::Window
- attr_accessor :states, :entities, :texts, :font, :images, :state, :previous_state
- include Observable
- def initialize(width, height, fullscreen = false)
- super(width, height, fullscreen)
- $system = System.new
- self.caption = "RRPG - Editor"
- @entities = []
- @images = { }
- @images[:cursor] = Gosu::Image.new('editor/cursor.png')
- @font = {} # this is necessary
- # @font[:sm] = Gosu::Font.new(($font_height * 0.8).to_i, name: "Noteworthy")
- # @font[:md] = Gosu::Font.new($font_height, name: "Noteworthy")
- @font[:sm] = Gosu::Font.new(($font_height * 0.8).to_i)
- @font[:md] = Gosu::Font.new($font_height)
- @font[:lg] = Gosu::Font.new(($font_height * 1.5).to_i)
- # @states = {}
- # @states = create_states('./states/editor.yml')
- @states= {
- start_menu: State.new(
- self,
- entities: [
- Entity::UI::Menu.new(
- 32,64,20,
- menu_entries: [
- Entity::UI::MenuEntry.new('New Game', proc { System.state_update(:new_game) }),
- Entity::UI::MenuEntry.new('Load Game', proc { System.state_update(:start_menu) }),
- Entity::UI::MenuEntry.new('Map Editor',
- proc {
- state = create_state(
- State.new(self, entities: [
- Entity::Map.new('./data/tilesets/default.png',
- [
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
- ]),
- Entity::UI::EditorTilePicker.new(16, 16,1000)
- ]
- ),
- )
- @state = state
- }),
- Entity::UI::MenuEntry.new('Exit', proc { System.exit_game })
- ]
- )
- ]
- ),
- new_game: State.new(
- self,
- entities: [
- Entity::Map.new('./data/tilesets/default.png',
- [
- [0,3,3,3,3,4,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,1,1,1,4,4,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,1,2,2,1,4,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,1,2,2,1,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,1,1,1,1,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,2,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- [0,0,0,2,0,0,1,2,3,4,2,3,1,2,3,4,1,2,3,5,],
- ],
- actors: [
- {
- name: "Gustaf",
- x: 32,
- y: 32
- },
- {
- name: "Peter",
- x: 96,
- y: 32
- }
- ]
- )
- ] # end entities
- )
- }
- @state = @states[:start_menu]
- @previous_state = @state
- end
- def create_state(state)
- @states[state] = state
- end
- # def create_states(file)
- # states_yaml = YAML.load_file(file)
- # states_yaml.each do |state, entities|
- # self.states[state] = State.new(self, state, entities['entities'])
- # end
- # end
- def button_up(id)
- @state.button_up(id)
- end
- def button_down(id)
- @state.button_down(id)
- # case id
- # when Gosu::KbQ
- # p "closing editor"
- # exit(0)
- # end
- end
- def state_update(args)
- if args.include? :next_state
- puts "Load State"
- @previous_state = @state
- @state = args[:next_state]
- elsif args.include? :go_back
- @state = @previous_state
- else
- abort "Couldn't change the State. Aborting.".colorize(:red)
- end
- end
- def update
- @state.update
- end
- def draw
- self.draw_quad(
- #1
- 0,0,Gosu::Color.argb(0x333333ff),
- #2
- self.width,0,Gosu::Color.argb(0x333333ff),
- #3
- 0,self.height,Gosu::Color.argb(0xff00ffff),
- #4
- self.width,self.height,Gosu::Color.argb(0xff00ffff),
- z = 0,
- mode = :default
- )
- @state.draw
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement