From e25230e6f2fe934e47502621cf498640d58f429d Mon Sep 17 00:00:00 2001
From: yasushiito
Date: Sat, 2 Nov 2013 07:10:54 +0900
Subject: [PATCH] t#2334:add gc offset
---
app/assets/javascripts/configurations.js.coffee | 53 +++++++++++++++
app/assets/javascripts/panels.js.coffee | 78 +++++++++++++++++++---
app/helpers/application_helper.rb | 56 +++++++++++++++-
app/models/ground_color.rb | 45 ++++++++++++-
app/views/ground_colors/_form.html.erb | 14 ++++
app/views/ground_colors/show.html.erb | 15 +++++
app/views/panels/_form.html.erb | 2 +-
config/locales/pettanr.ja.yml | 7 ++
config/magic_number.yml | 4 ++
.../20131029021930_add_offset_on_ground_color.rb | 13 ++++
spec/factories.rb | 1 +
spec/models/ground_color_spec.rb | 54 ++++++++++++++-
12 files changed, 329 insertions(+), 13 deletions(-)
create mode 100644 db/migrate/20131029021930_add_offset_on_ground_color.rb
diff --git a/app/assets/javascripts/configurations.js.coffee b/app/assets/javascripts/configurations.js.coffee
index 091a42ac..673c8915 100644
--- a/app/assets/javascripts/configurations.js.coffee
+++ b/app/assets/javascripts/configurations.js.coffee
@@ -501,6 +501,26 @@
range: [0, 0xffffff],
}
},
+ 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 : {
@@ -1445,6 +1465,36 @@
}
},
},
+ 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',
@@ -1469,6 +1519,9 @@
'panel_id',
'caption',
'code',
+ 'orientation',
+ 'xy',
+ 'wh',
'z',
't',
]
diff --git a/app/assets/javascripts/panels.js.coffee b/app/assets/javascripts/panels.js.coffee
index c5466fe5..37735c9d 100644
--- a/app/assets/javascripts/panels.js.coffee
+++ b/app/assets/javascripts/panels.js.coffee
@@ -416,16 +416,24 @@ $ ->
# ground-picture
+ refresh_ground_picture = (element_trace) ->
+ x = parseInt($(element_trace + 'x').val()).toString() + 'px'
+ y = parseInt($(element_trace + 'y').val()).toString() + 'px'
+ $(element_trace).css('background-position', x + ' ' + y)
+
# sync view
$('input').map ->
if editor.element_is('ground_picture', $(@))
- $(@).focusout ->
- switch $(@).attr('column')
- when 'x', 'y'
+ switch $(@).attr('column')
+ when 'x', 'y'
+ $(@).focusout ->
trace = editor.element_tag_id($(@))
- x = parseInt($(trace + 'x').val()).toString() + 'px'
- y = parseInt($(trace + 'y').val()).toString() + 'px'
- $(trace).css('background-position', x + ' ' + y)
+ refresh_ground_picture(trace)
+ $(@).spinner {
+ stop: ( event, ui ) ->
+ trace = editor.element_tag_id($(@))
+ refresh_ground_picture(trace)
+ }
$('select').map ->
if editor.element_is('ground_picture', $(@))
$(@).change ->
@@ -440,11 +448,65 @@ $ ->
# ground_color
ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
+ refresh_ground_color = (element_trace) ->
+ orientation = parseInt( $(element_trace + 'orientation').val() )
+ xy = $(element_trace + 'xy').val()
+ wh = $(element_trace + 'wh').val()
+ div_offset = if xy
+ xy
+ else
+ 0
+ div_size = if wh
+ wh
+ else
+ 100 - div_offset
+ div_x = if orientation == 0
+ 0
+ else
+ div_offset
+ div_y = if orientation == 0
+ div_offset
+ else
+ 0
+ div_width = if orientation == 0
+ 100
+ else
+ div_size
+ div_height = if orientation == 0
+ div_size
+ else
+ 100
+ div = $(element_trace)
+ div.css('left', div_x.toString() + '%')
+ div.css('top', div_y.toString() + '%')
+ div.css('width', div_width.toString() + '%')
+ div.css('height', div_height.toString() + '%')
+
# sync view
$('input').map ->
if editor.element_is('ground_color', $(@))
- if $(@).attr('column') == 'code'
- $(@).hide()
+ switch $(@).attr('column')
+ when 'code'
+ $(@).hide()
+ when 'xy', 'wh'
+ $(@).spinner {
+ stop: ( event, ui ) ->
+ trace = editor.element_tag_id($(@))
+ refresh_ground_color(trace)
+ , min: 0
+ , max: 100
+ }
+ $(@).focusout ->
+ trace = editor.element_tag_id($(@))
+ refresh_ground_color(trace)
+
+ $('select').map ->
+ if editor.element_is('ground_color', $(@))
+ switch $(@).attr('column')
+ when 'orientation'
+ $(@).change ->
+ trace = editor.element_tag_id($(@))
+ refresh_ground_color(trace)
update_t = (ultrace) ->
t = 0
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 2ad8c174..6fe9e84f 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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"
]
diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb
index 7f1a3f06..5204a02c 100644
--- a/app/models/ground_color.rb
+++ b/app/models/ground_color.rb
@@ -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
diff --git a/app/views/ground_colors/_form.html.erb b/app/views/ground_colors/_form.html.erb
index 3d58ef24..b8aadcfe 100644
--- a/app/views/ground_colors/_form.html.erb
+++ b/app/views/ground_colors/_form.html.erb
@@ -19,6 +19,18 @@
+ <%= 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) %>
+
+
+
+
<%= f.label :z %>
<%= f.number_field :z, elm.field_tag_attributes(:z, no_attr, :size => 5) %>
@@ -28,6 +40,8 @@
<%= f.label :t %>
<%= f.number_field :t, elm.field_tag_attributes(:t, no_attr, :size => 5) %>
+
+
<%= f.hidden_field :panel_id, elm.field_tag_attributes(:panel_id, no_attr) %>
<% unless elm.new_record? %>
diff --git a/app/views/ground_colors/show.html.erb b/app/views/ground_colors/show.html.erb
index e7fec197..0b9b3d0e 100644
--- a/app/views/ground_colors/show.html.erb
+++ b/app/views/ground_colors/show.html.erb
@@ -9,6 +9,21 @@
+ <%= t_m 'GroundColor.orientation' -%>:
+ <%= t_selected_item('ground_color_orientation_items', @ground_color.orientation) %>
+
+
+
+ <%= t_m 'GroundColor.xy' -%>:
+ <%= @ground_color.xy %>
+
+
+
+ <%= t_m 'GroundColor.wh' -%>:
+ <%= @ground_color.wh %>
+
+
+
<%= t_m 'GroundColor.z' -%>:
<%= @ground_color.z %>
diff --git a/app/views/panels/_form.html.erb b/app/views/panels/_form.html.erb
index 31e9e581..0045143b 100644
--- a/app/views/panels/_form.html.erb
+++ b/app/views/panels/_form.html.erb
@@ -182,4 +182,4 @@
<% end %>
- <%# text_field_tag "json", '', :id => 'pettanr-configurations' %>
+ <%= text_field_tag "json", '', :id => 'pettanr-configurations' %>
diff --git a/config/locales/pettanr.ja.yml b/config/locales/pettanr.ja.yml
index 1a79c171..9fc33446 100644
--- a/config/locales/pettanr.ja.yml
+++ b/config/locales/pettanr.ja.yml
@@ -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: 極å°
diff --git a/config/magic_number.yml b/config/magic_number.yml
index 2e9f9c27..418e7c33 100644
--- a/config/magic_number.yml
+++ b/config/magic_number.yml
@@ -32,6 +32,10 @@
['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
index 00000000..37ef5184
--- /dev/null
+++ b/db/migrate/20131029021930_add_offset_on_ground_color.rb
@@ -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
diff --git a/spec/factories.rb b/spec/factories.rb
index fd19cfa9..1a66ab11 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -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
diff --git a/spec/models/ground_color_spec.rb b/spec/models/ground_color_spec.rb
index 7f0567e1..f1020d04 100644
--- a/spec/models/ground_color_spec.rb
+++ b/spec/models/ground_color_spec.rb
@@ -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
--
2.11.0