Update to 13.0-RC1

This commit is contained in:
Pavel Stupnikov
2023-01-03 15:58:14 +04:00
parent be23283677
commit 59c991fa52
326 changed files with 12923 additions and 8705 deletions

View File

@@ -48,8 +48,8 @@ class BuildObjectWindow : public Window {
typedef GUIList<ObjectClassID, StringFilter &> GUIObjectClassList; ///< Type definition for the list to hold available object classes.
static const uint EDITBOX_MAX_SIZE = 16; ///< The maximum number of characters for the filter edit box.
static const int OBJECT_MARGIN = 4; ///< The margin (in pixels) around an object.
int object_margin; ///< The margin (in pixels) around an object.
int line_height; ///< The height of a single line.
int info_height; ///< The height of the info box.
Scrollbar *vscroll; ///< The scrollbar.
@@ -229,6 +229,11 @@ public:
}
}
void OnInit() override
{
this->object_margin = ScaleGUITrad(4);
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
@@ -239,7 +244,7 @@ public:
size->width = std::max(size->width, GetStringBoundingBox(objclass->name).width);
}
size->width += padding.width;
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
this->line_height = FONT_HEIGHT_NORMAL + padding.height;
resize->height = this->line_height;
size->height = 5 * this->line_height;
break;
@@ -266,7 +271,7 @@ public:
case WID_BO_OBJECT_SPRITE: {
bool two_wide = false; // Whether there will be two widgets next to each other in the matrix or not.
int height[2] = {0, 0}; // The height for the different views; in this case views 1/2 and 4.
uint height[2] = {0, 0}; // The height for the different views; in this case views 1/2 and 4.
/* Get the height and view information. */
for (int i = 0; i < NUM_OBJECTS; i++) {
@@ -279,26 +284,28 @@ public:
/* Determine the pixel heights. */
for (size_t i = 0; i < lengthof(height); i++) {
height[i] *= ScaleGUITrad(TILE_HEIGHT);
height[i] += ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN;
height[i] += ScaleGUITrad(TILE_PIXELS) + 2 * this->object_margin;
}
/* Now determine the size of the minimum widgets. When there are two columns, then
* we want these columns to be slightly less wide. When there are two rows, then
* determine the size of the widgets based on the maximum size for a single row
* of widgets, or just the twice the widget height of the two row ones. */
size->height = std::max(height[0], height[1] * 2 + 2);
size->height = std::max(height[0], height[1] * 2);
if (two_wide) {
size->width = (3 * ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN) * 2 + 2;
size->width = (3 * ScaleGUITrad(TILE_PIXELS) + 2 * this->object_margin) * 2;
} else {
size->width = 4 * ScaleGUITrad(TILE_PIXELS) + 2 * OBJECT_MARGIN;
size->width = 4 * ScaleGUITrad(TILE_PIXELS) + 2 * this->object_margin;
}
/* Get the right size for the single widget based on the current spec. */
ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
const ObjectSpec *spec = objclass->GetSpec(_selected_object_index);
if (spec != nullptr) {
if (spec->views >= 2) size->width = size->width / 2 - 1;
if (spec->views >= 4) size->height = size->height / 2 - 1;
if (spec->views <= 1) size->width += WidgetDimensions::scaled.hsep_normal;
if (spec->views <= 2) size->height += WidgetDimensions::scaled.vsep_normal;
if (spec->views >= 2) size->width /= 2;
if (spec->views >= 4) size->height /= 2;
}
break;
}
@@ -313,8 +320,8 @@ public:
break;
case WID_BO_SELECT_IMAGE:
size->width = ScaleGUITrad(64) + 2;
size->height = ScaleGUITrad(58) + 2;
size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal();
size->height = ScaleGUITrad(58) + WidgetDimensions::scaled.fullbevel.Vertical();
break;
default: break;
@@ -325,15 +332,15 @@ public:
{
switch (GB(widget, 0, 16)) {
case WID_BO_CLASS_LIST: {
int y = r.top;
Rect mr = r.Shrink(WidgetDimensions::scaled.matrix);
uint pos = 0;
for (auto object_class_id : this->object_classes) {
ObjectClass *objclass = ObjectClass::Get(object_class_id);
if (objclass->GetUISpecCount() == 0) continue;
if (!this->vscroll->IsVisible(pos++)) continue;
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, objclass->name,
DrawString(mr, objclass->name,
(object_class_id == _selected_object_class) ? TC_WHITE : TC_BLACK);
y += this->line_height;
mr.top += this->line_height;
}
break;
}
@@ -354,15 +361,15 @@ public:
DrawPixelInfo tmp_dpi;
/* Set up a clipping area for the preview. */
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) {
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
if (spec->grf_prop.grffile == nullptr) {
extern const DrawTileSprites _objects[];
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
DrawOrigTileSeqInGUI(r.Width() / 2 - 1, (r.Height() + matrix_height / 2) / 2 - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), dts, PAL_NONE);
} else {
DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec, GB(widget, 16, 16));
DrawNewObjectTileInGUI(r.Width() / 2 - 1, (r.Height() + matrix_height / 2) / 2 - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), spec, GB(widget, 16, 16));
}
_cur_dpi = old_dpi;
}
@@ -377,19 +384,19 @@ public:
if (spec == nullptr) break;
if (!spec->IsAvailable()) {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK, FILLRECT_CHECKER);
}
DrawPixelInfo tmp_dpi;
/* Set up a clipping area for the preview. */
if (FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top, (r.right - 1) - (r.left + 1) + 1, r.bottom - r.top + 1)) {
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) {
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
if (spec->grf_prop.grffile == nullptr) {
extern const DrawTileSprites _objects[];
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), dts, PAL_NONE);
DrawOrigTileSeqInGUI(r.Width() / 2 - 1, r.Height() - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), dts, PAL_NONE);
} else {
DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - ScaleGUITrad(TILE_PIXELS), spec,
DrawNewObjectTileInGUI(r.Width() / 2 - 1, r.Height() - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), spec,
std::min<int>(_selected_object_view, spec->views - 1));
}
_cur_dpi = old_dpi;
@@ -415,11 +422,11 @@ public:
/* Use all the available space left from where we stand up to the
* end of the window. We ALSO enlarge the window if needed, so we
* can 'go' wild with the bottom of the window. */
int y = DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top;
int y = DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, message, TC_ORANGE) - r.top - 1;
StopTextRefStackUsage();
if (y > this->info_height) {
BuildObjectWindow *bow = const_cast<BuildObjectWindow *>(this);
bow->info_height = y + 2;
bow->info_height = y;
bow->ReInit();
}
}
@@ -724,7 +731,7 @@ static const NWidgetPart _nested_build_object_widgets[] = {
EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetPadding(0, 5, 0, 1), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BO_INFO), SetPadding(0, 5, 2, 2), SetFill(1, 0), SetResize(1, 0),
NWidget(NWID_VERTICAL),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(0, 1), EndContainer(),
NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),