/** * */ package ui; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.javaxyq.core.SpriteFactory; import com.javaxyq.data.ItemInstance; import com.javaxyq.data.WeaponItem; import com.javaxyq.event.ActionEvent; import com.javaxyq.event.PanelEvent; import com.javaxyq.event.PanelHandler; import com.javaxyq.model.ItemTypes; import com.javaxyq.model.PlayerVO; import com.javaxyq.profile.Profile; import com.javaxyq.profile.ProfileException; import com.javaxyq.ui.Label; import com.javaxyq.ui.Panel; import com.javaxyq.ui.TextField; import com.javaxyq.ui.UIHelper; import com.javaxyq.widget.Animation; /** * ��Ϸ���˵� * @author gongdewei * @date 2011-5-2 create */ public class select_role extends PanelHandler implements MouseListener { private int profileIndex; String prefix = "icon_role"; private HashMap<String, String> charNames; private List<Label> profileLabels; private List<Profile> profiles; public void initial(PanelEvent evt) { super.initial(evt); profileIndex = 0; profileLabels = new ArrayList<Label>(6); for(int i=1;i<=6;i++) { Label label = (Label) panel.findCompByName(prefix+i); label.setAnim(null); UIHelper.removeAllMouseListeners(label); label.addMouseListener(this); profileLabels.add(label); } preloadProfiles(); displayProflieInfo(); } public void dispose(PanelEvent evt) { System.out.println("dispose: select_role "); } // public void selectRole(ActionEvent evt) { // try { // profileName = evt.getArgumentAsString(0); // application.loadProfile(profileName); // loaded = true; // } catch (ProfileException e) { // System.err.println("������Ϸ�浵ʧ��!"+profileName); // e.printStackTrace(); // application.getUIHelper().prompt("������Ϸ�浵ʧ��!", 3000); // } // } public void createRole(ActionEvent evt) { Panel dlg = helper.getDialog("create_role"); if(dlg != null) { helper.hideDialog(panel); helper.showDialog(dlg); } } public void goback(ActionEvent evt) { Panel dlg = helper.getDialog("mainmenu"); if(dlg != null) { helper.hideDialog(panel); helper.showDialog(dlg); } } public void gonext(ActionEvent evt) { if(profileIndex>=profiles.size()) { return; } try { Profile profile = profiles.get(profileIndex); String profileName = profile.getName(); application.loadProfile(profileName); application.enterScene(); } catch (ProfileException e) { System.err.println("������Ϸ�浵ʧ��!"); e.printStackTrace(); application.getUIHelper().prompt("������Ϸ�浵ʧ��!", 3000); } } private void preloadProfiles(){ try { profiles = application.getProfileManager().listProfiles(); for (int i = 0; i < profileLabels.size() && i<profiles.size(); i++) { PlayerVO data = profiles.get(i).getPlayerData(); Animation anim = SpriteFactory.loadAnimation("/shape/char/"+data.character+"/stand.tcp"); profileLabels.get(i).setAnim(anim); profileLabels.get(i).setSize(90, 120); //װ������ ItemInstance weaponItem = profiles.get(i).getItems()[2]; if(weaponItem != null) { //weaponItem.getType() //if(ItemTypes.isType(weaponItem.getItem(), ItemTypes.TYPE_WEAPON)){ //TODO װ������ //player.takeupWeapon((WeaponItem) weaponItem.getItem()); //System.out.println("takeup weapon: "+weaponItem.getItem()); //} } } } catch (ProfileException e) { e.printStackTrace(); } } private void displayProflieInfo() { if(profileIndex>=profiles.size()) { return; } Profile profile = profiles.get(profileIndex); PlayerVO data = profile.getPlayerData(); Label label = (Label) panel.findCompByName("role_name"); label.setText(data.getName()); label = (Label) panel.findCompByName("role_level"); label.setText(data.getLevel()+""); label = (Label) panel.findCompByName("role_faction"); label.setText(data.getSchool()); label = (Label) panel.findCompByName("role_appellation"); label.setText(data.getTitle()); label = (Label) panel.findCompByName("role_head"); Animation anim = SpriteFactory.loadAnimation("/wzife/login/photo/selected/"+data.character+".tcp"); if(anim != null) { label.setAnim(anim); } System.out.println("select��"+profile); } private String getCharacterName(String character) { if(charNames == null) { charNames= new HashMap<String, String>(); charNames.put("0001", "��ң��"); charNames.put("0002", "������"); charNames.put("0003", "����Ů"); charNames.put("0004", "ӢŮ��"); charNames.put("0005", "��ħ��"); charNames.put("0006", "��ͷ��"); charNames.put("0007", "������"); charNames.put("0008", "�Ǿ���"); charNames.put("0009", "�����"); charNames.put("0010", "��̫��"); charNames.put("0011", "���켧"); charNames.put("0012", "���ʶ�"); } return charNames.get(character); } @Override public void mouseClicked(MouseEvent e) { if(e.getClickCount() == 2) { gonext(null); }else { Label label = (Label) e.getSource(); String str = label.getName().substring(prefix.length()); profileIndex = Integer.parseInt(str)-1; displayProflieInfo(); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }