Sha256: b8c946c40e0995202dcb25094f6b481b8ec11480026d15063e3d2a543f8b5bea

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

#
# Class that lists all rooms in a map and allows you to jump to them
#
class FXRoomList < FXDialogBox

  def pick(sender, sel, ptr)
    item = @box.currentItem
    idx, r = @box.getItemData(item)

    @map.section = idx
    @map.clear_selection
    r.selected = true
    @map.center_view_on_room(r)
    @map.draw
  end

  def copy_from(map)
    @map = map
    sort
  end

  def sort
    item = @box.currentItem
    room = nil
    if item >= 0
      idx, room = @box.getItemData(item)
    end

    @box.clearItems

    rooms = []
    @map.sections.each_with_index { |s, idx| 
      s.rooms.each { |r|
	rooms << [idx, r]
      }
    }

    dir = @box.header.getArrowDir(0)
    if dir != MAYBE
      rooms = rooms.sort_by { |r| r[0] }
    else
      dir = @box.header.getArrowDir(1)
      if dir != MAYBE
	rooms = rooms.sort_by { |r| r[1].name }
      end
    end

    if dir == Fox::TRUE
      rooms.reverse! 
    end

    rooms.each { |r|
      item = "#{r[0]}\t#{r[1].name}"
      @box.appendItem(item, nil, nil, r)
    }

    if room
      rooms.each_with_index { |r, idx|
	if r[1] == room
	  @box.currentItem = idx
	  break
	end
      }
    end
  end

  def initialize(map)
    super(map.window.parent, "Locations", DECOR_ALL, 40, 40, 300, 400)
  
    @box = FXIconList.new(self, nil, 0, 
			   ICONLIST_BROWSESELECT|
			   LAYOUT_FILL_X|LAYOUT_FILL_Y)
    @box.appendHeader("Section", nil, 60)
    @box.appendHeader("Name", nil, 200)
    @box.header.connect(SEL_COMMAND) { |sender, sel, which|
      if @box.header.arrowUp?(which)
	dir = MAYBE
      elsif @box.header.arrowDown?(which)
	dir = TRUE
      else
	dir = FALSE
      end
      @box.header.setArrowDir(which, dir)
      @box.header.setArrowDir(which ^ 1, MAYBE)
      sort
    }

    @box.connect(SEL_COMMAND, method(:pick))

    create
    copy_from(map)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ifmapper-0.9.7 lib/IFMapper/FXRoomList.rb
ifmapper-0.9.5 lib/IFMapper/FXRoomList.rb
ifmapper-0.9.6 lib/IFMapper/FXRoomList.rb
ifmapper-0.9.8 lib/IFMapper/FXRoomList.rb