Start using FragmentActivity & FragmentTabHost for tabs instead of TabHost.

This commit is contained in:
Oskar Wiksten
2013-07-05 22:26:15 +02:00
parent 3dcc608cc1
commit f16149bccb
18 changed files with 573 additions and 539 deletions

View File

@@ -59,10 +59,6 @@
<activity android:name=".activity.ActorConditionInfoActivity" android:theme="@android:style/Theme.Dialog" />
<activity android:name=".activity.BulkSelectionInterface" android:theme="@android:style/Theme.Dialog" />
<activity android:name=".activity.SkillInfoActivity" android:theme="@android:style/Theme.Dialog" />
<activity android:name=".activity.HeroinfoActivity_Quests" />
<activity android:name=".activity.HeroinfoActivity_Stats" />
<activity android:name=".activity.HeroinfoActivity_Skills" />
<activity android:name=".activity.HeroinfoActivity_Inventory" />
<activity android:name=".activity.DisplayWorldMapActivity" />
</application>

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</TabHost>

View File

@@ -1,82 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- TAB 1 -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="left"
android:id="@+id/shop_tab1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/shop_buy_gc"
android:drawableLeft="@drawable/ui_icon_coins"
android:drawablePadding="@dimen/boxshape_margin"
android:layout_gravity="right"
android:gravity="center_vertical"
/>
<ListView
android:id="@+id/shop_buy_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<!-- TAB 2 -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="left"
android:id="@+id/shop_tab2"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/shop_sell_gc"
android:drawableLeft="@drawable/ui_icon_coins"
android:drawablePadding="@dimen/boxshape_margin"
android:layout_gravity="right"
android:gravity="center_vertical"
/>
<ListView
android:id="@+id/shop_sell_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>

View File

@@ -0,0 +1,26 @@
<?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="match_parent"
android:orientation="vertical"
android:gravity="left"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/shop_gc"
android:drawableLeft="@drawable/ui_icon_coins"
android:drawablePadding="@dimen/boxshape_margin"
android:layout_gravity="right"
android:gravity="center_vertical"
/>
<ListView
android:id="@+id/shop_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>

View File

@@ -1,38 +1,22 @@
package com.gpl.rpg.AndorsTrail;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import com.gpl.rpg.AndorsTrail.activity.ActorConditionInfoActivity;
import com.gpl.rpg.AndorsTrail.activity.BulkSelectionInterface;
import com.gpl.rpg.AndorsTrail.activity.ConversationActivity;
import com.gpl.rpg.AndorsTrail.activity.HeroinfoActivity_Inventory;
import com.gpl.rpg.AndorsTrail.activity.HeroinfoActivity_Skills;
import com.gpl.rpg.AndorsTrail.activity.HeroinfoActivity_Stats;
import com.gpl.rpg.AndorsTrail.activity.LoadSaveActivity;
import com.gpl.rpg.AndorsTrail.activity.MainActivity;
import com.gpl.rpg.AndorsTrail.activity.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail.activity.LevelUpActivity;
import com.gpl.rpg.AndorsTrail.activity.MonsterEncounterActivity;
import com.gpl.rpg.AndorsTrail.activity.MonsterInfoActivity;
import com.gpl.rpg.AndorsTrail.activity.ShopActivity;
import com.gpl.rpg.AndorsTrail.activity.SkillInfoActivity;
import com.gpl.rpg.AndorsTrail.activity.StartScreenActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail.activity.*;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionType;
@@ -43,6 +27,10 @@ import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail.view.ItemContainerAdapter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public final class Dialogs {
private static void showDialogAndPause(Dialog d, final ControllerContext context) {
@@ -230,20 +218,20 @@ public final class Dialogs {
});
}
public static void showItemInfo(final Activity currentActivity, String itemTypeID, int actionType, String buttonText, boolean buttonEnabled, int inventorySlot) {
Intent intent = new Intent(currentActivity, ItemInfoActivity.class);
public static Intent getIntentForItemInfo(final Context ctx, String itemTypeID, int actionType, String buttonText, boolean buttonEnabled, int inventorySlot) {
Intent intent = new Intent(ctx, ItemInfoActivity.class);
intent.putExtra("buttonText", buttonText);
intent.putExtra("buttonEnabled", buttonEnabled);
intent.putExtra("itemTypeID", itemTypeID);
intent.putExtra("actionType", actionType);
intent.putExtra("inventorySlot", inventorySlot);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/iteminfo/" + itemTypeID));
currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_ITEMINFO);
return intent;
}
public static void showLevelUp(final HeroinfoActivity_Stats currentActivity) {
Intent intent = new Intent(currentActivity, LevelUpActivity.class);
public static Intent getIntentForLevelUp(final Context ctx) {
Intent intent = new Intent(ctx, LevelUpActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/levelup"));
currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_LEVELUP);
return intent;
}
public static void showConfirmRest(final Activity currentActivity, final ControllerContext controllerContext, final MapObject area) {
@@ -303,31 +291,31 @@ public final class Dialogs {
context.startActivity(intent);
}
public static void showBulkBuyingInterface(ShopActivity currentActivity, String itemTypeID, int totalAvailableAmount) {
showBulkSelectionInterface(currentActivity, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BULK_INTERFACE_BUY, MainActivity.INTENTREQUEST_BULKSELECT_BUY);
public static Intent getIntentForBulkBuyingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BULK_INTERFACE_BUY);
}
public static void showBulkSellingInterface(ShopActivity currentActivity, String itemTypeID, int totalAvailableAmount) {
showBulkSelectionInterface(currentActivity, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BULK_INTERFACE_SELL, MainActivity.INTENTREQUEST_BULKSELECT_SELL);
public static Intent getIntentForBulkSellingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BULK_INTERFACE_SELL);
}
public static void showBulkDroppingInterface(HeroinfoActivity_Inventory currentActivity, String itemTypeID, int totalAvailableAmount) {
showBulkSelectionInterface(currentActivity, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BULK_INTERFACE_DROP, MainActivity.INTENTREQUEST_BULKSELECT_DROP);
public static Intent getIntentForBulkDroppingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BULK_INTERFACE_DROP);
}
private static void showBulkSelectionInterface(Activity currentActivity, String itemTypeID, int totalAvailableAmount, int interfaceType, int requestCode) {
Intent intent = new Intent(currentActivity, BulkSelectionInterface.class);
private static Intent getIntentForBulkSelectionInterface(final Context ctx, String itemTypeID, int totalAvailableAmount, int interfaceType) {
Intent intent = new Intent(ctx, BulkSelectionInterface.class);
intent.putExtra("itemTypeID", itemTypeID);
intent.putExtra("totalAvailableAmount", totalAvailableAmount);
intent.putExtra("interfaceType", interfaceType);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/bulkselection/" + itemTypeID));
currentActivity.startActivityForResult(intent, requestCode);
return intent;
}
public static void showSkillInfo(HeroinfoActivity_Skills currentActivity, int skillID) {
Intent intent = new Intent(currentActivity, SkillInfoActivity.class);
public static Intent getIntentForSkillInfo(final Context ctx, int skillID) {
Intent intent = new Intent(ctx, SkillInfoActivity.class);
intent.putExtra("skillID", skillID);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/showskillinfo/" + skillID));
currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_SKILLINFO);
return intent;
}
public static void showCombatLog(final Context context, final ControllerContext controllerContext, final WorldContext world) {

View File

@@ -1,19 +1,21 @@
package com.gpl.rpg.AndorsTrail.activity;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import android.app.ActivityGroup;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.activity.fragment.HeroinfoActivity_Inventory;
import com.gpl.rpg.AndorsTrail.activity.fragment.HeroinfoActivity_Quests;
import com.gpl.rpg.AndorsTrail.activity.fragment.HeroinfoActivity_Skills;
import com.gpl.rpg.AndorsTrail.activity.fragment.HeroinfoActivity_Stats;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
public final class HeroinfoActivity extends ActivityGroup {
public final class HeroinfoActivity extends FragmentActivity {
private WorldContext world;
private TabHost tabHost;
private FragmentTabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -24,25 +26,25 @@ public final class HeroinfoActivity extends ActivityGroup {
app.setWindowParameters(this);
setContentView(R.layout.heroinfo);
setContentView(R.layout.tabbedlayout);
Resources res = getResources();
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup(this.getLocalActivityManager());
tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
tabHost.addTab(tabHost.newTabSpec("char")
.setIndicator(res.getString(R.string.heroinfo_char), res.getDrawable(R.drawable.char_hero))
.setContent(new Intent(this, HeroinfoActivity_Stats.class)));
,HeroinfoActivity_Stats.class, null);
tabHost.addTab(tabHost.newTabSpec("quests")
.setIndicator(res.getString(R.string.heroinfo_quests), res.getDrawable(R.drawable.ui_icon_quest))
.setContent(new Intent(this, HeroinfoActivity_Quests.class)));
,HeroinfoActivity_Quests.class, null);
tabHost.addTab(tabHost.newTabSpec("skills")
.setIndicator(res.getString(R.string.heroinfo_skill), res.getDrawable(R.drawable.ui_icon_skill))
.setContent(new Intent(this, HeroinfoActivity_Skills.class)));
,HeroinfoActivity_Skills.class, null);
tabHost.addTab(tabHost.newTabSpec("inv")
.setIndicator(res.getString(R.string.heroinfo_inv), res.getDrawable(R.drawable.ui_icon_equipment))
.setContent(new Intent(this, HeroinfoActivity_Inventory.class)));
,HeroinfoActivity_Inventory.class, null);
String t = world.model.uiSelections.selectedTabHeroInfo;
if (t != null && t.length() > 0) {
tabHost.setCurrentTabByTag(t);

View File

@@ -39,14 +39,8 @@ import java.util.Collection;
public final class MainActivity extends Activity implements PlayerMovementListener, CombatActionListener, CombatTurnListener, WorldEventListener {
public static final int INTENTREQUEST_MONSTERENCOUNTER = 2;
public static final int INTENTREQUEST_ITEMINFO = 3;
public static final int INTENTREQUEST_CONVERSATION = 4;
public static final int INTENTREQUEST_LEVELUP = 6;
public static final int INTENTREQUEST_SAVEGAME = 8;
public static final int INTENTREQUEST_BULKSELECT_BUY = 9;
public static final int INTENTREQUEST_BULKSELECT_SELL = 10;
public static final int INTENTREQUEST_BULKSELECT_DROP = 11;
public static final int INTENTREQUEST_SKILLINFO = 12;
private ControllerContext controllers;
private WorldContext world;

View File

@@ -1,201 +1,36 @@
package com.gpl.rpg.AndorsTrail.activity;
import java.util.HashSet;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail.Dialogs;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.ItemController;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.ItemContainer;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter;
import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter.OnContainerItemClickedListener;
import com.gpl.rpg.AndorsTrail.activity.fragment.ShopActivity_Buy;
import com.gpl.rpg.AndorsTrail.activity.fragment.ShopActivity_Sell;
public final class ShopActivity extends TabActivity implements OnContainerItemClickedListener {
private WorldContext world;
private Player player;
public final class ShopActivity extends FragmentActivity {
private ItemContainer container_buy;
private TextView shop_buy_gc;
private TextView shop_sell_gc;
private ShopItemContainerAdapter buyListAdapter;
private ShopItemContainerAdapter sellListAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
this.world = app.getWorld();
this.player = world.model.player;
app.setWindowParameters(this);
final Monster npc = Dialogs.getMonsterFromIntent(getIntent(), world);
setContentView(R.layout.shop);
setContentView(R.layout.tabbedlayout);
final Resources res = getResources();
TabHost h = getTabHost();
h.addTab(h.newTabSpec("buy")
FragmentTabHost tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
tabHost.addTab(tabHost.newTabSpec("buy")
.setIndicator(res.getString(R.string.shop_buy))
.setContent(R.id.shop_tab1));
h.addTab(h.newTabSpec("sell")
.setIndicator(res.getString(R.string.shop_sell))
.setContent(R.id.shop_tab2));
h.setup();
shop_buy_gc = (TextView) h.findViewById(R.id.shop_buy_gc);
shop_sell_gc = (TextView) h.findViewById(R.id.shop_sell_gc);
ListView shoplist_buy = (ListView) h.findViewById(R.id.shop_buy_list);
ListView shoplist_sell = (ListView) h.findViewById(R.id.shop_sell_list);
container_buy = npc.getShopItems(player);
HashSet<Integer> iconIDs = world.tileManager.getTileIDsFor(container_buy);
iconIDs.addAll(world.tileManager.getTileIDsFor(player.inventory));
TileCollection tiles = world.tileManager.loadTilesFor(iconIDs, res);
buyListAdapter = new ShopItemContainerAdapter(this, tiles, world.tileManager, player, container_buy, this, false);
sellListAdapter = new ShopItemContainerAdapter(this, tiles, world.tileManager, player, player.inventory, this, true);
shoplist_buy.setAdapter(buyListAdapter);
shoplist_sell.setAdapter(sellListAdapter);
update();
}
@Override
public void onItemActionClicked(int position, ItemType itemType, boolean isSelling) {
if (isSelling) {
showSellingInterface(itemType);
} else {
showBuyingInterface(itemType);
}
}
@Override
public void onItemInfoClicked(int position, ItemType itemType, boolean isSelling) {
int price;
int resid;
boolean enableButton;
int action;
if (isSelling) {
resid = R.string.shop_sellitem;
action = ItemInfoActivity.ITEMACTION_SELL;
price = ItemController.getSellingPrice(player, itemType);
enableButton = ItemController.maySellItem(player, itemType);
} else {
resid = R.string.shop_buyitem;
action = ItemInfoActivity.ITEMACTION_BUY;
price = ItemController.getBuyingPrice(player, itemType);
enableButton = ItemController.canAfford(player, price);
}
String text = getResources().getString(resid, price);
Dialogs.showItemInfo(ShopActivity.this, itemType.id, action, text, enableButton, -1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case MainActivity.INTENTREQUEST_ITEMINFO:
if (resultCode != RESULT_OK) return;
ItemType itemType = world.itemTypes.getItemType(data.getExtras().getString("itemTypeID"));
int actionType = data.getExtras().getInt("actionType");
if (actionType == ItemInfoActivity.ITEMACTION_BUY) {
showBuyingInterface(itemType);
} else if (actionType == ItemInfoActivity.ITEMACTION_SELL) {
showSellingInterface(itemType);
}
break;
case MainActivity.INTENTREQUEST_BULKSELECT_BUY:
if (resultCode == Activity.RESULT_OK) {
int quantity = data.getExtras().getInt("selectedAmount");
String itemTypeID = data.getExtras().getString("itemTypeID");
buy(itemTypeID, quantity);
}
break;
case MainActivity.INTENTREQUEST_BULKSELECT_SELL:
if (resultCode == Activity.RESULT_OK) {
int quantity = data.getExtras().getInt("selectedAmount");
String itemTypeID = data.getExtras().getString("itemTypeID");
sell(itemTypeID, quantity);
}
break;
}
}
private void showSellingInterface(ItemType itemType) {
Dialogs.showBulkSellingInterface(this, itemType.id, player.inventory.getItemQuantity(itemType.id));
}
private void showBuyingInterface(ItemType itemType) {
Dialogs.showBulkBuyingInterface(this, itemType.id, container_buy.getItemQuantity(itemType.id));
}
private void buy(String itemTypeID, int quantity) {
ItemType itemType = world.itemTypes.getItemType(itemTypeID);
ItemController.buy(world.model, player, itemType, container_buy, quantity);
final String msg = getResources().getString(R.string.shop_item_bought, itemType.getName(player));
displayStoreAction(msg);
}
private void sell(String itemTypeID, int quantity) {
ItemType itemType = world.itemTypes.getItemType(itemTypeID);
ItemController.sell(player, itemType, container_buy, quantity);
final String msg = getResources().getString(R.string.shop_item_sold, itemType.getName(player));
displayStoreAction(msg);
}
private Toast lastToast = null;
private void displayStoreAction(final String msg) {
if (lastToast != null) {
lastToast.setText(msg);
} else {
lastToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
}
lastToast.show();
update();
}
@Override
protected void onPause() {
super.onPause();
lastToast = null;
}
private void update() {
updateBuyItemList();
updateSellItemList();
updateGc();
}
private void updateGc() {
String gc = getResources().getString(R.string.shop_yourgold, player.getGold());
shop_buy_gc.setText(gc);
shop_sell_gc.setText(gc);
}
private void updateBuyItemList() {
buyListAdapter.notifyDataSetChanged();
}
private void updateSellItemList() {
sellListAdapter.notifyDataSetChanged();
,ShopActivity_Buy.class, null);
tabHost.addTab(tabHost.newTabSpec("sell")
.setIndicator(res.getString(R.string.shop_sell))
,ShopActivity_Sell.class, null);
}
}

View File

@@ -1,8 +1,22 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail.activity.fragment;
import com.gpl.rpg.AndorsTrail.Dialogs;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.Dialogs;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.activity.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.ItemController;
@@ -13,23 +27,11 @@ import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.view.ItemContainerAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
public final class HeroinfoActivity_Inventory extends Fragment {
private static final int INTENTREQUEST_ITEMINFO = 3;
private static final int INTENTREQUEST_BULKSELECT_DROP = 11;
public final class HeroinfoActivity_Inventory extends Activity {
private WorldContext world;
private ControllerContext controllers;
private TileCollection wornTiles;
@@ -49,15 +51,18 @@ public final class HeroinfoActivity_Inventory extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this.getActivity());
if (!app.isInitialized()) return;
this.world = app.getWorld();
this.controllers = app.getControllerContext();
this.player = world.model.player;
setContentView(R.layout.heroinfo_inventory);
}
ListView inventoryList = (ListView) findViewById(R.id.inventorylist_root);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.heroinfo_inventory, container, false);
ListView inventoryList = (ListView) v.findViewById(R.id.inventorylist_root);
registerForContextMenu(inventoryList);
inventoryList.setOnItemClickListener(new OnItemClickListener() {
@Override
@@ -66,34 +71,36 @@ public final class HeroinfoActivity_Inventory extends Activity {
showInventoryItemInfo(itemType.id);
}
});
ItemContainer container = player.inventory;
ItemContainer inv = player.inventory;
wornTiles = world.tileManager.loadTilesFor(player.inventory, getResources());
inventoryListAdapter = new ItemContainerAdapter(this, world.tileManager, container, player, wornTiles);
inventoryListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, inv, player, wornTiles);
inventoryList.setAdapter(inventoryListAdapter);
heroinfo_stats_gold = (TextView) findViewById(R.id.heroinfo_stats_gold);
heroinfo_stats_attack = (TextView) findViewById(R.id.heroinfo_stats_attack);
heroinfo_stats_defense = (TextView) findViewById(R.id.heroinfo_stats_defense);
heroinfo_stats_gold = (TextView) v.findViewById(R.id.heroinfo_stats_gold);
heroinfo_stats_attack = (TextView) v.findViewById(R.id.heroinfo_stats_attack);
heroinfo_stats_defense = (TextView) v.findViewById(R.id.heroinfo_stats_defense);
setWearSlot(Inventory.WEARSLOT_WEAPON, R.id.heroinfo_worn_weapon, R.drawable.equip_weapon);
setWearSlot(Inventory.WEARSLOT_SHIELD, R.id.heroinfo_worn_shield, R.drawable.equip_shield);
setWearSlot(Inventory.WEARSLOT_HEAD, R.id.heroinfo_worn_head, R.drawable.equip_head);
setWearSlot(Inventory.WEARSLOT_BODY, R.id.heroinfo_worn_body, R.drawable.equip_body);
setWearSlot(Inventory.WEARSLOT_FEET, R.id.heroinfo_worn_feet, R.drawable.equip_feet);
setWearSlot(Inventory.WEARSLOT_NECK, R.id.heroinfo_worn_neck, R.drawable.equip_neck);
setWearSlot(Inventory.WEARSLOT_HAND, R.id.heroinfo_worn_hand, R.drawable.equip_hand);
setWearSlot(Inventory.WEARSLOT_LEFTRING, R.id.heroinfo_worn_ringleft, R.drawable.equip_ring);
setWearSlot(Inventory.WEARSLOT_RIGHTRING, R.id.heroinfo_worn_ringright, R.drawable.equip_ring);
setWearSlot(v, Inventory.WEARSLOT_WEAPON, R.id.heroinfo_worn_weapon, R.drawable.equip_weapon);
setWearSlot(v, Inventory.WEARSLOT_SHIELD, R.id.heroinfo_worn_shield, R.drawable.equip_shield);
setWearSlot(v, Inventory.WEARSLOT_HEAD, R.id.heroinfo_worn_head, R.drawable.equip_head);
setWearSlot(v, Inventory.WEARSLOT_BODY, R.id.heroinfo_worn_body, R.drawable.equip_body);
setWearSlot(v, Inventory.WEARSLOT_FEET, R.id.heroinfo_worn_feet, R.drawable.equip_feet);
setWearSlot(v, Inventory.WEARSLOT_NECK, R.id.heroinfo_worn_neck, R.drawable.equip_neck);
setWearSlot(v, Inventory.WEARSLOT_HAND, R.id.heroinfo_worn_hand, R.drawable.equip_hand);
setWearSlot(v, Inventory.WEARSLOT_LEFTRING, R.id.heroinfo_worn_ringleft, R.drawable.equip_ring);
setWearSlot(v, Inventory.WEARSLOT_RIGHTRING, R.id.heroinfo_worn_ringright, R.drawable.equip_ring);
return v;
}
@Override
protected void onResume() {
super.onResume();
public void onStart() {
super.onStart();
update();
}
private void setWearSlot(final int inventorySlot, int viewId, int resourceId) {
final ImageView imageView = (ImageView) findViewById(viewId);
private void setWearSlot(final View v, final int inventorySlot, int viewId, int resourceId) {
final ImageView imageView = (ImageView) v.findViewById(viewId);
wornItemImage[inventorySlot] = imageView;
defaultWornItemImageResourceIDs[inventorySlot] = resourceId;
imageView.setOnClickListener(new OnClickListener() {
@@ -105,13 +112,13 @@ public final class HeroinfoActivity_Inventory extends Activity {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case MainActivity.INTENTREQUEST_ITEMINFO:
if (resultCode != RESULT_OK) break;
case INTENTREQUEST_ITEMINFO:
if (resultCode != Activity.RESULT_OK) break;
ItemType itemType = world.itemTypes.getItemType(data.getExtras().getString("itemTypeID"));
int actionType = data.getExtras().getInt("actionType");
@@ -124,14 +131,15 @@ public final class HeroinfoActivity_Inventory extends Activity {
controllers.itemController.useItem(itemType);
}
break;
case MainActivity.INTENTREQUEST_BULKSELECT_DROP:
if (resultCode != RESULT_OK) break;
case INTENTREQUEST_BULKSELECT_DROP:
if (resultCode != Activity.RESULT_OK) break;
int quantity = data.getExtras().getInt("selectedAmount");
String itemTypeID = data.getExtras().getString("itemTypeID");
dropItem(itemTypeID, quantity);
break;
}
update();
}
private int suggestInventorySlot(ItemType itemType) {
@@ -199,7 +207,7 @@ public final class HeroinfoActivity_Inventory extends Activity {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
ItemType type = getSelectedItemType((AdapterContextMenuInfo) menuInfo);
MenuInflater inflater = getMenuInflater();
MenuInflater inflater = getActivity().getMenuInflater();
switch (v.getId()) {
case R.id.inventorylist_root:
inflater.inflate(R.menu.inventoryitem, menu);
@@ -233,7 +241,8 @@ public final class HeroinfoActivity_Inventory extends Activity {
String itemTypeID = getSelectedItemType(info).id;
int quantity = player.inventory.getItemQuantity(itemTypeID);
if (quantity > 1) {
Dialogs.showBulkDroppingInterface(this, itemTypeID, quantity);
Intent intent = Dialogs.getIntentForBulkDroppingInterface(getActivity(), itemTypeID, quantity);
startActivityForResult(intent, INTENTREQUEST_BULKSELECT_DROP);
} else {
dropItem(itemTypeID, quantity);
}
@@ -290,7 +299,8 @@ public final class HeroinfoActivity_Inventory extends Activity {
} else {
text = getResources().getString(R.string.iteminfo_action_unequip);
}
Dialogs.showItemInfo(HeroinfoActivity_Inventory.this, itemType.id, ItemInfoActivity.ITEMACTION_UNEQUIP, text, enabled, inventorySlot);
Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, ItemInfoActivity.ITEMACTION_UNEQUIP, text, enabled, inventorySlot);
startActivityForResult(intent, INTENTREQUEST_ITEMINFO);
}
private void showInventoryItemInfo(String itemTypeID) {
showInventoryItemInfo(world.itemTypes.getItemType(itemTypeID));
@@ -321,8 +331,8 @@ public final class HeroinfoActivity_Inventory extends Activity {
if (isInCombat && ap > 0) {
enabled = world.model.player.hasAPs(ap);
}
Dialogs.showItemInfo(HeroinfoActivity_Inventory.this, itemType.id, action, text, enabled, -1);
Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, action, text, enabled, -1);
startActivityForResult(intent, INTENTREQUEST_ITEMINFO);
}
}

View File

@@ -1,54 +1,54 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail.activity.fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.widget.AdapterView.OnItemSelectedListener;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.quest.Quest;
import com.gpl.rpg.AndorsTrail.model.quest.QuestLogEntry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
public final class HeroinfoActivity_Quests extends Fragment {
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.quest.Quest;
import com.gpl.rpg.AndorsTrail.model.quest.QuestCollection;
import com.gpl.rpg.AndorsTrail.model.quest.QuestLogEntry;
public final class HeroinfoActivity_Quests extends Activity {
private WorldContext world;
private Spinner questlog_includecompleted;
private SimpleExpandableListAdapter questlog_contents_adapter;
private QuestCollection questCollection;
private Player player;
private final List<Map<String, ?>> groupList = new ArrayList<Map<String, ?>>();
private final List<List<Map<String, ?>>> childList = new ArrayList<List<Map<String,?>>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
app.setWindowParameters(this);
final WorldContext world = app.getWorld();
this.questCollection = world.quests;
final AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this.getActivity());
if (!app.isInitialized()) return;
this.world = app.getWorld();
this.player = world.model.player;
setContentView(R.layout.questlog);
questlog_includecompleted = (Spinner) findViewById(R.id.questlog_includecompleted);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.questlog_includecompleted, android.R.layout.simple_spinner_item);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.questlog, container, false);
Context ctx = getActivity();
questlog_includecompleted = (Spinner) v.findViewById(R.id.questlog_includecompleted);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(ctx, R.array.questlog_includecompleted, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
questlog_includecompleted.setAdapter(adapter);
questlog_includecompleted.setOnItemSelectedListener(new OnItemSelectedListener() {
@@ -63,9 +63,9 @@ public final class HeroinfoActivity_Quests extends Activity {
});
questlog_includecompleted.setSelection(world.model.uiSelections.selectedQuestFilter);
ExpandableListView questlog_contents = (ExpandableListView) findViewById(R.id.questlog_contents);
ExpandableListView questlog_contents = (ExpandableListView) v.findViewById(R.id.questlog_contents);
questlog_contents_adapter = new SimpleExpandableListAdapter(
this
ctx
, groupList
, android.R.layout.simple_expandable_list_item_2
, new String[] { mn_questName, mn_questStatus }
@@ -76,6 +76,8 @@ public final class HeroinfoActivity_Quests extends Activity {
, new int[] { R.id.questlog_entrytext }
);
questlog_contents.setAdapter(questlog_contents_adapter);
return v;
}
private static final String mn_questName = "questName";
@@ -83,8 +85,18 @@ public final class HeroinfoActivity_Quests extends Activity {
private static final String mn_logText = "logText";
@Override
public void onResume() {
super.onResume();
public void onStart() {
super.onStart();
update();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
update();
}
private void update() {
reloadQuests();
}
@@ -92,7 +104,7 @@ public final class HeroinfoActivity_Quests extends Activity {
groupList.clear();
childList.clear();
for (Quest q : questCollection.getAllQuests()) {
for (Quest q : world.quests.getAllQuests()) {
if (!q.showInLog) continue; // Do not show
if (player.hasAnyQuestProgress(q.questID)) {
boolean isCompleted = q.isCompleted(player);

View File

@@ -1,9 +1,12 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail.activity.fragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
@@ -16,58 +19,70 @@ import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.view.SkillListAdapter;
public final class HeroinfoActivity_Skills extends Activity {
public final class HeroinfoActivity_Skills extends Fragment {
private static final int INTENTREQUEST_SKILLINFO = 12;
private WorldContext world;
private ControllerContext controllers;
private Player player;
private SkillListAdapter skillListAdapter;
@Override
private TextView listskills_number_of_increases;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(getActivity());
if (!app.isInitialized()) return;
this.world = app.getWorld();
this.controllers = app.getControllerContext();
this.controllers = app.getControllerContext();
this.player = world.model.player;
setContentView(R.layout.heroinfo_skill_list);
skillListAdapter = new SkillListAdapter(this, world.skills.getAllSkills(), player);
ListView skillList = (ListView) findViewById(R.id.heroinfo_listskills_list);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.heroinfo_skill_list, container, false);
final Activity ctx = getActivity();
skillListAdapter = new SkillListAdapter(ctx, world.skills.getAllSkills(), player);
ListView skillList = (ListView) v.findViewById(R.id.heroinfo_listskills_list);
skillList.setAdapter(skillListAdapter);
skillList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Dialogs.showSkillInfo(HeroinfoActivity_Skills.this, (int) id);
Intent intent = Dialogs.getIntentForSkillInfo(ctx, (int) id);
startActivityForResult(intent, INTENTREQUEST_SKILLINFO);
}
});
listskills_number_of_increases = (TextView) v.findViewById(R.id.heroinfo_listskills_number_of_increases);
return v;
}
@Override
protected void onResume() {
super.onResume();
updateSkillList();
}
@Override
public void onStart() {
super.onStart();
update();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case MainActivity.INTENTREQUEST_SKILLINFO:
if (resultCode != RESULT_OK) break;
case INTENTREQUEST_SKILLINFO:
if (resultCode != Activity.RESULT_OK) break;
int skillID = data.getExtras().getInt("skillID");
controllers.skillController.levelUpSkillManually(player, world.skills.getSkill(skillID));
break;
}
update();
}
private void update() {
updateSkillList();
}
private void updateSkillList() {
TextView listskills_number_of_increases = (TextView) findViewById(R.id.heroinfo_listskills_number_of_increases);
int numberOfSkillIncreases = player.getAvailableSkillIncreases();
if (numberOfSkillIncreases > 0) {
if (numberOfSkillIncreases == 1) {

View File

@@ -1,9 +1,17 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail.activity.fragment;
import java.util.ArrayList;
import com.gpl.rpg.AndorsTrail.Dialogs;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.Dialogs;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
@@ -14,18 +22,13 @@ import com.gpl.rpg.AndorsTrail.view.ItemEffectsView;
import com.gpl.rpg.AndorsTrail.view.RangeBar;
import com.gpl.rpg.AndorsTrail.view.TraitsInfoView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;
import java.util.ArrayList;
public final class HeroinfoActivity_Stats extends Activity {
public final class HeroinfoActivity_Stats extends Fragment {
private static final int INTENTREQUEST_LEVELUP = 6;
private WorldContext world;
private Player player;
private Button levelUpButton;
@@ -43,44 +46,48 @@ public final class HeroinfoActivity_Stats extends Activity {
private ItemEffectsView actorinfo_onhiteffects;
private TableLayout heroinfo_basestats_table;
private ViewGroup heroinfo_container;
@Override
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
final WorldContext world = app.getWorld();
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this.getActivity());
if (!app.isInitialized()) return;
this.world = app.getWorld();
this.player = world.model.player;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.heroinfo_stats, container, false);
setContentView(R.layout.heroinfo_stats);
TextView tv = (TextView) findViewById(R.id.heroinfo_title);
TextView tv = (TextView) v.findViewById(R.id.heroinfo_title);
tv.setText(player.getName());
world.tileManager.setImageViewTile(getResources(), tv, player);
heroinfo_container = (ViewGroup) findViewById(R.id.heroinfo_container);
heroinfo_ap = (TextView) findViewById(R.id.heroinfo_ap);
heroinfo_reequip_cost = (TextView) findViewById(R.id.heroinfo_reequip_cost);
heroinfo_useitem_cost = (TextView) findViewById(R.id.heroinfo_useitem_cost);
basetraitsinfo_max_hp = (TextView) findViewById(R.id.basetraitsinfo_max_hp);
basetraitsinfo_max_ap = (TextView) findViewById(R.id.basetraitsinfo_max_ap);
heroinfo_base_reequip_cost = (TextView) findViewById(R.id.heroinfo_base_reequip_cost);
heroinfo_base_useitem_cost = (TextView) findViewById(R.id.heroinfo_base_useitem_cost);
heroinfo_level = (TextView) findViewById(R.id.heroinfo_level);
heroinfo_totalexperience = (TextView) findViewById(R.id.heroinfo_totalexperience);
actorinfo_onhiteffects = (ItemEffectsView) findViewById(R.id.actorinfo_onhiteffects);
heroinfo_basestats_table = (TableLayout) findViewById(R.id.heroinfo_basestats_table);
heroinfo_container = (ViewGroup) v.findViewById(R.id.heroinfo_container);
heroinfo_ap = (TextView) v.findViewById(R.id.heroinfo_ap);
heroinfo_reequip_cost = (TextView) v.findViewById(R.id.heroinfo_reequip_cost);
heroinfo_useitem_cost = (TextView) v.findViewById(R.id.heroinfo_useitem_cost);
basetraitsinfo_max_hp = (TextView) v.findViewById(R.id.basetraitsinfo_max_hp);
basetraitsinfo_max_ap = (TextView) v.findViewById(R.id.basetraitsinfo_max_ap);
heroinfo_base_reequip_cost = (TextView) v.findViewById(R.id.heroinfo_base_reequip_cost);
heroinfo_base_useitem_cost = (TextView) v.findViewById(R.id.heroinfo_base_useitem_cost);
heroinfo_level = (TextView) v.findViewById(R.id.heroinfo_level);
heroinfo_totalexperience = (TextView) v.findViewById(R.id.heroinfo_totalexperience);
actorinfo_onhiteffects = (ItemEffectsView) v.findViewById(R.id.actorinfo_onhiteffects);
heroinfo_basestats_table = (TableLayout) v.findViewById(R.id.heroinfo_basestats_table);
rangebar_hp = (RangeBar) findViewById(R.id.heroinfo_healthbar);
rangebar_hp = (RangeBar) v.findViewById(R.id.heroinfo_healthbar);
rangebar_hp.init(R.drawable.ui_progress_health, R.string.status_hp);
rangebar_exp = (RangeBar) findViewById(R.id.heroinfo_expbar);
rangebar_exp = (RangeBar) v.findViewById(R.id.heroinfo_expbar);
rangebar_exp.init(R.drawable.ui_progress_exp, R.string.status_exp);
levelUpButton = (Button) findViewById(R.id.heroinfo_levelup);
levelUpButton = (Button) v.findViewById(R.id.heroinfo_levelup);
levelUpButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Dialogs.showLevelUp(HeroinfoActivity_Stats.this);
Intent intent = Dialogs.getIntentForLevelUp(getActivity());
startActivityForResult(intent, INTENTREQUEST_LEVELUP);
// We disable the button temporarily, so that there is no possibility
// of clicking it again before the levelup activity has started.
// See issue:
@@ -88,22 +95,25 @@ public final class HeroinfoActivity_Stats extends Activity {
levelUpButton.setEnabled(false);
}
});
return v;
}
@Override
protected void onResume() {
super.onResume();
updateTraits();
updateLevelup();
public void onStart() {
super.onStart();
update();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case MainActivity.INTENTREQUEST_LEVELUP:
break;
}
update();
}
private void update() {
updateTraits();
updateLevelup();
}
private void updateLevelup() {

View File

@@ -0,0 +1,100 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.Dialogs;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.ItemContainer;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter;
import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter.OnContainerItemClickedListener;
import java.util.HashSet;
public abstract class ShopActivityFragment extends Fragment implements OnContainerItemClickedListener {
protected static final int INTENTREQUEST_ITEMINFO = 3;
protected static final int INTENTREQUEST_BULKSELECT = 9;
protected WorldContext world;
protected Player player;
protected ItemContainer shopInventory;
private TextView shop_gc;
private ShopItemContainerAdapter listAdapter;
protected abstract boolean isSellingInterface();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(getActivity());
if (!app.isInitialized()) return;
this.world = app.getWorld();
this.player = world.model.player;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.shoplist, container, false);
final Monster npc = Dialogs.getMonsterFromIntent(getActivity().getIntent(), world);
final Resources res = getResources();
shop_gc = (TextView) v.findViewById(R.id.shop_gc);
ListView shoplist = (ListView) v.findViewById(R.id.shop_list);
shopInventory = npc.getShopItems(player);
HashSet<Integer> iconIDs = world.tileManager.getTileIDsFor(shopInventory);
iconIDs.addAll(world.tileManager.getTileIDsFor(player.inventory));
TileCollection tiles = world.tileManager.loadTilesFor(iconIDs, res);
final boolean isSelling = isSellingInterface();
listAdapter = new ShopItemContainerAdapter(getActivity(), tiles, world.tileManager, player, isSelling ? player.inventory : shopInventory, this, isSelling);
shoplist.setAdapter(listAdapter);
return v;
}
@Override
public void onStart() {
super.onStart();
update();
}
private Toast lastToast = null;
protected void displayStoreAction(final String msg) {
if (lastToast != null) {
lastToast.setText(msg);
} else {
lastToast = Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT);
}
lastToast.show();
update();
}
@Override
public void onPause() {
super.onPause();
lastToast = null;
}
protected void update() {
listAdapter.notifyDataSetChanged();
String gc = getResources().getString(R.string.shop_yourgold, player.getGold());
shop_gc.setText(gc);
}
}

View File

@@ -0,0 +1,60 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
import android.app.Activity;
import android.content.Intent;
import com.gpl.rpg.AndorsTrail.Dialogs;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.activity.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail.controller.ItemController;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
public final class ShopActivity_Buy extends ShopActivityFragment {
@Override
protected boolean isSellingInterface() {
return false;
}
@Override
public void onItemActionClicked(int position, ItemType itemType) {
showBuyingInterface(itemType);
}
@Override
public void onItemInfoClicked(int position, ItemType itemType) {
int price = ItemController.getBuyingPrice(player, itemType);
boolean enableButton = ItemController.canAfford(player, price);
String text = getResources().getString(R.string.shop_buyitem, price);
Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, ItemInfoActivity.ITEMACTION_BUY, text, enableButton, -1);
startActivityForResult(intent, INTENTREQUEST_ITEMINFO);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK) return;
ItemType itemType = world.itemTypes.getItemType(data.getExtras().getString("itemTypeID"));
switch (requestCode) {
case INTENTREQUEST_ITEMINFO:
showBuyingInterface(itemType);
break;
case INTENTREQUEST_BULKSELECT:
int quantity = data.getExtras().getInt("selectedAmount");
buy(itemType, quantity);
break;
}
update();
}
private void showBuyingInterface(ItemType itemType) {
Intent intent = Dialogs.getIntentForBulkBuyingInterface(getActivity(), itemType.id, shopInventory.getItemQuantity(itemType.id));
startActivityForResult(intent, INTENTREQUEST_BULKSELECT);
}
private void buy(ItemType itemType, int quantity) {
if (!ItemController.buy(world.model, player, itemType, shopInventory, quantity)) return;
final String msg = getResources().getString(R.string.shop_item_bought, itemType.getName(player));
displayStoreAction(msg);
}
}

View File

@@ -0,0 +1,60 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
import android.app.Activity;
import android.content.Intent;
import com.gpl.rpg.AndorsTrail.Dialogs;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.activity.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail.controller.ItemController;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
public final class ShopActivity_Sell extends ShopActivityFragment {
@Override
protected boolean isSellingInterface() {
return true;
}
@Override
public void onItemActionClicked(int position, ItemType itemType) {
showSellingInterface(itemType);
}
@Override
public void onItemInfoClicked(int position, ItemType itemType) {
int price = ItemController.getSellingPrice(player, itemType);
boolean enableButton = ItemController.maySellItem(player, itemType);
String text = getResources().getString(R.string.shop_sellitem, price);
Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, ItemInfoActivity.ITEMACTION_SELL, text, enableButton, -1);
startActivityForResult(intent, INTENTREQUEST_ITEMINFO);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK) return;
ItemType itemType = world.itemTypes.getItemType(data.getExtras().getString("itemTypeID"));
switch (requestCode) {
case INTENTREQUEST_ITEMINFO:
showSellingInterface(itemType);
break;
case INTENTREQUEST_BULKSELECT:
int quantity = data.getExtras().getInt("selectedAmount");
sell(itemType, quantity);
break;
}
update();
}
private void showSellingInterface(ItemType itemType) {
Intent intent = Dialogs.getIntentForBulkSellingInterface(getActivity(), itemType.id, player.inventory.getItemQuantity(itemType.id));
startActivityForResult(intent, INTENTREQUEST_BULKSELECT);
}
private void sell(ItemType itemType, int quantity) {
if (!ItemController.sell(player, itemType, shopInventory, quantity)) return;
final String msg = getResources().getString(R.string.shop_item_sold, itemType.getName(player));
displayStoreAction(msg);
}
}

View File

@@ -243,21 +243,22 @@ public final class ItemController {
if (!itemType.isSellable()) return false;
return true;
}
public static void sell(Player player, ItemType itemType, ItemContainer merchant, int quantity) {
public static boolean sell(Player player, ItemType itemType, ItemContainer merchant, int quantity) {
int price = getSellingPrice(player, itemType) * quantity;
if (player.inventory.removeItem(itemType.id, quantity)) {
player.inventory.gold += price;
merchant.addItem(itemType, quantity);
}
if (!maySellItem(player, itemType)) return false;
if (!player.inventory.removeItem(itemType.id, quantity)) return false;
player.inventory.gold += price;
merchant.addItem(itemType, quantity);
return true;
}
public static void buy(ModelContainer model, Player player, ItemType itemType, ItemContainer merchant, int quantity) {
public static boolean buy(ModelContainer model, Player player, ItemType itemType, ItemContainer merchant, int quantity) {
int price = getBuyingPrice(player, itemType) * quantity;
if (!canAfford(player, price)) return;
if (merchant.removeItem(itemType.id, quantity)) {
player.inventory.gold -= price;
player.inventory.addItem(itemType, quantity);
model.statistics.addGoldSpent(price);
}
if (!canAfford(player, price)) return false;
if (!merchant.removeItem(itemType.id, quantity)) return false;
player.inventory.gold -= price;
player.inventory.addItem(itemType, quantity);
model.statistics.addGoldSpent(price);
return true;
}

View File

@@ -61,14 +61,14 @@ public final class ShopItemContainerAdapter extends ArrayAdapter<ItemEntry> {
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
clickListener.onItemActionClicked(position, itemType, isSelling);
clickListener.onItemActionClicked(position, itemType);
}
});
b = (Button) result.findViewById(R.id.shopitem_infobutton);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
clickListener.onItemInfoClicked(position, itemType, isSelling);
clickListener.onItemInfoClicked(position, itemType);
}
});
return result;
@@ -80,7 +80,7 @@ public final class ShopItemContainerAdapter extends ArrayAdapter<ItemEntry> {
}
public static interface OnContainerItemClickedListener {
void onItemActionClicked(int position, ItemType itemType, boolean isSelling);
void onItemInfoClicked(int position, ItemType itemType, boolean isSelling);
void onItemActionClicked(int position, ItemType itemType);
void onItemInfoClicked(int position, ItemType itemType);
}
}