Advertisement
Guest User

GDT Multi-Topic Base

a guest
Aug 14th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var MT = {};
  2. (function () {
  3.     function addMultiTopic() { 
  4.         var Game = function (company) {
  5.             this.secondTopic;
  6.         }
  7.                
  8.         var getSelectedSecondTopic = function () {
  9.             var modalContent = $(".simplemodal-data");
  10.             var topicName = modalContent.find(".pickSecondTopicButton").text();
  11.             var topic = GameManager.company.topics.first(function (t) {
  12.                     return t.name == topicName
  13.                 });
  14.             return topic
  15.         };
  16.        
  17.         /* Add Button To Game Definition Screen */
  18.         var keepme = UI.showGameDefinition;
  19.         UI.showGameDefinition = function (company, options) {
  20.             keepme(company, options);
  21.            
  22.             var game = company.currentGame;
  23.             $(".selectionOverlayContainer").hide();
  24.             var content = $(".gameDefinitionContent");
  25.             var template = $("#gameDefinitionContentTemplate").clone();
  26.             var t = content.find('.centeredButtonWrapper').find('.pickTopicButton');
  27.             var q = t.parent();
  28.             template.find("#gameTitle").attr("value", company.currentGame.title);
  29.             originalName = company.currentGame.title;
  30.            
  31.             q.append('<div class="selectorButton windowStepActionButton selectorButtonEmpty pickSecondTopicButton" style="display: inline-block;"> Pick Topic </div>');
  32.            
  33.             content.find(".pickSecondTopicButton").css("margin-left", "2.5px").css("margin-right", "2.5px").css("width", "145px");
  34.             content.find(".pickTopicButton").css("margin-left", "2.5px").css("margin-right", "2.5px").css("width", "145px");
  35.             var a = content.find(".pickSecondTopicButton");
  36.             UI.maxFont(void 0, a, 18);
  37.            
  38.             content.find(".pickSecondTopicButton").clickExcl(function () {
  39.                 UI.pickSecondTopicClick()
  40.             });
  41.         }
  42.         /*  */
  43.        
  44.         /* Select Topic For Second Topic */
  45.         UI.pickTopicClick = function (element) {
  46.             Sound.click();
  47.             var isResearch = element === "research";
  48.             if (!isResearch) {
  49.                 var game =
  50.                     GameManager.company.currentGame;
  51.                 if (game && (game.flags.lockedSettings && game.flags.lockedSettings.topic)) {
  52.                     var container = $(".simplemodal-data").find(".pickTopicButton").parent(".centeredButtonWrapper");
  53.                     container.effect("shake", {
  54.                         times : 2,
  55.                         distance : 5
  56.                     }, 50);
  57.                     return
  58.                 }
  59.             }
  60.             if (!isResearch && element) {
  61.                 UI._selectTopic(element.innerText);
  62.                 return
  63.             }
  64.             PlatformShim.execUnsafeLocalFunction(function () {
  65.                 var modal = $(".simplemodal-data");
  66.                 modal.find(".overlayTitle").text("Pick Topic".localize("heading"));
  67.                 var container = modal.find(".listContainer");
  68.                 container.empty();
  69.                 var activeTopictemplate = '<div class="selectorButton whiteButton" onclick="UI.pickTopicClick(this)">{{name}}</div>';
  70.                 var lockedTopicTemplate = '<div class="selectorButton disabledButton">{{name}}</div>';
  71.                 var itemsPerRow = 3;
  72.                 var currentCount = 0;
  73.                 var row = 0;
  74.                 var researchVisibleCount = 0;
  75.                 var topics = General.getTopicOrder(GameManager.company);
  76.                 if(GameManager.company.currentgame != null)
  77.                     var second = modal.find(".pickSecondTopicButton").get(0).innerText;
  78.                
  79.                 if (UI.pickTopicFontSize == undefined) {
  80.                     var values = [];
  81.                     for (var i = 0; i < topics.length; i++) {
  82.                         if (second == topics[i].name)
  83.                             continue;
  84.                         values.push(topics[i].name);
  85.                     }
  86.                     //UI.pickTopicFontSize = UI._getMaxFontSize("{0}pt {1}",
  87.                             //UI.IS_SEGOE_UI_INSTALLED ? "Segoe UI" : "Open Sans", 16, 10, 175, values)
  88.                 }
  89.                 for (var i = 0; i < topics.length; i++) {
  90.                     var topic = topics[i];
  91.                     currentCount++;
  92.                     if (currentCount > itemsPerRow) {
  93.                         row++;
  94.                         currentCount = 1
  95.                     }
  96.                     var isAvailable = GameManager.company.topics.indexOf(topic) != -1;
  97.                     var isInResearch = GameManager.currentResearches.filter(function (f) {
  98.                             return f.topicId === topic.id
  99.                         }).length > 0;
  100.                     var isEnabled = isResearch ? !isAvailable && (!isInResearch && researchVisibleCount < Research.TOPICS_VISIBLE) : isAvailable;
  101.                     var template = isEnabled ? activeTopictemplate :
  102.                         lockedTopicTemplate;
  103.                     var isNameHidden = isResearch && (!isEnabled && (!isAvailable && !isInResearch)) || !isResearch && !isEnabled;
  104.                     if (!isNameHidden)
  105.                         if (GameManager.areHintsEnabled() && Knowledge.hasTopicAudienceWeightingKnowledge(GameManager.company, topic)) {
  106.                             var enabledDisabledContent = !isEnabled ? " disabledButton" : '" onclick="UI.pickTopicClick(this)';
  107.                             var whiteButton = !isEnabled ? " " : " whiteButton ";
  108.                             var t = '<div class="selectorButton' + whiteButton + "pickTopicButtonAudienceHintVisible" + enabledDisabledContent + '"><span style="position:relative;top:5px;">{0}<span style="font-size:11pt;"><br/>{1}</span></span></div>';
  109.                             template = t.format(topic.name, Knowledge.getTopicAudienceHtml(GameManager.company, topic))
  110.                         } else
  111.                             template = template.replace("{{name}}", topic.name);
  112.                     else
  113.                         template = template.replace("{{name}}", "?");
  114.                     var element = $(template);
  115.                     element.css("position", "absolute");
  116.                     element.css("top", 50 * row + row * 10);
  117.                     element.css("left", (currentCount - 1) * 190 + 10);
  118.                     element.css("font-size", UI.pickTopicFontSize + "pt");
  119.                     container.append(element);
  120.                     if (isResearch && (!isAvailable && !isInResearch))
  121.                         researchVisibleCount++
  122.                 }
  123.                 modal.find(".selectionOverlayContainer").fadeIn("fast")
  124.             })
  125.         };
  126.        
  127.         UI._selectTopic = function (name, topicNr) {
  128.             var pickTopicButton = topicNr == 2 ? $(".simplemodal-data").find(".pickSecondTopicButton") : $(".simplemodal-data").find(".pickTopicButton");
  129.             var current = pickTopicButton.get(0).innerText;
  130.             var names = name.split("\n");
  131.             if (names == current) {
  132.                 pickTopicButton.text("Pick Genre".localize());
  133.                 pickTopicButton.addClass("selectorButtonEmpty");
  134.             } else {
  135.                 pickTopicButton.text(names);
  136.                 pickTopicButton.removeClass("selectorButtonEmpty");
  137.             }
  138.             pickTopicButton.get(0).innerText = names[0];
  139.             var game = GameManager.company.currentGame;
  140.             var topic = Topics.topics.first(function (i) {
  141.                 return i.name == name;
  142.             });
  143.             if (topicNr != 2) {
  144.                 if(GameManager.company.currentgame != null) {
  145.                     game.topic = topic;
  146.                 } else {
  147.                     pickTopicButton.get(0).innerText = names[0];
  148.                     pickTopicButton.removeClass("selectorButtonEmpty");
  149.                 }
  150.                 if(GameManager.company.currentgame != null)
  151.                     if (game.topic)
  152.                         $(".simplemodal-data").find("#pickSecondGenreButton").removeClass("selectorButtonInactive windowStepActionInactive").addClass("selectorButton windowStepActionButton");
  153.             } else
  154.                 game.secondTopic = topic;
  155.            
  156.             $(".simplemodal-data").find(".selectionOverlayContainer").fadeOut("fast");
  157.             UI._updateGameDefinitionNextButtonEnabled()
  158.         };
  159.        
  160.         UI.pickSecondTopicClick = function (element) {
  161.             Sound.click();
  162.             var isResearch = element === "research";
  163.             if (!isResearch) {
  164.                 var game =
  165.                     GameManager.company.currentGame;
  166.                 if (game && (game.flags.lockedSettings && game.flags.lockedSettings.secondTopic)) {
  167.                     var container = $(".simplemodal-data").find(".pickSecondTopicButton").parent(".centeredButtonWrapper");
  168.                     container.effect("shake", {
  169.                         times : 2,
  170.                         distance : 5
  171.                     }, 50);
  172.                     return
  173.                 }
  174.             }
  175.             if (!isResearch && element) {
  176.                 UI._selectTopic(element.innerText, 2);
  177.                 return
  178.             }
  179.             PlatformShim.execUnsafeLocalFunction(function () {
  180.                 var modal = $(".simplemodal-data");
  181.                 modal.find(".overlayTitle").text("Pick Topic".localize("heading"));
  182.                 var container = modal.find(".listContainer");
  183.                 container.empty();
  184.                 var activeTopictemplate = '<div class="selectorButton whiteButton" onclick="UI.pickSecondTopicClick(this)">{{name}}</div>';
  185.                 var lockedTopicTemplate = '<div class="selectorButton disabledButton">{{name}}</div>';
  186.                 var itemsPerRow = 3;
  187.                 var currentCount = 0;
  188.                 var row = 0;
  189.                 var researchVisibleCount = 0;
  190.                 var topics = General.getTopicOrder(GameManager.company);
  191.                 var first = modal.find(".pickTopicButton").get(0).innerText;
  192.                 if (UI.pickSecondTopicFontSize == undefined) {
  193.                     var values = [];
  194.                     for (var i = 0; i < topics.length; i++) {
  195.                         if (first == topics[i].name)
  196.                             continue;
  197.                         values.push(topics[i].name);
  198.                     }
  199.                     //UI.pickSecondTopicFontSize = UI._getMaxFontSize("{0}pt {1}",
  200.                             //UI.IS_SEGOE_UI_INSTALLED ? "Segoe UI" : "Open Sans", 16, 10, 175, values)
  201.                 }
  202.                 for (var i = 0; i < topics.length; i++) {
  203.                     var topic = topics[i];
  204.                     currentCount++;
  205.                     if (currentCount > itemsPerRow) {
  206.                         row++;
  207.                         currentCount = 1
  208.                     }
  209.                     var isAvailable = GameManager.company.topics.indexOf(topic) != -1;
  210.                     var isInResearch = GameManager.currentResearches.filter(function (f) {
  211.                             return f.topicId === topic.id
  212.                         }).length > 0;
  213.                     var isEnabled = isResearch ? !isAvailable && (!isInResearch && researchVisibleCount < Research.TOPICS_VISIBLE) : isAvailable;
  214.                     var template = isEnabled ? activeTopictemplate :
  215.                         lockedTopicTemplate;
  216.                     var isNameHidden = isResearch && (!isEnabled && (!isAvailable && !isInResearch)) || !isResearch && !isEnabled;
  217.                     if (!isNameHidden)
  218.                         if (GameManager.areHintsEnabled() && Knowledge.hasTopicAudienceWeightingKnowledge(GameManager.company, topic)) {
  219.                             var enabledDisabledContent = !isEnabled ? " disabledButton" : '" onclick="UI.pickSecondTopicClick(this)';
  220.                             var whiteButton = !isEnabled ? " " : " whiteButton ";
  221.                             var t = '<div class="selectorButton' + whiteButton + "pickTopicButtonAudienceHintVisible" + enabledDisabledContent + '"><span style="position:relative;top:5px;">{0}<span style="font-size:11pt;"><br/>{1}</span></span></div>';
  222.                             template = t.format(topic.name, Knowledge.getTopicAudienceHtml(GameManager.company, topic))
  223.                         } else
  224.                             template = template.replace("{{name}}", topic.name);
  225.                     else
  226.                         template = template.replace("{{name}}", "?");
  227.                     var element = $(template);
  228.                     element.css("position", "absolute");
  229.                     element.css("top", 50 * row + row * 10);
  230.                     element.css("left", (currentCount - 1) * 190 + 10);
  231.                     element.css("font-size", UI.pickSecondTopicFontSize + "pt");
  232.                     container.append(element);
  233.                     if (isResearch && (!isAvailable && !isInResearch))
  234.                         researchVisibleCount++
  235.                 }
  236.                 modal.find(".selectionOverlayContainer").fadeIn("fast")
  237.             })
  238.         };
  239.         /*  */
  240.        
  241.         /* Update Game History */
  242.         var GameDetail = UI._getElementForGameDetail;
  243.         UI._getElementForGameDetail = function (game, avgReview) {
  244.             var d = GameDetail(game, avgReview);
  245.             if (game.secondTopic)
  246.                 d.find(".gameDetailsTopicGenre").text(game.topic.name + "-" + game.secondTopic.name + "/" + game.genre.name);
  247.             else if (game.secondGenre)
  248.                 d.find(".gameDetailsTopicGenre").text(game.topic.name + "/" + game.genre.name + "-" + game.secondGenre.name);
  249.             else if (game.secondToipc && game.secondGenre)
  250.                 d.find(".gameDetailsTopicGenre").text(game.topic.name + "-" + game.secondTopic.name + "/" + game.genre.name + "-" + game.secondGenre.name);
  251.             else
  252.                 d.find(".gameDetailsTopicGenre").text(game.topic.name + "/" + game.genre.name);
  253.             return d;
  254.         };
  255.         /*  */
  256.        
  257.         /* Save/Load Second Topic */
  258.         Game.prototype.getSecondTopicDisplayName = function () {
  259.             if (!this.secondTopic)
  260.                 return this.topic.name;
  261.             return this.topic.name + "-" + this.secondTopic.name
  262.         };
  263.        
  264.         var save = Game.prototype.save;
  265.         Game.prototype.save = function () {
  266.             var data = {};
  267.             if(this.secondTopic)
  268.                 data["secondTopic"] = this.secondTopic.id;
  269.                
  270.             save;
  271.         }
  272.        
  273.         var load = Game.load;
  274.         Game.load = function (data, company) {
  275.             load(data, company);
  276.             if (data["secondTopic"] != undefined)
  277.                 game.secondTopic = Topics.topics.first(function (item) {
  278.                         return item.id === data["secondTopic"]
  279.                     });
  280.         }      
  281.         /*  */
  282.        
  283.     } addMultiTopic();
  284. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement