Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
169 additions
and
5 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/main/java/net/bdew/wurm/customnpc/config/SettingsQuestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package net.bdew.wurm.customnpc.config; | ||
|
||
import com.wurmonline.server.creatures.Communicator; | ||
import com.wurmonline.server.creatures.Creature; | ||
import com.wurmonline.server.questions.Question; | ||
import net.bdew.wurm.customnpc.CustomAIData; | ||
import net.bdew.wurm.customnpc.CustomNpcMod; | ||
import org.gotti.wurmunlimited.modsupport.questions.ModQuestion; | ||
import org.gotti.wurmunlimited.modsupport.questions.ModQuestions; | ||
|
||
import java.util.Properties; | ||
|
||
public class SettingsQuestion implements ModQuestion { | ||
private final Creature responder, npc; | ||
private final CustomAIData data; | ||
|
||
public SettingsQuestion(Creature responder, Creature npc) { | ||
this.responder = responder; | ||
this.npc = npc; | ||
data = (CustomAIData) npc.getCreatureAIData(); | ||
} | ||
|
||
@Override | ||
public void sendQuestion(Question question) { | ||
final StringBuilder buf = new StringBuilder(ModQuestions.getBmlHeader(question)); | ||
|
||
buf.append("harray{label{text='Name:'};input{id='name'; text=\"").append(npc.getName()).append("\";maxchars='50'}}"); | ||
|
||
buf.append("text{text=''}"); | ||
|
||
buf.append("harray{label{text='Sex:'};"); | ||
buf.append("radio{group='sex';id='0';text='Male';").append(npc.getSex() == 0 ? "selected='true'" : "").append("}"); | ||
buf.append("radio{group='sex';id='1';text='Female';").append(npc.getSex() == 1 ? "selected='true'" : "").append("}"); | ||
buf.append("}"); | ||
|
||
buf.append("text{text=''}"); | ||
|
||
data.getConfig().getMovementScript().configBML(npc, buf); | ||
|
||
buf.append("text{text=''}"); | ||
|
||
buf.append(ModQuestions.createAnswerButton2(question, "Save")); | ||
|
||
question.getResponder().getCommunicator().sendBml(250, 400, true, true, buf.toString(), 200, 200, 200, question.getTitle()); | ||
} | ||
|
||
@Override | ||
public void answer(Question question, Properties answers) { | ||
Communicator comm = responder.getCommunicator(); | ||
|
||
boolean changed = false; | ||
|
||
String newName = answers.getProperty("name"); | ||
if (newName != null && newName.length() > 0 && !newName.equals(npc.getName())) { | ||
try { | ||
changed = true; | ||
npc.setVisible(false); | ||
npc.setName(newName); | ||
data.getConfig().setName(newName); | ||
data.configUpdated(); | ||
} catch (Exception e) { | ||
CustomNpcMod.logException("Error setting name", e); | ||
} | ||
} | ||
|
||
byte newSex = Byte.parseByte(answers.getProperty("sex")); | ||
if (newSex != npc.getSex()) { | ||
if (!changed) { | ||
changed = true; | ||
npc.setVisible(false); | ||
} | ||
npc.setSex(newSex); | ||
} | ||
|
||
if (changed) { | ||
npc.setVisible(true); | ||
} | ||
|
||
data.getConfig().getMovementScript().processConfig(npc, answers); | ||
data.configUpdated(); | ||
} | ||
|
||
public static void send(Creature player, Creature npc) { | ||
ModQuestions.createQuestion(player, "NPC Settings", "", -10, new SettingsQuestion(player, npc)).sendQuestion(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/net/bdew/wurm/customnpc/manage/SettingsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.bdew.wurm.customnpc.manage; | ||
|
||
import com.wurmonline.server.behaviours.Action; | ||
import com.wurmonline.server.behaviours.ActionEntry; | ||
import com.wurmonline.server.creatures.Creature; | ||
import net.bdew.wurm.customnpc.config.SettingsQuestion; | ||
import org.gotti.wurmunlimited.modsupport.actions.ModActions; | ||
|
||
import static org.gotti.wurmunlimited.modsupport.actions.ActionPropagation.FINISH_ACTION; | ||
import static org.gotti.wurmunlimited.modsupport.actions.ActionPropagation.NO_ACTION_PERFORMER_PROPAGATION; | ||
import static org.gotti.wurmunlimited.modsupport.actions.ActionPropagation.NO_SERVER_PROPAGATION; | ||
|
||
public class SettingsAction extends BaseManagementAction { | ||
public SettingsAction() { | ||
super(ActionEntry.createEntry((short) ModActions.getNextActionId(), "Settings", "managing", new int[]{ | ||
48 /* ACTION_TYPE_ENEMY_ALWAYS */, | ||
37 /* ACTION_TYPE_NEVER_USE_ACTIVE_ITEM */ | ||
})); | ||
|
||
} | ||
|
||
@Override | ||
public boolean action(Action action, Creature performer, Creature target, short num, float counter) { | ||
if (canUse(performer, target)) { | ||
SettingsQuestion.send(performer, target); | ||
} | ||
return propagate(action, FINISH_ACTION, NO_SERVER_PROPAGATION, NO_ACTION_PERFORMER_PROPAGATION); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters