diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/CSGOLayout.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/CSGOLayout.java index e24c744..afa7256 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/CSGOLayout.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/CSGOLayout.java @@ -55,7 +55,7 @@ public CSGOLayout (ILabeled label, Point position, int width, int popupWidth, Su @Override public void populateGUI (IComponentAdder gui, IComponentGenerator components, IClient client, ITheme theme) { - Button title=new Button(label,theme.getButtonRenderer(Void.class,0,0,true)); + Button title=new Button(label,()->null,theme.getButtonRenderer(Void.class,0,0,true)); HorizontalContainer window=new HorizontalContainer(label,theme.getContainerRenderer(0,horizontal?1:0,true)); IEnumSetting catSelect; if (horizontal) { @@ -82,7 +82,7 @@ public void populateGUI (IComponentAdder gui, IComponentGenerator components, IC category.getModules().forEach(module->{ int graphicalLevel=1; FocusableComponent moduleTitle; - if (module.isEnabled()==null) moduleTitle=new Button(module,theme.getButtonRenderer(Void.class,1,1,true)); + if (module.isEnabled()==null) moduleTitle=new Button(module,()->null,theme.getButtonRenderer(Void.class,1,1,true)); else moduleTitle=new ToggleButton(module,module.isEnabled(),theme.getButtonRenderer(Boolean.class,1,1,true)); VerticalContainer moduleContainer=new VerticalContainer(module,theme.getContainerRenderer(1,graphicalLevel,false)); if (module.isEnabled()==null) util.addContainer(module,moduleTitle,moduleContainer,()->null,Void.class,categoryContent,gui,new ThemeTuple(theme,1,graphicalLevel),ChildMode.DOWN); @@ -99,7 +99,7 @@ protected void addSettingsComponent (ISetting setting, VerticalContainer IComponent component=components.getComponent(setting,animation,theme,colorLevel,isContainer); if (component instanceof VerticalContainer) { VerticalContainer colorContainer=(VerticalContainer)component; - Button button=new Button(setting,theme.getButtonRenderer(Void.class,colorType==ChildMode.DOWN)); + Button button=new Button(setting,()->setting.getSettingState(),theme.getButtonRenderer(setting.getSettingClass(),colorType==ChildMode.DOWN)); util.addContainer(setting,button,colorContainer,()->setting.getSettingState(),setting.getSettingClass(),container,gui,new ThemeTuple(theme.theme,theme.logicalLevel,colorLevel),colorType); if (setting.getSubSettings()!=null) setting.getSubSettings().forEach(subSetting->addSettingsComponent(subSetting,colorContainer,gui,components,new ThemeTuple(theme.theme,theme.logicalLevel+1,colorLevel+1))); } else if (setting.getSubSettings()!=null) { @@ -135,6 +135,12 @@ public IBoolean isVisible() { public void increment() { state=(state+1)%array.length; } + + @Override + public void decrement() { + state-=1; + if (state<0) state=array.length-1; + } @Override public String getValueName() { @@ -156,7 +162,19 @@ public ILabeled[] getAllowedValues() { return array; } }; - RadioButton button=new RadioButton(setting,theme.getRadioRenderer(true),animation.get(),horizontal); + RadioButton button=new RadioButton(setting,theme.getRadioRenderer(true),animation.get(),horizontal) { + @Override + protected boolean isUpKey (int key) { + if (horizontal) return isLeftKey(key); + else return CSGOLayout.this.isUpKey(key); + } + + @Override + protected boolean isDownKey (int key) { + if (horizontal) return isRightKey(key); + else return CSGOLayout.this.isDownKey(key); + } + }; window.addComponent(container.apply(button),visible); return setting; } @@ -174,4 +192,20 @@ protected Void getState() { } },0,weight); } + + protected boolean isUpKey (int key) { + return false; + } + + protected boolean isDownKey (int key) { + return false; + } + + protected boolean isLeftKey (int key) { + return false; + } + + protected boolean isRightKey (int key) { + return false; + } } diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/ChildUtil.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/ChildUtil.java index 8156ab9..d09cb9f 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/ChildUtil.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/ChildUtil.java @@ -42,7 +42,7 @@ protected void addContainer (ILabeled label, IComponent title, IComponent co case POPUP: case DRAG_POPUP: toggle=new SimpleToggleable(false); - Button button=new Button(new Labeled(label.getDisplayName(),label.getDescription(),()->drawTitle&&label.isVisible().isOn()),theme.getButtonRenderer(Void.class,true)); + Button button=new Button(new Labeled(label.getDisplayName(),label.getDescription(),()->drawTitle&&label.isVisible().isOn()),state,theme.getButtonRenderer(stateClass,true)); if (popupType.dynamicPopup) popup=ClosableComponent.createDynamicPopup(button,container,state,animation.get(),new RendererTuple(stateClass,theme),popupType.popupSize,toggle,width); else popup=ClosableComponent.createStaticPopup(button,container,state,animation.get(),new RendererTuple(stateClass,theme),popupType.popupSize,toggle,width,false,""); parent.addComponent(new ComponentProxy(title) { diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/IComponentGenerator.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/IComponentGenerator.java index 19f458a..8016702 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/IComponentGenerator.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/IComponentGenerator.java @@ -31,7 +31,7 @@ public default IComponent getComponent (ISetting setting, Supplier } else if (setting instanceof IKeybindSetting) { return getKeybindComponent((IKeybindSetting)setting,animation,theme,colorLevel,isContainer); } else { - return new Button(setting,theme.getButtonRenderer(Void.class,isContainer)); + return new Button(setting,()->null,theme.getButtonRenderer(Void.class,isContainer)); } } diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelAdder.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelAdder.java index 6d46574..aa65ed1 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelAdder.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelAdder.java @@ -1,6 +1,5 @@ package com.lukflug.panelstudio.layout; -import java.awt.Dimension; import java.awt.Point; import java.util.function.Supplier; import java.util.function.UnaryOperator; @@ -23,7 +22,6 @@ public class PanelAdder implements IComponentAdder { protected boolean open; protected IBoolean isVisible; protected UnaryOperator configName; - protected Dimension minSize=new Dimension(20,20); public PanelAdder (IContainer container, boolean open, IBoolean isVisible, UnaryOperator configName) { this.container=container; diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelLayout.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelLayout.java index 14f30a7..9509cc9 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelLayout.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/PanelLayout.java @@ -44,7 +44,7 @@ public void populateGUI (IComponentAdder gui, IComponentGenerator components, IC Point pos=start; AtomicInteger skipY=new AtomicInteger(this.skipY); client.getCategories().forEach(category->{ - Button categoryTitle=new Button(category,theme.getButtonRenderer(Void.class,0,0,true)); + Button categoryTitle=new Button(category,()->null,theme.getButtonRenderer(Void.class,0,0,true)); VerticalContainer categoryContent=new VerticalContainer(category,theme.getContainerRenderer(0,0,false)); gui.addComponent(categoryTitle,categoryContent,new ThemeTuple(theme,0,0),new Point(pos),width,animation); pos.translate(skipX,skipY.get()); @@ -53,7 +53,7 @@ public void populateGUI (IComponentAdder gui, IComponentGenerator components, IC ChildMode mode=layoutType.apply(0); int graphicalLevel=(mode==ChildMode.DOWN)?1:0; FocusableComponent moduleTitle; - if (module.isEnabled()==null) moduleTitle=new Button(module,theme.getButtonRenderer(Void.class,1,1,mode==ChildMode.DOWN)); + if (module.isEnabled()==null) moduleTitle=new Button(module,()->null,theme.getButtonRenderer(Void.class,1,1,mode==ChildMode.DOWN)); else moduleTitle=new ToggleButton(module,module.isEnabled(),theme.getButtonRenderer(Boolean.class,1,1,mode==ChildMode.DOWN)); VerticalContainer moduleContainer=new VerticalContainer(module,theme.getContainerRenderer(1,graphicalLevel,false)); if (module.isEnabled()==null) util.addContainer(module,moduleTitle,moduleContainer,()->null,Void.class,categoryContent,gui,new ThemeTuple(theme,1,graphicalLevel),layoutType.apply(0)); @@ -70,7 +70,7 @@ protected void addSettingsComponent (ISetting setting, VerticalContainer IComponent component=components.getComponent(setting,animation,new ThemeTuple(theme.theme,theme.logicalLevel,theme.graphicalLevel),colorLevel,isContainer); if (component instanceof VerticalContainer) { VerticalContainer colorContainer=(VerticalContainer)component; - Button button=new Button(setting,theme.getButtonRenderer(Void.class,colorType.apply(theme.logicalLevel-1)==ChildMode.DOWN)); + Button button=new Button(setting,()->setting.getSettingState(),theme.getButtonRenderer(setting.getSettingClass(),colorType.apply(theme.logicalLevel-1)==ChildMode.DOWN)); util.addContainer(setting,button,colorContainer,()->setting.getSettingState(),setting.getSettingClass(),container,gui,new ThemeTuple(theme.theme,theme.logicalLevel,colorLevel),colorType.apply(theme.logicalLevel-1)); if (setting.getSubSettings()!=null) setting.getSubSettings().forEach(subSetting->addSettingsComponent(subSetting,colorContainer,gui,components,new ThemeTuple(theme.theme,theme.logicalLevel+1,colorLevel+1))); } else if (setting.getSubSettings()!=null) { diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/StackedPanelAdder.java b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/StackedPanelAdder.java index a31aaeb..52a2ec4 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/layout/StackedPanelAdder.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/layout/StackedPanelAdder.java @@ -38,7 +38,7 @@ public StackedPanelAdder (IContainer container, ILabele content=new VerticalContainer(label,theme.getContainerRenderer(-1,-1,true)); IResizable size=getResizable(width); IScrollSize scrollSize=getScrollSize(size); - container.addComponent(ResizableComponent.createResizableComponent(new Button(label,theme.getButtonRenderer(Void.class,-1,-1,true)),content,()->null,new AnimatedToggleable(new SimpleToggleable(true),animation.get()),new RendererTuple(Void.class,new ThemeTuple(theme,-1,-1)),theme.getResizeRenderer(),size,scrollSize,position,width,true,configName),isVisible); + container.addComponent(ResizableComponent.createResizableComponent(new Button(label,()->null,theme.getButtonRenderer(Void.class,-1,-1,true)),content,()->null,new AnimatedToggleable(new SimpleToggleable(true),animation.get()),new RendererTuple(Void.class,new ThemeTuple(theme,-1,-1)),theme.getResizeRenderer(),size,scrollSize,position,width,true,configName),isVisible); util=new ChildUtil(width,animation,new PopupTuple(popupPos,false,this)); } diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/setting/IColorSetting.java b/panelstudio/src/main/java/com/lukflug/panelstudio/setting/IColorSetting.java index 20adebc..0ba9e66 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/setting/IColorSetting.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/setting/IColorSetting.java @@ -6,7 +6,7 @@ * Setting representing a color. * @author lukflug */ -public interface IColorSetting extends ISetting { +public interface IColorSetting extends ISetting { /** * Get the current value for the color setting. * @return the current color @@ -62,12 +62,12 @@ public default boolean hasHSBModel() { } @Override - public default Void getSettingState() { - return null; + public default Color getSettingState() { + return getValue(); } @Override - public default Class getSettingClass() { - return Void.class; + public default Class getSettingClass() { + return Color.class; } } diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/setting/IEnumSetting.java b/panelstudio/src/main/java/com/lukflug/panelstudio/setting/IEnumSetting.java index 5f5e23a..7c5e8fc 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/setting/IEnumSetting.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/setting/IEnumSetting.java @@ -10,6 +10,8 @@ public interface IEnumSetting extends ISetting { */ public void increment(); + public void decrement(); + /** * Get the current value. * @return the name of the current enum value diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/theme/ClearTheme.java b/panelstudio/src/main/java/com/lukflug/panelstudio/theme/ClearTheme.java index 1b7cd99..6f357e8 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/theme/ClearTheme.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/theme/ClearTheme.java @@ -165,6 +165,7 @@ public void renderButton(Context context, String title, boolean focus, T state) } Color color=getFontColor(focus); if (type==Boolean.class && (Boolean)state==true) color=getMainColor(focus,true); + else if (type==Color.class) color=(Color)state; if (graphicalLevel>0) renderOverlay(context); if (type==String.class) context.getInterface().drawString(new Point(context.getRect().x+padding,context.getRect().y+padding),height,title+separator+state,color); else context.getInterface().drawString(new Point(context.getRect().x+padding,context.getRect().y+padding),height,title,color); @@ -239,8 +240,22 @@ public int getDefaultHeight(ILabeled[] items, boolean horizontal) { @Override public IResizeBorderRenderer getResizeRenderer() { - // TODO Auto-generated method stub - return null; + return new IResizeBorderRenderer() { + @Override + public void drawBorder(Context context, boolean focus) { + Color color=getBackgroundColor(focus); + Rectangle rect=context.getRect(); + context.getInterface().fillRect(new Rectangle(rect.x,rect.y,rect.width,getBorder()),color,color,color,color); + context.getInterface().fillRect(new Rectangle(rect.x,rect.y+rect.height-getBorder(),rect.width,getBorder()),color,color,color,color); + context.getInterface().fillRect(new Rectangle(rect.x,rect.y+getBorder(),getBorder(),rect.height-2*getBorder()),color,color,color,color); + context.getInterface().fillRect(new Rectangle(rect.x+rect.width-getBorder(),rect.y+getBorder(),getBorder(),rect.height-2*getBorder()),color,color,color,color); + } + + @Override + public int getBorder() { + return 2; + } + }; } @Override diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/theme/GameSenseTheme.java b/panelstudio/src/main/java/com/lukflug/panelstudio/theme/GameSenseTheme.java index 4c2247a..08c3e85 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/theme/GameSenseTheme.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/theme/GameSenseTheme.java @@ -31,10 +31,11 @@ public GameSenseTheme (IColorScheme scheme, int height, int padding, int scroll, scheme.createSetting(this,"Font Color","The main color for text.",false,true,new Color(255,255,255),false); } - protected void fillBaseRect (Context context, boolean focus, boolean active, int logicalLevel, int graphicalLevel) { + protected void fillBaseRect (Context context, boolean focus, boolean active, int logicalLevel, int graphicalLevel, Color colorState) { Color color=getMainColor(focus,active); if (logicalLevel>1 && !active) color=getBackgroundColor(focus); else if (graphicalLevel<=0 && active) color=ITheme.combineColors(getColor(scheme.getColor("Title Color")),scheme.getColor("Enabled Color")); + if (colorState!=null) color=ITheme.combineColors(colorState,scheme.getColor("Enabled Color")); context.getInterface().fillRect(context.getRect(),color,color,color,color); } @@ -166,8 +167,9 @@ public IButtonRenderer getButtonRenderer (Class type, int logicalLevel return new IButtonRenderer() { @Override public void renderButton(Context context, String title, boolean focus, T state) { - if (type==Boolean.class) fillBaseRect(context,focus,(Boolean)state,logicalLevel,graphicalLevel); - else fillBaseRect(context,focus,graphicalLevel<=0,logicalLevel,graphicalLevel); + if (type==Boolean.class) fillBaseRect(context,focus,(Boolean)state,logicalLevel,graphicalLevel,null); + else if (type==Color.class) fillBaseRect(context,focus,graphicalLevel<=0,logicalLevel,graphicalLevel,(Color)state); + else fillBaseRect(context,focus,graphicalLevel<=0,logicalLevel,graphicalLevel,null); if (graphicalLevel<=0 && container) { Color color=scheme.getColor("Outline Color"); context.getInterface().fillRect(new Rectangle(context.getPos().x,context.getPos().y+context.getSize().height-1,context.getSize().width,1),color,color,color,color); @@ -189,7 +191,7 @@ public IButtonRenderer getKeybindRenderer(int logicalLevel, int graphica return new IButtonRenderer() { @Override public void renderButton(Context context, String title, boolean focus, String state) { - fillBaseRect(context,focus,focus,logicalLevel,graphicalLevel); + fillBaseRect(context,focus,focus,logicalLevel,graphicalLevel,null); renderOverlay(context); context.getInterface().drawString(new Point(context.getRect().x+padding,context.getRect().y+padding),height,title+separator+(focus?"...":state),getFontColor(focus)); } @@ -231,7 +233,7 @@ public void renderItem (Context context, ILabeled[] items, boolean focus, int ta Rectangle rect=getItemRect(context,items,i,horizontal); Context subContext=new Context(context.getInterface(),rect.width,rect.getLocation(),context.hasFocus(),context.onTop()); subContext.setHeight(rect.height); - fillBaseRect(subContext,focus,i==target,logicalLevel,graphicalLevel); + fillBaseRect(subContext,focus,i==target,logicalLevel,graphicalLevel,null); renderOverlay(subContext); context.getInterface().drawString(new Point(rect.x+padding,rect.y+padding),height,items[i].getDisplayName(),getFontColor(focus)); } diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/widget/Button.java b/panelstudio/src/main/java/com/lukflug/panelstudio/widget/Button.java index 5bc60e3..d55c932 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/widget/Button.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/widget/Button.java @@ -1,5 +1,7 @@ package com.lukflug.panelstudio.widget; +import java.util.function.Supplier; + import com.lukflug.panelstudio.base.Context; import com.lukflug.panelstudio.component.FocusableComponent; import com.lukflug.panelstudio.setting.ILabeled; @@ -9,26 +11,28 @@ * Button widget class. * @author lukflug */ -public class Button extends FocusableComponent { +public class Button extends FocusableComponent { + protected Supplier state; /** * Renderer for this component. */ - protected IButtonRenderer renderer; + protected IButtonRenderer renderer; /** * Constructor. * @param label the label for the component * @param renderer the renderer for this component */ - public Button(ILabeled label, IButtonRenderer renderer) { + public Button(ILabeled label, Supplier state, IButtonRenderer renderer) { super(label); this.renderer=renderer; + this.state=state; } @Override public void render (Context context) { super.render(context); - renderer.renderButton(context,getTitle(),hasFocus(context),null); + renderer.renderButton(context,getTitle(),hasFocus(context),state.get()); } @Override diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/widget/RadioButton.java b/panelstudio/src/main/java/com/lukflug/panelstudio/widget/RadioButton.java index f9602df..4f68e36 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/widget/RadioButton.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/widget/RadioButton.java @@ -8,7 +8,7 @@ import com.lukflug.panelstudio.setting.IEnumSetting; import com.lukflug.panelstudio.theme.IRadioRenderer; -public class RadioButton extends FocusableComponent { +public abstract class RadioButton extends FocusableComponent { protected IEnumSetting setting; protected IRadioRenderer renderer; protected AnimatedEnum animation; @@ -40,10 +40,22 @@ public void handleButton (Context context, int button) { } } } + + @Override + public void handleKey (Context context, int key) { + super.handleKey(context,key); + if (context.hasFocus()) { + if (isUpKey(key)) setting.decrement(); + else if (isDownKey(key)) setting.increment(); + } + } @Override protected int getHeight() { return renderer.getDefaultHeight(setting.getAllowedValues(),horizontal); } - + + protected abstract boolean isUpKey (int key); + + protected abstract boolean isDownKey (int key); } diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/widget/ResizableComponent.java b/panelstudio/src/main/java/com/lukflug/panelstudio/widget/ResizableComponent.java index 6815e0b..8b33608 100644 --- a/panelstudio/src/main/java/com/lukflug/panelstudio/widget/ResizableComponent.java +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/widget/ResizableComponent.java @@ -63,23 +63,22 @@ public void handleButton (Context context, int button) { @Override public int getHeight (int height) { - return size.getSize().height+2*renderer.getBorder(); + return height+2*renderer.getBorder(); } @Override public Context getContext (Context context) { if (resizing[0]) { - getComponent().setPosition(context.getInterface(),new Point(attachRect.x,attachRect.y+context.getInterface().getMouse().y-attachPoint.y)); - size.setSize(new Dimension(attachRect.width,attachRect.height-context.getInterface().getMouse().y+attachPoint.y)); + getComponent().setPosition(context.getInterface(),new Point(getComponent().getPosition(context.getInterface()).x,attachRect.y+context.getInterface().getMouse().y-attachPoint.y)); + size.setSize(new Dimension(size.getSize().width,attachRect.height-context.getInterface().getMouse().y+attachPoint.y)); } else if (resizing[1]) { - size.setSize(new Dimension(attachRect.width,attachRect.height+context.getInterface().getMouse().y-attachPoint.y)); + size.setSize(new Dimension(size.getSize().width,attachRect.height+context.getInterface().getMouse().y-attachPoint.y)); } if (resizing[2]) { - Point p=getComponent().getPosition(context.getInterface()); - getComponent().setPosition(context.getInterface(),new Point(p.x+context.getInterface().getMouse().x-attachPoint.x,p.y)); - size.setSize(new Dimension(attachRect.width-context.getInterface().getMouse().x+attachPoint.x,attachRect.height)); + getComponent().setPosition(context.getInterface(),new Point(attachRect.x+context.getInterface().getMouse().x-attachPoint.x,getComponent().getPosition(context.getInterface()).y)); + size.setSize(new Dimension(attachRect.width-context.getInterface().getMouse().x+attachPoint.x,size.getSize().height)); } else if (resizing[3]) { - size.setSize(new Dimension(attachRect.width+context.getInterface().getMouse().x-attachPoint.x,attachRect.height)); + size.setSize(new Dimension(attachRect.width+context.getInterface().getMouse().x-attachPoint.x,size.getSize().height)); } return new Context(context,context.getSize().width-2*renderer.getBorder(),new Point(renderer.getBorder(),renderer.getBorder()),true,true); }