Advertisement
jerry2810

HistoryBook

Mar 11th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var COLD = COLD || {};
  2.  
  3. (function(){
  4.  
  5.     COLD.BOOKS = {
  6.        
  7.         Book_Window : function(){this.initialize.apply(this, arguments);},
  8.        
  9.         Book_Scene  : function(){this.initialize.apply(this, arguments);},
  10.        
  11.         Books       : {
  12.             DragonHistory:{
  13.                 title: 'History of Dragons',
  14.                 page1: 'This is page 1.',
  15.                 page2: 'This is page 2.'
  16.    
  17.             },
  18.            
  19.             ElfHistory:{
  20.                 title: 'History of Elfs',
  21.                 page1: '<wrap> Oh haaai... Latin text Qui '+
  22.                 'id vide molestie, graeco evertitur conceptam at est. Te'+
  23.                 'vis erant convenire, wisividisse expetendis mea ex, eos in dicant graeco.' +
  24.                 'Eum eu novum decore, ei qui mundi labitur inciderint, eam ne partem nullam. Eam '+
  25.                 'mutat aeque fabulas in. Quisconsequat cu est, soluta iriure no cum, ad pro feu'+
  26.                 'giat perpetua. Id mel wisi ridensreprimique, no has adhuc affert.',
  27.                 page2: 'This is page 2.'
  28.    
  29.             }
  30.         },
  31.  
  32.         PageOptionsText : {
  33.             changePageText : "Change page with Left/Right buttons.",
  34.             pageNumberText : "Page: "
  35.         }
  36.        
  37.     };
  38.  
  39. })();
  40.  
  41. (function($){
  42.  
  43.     ($.prototype = Object.create(Window_Base.prototype)).constructor = $;
  44.  
  45.     $.prototype.initialize = function(x, y, bookname) {
  46.         var width = this.windowWidth();
  47.         var height = this.windowHeight();
  48.         this._book = COLD.BOOKS.Books[bookname];
  49.         this.page = 1; 
  50.         this.lastPage = 0;
  51.         this.maxPages = Object.keys(this._book).length-1;
  52.         Window_Base.prototype.initialize.call(this, x, y, width, height);
  53.     };
  54.  
  55.     $.prototype.windowWidth = function(){
  56.         return Graphics.width;
  57.     };
  58.  
  59.     $.prototype.windowHeight = function(){
  60.         return Graphics.height;
  61.     };
  62.    
  63.     $.prototype.refresh = function() {
  64.         if(this.page != this.lastPage){
  65.             this.contents.clear();
  66.             this.drawBookTitle();
  67.             this.drawPageContents();
  68.             this.drawBookBottom();
  69.             this.lastPage = this.page;
  70.         };
  71.     };
  72.    
  73.     $.prototype.drawBookTitle = function(){
  74.         this.drawText(this._book.title,0,0,this.windowWidth()-2 * this.standardPadding(),'center');
  75.         this.drawHorzLine(this.lineHeight());
  76.     };
  77.    
  78.     $.prototype.drawPageContents = function(){
  79.         var page = 'page' + this.page;
  80.         this.drawTextEx(this._book[page],0,this.lineHeight()+2*this.standardPadding())
  81.     };
  82.    
  83.     $.prototype.drawBookBottom = function(){
  84.         this.makeFontSmaller();
  85.         var pad = 2 * this.standardPadding();
  86.         this.drawText(COLD.BOOKS.PageOptionsText.changePageText,0,this.windowHeight()-this.lineHeight()- pad,this.windowWidth()-pad,'left');
  87.         this.drawText(COLD.BOOKS.PageOptionsText.pageNumberText + this.page +'/'+ this.maxPages,0,this.windowHeight()-this.lineHeight()- pad,this.windowWidth()-pad,'right');
  88.         this.drawHorzLine(this.windowHeight()-3 * this.lineHeight());
  89.         this.makeFontBigger();
  90.     };
  91.    
  92.     $.prototype.drawHorzLine = function(y) {
  93.         var lineY = y + this.lineHeight() / 2 - 1;
  94.         this.contents.paintOpacity = 48;
  95.         this.contents.fillRect(0, lineY, this.contentsWidth(), 2, this.normalColor());
  96.         this.contents.paintOpacity = 255;
  97.     };
  98.    
  99.     $.prototype.update = function(){
  100.         if(Input.isTriggered('right') && this.page < this.maxPages){
  101.             this.page += 1;
  102.         };
  103.         if(Input.isTriggered('left') && this.page != 1){
  104.             this.page -= 1;
  105.         };
  106.         this.refresh();
  107.     };
  108.  
  109. })(COLD.BOOKS.Book_Window);
  110.  
  111. (function($){
  112.  
  113.     ($.prototype = Object.create(Scene_MenuBase.prototype)).constructor = $;
  114.  
  115.     $.prototype.initialize = function() {
  116.         Scene_MenuBase.prototype.initialize.call(this);
  117.     };
  118.    
  119.     $.prototype.create = function() {
  120.         Scene_MenuBase.prototype.create.call(this);
  121.         this.createWindow();
  122.     };
  123.    
  124.     $.prototype.prepare = function(bookname){
  125.         this._bookName = bookname;
  126.     };
  127.    
  128.     $.prototype.createWindow = function() {
  129.         this._BookWindow = new COLD.BOOKS.Book_Window(0,0, this._bookName);
  130.         this.addWindow(this._BookWindow);
  131.     };
  132.    
  133. })(COLD.BOOKS.Book_Scene);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement