Skip to content

Commit

Permalink
Fixed bug when removing gems from a socketgroup.
Browse files Browse the repository at this point in the history
  • Loading branch information
karakasis committed Mar 8, 2019
1 parent 27ad262 commit 97850ee
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/poe/level/fx/GemEntry_Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void setId(int id){
}

public AnchorPane getRoot(){
return root;
return outerRoot;
}

public Gem getGem(){
Expand Down
49 changes: 42 additions & 7 deletions src/poe/level/fx/GemsPanel_Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javafx.util.StringConverter;
import poe.level.data.*;
import poe.level.fx.SocketGroupsPanel_Controller.SocketGroupLinker;
import sun.plugin.javascript.navig.Anchor;

/**
* FXML Controller class
Expand All @@ -52,6 +53,7 @@ public class GemsPanelLinker{
int popup_id;
SocketGroup sg;
GemLinker currentMain;
public int panel_mapper;

public int hook(GemsPanel_Controller root, SocketGroup sg){
this.root = root;
Expand Down Expand Up @@ -337,8 +339,8 @@ public void update(SocketGroupLinker sgl){

try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("gemEntry.fxml"));

gemContainer.getChildren().add(loader.load());
AnchorPane gemEntry = loader.load();
gemContainer.getChildren().add(gemEntry);
sgl.gpl.loadGemPanel(gl.id);

gl.hookController(loader.<GemEntry_Controller>getController());
Expand All @@ -361,7 +363,8 @@ public void update(SocketGroupLinker sgl){
for(int gem_id : sgl.gpl.ids){
FXMLLoader loader = new FXMLLoader(getClass().getResource("gemEntry.fxml"));
try {
gemContainer.getChildren().add(loader.load());
AnchorPane gemEntry = loader.load();
gemContainer.getChildren().add(gemEntry);
} catch (IOException ex) {
Logger.getLogger(GemsPanel_Controller.class.getName()).log(Level.SEVERE, null, ex);
}
Expand Down Expand Up @@ -436,7 +439,8 @@ private void addGemPanel(){
current_sgl.gpl.gl_map.put(gl.hook(current_sgl.gpl), gl);
gl.gem = GemHolder.getInstance().tossDummie();
try {
gemContainer.getChildren().add(loader.load());
AnchorPane gemEntry = loader.load();
gemContainer.getChildren().add(gemEntry);
current_sgl.gpl.loadGemPanel(gl.id);
} catch (IOException ex) {
Logger.getLogger(GemsPanel_Controller.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -449,14 +453,24 @@ private void addGemPanel(){
private void removeGemPanel(){
GemLinker get = current_sgl.gpl.gl_map.get(current_sgl.gpl.active_gemLinker);
current_sgl.gpl.removeGemPanel(current_sgl.gpl.active_gemLinker);
/*
int active_gemLinker = current_sgl.gpl.active_gemLinker;
GemLinker gemLinker = current_sgl.gpl.gl_map.get(active_gemLinker);
Gem gem = gemLinker.gem;*/

GemEntry_Controller thisiswrong = get.controller;


removeGem(get.gem); //remove gem from socketGroup class
current_sgl.gpl.gl_map.remove(current_sgl.gpl.active_gemLinker);//let go of the GemLinker reference

//current.sgl//remove from the vbox lists
if(thisiswrong!=null){
gemContainer.getChildren().remove(thisiswrong.getRoot());
}
if(gemContainer.getChildren().isEmpty()){
current_sgl.triggerDelete();
}
removeGemPanel_button.setDisable(true);
}

Expand Down Expand Up @@ -532,8 +546,10 @@ private void mainGemValueChanged(){
}
}
current_sgl.changeLabel();
groupSliderChange(current_sgl.sg.getActiveGem().getLevelAdded(),0);
fromLevel.getValueFactory().setValue(current_sgl.sg.getActiveGem().getLevelAdded());
if(current_sgl.sg.getActiveGem()!=null){
groupSliderChange(current_sgl.sg.getActiveGem().getLevelAdded(),0);
fromLevel.getValueFactory().setValue(current_sgl.sg.getActiveGem().getLevelAdded());
}
if(current_sgl.sg.replaceGroup()){
groupSliderChange(current_sgl.sg.getGroupReplaced().getFromGroupLevel(),1);
untilLevel.getValueFactory().setValue(current_sgl.sg.getGroupReplaced().getFromGroupLevel());
Expand Down Expand Up @@ -615,7 +631,7 @@ public void gemUpdate(Gem gem, int id){
public void removeGem(Gem gem){



Gem replacement = null;
if(current_sgl.sg.getActiveGem()!=null){
if(current_sgl.sg.getActiveGem().equals(gem)){

Expand All @@ -625,6 +641,20 @@ public void removeGem(Gem gem){
a.sg.setReplaceGroup(false);
}
}
for(Gem g : current_sgl.sg.getGems()){
if(g.isActive && g != gem) {
replacement = g;
break;
}
}
if(replacement== null){
for(Gem g : current_sgl.sg.getGems()){
if(g != gem) {
replacement = g;
break;
}
}
}
}
}

Expand All @@ -644,6 +674,11 @@ public void removeGem(Gem gem){
}*/


if(replacement!=null){
System.out.println("Replacement" + replacement.getGemName());
activeSkillGroup.setValue(replacement);
}

for(Gem g : current_sgl.sg.getGems()){
if(g.replaced){
if(g.replacedWith.equals(gem)){
Expand Down
43 changes: 41 additions & 2 deletions src/poe/level/fx/SocketGroupsPanel_Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ public class SocketGroupLinker{
Label sgLabel;
SocketGroup sg;
GemsPanelLinker gpl;
SocketGroupsPanel_Controller sgpc;

public SocketGroupLinker(SocketGroup sgroup){
sg = sgroup;
generateLabel();
}


public void hookSGPC(SocketGroupsPanel_Controller sgpc){
this.sgpc = sgpc;
}

public void triggerDelete(){
sgpc.removeSocketGroupIfEmpty(this);
}

public SocketGroupLinker dupe(HashSet<Integer> s_id, HashSet<Integer> g_id){
SocketGroupLinker sgl = new SocketGroupLinker(sg.dupe(s_id,g_id));
sgl.hookSGPC(sgpc);
return sgl;
}

Expand Down Expand Up @@ -165,6 +175,7 @@ public void update(ArrayList<SocketGroupLinker> sgl_list){
ObservableList<Label> list = FXCollections.observableArrayList();
for(SocketGroupLinker sgl : linker){
list.add(sgl.sgLabel);
sgl.hookSGPC(this);
}
socketGroupView.setItems(list);
/*
Expand All @@ -180,11 +191,39 @@ public void update(ArrayList<SocketGroupLinker> sgl_list){
@FXML
private void addSocketGroup(){
SocketGroupLinker sgl_dum = new SocketGroupLinker(null);
sgl_dum.hookSGPC(this);
linker.add(sgl_dum);
socketGroupView.getItems().add(sgl_dum.sgLabel);
bpc.addNewSocketGroup(sgl_dum.getSocketGroup());
}


public void removeSocketGroupIfEmpty(SocketGroupLinker sgl){
int remove = -1;
for(int i=0; i<linker.size(); i++){
if(linker.get(i).equals(sgl)){
remove = i;
break;
}
}

if(remove!= -1){
for(SocketGroupLinker a : linker){
if(a.sg.replaceGroup()){
if(a.sg.getGroupReplaced().equals(linker.get(remove).sg))//if another group replaces with this one
a.sg.setReplaceGroup(false);
}

}
bpc.removeSocketGroup(linker.get(remove).sg);
socketGroupView.getItems().remove(remove);
linker.remove(remove);
socketGroupView.getSelectionModel().clearSelection();
removeSocketGroup_button.setDisable(true);
gpc.hidePanel();
}

}

@FXML
private void removeSocketGroup(){
int remove = socketGroupView.getSelectionModel().getSelectedIndex();
Expand Down

0 comments on commit 97850ee

Please sign in to comment.