#4855: Tutorial shows wrong icon for reticule area's central button
 Reporter:  Forgon                               |             Owner:  Per
     Type:  patch (an actual patch, not a        |            Status:  new
  request for one)                               |         Milestone:
 Priority:  normal                               |  unspecified
Component:  JavaScript Issues                    |           Version:
 Keywords:                                       |  git/master
 Blocking:                                       |        Blocked By:
                                                 |  Operating System:  All
                                                 |  /Non-Specific
 Before the base building tutorial was converted to JavaScript, it started
 all buttons in the reticule area grayed out, except for the central

 To achieve a similar look in the JavaScript tutorial, all reticule area
 including the central button, were disabled in

 commit e52249660909d2937a52de18c42588ecee66830f
 Author: KJeff01 <kjeff1...@gmail.com>
 Date:   Tue Aug 7 17:28:12 2018 -0500

     Update tutorial now that reticule buttons disable better.

     Specifically, disable reticule buttons like in past versions.

 This change had two unintended consequences: The central button
 * showed the picture data/base/images/intfac/image_reticule_grey.png
   instead of data/base/images/intfac/image_canceldown.png
 * was misaligned by 5 pixels to the left and 3 pixels upwards

 The close button was disabled and its reticule button shown by the
 instructions in data/base/script/tutorial.js:
         setReticuleButton(CLOSE_BUTTON, _("Close"), "", "");

 Because setReticuleButton() in src/qtscriptfuncs.cpp was called with an
 third argument (meant to contain a filename), setReticuleStats() in
 disabled its button number, 0 (the value of CLOSE_BUTTON).

 Later, js_showInterface() in src/qtscriptfuncs.cpp displayed reticule
 through functions in src/hci.cpp: intAddReticule() called addReticuleBut()
 called intDisplayReticuleButton(), which showed the same picture every
 a reticule button is disabled, the wrong one in the case of the central
         if (butDisabled)
                 iV_DrawImage(IntImages, IMAGE_RETICULE_GREY, x, y);

 Because the wrong picture was shown, its coordinates were wrong, too.
 The position of of reticule area images was calculated by the addition of:
 * an offset relative to the reticule area given in src/hci.cpp:
 static BUTOFFSET ReticuleOffsets[NUMRETBUTS] =          // Reticule button
 form relative positions.
         {48, 47},       // RETBUT_CANCEL,
 * an offset read from data/base/images/intfac.img:

 The correct central button picture is 46x37 pixels in size, larger than an
 ordinary reticule button picture of 37x28 pixels. The latter includes a
 at its right side, one pixel wide. The smaller picture's offset from its
 position is thus expected to be (46-37-1)/2,(37-28)/2 = 5,4 pixels.
 The actual value of 5,3 resulted from offsets in
 * -5,1 for the correct picture
 * -5,0 for the wrong picture

 === Refactoring

 In the course of investigating this bug, some related code was refactored:
 * calculation of reticule image coordinates has been simplified
 * the function setReticuleBut() was merged into intAddReticule() in
   because it was not used anywhere else and its name was too similar to
   setReticuleButton() of src/qtscriptfuncs.cpp
 * two useless variables, RETXOFFSET and RETYOFFSET, were removed in

 === Simplify script function setReticuleButton()

 The function setReticuleButton() no longer takes filenames that determine
 which images need to be displayed or whether the reticule button is
 The images that need to be shown for different buttons never change, and
 disabling buttons via empty filename argument was an undocumented feature.
 As a replacement for the filename arguments, a boolean argument determines
 whether a button is enabled (if set to true) or not (if set to false).

Ticket URL: <http://developer.wz2100.net/ticket/4855>
Warzone 2100 Trac <http://developer.wz2100.net/>
The Warzone 2100 Project

Warzone2100-project mailing list

Reply via email to