fix: Allow titlebars to be disabled

This commit is contained in:
2023-08-18 00:49:09 +01:00
parent 6215c0dd2d
commit a113d8874f
3 changed files with 169 additions and 141 deletions

View File

@@ -462,13 +462,19 @@ struct GameOptionsWindow : Window {
break;
case WID_GO_WINDOWS_TITLEBARS:
_settings_client.gui.windows_titlebars ^= _settings_client.gui.windows_titlebars;
_settings_client.gui.windows_titlebars = !_settings_client.gui.windows_titlebars;
this->SetWidgetLoweredState(WID_GO_WINDOWS_TITLEBARS, _settings_client.gui.windows_titlebars);
this->SetDirty();
if (_settings_client.gui.min_button == 48 && _settings_client.gui.windows_titlebars) {
_settings_client.gui.min_button = 40;
}
if (_settings_client.gui.min_button == 40 && !_settings_client.gui.windows_titlebars) {
_settings_client.gui.min_button = 48;
}
ReInitAllWindows(false);
break;
case WID_GO_MOUSE_CURSOR:

View File

@@ -2961,6 +2961,20 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
Dimension size = {this->min_x, this->min_y};
Dimension fill = {this->fill_x, this->fill_y};
Dimension resize = {this->resize_x, this->resize_y};
// Note: Disabled titlebars by reducing its elements size to zero
if (!_settings_client.gui.windows_titlebars && w->window_class != WC_NEWS_WINDOW &&
(this->type == WWT_CAPTION || this->type == WWT_STICKYBOX || this->type == WWT_SHADEBOX ||
this->type == WWT_DEFSIZEBOX || this->type == WWT_CLOSEBOX || this->type == WWT_DEBUGBOX)) {
this->sizing_type = NWST_NONE;
size = {0, 0};
fill = {0, 0};
resize = {0, 0};
if (this->type == WWT_CAPTION) {
fill.width = 1;
resize.width = 1;
}
} else {
switch (this->type) {
case WWT_EMPTY: {
break;
@@ -3115,6 +3129,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
default:
NOT_REACHED();
}
}
if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);

View File

@@ -39,6 +39,7 @@
#include "guitimer_func.h"
#include "news_func.h"
#include "build_confirmation_func.h"
#include "widgets/settings_widget.h"
#include "safeguards.h"
@@ -818,6 +819,12 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count, boo
Game::NewEvent(new ScriptEventWindowWidgetClick((ScriptWindow::WindowClass)w->window_class, w->window_number, widget_index));
}
// Note: Workaround to avoid immediate toggle when titlebars are enabled.
if (_settings_client.gui.windows_titlebars &&
w->window_class == WC_GAME_OPTIONS && widget_index == WID_GO_WINDOWS_TITLEBARS && mouse_down){
return;
}
w->OnClick(pt, widget_index, click_count);
}
@@ -844,7 +851,7 @@ static void DispatchLeftButtonDownEvent(Window *w, int x, int y, int click_count
static void DispatchLeftButtonUpEvent(Window *w, int x, int y)
{
_dragging_widget = false;
if (_settings_client.gui.windows_titlebars || _dragging_window) return;
if (_dragging_window) return;
DispatchLeftClickEvent(w, x, y, _left_button_click_count, false);
}