Add preferences for setting position of quickslots

This commit is contained in:
Oskar Wiksten
2013-06-29 18:11:07 +02:00
parent 7eeab282b7
commit 8ac12ac960
9 changed files with 96 additions and 51 deletions

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical" >
<com.gpl.rpg.AndorsTrail.view.QuickButton android:id="@+id/quickitemview_item1" style="@style/quickButton" />
<com.gpl.rpg.AndorsTrail.view.QuickButton android:id="@+id/quickitemview_item2" style="@style/quickButton" />
<com.gpl.rpg.AndorsTrail.view.QuickButton android:id="@+id/quickitemview_item3" style="@style/quickButton" />
</LinearLayout>

View File

@@ -14,7 +14,7 @@
<com.gpl.rpg.AndorsTrail.view.QuickitemView
android:id="@+id/main_quickitemview"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/main_statusview"
android:visibility="gone"

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<com.gpl.rpg.AndorsTrail.view.QuickButton android:id="@+id/quickitemview_item1" style="@style/quickButton" />
<com.gpl.rpg.AndorsTrail.view.QuickButton android:id="@+id/quickitemview_item2" style="@style/quickButton" />
<com.gpl.rpg.AndorsTrail.view.QuickButton android:id="@+id/quickitemview_item3" style="@style/quickButton" />
</LinearLayout>

View File

@@ -629,4 +629,25 @@ Every skill level increases the attack chance of weapons with %1$d %% of their o
<string name="skill_longdescription_specialization_2hand">Increases damage potential of two-handed weapons by an additional %1$d %% of the original damage potential, in addition to the benefis given by the weapon style skill. The attack chances of two-handed weapons are also increased by %2$d %% of their original attack chances.</string>
<string name="skill_longdescription_specialization_weapon_shield">Increases both attack chances and damage potential of weapons. The attack chance is increased by %1$d %% of the original attack chance, and the damage potential is increased by %2$d %% of the original damage potential.</string>
<string name="preferences_quickslots_placement">Quickslot position</string>
<string name="preferences_quickslots_placement_summary">Where to place the quickslots</string>
<string-array name="preferences_quickslots_placements">
<item>Center bottom</item>
<item>Middle left</item>
<item>Middle right</item>
<item>Bottom left, along left border</item>
<item>Bottom left, along bottom border</item>
<item>Bottom right, along bottom border</item>
<item>Bottom right, along right border</item>
</string-array>
<string-array name="preferences_quickslots_placements_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
</string-array>
</resources>

View File

@@ -3,9 +3,4 @@
<item type="id" name="quick_menu_assign"></item>
<item type="id" name="quick_menu_assign_group"></item>
<item type="id" name="quick_menu_unassign"></item>
<array name="quick_buttons">
<item>@id/quickitemview_item1</item>
<item>@id/quickitemview_item2</item>
<item>@id/quickitemview_item3</item>
</array>
</resources>

View File

@@ -86,5 +86,12 @@
android:defaultValue="true"
android:summary="@string/preferences_ui_enable_animations"
android:key="enableUiAnimations" />
</PreferenceCategory>
<ListPreference
android:title="@string/preferences_quickslots_placement"
android:summary="@string/preferences_quickslots_placement_summary"
android:key="quickslots_placement"
android:defaultValue="0"
android:entries="@array/preferences_quickslots_placements"
android:entryValues="@array/preferences_quickslots_placements_values" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -25,7 +25,14 @@ public final class AndorsTrailPreferences {
public static final int CONFIRM_OVERWRITE_SAVEGAME_ALWAYS = 0;
public static final int CONFIRM_OVERWRITE_SAVEGAME_WHEN_PLAYERNAME_DIFFERS = 1;
public static final int CONFIRM_OVERWRITE_SAVEGAME_NEVER = 2;
public static final int QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM = 0;
public static final int QUICKSLOTS_POSITION_VERTICAL_CENTER_LEFT = 1;
public static final int QUICKSLOTS_POSITION_VERTICAL_CENTER_RIGHT = 2;
public static final int QUICKSLOTS_POSITION_VERTICAL_BOTTOM_LEFT = 3;
public static final int QUICKSLOTS_POSITION_HORIZONTAL_BOTTOM_LEFT = 4;
public static final int QUICKSLOTS_POSITION_HORIZONTAL_BOTTOM_RIGHT = 5;
public static final int QUICKSLOTS_POSITION_VERTICAL_BOTTOM_RIGHT = 6;
public boolean confirmRest = true;
public boolean confirmAttack = true;
public int displayLoot = DISPLAYLOOT_DIALOG;
@@ -39,6 +46,7 @@ public final class AndorsTrailPreferences {
public boolean optimizedDrawing = false;
public boolean enableUiAnimations = true;
public int displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS;
public int quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM;
public void read(final Context androidContext) {
AndorsTrailPreferences dest = this;
@@ -56,7 +64,8 @@ public final class AndorsTrailPreferences {
dest.optimizedDrawing = prefs.getBoolean("optimized_drawing", false);
dest.enableUiAnimations = prefs.getBoolean("enableUiAnimations", true);
dest.displayOverwriteSavegame = Integer.parseInt(prefs.getString("display_overwrite_savegame", Integer.toString(CONFIRM_OVERWRITE_SAVEGAME_ALWAYS)));
dest.quickslotsPosition = Integer.parseInt(prefs.getString("quickslots_placement", Integer.toString(QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM)));
// This might be implemented as a skill in the future.
//dest.movementAggressiveness = Integer.parseInt(prefs.getString("movementaggressiveness", Integer.toString(MOVEMENTAGGRESSIVENESS_NORMAL)));
} catch (Exception e) {
@@ -73,15 +82,7 @@ public final class AndorsTrailPreferences {
dest.optimizedDrawing = false;
dest.enableUiAnimations = true;
dest.displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS;
dest.quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM;
}
}
public static boolean shouldUseFullscreen(final Context androidContext) {
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(androidContext);
return prefs.getBoolean("fullscreen", true);
} catch (Exception e) {
}
return true;
}
}

View File

@@ -99,6 +99,7 @@ public final class MainActivity extends Activity implements PlayerMovementListen
quickitemview.registerForContextMenu(this);
dpad.updateVisibility(preferences);
quickitemview.setPosition(preferences);
// Define which views are in front of each other.
dpad.bringToFront();

View File

@@ -9,9 +9,12 @@ import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.activity.MainActivity;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
@@ -36,21 +39,33 @@ public final class QuickitemView extends LinearLayout implements OnClickListener
this.world = app.getWorld();
this.controllers = app.getControllerContext();
setFocusable(false);
setOrientation(LinearLayout.HORIZONTAL);
inflate(context, R.layout.quickitemview, this);
Resources res = getResources();
int position = app.getPreferences().quickslotsPosition;
switch(position) {
case AndorsTrailPreferences.QUICKSLOTS_POSITION_HORIZONTAL_BOTTOM_LEFT:
case AndorsTrailPreferences.QUICKSLOTS_POSITION_HORIZONTAL_BOTTOM_RIGHT:
case AndorsTrailPreferences.QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM:
setOrientation(LinearLayout.HORIZONTAL);
break;
case AndorsTrailPreferences.QUICKSLOTS_POSITION_VERTICAL_BOTTOM_LEFT:
case AndorsTrailPreferences.QUICKSLOTS_POSITION_VERTICAL_BOTTOM_RIGHT:
case AndorsTrailPreferences.QUICKSLOTS_POSITION_VERTICAL_CENTER_LEFT:
case AndorsTrailPreferences.QUICKSLOTS_POSITION_VERTICAL_CENTER_RIGHT:
setOrientation(LinearLayout.VERTICAL);
break;
}
Resources res = getResources();
this.setBackgroundColor(res.getColor(color.transparent));
TypedArray quickButtons = res.obtainTypedArray(R.array.quick_buttons);
for(int i = 0; i < buttons.length; ++i) {
buttons[i] = (QuickButton)findViewById(quickButtons.getResourceId(i, -1));
for(int i = 0; i < NUM_QUICK_SLOTS; ++i) {
buttons[i] = new QuickButton(context, null);
QuickButton item = buttons[i];
item.setIndex(i);
item.setItemType(null, world, tiles);
item.setOnClickListener(this);
addView(item);
}
quickButtons.recycle();
}
public boolean isQuickButtonId(int id){
@@ -113,6 +128,37 @@ public final class QuickitemView extends LinearLayout implements OnClickListener
mainActivity.registerForContextMenu(item);
}
public void setPosition(AndorsTrailPreferences preferences) {
int positionRelativeTo = R.id.main_mainview;
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
switch (preferences.quickslotsPosition) {
case AndorsTrailPreferences.QUICKSLOTS_POSITION_HORIZONTAL_BOTTOM_LEFT:
case AndorsTrailPreferences.QUICKSLOTS_POSITION_VERTICAL_BOTTOM_LEFT:
params.addRule(RelativeLayout.ALIGN_LEFT, positionRelativeTo);
params.addRule(RelativeLayout.ALIGN_BOTTOM, positionRelativeTo);
break;
case AndorsTrailPreferences.QUICKSLOTS_POSITION_HORIZONTAL_BOTTOM_RIGHT:
case AndorsTrailPreferences.QUICKSLOTS_POSITION_VERTICAL_BOTTOM_RIGHT:
params.addRule(RelativeLayout.ALIGN_RIGHT, positionRelativeTo);
params.addRule(RelativeLayout.ALIGN_BOTTOM, positionRelativeTo);
break;
case AndorsTrailPreferences.QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM:
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.addRule(RelativeLayout.ALIGN_BOTTOM, positionRelativeTo);
break;
case AndorsTrailPreferences.QUICKSLOTS_POSITION_VERTICAL_CENTER_LEFT:
params.addRule(RelativeLayout.ALIGN_LEFT, positionRelativeTo);
params.addRule(RelativeLayout.CENTER_VERTICAL);
break;
case AndorsTrailPreferences.QUICKSLOTS_POSITION_VERTICAL_CENTER_RIGHT:
params.addRule(RelativeLayout.ALIGN_RIGHT, positionRelativeTo);
params.addRule(RelativeLayout.CENTER_VERTICAL);
break;
}
setLayoutParams(params);
}
@Override
public void onQuickSlotChanged(int slotId) {
refreshQuickitems();