diff -r a3cfaeee08f4 src/newgrf_gui.cpp --- a/src/newgrf_gui.cpp Sun May 23 22:14:22 2010 +0000 +++ b/src/newgrf_gui.cpp Mon May 24 09:23:02 2010 +0200 @@ -22,6 +22,7 @@ #include "sortlist_type.h" #include "querystring_gui.h" #include "core/geometry_func.hpp" +#include "tilehighlight_func.h" #include "table/strings.h" #include "table/sprites.h" @@ -482,6 +483,8 @@ } case SNGRFS_FILE_LIST: { // Select an active GRF. + ResetObjectToPlace(); + NWidgetBase *nw = this->GetWidget(SNGRFS_FILE_LIST); uint i = (pt.y - nw->pos_y) / nw->resize_y + this->vscroll.GetPosition(); @@ -494,7 +497,13 @@ this->avail_pos = -1; this->InvalidateData(); - if (click_count == 1) break; + if (click_count == 1) { + if (this->active_sel != NULL) { + /* Activate drag and drop */ + SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this); + } + break; + } } /* Fall through with double click. */ case SNGRFS_REMOVE: { // Remove GRF @@ -636,6 +645,58 @@ } } + virtual void OnDragDrop(Point pt, int widget) + { + if (widget == SNGRFS_FILE_LIST && this->active_sel != NULL) { + GRFConfig *from = this->active_sel; + /* Gets the selected file offset in the active list and its predecessor. */ + GRFConfig *from_prev = NULL; + uint from_pos = 0; + for (GRFConfig *cursor = this->actives; cursor != NULL; cursor = cursor->next) { + if (cursor == from) break; + + from_prev = cursor; + from_pos++; + } + + /* Gets the drag-and-drop destination offset. */ + NWidgetBase *nw = this->GetWidget(SNGRFS_FILE_LIST); + uint to_pos = (pt.y - nw->pos_y) / nw->resize_y + this->vscroll.GetPosition(); + + if (from_pos != to_pos) { // Don't move NewGRF file over itself + /* Gets destination file and its predecessor. */ + GRFConfig *to = this->actives; + GRFConfig *to_prev = NULL; + for (uint i = 0; to != NULL && i < to_pos; to_prev = to, to = to->next, i++) {} + + /* Detach NewGRF file of its original position. */ + if (from_prev == NULL) { // Detach from start of list + this->actives = this->actives->next; + } else { + from_prev->next = from->next; + } + + /* Attach NewGRF file to its new position. */ + if (from_pos < to_pos) { // Move down NewGRF file + from->next = to->next; + to->next = from; + } else if (to_prev == NULL) { // Move up at start of the list + this->actives = from; + from->next = to; + } else { // Move up inside list + from->next = to; + to_prev->next = from; + } + + this->vscroll.ScrollTowards(to_pos); + this->preset = -1; + this->InvalidateData(); + } + } + + ResetObjectToPlace(); + } + virtual void OnDropdownSelect(int widget, int index) { if (index == -1) {