Browse Source

Searching!

master
Chris Smith 12 years ago
parent
commit
c70e0e6aa8
4 changed files with 153 additions and 36 deletions
  1. 1
    1
      index.html
  2. 72
    13
      res/js/viewer.js
  3. 71
    13
      res/js/viewer/viewer.js
  4. 9
    9
      res/style.less

+ 1
- 1
index.html View File

@@ -15,7 +15,7 @@
15 15
    <h1><img src="res/images/dd-logo.png" alt="Dungeon Defenders"><span>Layout Editor</span></h1>
16 16
    <div id="buttons">
17 17
     <button id="showinstructions" class="initiallyhidden">Show Instructions</button>
18
-    <button id="search" class="initiallyhidden">Search layouts</button>
18
+    <button id="search">Search layouts</button>
19 19
     <button id="savelayout">Save this layout</button>
20 20
     <button id="createlayout">Create new layout</button>
21 21
    </div>

+ 72
- 13
res/js/viewer.js View File

@@ -196,6 +196,43 @@ $(function() {
196 196
     query.map = level;
197 197
    }
198 198
 
199
+   var difficulty = $('select[name=search_difficulty]').val();
200
+   if (difficulty != 'any') {
201
+    query.difficulty = difficulty;
202
+   }
203
+
204
+   var type = $('select[name=search_type]').val();
205
+   if (type != 'any') {
206
+    query.type = type;
207
+   }
208
+
209
+   query.classes = '';
210
+   $.each($('#search_classes img'), function() {
211
+    if (!$(this).hasClass('disabled')) {
212
+     if (query.classes.length > 0) { query.classes += ','; }
213
+     query.classes += this.id.replace('search_', '');
214
+    }
215
+   });
216
+
217
+   query.mode = '';
218
+   if ($('input[name=search_hc]').is(':checked')) {
219
+    query.mode += ',hardcore';
220
+   }
221
+   if ($('input[name=search_mm]').is(':checked')) {
222
+    query.mode += ',mixed';
223
+   }
224
+   if ($('input[name=search_ps]').is(':checked')) {
225
+    query.mode += ',strategy';
226
+   }
227
+
228
+   if (query.mode.length == 0) {
229
+    delete query.mode;
230
+   } else {
231
+    query.mode = query.mode.substr(1);
232
+   }
233
+
234
+   query.limit = 100;
235
+
199 236
    doSearch(query);
200 237
    return false;
201 238
   }
@@ -214,12 +251,29 @@ $(function() {
214 251
    var body = $('#searchresults tbody');
215 252
    $.each(data, function() {
216 253
     this.difficulty = this.difficulty || 'unknown';
254
+    this.type = (this.type && this.type != 'none') ? this.type : 'unknown';
217 255
 
218 256
     var tr = $('<tr>');
219 257
     tr.append($('<td>').append($('<a>').attr('href', '#' + this.id).text(this.id).click(hideSearch)));
220 258
     tr.append($('<td>').text(levels[this.level - 1] ? levels[this.level - 1].name : 'Unknown!'));
221 259
     tr.append($('<td>').addClass(this.difficulty).text(this.difficulty));
222 260
     tr.append($('<td>').addClass(this.type).text(this.type));
261
+    tr.append($('<td>').html(getModesHTML(this.mode)));
262
+
263
+    var classes = this.classes;
264
+    var td = $('<td>');
265
+    $.each(['huntress', 'apprentice', 'monk', 'squire'], function(k, v) {
266
+     var url = v == 'apprentice' ? 'mage' : v;
267
+     var img = $('<img>').attr('src', 'res/images/classes/' + url + '_icon.png')
268
+                         .attr('alt', v);
269
+     if ($.inArray(v, classes) == -1) {
270
+      img.addClass('disabled');
271
+     }
272
+     td.append(img);
273
+    });
274
+
275
+    tr.append(td);
276
+
223 277
     body.append(tr);
224 278
    });
225 279
   }
@@ -233,6 +287,23 @@ $(function() {
233 287
  var thisLevel;
234 288
  var layout;
235 289
 
290
+ function getModesHTML(modes) {
291
+  var res = '';
292
+  modes && $.each(modes, function() {
293
+   if (this == "hardcore") {
294
+    res = '<abbr title="Hardcore">hc</abbr> ' + res;
295
+   } else if (this == "mixed") {
296
+    res = '<abbr title="Mixed mode">mm</abbr> ' + res;
297
+   } else if (this == "strategy") {
298
+    res = '<abbr title="Pure strategy">ps</abbr> ' + res;
299
+   } else if (this == "none") {
300
+    res = 'none';
301
+   }
302
+  });
303
+
304
+  return res || 'unknown';
305
+ }
306
+
236 307
  function updateDefenseUnits() {
237 308
   var used = 0;
238 309
 
@@ -391,21 +462,9 @@ $(function() {
391 462
   $('#difficulty').text(difficulty).removeClass().addClass(difficulty);
392 463
 
393 464
   var type = layout.type && layout.type != 'none' ? layout.type : "unknown";
394
-  var modes = '';
395
-  layout.mode && $.each(layout.mode, function() {
396
-   if (this == "hardcore") {
397
-    modes = '<abbr title="Hardcore">hc</abbr> ' + modes;
398
-   } else if (this == "mixed") {
399
-    modes = '<abbr title="Mixed mode">mm</abbr> ' + modes;
400
-   } else if (this == "strategy") {
401
-    modes = '<abbr title="Pure strategy">ps</abbr> ' + modes;
402
-   } else if (this == "none") {
403
-    modes = 'none';
404
-   }
405
-  });
406 465
 
407 466
   $('#type').text(type);
408
-  $('#modes').html(modes == '' ? 'unknown' : modes);
467
+  $('#modes').html(getModesHTML(layout.mode));
409 468
 
410 469
   $('#du_total').text(thisLevel.du);
411 470
  }

+ 71
- 13
res/js/viewer/viewer.js View File

@@ -174,6 +174,43 @@ $(function() {
174 174
     query.map = level;
175 175
    }
176 176
 
177
+   var difficulty = $('select[name=search_difficulty]').val();
178
+   if (difficulty != 'any') {
179
+    query.difficulty = difficulty;
180
+   }
181
+
182
+   var type = $('select[name=search_type]').val();
183
+   if (type != 'any') {
184
+    query.type = type;
185
+   }
186
+
187
+   query.classes = '';
188
+   $.each($('#search_classes img'), function() {
189
+    if (!$(this).hasClass('disabled')) {
190
+     if (query.classes.length > 0) { query.classes += ','; }
191
+     query.classes += this.id.replace('search_', '');
192
+    }
193
+   });
194
+
195
+   query.mode = '';
196
+   if ($('input[name=search_hc]').is(':checked')) {
197
+    query.mode += ',hardcore';
198
+   }
199
+   if ($('input[name=search_mm]').is(':checked')) {
200
+    query.mode += ',mixed';
201
+   }
202
+   if ($('input[name=search_ps]').is(':checked')) {
203
+    query.mode += ',strategy';
204
+   }
205
+
206
+   if (query.mode.length == 0) {
207
+    delete query.mode;
208
+   } else {
209
+    query.mode = query.mode.substr(1);
210
+   }
211
+
212
+   query.limit = 100;
213
+
177 214
    doSearch(query);
178 215
    return false;
179 216
   }
@@ -199,6 +236,22 @@ $(function() {
199 236
     tr.append($('<td>').text(levels[this.level - 1] ? levels[this.level - 1].name : 'Unknown!'));
200 237
     tr.append($('<td>').addClass(this.difficulty).text(this.difficulty));
201 238
     tr.append($('<td>').addClass(this.type).text(this.type));
239
+    tr.append($('<td>').html(getModesHTML(this.mode)));
240
+
241
+    var classes = this.classes;
242
+    var td = $('<td>');
243
+    $.each(['huntress', 'apprentice', 'monk', 'squire'], function(k, v) {
244
+     var url = v == 'apprentice' ? 'mage' : v;
245
+     var img = $('<img>').attr('src', 'res/images/classes/' + url + '_icon.png')
246
+                         .attr('alt', v);
247
+     if ($.inArray(v, classes) == -1) {
248
+      img.addClass('disabled');
249
+     }
250
+     td.append(img);
251
+    });
252
+
253
+    tr.append(td);
254
+
202 255
     body.append(tr);
203 256
    });
204 257
   }
@@ -212,6 +265,23 @@ $(function() {
212 265
  var thisLevel;
213 266
  var layout;
214 267
 
268
+ function getModesHTML(modes) {
269
+  var res = '';
270
+  modes && $.each(modes, function() {
271
+   if (this == "hardcore") {
272
+    res = '<abbr title="Hardcore">hc</abbr> ' + res;
273
+   } else if (this == "mixed") {
274
+    res = '<abbr title="Mixed mode">mm</abbr> ' + res;
275
+   } else if (this == "strategy") {
276
+    res = '<abbr title="Pure strategy">ps</abbr> ' + res;
277
+   } else if (this == "none") {
278
+    res = 'none';
279
+   }
280
+  });
281
+
282
+  return res || 'unknown';
283
+ }
284
+
215 285
  function updateDefenseUnits() {
216 286
   var used = 0;
217 287
 
@@ -370,21 +440,9 @@ $(function() {
370 440
   $('#difficulty').text(difficulty).removeClass().addClass(difficulty);
371 441
 
372 442
   var type = layout.type && layout.type != 'none' ? layout.type : "unknown";
373
-  var modes = '';
374
-  layout.mode && $.each(layout.mode, function() {
375
-   if (this == "hardcore") {
376
-    modes = '<abbr title="Hardcore">hc</abbr> ' + modes;
377
-   } else if (this == "mixed") {
378
-    modes = '<abbr title="Mixed mode">mm</abbr> ' + modes;
379
-   } else if (this == "strategy") {
380
-    modes = '<abbr title="Pure strategy">ps</abbr> ' + modes;
381
-   } else if (this == "none") {
382
-    modes = 'none';
383
-   }
384
-  });
385 443
 
386 444
   $('#type').text(type);
387
-  $('#modes').html(modes == '' ? 'unknown' : modes);
445
+  $('#modes').html(getModesHTML(layout.mode));
388 446
 
389 447
   $('#du_total').text(thisLevel.du);
390 448
  }

+ 9
- 9
res/style.less View File

@@ -188,6 +188,15 @@ body .tower.ui-draggable-dragging { z-index: 101; }
188 188
   border-bottom: 1px solid @border-color;
189 189
  }
190 190
 
191
+ img {
192
+  width: 30px;
193
+  height: 30px;
194
+ }
195
+
196
+ img.disabled {
197
+  opacity: 0.3;
198
+ }
199
+
191 200
  #searchterms {
192 201
   width: 300px;
193 202
   float: left;
@@ -200,15 +209,6 @@ body .tower.ui-draggable-dragging { z-index: 101; }
200 209
    clear: left;
201 210
    text-align: left;
202 211
 
203
-   img {
204
-    width: 30px;
205
-    height: 30px;
206
-   }
207
-
208
-   img.disabled {
209
-    opacity: 0.4;
210
-   }
211
-
212 212
    label:first-child {
213 213
     width: 120px;
214 214
     height: 30px;

Loading…
Cancel
Save