Advertisement
boogalooper

Untitled

Feb 5th, 2021
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #target photoshop
  2.  
  3. f = $.os.indexOf('Windows') != -1 ? new File(app.path + '/Required/UIColors.txt') : new File(app.path.getFiles('*.app')[0] + '/Contents/Required/UIColors.txt')
  4. if (!f.exists) f = File.openDialog('Select your UIColors.txt', '*.txt,*.cel', false)
  5. if (f) {
  6.   var s = '('
  7.   f.open('r')
  8.   while (!f.eof) { s += f.readln() }
  9.   f.close()
  10.   s = s.replace(/00\./g, '0.') + ')'
  11.   var isHex = s.indexOf('0x') != -1 ? true : false
  12.   try { var obj = eval(s) } catch (e) { alert(e, decodeURI(f.name), true) }
  13.  
  14.   if (obj) {
  15.     if (isHex) HexColor(obj)
  16.  
  17.     var w = new Window('dialog', 'UIColors'),
  18.       gt = w.add('group {alignment : ["fill", "center"], alignChildren : ["left", "fill"]}'),
  19.       st = gt.add('statictext {text : "filter:"}'),
  20.       e = gt.add('edittext {preferredSize: [310,-1]}'),
  21.       gc = w.add('group'),
  22.       p = gc.add('panel {maximumSize: [355, 400], minimumSize: [355, 400]}'),
  23.       s = gc.add('scrollbar {stepdelta: 100}', [0, 0, 20, 400]),
  24.       g = p.add('group{orientation : "column"}'),
  25.       gh = w.add('group {alignment : ["fill", "center"], alignChildren : ["left", "fill"], orientation : "row"}'),
  26.       c = gh.add('checkbox', [0,0,200,20], 'one element color for all themes'),
  27.       r = gh.add('button', [0,0,145,20], 'random colors'),
  28.       b = w.add('button', undefined, 'Save UIColors.txt', { name: 'ok' });
  29.  
  30.     w.filter = null
  31.     w.changeAll = false
  32.  
  33.     e.onChanging = function () {
  34.       w.filter = this.text.toUpperCase()
  35.       for (var i = g.children.length - 1; i >= 0; i--) { g.remove(g.children[0]) }
  36.       loadLabels()
  37.     }
  38.  
  39.     s.onChanging = function () { g.location.y = -100 * this.value }
  40.     c.onClick = function () { w.changeAll = this.value }
  41.  
  42.     r.onClick = function () {
  43.       for (a in obj.Colors) {
  44.         if (a.toUpperCase().indexOf(w.filter) != -1 || !w.filter) {
  45.           var rnd = [Math.random(), Math.random(), Math.random()]
  46.           for (var i = 0; i < 4; i++) {
  47.             for (var x = 0; x < 3; x++) {
  48.               obj.Colors[a][i][x] = w.changeAll ? rnd[x] * 255 : Math.random() * 255
  49.             }
  50.           }
  51.         }
  52.       }
  53.       w.layout.layout(true)
  54.     }
  55.  
  56.     b.onClick = function () {
  57.       var ext = isHex ? 'cel' : 'txt',
  58.         n = f.saveDlg('Save file', '*.' + ext);
  59.       if (n) {
  60.         if (n.exists) {
  61.           var b = new File(n.path + '/UIColors.bak')
  62.           if (!b.exists) n.copy(b)
  63.         }
  64.         if (n.open('w')) {
  65.           w.close()
  66.           if (isHex) HexColor(obj, true)
  67.           var s = obj.toSource()
  68.           n.write(s.substr(1, s.length - 2))
  69.           n.close()
  70.         } else { alert(decodeURI(n) + '\nFile access error\nMake sure you have the required access rights') }
  71.       }
  72.     }
  73.  
  74.     w.onShow = function () {
  75.       loadLabels()
  76.     }
  77.  
  78.     w.show()
  79.  
  80.     function loadLabels() {
  81.       for (a in obj.Colors) {
  82.         if (a.toUpperCase().indexOf(w.filter) != -1 || !w.filter) {
  83.           colorGroup(g, a, [obj.Colors[a][0], obj.Colors[a][1], obj.Colors[a][2], obj.Colors[a][3]])
  84.         }
  85.       }
  86.       w.layout.layout(true)
  87.       s.value = s.minvalue = 0
  88.       s.maxvalue = (g.size.height - p.size.height + 15) / 100
  89.     }
  90.  
  91.     function colorGroup(parent, cpt, col) {
  92.       var g = parent.add('group{orientation : "row", alignChildren : ["left", "center"]}'),
  93.         s = g.add('statictext', undefined, cpt);
  94.       s.preferredSize.width = 200
  95.  
  96.       for (var i = 0; i < 4; i++) { addColor(g, col[i], cpt, i) }
  97.  
  98.       function addColor(parent, col, cpt, idx) {
  99.         var img = parent.add('image {preferredSize : [20,20]}')
  100.  
  101.         img.onDraw = function () {
  102.           var g = this.graphics
  103.           g.ellipsePath(2, 2, 15, 15)
  104.           g.fillPath(g.newBrush(g.BrushType.SOLID_COLOR, [col[0] / 255, col[1] / 255, col[2] / 255, col[3]]))
  105.           g.strokePath(g.newPen(g.PenType.SOLID_COLOR, [0, 0, 0], 2))
  106.         }
  107.  
  108.         img.onClick = function () {
  109.           var a = new SolidColor
  110.           a.rgb.red = col[0]
  111.           a.rgb.green = col[1]
  112.           a.rgb.blue = col[2]
  113.           app.foregroundColor = a
  114.           if (app.showColorPicker()) {
  115.             var a = app.foregroundColor,
  116.               from = w.changeAll ? 0 : idx,
  117.               to = w.changeAll ? 3 : idx;
  118.             for (var i = from; i <= to; i++) {
  119.               obj.Colors[cpt][i][0] = col[0] = a.rgb.red
  120.               obj.Colors[cpt][i][1] = col[1] = a.rgb.green
  121.               obj.Colors[cpt][i][2] = col[2] = a.rgb.blue
  122.               parent.visible = false
  123.               parent.visible = true
  124.             }
  125.           }
  126.         }
  127.       }
  128.     }
  129.  
  130.     function HexColor(obj, backwardMode) {
  131.       for (a in obj.Colors) {
  132.         for (var i = 0; i < 4; i++) {
  133.           for (var x = 0; x < 3; x++) {
  134.             obj.Colors[a][i][x] = backwardMode ? '0x' + ((obj.Colors[a][i][x] / 255 * 65535) + Math.pow(16, 4)).toString(16).substr(-4) : obj.Colors[a][i][x] / 65535 * 255
  135.           }
  136.         }
  137.       }
  138.     }
  139.   }
  140. } else { alert(decodeURI(f.name) + ' format is wrong!') }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement