summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-11-17 09:09:20 +0000
committerrubidium <rubidium@openttd.org>2009-11-17 09:09:20 +0000
commitbdb118aa69131d401850ad6209da8ffd748531b4 (patch)
tree0de56b7af7dc7046857df63ceecd3bb03de9e9dc
parenta808623b24b247d3a8b3b08875dd6cd2e22a85c6 (diff)
downloadopenttd-bdb118aa69131d401850ad6209da8ffd748531b4.tar.xz
(svn r18134) -Codechange: scale the offset of the text/vehicle in the vehicle lists based on the font and the unit numbers in the list
-rw-r--r--src/group_gui.cpp2
-rw-r--r--src/vehicle_gui.cpp26
-rw-r--r--src/vehicle_gui_base.h1
3 files changed, 24 insertions, 5 deletions
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 4b72080e9..8fe54f9f0 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -15,7 +15,6 @@
#include "textbuf_gui.h"
#include "command_func.h"
#include "vehicle_gui.h"
-#include "vehicle_gui_base.h"
#include "vehicle_base.h"
#include "group.h"
#include "strings_func.h"
@@ -27,6 +26,7 @@
#include "widgets/dropdown_type.h"
#include "widgets/dropdown_func.h"
#include "tilehighlight_func.h"
+#include "vehicle_gui_base.h"
#include "table/strings.h"
#include "table/sprites.h"
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 20e35fcfa..9bf5e6841 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -100,6 +100,22 @@ void BaseVehicleListWindow::BuildVehicleList(Owner owner, uint16 index, uint16 w
GenerateVehicleSortList(&this->vehicles, this->vehicle_type, owner, index, window_type);
+ uint unitnumber = 0;
+ for (const Vehicle **v = this->vehicles.Begin(); v != this->vehicles.End(); v++) {
+ unitnumber = max<uint>(unitnumber, (*v)->unitnumber);
+ }
+
+ /* Because 111 is much less wide than e.g. 999 we use the
+ * wider numbers to determine the width instead of just
+ * the random number that it seems to be. */
+ if (unitnumber >= 1000) {
+ this->max_unitnumber = 9999;
+ } else if (unitnumber >= 100) {
+ this->max_unitnumber = 999;
+ } else {
+ this->max_unitnumber = 99;
+ }
+
this->vehicles.RebuildDone();
this->vscroll.SetCount(this->vehicles.Length());
}
@@ -827,11 +843,13 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
int right = r.right - WD_MATRIX_RIGHT;
bool rtl = _dynlang.text_dir == TD_RTL;
- int text_left = left + (rtl ? 0 : 19);
- int text_right = right - (rtl ? 19 : 0);
+ SetDParam(0, this->max_unitnumber);
+ int text_offset = GetStringBoundingBox(STR_JUST_INT).width + WD_FRAMERECT_RIGHT;
+ int text_left = left + (rtl ? 0 : text_offset);
+ int text_right = right - (rtl ? text_offset : 0);
- int orderlist_left = left + (rtl ? 0 : 138);
- int orderlist_right = right - (rtl ? 138 : 0);
+ int orderlist_left = left + (rtl ? 0 : 120 + text_offset);
+ int orderlist_right = right - (rtl ? 120 + text_offset : 0);
int vehicle_button_x = rtl ? right - 8 : left;
diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h
index 6ce4b65ac..5380aacb0 100644
--- a/src/vehicle_gui_base.h
+++ b/src/vehicle_gui_base.h
@@ -20,6 +20,7 @@ struct BaseVehicleListWindow: public Window {
GUIVehicleList vehicles; ///< The list of vehicles
Listing *sorting; ///< Pointer to the vehicle type related sorting.
VehicleType vehicle_type; ///< The vehicle type that is sorted
+ UnitID max_unitnumber; ///< The maximum UnitID
static const StringID vehicle_sorter_names[];
static GUIVehicleList::SortFunction * const vehicle_sorter_funcs[];