OSDN Git Service

t#2334:add gc offset
authoryasushiito <yas@pen-chan.jp>
Fri, 1 Nov 2013 22:10:54 +0000 (07:10 +0900)
committeryasushiito <yas@pen-chan.jp>
Fri, 1 Nov 2013 22:10:54 +0000 (07:10 +0900)
12 files changed:
app/assets/javascripts/configurations.js.coffee
app/assets/javascripts/panels.js.coffee
app/helpers/application_helper.rb
app/models/ground_color.rb
app/views/ground_colors/_form.html.erb
app/views/ground_colors/show.html.erb
app/views/panels/_form.html.erb
config/locales/pettanr.ja.yml
config/magic_number.yml
db/migrate/20131029021930_add_offset_on_ground_color.rb [new file with mode: 0644]
spec/factories.rb
spec/models/ground_color_spec.rb

index 091a42a..673c891 100644 (file)
             range: [0, 0xffffff],\r
           }\r
         },\r
+        orientation: {\r
+          type: 'number',\r
+          rules : {\r
+            required: true,\r
+            number: true,\r
+            range: [0, 1],\r
+          }\r
+        },\r
+        xy: {\r
+          type: 'number',\r
+          rules : {\r
+            number: true,\r
+          }\r
+        },\r
+        wh: {\r
+          type: 'number',\r
+          rules : {\r
+            number: true,\r
+          }\r
+        },\r
         z: {\r
           type: 'number',\r
           rules : {\r
             }\r
           },\r
         },\r
+        orientation: {\r
+          column: 'orientation',\r
+          type: 'select',\r
+          label: {\r
+          },\r
+          options: {\r
+            source: 'magic_number',\r
+            key: 'ground_color_orientation_items',\r
+            row_break: true\r
+          }\r
+        },\r
+        xy: {\r
+          column: 'xy',\r
+          type: 'number',\r
+          label: {\r
+          },\r
+          options: {\r
+            size: 5, \r
+          }\r
+        },\r
+        wh: {\r
+          column: 'wh',\r
+          type: 'number',\r
+          label: {\r
+          },\r
+          options: {\r
+            size: 5, \r
+            row_break: true\r
+          }\r
+        },\r
         z: {\r
           column: 'z',\r
           type: 'hidden',\r
         'panel_id',\r
         'caption',\r
         'code',\r
+        'orientation',\r
+        'xy',\r
+        'wh',\r
         'z',\r
         't',\r
       ]\r
index c5466fe..37735c9 100644 (file)
@@ -416,16 +416,24 @@ $ ->
 \r
     \r
     # ground-picture\r
+    refresh_ground_picture = (element_trace)  ->\r
+      x = parseInt($(element_trace + 'x').val()).toString() + 'px'\r
+      y = parseInt($(element_trace + 'y').val()).toString() + 'px'\r
+      $(element_trace).css('background-position', x + ' ' + y)\r
+    \r
     # sync view \r
     $('input').map  ->\r
       if editor.element_is('ground_picture', $(@))\r
-        $(@).focusout ->\r
-          switch $(@).attr('column')\r
-            when 'x', 'y'\r
+        switch $(@).attr('column')\r
+          when 'x', 'y'\r
+            $(@).focusout ->\r
               trace = editor.element_tag_id($(@))\r
-              x = parseInt($(trace + 'x').val()).toString() + 'px'\r
-              y = parseInt($(trace + 'y').val()).toString() + 'px'\r
-              $(trace).css('background-position', x + ' ' + y)\r
+              refresh_ground_picture(trace)\r
+            $(@).spinner {\r
+              stop: ( event, ui ) ->\r
+                trace = editor.element_tag_id($(@))\r
+                refresh_ground_picture(trace)\r
+            }\r
     $('select').map  ->\r
       if editor.element_is('ground_picture', $(@))\r
         $(@).change ->\r
@@ -440,11 +448,65 @@ $ ->
     # ground_color\r
     ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')\r
     \r
+    refresh_ground_color = (element_trace)  ->\r
+      orientation = parseInt( $(element_trace + 'orientation').val() )\r
+      xy = $(element_trace + 'xy').val()\r
+      wh = $(element_trace + 'wh').val()\r
+      div_offset = if xy\r
+        xy\r
+      else\r
+        0\r
+      div_size = if wh\r
+        wh\r
+      else\r
+        100 - div_offset\r
+      div_x = if orientation == 0\r
+        0\r
+      else\r
+        div_offset\r
+      div_y = if orientation == 0\r
+        div_offset\r
+      else\r
+        0\r
+      div_width = if orientation == 0\r
+        100\r
+      else\r
+        div_size\r
+      div_height = if orientation == 0\r
+        div_size\r
+      else\r
+        100\r
+      div = $(element_trace)\r
+      div.css('left', div_x.toString() + '%')\r
+      div.css('top', div_y.toString() + '%')\r
+      div.css('width', div_width.toString() + '%')\r
+      div.css('height', div_height.toString() + '%')\r
+    \r
     # sync view \r
     $('input').map  ->\r
       if editor.element_is('ground_color', $(@))\r
-        if $(@).attr('column') == 'code'\r
-          $(@).hide()\r
+        switch $(@).attr('column')\r
+          when 'code'\r
+            $(@).hide()\r
+          when 'xy', 'wh'\r
+            $(@).spinner {\r
+              stop: ( event, ui ) ->\r
+                trace = editor.element_tag_id($(@))\r
+                refresh_ground_color(trace)\r
+              , min: 0\r
+              , max: 100\r
+            }\r
+            $(@).focusout ->\r
+              trace = editor.element_tag_id($(@))\r
+              refresh_ground_color(trace)\r
+    \r
+    $('select').map  ->\r
+      if editor.element_is('ground_color', $(@))\r
+        switch $(@).attr('column')\r
+          when 'orientation'\r
+            $(@).change ->\r
+              trace = editor.element_tag_id($(@))\r
+              refresh_ground_color(trace)\r
 \r
     update_t = (ultrace) -> \r
       t = 0\r
index 2ad8c17..6fe9e84 100644 (file)
@@ -125,8 +125,7 @@ module ApplicationHelper
                 },
                 "caption": {
                     "type": "text",
-                    "rules": {
-                    }
+                    "rules": {}
                 },
                 "publish": {
                     "type": "number",
@@ -591,6 +590,29 @@ module ApplicationHelper
                         ]
                     }
                 },
+                "orientation": {
+                    "type": "number",
+                    "rules": {
+                        "required": true,
+                        "number": true,
+                        "range": [
+                            0,
+                            1
+                        ]
+                    }
+                },
+                "xy": {
+                    "type": "number",
+                    "rules": {
+                        "number": true
+                    }
+                },
+                "wh": {
+                    "type": "number",
+                    "rules": {
+                        "number": true
+                    }
+                },
                 "z": {
                     "type": "number",
                     "rules": {
@@ -1472,6 +1494,33 @@ module ApplicationHelper
                         }
                     }
                 },
+                "orientation": {
+                    "column": "orientation",
+                    "type": "select",
+                    "label": {},
+                    "options": {
+                        "source": "magic_number",
+                        "key": "ground_color_orientation_items",
+                        "row_break": true
+                    }
+                },
+                "xy": {
+                    "column": "xy",
+                    "type": "number",
+                    "label": {},
+                    "options": {
+                        "size": 5
+                    }
+                },
+                "wh": {
+                    "column": "wh",
+                    "type": "number",
+                    "label": {},
+                    "options": {
+                        "size": 5,
+                        "row_break": true
+                    }
+                },
                 "z": {
                     "column": "z",
                     "type": "hidden",
@@ -1494,6 +1543,9 @@ module ApplicationHelper
                 "panel_id",
                 "caption",
                 "code",
+                "orientation",
+                "xy",
+                "wh",
                 "z",
                 "t"
             ]
index 7f1a3f0..5204a02 100644 (file)
@@ -6,6 +6,9 @@ class GroundColor < ActiveRecord::Base
   
   validates :panel_id, :numericality => {:allow_blank => true}
   validates :code, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000}
+  validates :orientation, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
+  validates :xy, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true}
+  validates :wh, :numericality => {:greater_than_or_equal_to => 0, :allow_blank => true}
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
@@ -71,9 +74,49 @@ class GroundColor < ActiveRecord::Base
     self.panel.visible? roles
   end
   
+  def div_offset
+    xy ? xy : 0
+  end
+  
+  def div_size
+    wh ? wh : 100 - self.div_offset
+  end
+  
+  def div_x
+    if self.orientation == 0
+      0
+    else
+      self.div_offset
+    end
+  end
+  
+  def div_y
+    if self.orientation == 0
+      self.div_offset
+    else
+      0
+    end
+  end
+  
+  def div_width
+    if self.orientation == 0
+      100
+    else
+      self.div_size
+    end
+  end
+  
+  def div_height 
+    if self.orientation == 0
+      self.div_size
+    else
+      100
+    end
+  end
+  
   def opt_div_style spot = nil, opacity = 20
     o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : ''
-    "position: absolute; width:#{self.get_panel.width}px; height:#{self.get_panel.height}px; z-index:#{self.z}; background-color:##{format("%06x", self.code)}; #{o}"
+    "position: absolute; left:#{self.div_x}%; top:#{self.div_y}%; width:#{self.div_width}%; height:#{self.div_height}%; z-index:#{self.z}; background-color:##{format("%06x", self.code)}; #{o}"
   end
   
   def boost
index 3d58ef2..b8aadcf 100644 (file)
   <div class="row_break">
   </div>
   <div class="field">
+    <%= f.label :orientation %>
+    <%= f.collection_select :orientation, t_select_items(MagicNumber['ground_color_orientation_items']), :last, :first, :html => {:selected => elm.orientation} %>
+
+    <%= f.label :xy %>
+    <%= f.number_field :xy, elm.field_tag_attributes(:xy, no_attr, :size => 5) %>
+
+    <%= f.label :wh %>
+    <%= f.number_field :wh, elm.field_tag_attributes(:wh, no_attr, :size => 5) %>
+  </div>
+  <div class="row_break">
+  </div>
+  <div class="field">
     <%= f.label :z %>
     <%= f.number_field :z, elm.field_tag_attributes(:z, no_attr, :size => 5) %>
   </div>
@@ -28,6 +40,8 @@
     <%= f.label :t %>
     <%= f.number_field :t, elm.field_tag_attributes(:t, no_attr, :size => 5) %>
   </div>
+  <div class="row_break">
+  </div>
 
   <%= f.hidden_field :panel_id, elm.field_tag_attributes(:panel_id, no_attr) %>
   <% unless elm.new_record?  %>
index e7fec19..0b9b3d0 100644 (file)
@@ -9,6 +9,21 @@
 </p>
 
 <p>
+  <b><%= t_m 'GroundColor.orientation' -%>:</b>
+  <%= t_selected_item('ground_color_orientation_items', @ground_color.orientation) %>
+</p>
+
+<p>
+  <b><%= t_m 'GroundColor.xy' -%>:</b>
+  <%= @ground_color.xy %>
+</p>
+
+<p>
+  <b><%= t_m 'GroundColor.wh' -%>:</b>
+  <%= @ground_color.wh %>
+</p>
+
+<p>
   <b><%= t_m 'GroundColor.z' -%>:</b>
   <%= @ground_color.z %>
 </p>
index 31e9e58..0045143 100644 (file)
     </div>
   <% end %>
 </div>
-  <%# text_field_tag "json", '', :id => 'pettanr-configurations' %>
+  <%= text_field_tag "json", '', :id => 'pettanr-configurations' %>
index 1a79c17..9fc3344 100644 (file)
@@ -200,6 +200,9 @@ ja:
       ground_color:
         panel_id: コマ
         code: カラーコード
+        orientation: 方向
+        xy: オフセット
+        wh: サイズ
         z: 重なり
         t: 話順
         caption: 様子
@@ -386,6 +389,10 @@ ja:
         repeat-x: 横方向
         repeat-y: 縦方向
         no-repeat: なし
+    ground_color:
+      orientation:
+        horizontal: 横方向
+        vertical: 縦方向
     speeches:
       font_size:
         ultra_small: 極小
index 2e9f9c2..418e7c3 100644 (file)
     ['select_items.ground_pictures.repeat.repeat-y', 2], 
     ['select_items.ground_pictures.repeat.no-repeat', 3]
   ]
+  ground_color_orientation_items: [
+    ['select_items.ground_color.orientation.horizontal', 0], 
+    ['select_items.ground_color.orientation.vertical', 1]
+  ]
   speech_font_size_items: [
     ['select_items.speeches.font_size.ultra_small', 0.2], 
     ['select_items.speeches.font_size.very_small', 0.4], 
diff --git a/db/migrate/20131029021930_add_offset_on_ground_color.rb b/db/migrate/20131029021930_add_offset_on_ground_color.rb
new file mode 100644 (file)
index 0000000..37ef518
--- /dev/null
@@ -0,0 +1,13 @@
+class AddOffsetOnGroundColor < ActiveRecord::Migration
+  def up
+    add_column :ground_colors, :orientation, :integer, :null => false, :default => 0
+    add_column :ground_colors, :xy, :integer
+    add_column :ground_colors, :wh, :integer
+  end
+
+  def down
+    remove_column :ground_colors, :orientation
+    remove_column :ground_colors, :xy
+    remove_column :ground_colors, :wh
+  end
+end
index fd19cfa..1a66ab1 100644 (file)
@@ -233,6 +233,7 @@ FactoryGirl.define do
   factory :ground_color, :class => GroundColor do |gc|
     gc.panel_id 1
     gc.code 1
+    gc.orientation 0
     gc.z 1
   end
 
index 7f0567e..f1020d0 100644 (file)
@@ -29,12 +29,18 @@ describe GroundColor do
     context 'オーソドックスなデータのとき' do
       it '下限データが通る' do
         @gc.code = 0
+        @gc.orientation = 0
+        @gc.xy = 0
+        @gc.wh = 0
         @gc.z = 1
         @gc.t = 0
         @gc.should be_valid
       end
       it '上限データが通る' do
         @gc.code = 99999
+        @gc.orientation = 1
+        @gc.xy = 100
+        @gc.wh = 100
         @gc.z = 99999
         @gc.t = 99999
         @gc.should be_valid
@@ -70,6 +76,52 @@ describe GroundColor do
         @gc.should_not be_valid
       end
     end
+    context 'orientationを検証するとき' do
+      it 'nullなら失敗する' do
+        @gc.orientation = nil
+        @gc.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @gc.orientation = 'a'
+        @gc.should_not be_valid
+      end
+      it '負なら失敗する' do
+        @gc.orientation = -1
+        @gc.should_not be_valid
+      end
+      it '2以上なら失敗する' do
+        @gc.orientation = 2
+        @gc.should_not be_valid
+      end
+    end
+    context 'xyを検証するとき' do
+      it 'nullでも通る' do
+        @gc.xy = nil
+        @gc.should be_valid
+      end
+      it '数値でなければ失敗する' do
+        @gc.xy = 'a'
+        @gc.should_not be_valid
+      end
+      it '負なら失敗する' do
+        @gc.xy = -1
+        @gc.should_not be_valid
+      end
+    end
+    context 'whを検証するとき' do
+      it 'nullでも通る' do
+        @gc.wh = nil
+        @gc.should be_valid
+      end
+      it '数値でなければ失敗する' do
+        @gc.wh = 'a'
+        @gc.should_not be_valid
+      end
+      it '負なら失敗する' do
+        @gc.wh = -1
+        @gc.should_not be_valid
+      end
+    end
     context 'zを検証するとき' do
       it 'nullなら失敗する' do
         @gc.z = nil
@@ -83,7 +135,7 @@ describe GroundColor do
         @gc.z = -1
         @gc.should_not be_valid
       end
-      it 'なら失敗する' do
+      it '0なら失敗する' do
         @gc.z = 0
         @gc.should_not be_valid
       end