Exemplo n.º 1
0
    def load(self, filename):
        self.nonstop = NonstopParser()
        self.nonstop.load(filename)

        if len(self.nonstop.script_pack) == 0:
            return

        self.bg = get_trial(self.nonstop.script_pack[0].scene_info,
                            show_box=False,
                            show_sprite=False)
        qt_pixmap = QtGui.QPixmap.fromImage(self.bg)
        self.ui.lblPreview.setPixmap(qt_pixmap)

        self.lines = []
        for i in range(len(self.nonstop.lines)):
            if self.nonstop.script_pack[i][
                    common.editor_config.lang_trans] != "":
                text = self.nonstop.script_pack[i][
                    common.editor_config.lang_trans]
            else:
                text = self.nonstop.script_pack[i][
                    common.editor_config.lang_orig]

            format = self.nonstop.script_pack[i].scene_info.format
            text_img = get_text(text, common.SCENE_MODES.debate, format)

            self.lines.append(QtGui.QPixmap.fromImage(text_img))

        self.anims = [None] * len(self.nonstop.lines)
        self.labels = [None] * len(self.nonstop.lines)
        self.timers = [None] * len(self.nonstop.lines)
 def load(self, filename):
   self.nonstop = NonstopParser()
   self.nonstop.load(filename)
   
   if len(self.nonstop.script_pack) == 0:
     return
   
   self.bg = get_trial(self.nonstop.script_pack[0].scene_info, show_box = False, show_sprite = False)
   qt_pixmap = QtGui.QPixmap.fromImage(self.bg)
   self.ui.lblPreview.setPixmap(qt_pixmap)
   
   self.lines = []
   for i in range(len(self.nonstop.lines)):
     if self.nonstop.script_pack[i][common.editor_config.lang_trans] != "":
       text = self.nonstop.script_pack[i][common.editor_config.lang_trans]
     else:
       text = self.nonstop.script_pack[i][common.editor_config.lang_orig]
     
     format = self.nonstop.script_pack[i].scene_info.format
     text_img = get_text(text, common.SCENE_MODES.debate, format)
     
     self.lines.append(QtGui.QPixmap.fromImage(text_img))
   
   self.anims  = [None] * len(self.nonstop.lines)
   self.labels = [None] * len(self.nonstop.lines)
   self.timers = [None] * len(self.nonstop.lines)
def script_to_text(dir, translated = True, strip_clt = False, only_voiced = False, line_numbers = True):
  script_pack = ScriptPack()
  
  if dir[:7] == "nonstop":
    parser = NonstopParser()
    parser.load(dir)
    script_pack = parser.script_pack
  
  elif dir[:8] == "hs_mtb_s":
    parser = MTBParser()
    parser.load(dir)
    script_pack = parser.script_pack
  
  elif dir[:7] == "anagram":
    return u""
  
  else:
    script_pack.load_dir(dir, common.editor_config.umdimage_dir)
  
  # pack = ScriptPack(directory = dir, umdimage = "X:/Danganronpa/Demo_FINAL/umdimage/")
  
  output = []
  
  if len(script_pack) > 0:
  
    output.append("==================================================\n=== %s" % dir)
    room = get_map_name(script_pack[0].scene_info.room)
    if not room == None:
      output.append("\n=== Room: %s" % room)
    output.append("\n==================================================\n\n")
    
    for script in script_pack:
      voice = get_voice_file(script.scene_info.voice)
      if voice == None and only_voiced:
        continue
      
      if script.scene_info.special in [common.SCENE_SPECIAL.checkobj, common.SCENE_SPECIAL.checkchar, common.SCENE_SPECIAL.option, common.SCENE_SPECIAL.showopt]:
        output.append("********************\n\n")
      
      if line_numbers:
        output.append("[%04d.txt]" % script.scene_info.file_id)
        output.append("\n")
      
      output.append("[%s]\n" % (common.CHAR_IDS[script.scene_info.speaker] if script.scene_info.speaker in common.CHAR_IDS else "N/A"))
      
      if not voice == None:
        # output.append("  [Voice: %04d.at3, %s]\n" % (voice, common.CHAR_IDS[script.scene_info.voice.char_id] if script.scene_info.voice.char_id in common.CHAR_IDS else "N/A"))
        output.append("[Voice: %04d.at3" % (voice))
        if script.scene_info.voice.chapter == 0x63:
          output.append(" (Generic)")
        output.append("]\n")
      # output.append("\n")
      
      line = ""
      if translated and script.translated:
        if strip_clt:
          line = script.translated_notags
        else:
          line = script.translated
      
      else:
        if strip_clt:
          line = script.original_notags
        else:
          line = script.original
      
      output.append("  %s" % line.strip().replace("\n", "\n  "))
      output.append("\n\n")
  
  return u''.join(output)
class NonstopPlayer(QtGui.QDialog):
  def __init__(self, parent = None):
    super(NonstopPlayer, self).__init__(parent)
    
    self.ui = Ui_NonstopPlayer()
    self.ui.setupUi(self)
    self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    
    self.lblSprite = QLabel(self.ui.lblPreview)
    self.lblSprite.setGeometry(0, 0, 480, 272)
    
    self.nonstop = None
    
    self.line   = 0
    self.lines  = []
    self.labels = []
    
    self.ui.actionSaveImg = QtGui.QAction("Save image...", None, triggered = self.saveImage)
    self.ui.actionSaveImg.setShortcut("Ctrl+S")
    self.addAction(self.ui.actionSaveImg)
    
    self.voice_player = VoicePlayer()
    self.auto_play    = True
  
  def load(self, filename):
    self.nonstop = NonstopParser()
    self.nonstop.load(filename)
    
    if len(self.nonstop.script_pack) == 0:
      return
    
    self.bg = get_trial(self.nonstop.script_pack[0].scene_info, show_box = False, show_sprite = False)
    qt_pixmap = QtGui.QPixmap.fromImage(self.bg)
    self.ui.lblPreview.setPixmap(qt_pixmap)
    
    self.lines = []
    for i in range(len(self.nonstop.lines)):
      if self.nonstop.script_pack[i][common.editor_config.lang_trans] != "":
        text = self.nonstop.script_pack[i][common.editor_config.lang_trans]
      else:
        text = self.nonstop.script_pack[i][common.editor_config.lang_orig]
      
      format = self.nonstop.script_pack[i].scene_info.format
      text_img = get_text(text, common.SCENE_MODES.debate, format)
      
      self.lines.append(QtGui.QPixmap.fromImage(text_img))
    
    self.anims  = [None] * len(self.nonstop.lines)
    self.labels = [None] * len(self.nonstop.lines)
    self.timers = [None] * len(self.nonstop.lines)
  
  def start(self):
    self.line = 0
    self.show_line(self.line)
  
  def _finished(self, line):
    self.labels[line].deleteLater()
  
  def show_line(self, line, queue_next = True):
    
    scene_info = self.nonstop.script_pack[line].scene_info
    voice  = scene_info.voice
    format = scene_info.format
    sprite_id = scene_info.sprite
    sprite_id.sprite_type = SPRITE_TYPE.stand
    sprite = get_sprite(sprite_id)
    
    if self.auto_play:
      self.voice_player.play(voice)
    
    if sprite:
      qt_pixmap = QtGui.QPixmap.fromImage(sprite)
      self.lblSprite.setPixmap(qt_pixmap)
    
    text_img  = self.lines[line]
    line_info = self.nonstop.lines[line]
    
    matrix = QMatrix()
    matrix.rotate(line_info.rot_angle - (90 if format.orient == TEXT_ORIENT.ver else 0))
    text_img = text_img.transformed(matrix, Qt.Qt.SmoothTransformation)
    
    time_visible = line_info.time_visible / 60.0
    
    width_start  = text_img.width() * line_info.zoom_start / 100.0
    height_start = text_img.height() * line_info.zoom_start / 100.0
    width_end    = width_start * ((line_info.zoom_change / 100.0) ** time_visible)
    height_end   = height_start * ((line_info.zoom_change / 100.0) ** time_visible)
    
    x_start = line_info.x_start - (width_start / 2.0)
    y_start = line_info.y_start - (height_start / 2.0)
    x_vel   = line_info.velocity * math.cos(math.radians(90 - line_info.angle))
    y_vel   = -line_info.velocity * math.sin(math.radians(90 - line_info.angle))
    
    x_end = x_start + (x_vel * time_visible) - ((width_end - width_start) / 2.0)
    y_end = y_start + (y_vel * time_visible) - ((height_end - height_start) / 2.0)
    
    self.labels[line] = QLabel(self.ui.lblPreview)
    self.labels[line].setScaledContents(True)
    self.labels[line].setGeometry(x_start, y_start, text_img.width(), text_img.height())
    self.labels[line].setPixmap(text_img)
    self.labels[line].show()
    
    self.anims[line] = QtCore.QPropertyAnimation(self.labels[line], "geometry")
    self.anims[line].setDuration(time_visible * 1000)
    self.anims[line].setStartValue(QRectF(x_start, y_start, width_start, height_start))
    self.anims[line].setEndValue(QRectF(x_end, y_end, width_end, height_end))
    self.anims[line].finished.connect(lambda: self._finished(line))
    
    self.anims[line].start(QtCore.QAbstractAnimation.DeleteWhenStopped)
    
    if queue_next:
      next_line = line + 1
      if next_line < len(self.lines):
        self.timers[line] = QtCore.QTimer()
        self.timers[line].timeout.connect(lambda: self.show_line(next_line, queue_next = True))
        self.timers[line].setSingleShot(True)
        self.timers[line].start(line_info.delay / 60.0 * 1000)
    
  ##############################################################################
  ### @fn   saveImage()
  ### @desc Saves a preview image. :D
  ##############################################################################
  def saveImage(self):
  
    dir   = "ss"
    index = 0
    
    if not os.path.isdir(dir):
      if os.path.isfile(dir):
        return
      else:
        os.mkdir(dir)
    
    while True:
      if index >= 9999:
        return
        
      filename = os.path.join(dir, ("shot%04d.png" % index))
      
      if not os.path.isfile(filename):
        break
        
      index = index + 1
    
    if not os.path.isdir(dir):
      os.mkdir(dir)
    
    self.lblText.pixmap().save(filename)
def script_to_text(dir, translated = True, strip_clt = False, only_voiced = False, line_numbers = True):
  script_pack = ScriptPack()
  
  if dir[:7] == "nonstop":
    parser = NonstopParser()
    parser.load(dir)
    script_pack = parser.script_pack
  
  elif dir[:8] == "hs_mtb_s":
    parser = MTBParser()
    parser.load(dir)
    script_pack = parser.script_pack
  
  elif dir[:7] == "anagram":
    return u""
  
  else:
    script_pack.load_dir(dir, common.editor_config.data01_dir)
  
  # pack = ScriptPack(directory = dir, umdimage = "X:/Danganronpa/Demo_FINAL/umdimage/")
  
  output = []
  
  if len(script_pack) > 0:
  
    output.append("==================================================\n=== %s" % dir)
    room = get_map_name(script_pack[0].scene_info.room)
    if not room == None:
      output.append("\n=== Room: %s" % room)
    output.append("\n==================================================\n\n")
    
    for script in script_pack:
      voice = get_voice_file(script.scene_info.voice)
      if voice == None and only_voiced:
        continue
      
      if script.scene_info.special in [common.SCENE_SPECIAL.checkobj, common.SCENE_SPECIAL.checkchar, common.SCENE_SPECIAL.option, common.SCENE_SPECIAL.showopt]:
        output.append("********************\n\n")
      
      if line_numbers:
        output.append("[%04d.txt]" % script.scene_info.file_id)
        output.append("\n")
      
      char_name = get_char_name(script.scene_info.speaker)
      output.append("[%s]\n" % (char_name if char_name else "N/A"))
      
      if not voice == None:
        # output.append("  [Voice: %04d.at3, %s]\n" % (voice, common.CHAR_IDS[script.scene_info.voice.char_id] if script.scene_info.voice.char_id in common.CHAR_IDS else "N/A"))
        output.append("[Voice: %04d.at3" % (voice))
        if script.scene_info.voice.chapter == 0x63:
          output.append(" (Generic)")
        output.append("]\n")
      # output.append("\n")
      
      line = ""
      if translated and script[common.editor_config.lang_trans]:
        if strip_clt:
          line = script.notags[common.editor_config.lang_trans]
        else:
          line = script[common.editor_config.lang_trans]
      
      else:
        if strip_clt:
          line = script.notags[common.editor_config.lang_orig]
        else:
          line = script[common.editor_config.lang_orig]
      
      output.append("  %s" % line.strip().replace("\n", "\n  "))
      output.append("\n\n")
  
  return u''.join(output)
Exemplo n.º 6
0
class NonstopPlayer(QtGui.QDialog):
    def __init__(self, parent=None):
        super(NonstopPlayer, self).__init__(parent)

        self.ui = Ui_NonstopPlayer()
        self.ui.setupUi(self)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.lblSprite = QLabel(self.ui.lblPreview)
        self.lblSprite.setGeometry(0, 0, 480, 272)

        self.nonstop = None

        self.line = 0
        self.lines = []
        self.labels = []

        self.ui.actionSaveImg = QtGui.QAction("Save image...",
                                              None,
                                              triggered=self.saveImage)
        self.ui.actionSaveImg.setShortcut("Ctrl+S")
        self.addAction(self.ui.actionSaveImg)

        self.voice_player = VoicePlayer()
        self.auto_play = True

    def load(self, filename):
        self.nonstop = NonstopParser()
        self.nonstop.load(filename)

        if len(self.nonstop.script_pack) == 0:
            return

        self.bg = get_trial(self.nonstop.script_pack[0].scene_info,
                            show_box=False,
                            show_sprite=False)
        qt_pixmap = QtGui.QPixmap.fromImage(self.bg)
        self.ui.lblPreview.setPixmap(qt_pixmap)

        self.lines = []
        for i in range(len(self.nonstop.lines)):
            if self.nonstop.script_pack[i][
                    common.editor_config.lang_trans] != "":
                text = self.nonstop.script_pack[i][
                    common.editor_config.lang_trans]
            else:
                text = self.nonstop.script_pack[i][
                    common.editor_config.lang_orig]

            format = self.nonstop.script_pack[i].scene_info.format
            text_img = get_text(text, common.SCENE_MODES.debate, format)

            self.lines.append(QtGui.QPixmap.fromImage(text_img))

        self.anims = [None] * len(self.nonstop.lines)
        self.labels = [None] * len(self.nonstop.lines)
        self.timers = [None] * len(self.nonstop.lines)

    def start(self):
        self.line = 0
        self.show_line(self.line)

    def _finished(self, line):
        self.labels[line].deleteLater()

    def show_line(self, line, queue_next=True):

        scene_info = self.nonstop.script_pack[line].scene_info
        voice = scene_info.voice
        format = scene_info.format
        sprite_id = scene_info.sprite
        sprite_id.sprite_type = SPRITE_TYPE.stand
        sprite = get_sprite(sprite_id)

        if self.auto_play:
            self.voice_player.play(voice)

        if sprite:
            qt_pixmap = QtGui.QPixmap.fromImage(sprite)
            self.lblSprite.setPixmap(qt_pixmap)

        text_img = self.lines[line]
        line_info = self.nonstop.lines[line]

        matrix = QMatrix()
        matrix.rotate(line_info.rot_angle -
                      (90 if format.orient == TEXT_ORIENT.ver else 0))
        text_img = text_img.transformed(matrix, Qt.Qt.SmoothTransformation)

        time_visible = line_info.time_visible / 60.0

        width_start = text_img.width() * line_info.zoom_start / 100.0
        height_start = text_img.height() * line_info.zoom_start / 100.0
        width_end = width_start * (
            (line_info.zoom_change / 100.0)**time_visible)
        height_end = height_start * (
            (line_info.zoom_change / 100.0)**time_visible)

        x_start = line_info.x_start - (width_start / 2.0)
        y_start = line_info.y_start - (height_start / 2.0)
        x_vel = line_info.velocity * math.cos(
            math.radians(90 - line_info.angle))
        y_vel = -line_info.velocity * math.sin(
            math.radians(90 - line_info.angle))

        x_end = x_start + (x_vel * time_visible) - (
            (width_end - width_start) / 2.0)
        y_end = y_start + (y_vel * time_visible) - (
            (height_end - height_start) / 2.0)

        self.labels[line] = QLabel(self.ui.lblPreview)
        self.labels[line].setScaledContents(True)
        self.labels[line].setGeometry(x_start, y_start, text_img.width(),
                                      text_img.height())
        self.labels[line].setPixmap(text_img)
        self.labels[line].show()

        self.anims[line] = QtCore.QPropertyAnimation(self.labels[line],
                                                     "geometry")
        self.anims[line].setDuration(time_visible * 1000)
        self.anims[line].setStartValue(
            QRectF(x_start, y_start, width_start, height_start))
        self.anims[line].setEndValue(
            QRectF(x_end, y_end, width_end, height_end))
        self.anims[line].finished.connect(lambda: self._finished(line))

        self.anims[line].start(QtCore.QAbstractAnimation.DeleteWhenStopped)

        if queue_next:
            next_line = line + 1
            if next_line < len(self.lines):
                self.timers[line] = QtCore.QTimer()
                self.timers[line].timeout.connect(
                    lambda: self.show_line(next_line, queue_next=True))
                self.timers[line].setSingleShot(True)
                self.timers[line].start(line_info.delay / 60.0 * 1000)

    ##############################################################################
    ### @fn   saveImage()
    ### @desc Saves a preview image. :D
    ##############################################################################
    def saveImage(self):

        dir = "ss"
        index = 0

        if not os.path.isdir(dir):
            if os.path.isfile(dir):
                return
            else:
                os.mkdir(dir)

        while True:
            if index >= 9999:
                return

            filename = os.path.join(dir, ("shot%04d.png" % index))

            if not os.path.isfile(filename):
                break

            index = index + 1

        if not os.path.isdir(dir):
            os.mkdir(dir)

        self.lblText.pixmap().save(filename)