From: <aki...@us...> - 2007-01-07 13:24:46
|
Revision: 1493 http://svn.sourceforge.net/gridarta/?rev=1493&view=rev Author: akirschbaum Date: 2007-01-07 05:24:47 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Fix #1621873 (Analyze menus misrender on multi-tile objects). Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/filter/AttributeFilter.java trunk/crossfire/src/cfeditor/filter/NamedFilterList.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2007-01-07 13:02:29 UTC (rev 1492) +++ trunk/crossfire/ChangeLog 2007-01-07 13:24:47 UTC (rev 1493) @@ -1,5 +1,7 @@ 2007-01-07 Andreas Kirschbaum + * Fix #1621873 (Analyze menus misrender on multi-tile objects). + * Fix #1613729 (Monsters appear as "weak wall (0)"). (Previous fix did miss the game object attributes panel.) Modified: trunk/crossfire/src/cfeditor/filter/AttributeFilter.java =================================================================== --- trunk/crossfire/src/cfeditor/filter/AttributeFilter.java 2007-01-07 13:02:29 UTC (rev 1492) +++ trunk/crossfire/src/cfeditor/filter/AttributeFilter.java 2007-01-07 13:24:47 UTC (rev 1493) @@ -16,6 +16,7 @@ import javax.swing.JMenuItem; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jdom.Element; /** @@ -35,23 +36,49 @@ private static final Logger log = Logger.getLogger(AttributeFilter.class); - private final Map<String, String> attrList; + /** + * Set of attributes to check for in the head part. + */ + private final Map<String, String> headAttrList = new HashMap<String, String>(); + /** + * Set of attributes to check for in the tail part. + */ + private final Map<String, String> tailAttrList = new HashMap<String, String>(); + private int matchType = -1; - /** Creates an AttributeFilter. */ - public AttributeFilter() { - attrList = new HashMap<String, String>(); + /** + * Add a game object attribute to check for. + * + * @param name the game object attribute name + * + * @param value the game object attribute value + * + * @param useHead if set use the game object's head's attribute; if unset + * use the game objects's attribute + */ + public void addAttribute(@NotNull final String name, @NotNull final String value, final boolean useHead) { + if (useHead) { + headAttrList.put(name, value); + } else { + tailAttrList.put(name, value); + } } - public void addAttribute(final String name, final String value) { - attrList.put(name, value); + /** + * Remove a game object attribute to check for. Does nothing if the + * attribute didn't exist. + * + * @param name the game object attribute name + * + * @param value the game object attribute value + */ + public void removeAttribute(@NotNull final String name, @NotNull final String value) { + headAttrList.remove(name); + tailAttrList.remove(name); } - public void removeAttribute(final String name, final String value) { - attrList.remove(name); - } - public void setType(final int type) { matchType = type; } @@ -63,22 +90,23 @@ /** {@inheritDoc} */ public boolean match(final FilterConfig config, final GameObject gameObject) { boolean hasChecked = false; - final Set<Map.Entry<String, String>> pairs = attrList.entrySet(); - if (!pairs.isEmpty()) { + if (!tailAttrList.isEmpty()) { hasChecked = true; - for (final Map.Entry<String, String> ent : pairs) { - final String key = ent.getKey(); - final String val = ent.getValue(); - if (!gameObject.getAttributeString(key).equals(val)) { - return false; - } + if (!match(gameObject, tailAttrList)) { + return false; } } + if (!headAttrList.isEmpty()) { + hasChecked = true; + if (!match(gameObject.getHead(), headAttrList)) { + return false; + } + } if (matchType >= 0) { hasChecked = true; if (log.isDebugEnabled()) { log.debug("checking type for " + gameObject.getBestName()); - log.debug("o.getArchTypNr() != matchType: " + gameObject.getArchTypNr() + " != " + matchType); + log.debug("gameObject.getArchTypNr() != matchType: " + gameObject.getArchTypNr() + " != " + matchType); } if (gameObject.getArchTypNr() != matchType) { return false; @@ -87,6 +115,27 @@ return hasChecked; } + /** + * Check if a game object matches a set of attributes. + * + * @param gameObject the game object to match + * + * @param pairs the attribute set as (key, value) pairs + * + * @return <code>true</code> if the game object matches all attributes, + * <code>false</code> otherwise + */ + private static boolean match(@NotNull final GameObject gameObject, @NotNull final Map<String, String> pairs) { + for (final Map.Entry<String, String> ent : pairs.entrySet()) { + final String key = ent.getKey(); + final String val = ent.getValue(); + if (!gameObject.getAttributeString(key).equals(val)) { + return false; + } + } + return true; + } + /** {@inheritDoc} */ public boolean reset(final FilterConfig config) { return false; Modified: trunk/crossfire/src/cfeditor/filter/NamedFilterList.java =================================================================== --- trunk/crossfire/src/cfeditor/filter/NamedFilterList.java 2007-01-07 13:02:29 UTC (rev 1492) +++ trunk/crossfire/src/cfeditor/filter/NamedFilterList.java 2007-01-07 13:24:47 UTC (rev 1493) @@ -57,36 +57,36 @@ subFilters = new LinkedHashMap<String, Filter>(); AttributeFilter f; f = new AttributeFilter(); - f.addAttribute("no_pass", "1"); + f.addAttribute("no_pass", "1", false); subFilters.put("Blocked way", f); f = new AttributeFilter(); - f.addAttribute("alive", "1"); - f.addAttribute("tear_down", "1"); + f.addAttribute("alive", "1", true); + f.addAttribute("tear_down", "1", true); subFilters.put("Weak wall", f); f = new AttributeFilter(); - f.addAttribute("invisible", "1"); + f.addAttribute("invisible", "1", false); subFilters.put("Hidden Items", f); f = new AttributeFilter(); - f.addAttribute("is_floor", "1"); + f.addAttribute("is_floor", "1", true); subFilters.put("Floor", f); f = new AttributeFilter(); - f.addAttribute("no_magic", "1"); - f.addAttribute("no_pick", "1"); + f.addAttribute("no_magic", "1", false); + f.addAttribute("no_pick", "1", true); subFilters.put("Magic forbidden", f); f = new AttributeFilter(); - f.addAttribute("damned", "1"); - f.addAttribute("no_pick", "1"); + f.addAttribute("damned", "1", true); + f.addAttribute("no_pick", "1", true); subFilters.put("Unholy ground", f); f = new AttributeFilter(); - f.addAttribute("no_magic", "1"); - f.addAttribute("damned", "1"); - f.addAttribute("no_pick", "1"); + f.addAttribute("no_magic", "1", true); + f.addAttribute("damned", "1", true); + f.addAttribute("no_pick", "1", true); subFilters.put("Spells forbidden", f); f = new AttributeFilter(); - f.addAttribute("alive", "1"); + f.addAttribute("alive", "1", true); subFilters.put("Living creature", f); f = new AttributeFilter(); - f.addAttribute("monster", "1"); + f.addAttribute("monster", "1", true); subFilters.put("Monsters", f); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |