Ticket #2421: 2421.1.patch

File 2421.1.patch, 7.4 KB (added by Stan, 9 years ago)

Hopefully Fix what wraitii wanted so it can be commited. Can someone review this ?

  • binaries/data/mods/public/gui/common/colorFades.js

     
    2222 * duration: maximal duration of the complete fade (if 0 it runs until it is stopped)
    2323 * fun_colorTransform: function which transform the colors;
    2424 *                     arguments: [var data]
     25 * colorMask[optional]: path to a image which is used as a color mask
    2526 * restartAble [optional: if false, the fade can not be restarted; default: true
    2627 * fun_smoothRestart [optional]: a function, which returns a smooth tick counter, if the fade should be started;
    2728 *                               arguments: [var data]; must return false, if smooth restart was not possible and true, if it was ok
    2829 */
    29 function startColorFade(name, tickInterval, duration, fun_colorTransform, restartAble, fun_smoothRestart)
     30function startColorFade(name, tickInterval, duration, fun_colorTransform, colorMask, restartAble, fun_smoothRestart)
    3031{
    3132    // get the overlay
    3233    var overlay = Engine.GetGUIObjectByName(name);
     
    4748                        "tickCounter": 0,
    4849                        "justStopAtExternCall": duration == 0,
    4950                        "stopFade": false,
    50                         "rgb": getInitColorFadeRGB()
     51                        "rgb": getInitColorFadeRGB(),
     52                        "colorMask": colorMask
    5153                    };
    5254        // store it!
    5355        g_colorFade[name] = data;
     
    5759    }
    5860    else if (restartAble)
    5961    {
    60         restartColorFade(name, tickInterval, duration, fun_colorTransform, restartAble, fun_smoothRestart);
     62        restartColorFade(name);
    6163        return;
    6264    }
    6365}
     
    8486    var rgb = data.rgb;
    8587    overlay.sprite="colour: " + rgb.r + " " + rgb.g + " " + rgb.b + " " + rgb.o;
    8688
     89    // check, if color mask mode is used and add the filename in this case
     90    if (data.colorMask)
     91        overlay.sprite += ":" + data.colorMask;
     92       
    8793    // recusive call, if duration is positive
    8894    if (!data.stopFade && (data.justStopAtExternCall || data.duration - (data.tickInterval * data.tickCounter) > 0))
    8995    {
     
    159165    else
    160166    {
    161167        stopColorFade(name, false);
    162         startColorFade(name, data.changeInterval, data.duration, data.fun_colorTransform, data.restartAble, data.fun_smoothRestart);
     168        startColorFade(name, data.changeInterval, data.duration, data.fun_colorTransform, data.colorMask, data.restartAble, data.fun_smoothRestart);
    163169    }
    164170    return true;
    165171}
  • binaries/data/mods/public/gui/gui.dtd

     
    201201<!ATTLIST effect
    202202  add_color             CDATA #IMPLIED
    203203  multiply_color        CDATA #IMPLIED
     204  textureMaskMode       %bool; #IMPLIED
    204205  grayscale             CDATA #IMPLIED
    205206>
  • binaries/data/mods/public/shaders/effects/gui_add.xml

     
    22<effect>
    33
    44    <technique>
     5        <require context="!TEXTURE_MASK_MODE"/>
    56        <require shaders="fixed"/>
    67        <pass shader="fixed:gui_add"/>
    78    </technique>
  • binaries/data/mods/public/shaders/glsl/gui_add.fs

     
    77
    88void main()
    99{
    10   gl_FragColor = texture2D(tex, v_tex) + color;
     10    vec4 t = texture2D(tex, v_tex);
     11
     12    #if TEXTURE_MASK_MODE
     13        gl_FragColor.rgb = color.rgb;
     14        gl_FragColor = color*min(t.a,1.0);;
     15    #else
     16        gl_FragColor = t + color;
     17    #endif
    1118}
  • source/gui/CGUI.cpp

     
    16171617        {
    16181618            effects.m_Greyscale = true;
    16191619        }
     1620        else if (attr_name == "textureMaskMode")
     1621        {
     1622            effects.m_TextureMaskMode = true;
     1623        }
    16201624        else
    16211625        {
    16221626            debug_warn(L"Invalid data - DTD shouldn't allow this");
  • source/gui/CGUISprite.h

     
    6464
    6565struct SGUIImageEffects
    6666{
    67     SGUIImageEffects() : m_Greyscale(false) {}
     67    SGUIImageEffects() : m_Greyscale(false), m_TextureMaskMode(false) {}
    6868    CColor m_AddColor;
    6969    bool m_Greyscale;
     70    bool m_TextureMaskMode;
    7071};
    7172
    7273/**
  • source/gui/GUIRenderer.cpp

     
    7979        //     "stretched:grayscale:filename.ext" - stretched grayscale image
    8080        //     "cropped:(0.5, 0.25)"    - stretch this ratio (x,y) of the top left of the image
    8181        //     "colour:r g b a"         - solid colour
     82        //     "colour:r g b a:filenameMask.ext"  - solid colour with textureMask
    8283        //
    8384        // and if so, try to create it as a new sprite.
    8485        if (SpriteName.substr(0, 10) == "stretched:")
     
    137138        }
    138139        else if (SpriteName.substr(0, 7) == "colour:")
    139140        {
     141            SGUIImage* Image = new SGUIImage;
     142
     143            // check, if there is a sprite for defining of opacity values
     144            size_t splitIndex = SpriteName.substr(7).find_first_of(":");
    140145            CStrW value = wstring_from_utf8(SpriteName.substr(7));
     146            CStrW textureMask;
    141147            CColor color;
    142148
     149            // trim the color value and the name of the textureMask
     150            if(splitIndex != std::basic_string<char>::npos)
     151            {
     152                textureMask = value.substr(splitIndex + 1);
     153                value = value.substr(0, splitIndex);
     154            }
     155
    143156            // Check colour is valid
    144157            if (!GUI<CColor>::ParseString(value, color))
    145158            {
     
    147160                return;
    148161            }
    149162
    150             SGUIImage* Image = new SGUIImage;
     163            // set background color or add color effect if textureMask is set
     164            if(splitIndex != std::basic_string<char>::npos)
     165            {
     166                // TODO: Should check (nicely) that this is a valid file?
     167                Image->m_TextureName = VfsPath("art/textures/ui") / textureMask;
     168                Image->m_Effects = new SGUIImageEffects;
     169                Image->m_Effects->m_AddColor = color;
     170                Image->m_Effects->m_TextureMaskMode = true;
     171            }
     172            else
     173                Image->m_BackColor = color;
    151174
    152             Image->m_BackColor = color;
    153 
    154175            CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
    155176            Image->m_Size = ca;
    156177            Image->m_TextureSize = ca;
     
    231252        {
    232253            if ((*cit)->m_Effects->m_AddColor != CColor())
    233254            {
    234                 Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_add);
     255                CShaderDefines defines;
     256                // enable texture mask mode
     257                if ((*cit)->m_Effects->m_TextureMaskMode)
     258                    defines.Add(str_TEXTURE_MASK_MODE, str_1);
     259               
     260                Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_add, g_Renderer.GetSystemShaderDefines(), defines);
    235261                Call.m_ShaderColorParameter = (*cit)->m_Effects->m_AddColor;
    236262                // Always enable blending if something's being subtracted from
    237263                // the alpha channel
  • source/ps/CStrInternStatic.h

     
    6464X(USE_SHADOW_PCF)
    6565X(USE_SHADOW_SAMPLER)
    6666X(USE_WAVES)
     67X(TEXTURE_MASK_MODE)
    6768X2(_emptystring, "")
    6869X(a_skinJoints)
    6970X(a_skinWeights)