appearance dropdown - wow, that was easy

This commit is contained in:
Emi Matchu 2013-01-31 19:46:34 -06:00
parent 5985e234da
commit 7f2ce2839b
9 changed files with 246 additions and 285 deletions

View file

@ -35,6 +35,10 @@ class PetState < ActiveRecord::Base
group("pet_states.id"). group("pet_states.id").
order("(mood_id = 1) DESC, COUNT(effect_assets.remote_id) ASC, COUNT(parents_swf_assets.swf_asset_id) DESC, female ASC, SUM(parents_swf_assets.swf_asset_id) ASC") order("(mood_id = 1) DESC, COUNT(effect_assets.remote_id) ASC, COUNT(parents_swf_assets.swf_asset_id) DESC, female ASC, SUM(parents_swf_assets.swf_asset_id) ASC")
def as_json(options={})
serializable_hash :only => [:id], :methods => [:gender_mood_description]
end
def reassign_children_to!(main_pet_state) def reassign_children_to!(main_pet_state)
self.contributions.each do |contribution| self.contributions.each do |contribution|
contribution.contributed = main_pet_state contribution.contributed = main_pet_state
@ -117,7 +121,9 @@ class PetState < ActiveRecord::Base
end end
def gender_mood_description def gender_mood_description
if labeled? if unconverted?
I18n.translate('pet_states.description.unconverted')
elsif labeled?
I18n.translate('pet_states.description.main', :gender => gender_name, I18n.translate('pet_states.description.main', :gender => gender_name,
:mood => mood_name) :mood => mood_name)
else else

View file

@ -50,7 +50,7 @@ class PetType < ActiveRecord::Base
{ {
:id => id, :id => id,
:body_id => body_id, :body_id => body_id,
:pet_state_ids => pet_state_ids :pet_states => pet_states.emotion_order.as_json
} }
else else
{:image_hash => image_hash} {:image_hash => image_hash}
@ -105,10 +105,6 @@ class PetType < ActiveRecord::Base
pet_state = PetState.from_pet_type_and_biology_info(self, biology) pet_state = PetState.from_pet_type_and_biology_info(self, biology)
pet_state pet_state
end end
def pet_state_ids
pet_states.select('pet_states.id').emotion_order.map(&:id)
end
before_save do before_save do
if @origin_pet && @origin_pet.name =~ IMAGE_CPN_ACCEPTABLE_NAME if @origin_pet && @origin_pet.name =~ IMAGE_CPN_ACCEPTABLE_NAME

View file

@ -55,17 +55,7 @@ body.outfits-edit
#pet-info form #pet-info form
display: inline display: inline
#pet-state-form #pet-state-form
ul font-size: 85%
list-style: none
&, li
display: inline
input
display: none
label
+awesome-button
margin: 0 .25em
li.selected button
+awesome-button-color($marked_button_color)
&.hidden &.hidden
visibility: hidden visibility: hidden
#save-outfit-wrapper #save-outfit-wrapper

View file

@ -9,7 +9,7 @@
%input{:type => "submit", :value => t('.pet_type.form.submit')} %input{:type => "submit", :value => t('.pet_type.form.submit')}
%form#pet-state-form %form#pet-state-form
= t '.pet_state_form.header' = t '.pet_state_form.header'
%ul %select
#save-outfit-wrapper #save-outfit-wrapper
%a#current-outfit-permalink{:target => '_blank'} %a#current-outfit-permalink{:target => '_blank'}
= image_tag 'link_go.png', :alt => t('.outfit.permalink.name'), = image_tag 'link_go.png', :alt => t('.outfit.permalink.name'),

View file

@ -480,7 +480,7 @@ en-MEEP:
form: form:
submit: Meep submit: Meep
pet_state_form: pet_state_form:
header: "Gender/Emeepshuns:" header: "Meepearance:"
outfit: outfit:
permalink: permalink:
name: Permameep name: Permameep
@ -657,6 +657,19 @@ en-MEEP:
clone: Meep a copy clone: Meep a copy
creation_summary_html: Meeped by %{user_link}, %{created_at_ago} ago creation_summary_html: Meeped by %{user_link}, %{created_at_ago} ago
pet_states:
description:
main: "%{gender} %{mood}"
gender:
female: Feepmale
male: Meep
mood:
happy: ":)"
sad: ":("
sick: "X("
unconverted: Unconveeped
unlabeled: Unleeped
pets: pets:
bulk: bulk:
needed_items: needed_items:

View file

@ -511,7 +511,7 @@ en:
form: form:
submit: Go submit: Go
pet_state_form: pet_state_form:
header: "Gender/Emotions:" header: "Appearance:"
outfit: outfit:
permalink: permalink:
name: Permalink name: Permalink
@ -716,6 +716,7 @@ en:
happy: Happy happy: Happy
sad: Sad sad: Sad
sick: Sick sick: Sick
unconverted: Unconverted
unlabeled: Unlabeled unlabeled: Unlabeled
pets: pets:

View file

@ -370,7 +370,7 @@ View.Hash = function (wardrobe) {
singleOutfitResponse('updatePetState', function (pet_state) { singleOutfitResponse('updatePetState', function (pet_state) {
var pet_type = wardrobe.outfits.getPetType(); var pet_type = wardrobe.outfits.getPetType();
if(pet_state.id != data.state && pet_type && (data.state || pet_state.id != pet_type.pet_state_ids[0])) { if(pet_state.id != data.state && pet_type && (data.state || pet_state.id != pet_type.pet_states[0].id)) {
changeQuery({state: pet_state.id}); changeQuery({state: pet_state.id});
} }
}); });
@ -929,37 +929,33 @@ View.Outfits = function (wardrobe) {
View.PetStateForm = function (wardrobe) { View.PetStateForm = function (wardrobe) {
var INPUT_NAME = 'pet_state_id', form_query = '#pet-state-form', var INPUT_NAME = 'pet_state_id', form_query = '#pet-state-form',
form = $(form_query), form = $(form_query),
ul = form.children('ul'), select = form.children('select');
button_query = form_query + ' button';
$(button_query).live('click', function (e) { select.change(function (e) {
e.preventDefault(); var id = parseInt(select.children(':selected').val(), 10);
wardrobe.outfits.setPetStateById(+$(this).data('value')); wardrobe.outfits.setPetStateById(id);
}); });
function updatePetState(pet_state) { function updatePetState(pet_state) {
if(pet_state) { if(pet_state) {
ul.children('li.selected').removeClass('selected'); select.val(pet_state.id);
$(button_query + '[data-value=' + pet_state.id + ']').parent().addClass('selected');
} }
} }
wardrobe.outfits.bind('petTypeLoaded', function (pet_type) { wardrobe.outfits.bind('petTypeLoaded', function (pet_type) {
var ids = pet_type.pet_state_ids, i, id, li, button, label; var pet_states = pet_type.pet_states, i, id, option;
ul.children().remove(); select.children().remove();
if(ids.length == 1) { if(pet_states.length == 1) {
form.addClass('hidden'); form.addClass('hidden');
} else { } else {
form.removeClass('hidden'); form.removeClass('hidden');
for(var i = 0; i < ids.length; i++) { for(var i = 0; i < pet_states.length; i++) {
id = 'pet-state-button-' + i; id = 'pet-state-button-' + i;
li = $('<li/>'); option = $('<option/>', {
button = $('<button/>', { value: pet_states[i].id,
id: id, text: pet_states[i].gender_mood_description
text: i + 1,
"data-value": ids[i]
}); });
button.appendTo(li); option.appendTo(select);
li.appendTo(ul);
} }
updatePetState(wardrobe.outfits.getPetState()); updatePetState(wardrobe.outfits.getPetState());
} }

View file

@ -441,7 +441,7 @@ function Wardrobe() {
this.setPetStateById = function (id, petStateOnLoad) { this.setPetStateById = function (id, petStateOnLoad) {
if(!id && this.pet_type) { if(!id && this.pet_type) {
id = this.pet_type.pet_state_ids[0]; id = this.pet_type.pet_states[0].id;
} }
if(id) { if(id) {
this.pet_state = PetState.find(id); this.pet_state = PetState.find(id);
@ -670,6 +670,7 @@ function Wardrobe() {
var pet_state = this, loaded = false; var pet_state = this, loaded = false;
this.id = id; this.id = id;
this.gender_mood_description = '';
this.assets = []; this.assets = [];
this.loadAssets = function (success) { this.loadAssets = function (success) {
@ -685,6 +686,10 @@ function Wardrobe() {
}); });
} }
} }
this.update = function (data) {
this.gender_mood_description = data.gender_mood_description;
}
PetState.cache[id] = this; PetState.cache[id] = this;
} }
@ -696,6 +701,12 @@ function Wardrobe() {
} }
return pet_state; return pet_state;
} }
PetState.buildOrUpdate = function (data) {
var pet_state = PetState.find(data.id);
pet_state.update(data);
return pet_state;
}
PetState.cache = {}; PetState.cache = {};
@ -713,13 +724,13 @@ function Wardrobe() {
'for': 'wardrobe' 'for': 'wardrobe'
}, function (data) { }, function (data) {
if(data) { if(data) {
for(var key in data) { pet_type.id = data.id;
if(data.hasOwnProperty(key)) { pet_type.body_id = data.body_id;
pet_type[key] = data[key];
} var pet_state;
} for(var i = 0; i < data.pet_states.length; i++) {
for(var i = 0; i < pet_type.pet_state_ids.length; i++) { pet_state = PetState.buildOrUpdate(data.pet_states[i]);
pet_type.pet_states.push(PetState.find(pet_type.pet_state_ids[i])); pet_type.pet_states.push(pet_state);
} }
PetType.cache_by_color_and_species.deepSet( PetType.cache_by_color_and_species.deepSet(
pet_type.color_id, pet_type.color_id,

File diff suppressed because it is too large Load diff