Skip to content

Commit 9c3742d

Browse files
AvaLanCSAvaLanCS
authored andcommitted
Add "Can't sell equipped items" option
1 parent 2e935bc commit 9c3742d

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

README.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Contributors
119119
* [LadySerenaKitty](https://github.com/LadySerenaKitty)
120120
* [askneller](https://github.com/askneller)
121121
* [JGelfand](https://github.com/JGelfand)
122+
* [AvaLanCS](https://github.com/Avalancs)
122123

123124
... and your name here? :-) More coming!
124125

main/src/org/destinationsol/GameOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class GameOptions {
7171
public int controlType;
7272
public float volMul;
7373
public float musicMul;
74+
public boolean canSellEquippedItems;
7475
private String keyUpMouseName;
7576
private String keyDownMouseName;
7677
private String keyUpName;
@@ -149,6 +150,7 @@ public GameOptions(boolean mobile, SolFileReader reader) {
149150
controllerButtonRight = r.getInt("controllerButtonRight", DEFAULT_BUTTON_RIGHT);
150151
controllerButtonUp = r.getInt("controllerButtonUp", DEFAULT_BUTTON_UP);
151152
controllerButtonDown = r.getInt("controllerButtonDown", DEFAULT_BUTTON_DOWN);
153+
canSellEquippedItems = r.getBoolean("canSellEquippedItems", false);
152154
}
153155

154156
public void advanceReso() {
@@ -228,6 +230,7 @@ public void advanceMusicVolMul() {
228230
*/
229231
public void save() {
230232
IniReader.write(FILE_NAME, "x", x, "y", y, "fullscreen", fullscreen, "controlType", controlType, "vol", volMul,
233+
"canSellEquippedItems", canSellEquippedItems,
231234
"keyUpMouse", getKeyUpMouseName(), "keyDownMouse", getKeyDownMouseName(), "keyUp", getKeyUpName(), "keyDown", keyDownName,
232235
"keyLeft", keyLeftName, "keyRight", keyRightName, "keyShoot", keyShootName, "keyShoot2", getKeyShoot2Name(),
233236
"keyAbility", getKeyAbilityName(), "keyEscape", getKeyEscapeName(), "keyMap", keyMapName, "keyInventory", keyInventoryName,

main/src/org/destinationsol/game/screens/MenuScreen.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ public class MenuScreen implements SolUiScreen {
3636
private final SolUiControl myRespawnCtrl;
3737
private final SolUiControl mySoundVolCtrl;
3838
private final SolUiControl myMusVolCtrl;
39+
private final SolUiControl myDoNotSellEquippedControl;
3940

4041
public MenuScreen(MenuLayout menuLayout, GameOptions gameOptions) {
4142
myControls = new ArrayList<SolUiControl>();
4243

44+
myDoNotSellEquippedControl = new SolUiControl(menuLayout.buttonRect(-1, -1), true);
45+
myDoNotSellEquippedControl.setDisplayName("Can't sell equipped items");
46+
myControls.add(myDoNotSellEquippedControl);
4347
mySoundVolCtrl = new SolUiControl(menuLayout.buttonRect(-1, 1), true);
4448
mySoundVolCtrl.setDisplayName("Sound Vol");
4549
myControls.add(mySoundVolCtrl);
@@ -88,6 +92,11 @@ public void updateCustom(SolApplication cmp, SolInputManager.Ptr[] ptrs, boolean
8892
g.setPaused(false);
8993
im.setScreen(cmp, g.getScreens().mainScreen);
9094
}
95+
myDoNotSellEquippedControl.setDisplayName("Can't sell equipped items: " +
96+
(options.canSellEquippedItems ? "No" : "Yes"));
97+
if (myDoNotSellEquippedControl.isJustOff()) {
98+
options.canSellEquippedItems = !options.canSellEquippedItems;
99+
}
91100
}
92101

93102
private String getVolName(GameOptions options) {

main/src/org/destinationsol/game/screens/SellItems.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.destinationsol.game.item.ItemContainer;
2323
import org.destinationsol.game.item.SolItem;
2424
import org.destinationsol.game.ship.SolShip;
25+
import org.destinationsol.menu.OptionsScreen;
2526
import org.destinationsol.ui.SolInputManager;
2627
import org.destinationsol.ui.SolUiControl;
2728
import org.destinationsol.ui.UiDrawer;
@@ -82,10 +83,27 @@ public void updateCustom(SolApplication cmp, SolInputManager.Ptr[] ptrs, boolean
8283
return;
8384
}
8485
SolItem selItem = is.getSelectedItem();
85-
boolean enabled = selItem != null && target.getTradeContainer().getItems().canAdd(selItem);
86-
sellCtrl.setDisplayName(enabled ? "Sell" : "---");
87-
sellCtrl.setEnabled(enabled);
88-
if (!enabled) return;
86+
if(selItem == null) {
87+
sellCtrl.setDisplayName("----");
88+
sellCtrl.setEnabled(false);
89+
return;
90+
}
91+
92+
boolean isWornAndCanBeSold = isItemEquippedAndSellable(selItem, target, game, cmp.getOptions());
93+
boolean enabled = isItemSellable(selItem, target);
94+
95+
if(enabled && isWornAndCanBeSold) {
96+
sellCtrl.setDisplayName("Sell");
97+
sellCtrl.setEnabled(true);
98+
} else if(enabled && !isWornAndCanBeSold) {
99+
sellCtrl.setDisplayName("Unequip it!");
100+
sellCtrl.setEnabled(false);
101+
} else {
102+
sellCtrl.setDisplayName("----");
103+
sellCtrl.setEnabled(false);
104+
}
105+
106+
if (!enabled || !isWornAndCanBeSold) return;
89107
if (sellCtrl.isJustOff()) {
90108
ItemContainer ic = hero.getItemContainer();
91109
is.setSelected(ic.getSelectionAfterRemove(is.getSelected()));
@@ -95,6 +113,18 @@ public void updateCustom(SolApplication cmp, SolInputManager.Ptr[] ptrs, boolean
95113
}
96114
}
97115

116+
private boolean isItemSellable(SolItem item, SolShip target) {
117+
return target.getTradeContainer().getItems().canAdd(item);
118+
}
119+
120+
// return true if the item is not worn, or is worn and canSellEquippedItems is true
121+
private boolean isItemEquippedAndSellable(SolItem item, SolShip target, SolGame game, GameOptions options) {
122+
if(item.isEquipped()==0 || ((item.isEquipped() != 0) && options.canSellEquippedItems)) {
123+
return true;
124+
}
125+
return false;
126+
}
127+
98128
@Override
99129
public void drawBg(UiDrawer uiDrawer, SolApplication cmp) {
100130

main/src/org/destinationsol/menu/MenuLayout.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ public class MenuLayout {
2626
public final float row0;
2727
private final float rowH;
2828
private final float myPad;
29+
private static final int numberOfRowsTotal = 5;
2930

3031
public MenuLayout(float r) {
31-
btnW = .25f * r;
32+
btnW = .30f * r;
3233
btnH = .1f;
3334
myPad = .1f * btnH;
3435
rowH = btnH + myPad;
3536
colCenter = .5f * r - btnW / 2;
36-
row0 = 1 - myPad - 5 * rowH;
37+
row0 = 1 - myPad - numberOfRowsTotal * rowH;
3738
}
3839

3940
public Rectangle buttonRect(int col, int row) {

0 commit comments

Comments
 (0)