Index: lang/english.txt =================================================================== --- lang/english.txt (revision 27171) +++ lang/english.txt (working copy) @@ -2879,7 +2879,10 @@ STR_SPRITE_ALIGNER_PREVIOUS_TOOLTIP :{BLACK}Proceed to the previous normal sprite, skipping any pseudo/recolour/font sprites and wrapping around from the first sprite to the last STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Representation of the currently selected sprite. The alignment is ignored when drawing this sprite STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Move the sprite around, changing the X and Y offsets -STR_SPRITE_ALIGNER_OFFSETS :{BLACK}X offset: {NUM}, Y offset: {NUM} +STR_SPRITE_ALIGNER_OFFSETS :{BLACK}X offset: {NUM}, Y offset: {NUM} (Absolute) +STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relative +STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Reset the current relative offsets +STR_SPRITE_ALIGNER_OFFSETS_REL :{BLACK}X offset: {NUM}, Y offset: {NUM} (Relative) STR_SPRITE_ALIGNER_PICKER_BUTTON :{BLACK}Pick sprite STR_SPRITE_ALIGNER_PICKER_TOOLTIP :{BLACK}Pick a sprite from anywhere on the screen Index: newgrf_debug_gui.cpp =================================================================== --- newgrf_debug_gui.cpp (revision 27171) +++ newgrf_debug_gui.cpp (working copy) @@ -808,19 +808,36 @@ struct SpriteAlignerWindow : Window { SpriteID current_sprite; ///< The currently shown sprite Scrollbar *vscroll; + typedef SmallPair xy_offs; + SmallMap offs_start_map; ///< Mapping of starting offsets for all sprites viewed since opening the sprite aligner window SpriteAlignerWindow(WindowDesc *desc, WindowNumber wno) : Window(desc) { + const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL); + /* Initialize offset mapping */ + this->offs_start_map.Insert(this->current_sprite, xy_offs(spr->x_offs, spr->y_offs)); this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_SA_SCROLLBAR); this->FinishInitNested(wno); /* Oh yes, we assume there is at least one normal sprite! */ - while (GetSpriteType(this->current_sprite) != ST_NORMAL) this->current_sprite++; + while (GetSpriteType(this->current_sprite) != ST_NORMAL) SetCurrentSprite(this->current_sprite + 1); } + void SetCurrentSprite(SpriteID new_sprite) + { + this->current_sprite = new_sprite; + + /* Remember the original offsets of the new sprite, if not already in map */ + if (this->offs_start_map.Contains(new_sprite)) return; + + const Sprite *spr = GetSprite(new_sprite, ST_NORMAL); + this->offs_start_map.Insert(new_sprite, xy_offs(spr->x_offs, spr->y_offs)); + } + virtual void SetStringParameters(int widget) const { + const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL); switch (widget) { case WID_SA_CAPTION: SetDParam(0, this->current_sprite); @@ -828,11 +845,16 @@ break; case WID_SA_OFFSETS: { - const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL); SetDParam(0, spr->x_offs); SetDParam(1, spr->y_offs); break; } + case WID_SA_OFFSETS_REL: { + /* Relative offset is -(starting absolute offset) + new absolute offset */ + SetDParam(0, -(this->offs_start_map.Find(this->current_sprite)->second.first) + spr->x_offs); + SetDParam(1, -(this->offs_start_map.Find(this->current_sprite)->second.second) + spr->y_offs); + break; + } default: break; @@ -896,7 +918,7 @@ switch (widget) { case WID_SA_PREVIOUS: do { - this->current_sprite = (this->current_sprite == 0 ? GetMaxSpriteID() : this->current_sprite) - 1; + SetCurrentSprite((this->current_sprite == 0 ? GetMaxSpriteID() : this->current_sprite) - 1); } while (GetSpriteType(this->current_sprite) != ST_NORMAL); this->SetDirty(); break; @@ -907,7 +929,7 @@ case WID_SA_NEXT: do { - this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID(); + SetCurrentSprite((this->current_sprite + 1) % GetMaxSpriteID()); } while (GetSpriteType(this->current_sprite) != ST_NORMAL); this->SetDirty(); break; @@ -925,7 +947,7 @@ uint i = this->vscroll->GetPosition() + (pt.y - nwid->pos_y) / step_size; if (i < _newgrf_debug_sprite_picker.sprites.Length()) { SpriteID spr = _newgrf_debug_sprite_picker.sprites[i]; - if (GetSpriteType(spr) == ST_NORMAL) this->current_sprite = spr; + if (GetSpriteType(spr) == ST_NORMAL) SetCurrentSprite(spr); } this->SetDirty(); break; @@ -960,6 +982,14 @@ MarkWholeScreenDirty(); break; } + + case WID_SA_RESET_REL: { + Sprite *spr = const_cast(GetSprite(this->current_sprite, ST_NORMAL)); + /* Reset the starting offsets for the current sprite */ + this->offs_start_map.Find(this->current_sprite)->second = xy_offs(spr->x_offs, spr->y_offs); + this->SetDirty(); + break; + } } } @@ -967,10 +997,10 @@ { if (StrEmpty(str)) return; - this->current_sprite = atoi(str); - if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0; + SetCurrentSprite(atoi(str)); + if (this->current_sprite >= GetMaxSpriteID()) SetCurrentSprite(0); while (GetSpriteType(this->current_sprite) != ST_NORMAL) { - this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID(); + SetCurrentSprite((this->current_sprite + 1) % GetMaxSpriteID()); } this->SetDirty(); } @@ -1038,6 +1068,14 @@ NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10), NWidget(WWT_LABEL, COLOUR_GREY, WID_SA_OFFSETS), SetDataTip(STR_SPRITE_ALIGNER_OFFSETS, STR_NULL), SetFill(1, 0), EndContainer(), + NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10), + NWidget(WWT_LABEL, COLOUR_GREY, WID_SA_OFFSETS_REL), SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_REL, STR_NULL), SetFill(1, 0), + EndContainer(), + NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10), + NWidget(NWID_SPACER), SetFill(1, 1), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_RESET_REL), SetDataTip(STR_SPRITE_ALIGNER_RESET_BUTTON, STR_SPRITE_ALIGNER_RESET_TOOLTIP), SetResize(0, 0), + NWidget(NWID_SPACER), SetFill(1, 1), + EndContainer(), EndContainer(), NWidget(NWID_VERTICAL), SetPIP(10, 5, 10), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_PICKER), SetDataTip(STR_SPRITE_ALIGNER_PICKER_BUTTON, STR_SPRITE_ALIGNER_PICKER_TOOLTIP), SetFill(1, 0), Index: script/api/script_window.hpp =================================================================== --- script/api/script_window.hpp (revision 27171) +++ script/api/script_window.hpp (working copy) @@ -1800,10 +1800,12 @@ WID_SA_RIGHT = ::WID_SA_RIGHT, ///< Move the sprite to the right. WID_SA_DOWN = ::WID_SA_DOWN, ///< Move the sprite down. WID_SA_SPRITE = ::WID_SA_SPRITE, ///< The actual sprite. - WID_SA_OFFSETS = ::WID_SA_OFFSETS, ///< The sprite offsets. + WID_SA_OFFSETS = ::WID_SA_OFFSETS, ///< The sprite offsets (absolute). + WID_SA_OFFSETS_REL = ::WID_SA_OFFSETS_REL, ///< The sprite offsets (relative). WID_SA_PICKER = ::WID_SA_PICKER, ///< Sprite picker. WID_SA_LIST = ::WID_SA_LIST, ///< Queried sprite list. WID_SA_SCROLLBAR = ::WID_SA_SCROLLBAR, ///< Scrollbar for sprite list. + WID_SA_RESET_REL = ::WID_SA_RESET_REL, ///< Reset relative sprite offsets }; /* automatically generated from ../../widgets/newgrf_widget.h */ Index: widgets/newgrf_debug_widget.h =================================================================== --- widgets/newgrf_debug_widget.h (revision 27171) +++ widgets/newgrf_debug_widget.h (working copy) @@ -25,19 +25,21 @@ /** Widgets of the #SpriteAlignerWindow class. */ enum SpriteAlignerWidgets { - WID_SA_CAPTION, ///< Caption of the window. - WID_SA_PREVIOUS, ///< Skip to the previous sprite. - WID_SA_GOTO, ///< Go to a given sprite. - WID_SA_NEXT, ///< Skip to the next sprite. - WID_SA_UP, ///< Move the sprite up. - WID_SA_LEFT, ///< Move the sprite to the left. - WID_SA_RIGHT, ///< Move the sprite to the right. - WID_SA_DOWN, ///< Move the sprite down. - WID_SA_SPRITE, ///< The actual sprite. - WID_SA_OFFSETS, ///< The sprite offsets. - WID_SA_PICKER, ///< Sprite picker. - WID_SA_LIST, ///< Queried sprite list. - WID_SA_SCROLLBAR, ///< Scrollbar for sprite list. + WID_SA_CAPTION, ///< Caption of the window. + WID_SA_PREVIOUS, ///< Skip to the previous sprite. + WID_SA_GOTO, ///< Go to a given sprite. + WID_SA_NEXT, ///< Skip to the next sprite. + WID_SA_UP, ///< Move the sprite up. + WID_SA_LEFT, ///< Move the sprite to the left. + WID_SA_RIGHT, ///< Move the sprite to the right. + WID_SA_DOWN, ///< Move the sprite down. + WID_SA_SPRITE, ///< The actual sprite. + WID_SA_OFFSETS, ///< The sprite offsets (absolute). + WID_SA_OFFSETS_REL, ///< The sprite offsets (relative). + WID_SA_PICKER, ///< Sprite picker. + WID_SA_LIST, ///< Queried sprite list. + WID_SA_SCROLLBAR, ///< Scrollbar for sprite list. + WID_SA_RESET_REL, ///< Reset relative sprite offset }; #endif /* WIDGETS_NEWGRF_DEBUG_WIDGET_H */