diff -r e706da6b8ddc src/newgrf_gui.cpp --- a/src/newgrf_gui.cpp Sat May 22 19:59:37 2010 +0000 +++ b/src/newgrf_gui.cpp Sun May 23 10:30:12 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,54 @@ } } + virtual void OnDragDrop(Point pt, int widget) + { + if (widget == SNGRFS_FILE_LIST) { + if (this->active_sel != NULL) { + GRFConfig *from_config = this->active_sel; + GRFConfig *prev_from_config = NULL; + uint from_offset = 0; + for (GRFConfig *cursor = this->actives; cursor != NULL && cursor != from_config; prev_from_config = cursor, cursor = cursor->next, from_offset++) {} + + NWidgetBase *nw = this->GetWidget(SNGRFS_FILE_LIST); + uint to_offset = (pt.y - nw->pos_y) / nw->resize_y + this->vscroll.GetPosition(); + + if (from_offset != to_offset) { // Don't move NewGRF file over itself + GRFConfig *to_config = this->actives; + GRFConfig *prev_to_config = NULL; + for (uint i = 0; to_config != NULL && i < to_offset; prev_to_config = to_config, to_config = to_config->next, i++) {} + + /* Detach NewGRF file of its original position. */ + if (prev_from_config == NULL) { // Detach from start of list + this->actives = this->actives->next; + } else { + prev_from_config->next = from_config->next; + } + + /* Attach NewGRF file to its new position. */ + if (from_offset < to_offset) { // Move down NewGRF file + from_config->next = to_config->next; + to_config->next = from_config; + } else if (from_offset > to_offset) { //Move up NewGRF file + if (prev_to_config == NULL) { // Move at start of the list + this->actives = from_config; + from_config->next = to_config; + } else { + from_config->next = to_config; + prev_to_config->next = from_config; + } + } + + this->vscroll.ScrollTowards(to_offset); + this->preset = -1; + this->InvalidateData(); + } + } + } + + ResetObjectToPlace(); + } + virtual void OnDropdownSelect(int widget, int index) { if (index == -1) {