Class: FXItemList

Inherits:
FXDialogBox
  • Object
show all
Defined in:
lib/IFMapper/FXItemList.rb

Overview

Class that lists all rooms in a map and allows you to jump to them

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ FXItemList

Returns a new instance of FXItemList.



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
# File 'lib/IFMapper/FXItemList.rb', line 77

def initialize(map)
  super(map.window.parent, BOX_LOCATIONS, DECOR_ALL, 40, 40, 420, 400)

  @box = FXIconList.new(self, nil, 0, 
	   ICONLIST_BROWSESELECT|
	   LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @box.appendHeader(BOX_NAME, nil, 120)
  @box.appendHeader(BOX_SECTION, nil, 60)
  @box.appendHeader(BOX_LOCATION, 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
    0.upto(2) { |idx|
      @box.header.setArrowDir(idx, MAYBE)
    }
    @box.header.setArrowDir(which, dir)
    
    sort
  }

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

  create
  copy_from(map)
end

Instance Method Details

#copy_from(map) ⇒ Object



18
19
20
21
# File 'lib/IFMapper/FXItemList.rb', line 18

def copy_from(map)
  @map = map
  sort
end

#pick(sender, sel, ptr) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/IFMapper/FXItemList.rb', line 7

def pick(sender, sel, ptr)
  it = @box.currentItem
  name, section, room = @box.getItemData(it)

  @map.section = section - 1
  @map.clear_selection
  room.selected = true
  @map.center_view_on_room(room)
  @map.draw
end

#sortObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
# File 'lib/IFMapper/FXItemList.rb', line 23

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

  @box.clearItems

  items = []
  @map.sections.each_with_index { |s, idx| 
    s.rooms.each { |r|
      r.objects.each_line { |i|
        i.chomp!
        next if i.empty?
        items << [i, idx+1, r ]
      }
    }
  }

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

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

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

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