64 _sign_sort_dirty = false; |
64 _sign_sort_dirty = false; |
65 |
65 |
66 DEBUG(misc, 3, "Resorting global signs list"); |
66 DEBUG(misc, 3, "Resorting global signs list"); |
67 } |
67 } |
68 |
68 |
69 static void SignListWndProc(Window *w, WindowEvent *e) |
69 struct SignListWindow : Window { |
70 { |
70 SignListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) |
71 switch (e->event) { |
71 { |
72 case WE_PAINT: { |
72 this->vscroll.cap = 12; |
73 if (_sign_sort_dirty) GlobalSortSignList(); |
73 this->resize.step_height = 10; |
74 |
74 this->resize.height = this->height - 10 * 7; // minimum if 5 in the list |
75 SetVScrollCount(w, _num_sign_sort); |
75 |
76 |
76 this->FindWindowPlacementAndResize(desc); |
77 SetDParam(0, w->vscroll.count); |
77 } |
78 w->DrawWidgets(); |
78 |
79 |
79 virtual void OnPaint() |
80 /* No signs? */ |
80 { |
81 int y = 16; // offset from top of widget |
81 if (_sign_sort_dirty) GlobalSortSignList(); |
82 if (w->vscroll.count == 0) { |
82 |
83 DrawString(2, y, STR_304A_NONE, TC_FROMSTRING); |
83 SetVScrollCount(this, _num_sign_sort); |
84 return; |
84 |
85 } |
85 SetDParam(0, this->vscroll.count); |
86 |
86 this->DrawWidgets(); |
87 /* Start drawing the signs */ |
87 |
88 for (uint16 i = w->vscroll.pos; i < w->vscroll.cap + w->vscroll.pos && i < w->vscroll.count; i++) { |
88 /* No signs? */ |
89 const Sign *si = _sign_sort[i]; |
89 int y = 16; // offset from top of widget |
90 |
90 if (this->vscroll.count == 0) { |
91 if (si->owner != OWNER_NONE) DrawPlayerIcon(si->owner, 4, y + 1); |
91 DrawString(2, y, STR_304A_NONE, TC_FROMSTRING); |
92 |
92 return; |
93 SetDParam(0, si->index); |
93 } |
94 DrawString(22, y, STR_SIGN_NAME, TC_YELLOW); |
94 |
95 y += 10; |
95 /* Start drawing the signs */ |
96 } |
96 for (uint16 i = this->vscroll.pos; i < this->vscroll.cap + this->vscroll.pos && i < this->vscroll.count; i++) { |
97 } break; |
97 const Sign *si = _sign_sort[i]; |
98 |
98 |
99 case WE_CLICK: |
99 if (si->owner != OWNER_NONE) DrawPlayerIcon(si->owner, 4, y + 1); |
100 if (e->we.click.widget == 3) { |
100 |
101 uint32 id_v = (e->we.click.pt.y - 15) / 10; |
101 SetDParam(0, si->index); |
102 |
102 DrawString(22, y, STR_SIGN_NAME, TC_YELLOW); |
103 if (id_v >= w->vscroll.cap) return; |
103 y += 10; |
104 id_v += w->vscroll.pos; |
104 } |
105 if (id_v >= w->vscroll.count) return; |
105 } |
106 |
106 |
107 const Sign *si = _sign_sort[id_v]; |
107 virtual void OnClick(Point pt, int widget) |
108 ScrollMainWindowToTile(TileVirtXY(si->x, si->y)); |
108 { |
109 } |
109 if (widget == 3) { |
110 break; |
110 uint32 id_v = (pt.y - 15) / 10; |
111 |
111 |
112 case WE_RESIZE: |
112 if (id_v >= this->vscroll.cap) return; |
113 w->vscroll.cap += e->we.sizing.diff.y / 10; |
113 id_v += this->vscroll.pos; |
114 break; |
114 if (id_v >= this->vscroll.count) return; |
115 } |
115 |
116 } |
116 const Sign *si = _sign_sort[id_v]; |
|
117 ScrollMainWindowToTile(TileVirtXY(si->x, si->y)); |
|
118 } |
|
119 } |
|
120 |
|
121 virtual void OnResize(Point new_size, Point delta) |
|
122 { |
|
123 this->vscroll.cap += delta.y / 10; |
|
124 } |
|
125 }; |
117 |
126 |
118 static const Widget _sign_list_widget[] = { |
127 static const Widget _sign_list_widget[] = { |
119 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
128 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
120 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 345, 0, 13, STR_SIGN_LIST_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
129 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 345, 0, 13, STR_SIGN_LIST_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
121 { WWT_STICKYBOX, RESIZE_LR, 14, 346, 357, 0, 13, 0x0, STR_STICKY_BUTTON}, |
130 { WWT_STICKYBOX, RESIZE_LR, 14, 346, 357, 0, 13, 0x0, STR_STICKY_BUTTON}, |
128 static const WindowDesc _sign_list_desc = { |
137 static const WindowDesc _sign_list_desc = { |
129 WDP_AUTO, WDP_AUTO, 358, 138, 358, 138, |
138 WDP_AUTO, WDP_AUTO, 358, 138, 358, 138, |
130 WC_SIGN_LIST, WC_NONE, |
139 WC_SIGN_LIST, WC_NONE, |
131 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
140 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
132 _sign_list_widget, |
141 _sign_list_widget, |
133 SignListWndProc |
142 NULL |
134 }; |
143 }; |
135 |
144 |
136 |
145 |
137 void ShowSignList() |
146 void ShowSignList() |
138 { |
147 { |
139 Window *w = AllocateWindowDescFront<Window>(&_sign_list_desc, 0); |
148 AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0); |
140 if (w != NULL) { |
|
141 w->vscroll.cap = 12; |
|
142 w->resize.step_height = 10; |
|
143 w->resize.height = w->height - 10 * 7; // minimum if 5 in the list |
|
144 } |
|
145 } |
149 } |
146 |
150 |
147 static void RenameSign(SignID index, const char *text) |
151 static void RenameSign(SignID index, const char *text) |
148 { |
152 { |
149 _cmd_text = text; |
153 _cmd_text = text; |