OSDN Git Service

t#31757:add font
[pettanr/pettanr.git] / app / models / speech.rb
index daeec69..c97e019 100644 (file)
@@ -1,13 +1,18 @@
 class Speech < ActiveRecord::Base
   belongs_to :speech_balloon
+  belongs_to :writing_format
   
   validates :speech_balloon_id, :numericality => {:allow_blank => true}
+  validates :writing_format_id, :presence => true, :numericality => true, :existence => {:both => false}
+  validates :font_size, :presence => true, :numericality => {:only_integer => false}
+  validates :text_align, :presence => true, :numericality => true, :inclusion => { :in => 0..3 }
+  validates :fore_color, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000}
   validates :x, :presence => true, :numericality => true
   validates :y, :presence => true, :numericality => true
   validates :width, :presence => true, :numericality => true, :natural_number => true
   validates :height, :presence => true, :numericality => true, :natural_number => true
   validates :quotes, :length => {:maximum => 15}, :quotes_even => true
-#  validates :settings, :presence => true
+  validates :settings, :extend_speech => true
   
   before_validation :valid_encode
   
@@ -35,8 +40,16 @@ class Speech < ActiveRecord::Base
     self.speech_balloon.panel.visible? roles
   end
   
+  def new_speech_balloon
+    @new_speech_balloon
+  end
+  
+  def new_speech_balloon= v
+    @new_speech_balloon = v
+  end
+  
   def get_speech_balloon
-    self.speech_balloon
+    self.speech_balloon || @new_speech_balloon
   end
   
   def get_panel_id
@@ -80,8 +93,12 @@ class Speech < ActiveRecord::Base
     'speech'
   end
   
-  def field_tree f
-    'panels-' + self.tag_panel_id + '-speech_balloons_attributes-' + self.tag_element_id + '-speech_attributes-' + f.to_s
+  def tag_new_index
+    if self.get_speech_balloon == nil
+      nil
+    else
+      self.get_speech_balloon.tag_new_index
+    end
   end
   
   def self.default_page_size
@@ -150,8 +167,12 @@ class Speech < ActiveRecord::Base
     {'speech_attributes' => speech_attributes}
   end
   
+  def writing_format_engine_model
+    self.writing_format.engine_model
+  end
+  
   def scenario
-    ERB::Util.html_escape(self.content)
+    self.writing_format_engine_model.render self.content
   end
   
   def plain_scenario