#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
 with
 all buttons in the reticule area grayed out, except for the central
 button.

 To achieve a similar look in the JavaScript tutorial, all reticule area
 buttons,
 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
 following
 instructions in data/base/script/tutorial.js:
 {{{
         setReticuleButton(CLOSE_BUTTON, _("Close"), "", "");
         [...]
         showInterface();
 }}}

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

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

 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:
 {{{
 -5,1,image_reticule_grey.png
 }}}

 The correct central button picture is 46x37 pixels in size, larger than an
 ordinary reticule button picture of 37x28 pixels. The latter includes a
 shadow
 at its right side, one pixel wide. The smaller picture's offset from its
 correct
 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
 data/base/images/intfac.img:
 * -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
 src/hci.cpp,
   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
 src/hci.cpp

 === 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
 enabled.
 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
Warzone2100-project@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/warzone2100-project

Reply via email to