From 93599c1be548fb9938d5da8d45c96e9ece760ea1 Mon Sep 17 00:00:00 2001 From: Darkvater Date: Tue, 24 Oct 2006 23:11:40 +0000 Subject: (svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification of order_gui (only disable a single widget if not local player, all others aren't visible anyways). --- gfx.c | 24 ++++++++++++++---------- misc_gui.c | 4 ++-- order_gui.c | 45 +++++++++++++++++++++++---------------------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/gfx.c b/gfx.c index e54680453..8ffb5de59 100644 --- a/gfx.c +++ b/gfx.c @@ -33,22 +33,19 @@ static byte _string_colorremap[3]; #define DIRTY_BYTES_PER_LINE (MAX_SCREEN_WIDTH / 64) static byte _dirty_blocks[DIRTY_BYTES_PER_LINE * MAX_SCREEN_HEIGHT / 8]; - - -void memcpy_pitch(void *d, void *s, int w, int h, int spitch, int dpitch) +void memcpy_pitch(void *dst, void *src, int w, int h, int srcpitch, int dstpitch) { - byte *dp = (byte*)d; - byte *sp = (byte*)s; + byte *dstp = (byte*)dst; + byte *srcp = (byte*)src; assert(h >= 0); for (; h != 0; --h) { - memcpy(dp, sp, w); - dp += dpitch; - sp += spitch; + memcpy(dstp, srcp, w); + dstp += dstpitch; + srcp += srcpitch; } } - void GfxScroll(int left, int top, int width, int height, int xo, int yo) { const Pixel *src; @@ -583,7 +580,14 @@ BoundingRect GetStringBoundingBox(const char *str) return br; } - +/** Draw a string at the given coordinates with the given colour + * @param string the string to draw + * @param x offset from left side of the screen, if negative offset from the right side + * @param x offset from top side of the screen, if negative offset from the bottom + * @param real_color colour of the string, see _string_colormap in + * table/palettes.h or docs/ottd-colourtext-palette.png + * @return the x-coordinates where the drawing has finished. If nothing is drawn + * the originally passed x-coordinate is returned */ int DoDrawString(const char *string, int x, int y, uint16 real_color) { DrawPixelInfo *dpi = _cur_dpi; diff --git a/misc_gui.c b/misc_gui.c index 854ad7bec..489ee3383 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -1094,12 +1094,12 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, w = AllocateWindowDesc(&_query_string_desc); GetString(_edit_str_buf, str, lastof(_edit_str_buf)); - _edit_str_buf[realmaxlen-1] = '\0'; + _edit_str_buf[realmaxlen - 1] = '\0'; if (maxlen & 0x1000) { WP(w, querystr_d).orig = NULL; } else { - strcpy(_orig_str_buf, _edit_str_buf); + strecpy(_orig_str_buf, _edit_str_buf, lastof(_orig_str_buf)); WP(w, querystr_d).orig = _orig_str_buf; } diff --git a/order_gui.c b/order_gui.c index d80f70280..7df67785a 100644 --- a/order_gui.c +++ b/order_gui.c @@ -57,11 +57,9 @@ static void DrawOrdersWindow(Window *w) int sel; int y, i; bool shared_orders; - bool not_localplayer; byte color; v = GetVehicle(w->window_number); - not_localplayer = v->owner != _local_player; shared_orders = IsOrderListShared(v); @@ -72,31 +70,32 @@ static void DrawOrdersWindow(Window *w) order = GetVehicleOrder(v, sel); - /* skip */ - SetWindowWidgetDisabledState(w, 4, not_localplayer || v->num_orders == 0); - - /* delete */ - SetWindowWidgetDisabledState(w, 5, not_localplayer || - (uint)v->num_orders + (shared_orders ? 1 : 0) <= (uint)WP(w, order_d).sel); - - /* non-stop only for trains */ - SetWindowWidgetDisabledState(w, 6, not_localplayer || v->type != VEH_Train - || order == NULL); - SetWindowWidgetDisabledState(w, 7, not_localplayer); // go-to - SetWindowWidgetDisabledState(w, 8, not_localplayer || order == NULL); // full load - SetWindowWidgetDisabledState(w, 9, not_localplayer || order == NULL); // unload - SetWindowWidgetDisabledState(w, 10, not_localplayer || order == NULL); // transfer - SetWindowWidgetDisabledState(w, 11, !shared_orders || v->orders == NULL); // Disable list of vehicles with the same shared orders if there are no list - SetWindowWidgetDisabledState(w, 12, not_localplayer || order == NULL); // Refit - + if (v->owner == _local_player) { + /* skip */ + SetWindowWidgetDisabledState(w, 4, v->num_orders == 0); + + /* delete */ + SetWindowWidgetDisabledState(w, 5, + (uint)v->num_orders + (shared_orders ? 1 : 0) <= (uint)WP(w, order_d).sel); + + /* non-stop only for trains */ + SetWindowWidgetDisabledState(w, 6, v->type != VEH_Train || order == NULL); + SetWindowWidgetDisabledState(w, 8, order == NULL); // full load + SetWindowWidgetDisabledState(w, 9, order == NULL); // unload + SetWindowWidgetDisabledState(w, 10, order == NULL); // transfer + /* Disable list of vehicles with the same shared orders if there is no list */ + SetWindowWidgetDisabledState(w, 11, !shared_orders || v->orders == NULL); + SetWindowWidgetDisabledState(w, 12, order == NULL); // Refit + } else { + DisableWindowWidget(w, 10); + } ShowWindowWidget(w, 9); // Unload HideWindowWidget(w, 12); // Refit if (order != NULL) { switch (order->type) { - case OT_GOTO_STATION: - break; + case OT_GOTO_STATION: break; case OT_GOTO_DEPOT: DisableWindowWidget(w, 10); @@ -495,6 +494,8 @@ static void OrdersWndProc(Window *w, WindowEvent *e) Vehicle *v = GetVehicle(w->window_number); uint i; + if (v->owner != _local_player) break; + for (i = 0; i < lengthof(_order_keycodes); i++) { if (e->we.keypress.keycode == _order_keycodes[i]) { e->we.keypress.cont = false; @@ -536,7 +537,7 @@ static void OrdersWndProc(Window *w, WindowEvent *e) * This is because of all open order windows WE_MOUSELOOP is called * and if you have 3 windows open, and this check is not done * the order is copied to the last open window instead of the - * one where GOTO is enalbed + * one where GOTO is enabled */ if (v != NULL && IsWindowWidgetLowered(w, 7)) { _place_clicked_vehicle = NULL; -- cgit v1.2.3-70-g09d2