Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor sprite aligner enhancements #10249

Merged
merged 3 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/lang/english.txt
Expand Up @@ -3325,6 +3325,13 @@ STR_SPRITE_ALIGNER_PREVIOUS_BUTTON :{BLACK}Previous
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. Ctrl+Click to move the sprite eight units at a time

###length 2
STR_SPRITE_ALIGNER_CENTRE_OFFSET :{BLACK}Offset centred
STR_SPRITE_ALIGNER_CENTRE_SPRITE :{BLACK}Sprite centred

STR_SPRITE_ALIGNER_CROSSHAIR :{BLACK}Crosshair

STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relative
STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Reset the current relative offsets
STR_SPRITE_ALIGNER_OFFSETS_ABS :{BLACK}X offset: {NUM}, Y offset: {NUM} (Absolute)
Expand Down
56 changes: 45 additions & 11 deletions src/newgrf_debug_gui.cpp
Expand Up @@ -808,12 +808,18 @@ struct SpriteAlignerWindow : Window {
Scrollbar *vscroll;
SmallMap<SpriteID, XyOffs> offs_start_map; ///< Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window.

static bool centre;
static bool crosshair;

SpriteAlignerWindow(WindowDesc *desc, WindowNumber wno) : Window(desc)
{
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_SA_SCROLLBAR);
this->FinishInitNested(wno);

this->SetWidgetLoweredState(WID_SA_CENTRE, SpriteAlignerWindow::centre);
this->SetWidgetLoweredState(WID_SA_CROSSHAIR, SpriteAlignerWindow::crosshair);

/* Oh yes, we assume there is at least one normal sprite! */
while (GetSpriteType(this->current_sprite) != ST_NORMAL) this->current_sprite++;
}
Expand Down Expand Up @@ -859,6 +865,8 @@ struct SpriteAlignerWindow : Window {
size->height = ScaleGUITrad(200);
break;
case WID_SA_LIST:
SetDParamMaxDigits(0, 6);
size->width = GetStringBoundingBox(STR_BLACK_COMMA).width + padding.width;
resize->height = FONT_HEIGHT_NORMAL + padding.height;
resize->width = 1;
fill->height = resize->height;
Expand All @@ -875,15 +883,26 @@ struct SpriteAlignerWindow : Window {
/* Center the sprite ourselves */
const Sprite *spr = GetSprite(this->current_sprite, ST_NORMAL);
Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
int x = -UnScaleGUI(spr->x_offs) + (ir.Width() - UnScaleGUI(spr->width) ) / 2;
int y = -UnScaleGUI(spr->y_offs) + (ir.Height() - UnScaleGUI(spr->height)) / 2;
int x;
int y;
if (SpriteAlignerWindow::centre) {
x = -UnScaleGUI(spr->x_offs) + (ir.Width() - UnScaleGUI(spr->width)) / 2;
y = -UnScaleGUI(spr->y_offs) + (ir.Height() - UnScaleGUI(spr->height)) / 2;
} else {
x = ir.Width() / 2;
y = ir.Height() / 2;
}

DrawPixelInfo new_dpi;
if (!FillDrawPixelInfo(&new_dpi, ir.left, ir.top, ir.Width(), ir.Height())) break;
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &new_dpi;

DrawSprite(this->current_sprite, PAL_NONE, x, y, nullptr, ZOOM_LVL_GUI);
if (this->crosshair) {
GfxDrawLine(x, 0, x, ir.Height() - 1, PC_WHITE, 1, 1);
GfxDrawLine(0, y, ir.Width() - 1, y, PC_WHITE, 1, 1);
}

_cur_dpi = old_dpi;

Expand All @@ -897,7 +916,7 @@ struct SpriteAlignerWindow : Window {
std::vector<SpriteID> &list = _newgrf_debug_sprite_picker.sprites;
int max = std::min<int>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (uint)list.size());

Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
Rect ir = r.Shrink(WidgetDimensions::scaled.matrix);
for (int i = this->vscroll->GetPosition(); i < max; i++) {
SetDParam(0, list[i]);
DrawString(ir, STR_BLACK_COMMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
Expand Down Expand Up @@ -989,6 +1008,18 @@ struct SpriteAlignerWindow : Window {
this->offs_start_map.Erase(this->current_sprite);
this->SetDirty();
break;

case WID_SA_CENTRE:
SpriteAlignerWindow::centre = !SpriteAlignerWindow::centre;
this->SetWidgetLoweredState(widget, SpriteAlignerWindow::centre);
this->SetDirty();
break;

case WID_SA_CROSSHAIR:
SpriteAlignerWindow::crosshair = !SpriteAlignerWindow::crosshair;
this->SetWidgetLoweredState(widget, SpriteAlignerWindow::crosshair);
this->SetDirty();
break;
}
}

Expand Down Expand Up @@ -1025,6 +1056,9 @@ struct SpriteAlignerWindow : Window {
}
};

bool SpriteAlignerWindow::centre = true;
bool SpriteAlignerWindow::crosshair = true;

static const NWidgetPart _nested_sprite_aligner_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
Expand All @@ -1042,34 +1076,34 @@ static const NWidgetPart _nested_sprite_aligner_widgets[] = {
EndContainer(),
NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
NWidget(NWID_SPACER), SetFill(1, 1),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_UP), SetDataTip(SPR_ARROW_UP, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_UP), SetDataTip(SPR_ARROW_UP, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
NWidget(NWID_SPACER), SetFill(1, 1),
EndContainer(),
NWidget(NWID_HORIZONTAL_LTR), SetPIP(10, 5, 10),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(1, 1),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_LEFT), SetDataTip(SPR_ARROW_LEFT, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_LEFT), SetDataTip(SPR_ARROW_LEFT, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
NWidget(NWID_SPACER), SetFill(1, 1),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_DARK_BLUE, WID_SA_SPRITE), SetDataTip(STR_NULL, STR_SPRITE_ALIGNER_SPRITE_TOOLTIP),
EndContainer(),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(1, 1),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_RIGHT), SetDataTip(SPR_ARROW_RIGHT, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_RIGHT), SetDataTip(SPR_ARROW_RIGHT, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
NWidget(NWID_SPACER), SetFill(1, 1),
EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
NWidget(NWID_SPACER), SetFill(1, 1),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SA_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SPRITE_ALIGNER_MOVE_TOOLTIP), SetResize(0, 0), SetMinimalSize(11, 11),
NWidget(NWID_SPACER), SetFill(1, 1),
EndContainer(),
NWidget(WWT_LABEL, COLOUR_GREY, WID_SA_OFFSETS_ABS), SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_ABS, STR_NULL), SetFill(1, 0), SetPadding(0, 10, 0, 10),
NWidget(WWT_LABEL, COLOUR_GREY, WID_SA_OFFSETS_REL), SetDataTip(STR_SPRITE_ALIGNER_OFFSETS_REL, STR_NULL), SetFill(1, 0), SetPadding(0, 10, 0, 10),
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), SetFill(0, 0),
NWidget(NWID_SPACER), SetFill(1, 1),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 5, 10),
NWidget(WWT_TEXTBTN_2, COLOUR_GREY, WID_SA_CENTRE), SetDataTip(STR_SPRITE_ALIGNER_CENTRE_OFFSET, STR_NULL), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SA_RESET_REL), SetDataTip(STR_SPRITE_ALIGNER_RESET_BUTTON, STR_SPRITE_ALIGNER_RESET_TOOLTIP), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SA_CROSSHAIR), SetDataTip(STR_SPRITE_ALIGNER_CROSSHAIR, STR_NULL), SetFill(1, 0),
EndContainer(),
EndContainer(),
NWidget(NWID_VERTICAL), SetPIP(10, 5, 10),
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/newgrf_debug_widget.h
Expand Up @@ -38,6 +38,8 @@ enum SpriteAlignerWidgets {
WID_SA_LIST, ///< Queried sprite list.
WID_SA_SCROLLBAR, ///< Scrollbar for sprite list.
WID_SA_RESET_REL, ///< Reset relative sprite offset
WID_SA_CENTRE, ///< Toggle centre sprite.
WID_SA_CROSSHAIR, ///< Toggle crosshair.
};

#endif /* WIDGETS_NEWGRF_DEBUG_WIDGET_H */