v0.7.17dev

package="com.gpl.rpg.AndorsTrail_beta1"
This commit is contained in:
Nut.andor
2022-04-08 23:30:14 +02:00
parent cc6a573ef0
commit 5378279d46
227 changed files with 9371 additions and 9423 deletions

View File

@@ -2,9 +2,9 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gpl.rpg.AndorsTrail"
package="com.gpl.rpg.AndorsTrail_beta1"
android:versionCode="64"
android:versionName="0.7.17"
android:versionName="0.7.17dev"
android:installLocation="auto"
>
<uses-sdk
@@ -26,7 +26,7 @@
<application
android:name=".AndorsTrailApplication"
android:name="com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication"
android:label="@string/app_name"
android:icon="@drawable/icon"
android:description="@string/app_description"
@@ -38,7 +38,7 @@
android:debuggable="true"
>
<activity
android:name=".activity.StartScreenActivity"
android:name="com.gpl.rpg.AndorsTrail_beta1.activity.StartScreenActivity"
android:clearTaskOnLaunch="true"
>
<intent-filter>
@@ -47,29 +47,29 @@
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
android:name="com.gpl.rpg.AndorsTrail_beta1.activity.MainActivity"
android:label="@string/app_name"
android:theme="@style/AndorsTrailTheme_Blue.NoBackground"
/>
<activity android:name=".activity.HeroinfoActivity" />
<activity android:name=".activity.MonsterInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.ItemInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.LevelUpActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.MonsterEncounterActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.ConversationActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.ShopActivity" />
<activity android:name=".activity.AboutActivity" />
<activity android:name=".activity.LoadingActivity" />
<activity android:name=".activity.Preferences" />
<activity android:name=".activity.LoadSaveActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.ActorConditionInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.BulkSelectionInterface" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.SkillInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name=".activity.DisplayWorldMapActivity" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.HeroinfoActivity" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.MonsterInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.ItemInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.LevelUpActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.MonsterEncounterActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.ConversationActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.ShopActivity" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.AboutActivity" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.LoadingActivity" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.Preferences" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.LoadSaveActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.ActorConditionInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.BulkSelectionInterface" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.SkillInfoActivity" android:theme="@style/AndorsTrailDialogTheme_Blue" />
<activity android:name="com.gpl.rpg.AndorsTrail_beta1.activity.DisplayWorldMapActivity" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.gpl.rpg.AndorsTrail.fileprovider"
android:authorities="com.gpl.rpg.AndorsTrail_beta1.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.gpl.rpg.AndorsTrail" >
xmlns:app="http://schemas.android.com/apk/res/com.gpl.rpg.AndorsTrail_beta1" >
<item app:single="true" android:drawable="@drawable/ui_blue_buttonbar_frame_solo" />

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.gpl.rpg.AndorsTrail" >
xmlns:app="http://schemas.android.com/apk/res/com.gpl.rpg.AndorsTrail_beta1" >
<item app:single="true" android:drawable="@drawable/ui_charcoal_buttonbar_frame_solo" />

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.gpl.rpg.AndorsTrail" >
xmlns:app="http://schemas.android.com/apk/res/com.gpl.rpg.AndorsTrail_beta1" >
<item app:single="true" android:drawable="@drawable/ui_green_buttonbar_frame_solo" />

View File

@@ -6,7 +6,7 @@
<include layout="@layout/title_bg_sky_layout"/>
<com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView
<com.gpl.rpg.AndorsTrail_beta1.view.CloudsAnimatorView
android:id="@+id/ts_clouds_animator_back"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -19,7 +19,7 @@
android:scaleType="fitEnd"
android:src="@drawable/ts_background"/>
<com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView
<com.gpl.rpg.AndorsTrail_beta1.view.CloudsAnimatorView
android:id="@+id/ts_clouds_animator_mid"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -32,7 +32,7 @@
android:scaleType="fitEnd"
android:src="@drawable/ts_midground"/>
<com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView
<com.gpl.rpg.AndorsTrail_beta1.view.CloudsAnimatorView
android:id="@+id/ts_clouds_animator_front"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -37,7 +37,7 @@
android:layout_height="wrap_content"
android:text="@string/actorconditioninfo_constant_effect" />
<com.gpl.rpg.AndorsTrail.view.AbilityModifierInfoView
<com.gpl.rpg.AndorsTrail_beta1.view.AbilityModifierInfoView
android:id="@+id/actorconditioninfo_constant_effect_abilitymodifierinfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -29,7 +29,7 @@
android:text="@string/combat_attack"
android:textSize="@dimen/actionbar_text" />
<com.gpl.rpg.AndorsTrail.view.RangeBar
<com.gpl.rpg.AndorsTrail_beta1.view.RangeBar
android:id="@+id/combatview_status"
android:layout_width="0dp"
android:layout_height="wrap_content"
@@ -107,7 +107,7 @@
android:padding="8dp"
android:scaleType="fitCenter" />
<com.gpl.rpg.AndorsTrail.view.RangeBar
<com.gpl.rpg.AndorsTrail_beta1.view.RangeBar
android:id="@+id/combatview_monsterhealth"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.gpl.rpg.AndorsTrail.view.SelectableTextView xmlns:android="http://schemas.android.com/apk/res/android"
<com.gpl.rpg.AndorsTrail_beta1.view.SelectableTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@style/checkedListItem"
android:layout_width="match_parent"

View File

@@ -72,18 +72,18 @@
android:background="?attr/ui_theme_stdframe_bitmap"
android:orientation="vertical" >
<com.gpl.rpg.AndorsTrail.view.RangeBar
<com.gpl.rpg.AndorsTrail_beta1.view.RangeBar
android:id="@+id/heroinfo_healthbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.gpl.rpg.AndorsTrail.view.RangeBar
<com.gpl.rpg.AndorsTrail_beta1.view.RangeBar
android:id="@+id/heroinfo_expbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5sp" />
<com.gpl.rpg.AndorsTrail.view.RangeBar
<com.gpl.rpg.AndorsTrail_beta1.view.RangeBar
android:id="@+id/heroinfo_apbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -144,7 +144,7 @@
<include layout="@layout/traitsinfoview" />
</TableLayout>
<com.gpl.rpg.AndorsTrail.view.ItemEffectsView
<com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView
android:id="@+id/actorinfo_onhiteffects"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
@@ -156,7 +156,7 @@
android:layout_height="wrap_content"
android:text="@string/actorinfo_currentconditions" />
<com.gpl.rpg.AndorsTrail.view.ActorConditionList
<com.gpl.rpg.AndorsTrail_beta1.view.ActorConditionList
android:id="@+id/actorinfo_currentconditions"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

View File

@@ -12,14 +12,14 @@
android:layout_height="wrap_content"
/>
<com.gpl.rpg.AndorsTrail.view.AbilityModifierInfoView
<com.gpl.rpg.AndorsTrail_beta1.view.AbilityModifierInfoView
android:id="@+id/itemeffect_onequip_abilitymodifierinfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10sp"
/>
<com.gpl.rpg.AndorsTrail.view.ActorConditionEffectList
<com.gpl.rpg.AndorsTrail_beta1.view.ActorConditionEffectList
android:id="@+id/itemeffect_onequip_conditions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -32,7 +32,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.gpl.rpg.AndorsTrail.view.ItemEffectsView_OnUse
<com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView_OnUse
android:id="@+id/itemeffect_onuse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -45,7 +45,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.gpl.rpg.AndorsTrail.view.ItemEffectsView_OnUse
<com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView_OnUse
android:id="@+id/itemeffect_onhit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -58,7 +58,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.gpl.rpg.AndorsTrail.view.ItemEffectsView_OnUse
<com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView_OnUse
android:id="@+id/itemeffect_onkill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -71,7 +71,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.gpl.rpg.AndorsTrail.view.ItemEffectsView_OnHitReceived
<com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView_OnHitReceived
android:id="@+id/itemeffect_onhitreceived"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -84,7 +84,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.gpl.rpg.AndorsTrail.view.ItemEffectsView_OnDeath
<com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView_OnDeath
android:id="@+id/itemeffect_ondeath"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -21,7 +21,7 @@
>
</LinearLayout>
<com.gpl.rpg.AndorsTrail.view.ActorConditionEffectList
<com.gpl.rpg.AndorsTrail_beta1.view.ActorConditionEffectList
android:id="@+id/itemeffect_ondeath_conditions_source"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -21,7 +21,7 @@
>
</LinearLayout>
<com.gpl.rpg.AndorsTrail.view.ActorConditionEffectList
<com.gpl.rpg.AndorsTrail_beta1.view.ActorConditionEffectList
android:id="@+id/itemeffect_onhitreceived_conditions_source"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -43,7 +43,7 @@
>
</LinearLayout>
<com.gpl.rpg.AndorsTrail.view.ActorConditionEffectList
<com.gpl.rpg.AndorsTrail_beta1.view.ActorConditionEffectList
android:id="@+id/itemeffect_onhitreceived_conditions_target"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -19,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.gpl.rpg.AndorsTrail.view.ActorConditionEffectList
<com.gpl.rpg.AndorsTrail_beta1.view.ActorConditionEffectList
android:id="@+id/itemeffect_onuse_conditions_source"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -32,7 +32,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.gpl.rpg.AndorsTrail.view.ActorConditionEffectList
<com.gpl.rpg.AndorsTrail_beta1.view.ActorConditionEffectList
android:id="@+id/itemeffect_onuse_conditions_target"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -55,7 +55,7 @@
android:layout_height="wrap_content" />
</LinearLayout>
<com.gpl.rpg.AndorsTrail.view.ItemEffectsView
<com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView
android:id="@+id/iteminfo_effects"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

View File

@@ -6,14 +6,14 @@
android:id="@+id/main_container"
>
<com.gpl.rpg.AndorsTrail.view.StatusView
<com.gpl.rpg.AndorsTrail_beta1.view.StatusView
android:id="@+id/main_statusview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<com.gpl.rpg.AndorsTrail.view.QuickitemView
<com.gpl.rpg.AndorsTrail_beta1.view.QuickitemView
android:id="@+id/main_quickitemview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -21,7 +21,7 @@
android:visibility="gone"
/>
<com.gpl.rpg.AndorsTrail.view.CombatView
<com.gpl.rpg.AndorsTrail_beta1.view.CombatView
android:id="@+id/main_combatview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -29,7 +29,7 @@
android:visibility="gone"
/>
<com.gpl.rpg.AndorsTrail.view.ToolboxView
<com.gpl.rpg.AndorsTrail_beta1.view.ToolboxView
android:id="@+id/main_toolboxview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -38,7 +38,7 @@
android:visibility="gone"
/>
<com.gpl.rpg.AndorsTrail.view.MainView
<com.gpl.rpg.AndorsTrail_beta1.view.MainView
android:id="@+id/main_mainview"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -72,7 +72,7 @@
android:gravity="right"
/>
<com.gpl.rpg.AndorsTrail.view.VirtualDpadView
<com.gpl.rpg.AndorsTrail_beta1.view.VirtualDpadView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/main_virtual_dpad"

View File

@@ -46,7 +46,7 @@
android:text="@string/monster_difficulty_normal" />
</LinearLayout>
<com.gpl.rpg.AndorsTrail.view.RangeBar
<com.gpl.rpg.AndorsTrail_beta1.view.RangeBar
android:id="@+id/monsterinfo_healthbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -69,7 +69,7 @@
<include layout="@layout/traitsinfoview" />
</TableLayout>
<com.gpl.rpg.AndorsTrail.view.ItemEffectsView
<com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView
android:id="@+id/actorinfo_onhiteffects"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
@@ -81,7 +81,7 @@
android:layout_marginTop="@dimen/section_margin"
android:text="@string/actorinfo_currentconditions" />
<com.gpl.rpg.AndorsTrail.view.ActorConditionList
<com.gpl.rpg.AndorsTrail_beta1.view.ActorConditionList
android:id="@+id/actorinfo_currentconditions"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

View File

@@ -36,12 +36,12 @@
android:layout_toRightOf="@id/status_image"
android:orientation="vertical" >
<com.gpl.rpg.AndorsTrail.view.RangeBar
<com.gpl.rpg.AndorsTrail_beta1.view.RangeBar
android:id="@+id/statusview_health"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.gpl.rpg.AndorsTrail.view.RangeBar
<com.gpl.rpg.AndorsTrail_beta1.view.RangeBar
android:id="@+id/statusview_exp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

View File

@@ -6,7 +6,7 @@
<include layout="@layout/title_bg_sky_layout"/>
<com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView
<com.gpl.rpg.AndorsTrail_beta1.view.CloudsAnimatorView
android:id="@+id/ts_clouds_animator_back"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -21,7 +21,7 @@
android:adjustViewBounds="true"
android:src="@drawable/ts_background"/>
<com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView
<com.gpl.rpg.AndorsTrail_beta1.view.CloudsAnimatorView
android:id="@+id/ts_clouds_animator_mid"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -36,7 +36,7 @@
android:adjustViewBounds="true"
android:src="@drawable/ts_midground"/>
<com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView
<com.gpl.rpg.AndorsTrail_beta1.view.CloudsAnimatorView
android:id="@+id/ts_clouds_animator_front"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -7,14 +7,14 @@
android:defaultValue="true"
android:summary="@string/preferences_display_fullscreen"
android:key="fullscreen" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_display_theme_title"
android:summary="@string/preferences_display_theme"
android:key="selectedTheme"
android:defaultValue="0"
android:entries="@array/preferences_display_theme"
android:entryValues="@array/preferences_display_theme_values" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_display_scaling_factor_title"
android:summary="@string/preferences_display_scaling_factor"
android:key="scaling_factor"
@@ -44,14 +44,14 @@
android:defaultValue="true"
android:summary="@string/preferences_dialog_confirmattack"
android:key="confirm_attack" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_dialog_monsterloot_title"
android:summary="@string/preferences_dialog_monsterloot"
android:key="display_lootdialog"
android:defaultValue="0"
android:entries="@array/preferences_display_loot"
android:entryValues="@array/preferences_display_loot_values" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_dialog_overwrite_savegame_title"
android:summary="@string/preferences_dialog_overwrite_savegame"
android:key="display_overwrite_savegame"
@@ -61,7 +61,7 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/preferences_combat_category">
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_combat_speed_title"
android:summary="@string/preferences_combat_speed"
android:key="attackspeed"
@@ -71,21 +71,21 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/preferences_movement_category">
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_movementmethod_title"
android:summary="@string/preferences_movementmethod"
android:key="movementmethod"
android:defaultValue="0"
android:entries="@array/preferences_movementmethods"
android:entryValues="@array/preferences_movementmethod_values" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_movement_dpad_position_title"
android:summary="@string/preferences_movement_dpad_position"
android:key="dpadposition"
android:defaultValue="0"
android:entries="@array/preferences_movement_dpad_positions"
android:entryValues="@array/preferences_movement_dpad_positions_values" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_movement_dpad_transparency_title"
android:summary="@string/preferences_movement_dpad_transparency"
android:key="dpadtransparency"
@@ -105,7 +105,7 @@
android:defaultValue="true"
android:summary="@string/preferences_ui_enable_animations"
android:key="enableUiAnimations" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_quickslots_placement"
android:summary="@string/preferences_quickslots_placement_summary"
android:key="quickslots_placement"
@@ -117,7 +117,7 @@
android:defaultValue="false"
android:summary="@string/preferences_ui_show_quickslots_when_toolbox_is_visible"
android:key="showQuickslotsWhenToolboxIsVisible" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
<com.gpl.rpg.AndorsTrail_beta1.view.CustomListPreference
android:title="@string/preferences_language"
android:summary="@string/preferences_language_description"
android:key="language"

View File

@@ -1,11 +0,0 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.Coord;
public interface MapLayoutListener {
void onLootBagCreated(PredefinedMap map, Coord p);
void onLootBagRemoved(PredefinedMap map, Coord p);
void onMapTilesChanged(PredefinedMap map, LayeredTileMap tileMap);
}

View File

@@ -1,10 +0,0 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
public interface MonsterMovementListener {
void onMonsterSteppedOnPlayer(Monster m);
void onMonsterMoved(PredefinedMap map, Monster m, CoordRect previousPosition);
}

View File

@@ -1,7 +0,0 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
public interface PlayerStatsListener {
void onPlayerExperienceChanged(Player p);
}

View File

@@ -1,11 +0,0 @@
package com.gpl.rpg.AndorsTrail.model;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
public final class MapBundle {
public PredefinedMap map;
public LayeredTileMap tileMap;
public TileCollection tiles;
}

View File

@@ -1,169 +1,169 @@
package com.gpl.rpg.AndorsTrail;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.Constants;
import com.gpl.rpg.AndorsTrail.util.AndroidStorage;
import com.gpl.rpg.AndorsTrail.util.Pair;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Environment;
import android.view.Window;
import android.view.WindowManager;
public final class AndorsTrailApplication extends Application {
public static final boolean DEVELOPMENT_DEBUGRESOURCES = false;
public static final boolean DEVELOPMENT_FORCE_STARTNEWGAME = false;
public static final boolean DEVELOPMENT_FORCE_CONTINUEGAME = false;
public static final boolean DEVELOPMENT_DEBUGBUTTONS = true;
public static final boolean DEVELOPMENT_FASTSPEED = false;
public static final boolean DEVELOPMENT_VALIDATEDATA = true;
public static final boolean DEVELOPMENT_DEBUGMESSAGES = true;
public static final String CURRENT_VERSION_DISPLAY = "0.7.17";
public static final boolean IS_RELEASE_VERSION = !CURRENT_VERSION_DISPLAY.matches(".*[a-d].*");
public static final boolean DEVELOPMENT_INCOMPATIBLE_SAVEGAMES = DEVELOPMENT_DEBUGRESOURCES || DEVELOPMENT_DEBUGBUTTONS || DEVELOPMENT_FASTSPEED || !IS_RELEASE_VERSION;
public static final int DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION = 999;
public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION : 64;
private final AndorsTrailPreferences preferences = new AndorsTrailPreferences();
private WorldContext world = new WorldContext();
private ControllerContext controllers = new ControllerContext(this, world);
private WorldSetup setup = new WorldSetup(world, controllers, this);
public WorldContext getWorld() { return world; }
public WorldSetup getWorldSetup() { return setup; }
public AndorsTrailPreferences getPreferences() { return preferences; }
public ControllerContext getControllerContext() { return controllers; }
public static AndorsTrailApplication getApplicationFromActivity(Activity activity) {
return ((AndorsTrailApplication) activity.getApplication());
}
public static AndorsTrailApplication getApplicationFromActivityContext(Context context) {
return getApplicationFromActivity(getActivityFromActivityContext(context));
}
private static Activity getActivityFromActivityContext(Context context) {
return (Activity) context;
}
public boolean isInitialized() { return world.model != null; }
public void setWindowParameters(Activity activity) {
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
if (preferences.fullscreen) {
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
activity.getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
//Get default locale at startup, as somehow it seems that changing the app's
//configured locale impacts the value returned by Locale.getDefault() nowadays.
private final Locale defaultLocale = Locale.getDefault();
private Pair<String, Locale> lastLocale = null;
public boolean setLocale(Activity context) {
Resources res = context.getResources();
Configuration conf = res.getConfiguration();
Locale targetLocale;
if (lastLocale != null && lastLocale.first == preferences.language) {
targetLocale = lastLocale.second;
} else {
targetLocale = localeForLanguageTag(preferences.language);
lastLocale = new Pair<String, Locale>(preferences.language, targetLocale);
}
if (targetLocale.equals(conf.locale)) {
return false;
}
conf.locale = targetLocale;
res.updateConfiguration(conf, res.getDisplayMetrics());
this.getResources().updateConfiguration(conf, res.getDisplayMetrics());
return true;
}
// Supports language or language_COUNTRY in short form e.g. "en" or "en_US"
private Locale localeForLanguageTag(String languageTag) {
Locale locale = null;
if (languageTag != null && !languageTag.equalsIgnoreCase("default")) {
final int pos = languageTag.indexOf('-');
if (pos == -1) {
locale = new Locale(languageTag);
}
else locale = new Locale(languageTag.substring(0, pos), languageTag.substring(pos+1));
}
if (locale == null) {
locale = defaultLocale;
}
return locale;
}
/**
* Logging to text file system as found on https://stackoverflow.com/questions/19565685/saving-logcat-to-a-text-file-in-android-device
*/
public void onCreate() {
super.onCreate();
if ( DEVELOPMENT_DEBUGMESSAGES && isExternalStorageWritable() ) {
File appDirectory = AndroidStorage.getStorageDirectory(getApplicationContext(), Constants.FILENAME_SAVEGAME_DIRECTORY);
File logDirectory = new File( appDirectory, "log" );
File logFile = new File( logDirectory, "logcat" + System.currentTimeMillis() + ".txt" );
// create app folder
if ( !appDirectory.exists() ) {
appDirectory.mkdir();
}
// create log folder
if ( !logDirectory.exists() ) {
logDirectory.mkdir();
}
// clear the previous logcat and then write the new one to the file
try {
Process process = Runtime.getRuntime().exec("logcat -c");
process = Runtime.getRuntime().exec("logcat -f " + logFile+" *:W");
} catch ( IOException e ) {
e.printStackTrace();
}
}
}
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if ( Environment.MEDIA_MOUNTED.equals( state ) ) {
return true;
}
return false;
}
/* Checks if external storage is available to at least read */
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if ( Environment.MEDIA_MOUNTED.equals( state ) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) ) {
return true;
}
return false;
}
public void discardWorld() {
world = new WorldContext();
controllers = new ControllerContext(this, world);
setup = new WorldSetup(world, controllers, getApplicationContext());
}
}
package com.gpl.rpg.AndorsTrail_beta1;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.Constants;
import com.gpl.rpg.AndorsTrail_beta1.util.AndroidStorage;
import com.gpl.rpg.AndorsTrail_beta1.util.Pair;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Environment;
import android.view.Window;
import android.view.WindowManager;
public final class AndorsTrailApplication extends Application {
public static final boolean DEVELOPMENT_DEBUGRESOURCES = false;
public static final boolean DEVELOPMENT_FORCE_STARTNEWGAME = false;
public static final boolean DEVELOPMENT_FORCE_CONTINUEGAME = false;
public static final boolean DEVELOPMENT_DEBUGBUTTONS = true;
public static final boolean DEVELOPMENT_FASTSPEED = false;
public static final boolean DEVELOPMENT_VALIDATEDATA = true;
public static final boolean DEVELOPMENT_DEBUGMESSAGES = true;
public static final String CURRENT_VERSION_DISPLAY = "0.7.17dev";
public static final boolean IS_RELEASE_VERSION = !CURRENT_VERSION_DISPLAY.matches(".*[a-d].*");
public static final boolean DEVELOPMENT_INCOMPATIBLE_SAVEGAMES = DEVELOPMENT_DEBUGRESOURCES || DEVELOPMENT_DEBUGBUTTONS || DEVELOPMENT_FASTSPEED || !IS_RELEASE_VERSION;
public static final int DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION = 999;
public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION : 64;
private final AndorsTrailPreferences preferences = new AndorsTrailPreferences();
private WorldContext world = new WorldContext();
private ControllerContext controllers = new ControllerContext(this, world);
private WorldSetup setup = new WorldSetup(world, controllers, this);
public WorldContext getWorld() { return world; }
public WorldSetup getWorldSetup() { return setup; }
public AndorsTrailPreferences getPreferences() { return preferences; }
public ControllerContext getControllerContext() { return controllers; }
public static AndorsTrailApplication getApplicationFromActivity(Activity activity) {
return ((AndorsTrailApplication) activity.getApplication());
}
public static AndorsTrailApplication getApplicationFromActivityContext(Context context) {
return getApplicationFromActivity(getActivityFromActivityContext(context));
}
private static Activity getActivityFromActivityContext(Context context) {
return (Activity) context;
}
public boolean isInitialized() { return world.model != null; }
public void setWindowParameters(Activity activity) {
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
if (preferences.fullscreen) {
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
activity.getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
//Get default locale at startup, as somehow it seems that changing the app's
//configured locale impacts the value returned by Locale.getDefault() nowadays.
private final Locale defaultLocale = Locale.getDefault();
private Pair<String, Locale> lastLocale = null;
public boolean setLocale(Activity context) {
Resources res = context.getResources();
Configuration conf = res.getConfiguration();
Locale targetLocale;
if (lastLocale != null && lastLocale.first == preferences.language) {
targetLocale = lastLocale.second;
} else {
targetLocale = localeForLanguageTag(preferences.language);
lastLocale = new Pair<String, Locale>(preferences.language, targetLocale);
}
if (targetLocale.equals(conf.locale)) {
return false;
}
conf.locale = targetLocale;
res.updateConfiguration(conf, res.getDisplayMetrics());
this.getResources().updateConfiguration(conf, res.getDisplayMetrics());
return true;
}
// Supports language or language_COUNTRY in short form e.g. "en" or "en_US"
private Locale localeForLanguageTag(String languageTag) {
Locale locale = null;
if (languageTag != null && !languageTag.equalsIgnoreCase("default")) {
final int pos = languageTag.indexOf('-');
if (pos == -1) {
locale = new Locale(languageTag);
}
else locale = new Locale(languageTag.substring(0, pos), languageTag.substring(pos+1));
}
if (locale == null) {
locale = defaultLocale;
}
return locale;
}
/**
* Logging to text file system as found on https://stackoverflow.com/questions/19565685/saving-logcat-to-a-text-file-in-android-device
*/
public void onCreate() {
super.onCreate();
if ( DEVELOPMENT_DEBUGMESSAGES && isExternalStorageWritable() ) {
File appDirectory = AndroidStorage.getStorageDirectory(getApplicationContext(), Constants.FILENAME_SAVEGAME_DIRECTORY);
File logDirectory = new File( appDirectory, "log" );
File logFile = new File( logDirectory, "logcat" + System.currentTimeMillis() + ".txt" );
// create app folder
if ( !appDirectory.exists() ) {
appDirectory.mkdir();
}
// create log folder
if ( !logDirectory.exists() ) {
logDirectory.mkdir();
}
// clear the previous logcat and then write the new one to the file
try {
Process process = Runtime.getRuntime().exec("logcat -c");
process = Runtime.getRuntime().exec("logcat -f " + logFile+" *:W");
} catch ( IOException e ) {
e.printStackTrace();
}
}
}
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if ( Environment.MEDIA_MOUNTED.equals( state ) ) {
return true;
}
return false;
}
/* Checks if external storage is available to at least read */
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if ( Environment.MEDIA_MOUNTED.equals( state ) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) ) {
return true;
}
return false;
}
public void discardWorld() {
world = new WorldContext();
controllers = new ControllerContext(this, world);
setup = new WorldSetup(world, controllers, getApplicationContext());
}
}

View File

@@ -1,114 +1,112 @@
package com.gpl.rpg.AndorsTrail;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public final class AndorsTrailPreferences {
public static final int DISPLAYLOOT_DIALOG_ALWAYS = 0;
public static final int DISPLAYLOOT_DIALOG_FOR_ITEMS = 3;
public static final int DISPLAYLOOT_DIALOG_FOR_ITEMS_ELSE_TOAST = 4;
public static final int DISPLAYLOOT_TOAST = 1;
public static final int DISPLAYLOOT_TOAST_FOR_ITEMS = 5;
public static final int DISPLAYLOOT_NONE = 2;
public static final int MOVEMENTMETHOD_STRAIGHT = 0;
public static final int MOVEMENTMETHOD_DIRECTIONAL = 1;
public static final int MOVEMENTAGGRESSIVENESS_NORMAL = 0;
public static final int MOVEMENTAGGRESSIVENESS_AGGRESSIVE = 1;
public static final int MOVEMENTAGGRESSIVENESS_DEFENSIVE = 2;
public static final int DPAD_POSITION_DISABLED = 0;
public static final int DPAD_POSITION_LOWER_RIGHT = 1;
public static final int DPAD_POSITION_LOWER_LEFT = 2;
public static final int DPAD_POSITION_LOWER_CENTER = 3;
public static final int DPAD_POSITION_CENTER_LEFT = 4;
public static final int DPAD_POSITION_CENTER_RIGHT = 5;
public static final int DPAD_POSITION_UPPER_LEFT = 6;
public static final int DPAD_POSITION_UPPER_RIGHT = 7;
public static final int DPAD_POSITION_UPPER_CENTER = 8;
public static final int DPAD_TRANSPARENCY_30_PERCENT = 0;
public static final int DPAD_TRANSPARENCY_40_PERCENT = 1;
public static final int DPAD_TRANSPARENCY_50_PERCENT = 2;
public static final int DPAD_TRANSPARENCY_60_PERCENT = 3;
public static final int DPAD_TRANSPARENCY_70_PERCENT = 4;
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 static final int ATTACKSPEED_DEFAULT_MILLISECONDS = 1000;
public boolean confirmRest = true;
public boolean confirmAttack = true;
public int displayLoot = DISPLAYLOOT_DIALOG_ALWAYS;
public boolean fullscreen = true;
public int attackspeed_milliseconds = 1000;
public int movementMethod = MOVEMENTMETHOD_STRAIGHT;
public int movementAggressiveness = MOVEMENTAGGRESSIVENESS_NORMAL;
public float scalingFactor = 1.0f;
public int dpadPosition;
public int dpadTransparency;
public boolean dpadMinimizeable = true;
public boolean optimizedDrawing = false;
public boolean highQualityFilters = true;
public boolean enableUiAnimations = true;
public int displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS;
public int quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM;
public boolean showQuickslotsWhenToolboxIsVisible = false;
public String language = "default";
public int selectedTheme = 0;
public void read(final Context androidContext) {
AndorsTrailPreferences dest = this;
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(androidContext);
dest.confirmRest = prefs.getBoolean("confirm_rest", true);
dest.confirmAttack = prefs.getBoolean("confirm_attack", true);
dest.displayLoot = Integer.parseInt(prefs.getString("display_lootdialog", Integer.toString(DISPLAYLOOT_DIALOG_ALWAYS)));
dest.fullscreen = prefs.getBoolean("fullscreen", true);
dest.attackspeed_milliseconds = Integer.parseInt(prefs.getString("attackspeed", "1000"));
dest.movementMethod = Integer.parseInt(prefs.getString("movementmethod", Integer.toString(MOVEMENTMETHOD_STRAIGHT)));
dest.scalingFactor = Float.parseFloat(prefs.getString("scaling_factor", "1.0f"));
dest.dpadPosition = Integer.parseInt(prefs.getString("dpadposition", Integer.toString(DPAD_POSITION_DISABLED)));
dest.dpadTransparency = Integer.parseInt(prefs.getString("dpadtransparency", Integer.toString(DPAD_TRANSPARENCY_50_PERCENT)));
dest.dpadMinimizeable = prefs.getBoolean("dpadMinimizeable", true);
dest.optimizedDrawing = prefs.getBoolean("optimized_drawing", false);
dest.highQualityFilters = prefs.getBoolean("high_quality_filters", true);
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)));
dest.showQuickslotsWhenToolboxIsVisible = prefs.getBoolean("showQuickslotsWhenToolboxIsVisible", false);
dest.language = prefs.getString("language", "default");
dest.selectedTheme = Integer.parseInt(prefs.getString("selectedTheme", Integer.toString(0)));
// This might be implemented as a skill in the future.
//dest.movementAggressiveness = Integer.parseInt(prefs.getString("movementaggressiveness", Integer.toString(MOVEMENTAGGRESSIVENESS_NORMAL)));
} catch (Exception e) {
dest.confirmRest = true;
dest.confirmAttack = true;
dest.displayLoot = DISPLAYLOOT_DIALOG_ALWAYS;
dest.fullscreen = true;
dest.attackspeed_milliseconds = 1000;
dest.movementMethod = MOVEMENTMETHOD_STRAIGHT;
dest.movementAggressiveness = MOVEMENTAGGRESSIVENESS_NORMAL;
dest.scalingFactor = 1.0f;
dest.dpadPosition = DPAD_POSITION_DISABLED;
dest.dpadTransparency = DPAD_TRANSPARENCY_50_PERCENT;
dest.dpadMinimizeable = true;
dest.optimizedDrawing = false;
dest.highQualityFilters = true;
dest.enableUiAnimations = true;
dest.displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS;
dest.quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM;
dest.showQuickslotsWhenToolboxIsVisible = false;
dest.language = "default";
dest.selectedTheme = 0;
}
}
}
package com.gpl.rpg.AndorsTrail_beta1;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public final class AndorsTrailPreferences {
public static final int DISPLAYLOOT_DIALOG_ALWAYS = 0;
public static final int DISPLAYLOOT_DIALOG_FOR_ITEMS = 3;
public static final int DISPLAYLOOT_DIALOG_FOR_ITEMS_ELSE_TOAST = 4;
public static final int DISPLAYLOOT_TOAST = 1;
public static final int DISPLAYLOOT_TOAST_FOR_ITEMS = 5;
public static final int DISPLAYLOOT_NONE = 2;
public static final int MOVEMENTMETHOD_STRAIGHT = 0;
public static final int MOVEMENTMETHOD_DIRECTIONAL = 1;
public static final int MOVEMENTAGGRESSIVENESS_NORMAL = 0;
public static final int MOVEMENTAGGRESSIVENESS_AGGRESSIVE = 1;
public static final int MOVEMENTAGGRESSIVENESS_DEFENSIVE = 2;
public static final int DPAD_POSITION_DISABLED = 0;
public static final int DPAD_POSITION_LOWER_RIGHT = 1;
public static final int DPAD_POSITION_LOWER_LEFT = 2;
public static final int DPAD_POSITION_LOWER_CENTER = 3;
public static final int DPAD_POSITION_CENTER_LEFT = 4;
public static final int DPAD_POSITION_CENTER_RIGHT = 5;
public static final int DPAD_POSITION_UPPER_LEFT = 6;
public static final int DPAD_POSITION_UPPER_RIGHT = 7;
public static final int DPAD_POSITION_UPPER_CENTER = 8;
public static final int DPAD_TRANSPARENCY_30_PERCENT = 0;
public static final int DPAD_TRANSPARENCY_40_PERCENT = 1;
public static final int DPAD_TRANSPARENCY_50_PERCENT = 2;
public static final int DPAD_TRANSPARENCY_60_PERCENT = 3;
public static final int DPAD_TRANSPARENCY_70_PERCENT = 4;
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 static final int ATTACKSPEED_DEFAULT_MILLISECONDS = 1000;
public boolean confirmRest = true;
public boolean confirmAttack = true;
public int displayLoot = DISPLAYLOOT_DIALOG_ALWAYS;
public boolean fullscreen = true;
public int attackspeed_milliseconds = 1000;
public int movementMethod = MOVEMENTMETHOD_STRAIGHT;
public int movementAggressiveness = MOVEMENTAGGRESSIVENESS_NORMAL;
public float scalingFactor = 1.0f;
public int dpadPosition;
public int dpadTransparency;
public boolean dpadMinimizeable = true;
public boolean optimizedDrawing = false;
public boolean highQualityFilters = true;
public boolean enableUiAnimations = true;
public int displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS;
public int quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM;
public boolean showQuickslotsWhenToolboxIsVisible = false;
public String language = "default";
public int selectedTheme = 0;
public void read(final Context androidContext) {
AndorsTrailPreferences dest = this;
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(androidContext);
dest.confirmRest = prefs.getBoolean("confirm_rest", true);
dest.confirmAttack = prefs.getBoolean("confirm_attack", true);
dest.displayLoot = Integer.parseInt(prefs.getString("display_lootdialog", Integer.toString(DISPLAYLOOT_DIALOG_ALWAYS)));
dest.fullscreen = prefs.getBoolean("fullscreen", true);
dest.attackspeed_milliseconds = Integer.parseInt(prefs.getString("attackspeed", "1000"));
dest.movementMethod = Integer.parseInt(prefs.getString("movementmethod", Integer.toString(MOVEMENTMETHOD_STRAIGHT)));
dest.scalingFactor = Float.parseFloat(prefs.getString("scaling_factor", "1.0f"));
dest.dpadPosition = Integer.parseInt(prefs.getString("dpadposition", Integer.toString(DPAD_POSITION_DISABLED)));
dest.dpadTransparency = Integer.parseInt(prefs.getString("dpadtransparency", Integer.toString(DPAD_TRANSPARENCY_50_PERCENT)));
dest.dpadMinimizeable = prefs.getBoolean("dpadMinimizeable", true);
dest.optimizedDrawing = prefs.getBoolean("optimized_drawing", false);
dest.highQualityFilters = prefs.getBoolean("high_quality_filters", true);
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)));
dest.showQuickslotsWhenToolboxIsVisible = prefs.getBoolean("showQuickslotsWhenToolboxIsVisible", false);
dest.language = prefs.getString("language", "default");
dest.selectedTheme = Integer.parseInt(prefs.getString("selectedTheme", Integer.toString(0)));
// This might be implemented as a skill in the future.
//dest.movementAggressiveness = Integer.parseInt(prefs.getString("movementaggressiveness", Integer.toString(MOVEMENTAGGRESSIVENESS_NORMAL)));
} catch (Exception e) {
dest.confirmRest = true;
dest.confirmAttack = true;
dest.displayLoot = DISPLAYLOOT_DIALOG_ALWAYS;
dest.fullscreen = true;
dest.attackspeed_milliseconds = 1000;
dest.movementMethod = MOVEMENTMETHOD_STRAIGHT;
dest.movementAggressiveness = MOVEMENTAGGRESSIVENESS_NORMAL;
dest.scalingFactor = 1.0f;
dest.dpadPosition = DPAD_POSITION_DISABLED;
dest.dpadTransparency = DPAD_TRANSPARENCY_50_PERCENT;
dest.dpadMinimizeable = true;
dest.optimizedDrawing = false;
dest.highQualityFilters = true;
dest.enableUiAnimations = true;
dest.displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS;
dest.quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM;
dest.showQuickslotsWhenToolboxIsVisible = false;
dest.language = "default";
dest.selectedTheme = 0;
}
}
}

View File

@@ -1,478 +1,475 @@
package com.gpl.rpg.AndorsTrail;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import android.*;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
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.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail.activity.LevelUpActivity;
import com.gpl.rpg.AndorsTrail.activity.LoadSaveActivity;
import com.gpl.rpg.AndorsTrail.activity.MainActivity;
import com.gpl.rpg.AndorsTrail.activity.MonsterEncounterActivity;
import com.gpl.rpg.AndorsTrail.activity.MonsterInfoActivity;
import com.gpl.rpg.AndorsTrail.activity.SkillInfoActivity;
import com.gpl.rpg.AndorsTrail.activity.fragment.StartScreenActivity_MainMenu;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.item.Inventory;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.model.item.Loot;
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
import com.gpl.rpg.AndorsTrail.view.ItemContainerAdapter;
public final class Dialogs {
private static void showDialogAndPause(Dialog d, final ControllerContext context) {
showDialogAndPause(d, context, null);
}
private static void showDialogAndPause(Dialog d, final ControllerContext context, final OnDismissListener onDismiss) {
context.gameRoundController.pause();
CustomDialogFactory.setDismissListener(d, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
if (onDismiss != null) onDismiss.onDismiss(arg0);
context.gameRoundController.resume();
}
});
CustomDialogFactory.show(d);
}
public static void showKeyArea(final MainActivity currentActivity, final ControllerContext context, String phraseID) {
showConversation(currentActivity, context, phraseID, null);
}
public static void showMapSign(final MainActivity currentActivity, final ControllerContext context, String phraseID) {
showConversation(currentActivity, context, phraseID, null);
}
public static void showMapScriptMessage(final MainActivity currentActivity, final ControllerContext context, String phraseID) {
showConversation(currentActivity, context, phraseID, null, false);
}
public static void showConversation(final MainActivity currentActivity, final ControllerContext context, final String phraseID, final Monster npc) {
showConversation(currentActivity, context, phraseID, npc, true);
}
private static void showConversation(final MainActivity currentActivity, final ControllerContext context, final String phraseID, final Monster npc, boolean applyScriptEffectsForFirstPhrase) {
context.gameRoundController.pause();
Intent intent = new Intent(currentActivity, ConversationActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/conversation/" + phraseID));
intent.putExtra("applyScriptEffectsForFirstPhrase", applyScriptEffectsForFirstPhrase);
addMonsterIdentifiers(intent, npc);
currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_CONVERSATION);
}
public static void addMonsterIdentifiers(Intent intent, Monster monster) {
if (monster == null) return;
intent.putExtra("x", monster.position.x);
intent.putExtra("y", monster.position.y);
}
public static void addMonsterIdentifiers(Bundle bundle, Monster monster) {
if (monster == null) return;
bundle.putInt("x", monster.position.x);
bundle.putInt("y", monster.position.y);
}
public static Monster getMonsterFromIntent(Intent intent, final WorldContext world) {
return getMonsterFromBundle(intent.getExtras(), world);
}
public static Monster getMonsterFromBundle(Bundle params, final WorldContext world) {
if (params == null) return null;
if (!params.containsKey("x")) return null;
int x = params.getInt("x");
int y = params.getInt("y");
return world.model.currentMaps.map.getMonsterAt(x, y);
}
public static void showMonsterEncounter(final MainActivity currentActivity, final ControllerContext context, final Monster monster) {
context.gameRoundController.pause();
Intent intent = new Intent(currentActivity, MonsterEncounterActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/monsterencounter"));
addMonsterIdentifiers(intent, monster);
currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_MONSTERENCOUNTER);
}
public static void showMonsterInfo(final Context context, final Monster monster) {
Intent intent = new Intent(context, MonsterInfoActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/monsterinfo"));
addMonsterIdentifiers(intent, monster);
context.startActivity(intent);
}
public static String getGroundLootFoundMessage(final Context ctx, final Loot loot) {
StringBuilder sb = new StringBuilder(60);
if (!loot.items.isEmpty()) {
sb.append(ctx.getString(R.string.dialog_groundloot_message));
}
appendGoldPickedUpMessage(ctx, loot, sb);
return sb.toString();
}
public static String getGroundLootPickedUpMessage(final Context ctx, final Loot loot) {
StringBuilder sb = new StringBuilder(60);
appendLootPickedUpMessage(ctx, loot, sb);
return sb.toString();
}
public static String getMonsterLootFoundMessage(final Context ctx, final Loot combinedLoot, final int exp) {
StringBuilder sb = new StringBuilder(60);
appendMonsterEncounterSurvivedMessage(ctx, sb, exp);
appendGoldPickedUpMessage(ctx, combinedLoot, sb);
return sb.toString();
}
public static String getMonsterLootPickedUpMessage(final Context ctx, final Loot combinedLoot, final int exp) {
StringBuilder sb = new StringBuilder(60);
appendMonsterEncounterSurvivedMessage(ctx, sb, exp);
appendLootPickedUpMessage(ctx, combinedLoot, sb);
return sb.toString();
}
private static void appendMonsterEncounterSurvivedMessage(final Context ctx, final StringBuilder sb, final int exp) {
sb.append(ctx.getString(R.string.dialog_monsterloot_message));
if (exp > 0) {
sb.append(' ');
sb.append(ctx.getString(R.string.dialog_monsterloot_gainedexp, exp));
}
}
private static void appendGoldPickedUpMessage(final Context ctx, final Loot loot, final StringBuilder sb) {
if (loot.gold > 0) {
sb.append(' ');
sb.append(ctx.getString(R.string.dialog_loot_foundgold, loot.gold));
}
}
private static void appendLootPickedUpMessage(final Context ctx, final Loot loot, final StringBuilder sb) {
appendGoldPickedUpMessage(ctx, loot, sb);
int numItems = loot.items.countItems();
if (numItems == 1) {
sb.append(' ');
sb.append(ctx.getString(R.string.dialog_loot_pickedupitem));
} else if (numItems > 1){
sb.append(' ');
sb.append(ctx.getString(R.string.dialog_loot_pickedupitems, numItems));
}
}
public static void showMonsterLoot(final MainActivity mainActivity, final ControllerContext controllers, final WorldContext world, final Collection<Loot> lootBags, final Loot combinedLoot, final String msg) {
// CombatController will do killedMonsterBags.clear() after this method has been called,
// so we need to keep the list of objects. Therefore, we create a shallow copy of the list of bags.
ArrayList<Loot> bags = new ArrayList<Loot>(lootBags);
showLoot(mainActivity, controllers, world, combinedLoot, bags, R.string.dialog_monsterloot_title, msg);
}
public static void showGroundLoot(final MainActivity mainActivity, final ControllerContext controllers, final WorldContext world, final Loot loot, final String msg) {
showLoot(mainActivity, controllers, world, loot, Collections.singletonList(loot), R.string.dialog_groundloot_title, msg);
}
private static void showLoot(final MainActivity mainActivity, final ControllerContext controllers, final WorldContext world, final Loot combinedLoot, final Iterable<Loot> lootBags, final int title, final String msg) {
final ListView itemList = new ListView(mainActivity);
itemList.setBackgroundResource(android.R.color.transparent);
itemList.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT));
// itemList.setPadding(20, 0, 20, 20);
itemList.setAdapter(new ItemContainerAdapter(mainActivity, world.tileManager, combinedLoot.items, world.model.player));
final Dialog d = CustomDialogFactory.createDialog(mainActivity,
mainActivity.getResources().getString(title),
mainActivity.getResources().getDrawable(R.drawable.ui_icon_equipment),
msg,
combinedLoot.items.isEmpty() ? null : itemList,
true,
false);
itemList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
final String itemTypeID = ((ItemContainerAdapter) parent.getAdapter()).getItem(position).itemType.id;
boolean removeFromCombinedLoot = true;
for (Loot l : lootBags) {
if (l == combinedLoot) removeFromCombinedLoot = false;
if (l.items.removeItem(itemTypeID)) {
controllers.itemController.removeLootBagIfEmpty(l);
break;
}
}
if (removeFromCombinedLoot) {
combinedLoot.items.removeItem(itemTypeID);
}
if (((ItemContainerAdapter) parent.getAdapter()).isEmpty()) {
ViewGroup vg = (ViewGroup) d.findViewById(R.id.dialog_content_container);
vg.setVisibility(View.GONE);
}
ItemType type = world.itemTypes.getItemType(itemTypeID);
world.model.player.inventory.addItem(type);
((ItemContainerAdapter) itemList.getAdapter()).notifyDataSetChanged();
}
});
if (!itemList.getAdapter().isEmpty()) {
CustomDialogFactory.addButton(d, R.string.dialog_loot_pickall, new View.OnClickListener() {
@Override
public void onClick(View v) {
controllers.itemController.pickupAll(lootBags);
}
});
}
CustomDialogFactory.addDismissButton(d, R.string.dialog_close);
showDialogAndPause(d, controllers, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
controllers.itemController.removeLootBagIfEmpty(lootBags);
}
});
}
public static void showHeroDied(final MainActivity mainActivity, final ControllerContext controllers) {
final Dialog d = CustomDialogFactory.createDialog(mainActivity,
mainActivity.getResources().getString(R.string.dialog_game_over_title),
mainActivity.getResources().getDrawable(R.drawable.ui_icon_combat),
mainActivity.getResources().getString(R.string.dialog_game_over_text),
null,
true,
false);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
showDialogAndPause(d, controllers, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
mainActivity.finish();
}
});
}
public static Intent getIntentForItemInfo(final Context ctx, String itemTypeID, ItemInfoActivity.ItemInfoAction actionType, String buttonText, boolean buttonEnabled, Inventory.WearSlot inventorySlot) {
Intent intent = new Intent(ctx, ItemInfoActivity.class);
intent.putExtra("buttonText", buttonText);
intent.putExtra("buttonEnabled", buttonEnabled);
intent.putExtra("moreActions", (actionType == ItemInfoActivity.ItemInfoAction.equip || actionType == ItemInfoActivity.ItemInfoAction.use || actionType == ItemInfoActivity.ItemInfoAction.none));
intent.putExtra("itemTypeID", itemTypeID);
intent.putExtra("actionType", actionType.name());
if (inventorySlot != null) intent.putExtra("inventorySlot", inventorySlot.name());
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/iteminfo/" + itemTypeID));
return intent;
}
public static Intent getIntentForLevelUp(final Context ctx) {
Intent intent = new Intent(ctx, LevelUpActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/levelup"));
return intent;
}
public static void showConfirmRest(final Activity currentActivity, final ControllerContext controllerContext, final MapObject area) {
final Dialog d = CustomDialogFactory.createDialog(currentActivity,
currentActivity.getResources().getString(R.string.dialog_rest_title),
null,
currentActivity.getResources().getString(R.string.dialog_rest_confirm_message),
null,
true);
CustomDialogFactory.addButton(d, android.R.string.yes, new View.OnClickListener() {
@Override
public void onClick(View v) {
controllerContext.mapController.rest(area);
}
});
CustomDialogFactory.addDismissButton(d, android.R.string.no);
showDialogAndPause(d, controllerContext);
}
public static void showRested(final Activity currentActivity, final ControllerContext controllerContext) {
// Dialog d = new AlertDialog.Builder(new ContextThemeWrapper(currentActivity, R.style.AndorsTrailStyle))
// .setTitle(R.string.dialog_rest_title)
// .setMessage(R.string.dialog_rest_message)
// .setNeutralButton(android.R.string.ok, null)
// .create();
final Dialog d = CustomDialogFactory.createDialog(currentActivity,
currentActivity.getResources().getString(R.string.dialog_rest_title),
null,
currentActivity.getResources().getString(R.string.dialog_rest_message),
null,
true);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
showDialogAndPause(d, controllerContext);
}
public static void showNewVersion(final Activity currentActivity, final OnDismissListener onDismiss) {
// new AlertDialog.Builder(new ContextThemeWrapper(currentActivity, R.style.AndorsTrailStyle))
// .setTitle(R.string.dialog_newversion_title)
// .setMessage(R.string.dialog_newversion_message)
// .setNeutralButton(android.R.string.ok, null)
// .show();
String text = currentActivity.getResources().getString(R.string.dialog_newversion_message);
if (!hasPermissions(currentActivity) && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
text += currentActivity.getResources().getString(R.string.dialog_newversion_permission_information);
}
final Dialog d = CustomDialogFactory.createDialog(currentActivity,
currentActivity.getResources().getString(R.string.dialog_newversion_title),
null,
text,
null,
true);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
CustomDialogFactory.setDismissListener(d, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
if (onDismiss != null) onDismiss.onDismiss(arg0);
}
});
CustomDialogFactory.show(d);
}
@TargetApi(23)
private static boolean hasPermissions(final Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.getApplicationContext().checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|| activity.getApplicationContext().checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
public static boolean showSave(final Activity mainActivity, final ControllerContext controllerContext, final WorldContext world) {
if (world.model.uiSelections.isInCombat) {
Toast.makeText(mainActivity, R.string.menu_save_saving_not_allowed_in_combat, Toast.LENGTH_SHORT).show();
return false;
}
if (!world.model.statistics.hasUnlimitedSaves()) {
final Dialog d = CustomDialogFactory.createDialog(mainActivity,
mainActivity.getResources().getString(R.string.menu_save_switch_character_title),
null,
mainActivity.getResources().getString(R.string.menu_save_switch_character),
null,
true);
CustomDialogFactory.addButton(d, android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
controllerContext.gameRoundController.pause();
Intent intent = new Intent(mainActivity, LoadSaveActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/save"));
mainActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_SAVEGAME);
}
});
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
CustomDialogFactory.show(d);
return false;
} else {
controllerContext.gameRoundController.pause();
Intent intent = new Intent(mainActivity, LoadSaveActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/save"));
mainActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_SAVEGAME);
return true;
}
}
public static void showLoad(final Activity currentActivity) {
Intent intent = new Intent(currentActivity, LoadSaveActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/load"));
currentActivity.startActivityForResult(intent, StartScreenActivity_MainMenu.INTENTREQUEST_LOADGAME);
}
public static void showLoad(final Fragment currentFragment) {
Intent intent = new Intent(currentFragment.getActivity(), LoadSaveActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/load"));
currentFragment.startActivityForResult(intent, StartScreenActivity_MainMenu.INTENTREQUEST_LOADGAME);
}
public static void showActorConditionInfo(final Context context, ActorConditionType conditionType) {
Intent intent = new Intent(context, ActorConditionInfoActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/actorconditioninfo/" + conditionType.conditionTypeID));
context.startActivity(intent);
}
public static Intent getIntentForBulkBuyingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BulkInterfaceType.buy);
}
public static Intent getIntentForBulkSellingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BulkInterfaceType.sell);
}
public static Intent getIntentForBulkDroppingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BulkInterfaceType.drop);
}
private static Intent getIntentForBulkSelectionInterface(final Context ctx, String itemTypeID, int totalAvailableAmount, BulkSelectionInterface.BulkInterfaceType interfaceType) {
Intent intent = new Intent(ctx, BulkSelectionInterface.class);
intent.putExtra("itemTypeID", itemTypeID);
intent.putExtra("totalAvailableAmount", totalAvailableAmount);
intent.putExtra("interfaceType", interfaceType.name());
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/bulkselection/" + itemTypeID));
return intent;
}
public static Intent getIntentForSkillInfo(final Context ctx, SkillCollection.SkillID skillID) {
Intent intent = new Intent(ctx, SkillInfoActivity.class);
intent.putExtra("skillID", skillID.name());
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/showskillinfo/" + skillID));
return intent;
}
public static void showCombatLog(final Context context, final ControllerContext controllerContext, final WorldContext world) {
String[] combatLogMessages = world.model.combatLog.getAllMessages();
View view = null;
ListView itemList = null;
itemList = new ListView(context);
itemList.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT));
itemList.setStackFromBottom(true);
itemList.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
itemList.setChoiceMode(ListView.CHOICE_MODE_NONE);
itemList.setBackgroundColor(ThemeHelper.getThemeColor(context, R.attr.ui_theme_stdframe_bg_color));
if (combatLogMessages.length <= 0) {
combatLogMessages = new String[] {context.getResources().getString(R.string.combat_log_noentries)};
}
itemList.setAdapter(new ArrayAdapter<String>(context, R.layout.combatlog_row, android.R.id.text1, combatLogMessages));
view = itemList;
final Dialog d = CustomDialogFactory.createDialog(context,
context.getResources().getString(R.string.combat_log_title),
context.getResources().getDrawable(R.drawable.ui_icon_combat),
null,
view,
true);
CustomDialogFactory.addDismissButton(d, R.string.dialog_close);
showDialogAndPause(d, controllerContext);
}
}
package com.gpl.rpg.AndorsTrail_beta1;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail_beta1.activity.ActorConditionInfoActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.BulkSelectionInterface;
import com.gpl.rpg.AndorsTrail_beta1.activity.ConversationActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.LevelUpActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.LoadSaveActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.MainActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.MonsterEncounterActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.MonsterInfoActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.SkillInfoActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.StartScreenActivity_MainMenu;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Inventory;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Loot;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapObject;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.CustomDialogFactory;
import com.gpl.rpg.AndorsTrail_beta1.view.ItemContainerAdapter;
public final class Dialogs {
private static void showDialogAndPause(Dialog d, final ControllerContext context) {
showDialogAndPause(d, context, null);
}
private static void showDialogAndPause(Dialog d, final ControllerContext context, final OnDismissListener onDismiss) {
context.gameRoundController.pause();
CustomDialogFactory.setDismissListener(d, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
if (onDismiss != null) onDismiss.onDismiss(arg0);
context.gameRoundController.resume();
}
});
CustomDialogFactory.show(d);
}
public static void showKeyArea(final MainActivity currentActivity, final ControllerContext context, String phraseID) {
showConversation(currentActivity, context, phraseID, null);
}
public static void showMapSign(final MainActivity currentActivity, final ControllerContext context, String phraseID) {
showConversation(currentActivity, context, phraseID, null);
}
public static void showMapScriptMessage(final MainActivity currentActivity, final ControllerContext context, String phraseID) {
showConversation(currentActivity, context, phraseID, null, false);
}
public static void showConversation(final MainActivity currentActivity, final ControllerContext context, final String phraseID, final Monster npc) {
showConversation(currentActivity, context, phraseID, npc, true);
}
private static void showConversation(final MainActivity currentActivity, final ControllerContext context, final String phraseID, final Monster npc, boolean applyScriptEffectsForFirstPhrase) {
context.gameRoundController.pause();
Intent intent = new Intent(currentActivity, ConversationActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/conversation/" + phraseID));
intent.putExtra("applyScriptEffectsForFirstPhrase", applyScriptEffectsForFirstPhrase);
addMonsterIdentifiers(intent, npc);
currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_CONVERSATION);
}
public static void addMonsterIdentifiers(Intent intent, Monster monster) {
if (monster == null) return;
intent.putExtra("x", monster.position.x);
intent.putExtra("y", monster.position.y);
}
public static void addMonsterIdentifiers(Bundle bundle, Monster monster) {
if (monster == null) return;
bundle.putInt("x", monster.position.x);
bundle.putInt("y", monster.position.y);
}
public static Monster getMonsterFromIntent(Intent intent, final WorldContext world) {
return getMonsterFromBundle(intent.getExtras(), world);
}
public static Monster getMonsterFromBundle(Bundle params, final WorldContext world) {
if (params == null) return null;
if (!params.containsKey("x")) return null;
int x = params.getInt("x");
int y = params.getInt("y");
return world.model.currentMaps.map.getMonsterAt(x, y);
}
public static void showMonsterEncounter(final MainActivity currentActivity, final ControllerContext context, final Monster monster) {
context.gameRoundController.pause();
Intent intent = new Intent(currentActivity, MonsterEncounterActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/monsterencounter"));
addMonsterIdentifiers(intent, monster);
currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_MONSTERENCOUNTER);
}
public static void showMonsterInfo(final Context context, final Monster monster) {
Intent intent = new Intent(context, MonsterInfoActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/monsterinfo"));
addMonsterIdentifiers(intent, monster);
context.startActivity(intent);
}
public static String getGroundLootFoundMessage(final Context ctx, final Loot loot) {
StringBuilder sb = new StringBuilder(60);
if (!loot.items.isEmpty()) {
sb.append(ctx.getString(R.string.dialog_groundloot_message));
}
appendGoldPickedUpMessage(ctx, loot, sb);
return sb.toString();
}
public static String getGroundLootPickedUpMessage(final Context ctx, final Loot loot) {
StringBuilder sb = new StringBuilder(60);
appendLootPickedUpMessage(ctx, loot, sb);
return sb.toString();
}
public static String getMonsterLootFoundMessage(final Context ctx, final Loot combinedLoot, final int exp) {
StringBuilder sb = new StringBuilder(60);
appendMonsterEncounterSurvivedMessage(ctx, sb, exp);
appendGoldPickedUpMessage(ctx, combinedLoot, sb);
return sb.toString();
}
public static String getMonsterLootPickedUpMessage(final Context ctx, final Loot combinedLoot, final int exp) {
StringBuilder sb = new StringBuilder(60);
appendMonsterEncounterSurvivedMessage(ctx, sb, exp);
appendLootPickedUpMessage(ctx, combinedLoot, sb);
return sb.toString();
}
private static void appendMonsterEncounterSurvivedMessage(final Context ctx, final StringBuilder sb, final int exp) {
sb.append(ctx.getString(R.string.dialog_monsterloot_message));
if (exp > 0) {
sb.append(' ');
sb.append(ctx.getString(R.string.dialog_monsterloot_gainedexp, exp));
}
}
private static void appendGoldPickedUpMessage(final Context ctx, final Loot loot, final StringBuilder sb) {
if (loot.gold > 0) {
sb.append(' ');
sb.append(ctx.getString(R.string.dialog_loot_foundgold, loot.gold));
}
}
private static void appendLootPickedUpMessage(final Context ctx, final Loot loot, final StringBuilder sb) {
appendGoldPickedUpMessage(ctx, loot, sb);
int numItems = loot.items.countItems();
if (numItems == 1) {
sb.append(' ');
sb.append(ctx.getString(R.string.dialog_loot_pickedupitem));
} else if (numItems > 1){
sb.append(' ');
sb.append(ctx.getString(R.string.dialog_loot_pickedupitems, numItems));
}
}
public static void showMonsterLoot(final MainActivity mainActivity, final ControllerContext controllers, final WorldContext world, final Collection<Loot> lootBags, final Loot combinedLoot, final String msg) {
// CombatController will do killedMonsterBags.clear() after this method has been called,
// so we need to keep the list of objects. Therefore, we create a shallow copy of the list of bags.
ArrayList<Loot> bags = new ArrayList<Loot>(lootBags);
showLoot(mainActivity, controllers, world, combinedLoot, bags, R.string.dialog_monsterloot_title, msg);
}
public static void showGroundLoot(final MainActivity mainActivity, final ControllerContext controllers, final WorldContext world, final Loot loot, final String msg) {
showLoot(mainActivity, controllers, world, loot, Collections.singletonList(loot), R.string.dialog_groundloot_title, msg);
}
private static void showLoot(final MainActivity mainActivity, final ControllerContext controllers, final WorldContext world, final Loot combinedLoot, final Iterable<Loot> lootBags, final int title, final String msg) {
final ListView itemList = new ListView(mainActivity);
itemList.setBackgroundResource(android.R.color.transparent);
itemList.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT));
// itemList.setPadding(20, 0, 20, 20);
itemList.setAdapter(new ItemContainerAdapter(mainActivity, world.tileManager, combinedLoot.items, world.model.player));
final Dialog d = CustomDialogFactory.createDialog(mainActivity,
mainActivity.getResources().getString(title),
mainActivity.getResources().getDrawable(R.drawable.ui_icon_equipment),
msg,
combinedLoot.items.isEmpty() ? null : itemList,
true,
false);
itemList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
final String itemTypeID = ((ItemContainerAdapter) parent.getAdapter()).getItem(position).itemType.id;
boolean removeFromCombinedLoot = true;
for (Loot l : lootBags) {
if (l == combinedLoot) removeFromCombinedLoot = false;
if (l.items.removeItem(itemTypeID)) {
controllers.itemController.removeLootBagIfEmpty(l);
break;
}
}
if (removeFromCombinedLoot) {
combinedLoot.items.removeItem(itemTypeID);
}
if (((ItemContainerAdapter) parent.getAdapter()).isEmpty()) {
ViewGroup vg = (ViewGroup) d.findViewById(R.id.dialog_content_container);
vg.setVisibility(View.GONE);
}
ItemType type = world.itemTypes.getItemType(itemTypeID);
world.model.player.inventory.addItem(type);
((ItemContainerAdapter) itemList.getAdapter()).notifyDataSetChanged();
}
});
if (!itemList.getAdapter().isEmpty()) {
CustomDialogFactory.addButton(d, R.string.dialog_loot_pickall, new View.OnClickListener() {
@Override
public void onClick(View v) {
controllers.itemController.pickupAll(lootBags);
}
});
}
CustomDialogFactory.addDismissButton(d, R.string.dialog_close);
showDialogAndPause(d, controllers, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
controllers.itemController.removeLootBagIfEmpty(lootBags);
}
});
}
public static void showHeroDied(final MainActivity mainActivity, final ControllerContext controllers) {
final Dialog d = CustomDialogFactory.createDialog(mainActivity,
mainActivity.getResources().getString(R.string.dialog_game_over_title),
mainActivity.getResources().getDrawable(R.drawable.ui_icon_combat),
mainActivity.getResources().getString(R.string.dialog_game_over_text),
null,
true,
false);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
showDialogAndPause(d, controllers, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
mainActivity.finish();
}
});
}
public static Intent getIntentForItemInfo(final Context ctx, String itemTypeID, ItemInfoActivity.ItemInfoAction actionType, String buttonText, boolean buttonEnabled, Inventory.WearSlot inventorySlot) {
Intent intent = new Intent(ctx, ItemInfoActivity.class);
intent.putExtra("buttonText", buttonText);
intent.putExtra("buttonEnabled", buttonEnabled);
intent.putExtra("moreActions", (actionType == ItemInfoActivity.ItemInfoAction.equip || actionType == ItemInfoActivity.ItemInfoAction.use || actionType == ItemInfoActivity.ItemInfoAction.none));
intent.putExtra("itemTypeID", itemTypeID);
intent.putExtra("actionType", actionType.name());
if (inventorySlot != null) intent.putExtra("inventorySlot", inventorySlot.name());
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/iteminfo/" + itemTypeID));
return intent;
}
public static Intent getIntentForLevelUp(final Context ctx) {
Intent intent = new Intent(ctx, LevelUpActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/levelup"));
return intent;
}
public static void showConfirmRest(final Activity currentActivity, final ControllerContext controllerContext, final MapObject area) {
final Dialog d = CustomDialogFactory.createDialog(currentActivity,
currentActivity.getResources().getString(R.string.dialog_rest_title),
null,
currentActivity.getResources().getString(R.string.dialog_rest_confirm_message),
null,
true);
CustomDialogFactory.addButton(d, android.R.string.yes, new View.OnClickListener() {
@Override
public void onClick(View v) {
controllerContext.mapController.rest(area);
}
});
CustomDialogFactory.addDismissButton(d, android.R.string.no);
showDialogAndPause(d, controllerContext);
}
public static void showRested(final Activity currentActivity, final ControllerContext controllerContext) {
// Dialog d = new AlertDialog.Builder(new ContextThemeWrapper(currentActivity, R.style.AndorsTrailStyle))
// .setTitle(R.string.dialog_rest_title)
// .setMessage(R.string.dialog_rest_message)
// .setNeutralButton(android.R.string.ok, null)
// .create();
final Dialog d = CustomDialogFactory.createDialog(currentActivity,
currentActivity.getResources().getString(R.string.dialog_rest_title),
null,
currentActivity.getResources().getString(R.string.dialog_rest_message),
null,
true);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
showDialogAndPause(d, controllerContext);
}
public static void showNewVersion(final Activity currentActivity, final OnDismissListener onDismiss) {
// new AlertDialog.Builder(new ContextThemeWrapper(currentActivity, R.style.AndorsTrailStyle))
// .setTitle(R.string.dialog_newversion_title)
// .setMessage(R.string.dialog_newversion_message)
// .setNeutralButton(android.R.string.ok, null)
// .show();
String text = currentActivity.getResources().getString(R.string.dialog_newversion_message);
if (!hasPermissions(currentActivity) && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
text += currentActivity.getResources().getString(R.string.dialog_newversion_permission_information);
}
final Dialog d = CustomDialogFactory.createDialog(currentActivity,
currentActivity.getResources().getString(R.string.dialog_newversion_title),
null,
text,
null,
true);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
CustomDialogFactory.setDismissListener(d, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
if (onDismiss != null) onDismiss.onDismiss(arg0);
}
});
CustomDialogFactory.show(d);
}
@TargetApi(23)
private static boolean hasPermissions(final Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.getApplicationContext().checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|| activity.getApplicationContext().checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
public static boolean showSave(final Activity mainActivity, final ControllerContext controllerContext, final WorldContext world) {
if (world.model.uiSelections.isInCombat) {
Toast.makeText(mainActivity, R.string.menu_save_saving_not_allowed_in_combat, Toast.LENGTH_SHORT).show();
return false;
}
if (!world.model.statistics.hasUnlimitedSaves()) {
final Dialog d = CustomDialogFactory.createDialog(mainActivity,
mainActivity.getResources().getString(R.string.menu_save_switch_character_title),
null,
mainActivity.getResources().getString(R.string.menu_save_switch_character),
null,
true);
CustomDialogFactory.addButton(d, android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
controllerContext.gameRoundController.pause();
Intent intent = new Intent(mainActivity, LoadSaveActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/save"));
mainActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_SAVEGAME);
}
});
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
CustomDialogFactory.show(d);
return false;
} else {
controllerContext.gameRoundController.pause();
Intent intent = new Intent(mainActivity, LoadSaveActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/save"));
mainActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_SAVEGAME);
return true;
}
}
public static void showLoad(final Activity currentActivity) {
Intent intent = new Intent(currentActivity, LoadSaveActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/load"));
currentActivity.startActivityForResult(intent, StartScreenActivity_MainMenu.INTENTREQUEST_LOADGAME);
}
public static void showLoad(final Fragment currentFragment) {
Intent intent = new Intent(currentFragment.getActivity(), LoadSaveActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/load"));
currentFragment.startActivityForResult(intent, StartScreenActivity_MainMenu.INTENTREQUEST_LOADGAME);
}
public static void showActorConditionInfo(final Context context, ActorConditionType conditionType) {
Intent intent = new Intent(context, ActorConditionInfoActivity.class);
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/actorconditioninfo/" + conditionType.conditionTypeID));
context.startActivity(intent);
}
public static Intent getIntentForBulkBuyingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BulkInterfaceType.buy);
}
public static Intent getIntentForBulkSellingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BulkInterfaceType.sell);
}
public static Intent getIntentForBulkDroppingInterface(final Context ctx, String itemTypeID, int totalAvailableAmount) {
return getIntentForBulkSelectionInterface(ctx, itemTypeID, totalAvailableAmount, BulkSelectionInterface.BulkInterfaceType.drop);
}
private static Intent getIntentForBulkSelectionInterface(final Context ctx, String itemTypeID, int totalAvailableAmount, BulkSelectionInterface.BulkInterfaceType interfaceType) {
Intent intent = new Intent(ctx, BulkSelectionInterface.class);
intent.putExtra("itemTypeID", itemTypeID);
intent.putExtra("totalAvailableAmount", totalAvailableAmount);
intent.putExtra("interfaceType", interfaceType.name());
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/bulkselection/" + itemTypeID));
return intent;
}
public static Intent getIntentForSkillInfo(final Context ctx, SkillCollection.SkillID skillID) {
Intent intent = new Intent(ctx, SkillInfoActivity.class);
intent.putExtra("skillID", skillID.name());
intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/showskillinfo/" + skillID));
return intent;
}
public static void showCombatLog(final Context context, final ControllerContext controllerContext, final WorldContext world) {
String[] combatLogMessages = world.model.combatLog.getAllMessages();
View view = null;
ListView itemList = null;
itemList = new ListView(context);
itemList.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.WRAP_CONTENT));
itemList.setStackFromBottom(true);
itemList.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
itemList.setChoiceMode(ListView.CHOICE_MODE_NONE);
itemList.setBackgroundColor(ThemeHelper.getThemeColor(context, R.attr.ui_theme_stdframe_bg_color));
if (combatLogMessages.length <= 0) {
combatLogMessages = new String[] {context.getResources().getString(R.string.combat_log_noentries)};
}
itemList.setAdapter(new ArrayAdapter<String>(context, R.layout.combatlog_row, android.R.id.text1, combatLogMessages));
view = itemList;
final Dialog d = CustomDialogFactory.createDialog(context,
context.getResources().getString(R.string.combat_log_title),
context.getResources().getDrawable(R.drawable.ui_icon_combat),
null,
view,
true);
CustomDialogFactory.addDismissButton(d, R.string.dialog_close);
showDialogAndPause(d, controllerContext);
}
}

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail;
package com.gpl.rpg.AndorsTrail_beta1;
import java.lang.ref.WeakReference;
@@ -6,11 +6,11 @@ import android.content.Context;
import android.content.res.Resources;
import android.os.AsyncTask;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.ModelContainer;
import com.gpl.rpg.AndorsTrail.resource.ResourceLoader;
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.ModelContainer;
import com.gpl.rpg.AndorsTrail_beta1.resource.ResourceLoader;
import com.gpl.rpg.AndorsTrail_beta1.savegames.Savegames;
public final class WorldSetup {

View File

@@ -1,6 +1,5 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -12,9 +11,9 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
public final class AboutActivity extends AndorsTrailBaseActivity implements ImageGetter {

View File

@@ -1,6 +1,5 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
@@ -10,13 +9,13 @@ import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
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.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.AbilityModifierInfoView;
import com.gpl.rpg.AndorsTrail.view.ItemEffectsView_OnUse;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.AbilityModifierInfoView;
import com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView_OnUse;
public final class ActorConditionInfoActivity extends AndorsTrailBaseActivity {

View File

@@ -1,9 +1,9 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.os.Bundle;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
public abstract class AndorsTrailBaseActivity extends Activity {
@Override

View File

@@ -1,12 +1,9 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
public abstract class AndorsTrailBaseFragmentActivity extends FragmentActivity {
@Override

View File

@@ -1,6 +1,5 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.Resources;
@@ -17,13 +16,13 @@ import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;
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.item.ItemType;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.ItemController;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.CustomDialogFactory;
/**
* @author ejwessel

View File

@@ -1,8 +1,7 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@@ -30,22 +29,22 @@ import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.TextView.BufferType;
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.controller.ConversationController;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.conversation.Reply;
import com.gpl.rpg.AndorsTrail.model.item.Loot;
import com.gpl.rpg.AndorsTrail.model.quest.Quest;
import com.gpl.rpg.AndorsTrail.model.quest.QuestLogEntry;
import com.gpl.rpg.AndorsTrail.model.quest.QuestProgress;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.ConversationController;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.conversation.Reply;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Loot;
import com.gpl.rpg.AndorsTrail_beta1.model.quest.Quest;
import com.gpl.rpg.AndorsTrail_beta1.model.quest.QuestLogEntry;
import com.gpl.rpg.AndorsTrail_beta1.model.quest.QuestProgress;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
public final class ConversationActivity
extends AndorsTrailBaseActivity

View File

@@ -1,18 +1,18 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.Constants;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.view.MainView;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.Constants;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapObject;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.view.MainView;
import android.content.Context;
import android.content.res.Resources;

View File

@@ -1,172 +1,168 @@
package com.gpl.rpg.AndorsTrail.activity;
import java.io.File;
import java.io.FileNotFoundException;
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.WorldMapController;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.model.map.WorldMapSegment;
import com.gpl.rpg.AndorsTrail.model.map.WorldMapSegment.WorldMapSegmentMap;
import com.gpl.rpg.AndorsTrail.util.AndroidStorage;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.L;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.FileProvider;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;
public final class DisplayWorldMapActivity extends AndorsTrailBaseActivity {
private WorldContext world;
private WebView displayworldmap_webview;
private String worldMapSegmentName;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.getBaseTheme());
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
this.world = app.getWorld();
app.setWindowParameters(this);
setContentView(R.layout.displayworldmap);
displayworldmap_webview = (WebView) findViewById(R.id.displayworldmap_webview);
displayworldmap_webview.setBackgroundColor(ThemeHelper.getThemeColor(this, R.attr.ui_theme_displayworldmap_bg_color));
displayworldmap_webview.getSettings().setBuiltInZoomControls(true);
displayworldmap_webview.getSettings().setUseWideViewPort(true);
displayworldmap_webview.setVerticalScrollBarEnabled(true);
displayworldmap_webview.setHorizontalScrollBarEnabled(true);
displayworldmap_webview.getSettings().setAllowFileAccess(true);
enableJavascript();
Button b = (Button) findViewById(R.id.displayworldmap_close);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DisplayWorldMapActivity.this.finish();
}
});
b = (Button) findViewById(R.id.displayworldmap_recenter);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
recenter();
}
});
worldMapSegmentName = getIntent().getStringExtra("worldMapSegmentName");
}
@SuppressLint("SetJavaScriptEnabled")
public void enableJavascript() {
displayworldmap_webview.getSettings().setJavaScriptEnabled(true);
}
@Override
public void onResume() {
super.onResume();
update();
}
WorldMapSegmentMap map;
Coord offsetWorldmapTo;
@SuppressLint("NewApi")
private void update() {
File worldmap = WorldMapController.getCombinedWorldMapFile(this, worldMapSegmentName);
if (!worldmap.exists()) {
Toast.makeText(this, getResources().getString(R.string.menu_button_worldmap_failed), Toast.LENGTH_LONG).show();
this.finish();
}
WorldMapSegment segment = world.maps.worldMapSegments.get(worldMapSegmentName);
map = segment.maps.get(world.model.currentMaps.map.name);
if (map == null) {
this.finish();
return;
}
offsetWorldmapTo = new Coord(999999, 999999);
for (WorldMapSegmentMap map : segment.maps.values()) {
PredefinedMap predefinedMap = world.maps.findPredefinedMap(map.mapName);
if (predefinedMap == null) continue;
if (!predefinedMap.visited) continue;
if (!WorldMapController.fileForMapExists(this, predefinedMap)) continue;
offsetWorldmapTo.x = Math.min(offsetWorldmapTo.x, map.worldPosition.x);
offsetWorldmapTo.y = Math.min(offsetWorldmapTo.y, map.worldPosition.y);
}
String url = AndroidStorage.getUrlForFile(this, worldmap) + '?'
+ (world.model.player.position.x + map.worldPosition.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE
+ ','
+ (world.model.player.position.y + map.worldPosition.y-1) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE;
L.log("Showing " + url);
displayworldmap_webview.loadUrl(url);
displayworldmap_webview.setBackgroundColor(ThemeHelper.getThemeColor(this, R.attr.ui_theme_displayworldmap_bg_color));
displayworldmap_webview.setWebViewClient(new WebViewClient() {
@SuppressLint("NewApi")
@Override
public void onPageFinished(WebView view, String url)
{
recenter();
}
});
}
private void recenter() {
displayworldmap_webview.postDelayed(new Runnable() {
@Override
public void run() {
if (map != null) {
//Local map to global worldmap
int x = world.model.player.position.x + map.worldPosition.x - offsetWorldmapTo.x;
//Tile coord to pixel coord
x *= WorldMapController.WORLDMAP_DISPLAY_TILESIZE;
x += WorldMapController.WORLDMAP_DISPLAY_TILESIZE/2;
//Zoom level
x = (int)(x * displayworldmap_webview.getScale());
//Center
x -= displayworldmap_webview.getWidth() / 2;
//Local map to global worldmap
int y = world.model.player.position.y + map.worldPosition.y - offsetWorldmapTo.y;
//Tile coord to pixel coord
y *= WorldMapController.WORLDMAP_DISPLAY_TILESIZE;
y += WorldMapController.WORLDMAP_DISPLAY_TILESIZE/2;
//Zoom level
y = (int)(y * displayworldmap_webview.getScale());
//Center
y -= displayworldmap_webview.getHeight() / 2;
displayworldmap_webview.scrollTo(x, y);
}
}
}, 100);
}
@Override
public void finish() {
ViewGroup view = (ViewGroup) getWindow().getDecorView();
view.removeAllViews();
super.finish();
}
}
package com.gpl.rpg.AndorsTrail_beta1.activity;
import java.io.File;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.WorldMapController;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.WorldMapSegment;
import com.gpl.rpg.AndorsTrail_beta1.model.map.WorldMapSegment.WorldMapSegmentMap;
import com.gpl.rpg.AndorsTrail_beta1.util.AndroidStorage;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.L;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;
public final class DisplayWorldMapActivity extends AndorsTrailBaseActivity {
private WorldContext world;
private WebView displayworldmap_webview;
private String worldMapSegmentName;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.getBaseTheme());
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
this.world = app.getWorld();
app.setWindowParameters(this);
setContentView(R.layout.displayworldmap);
displayworldmap_webview = (WebView) findViewById(R.id.displayworldmap_webview);
displayworldmap_webview.setBackgroundColor(ThemeHelper.getThemeColor(this, R.attr.ui_theme_displayworldmap_bg_color));
displayworldmap_webview.getSettings().setBuiltInZoomControls(true);
displayworldmap_webview.getSettings().setUseWideViewPort(true);
displayworldmap_webview.setVerticalScrollBarEnabled(true);
displayworldmap_webview.setHorizontalScrollBarEnabled(true);
displayworldmap_webview.getSettings().setAllowFileAccess(true);
enableJavascript();
Button b = (Button) findViewById(R.id.displayworldmap_close);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DisplayWorldMapActivity.this.finish();
}
});
b = (Button) findViewById(R.id.displayworldmap_recenter);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
recenter();
}
});
worldMapSegmentName = getIntent().getStringExtra("worldMapSegmentName");
}
@SuppressLint("SetJavaScriptEnabled")
public void enableJavascript() {
displayworldmap_webview.getSettings().setJavaScriptEnabled(true);
}
@Override
public void onResume() {
super.onResume();
update();
}
WorldMapSegmentMap map;
Coord offsetWorldmapTo;
@SuppressLint("NewApi")
private void update() {
File worldmap = WorldMapController.getCombinedWorldMapFile(this, worldMapSegmentName);
if (!worldmap.exists()) {
Toast.makeText(this, getResources().getString(R.string.menu_button_worldmap_failed), Toast.LENGTH_LONG).show();
this.finish();
}
WorldMapSegment segment = world.maps.worldMapSegments.get(worldMapSegmentName);
map = segment.maps.get(world.model.currentMaps.map.name);
if (map == null) {
this.finish();
return;
}
offsetWorldmapTo = new Coord(999999, 999999);
for (WorldMapSegmentMap map : segment.maps.values()) {
PredefinedMap predefinedMap = world.maps.findPredefinedMap(map.mapName);
if (predefinedMap == null) continue;
if (!predefinedMap.visited) continue;
if (!WorldMapController.fileForMapExists(this, predefinedMap)) continue;
offsetWorldmapTo.x = Math.min(offsetWorldmapTo.x, map.worldPosition.x);
offsetWorldmapTo.y = Math.min(offsetWorldmapTo.y, map.worldPosition.y);
}
String url = AndroidStorage.getUrlForFile(this, worldmap) + '?'
+ (world.model.player.position.x + map.worldPosition.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE
+ ','
+ (world.model.player.position.y + map.worldPosition.y-1) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE;
L.log("Showing " + url);
displayworldmap_webview.loadUrl(url);
displayworldmap_webview.setBackgroundColor(ThemeHelper.getThemeColor(this, R.attr.ui_theme_displayworldmap_bg_color));
displayworldmap_webview.setWebViewClient(new WebViewClient() {
@SuppressLint("NewApi")
@Override
public void onPageFinished(WebView view, String url)
{
recenter();
}
});
}
private void recenter() {
displayworldmap_webview.postDelayed(new Runnable() {
@Override
public void run() {
if (map != null) {
//Local map to global worldmap
int x = world.model.player.position.x + map.worldPosition.x - offsetWorldmapTo.x;
//Tile coord to pixel coord
x *= WorldMapController.WORLDMAP_DISPLAY_TILESIZE;
x += WorldMapController.WORLDMAP_DISPLAY_TILESIZE/2;
//Zoom level
x = (int)(x * displayworldmap_webview.getScale());
//Center
x -= displayworldmap_webview.getWidth() / 2;
//Local map to global worldmap
int y = world.model.player.position.y + map.worldPosition.y - offsetWorldmapTo.y;
//Tile coord to pixel coord
y *= WorldMapController.WORLDMAP_DISPLAY_TILESIZE;
y += WorldMapController.WORLDMAP_DISPLAY_TILESIZE/2;
//Zoom level
y = (int)(y * displayworldmap_webview.getScale());
//Center
y -= displayworldmap_webview.getHeight() / 2;
displayworldmap_webview.scrollTo(x, y);
}
}
}, 100);
}
@Override
public void finish() {
ViewGroup view = (ViewGroup) getWindow().getDecorView();
view.removeAllViews();
super.finish();
}
}

View File

@@ -1,23 +1,21 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
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;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.HeroinfoActivity_Inventory;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.HeroinfoActivity_Quests;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.HeroinfoActivity_Skills;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.HeroinfoActivity_Stats;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
public final class HeroinfoActivity extends AndorsTrailBaseFragmentActivity {
private WorldContext world;

View File

@@ -1,139 +1,139 @@
package com.gpl.rpg.AndorsTrail.activity;
import java.util.Collections;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
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.item.ItemType;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.ItemEffectsView;
public final class ItemInfoActivity extends AndorsTrailBaseActivity {
public static enum ItemInfoAction {
none, use, equip, unequip, buy, sell
}
public static final int RESULT_MORE_ACTIONS = Activity.RESULT_FIRST_USER;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.getDialogTheme());
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
final WorldContext world = app.getWorld();
app.setWindowParameters(this);
final Intent intent = getIntent();
Bundle params = intent.getExtras();
String itemTypeID = params.getString("itemTypeID");
final ItemType itemType = world.itemTypes.getItemType(itemTypeID);
final String buttonText = params.getString("buttonText");
boolean buttonEnabled = params.getBoolean("buttonEnabled");
boolean moreButtonEnabled = params.getBoolean("moreActions");
setContentView(R.layout.iteminfo);
TextView tv = (TextView) findViewById(R.id.iteminfo_title);
tv.setText(itemType.getName(world.model.player));
world.tileManager.setImageViewTileForSingleItemType(getResources(), tv, itemType);
tv = (TextView) findViewById(R.id.iteminfo_description);
String description = itemType.getDescription();
if (description != null) {
tv.setText(description);
tv.setVisibility(View.VISIBLE);
} else {
tv.setVisibility(View.GONE);
}
tv = (TextView) findViewById(R.id.iteminfo_category);
tv.setText(itemType.category.displayName);
((ItemEffectsView) findViewById(R.id.iteminfo_effects)).update(
itemType.effects_equip,
itemType.effects_use == null ? null : Collections.singletonList(itemType.effects_use),
itemType.effects_hit == null ? null : Collections.singletonList(itemType.effects_hit),
itemType.effects_kill == null ? null : Collections.singletonList(itemType.effects_kill),
itemType.effects_hitReceived == null ? null : Collections.singletonList(itemType.effects_hitReceived),
null,
itemType.isWeapon()
);
Button b = (Button) findViewById(R.id.iteminfo_close);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
setResult(RESULT_CANCELED);
ItemInfoActivity.this.finish();
}
});
b = (Button) findViewById(R.id.iteminfo_more);
if (!moreButtonEnabled) {
b.setVisibility(View.GONE);
} else {
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtras(intent);
setResult(RESULT_MORE_ACTIONS, intent);
ItemInfoActivity.this.finish();
}
});
}
b = (Button) findViewById(R.id.iteminfo_action);
if (buttonText != null && buttonText.length() > 0) {
b.setVisibility(View.VISIBLE);
b.setEnabled(buttonEnabled);
b.setText(buttonText);
} else {
b.setVisibility(View.GONE);
}
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtras(intent);
setResult(RESULT_OK, result);
ItemInfoActivity.this.finish();
}
});
tv = (TextView) findViewById(R.id.iteminfo_displaytype);
if (itemType.isOrdinaryItem()) {
tv.setVisibility(View.GONE);
} else {
tv.setVisibility(View.VISIBLE);
final String diplayType = getDisplayTypeString(getResources(), itemType);
tv.setText(diplayType);
}
}
public static String getDisplayTypeString(Resources res, ItemType itemType) {
switch (itemType.displayType) {
case rare: return res.getString(R.string.iteminfo_displaytypes_rare);
case extraordinary: return res.getString(R.string.iteminfo_displaytypes_extraordinary);
case legendary: return res.getString(R.string.iteminfo_displaytypes_legendary);
case ordinary: return res.getString(R.string.iteminfo_displaytypes_ordinary);
case quest: return res.getString(R.string.iteminfo_displaytypes_quest);
default: return "";
}
}
}
package com.gpl.rpg.AndorsTrail_beta1.activity;
import java.util.Collections;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView;
public final class ItemInfoActivity extends AndorsTrailBaseActivity {
public static enum ItemInfoAction {
none, use, equip, unequip, buy, sell
}
public static final int RESULT_MORE_ACTIONS = Activity.RESULT_FIRST_USER;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.getDialogTheme());
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (!app.isInitialized()) { finish(); return; }
final WorldContext world = app.getWorld();
app.setWindowParameters(this);
final Intent intent = getIntent();
Bundle params = intent.getExtras();
String itemTypeID = params.getString("itemTypeID");
final ItemType itemType = world.itemTypes.getItemType(itemTypeID);
final String buttonText = params.getString("buttonText");
boolean buttonEnabled = params.getBoolean("buttonEnabled");
boolean moreButtonEnabled = params.getBoolean("moreActions");
setContentView(R.layout.iteminfo);
TextView tv = (TextView) findViewById(R.id.iteminfo_title);
tv.setText(itemType.getName(world.model.player));
world.tileManager.setImageViewTileForSingleItemType(getResources(), tv, itemType);
tv = (TextView) findViewById(R.id.iteminfo_description);
String description = itemType.getDescription();
if (description != null) {
tv.setText(description);
tv.setVisibility(View.VISIBLE);
} else {
tv.setVisibility(View.GONE);
}
tv = (TextView) findViewById(R.id.iteminfo_category);
tv.setText(itemType.category.displayName);
((ItemEffectsView) findViewById(R.id.iteminfo_effects)).update(
itemType.effects_equip,
itemType.effects_use == null ? null : Collections.singletonList(itemType.effects_use),
itemType.effects_hit == null ? null : Collections.singletonList(itemType.effects_hit),
itemType.effects_kill == null ? null : Collections.singletonList(itemType.effects_kill),
itemType.effects_hitReceived == null ? null : Collections.singletonList(itemType.effects_hitReceived),
null,
itemType.isWeapon()
);
Button b = (Button) findViewById(R.id.iteminfo_close);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
setResult(RESULT_CANCELED);
ItemInfoActivity.this.finish();
}
});
b = (Button) findViewById(R.id.iteminfo_more);
if (!moreButtonEnabled) {
b.setVisibility(View.GONE);
} else {
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtras(intent);
setResult(RESULT_MORE_ACTIONS, intent);
ItemInfoActivity.this.finish();
}
});
}
b = (Button) findViewById(R.id.iteminfo_action);
if (buttonText != null && buttonText.length() > 0) {
b.setVisibility(View.VISIBLE);
b.setEnabled(buttonEnabled);
b.setText(buttonText);
} else {
b.setVisibility(View.GONE);
}
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent result = new Intent();
result.putExtras(intent);
setResult(RESULT_OK, result);
ItemInfoActivity.this.finish();
}
});
tv = (TextView) findViewById(R.id.iteminfo_displaytype);
if (itemType.isOrdinaryItem()) {
tv.setVisibility(View.GONE);
} else {
tv.setVisibility(View.VISIBLE);
final String diplayType = getDisplayTypeString(getResources(), itemType);
tv.setText(diplayType);
}
}
public static String getDisplayTypeString(Resources res, ItemType itemType) {
switch (itemType.displayType) {
case rare: return res.getString(R.string.iteminfo_displaytypes_rare);
case extraordinary: return res.getString(R.string.iteminfo_displaytypes_extraordinary);
case legendary: return res.getString(R.string.iteminfo_displaytypes_legendary);
case ordinary: return res.getString(R.string.iteminfo_displaytypes_ordinary);
case quest: return res.getString(R.string.iteminfo_displaytypes_quest);
default: return "";
}
}
}

View File

@@ -1,6 +1,5 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
@@ -9,14 +8,14 @@ import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.ActorStatsController;
import com.gpl.rpg.AndorsTrail.controller.Constants;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.ActorStatsController;
import com.gpl.rpg.AndorsTrail_beta1.controller.Constants;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
public final class LevelUpActivity extends AndorsTrailBaseActivity {
private WorldContext world;

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import java.util.Collections;
import java.util.List;
@@ -19,15 +19,15 @@ import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.model.ModelContainer;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
import com.gpl.rpg.AndorsTrail.savegames.Savegames.FileHeader;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.model.ModelContainer;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail_beta1.savegames.Savegames;
import com.gpl.rpg.AndorsTrail_beta1.savegames.Savegames.FileHeader;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.CustomDialogFactory;
public final class LoadSaveActivity extends AndorsTrailBaseActivity implements OnClickListener {
private boolean isLoading = true;

View File

@@ -1,180 +1,179 @@
package com.gpl.rpg.AndorsTrail.activity;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.WorldSetup;
import com.gpl.rpg.AndorsTrail.WorldSetup.OnResourcesLoadedListener;
import com.gpl.rpg.AndorsTrail.WorldSetup.OnSceneLoadedListener;
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView;
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
public final class LoadingActivity extends AndorsTrailBaseActivity implements OnResourcesLoadedListener, OnSceneLoadedListener {
private WorldSetup setup;
private Dialog progressDialog;
private CloudsAnimatorView clouds_back, clouds_mid, clouds_front;
boolean loaded = false;
private Object semaphore = new Object();
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.getBaseTheme());
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
app.setWindowParameters(this);
setContentView(R.layout.startscreen);
TextView tv = (TextView) findViewById(R.id.startscreen_version);
tv.setVisibility(View.GONE);
clouds_back = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_back);
if (clouds_back != null) clouds_back.setCloudsCountAndLayer(40, CloudsAnimatorView.Layer.below);
clouds_mid = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_mid);
if (clouds_mid != null) clouds_mid.setCloudsCountAndLayer(15, CloudsAnimatorView.Layer.center);
clouds_front = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_front);
if (clouds_front != null) clouds_front.setCloudsCountAndLayer(8, CloudsAnimatorView.Layer.above);
this.setup = app.getWorldSetup();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
((AnimationDrawable)((ImageView)findViewById(R.id.title_logo)).getDrawable()).start();
ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
int ivWidth = iv.getWidth();
int drawableWidth = iv.getDrawable().getIntrinsicWidth();
float ratio = ((float)ivWidth) / ((float)drawableWidth);
if (clouds_back != null) {
clouds_back.setScalingRatio(ratio);
}
if (clouds_mid != null) {
clouds_mid.setScalingRatio(ratio);
}
if (clouds_front != null) {
clouds_front.setScalingRatio(ratio);
}
if (progressDialog == null) {
progressDialog = CustomDialogFactory.createDialog(this, getResources().getString(R.string.dialog_loading_message),
getResources().getDrawable(R.drawable.loading_anim), null, null, false, false);
synchronized (semaphore) {
if (!loaded) {
progressDialog.setOwnerActivity(this);
CustomDialogFactory.show(progressDialog);
}
}
}
}
}
@Override
public void onResume() {
super.onResume();
setup.setOnResourcesLoadedListener(this);
final ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
iv.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
float[] point = new float[]{0f,0.25f * iv.getDrawable().getIntrinsicHeight()};
iv.getImageMatrix().mapPoints(point);
int imgY = (int) (iv.getTop() + point[1]);
if (clouds_back != null) {
clouds_back.setYMax(imgY);
}
if (clouds_mid != null) {
clouds_mid.setYMax(imgY);
}
if (clouds_front != null) {
clouds_front.setYMax(imgY);
}
iv.getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
});
if (clouds_back != null)clouds_back.resumeAnimation();
if (clouds_mid != null)clouds_mid.resumeAnimation();
if (clouds_front != null)clouds_front.resumeAnimation();
}
@Override
public void onPause() {
super.onPause();
setup.setOnResourcesLoadedListener(null);
setup.removeOnSceneLoadedListener(this);
if (clouds_back != null)clouds_back.pauseAnimation();
if (clouds_mid != null)clouds_mid.pauseAnimation();
if (clouds_front != null)clouds_front.pauseAnimation();
}
@Override
public void onResourcesLoaded() {
loaded = false;
setup.startCharacterSetup(this);
}
@Override
public void onSceneLoaded() {
synchronized (semaphore) {
if (progressDialog != null) progressDialog.dismiss();
loaded =true;
}
startActivity(new Intent(this, MainActivity.class));
this.finish();
}
@Override
public void onSceneLoadFailed(Savegames.LoadSavegameResult loadResult) {
synchronized (semaphore) {
if (progressDialog != null) progressDialog.dismiss();
loaded =true;
}
if (loadResult == Savegames.LoadSavegameResult.savegameIsFromAFutureVersion) {
showLoadingFailedDialog(R.string.dialog_loading_failed_incorrectversion);
} else if (loadResult == Savegames.LoadSavegameResult.cheatingDetected) {
showLoadingFailedDialog(R.string.dialog_loading_failed_cheat);
} else {
showLoadingFailedDialog(R.string.dialog_loading_failed_message);
}
}
private void showLoadingFailedDialog(int messageResourceID) {
final Dialog d = CustomDialogFactory.createDialog(this, getResources().getString(R.string.dialog_loading_failed_title), null, getResources().getString(messageResourceID), null, true);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
CustomDialogFactory.setDismissListener(d, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
LoadingActivity.this.finish();
}
});
CustomDialogFactory.show(d);
}
}
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.WorldSetup;
import com.gpl.rpg.AndorsTrail_beta1.WorldSetup.OnResourcesLoadedListener;
import com.gpl.rpg.AndorsTrail_beta1.WorldSetup.OnSceneLoadedListener;
import com.gpl.rpg.AndorsTrail_beta1.savegames.Savegames;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.CloudsAnimatorView;
import com.gpl.rpg.AndorsTrail_beta1.view.CustomDialogFactory;
public final class LoadingActivity extends AndorsTrailBaseActivity implements OnResourcesLoadedListener, OnSceneLoadedListener {
private WorldSetup setup;
private Dialog progressDialog;
private CloudsAnimatorView clouds_back, clouds_mid, clouds_front;
boolean loaded = false;
private Object semaphore = new Object();
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.getBaseTheme());
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
app.setWindowParameters(this);
setContentView(R.layout.startscreen);
TextView tv = (TextView) findViewById(R.id.startscreen_version);
tv.setVisibility(View.GONE);
clouds_back = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_back);
if (clouds_back != null) clouds_back.setCloudsCountAndLayer(40, CloudsAnimatorView.Layer.below);
clouds_mid = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_mid);
if (clouds_mid != null) clouds_mid.setCloudsCountAndLayer(15, CloudsAnimatorView.Layer.center);
clouds_front = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_front);
if (clouds_front != null) clouds_front.setCloudsCountAndLayer(8, CloudsAnimatorView.Layer.above);
this.setup = app.getWorldSetup();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
((AnimationDrawable)((ImageView)findViewById(R.id.title_logo)).getDrawable()).start();
ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
int ivWidth = iv.getWidth();
int drawableWidth = iv.getDrawable().getIntrinsicWidth();
float ratio = ((float)ivWidth) / ((float)drawableWidth);
if (clouds_back != null) {
clouds_back.setScalingRatio(ratio);
}
if (clouds_mid != null) {
clouds_mid.setScalingRatio(ratio);
}
if (clouds_front != null) {
clouds_front.setScalingRatio(ratio);
}
if (progressDialog == null) {
progressDialog = CustomDialogFactory.createDialog(this, getResources().getString(R.string.dialog_loading_message),
getResources().getDrawable(R.drawable.loading_anim), null, null, false, false);
synchronized (semaphore) {
if (!loaded) {
progressDialog.setOwnerActivity(this);
CustomDialogFactory.show(progressDialog);
}
}
}
}
}
@Override
public void onResume() {
super.onResume();
setup.setOnResourcesLoadedListener(this);
final ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
iv.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
float[] point = new float[]{0f,0.25f * iv.getDrawable().getIntrinsicHeight()};
iv.getImageMatrix().mapPoints(point);
int imgY = (int) (iv.getTop() + point[1]);
if (clouds_back != null) {
clouds_back.setYMax(imgY);
}
if (clouds_mid != null) {
clouds_mid.setYMax(imgY);
}
if (clouds_front != null) {
clouds_front.setYMax(imgY);
}
iv.getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
});
if (clouds_back != null)clouds_back.resumeAnimation();
if (clouds_mid != null)clouds_mid.resumeAnimation();
if (clouds_front != null)clouds_front.resumeAnimation();
}
@Override
public void onPause() {
super.onPause();
setup.setOnResourcesLoadedListener(null);
setup.removeOnSceneLoadedListener(this);
if (clouds_back != null)clouds_back.pauseAnimation();
if (clouds_mid != null)clouds_mid.pauseAnimation();
if (clouds_front != null)clouds_front.pauseAnimation();
}
@Override
public void onResourcesLoaded() {
loaded = false;
setup.startCharacterSetup(this);
}
@Override
public void onSceneLoaded() {
synchronized (semaphore) {
if (progressDialog != null) progressDialog.dismiss();
loaded =true;
}
startActivity(new Intent(this, MainActivity.class));
this.finish();
}
@Override
public void onSceneLoadFailed(Savegames.LoadSavegameResult loadResult) {
synchronized (semaphore) {
if (progressDialog != null) progressDialog.dismiss();
loaded =true;
}
if (loadResult == Savegames.LoadSavegameResult.savegameIsFromAFutureVersion) {
showLoadingFailedDialog(R.string.dialog_loading_failed_incorrectversion);
} else if (loadResult == Savegames.LoadSavegameResult.cheatingDetected) {
showLoadingFailedDialog(R.string.dialog_loading_failed_cheat);
} else {
showLoadingFailedDialog(R.string.dialog_loading_failed_message);
}
}
private void showLoadingFailedDialog(int messageResourceID) {
final Dialog d = CustomDialogFactory.createDialog(this, getResources().getString(R.string.dialog_loading_failed_title), null, getResources().getString(messageResourceID), null, true);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
CustomDialogFactory.setDismissListener(d, new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
LoadingActivity.this.finish();
}
});
CustomDialogFactory.show(d);
}
}

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import java.lang.ref.WeakReference;
import java.util.Collection;
@@ -18,41 +18,40 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.Dialogs;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.AttackResult;
import com.gpl.rpg.AndorsTrail.controller.CombatController;
import com.gpl.rpg.AndorsTrail.controller.Constants;
import com.gpl.rpg.AndorsTrail.controller.listeners.CombatActionListener;
import com.gpl.rpg.AndorsTrail.controller.listeners.CombatTurnListener;
import com.gpl.rpg.AndorsTrail.controller.listeners.PlayerMovementListener;
import com.gpl.rpg.AndorsTrail.controller.listeners.WorldEventListener;
import com.gpl.rpg.AndorsTrail.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.Loot;
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.CombatView;
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
import com.gpl.rpg.AndorsTrail.view.DisplayActiveActorConditionIcons;
import com.gpl.rpg.AndorsTrail.view.ItemContainerAdapter;
import com.gpl.rpg.AndorsTrail.view.MainView;
import com.gpl.rpg.AndorsTrail.view.QuickButton;
import com.gpl.rpg.AndorsTrail.view.QuickitemView;
import com.gpl.rpg.AndorsTrail.view.QuickslotsItemContainerAdapter;
import com.gpl.rpg.AndorsTrail.view.StatusView;
import com.gpl.rpg.AndorsTrail.view.ToolboxView;
import com.gpl.rpg.AndorsTrail.view.VirtualDpadView;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.AttackResult;
import com.gpl.rpg.AndorsTrail_beta1.controller.CombatController;
import com.gpl.rpg.AndorsTrail_beta1.controller.Constants;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.CombatActionListener;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.CombatTurnListener;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.PlayerMovementListener;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.WorldEventListener;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Loot;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapObject;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail_beta1.savegames.Savegames;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.CombatView;
import com.gpl.rpg.AndorsTrail_beta1.view.CustomDialogFactory;
import com.gpl.rpg.AndorsTrail_beta1.view.DisplayActiveActorConditionIcons;
import com.gpl.rpg.AndorsTrail_beta1.view.ItemContainerAdapter;
import com.gpl.rpg.AndorsTrail_beta1.view.MainView;
import com.gpl.rpg.AndorsTrail_beta1.view.QuickButton;
import com.gpl.rpg.AndorsTrail_beta1.view.QuickitemView;
import com.gpl.rpg.AndorsTrail_beta1.view.QuickslotsItemContainerAdapter;
import com.gpl.rpg.AndorsTrail_beta1.view.StatusView;
import com.gpl.rpg.AndorsTrail_beta1.view.ToolboxView;
import com.gpl.rpg.AndorsTrail_beta1.view.VirtualDpadView;
public final class MainActivity
extends AndorsTrailBaseActivity

View File

@@ -1,6 +1,5 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
@@ -8,13 +7,13 @@ import android.view.Window;
import android.widget.Button;
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.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
public final class MonsterEncounterActivity extends AndorsTrailBaseActivity {

View File

@@ -1,6 +1,5 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
@@ -9,16 +8,16 @@ import android.view.Window;
import android.widget.Button;
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.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.ItemEffectsView;
import com.gpl.rpg.AndorsTrail.view.RangeBar;
import com.gpl.rpg.AndorsTrail.view.TraitsInfoView;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView;
import com.gpl.rpg.AndorsTrail_beta1.view.RangeBar;
import com.gpl.rpg.AndorsTrail_beta1.view.TraitsInfoView;
public final class MonsterInfoActivity extends AndorsTrailBaseActivity {

View File

@@ -1,36 +1,36 @@
package com.gpl.rpg.AndorsTrail.activity;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.Window;
import android.view.WindowManager;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
public final class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.getBaseTheme());
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (app.getPreferences().fullscreen) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
app.setLocale(this);
addPreferencesFromResource(R.xml.preferences);
}
@Override
protected void onResume() {
super.onResume();
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
app.setLocale(this);
}
}
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.Window;
import android.view.WindowManager;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
public final class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.getBaseTheme());
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
if (app.getPreferences().fullscreen) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
app.setLocale(this);
addPreferencesFromResource(R.xml.preferences);
}
@Override
protected void onResume() {
super.onResume();
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
app.setLocale(this);
}
}

View File

@@ -1,20 +1,18 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.activity.fragment.ShopActivity_Buy;
import com.gpl.rpg.AndorsTrail.activity.fragment.ShopActivity_Sell;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.ShopActivity_Buy;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.ShopActivity_Sell;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
public final class ShopActivity extends AndorsTrailBaseFragmentActivity {

View File

@@ -1,6 +1,5 @@
package com.gpl.rpg.AndorsTrail.activity;
package com.gpl.rpg.AndorsTrail_beta1.activity;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
@@ -11,15 +10,15 @@ import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.TextView;
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.SkillController;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.ability.SkillInfo;
import com.gpl.rpg.AndorsTrail.model.ability.SkillInfo.SkillLevelRequirement;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.SkillController;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillInfo;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillInfo.SkillLevelRequirement;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
public final class SkillInfoActivity extends AndorsTrailBaseActivity {

View File

@@ -1,292 +1,287 @@
package com.gpl.rpg.AndorsTrail.activity;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.activity.fragment.StartScreenActivity_MainMenu;
import com.gpl.rpg.AndorsTrail.activity.fragment.StartScreenActivity_MainMenu.OnNewGameRequestedListener;
import com.gpl.rpg.AndorsTrail.activity.fragment.StartScreenActivity_NewGame;
import com.gpl.rpg.AndorsTrail.activity.fragment.StartScreenActivity_NewGame.GameCreationOverListener;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.CloudsAnimatorView;
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.AnimationDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public final class StartScreenActivity extends AndorsTrailBaseFragmentActivity implements OnNewGameRequestedListener, GameCreationOverListener, OnBackStackChangedListener {
private TextView tv;
private TextView development_version;
private CloudsAnimatorView clouds_back, clouds_mid, clouds_front;
private Fragment currentFragment;
//Means false by default, as a toggle is initiated in onCreate.
boolean ui_visible = true;
@Override
public void onCreate(Bundle savedInstanceState) {
initPreferences();
setTheme(ThemeHelper.getBaseTheme());
super.onCreate(savedInstanceState);
final AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
final Resources res = getResources();
TileManager tileManager = app.getWorld().tileManager;
tileManager.setDensity(res);
app.setWindowParameters(this);
setContentView(R.layout.startscreen);
if (findViewById(R.id.startscreen_fragment_container) != null) {
StartScreenActivity_MainMenu mainMenu = new StartScreenActivity_MainMenu();
getSupportFragmentManager().beginTransaction()
.replace(R.id.startscreen_fragment_container, mainMenu)
.commit();
currentFragment = mainMenu;
getSupportFragmentManager().addOnBackStackChangedListener(this);
}
tv = (TextView) findViewById(R.id.startscreen_version);
tv.setText('v' + AndorsTrailApplication.CURRENT_VERSION_DISPLAY);
development_version = (TextView) findViewById(R.id.startscreen_dev_version);
if (AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAMES) {
development_version.setText(R.string.startscreen_incompatible_savegames);
development_version.setVisibility(View.VISIBLE);
} else if (!AndorsTrailApplication.IS_RELEASE_VERSION) {
development_version.setText(R.string.startscreen_non_release_version);
development_version.setVisibility(View.VISIBLE);
}
clouds_back = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_back);
if (clouds_back != null) clouds_back.setCloudsCountAndLayer(40, CloudsAnimatorView.Layer.below);
clouds_mid = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_mid);
if (clouds_mid != null) clouds_mid.setCloudsCountAndLayer(15, CloudsAnimatorView.Layer.center);
clouds_front = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_front);
if (clouds_front != null) clouds_front.setCloudsCountAndLayer(8, CloudsAnimatorView.Layer.above);
View background = findViewById(R.id.title_bg);
if (background != null) {
background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleUiVisibility();
}
});
}
if (development_version.getVisibility() == View.VISIBLE) {
development_version.setText(development_version.getText()
// +
// "\nMax Heap: " + Runtime.getRuntime().maxMemory() / (1024 * 1024) + "MB"+
// "\nUsed Heap: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + "MB"+
// "\nTile size: " + (int) (32 * res.getDisplayMetrics().density)
);
}
toggleUiVisibility();
app.getWorldSetup().startResourceLoader(res);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
final Dialog d = CustomDialogFactory.createDialog(this,
getResources().getString(R.string.dialog_permission_information_title),
getResources().getDrawable(android.R.drawable.ic_dialog_info),
getResources().getString(R.string.dialog_permission_information),
null,
true);
final Activity activity = this;
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
CustomDialogFactory.setDismissListener(d, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
StartScreenActivity_MainMenu.checkAndRequestPermissions(activity);
}
});
CustomDialogFactory.show(d);
}
}
private void toggleUiVisibility() {
ui_visible = !ui_visible;
int visibility = ui_visible ? View.VISIBLE : View.GONE;
if (tv != null) tv.setVisibility(visibility);
if (!AndorsTrailApplication.IS_RELEASE_VERSION) {
if (development_version != null) development_version.setVisibility(visibility);
}
if (currentFragment != null) {
if (ui_visible) {
if (!AndorsTrailApplication.IS_RELEASE_VERSION) {
development_version.setText(
development_version.getText()
// +
// "\nMax Heap: " + Runtime.getRuntime().maxMemory() / (1024 * 1024) + "MB"+
// "\nUsed Heap: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + "MB"+
// "\nTile size: " + (int) (32 * getResources().getDisplayMetrics().density)
);
}
getSupportFragmentManager().beginTransaction()
.show(currentFragment)
.commit();
} else {
getSupportFragmentManager().beginTransaction()
.hide(currentFragment)
.commit();
}
}
}
private void initPreferences() {
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
AndorsTrailPreferences preferences = app.getPreferences();
preferences.read(this);
ThemeHelper.changeTheme(preferences.selectedTheme);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
((AnimationDrawable)((ImageView)findViewById(R.id.title_logo)).getDrawable()).start();
ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
int ivWidth = iv.getWidth();
int drawableWidth = iv.getDrawable().getIntrinsicWidth();
float ratio = ((float)ivWidth) / ((float)drawableWidth);
if (clouds_back != null) {
clouds_back.setScalingRatio(ratio);
}
if (clouds_mid != null) {
clouds_mid.setScalingRatio(ratio);
}
if (clouds_front != null) {
clouds_front.setScalingRatio(ratio);
}
}
}
@Override
protected void onResume() {
super.onResume();
final ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
iv.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
float[] point = new float[]{0f,0.25f * iv.getDrawable().getIntrinsicHeight()};
iv.getImageMatrix().mapPoints(point);
int imgY = (int) (iv.getTop() + point[1]);
int screenHeight = getResources().getDisplayMetrics().heightPixels;
if (clouds_back != null) {
clouds_back.setYMax(imgY);
}
if (clouds_mid != null) {
clouds_mid.setYMax(imgY);
}
if (clouds_front != null) {
clouds_front.setYMax(imgY);
}
iv.getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
});
if (clouds_back != null)clouds_back.resumeAnimation();
if (clouds_mid != null)clouds_mid.resumeAnimation();
if (clouds_front != null)clouds_front.resumeAnimation();
}
@Override
protected void onPause() {
super.onPause();
if (clouds_back != null)clouds_back.pauseAnimation();
if (clouds_mid != null)clouds_mid.pauseAnimation();
if (clouds_front != null)clouds_front.pauseAnimation();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
backPressed();
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
return super.onKeyDown(keyCode, event);
}
private void backPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStack();
currentFragment = getSupportFragmentManager().findFragmentById(R.id.startscreen_fragment_container);
}
}
public void onNewGameRequested() {
if (findViewById(R.id.startscreen_fragment_container) != null) {
StartScreenActivity_NewGame newGameFragment = new StartScreenActivity_NewGame();
getSupportFragmentManager().beginTransaction()
.replace(R.id.startscreen_fragment_container, newGameFragment)
.addToBackStack(null)
.commit();
currentFragment = newGameFragment;
}
}
@Override
public void onGameCreationCancelled() {
backPressed();
}
@Override
public void onBackStackChanged() {
currentFragment = getSupportFragmentManager().findFragmentById(R.id.startscreen_fragment_container);
}
}
package com.gpl.rpg.AndorsTrail_beta1.activity;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.StartScreenActivity_MainMenu;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.StartScreenActivity_MainMenu.OnNewGameRequestedListener;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.StartScreenActivity_NewGame;
import com.gpl.rpg.AndorsTrail_beta1.activity.fragment.StartScreenActivity_NewGame.GameCreationOverListener;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.CloudsAnimatorView;
import com.gpl.rpg.AndorsTrail_beta1.view.CustomDialogFactory;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.TextView;
public final class StartScreenActivity extends AndorsTrailBaseFragmentActivity implements OnNewGameRequestedListener, GameCreationOverListener, OnBackStackChangedListener {
private TextView tv;
private TextView development_version;
private CloudsAnimatorView clouds_back, clouds_mid, clouds_front;
private Fragment currentFragment;
//Means false by default, as a toggle is initiated in onCreate.
boolean ui_visible = true;
@Override
public void onCreate(Bundle savedInstanceState) {
initPreferences();
setTheme(ThemeHelper.getBaseTheme());
super.onCreate(savedInstanceState);
final AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
final Resources res = getResources();
TileManager tileManager = app.getWorld().tileManager;
tileManager.setDensity(res);
app.setWindowParameters(this);
setContentView(R.layout.startscreen);
if (findViewById(R.id.startscreen_fragment_container) != null) {
StartScreenActivity_MainMenu mainMenu = new StartScreenActivity_MainMenu();
getSupportFragmentManager().beginTransaction()
.replace(R.id.startscreen_fragment_container, mainMenu)
.commit();
currentFragment = mainMenu;
getSupportFragmentManager().addOnBackStackChangedListener(this);
}
tv = (TextView) findViewById(R.id.startscreen_version);
tv.setText('v' + AndorsTrailApplication.CURRENT_VERSION_DISPLAY);
development_version = (TextView) findViewById(R.id.startscreen_dev_version);
if (AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAMES) {
development_version.setText(R.string.startscreen_incompatible_savegames);
development_version.setVisibility(View.VISIBLE);
} else if (!AndorsTrailApplication.IS_RELEASE_VERSION) {
development_version.setText(R.string.startscreen_non_release_version);
development_version.setVisibility(View.VISIBLE);
}
clouds_back = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_back);
if (clouds_back != null) clouds_back.setCloudsCountAndLayer(40, CloudsAnimatorView.Layer.below);
clouds_mid = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_mid);
if (clouds_mid != null) clouds_mid.setCloudsCountAndLayer(15, CloudsAnimatorView.Layer.center);
clouds_front = (CloudsAnimatorView) findViewById(R.id.ts_clouds_animator_front);
if (clouds_front != null) clouds_front.setCloudsCountAndLayer(8, CloudsAnimatorView.Layer.above);
View background = findViewById(R.id.title_bg);
if (background != null) {
background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleUiVisibility();
}
});
}
if (development_version.getVisibility() == View.VISIBLE) {
development_version.setText(development_version.getText()
// +
// "\nMax Heap: " + Runtime.getRuntime().maxMemory() / (1024 * 1024) + "MB"+
// "\nUsed Heap: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + "MB"+
// "\nTile size: " + (int) (32 * res.getDisplayMetrics().density)
);
}
toggleUiVisibility();
app.getWorldSetup().startResourceLoader(res);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
final Dialog d = CustomDialogFactory.createDialog(this,
getResources().getString(R.string.dialog_permission_information_title),
getResources().getDrawable(android.R.drawable.ic_dialog_info),
getResources().getString(R.string.dialog_permission_information),
null,
true);
final Activity activity = this;
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
CustomDialogFactory.setDismissListener(d, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
StartScreenActivity_MainMenu.checkAndRequestPermissions(activity);
}
});
CustomDialogFactory.show(d);
}
}
private void toggleUiVisibility() {
ui_visible = !ui_visible;
int visibility = ui_visible ? View.VISIBLE : View.GONE;
if (tv != null) tv.setVisibility(visibility);
if (!AndorsTrailApplication.IS_RELEASE_VERSION) {
if (development_version != null) development_version.setVisibility(visibility);
}
if (currentFragment != null) {
if (ui_visible) {
if (!AndorsTrailApplication.IS_RELEASE_VERSION) {
development_version.setText(
development_version.getText()
// +
// "\nMax Heap: " + Runtime.getRuntime().maxMemory() / (1024 * 1024) + "MB"+
// "\nUsed Heap: " + Runtime.getRuntime().totalMemory() / (1024 * 1024) + "MB"+
// "\nTile size: " + (int) (32 * getResources().getDisplayMetrics().density)
);
}
getSupportFragmentManager().beginTransaction()
.show(currentFragment)
.commit();
} else {
getSupportFragmentManager().beginTransaction()
.hide(currentFragment)
.commit();
}
}
}
private void initPreferences() {
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this);
AndorsTrailPreferences preferences = app.getPreferences();
preferences.read(this);
ThemeHelper.changeTheme(preferences.selectedTheme);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
((AnimationDrawable)((ImageView)findViewById(R.id.title_logo)).getDrawable()).start();
ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
int ivWidth = iv.getWidth();
int drawableWidth = iv.getDrawable().getIntrinsicWidth();
float ratio = ((float)ivWidth) / ((float)drawableWidth);
if (clouds_back != null) {
clouds_back.setScalingRatio(ratio);
}
if (clouds_mid != null) {
clouds_mid.setScalingRatio(ratio);
}
if (clouds_front != null) {
clouds_front.setScalingRatio(ratio);
}
}
}
@Override
protected void onResume() {
super.onResume();
final ImageView iv = (ImageView) findViewById(R.id.ts_foreground);
iv.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
float[] point = new float[]{0f,0.25f * iv.getDrawable().getIntrinsicHeight()};
iv.getImageMatrix().mapPoints(point);
int imgY = (int) (iv.getTop() + point[1]);
int screenHeight = getResources().getDisplayMetrics().heightPixels;
if (clouds_back != null) {
clouds_back.setYMax(imgY);
}
if (clouds_mid != null) {
clouds_mid.setYMax(imgY);
}
if (clouds_front != null) {
clouds_front.setYMax(imgY);
}
iv.getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
});
if (clouds_back != null)clouds_back.resumeAnimation();
if (clouds_mid != null)clouds_mid.resumeAnimation();
if (clouds_front != null)clouds_front.resumeAnimation();
}
@Override
protected void onPause() {
super.onPause();
if (clouds_back != null)clouds_back.pauseAnimation();
if (clouds_mid != null)clouds_mid.pauseAnimation();
if (clouds_front != null)clouds_front.pauseAnimation();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
backPressed();
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
return super.onKeyDown(keyCode, event);
}
private void backPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStack();
currentFragment = getSupportFragmentManager().findFragmentById(R.id.startscreen_fragment_container);
}
}
public void onNewGameRequested() {
if (findViewById(R.id.startscreen_fragment_container) != null) {
StartScreenActivity_NewGame newGameFragment = new StartScreenActivity_NewGame();
getSupportFragmentManager().beginTransaction()
.replace(R.id.startscreen_fragment_container, newGameFragment)
.addToBackStack(null)
.commit();
currentFragment = newGameFragment;
}
}
@Override
public void onGameCreationCancelled() {
backPressed();
}
@Override
public void onBackStackChanged() {
currentFragment = getSupportFragmentManager().findFragmentById(R.id.startscreen_fragment_container);
}
}

View File

@@ -1,490 +1,490 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
import java.util.Arrays;
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.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
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;
import com.gpl.rpg.AndorsTrail.model.actor.HeroCollection;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.Inventory;
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.CustomMenuInflater;
import com.gpl.rpg.AndorsTrail.view.ItemContainerAdapter;
import com.gpl.rpg.AndorsTrail.view.SpinnerEmulator;
public final class HeroinfoActivity_Inventory extends Fragment implements CustomMenuInflater.MenuItemSelectedListener {
private static final int INTENTREQUEST_ITEMINFO = 3;
private static final int INTENTREQUEST_BULKSELECT_DROP = 11;
private WorldContext world;
private ControllerContext controllers;
private TileCollection wornTiles;
private Player player;
private ListView inventoryList;
private ItemContainerAdapter inventoryListAdapter;
private ItemContainerAdapter inventoryWeaponsListAdapter;
private ItemContainerAdapter inventoryArmorListAdapter;
private ItemContainerAdapter inventoryJewelryListAdapter;
private ItemContainerAdapter inventoryPotionListAdapter;
private ItemContainerAdapter inventoryFoodListAdapter;
private ItemContainerAdapter inventoryQuestListAdapter;
private ItemContainerAdapter inventoryOtherListAdapter;
private TextView heroinfo_stats_gold;
private TextView heroinfo_stats_attack;
private TextView heroinfo_stats_defense;
private ItemType lastSelectedItem; // Workaround android bug #7139
private final ImageView[] wornItemImage = new ImageView[Inventory.WearSlot.values().length];
private final int[] defaultWornItemImageResourceIDs = new int[Inventory.WearSlot.values().length];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this.getActivity());
if (!app.isInitialized()) return;
this.world = app.getWorld();
this.controllers = app.getControllerContext();
this.player = world.model.player;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.heroinfo_inventory, container, false);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this.getActivity());
if (!app.isInitialized()) return v;
inventoryList = (ListView) v.findViewById(R.id.inventorylist_root);
ImageView heroicon = (ImageView) v.findViewById(R.id.heroinfo_inventory_heroicon);
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);
registerForContextMenu(inventoryList);
inventoryList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// Move this code to separate function? -- Done
ItemType itemType = getSelectedItemType(position);
showInventoryItemInfo(itemType.id);
}
});
inventoryList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
showContextMenuForItem(getSelectedItemType(position));
return true;
}
});
new SpinnerEmulator(v, R.id.inventorylist_category_filters_button, R.array.inventorylist_category_filters, R.string.heroinfo_inventory_categories) {
@Override
public void setValue(int value) {
world.model.uiSelections.selectedInventoryCategory = value;
}
@Override
public void selectionChanged(int value) {
reloadShownCategory(value);
}
@Override
public int getValue() {
return world.model.uiSelections.selectedInventoryCategory;
}
};
new SpinnerEmulator(v, R.id.inventorylist_sort_filters_button, R.array.inventorylist_sort_filters, R.string.heroinfo_inventory_sort) {
@Override
public void setValue(int value) {
world.model.uiSelections.selectedInventorySort = value;
}
@Override
public void selectionChanged(int value) {
reloadShownSort(player.inventory);
}
@Override
public int getValue() {
return world.model.uiSelections.selectedInventorySort;
}
};
ItemContainer inv = player.inventory;
wornTiles = world.tileManager.loadTilesFor(player.inventory, getResources());
inventoryListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, inv, player, wornTiles);
inventoryList.setAdapter(inventoryListAdapter);
heroicon.setImageResource(HeroCollection.getHeroLargeSprite(player.iconID));
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
public void onStart() {
super.onStart();
update();
}
private void setWearSlot(final View v, final Inventory.WearSlot inventorySlot, int viewId, int resourceId) {
final ImageView imageView = (ImageView) v.findViewById(viewId);
wornItemImage[inventorySlot.ordinal()] = imageView;
defaultWornItemImageResourceIDs[inventorySlot.ordinal()] = resourceId;
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (player.inventory.isEmptySlot(inventorySlot)) return;
imageView.setClickable(false); // Will be enabled again on update()
showEquippedItemInfo(player.inventory.getItemTypeInWearSlot(inventorySlot), inventorySlot);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case INTENTREQUEST_ITEMINFO:
if (resultCode == ItemInfoActivity.RESULT_MORE_ACTIONS) {
showContextMenuForItem( world.itemTypes.getItemType(data.getExtras().getString("itemTypeID")));
break;
}
if (resultCode != Activity.RESULT_OK) break;
ItemType itemType = world.itemTypes.getItemType(data.getExtras().getString("itemTypeID"));
ItemInfoActivity.ItemInfoAction actionType = ItemInfoActivity.ItemInfoAction.valueOf(data.getExtras().getString("actionType"));
if (actionType == ItemInfoActivity.ItemInfoAction.unequip) {
Inventory.WearSlot slot = Inventory.WearSlot.valueOf(data.getExtras().getString("inventorySlot"));
controllers.itemController.unequipSlot(itemType, slot);
} else if (actionType == ItemInfoActivity.ItemInfoAction.equip) {
Inventory.WearSlot slot = suggestInventorySlot(itemType);
controllers.itemController.equipItem(itemType, slot);
} else if (actionType == ItemInfoActivity.ItemInfoAction.use) {
controllers.itemController.useItem(itemType);
}
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 Inventory.WearSlot suggestInventorySlot(ItemType itemType) {
Inventory.WearSlot slot = itemType.category.inventorySlot;
if (player.inventory.isEmptySlot(slot)) return slot;
if (slot == Inventory.WearSlot.leftring) return Inventory.WearSlot.rightring;
if (itemType.isOffhandCapableWeapon()) {
ItemType mainWeapon = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
if (mainWeapon != null && mainWeapon.isTwohandWeapon()) return slot;
else if (player.inventory.isEmptySlot(Inventory.WearSlot.shield)) return Inventory.WearSlot.shield;
}
return slot;
}
private void dropItem(String itemTypeID, int quantity) {
ItemType itemType = world.itemTypes.getItemType(itemTypeID);
controllers.itemController.dropItem(itemType, quantity);
}
private void update() {
updateTraits();
updateWorn();
updateItemList();
}
private void updateTraits() {
heroinfo_stats_gold.setText(getResources().getString(R.string.heroinfo_gold, player.inventory.gold));
StringBuilder sb = new StringBuilder(10);
ItemController.describeAttackEffect(
player.getAttackChance(),
player.getDamagePotential().current,
player.getDamagePotential().max,
player.getCriticalSkill(),
player.getCriticalMultiplier(),
sb);
heroinfo_stats_attack.setText(sb.toString());
sb = new StringBuilder(10);
ItemController.describeBlockEffect(player.getBlockChance(), player.getDamageResistance(), sb);
heroinfo_stats_defense.setText(sb.toString());
}
private void updateWorn() {
for(Inventory.WearSlot slot : Inventory.WearSlot.values()) {
updateWornImage(wornItemImage[slot.ordinal()], defaultWornItemImageResourceIDs[slot.ordinal()], player.inventory.getItemTypeInWearSlot(slot));
}
}
private void updateWornImage(ImageView imageView, int resourceIDEmptyImage, ItemType type) {
if (type != null) {
world.tileManager.setImageViewTile(getResources(), imageView, type, wornTiles);
} else {
imageView.setImageResource(resourceIDEmptyImage);
}
imageView.setClickable(true);
}
private void updateItemList() {
int currentScreen = world.model.uiSelections.selectedInventoryCategory;
if (currentScreen == 0)
inventoryListAdapter.notifyDataSetChanged();
else
reloadShownCategory(world.model.uiSelections.selectedInventoryCategory);
}
// @Override
// public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {}
// ItemType type = getSelectedItemType((AdapterContextMenuInfo) menuInfo);
public void showContextMenuForItem(ItemType type) {
MenuInflater inflater = getActivity().getMenuInflater();
Menu menu = CustomMenuInflater.newMenuInstance(getActivity());
inflater.inflate(R.menu.inventoryitem, menu);
if (type.isUsable()){
menu.findItem(R.id.inv_menu_use).setVisible(true);
menu.findItem(R.id.inv_menu_assign).setVisible(true);
}
if (type.isEquippable()) {
menu.findItem(R.id.inv_menu_equip).setVisible(true);
if (type.isOffhandCapableWeapon()) menu.findItem(R.id.inv_menu_equip_offhand).setVisible(true);
else if (type.category.inventorySlot == Inventory.WearSlot.leftring) menu.findItem(R.id.inv_menu_equip_offhand).setVisible(true);
}
lastSelectedItem = null;
CustomMenuInflater.showMenuInDialog(getActivity(), menu, world.tileManager.getDrawableForItem(getResources(), type.iconID, world.tileManager.loadTilesFor(Arrays.asList(new Integer[] { type.iconID}), getResources())), type.getName(player), type, this);
}
private ItemType getSelectedItemType(int position) {
int v = world.model.uiSelections.selectedInventoryCategory;
if (v == 0) { //All items
return inventoryListAdapter.getItem(position).itemType;
}else if (v == 1) { //Weapon items
return inventoryWeaponsListAdapter.getItem(position).itemType;
} else if (v == 2) { //Armor items
return inventoryArmorListAdapter.getItem(position).itemType;
} else if (v == 3) { //Jewelry items
return inventoryJewelryListAdapter.getItem(position).itemType;
} else if (v == 4) { //Potion items
return inventoryPotionListAdapter.getItem(position).itemType;
} else if (v == 5) { //Food items
return inventoryFoodListAdapter.getItem(position).itemType;
} else if (v == 6) { //Quest items
return inventoryQuestListAdapter.getItem(position).itemType;
} else if (v == 7) { //Other items
return inventoryOtherListAdapter.getItem(position).itemType;
}
// Better than crashing...
return inventoryListAdapter.getItem(position).itemType;
}
private ItemType getSelectedItemType(AdapterContextMenuInfo info) {
return getSelectedItemType(info.position);
}
@Override
public void onMenuItemSelected(MenuItem item, Object data) {
ItemType itemType = (ItemType) data;
switch (item.getItemId()) {
case R.id.inv_menu_info:
showInventoryItemInfo(itemType);
//context.mapController.itemInfo(this, getSelectedItemType(info));
break;
case R.id.inv_menu_drop:
String itemTypeID = itemType.id;
int quantity = player.inventory.getItemQuantity(itemTypeID);
if (quantity > 1) {
Intent intent = Dialogs.getIntentForBulkDroppingInterface(getActivity(), itemTypeID, quantity);
startActivityForResult(intent, INTENTREQUEST_BULKSELECT_DROP);
} else {
dropItem(itemTypeID, quantity);
}
break;
case R.id.inv_menu_equip:
controllers.itemController.equipItem(itemType, itemType.category.inventorySlot);
break;
case R.id.inv_menu_equip_offhand:
if (itemType.category.inventorySlot == Inventory.WearSlot.weapon) {
controllers.itemController.equipItem(itemType, Inventory.WearSlot.shield);
} else if (itemType.category.inventorySlot == Inventory.WearSlot.leftring) {
controllers.itemController.equipItem(itemType, Inventory.WearSlot.rightring);
}
break;
/*case R.id.inv_menu_unequip:
context.mapController.unequipItem(this, getSelectedItemType(info));
break;*/
case R.id.inv_menu_use:
controllers.itemController.useItem(itemType);
break;
case R.id.inv_menu_assign:
//lastSelectedItem = itemType;
break;
case R.id.inv_assign_slot1:
controllers.itemController.setQuickItem(itemType, 0);
break;
case R.id.inv_assign_slot2:
controllers.itemController.setQuickItem(itemType, 1);
break;
case R.id.inv_assign_slot3:
controllers.itemController.setQuickItem(itemType, 2);
break;
case R.id.inv_menu_movetop:
player.inventory.sortToTop(itemType.id);
break;
case R.id.inv_menu_movebottom:
player.inventory.sortToBottom(itemType.id);
break;
}
update();
}
private void showEquippedItemInfo(ItemType itemType, Inventory.WearSlot inventorySlot) {
String text;
boolean enabled = true;
if (world.model.uiSelections.isInCombat) {
int ap = world.model.player.getReequipCost();
text = getResources().getString(R.string.iteminfo_action_unequip_ap, ap);
if (ap > 0) {
enabled = world.model.player.hasAPs(ap);
}
} else {
text = getResources().getString(R.string.iteminfo_action_unequip);
}
Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, ItemInfoActivity.ItemInfoAction.unequip, text, enabled, inventorySlot);
startActivityForResult(intent, INTENTREQUEST_ITEMINFO);
}
private void showInventoryItemInfo(String itemTypeID) {
showInventoryItemInfo(world.itemTypes.getItemType(itemTypeID));
}
private void showInventoryItemInfo(ItemType itemType) {
String text = "";
int ap = 0;
boolean enabled = true;
ItemInfoActivity.ItemInfoAction action = ItemInfoActivity.ItemInfoAction.none;
final boolean isInCombat = world.model.uiSelections.isInCombat;
if (itemType.isEquippable()) {
if (isInCombat) {
ap = world.model.player.getReequipCost();
text = getResources().getString(R.string.iteminfo_action_equip_ap, ap);
} else {
text = getResources().getString(R.string.iteminfo_action_equip);
}
action = ItemInfoActivity.ItemInfoAction.equip;
} else if (itemType.isUsable()) {
if (isInCombat) {
ap = world.model.player.getUseItemCost();
text = getResources().getString(R.string.iteminfo_action_use_ap, ap);
} else {
text = getResources().getString(R.string.iteminfo_action_use);
}
action = ItemInfoActivity.ItemInfoAction.use;
}
if (isInCombat && ap > 0) {
enabled = world.model.player.hasAPs(ap);
}
Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, action, text, enabled, null);
startActivityForResult(intent, INTENTREQUEST_ITEMINFO);
}
private void reloadShownCategory(int v) { // Apologies about the code duplication,
// just didn't seem to make sense as an array, although I did create a nice array for skill category adapters.
// Decide which category to show
if (v == 0) { //All items
inventoryList.setAdapter(inventoryListAdapter);
inventoryListAdapter.notifyDataSetChanged();
} else if (v == 1) { //Weapon items
inventoryWeaponsListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildWeaponItems(), player, wornTiles);
inventoryList.setAdapter(inventoryWeaponsListAdapter);
inventoryWeaponsListAdapter.notifyDataSetChanged();
} else if (v == 2) { //Armor items
inventoryArmorListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildArmorItems(), player, wornTiles);
inventoryList.setAdapter(inventoryArmorListAdapter);
inventoryArmorListAdapter.notifyDataSetChanged();
} else if (v == 3) { //Jewelry items
inventoryJewelryListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildJewelryItems(), player, wornTiles);
inventoryList.setAdapter(inventoryJewelryListAdapter);
inventoryJewelryListAdapter.notifyDataSetChanged();
} else if (v == 4) { //Potion items
inventoryPotionListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildPotionItems(), player, wornTiles);
inventoryList.setAdapter(inventoryPotionListAdapter);
inventoryPotionListAdapter.notifyDataSetChanged();
} else if (v == 5) { //Food items
inventoryFoodListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildFoodItems(), player, wornTiles);
inventoryList.setAdapter(inventoryFoodListAdapter);
inventoryFoodListAdapter.notifyDataSetChanged();
} else if (v == 6) { //Quest items
inventoryQuestListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildQuestItems(), player, wornTiles);
inventoryList.setAdapter(inventoryQuestListAdapter);
inventoryQuestListAdapter.notifyDataSetChanged();
} else if (v == 7) { //Other items
inventoryOtherListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildOtherItems(), player, wornTiles);
inventoryList.setAdapter(inventoryOtherListAdapter);
inventoryOtherListAdapter.notifyDataSetChanged();
}
//updateItemList();
}
private void reloadShownSort(Inventory inv) {
int selected = world.model.uiSelections.selectedInventorySort;
inventoryListAdapter.reloadShownSort(selected, world.model.uiSelections.oldSortSelection, player.inventory, player);
// Currently not functional, perhaps because selection only updates when changed.
if (world.model.uiSelections.oldSortSelection == selected)
world.model.uiSelections.oldSortSelection = 0;
else world.model.uiSelections.oldSortSelection = selected;
updateItemList();
}
}
package com.gpl.rpg.AndorsTrail_beta1.activity.fragment;
import java.util.Arrays;
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.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.activity.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.ItemController;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.HeroCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Inventory;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemContainer;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail_beta1.view.CustomMenuInflater;
import com.gpl.rpg.AndorsTrail_beta1.view.ItemContainerAdapter;
import com.gpl.rpg.AndorsTrail_beta1.view.SpinnerEmulator;
public final class HeroinfoActivity_Inventory extends Fragment implements CustomMenuInflater.MenuItemSelectedListener {
private static final int INTENTREQUEST_ITEMINFO = 3;
private static final int INTENTREQUEST_BULKSELECT_DROP = 11;
private WorldContext world;
private ControllerContext controllers;
private TileCollection wornTiles;
private Player player;
private ListView inventoryList;
private ItemContainerAdapter inventoryListAdapter;
private ItemContainerAdapter inventoryWeaponsListAdapter;
private ItemContainerAdapter inventoryArmorListAdapter;
private ItemContainerAdapter inventoryJewelryListAdapter;
private ItemContainerAdapter inventoryPotionListAdapter;
private ItemContainerAdapter inventoryFoodListAdapter;
private ItemContainerAdapter inventoryQuestListAdapter;
private ItemContainerAdapter inventoryOtherListAdapter;
private TextView heroinfo_stats_gold;
private TextView heroinfo_stats_attack;
private TextView heroinfo_stats_defense;
private ItemType lastSelectedItem; // Workaround android bug #7139
private final ImageView[] wornItemImage = new ImageView[Inventory.WearSlot.values().length];
private final int[] defaultWornItemImageResourceIDs = new int[Inventory.WearSlot.values().length];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this.getActivity());
if (!app.isInitialized()) return;
this.world = app.getWorld();
this.controllers = app.getControllerContext();
this.player = world.model.player;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.heroinfo_inventory, container, false);
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(this.getActivity());
if (!app.isInitialized()) return v;
inventoryList = (ListView) v.findViewById(R.id.inventorylist_root);
ImageView heroicon = (ImageView) v.findViewById(R.id.heroinfo_inventory_heroicon);
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);
registerForContextMenu(inventoryList);
inventoryList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// Move this code to separate function? -- Done
ItemType itemType = getSelectedItemType(position);
showInventoryItemInfo(itemType.id);
}
});
inventoryList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
showContextMenuForItem(getSelectedItemType(position));
return true;
}
});
new SpinnerEmulator(v, R.id.inventorylist_category_filters_button, R.array.inventorylist_category_filters, R.string.heroinfo_inventory_categories) {
@Override
public void setValue(int value) {
world.model.uiSelections.selectedInventoryCategory = value;
}
@Override
public void selectionChanged(int value) {
reloadShownCategory(value);
}
@Override
public int getValue() {
return world.model.uiSelections.selectedInventoryCategory;
}
};
new SpinnerEmulator(v, R.id.inventorylist_sort_filters_button, R.array.inventorylist_sort_filters, R.string.heroinfo_inventory_sort) {
@Override
public void setValue(int value) {
world.model.uiSelections.selectedInventorySort = value;
}
@Override
public void selectionChanged(int value) {
reloadShownSort(player.inventory);
}
@Override
public int getValue() {
return world.model.uiSelections.selectedInventorySort;
}
};
ItemContainer inv = player.inventory;
wornTiles = world.tileManager.loadTilesFor(player.inventory, getResources());
inventoryListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, inv, player, wornTiles);
inventoryList.setAdapter(inventoryListAdapter);
heroicon.setImageResource(HeroCollection.getHeroLargeSprite(player.iconID));
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
public void onStart() {
super.onStart();
update();
}
private void setWearSlot(final View v, final Inventory.WearSlot inventorySlot, int viewId, int resourceId) {
final ImageView imageView = (ImageView) v.findViewById(viewId);
wornItemImage[inventorySlot.ordinal()] = imageView;
defaultWornItemImageResourceIDs[inventorySlot.ordinal()] = resourceId;
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (player.inventory.isEmptySlot(inventorySlot)) return;
imageView.setClickable(false); // Will be enabled again on update()
showEquippedItemInfo(player.inventory.getItemTypeInWearSlot(inventorySlot), inventorySlot);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case INTENTREQUEST_ITEMINFO:
if (resultCode == ItemInfoActivity.RESULT_MORE_ACTIONS) {
showContextMenuForItem( world.itemTypes.getItemType(data.getExtras().getString("itemTypeID")));
break;
}
if (resultCode != Activity.RESULT_OK) break;
ItemType itemType = world.itemTypes.getItemType(data.getExtras().getString("itemTypeID"));
ItemInfoActivity.ItemInfoAction actionType = ItemInfoActivity.ItemInfoAction.valueOf(data.getExtras().getString("actionType"));
if (actionType == ItemInfoActivity.ItemInfoAction.unequip) {
Inventory.WearSlot slot = Inventory.WearSlot.valueOf(data.getExtras().getString("inventorySlot"));
controllers.itemController.unequipSlot(itemType, slot);
} else if (actionType == ItemInfoActivity.ItemInfoAction.equip) {
Inventory.WearSlot slot = suggestInventorySlot(itemType);
controllers.itemController.equipItem(itemType, slot);
} else if (actionType == ItemInfoActivity.ItemInfoAction.use) {
controllers.itemController.useItem(itemType);
}
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 Inventory.WearSlot suggestInventorySlot(ItemType itemType) {
Inventory.WearSlot slot = itemType.category.inventorySlot;
if (player.inventory.isEmptySlot(slot)) return slot;
if (slot == Inventory.WearSlot.leftring) return Inventory.WearSlot.rightring;
if (itemType.isOffhandCapableWeapon()) {
ItemType mainWeapon = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
if (mainWeapon != null && mainWeapon.isTwohandWeapon()) return slot;
else if (player.inventory.isEmptySlot(Inventory.WearSlot.shield)) return Inventory.WearSlot.shield;
}
return slot;
}
private void dropItem(String itemTypeID, int quantity) {
ItemType itemType = world.itemTypes.getItemType(itemTypeID);
controllers.itemController.dropItem(itemType, quantity);
}
private void update() {
updateTraits();
updateWorn();
updateItemList();
}
private void updateTraits() {
heroinfo_stats_gold.setText(getResources().getString(R.string.heroinfo_gold, player.inventory.gold));
StringBuilder sb = new StringBuilder(10);
ItemController.describeAttackEffect(
player.getAttackChance(),
player.getDamagePotential().current,
player.getDamagePotential().max,
player.getCriticalSkill(),
player.getCriticalMultiplier(),
sb);
heroinfo_stats_attack.setText(sb.toString());
sb = new StringBuilder(10);
ItemController.describeBlockEffect(player.getBlockChance(), player.getDamageResistance(), sb);
heroinfo_stats_defense.setText(sb.toString());
}
private void updateWorn() {
for(Inventory.WearSlot slot : Inventory.WearSlot.values()) {
updateWornImage(wornItemImage[slot.ordinal()], defaultWornItemImageResourceIDs[slot.ordinal()], player.inventory.getItemTypeInWearSlot(slot));
}
}
private void updateWornImage(ImageView imageView, int resourceIDEmptyImage, ItemType type) {
if (type != null) {
world.tileManager.setImageViewTile(getResources(), imageView, type, wornTiles);
} else {
imageView.setImageResource(resourceIDEmptyImage);
}
imageView.setClickable(true);
}
private void updateItemList() {
int currentScreen = world.model.uiSelections.selectedInventoryCategory;
if (currentScreen == 0)
inventoryListAdapter.notifyDataSetChanged();
else
reloadShownCategory(world.model.uiSelections.selectedInventoryCategory);
}
// @Override
// public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {}
// ItemType type = getSelectedItemType((AdapterContextMenuInfo) menuInfo);
public void showContextMenuForItem(ItemType type) {
MenuInflater inflater = getActivity().getMenuInflater();
Menu menu = CustomMenuInflater.newMenuInstance(getActivity());
inflater.inflate(R.menu.inventoryitem, menu);
if (type.isUsable()){
menu.findItem(R.id.inv_menu_use).setVisible(true);
menu.findItem(R.id.inv_menu_assign).setVisible(true);
}
if (type.isEquippable()) {
menu.findItem(R.id.inv_menu_equip).setVisible(true);
if (type.isOffhandCapableWeapon()) menu.findItem(R.id.inv_menu_equip_offhand).setVisible(true);
else if (type.category.inventorySlot == Inventory.WearSlot.leftring) menu.findItem(R.id.inv_menu_equip_offhand).setVisible(true);
}
lastSelectedItem = null;
CustomMenuInflater.showMenuInDialog(getActivity(), menu, world.tileManager.getDrawableForItem(getResources(), type.iconID, world.tileManager.loadTilesFor(Arrays.asList(new Integer[] { type.iconID}), getResources())), type.getName(player), type, this);
}
private ItemType getSelectedItemType(int position) {
int v = world.model.uiSelections.selectedInventoryCategory;
if (v == 0) { //All items
return inventoryListAdapter.getItem(position).itemType;
}else if (v == 1) { //Weapon items
return inventoryWeaponsListAdapter.getItem(position).itemType;
} else if (v == 2) { //Armor items
return inventoryArmorListAdapter.getItem(position).itemType;
} else if (v == 3) { //Jewelry items
return inventoryJewelryListAdapter.getItem(position).itemType;
} else if (v == 4) { //Potion items
return inventoryPotionListAdapter.getItem(position).itemType;
} else if (v == 5) { //Food items
return inventoryFoodListAdapter.getItem(position).itemType;
} else if (v == 6) { //Quest items
return inventoryQuestListAdapter.getItem(position).itemType;
} else if (v == 7) { //Other items
return inventoryOtherListAdapter.getItem(position).itemType;
}
// Better than crashing...
return inventoryListAdapter.getItem(position).itemType;
}
private ItemType getSelectedItemType(AdapterContextMenuInfo info) {
return getSelectedItemType(info.position);
}
@Override
public void onMenuItemSelected(MenuItem item, Object data) {
ItemType itemType = (ItemType) data;
switch (item.getItemId()) {
case R.id.inv_menu_info:
showInventoryItemInfo(itemType);
//context.mapController.itemInfo(this, getSelectedItemType(info));
break;
case R.id.inv_menu_drop:
String itemTypeID = itemType.id;
int quantity = player.inventory.getItemQuantity(itemTypeID);
if (quantity > 1) {
Intent intent = Dialogs.getIntentForBulkDroppingInterface(getActivity(), itemTypeID, quantity);
startActivityForResult(intent, INTENTREQUEST_BULKSELECT_DROP);
} else {
dropItem(itemTypeID, quantity);
}
break;
case R.id.inv_menu_equip:
controllers.itemController.equipItem(itemType, itemType.category.inventorySlot);
break;
case R.id.inv_menu_equip_offhand:
if (itemType.category.inventorySlot == Inventory.WearSlot.weapon) {
controllers.itemController.equipItem(itemType, Inventory.WearSlot.shield);
} else if (itemType.category.inventorySlot == Inventory.WearSlot.leftring) {
controllers.itemController.equipItem(itemType, Inventory.WearSlot.rightring);
}
break;
/*case R.id.inv_menu_unequip:
context.mapController.unequipItem(this, getSelectedItemType(info));
break;*/
case R.id.inv_menu_use:
controllers.itemController.useItem(itemType);
break;
case R.id.inv_menu_assign:
//lastSelectedItem = itemType;
break;
case R.id.inv_assign_slot1:
controllers.itemController.setQuickItem(itemType, 0);
break;
case R.id.inv_assign_slot2:
controllers.itemController.setQuickItem(itemType, 1);
break;
case R.id.inv_assign_slot3:
controllers.itemController.setQuickItem(itemType, 2);
break;
case R.id.inv_menu_movetop:
player.inventory.sortToTop(itemType.id);
break;
case R.id.inv_menu_movebottom:
player.inventory.sortToBottom(itemType.id);
break;
}
update();
}
private void showEquippedItemInfo(ItemType itemType, Inventory.WearSlot inventorySlot) {
String text;
boolean enabled = true;
if (world.model.uiSelections.isInCombat) {
int ap = world.model.player.getReequipCost();
text = getResources().getString(R.string.iteminfo_action_unequip_ap, ap);
if (ap > 0) {
enabled = world.model.player.hasAPs(ap);
}
} else {
text = getResources().getString(R.string.iteminfo_action_unequip);
}
Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, ItemInfoActivity.ItemInfoAction.unequip, text, enabled, inventorySlot);
startActivityForResult(intent, INTENTREQUEST_ITEMINFO);
}
private void showInventoryItemInfo(String itemTypeID) {
showInventoryItemInfo(world.itemTypes.getItemType(itemTypeID));
}
private void showInventoryItemInfo(ItemType itemType) {
String text = "";
int ap = 0;
boolean enabled = true;
ItemInfoActivity.ItemInfoAction action = ItemInfoActivity.ItemInfoAction.none;
final boolean isInCombat = world.model.uiSelections.isInCombat;
if (itemType.isEquippable()) {
if (isInCombat) {
ap = world.model.player.getReequipCost();
text = getResources().getString(R.string.iteminfo_action_equip_ap, ap);
} else {
text = getResources().getString(R.string.iteminfo_action_equip);
}
action = ItemInfoActivity.ItemInfoAction.equip;
} else if (itemType.isUsable()) {
if (isInCombat) {
ap = world.model.player.getUseItemCost();
text = getResources().getString(R.string.iteminfo_action_use_ap, ap);
} else {
text = getResources().getString(R.string.iteminfo_action_use);
}
action = ItemInfoActivity.ItemInfoAction.use;
}
if (isInCombat && ap > 0) {
enabled = world.model.player.hasAPs(ap);
}
Intent intent = Dialogs.getIntentForItemInfo(getActivity(), itemType.id, action, text, enabled, null);
startActivityForResult(intent, INTENTREQUEST_ITEMINFO);
}
private void reloadShownCategory(int v) { // Apologies about the code duplication,
// just didn't seem to make sense as an array, although I did create a nice array for skill category adapters.
// Decide which category to show
if (v == 0) { //All items
inventoryList.setAdapter(inventoryListAdapter);
inventoryListAdapter.notifyDataSetChanged();
} else if (v == 1) { //Weapon items
inventoryWeaponsListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildWeaponItems(), player, wornTiles);
inventoryList.setAdapter(inventoryWeaponsListAdapter);
inventoryWeaponsListAdapter.notifyDataSetChanged();
} else if (v == 2) { //Armor items
inventoryArmorListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildArmorItems(), player, wornTiles);
inventoryList.setAdapter(inventoryArmorListAdapter);
inventoryArmorListAdapter.notifyDataSetChanged();
} else if (v == 3) { //Jewelry items
inventoryJewelryListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildJewelryItems(), player, wornTiles);
inventoryList.setAdapter(inventoryJewelryListAdapter);
inventoryJewelryListAdapter.notifyDataSetChanged();
} else if (v == 4) { //Potion items
inventoryPotionListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildPotionItems(), player, wornTiles);
inventoryList.setAdapter(inventoryPotionListAdapter);
inventoryPotionListAdapter.notifyDataSetChanged();
} else if (v == 5) { //Food items
inventoryFoodListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildFoodItems(), player, wornTiles);
inventoryList.setAdapter(inventoryFoodListAdapter);
inventoryFoodListAdapter.notifyDataSetChanged();
} else if (v == 6) { //Quest items
inventoryQuestListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildQuestItems(), player, wornTiles);
inventoryList.setAdapter(inventoryQuestListAdapter);
inventoryQuestListAdapter.notifyDataSetChanged();
} else if (v == 7) { //Other items
inventoryOtherListAdapter = new ItemContainerAdapter(getActivity(), world.tileManager, player.inventory.buildOtherItems(), player, wornTiles);
inventoryList.setAdapter(inventoryOtherListAdapter);
inventoryOtherListAdapter.notifyDataSetChanged();
}
//updateItemList();
}
private void reloadShownSort(Inventory inv) {
int selected = world.model.uiSelections.selectedInventorySort;
inventoryListAdapter.reloadShownSort(selected, world.model.uiSelections.oldSortSelection, player.inventory, player);
// Currently not functional, perhaps because selection only updates when changed.
if (world.model.uiSelections.oldSortSelection == selected)
world.model.uiSelections.oldSortSelection = 0;
else world.model.uiSelections.oldSortSelection = selected;
updateItemList();
}
}

View File

@@ -1,8 +1,7 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
package com.gpl.rpg.AndorsTrail_beta1.activity.fragment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -16,14 +15,13 @@ import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
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 com.gpl.rpg.AndorsTrail.model.quest.QuestProgress;
import com.gpl.rpg.AndorsTrail.view.SpinnerEmulator;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.quest.Quest;
import com.gpl.rpg.AndorsTrail_beta1.model.quest.QuestLogEntry;
import com.gpl.rpg.AndorsTrail_beta1.view.SpinnerEmulator;
public final class HeroinfoActivity_Quests extends Fragment {

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
package com.gpl.rpg.AndorsTrail_beta1.activity.fragment;
import java.util.ArrayList;
@@ -14,15 +14,15 @@ import android.widget.AdapterView.OnItemClickListener;
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.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.view.SkillListAdapter;
import com.gpl.rpg.AndorsTrail.view.SpinnerEmulator;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.view.SkillListAdapter;
import com.gpl.rpg.AndorsTrail_beta1.view.SpinnerEmulator;
public final class HeroinfoActivity_Skills extends Fragment {
private static final int INTENTREQUEST_SKILLINFO = 12;

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
package com.gpl.rpg.AndorsTrail_beta1.activity.fragment;
import java.util.ArrayList;
@@ -6,10 +6,6 @@ import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -19,20 +15,20 @@ import android.widget.TableLayout;
import android.widget.TableRow;
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.GameStatistics;
import com.gpl.rpg.AndorsTrail.model.actor.HeroCollection;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.Inventory;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnHitReceived;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnUse;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.view.ItemEffectsView;
import com.gpl.rpg.AndorsTrail.view.RangeBar;
import com.gpl.rpg.AndorsTrail.view.TraitsInfoView;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.GameStatistics;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.HeroCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Inventory;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnHitReceived;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnUse;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.view.ItemEffectsView;
import com.gpl.rpg.AndorsTrail_beta1.view.RangeBar;
import com.gpl.rpg.AndorsTrail_beta1.view.TraitsInfoView;
public final class HeroinfoActivity_Stats extends Fragment {

View File

@@ -1,131 +1,128 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
import java.util.HashSet;
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.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
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.SpinnerEmulator;
import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter.OnContainerItemClickedListener;
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;
private Button shoplist_sort;
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);
//Initiating drop-down list for category filters
shoplist_sort = (Button) v.findViewById(R.id.shoplist_sort_filters);
new SpinnerEmulator(v, R.id.shoplist_sort_filters, R.array.shoplist_sort_filters, R.string.shop_item_sort) {
@Override
public void setValue(int value) {
world.model.uiSelections.selectedShopSort = value;
}
@Override
public void selectionChanged(int value) {
reloadShownSort(isSelling ? player.inventory : shopInventory);
}
@Override
public int getValue() {
return world.model.uiSelections.selectedShopSort;
}
};
return v;
}
private void reloadShownSort(ItemContainer itemContainer) {
listAdapter.reloadShownSort(world.model.uiSelections.selectedShopSort, itemContainer, player);
listAdapter.notifyDataSetChanged();
}
@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);
}
}
package com.gpl.rpg.AndorsTrail_beta1.activity.fragment;
import java.util.HashSet;
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.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemContainer;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail_beta1.view.ShopItemContainerAdapter;
import com.gpl.rpg.AndorsTrail_beta1.view.SpinnerEmulator;
import com.gpl.rpg.AndorsTrail_beta1.view.ShopItemContainerAdapter.OnContainerItemClickedListener;
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;
private Button shoplist_sort;
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);
//Initiating drop-down list for category filters
shoplist_sort = (Button) v.findViewById(R.id.shoplist_sort_filters);
new SpinnerEmulator(v, R.id.shoplist_sort_filters, R.array.shoplist_sort_filters, R.string.shop_item_sort) {
@Override
public void setValue(int value) {
world.model.uiSelections.selectedShopSort = value;
}
@Override
public void selectionChanged(int value) {
reloadShownSort(isSelling ? player.inventory : shopInventory);
}
@Override
public int getValue() {
return world.model.uiSelections.selectedShopSort;
}
};
return v;
}
private void reloadShownSort(ItemContainer itemContainer) {
listAdapter.reloadShownSort(world.model.uiSelections.selectedShopSort, itemContainer, player);
listAdapter.notifyDataSetChanged();
}
@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

@@ -1,13 +1,13 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
package com.gpl.rpg.AndorsTrail_beta1.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;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.activity.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail_beta1.controller.ItemController;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
public final class ShopActivity_Buy extends ShopActivityFragment {

View File

@@ -1,13 +1,13 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
package com.gpl.rpg.AndorsTrail_beta1.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;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.activity.ItemInfoActivity;
import com.gpl.rpg.AndorsTrail_beta1.controller.ItemController;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
public final class ShopActivity_Sell extends ShopActivityFragment {

View File

@@ -1,400 +1,400 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.os.Build;
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.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.Dialogs;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.WorldSetup;
import com.gpl.rpg.AndorsTrail.activity.AboutActivity;
import com.gpl.rpg.AndorsTrail.activity.LoadingActivity;
import com.gpl.rpg.AndorsTrail.activity.Preferences;
import com.gpl.rpg.AndorsTrail.controller.Constants;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail.savegames.Savegames;
import com.gpl.rpg.AndorsTrail.savegames.Savegames.FileHeader;
import com.gpl.rpg.AndorsTrail.util.AndroidStorage;
import com.gpl.rpg.AndorsTrail.util.L;
import com.gpl.rpg.AndorsTrail.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail.view.CustomDialogFactory;
public class StartScreenActivity_MainMenu extends Fragment {
private static final int INTENTREQUEST_PREFERENCES = 7;
public static final int INTENTREQUEST_LOADGAME = 9;
private boolean hasExistingGame = false;
private Button startscreen_continue;
private Button startscreen_newgame;
private Button startscreen_load;
private ViewGroup save_preview_holder;
private ImageView save_preview_hero_icon;
private TextView save_preview_hero_desc;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
updatePreferences(false);
super.onCreateView(inflater, container, savedInstanceState);
if (container != null) {
container.removeAllViews();
}
View root = inflater.inflate(R.layout.startscreen_mainmenu, container, false);
save_preview_holder = (ViewGroup) root.findViewById(R.id.save_preview_holder);
save_preview_hero_icon = (ImageView) root.findViewById(R.id.save_preview_hero_icon);
save_preview_hero_desc = (TextView) root.findViewById(R.id.save_preview_hero_desc);
startscreen_continue = (Button) root.findViewById(R.id.startscreen_continue);
startscreen_continue.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
continueGame(false, Savegames.SLOT_QUICKSAVE, null);
}
});
startscreen_newgame = (Button) root.findViewById(R.id.startscreen_newgame);
startscreen_newgame.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (hasExistingGame) {
comfirmNewGame();
} else {
createNewGame();
}
}
});
Button b = (Button) root.findViewById(R.id.startscreen_about);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(getActivity(), AboutActivity.class));
}
});
b = (Button) root.findViewById(R.id.startscreen_preferences);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getActivity(), Preferences.class);
StartScreenActivity_MainMenu.this.startActivityForResult(intent, INTENTREQUEST_PREFERENCES);
}
});
startscreen_load = (Button) root.findViewById(R.id.startscreen_load);
startscreen_load.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(getActivity());
if (hasExistingGame && app != null && app.getWorld() != null && app.getWorld().model != null
&& app.getWorld().model.statistics != null && !app.getWorld().model.statistics.hasUnlimitedSaves()) {
final Dialog d = CustomDialogFactory.createDialog(getActivity(),
getString(R.string.startscreen_load_game),
getResources().getDrawable(android.R.drawable.ic_delete),
getString(R.string.startscreen_load_game_confirm),
null,
true);
CustomDialogFactory.addButton(d, android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialogs.showLoad(StartScreenActivity_MainMenu.this);
}
});
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
CustomDialogFactory.show(d);
} else {
Dialogs.showLoad(StartScreenActivity_MainMenu.this);
}
}
});
if (AndorsTrailApplication.DEVELOPMENT_FORCE_STARTNEWGAME) {
if (AndorsTrailApplication.DEVELOPMENT_DEBUGRESOURCES) {
continueGame(true, 0, "Debug player");
} else {
continueGame(true, 0, "Player");
}
} else if (AndorsTrailApplication.DEVELOPMENT_FORCE_CONTINUEGAME) {
continueGame(false, Savegames.SLOT_QUICKSAVE, null);
}
// if it is a new version we first fire a welcome screen in onResume
// and afterwards check the permissions
if (!isNewVersion()) {
checkAndRequestPermissions(getActivity());
migrateDataOnDemand(getActivity());
}
return root;
}
@Override
public void onResume() {
super.onResume();
String playerName;
String displayInfo = null;
int iconID = TileManager.CHAR_HERO;
boolean isDead = false;
FileHeader header = Savegames.quickload(getActivity(), Savegames.SLOT_QUICKSAVE);
if (header != null && header.playerName != null) {
playerName = header.playerName;
displayInfo = header.displayInfo;
iconID = header.iconID;
isDead = header.isDead;
} else {
// Before fileversion 14 (v0.6.7), quicksave was stored in Shared preferences
SharedPreferences p = getActivity().getSharedPreferences("quicksave", Activity.MODE_PRIVATE);
playerName = p.getString("playername", null);
if (playerName != null) {
displayInfo = "level " + p.getInt("level", -1);
}
}
hasExistingGame = (playerName != null);
setButtonState(playerName, displayInfo, iconID, isDead);
if (isNewVersion()) {
Dialogs.showNewVersion(getActivity(), new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
setCurrentVersionForVersionCheck();
checkAndRequestPermissions(getActivity());
migrateDataOnDemand(getActivity());
boolean hasSavegames = !Savegames.getUsedSavegameSlots(getActivity()).isEmpty();
startscreen_load.setEnabled(hasSavegames);
}
});
}
boolean hasSavegames = !Savegames.getUsedSavegameSlots(getActivity()).isEmpty();
startscreen_load.setEnabled(hasSavegames);
}
@TargetApi(29)
public void migrateDataOnDemand(final Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
if (AndroidStorage.shouldMigrateToInternalStorage(activity.getApplicationContext())) {
final Dialog d = CustomDialogFactory.createDialog(activity,
getString(R.string.startscreen_migration_title),
activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert),
getString(R.string.startscreen_migration_text),
null,
true);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
d.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
boolean hasSavegames = !Savegames.getUsedSavegameSlots(getActivity()).isEmpty();
startscreen_load.setEnabled(hasSavegames);
}
});
CustomDialogFactory.show(d);
if (!AndroidStorage.migrateToInternalStorage(activity.getApplicationContext())) {
final Dialog errorDlg = CustomDialogFactory.createDialog(activity,
getString(R.string.startscreen_migration_title),
activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert),
getString(R.string.startscreen_migration_failure),
null,
true);
CustomDialogFactory.addDismissButton(errorDlg, android.R.string.ok);
d.cancel();
CustomDialogFactory.show(errorDlg);
}
} else {
L.log("INFO: No external files or destination folder ist not empty. No data migration.");
}
} else {
L.log("INFO: No read permission on external folder. No data migration.");
}
}
}
private static final int READ_EXTERNAL_STORAGE_REQUEST=1;
private static final int WRITE_EXTERNAL_STORAGE_REQUEST=2;
@TargetApi(23)
public static void checkAndRequestPermissions(final Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, READ_EXTERNAL_STORAGE_REQUEST);
}
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE_REQUEST);
}
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listener = (OnNewGameRequestedListener) activity;
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
private void setButtonState(final String playerName, final String displayInfo, int iconID, boolean isDead) {
startscreen_continue.setEnabled(hasExistingGame && !isDead);
startscreen_newgame.setEnabled(true);
if (hasExistingGame) {
TileManager tm = AndorsTrailApplication.getApplicationFromActivity(getActivity()).getWorld().tileManager;
tm.setImageViewTileForPlayer(getResources(), save_preview_hero_icon, iconID);
save_preview_hero_desc.setText((isDead ? getString(R.string.rip_startscreen) : "") + playerName + ", " + displayInfo);
save_preview_holder.setVisibility(View.VISIBLE);
} else {
save_preview_holder.setVisibility(View.GONE);
}
}
private void continueGame(boolean createNewCharacter, int loadFromSlot, String name) {
final WorldSetup setup = AndorsTrailApplication.getApplicationFromActivity(getActivity()).getWorldSetup();
setup.createNewCharacter = createNewCharacter;
setup.loadFromSlot = loadFromSlot;
setup.newHeroName = name;
startActivity(new Intent(getActivity(), LoadingActivity.class));
}
private void comfirmNewGame() {
// new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AndorsTrailStyle_Dialog))
// .setTitle(R.string.startscreen_newgame)
// .setMessage(R.string.startscreen_newgame_confirm)
// .setIcon(android.R.drawable.ic_delete)
// .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// //continueGame(true);
//// hasExistingGame = false;
//// setButtonState(null, null, 0);
// createNewGame();
// }
// })
// .setNegativeButton(android.R.string.cancel, null)
// .create().show();
//
//
final Dialog d = CustomDialogFactory.createDialog(getActivity(),
getString(R.string.startscreen_newgame),
getResources().getDrawable(android.R.drawable.ic_delete),
getResources().getString(R.string.startscreen_newgame_confirm),
null,
true);
CustomDialogFactory.addButton(d, android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
createNewGame();
}
});
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
CustomDialogFactory.show(d);
}
private static final String versionCheck = "lastversion";
private boolean isNewVersion() {
SharedPreferences s = getActivity().getSharedPreferences(Constants.PREFERENCE_MODEL_LASTRUNVERSION, Activity.MODE_PRIVATE);
int lastversion = s.getInt(versionCheck, 0);
if (lastversion >= AndorsTrailApplication.CURRENT_VERSION) return false;
return true;
}
private void setCurrentVersionForVersionCheck() {
SharedPreferences s = getActivity().getSharedPreferences(Constants.PREFERENCE_MODEL_LASTRUNVERSION, Activity.MODE_PRIVATE);
Editor e = s.edit();
e.putInt(versionCheck, AndorsTrailApplication.CURRENT_VERSION);
e.commit();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case INTENTREQUEST_LOADGAME:
if (resultCode != Activity.RESULT_OK) break;
final int slot = data.getIntExtra("slot", 1);
continueGame(false, slot, null);
break;
case INTENTREQUEST_PREFERENCES:
updatePreferences(true);
break;
}
}
private void updatePreferences(boolean alreadyStartedLoadingResources) {
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(getActivity());
AndorsTrailPreferences preferences = app.getPreferences();
preferences.read(getActivity());
if (app.setLocale(getActivity())) {
if (alreadyStartedLoadingResources) {
// Changing the locale after having loaded the game requires resources to
// be re-loaded. Therefore, we just exit here.
Toast.makeText(getActivity(), R.string.change_locale_requires_restart, Toast.LENGTH_LONG).show();
doFinish();
return;
}
}
if (ThemeHelper.changeTheme(preferences.selectedTheme)) {
// Changing the theme requires a restart to re-create all activities.
Toast.makeText(getActivity(), R.string.change_theme_requires_restart, Toast.LENGTH_LONG).show();
doFinish();
return;
}
app.getWorld().tileManager.updatePreferences(preferences);
}
@SuppressLint("NewApi")
private void doFinish() {
//For Lollipop and above
((AndorsTrailApplication)getActivity().getApplication()).discardWorld();
getActivity().finish();
}
public interface OnNewGameRequestedListener {
public void onNewGameRequested();
}
private OnNewGameRequestedListener listener = null;
private void createNewGame() {
if (listener != null) {
listener.onNewGameRequested();
}
}
}
package com.gpl.rpg.AndorsTrail_beta1.activity.fragment;
import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.os.Build;
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.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.Dialogs;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.WorldSetup;
import com.gpl.rpg.AndorsTrail_beta1.activity.AboutActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.LoadingActivity;
import com.gpl.rpg.AndorsTrail_beta1.activity.Preferences;
import com.gpl.rpg.AndorsTrail_beta1.controller.Constants;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail_beta1.savegames.Savegames;
import com.gpl.rpg.AndorsTrail_beta1.savegames.Savegames.FileHeader;
import com.gpl.rpg.AndorsTrail_beta1.util.AndroidStorage;
import com.gpl.rpg.AndorsTrail_beta1.util.L;
import com.gpl.rpg.AndorsTrail_beta1.util.ThemeHelper;
import com.gpl.rpg.AndorsTrail_beta1.view.CustomDialogFactory;
public class StartScreenActivity_MainMenu extends Fragment {
private static final int INTENTREQUEST_PREFERENCES = 7;
public static final int INTENTREQUEST_LOADGAME = 9;
private boolean hasExistingGame = false;
private Button startscreen_continue;
private Button startscreen_newgame;
private Button startscreen_load;
private ViewGroup save_preview_holder;
private ImageView save_preview_hero_icon;
private TextView save_preview_hero_desc;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
updatePreferences(false);
super.onCreateView(inflater, container, savedInstanceState);
if (container != null) {
container.removeAllViews();
}
View root = inflater.inflate(R.layout.startscreen_mainmenu, container, false);
save_preview_holder = (ViewGroup) root.findViewById(R.id.save_preview_holder);
save_preview_hero_icon = (ImageView) root.findViewById(R.id.save_preview_hero_icon);
save_preview_hero_desc = (TextView) root.findViewById(R.id.save_preview_hero_desc);
startscreen_continue = (Button) root.findViewById(R.id.startscreen_continue);
startscreen_continue.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
continueGame(false, Savegames.SLOT_QUICKSAVE, null);
}
});
startscreen_newgame = (Button) root.findViewById(R.id.startscreen_newgame);
startscreen_newgame.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (hasExistingGame) {
comfirmNewGame();
} else {
createNewGame();
}
}
});
Button b = (Button) root.findViewById(R.id.startscreen_about);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(getActivity(), AboutActivity.class));
}
});
b = (Button) root.findViewById(R.id.startscreen_preferences);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getActivity(), Preferences.class);
StartScreenActivity_MainMenu.this.startActivityForResult(intent, INTENTREQUEST_PREFERENCES);
}
});
startscreen_load = (Button) root.findViewById(R.id.startscreen_load);
startscreen_load.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(getActivity());
if (hasExistingGame && app != null && app.getWorld() != null && app.getWorld().model != null
&& app.getWorld().model.statistics != null && !app.getWorld().model.statistics.hasUnlimitedSaves()) {
final Dialog d = CustomDialogFactory.createDialog(getActivity(),
getString(R.string.startscreen_load_game),
getResources().getDrawable(android.R.drawable.ic_delete),
getString(R.string.startscreen_load_game_confirm),
null,
true);
CustomDialogFactory.addButton(d, android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialogs.showLoad(StartScreenActivity_MainMenu.this);
}
});
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
CustomDialogFactory.show(d);
} else {
Dialogs.showLoad(StartScreenActivity_MainMenu.this);
}
}
});
if (AndorsTrailApplication.DEVELOPMENT_FORCE_STARTNEWGAME) {
if (AndorsTrailApplication.DEVELOPMENT_DEBUGRESOURCES) {
continueGame(true, 0, "Debug player");
} else {
continueGame(true, 0, "Player");
}
} else if (AndorsTrailApplication.DEVELOPMENT_FORCE_CONTINUEGAME) {
continueGame(false, Savegames.SLOT_QUICKSAVE, null);
}
// if it is a new version we first fire a welcome screen in onResume
// and afterwards check the permissions
if (!isNewVersion()) {
checkAndRequestPermissions(getActivity());
migrateDataOnDemand(getActivity());
}
return root;
}
@Override
public void onResume() {
super.onResume();
String playerName;
String displayInfo = null;
int iconID = TileManager.CHAR_HERO;
boolean isDead = false;
FileHeader header = Savegames.quickload(getActivity(), Savegames.SLOT_QUICKSAVE);
if (header != null && header.playerName != null) {
playerName = header.playerName;
displayInfo = header.displayInfo;
iconID = header.iconID;
isDead = header.isDead;
} else {
// Before fileversion 14 (v0.6.7), quicksave was stored in Shared preferences
SharedPreferences p = getActivity().getSharedPreferences("quicksave", Activity.MODE_PRIVATE);
playerName = p.getString("playername", null);
if (playerName != null) {
displayInfo = "level " + p.getInt("level", -1);
}
}
hasExistingGame = (playerName != null);
setButtonState(playerName, displayInfo, iconID, isDead);
if (isNewVersion()) {
Dialogs.showNewVersion(getActivity(), new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
setCurrentVersionForVersionCheck();
checkAndRequestPermissions(getActivity());
migrateDataOnDemand(getActivity());
boolean hasSavegames = !Savegames.getUsedSavegameSlots(getActivity()).isEmpty();
startscreen_load.setEnabled(hasSavegames);
}
});
}
boolean hasSavegames = !Savegames.getUsedSavegameSlots(getActivity()).isEmpty();
startscreen_load.setEnabled(hasSavegames);
}
@TargetApi(29)
public void migrateDataOnDemand(final Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
if (AndroidStorage.shouldMigrateToInternalStorage(activity.getApplicationContext())) {
final Dialog d = CustomDialogFactory.createDialog(activity,
getString(R.string.startscreen_migration_title),
activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert),
getString(R.string.startscreen_migration_text),
null,
true);
CustomDialogFactory.addDismissButton(d, android.R.string.ok);
d.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
boolean hasSavegames = !Savegames.getUsedSavegameSlots(getActivity()).isEmpty();
startscreen_load.setEnabled(hasSavegames);
}
});
CustomDialogFactory.show(d);
if (!AndroidStorage.migrateToInternalStorage(activity.getApplicationContext())) {
final Dialog errorDlg = CustomDialogFactory.createDialog(activity,
getString(R.string.startscreen_migration_title),
activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert),
getString(R.string.startscreen_migration_failure),
null,
true);
CustomDialogFactory.addDismissButton(errorDlg, android.R.string.ok);
d.cancel();
CustomDialogFactory.show(errorDlg);
}
} else {
L.log("INFO: No external files or destination folder ist not empty. No data migration.");
}
} else {
L.log("INFO: No read permission on external folder. No data migration.");
}
}
}
private static final int READ_EXTERNAL_STORAGE_REQUEST=1;
private static final int WRITE_EXTERNAL_STORAGE_REQUEST=2;
@TargetApi(23)
public static void checkAndRequestPermissions(final Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, READ_EXTERNAL_STORAGE_REQUEST);
}
if (activity.getApplicationContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE_REQUEST);
}
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listener = (OnNewGameRequestedListener) activity;
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
private void setButtonState(final String playerName, final String displayInfo, int iconID, boolean isDead) {
startscreen_continue.setEnabled(hasExistingGame && !isDead);
startscreen_newgame.setEnabled(true);
if (hasExistingGame) {
TileManager tm = AndorsTrailApplication.getApplicationFromActivity(getActivity()).getWorld().tileManager;
tm.setImageViewTileForPlayer(getResources(), save_preview_hero_icon, iconID);
save_preview_hero_desc.setText((isDead ? getString(R.string.rip_startscreen) : "") + playerName + ", " + displayInfo);
save_preview_holder.setVisibility(View.VISIBLE);
} else {
save_preview_holder.setVisibility(View.GONE);
}
}
private void continueGame(boolean createNewCharacter, int loadFromSlot, String name) {
final WorldSetup setup = AndorsTrailApplication.getApplicationFromActivity(getActivity()).getWorldSetup();
setup.createNewCharacter = createNewCharacter;
setup.loadFromSlot = loadFromSlot;
setup.newHeroName = name;
startActivity(new Intent(getActivity(), LoadingActivity.class));
}
private void comfirmNewGame() {
// new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AndorsTrailStyle_Dialog))
// .setTitle(R.string.startscreen_newgame)
// .setMessage(R.string.startscreen_newgame_confirm)
// .setIcon(android.R.drawable.ic_delete)
// .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// //continueGame(true);
//// hasExistingGame = false;
//// setButtonState(null, null, 0);
// createNewGame();
// }
// })
// .setNegativeButton(android.R.string.cancel, null)
// .create().show();
//
//
final Dialog d = CustomDialogFactory.createDialog(getActivity(),
getString(R.string.startscreen_newgame),
getResources().getDrawable(android.R.drawable.ic_delete),
getResources().getString(R.string.startscreen_newgame_confirm),
null,
true);
CustomDialogFactory.addButton(d, android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
createNewGame();
}
});
CustomDialogFactory.addDismissButton(d, android.R.string.cancel);
CustomDialogFactory.show(d);
}
private static final String versionCheck = "lastversion";
private boolean isNewVersion() {
SharedPreferences s = getActivity().getSharedPreferences(Constants.PREFERENCE_MODEL_LASTRUNVERSION, Activity.MODE_PRIVATE);
int lastversion = s.getInt(versionCheck, 0);
if (lastversion >= AndorsTrailApplication.CURRENT_VERSION) return false;
return true;
}
private void setCurrentVersionForVersionCheck() {
SharedPreferences s = getActivity().getSharedPreferences(Constants.PREFERENCE_MODEL_LASTRUNVERSION, Activity.MODE_PRIVATE);
Editor e = s.edit();
e.putInt(versionCheck, AndorsTrailApplication.CURRENT_VERSION);
e.commit();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case INTENTREQUEST_LOADGAME:
if (resultCode != Activity.RESULT_OK) break;
final int slot = data.getIntExtra("slot", 1);
continueGame(false, slot, null);
break;
case INTENTREQUEST_PREFERENCES:
updatePreferences(true);
break;
}
}
private void updatePreferences(boolean alreadyStartedLoadingResources) {
AndorsTrailApplication app = AndorsTrailApplication.getApplicationFromActivity(getActivity());
AndorsTrailPreferences preferences = app.getPreferences();
preferences.read(getActivity());
if (app.setLocale(getActivity())) {
if (alreadyStartedLoadingResources) {
// Changing the locale after having loaded the game requires resources to
// be re-loaded. Therefore, we just exit here.
Toast.makeText(getActivity(), R.string.change_locale_requires_restart, Toast.LENGTH_LONG).show();
doFinish();
return;
}
}
if (ThemeHelper.changeTheme(preferences.selectedTheme)) {
// Changing the theme requires a restart to re-create all activities.
Toast.makeText(getActivity(), R.string.change_theme_requires_restart, Toast.LENGTH_LONG).show();
doFinish();
return;
}
app.getWorld().tileManager.updatePreferences(preferences);
}
@SuppressLint("NewApi")
private void doFinish() {
//For Lollipop and above
((AndorsTrailApplication)getActivity().getApplication()).discardWorld();
getActivity().finish();
}
public interface OnNewGameRequestedListener {
public void onNewGameRequested();
}
private OnNewGameRequestedListener listener = null;
private void createNewGame() {
if (listener != null) {
listener.onNewGameRequested();
}
}
}

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.activity.fragment;
package com.gpl.rpg.AndorsTrail_beta1.activity.fragment;
import android.app.Activity;
import android.content.Intent;
@@ -15,12 +15,12 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.WorldSetup;
import com.gpl.rpg.AndorsTrail.activity.LoadingActivity;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail.view.SpinnerEmulator;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.WorldSetup;
import com.gpl.rpg.AndorsTrail_beta1.activity.LoadingActivity;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail_beta1.view.SpinnerEmulator;
public class StartScreenActivity_NewGame extends Fragment {

View File

@@ -1,24 +1,24 @@
package com.gpl.rpg.AndorsTrail.context;
package com.gpl.rpg.AndorsTrail_beta1.context;
import java.lang.ref.WeakReference;
import android.content.Context;
import android.content.res.Resources;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.controller.ActorStatsController;
import com.gpl.rpg.AndorsTrail.controller.CombatController;
import com.gpl.rpg.AndorsTrail.controller.ConversationController;
import com.gpl.rpg.AndorsTrail.controller.GameRoundController;
import com.gpl.rpg.AndorsTrail.controller.InputController;
import com.gpl.rpg.AndorsTrail.controller.ItemController;
import com.gpl.rpg.AndorsTrail.controller.MapController;
import com.gpl.rpg.AndorsTrail.controller.MonsterMovementController;
import com.gpl.rpg.AndorsTrail.controller.MonsterSpawningController;
import com.gpl.rpg.AndorsTrail.controller.MovementController;
import com.gpl.rpg.AndorsTrail.controller.SkillController;
import com.gpl.rpg.AndorsTrail.controller.VisualEffectController;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.controller.ActorStatsController;
import com.gpl.rpg.AndorsTrail_beta1.controller.CombatController;
import com.gpl.rpg.AndorsTrail_beta1.controller.ConversationController;
import com.gpl.rpg.AndorsTrail_beta1.controller.GameRoundController;
import com.gpl.rpg.AndorsTrail_beta1.controller.InputController;
import com.gpl.rpg.AndorsTrail_beta1.controller.ItemController;
import com.gpl.rpg.AndorsTrail_beta1.controller.MapController;
import com.gpl.rpg.AndorsTrail_beta1.controller.MonsterMovementController;
import com.gpl.rpg.AndorsTrail_beta1.controller.MonsterSpawningController;
import com.gpl.rpg.AndorsTrail_beta1.controller.MovementController;
import com.gpl.rpg.AndorsTrail_beta1.controller.SkillController;
import com.gpl.rpg.AndorsTrail_beta1.controller.VisualEffectController;
public final class ControllerContext {
//Controllers

View File

@@ -1,17 +1,17 @@
package com.gpl.rpg.AndorsTrail.context;
package com.gpl.rpg.AndorsTrail_beta1.context;
import com.gpl.rpg.AndorsTrail.model.ModelContainer;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionTypeCollection;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.actor.MonsterTypeCollection;
import com.gpl.rpg.AndorsTrail.model.item.DropListCollection;
import com.gpl.rpg.AndorsTrail.model.item.ItemCategoryCollection;
import com.gpl.rpg.AndorsTrail.model.item.ItemTypeCollection;
import com.gpl.rpg.AndorsTrail.model.map.MapCollection;
import com.gpl.rpg.AndorsTrail.model.quest.QuestCollection;
import com.gpl.rpg.AndorsTrail.resource.ConversationLoader;
import com.gpl.rpg.AndorsTrail.resource.VisualEffectCollection;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail_beta1.model.ModelContainer;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionTypeCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.MonsterTypeCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.item.DropListCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemCategoryCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTypeCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.quest.QuestCollection;
import com.gpl.rpg.AndorsTrail_beta1.resource.ConversationLoader;
import com.gpl.rpg.AndorsTrail_beta1.resource.VisualEffectCollection;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileManager;
public final class WorldContext {
//Objectcollections

View File

@@ -1,31 +1,31 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import java.util.ArrayList;
import java.util.List;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.listeners.ActorConditionListeners;
import com.gpl.rpg.AndorsTrail.controller.listeners.ActorStatsListeners;
import com.gpl.rpg.AndorsTrail.controller.listeners.CombatActionListeners;
import com.gpl.rpg.AndorsTrail.controller.listeners.PlayerStatsListeners;
import com.gpl.rpg.AndorsTrail.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.ability.traits.AbilityModifierTraits;
import com.gpl.rpg.AndorsTrail.model.ability.traits.StatsModifierTraits;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.Inventory;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnEquip;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnHitReceived;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnUse;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.resource.VisualEffectCollection;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.ActorConditionListeners;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.ActorStatsListeners;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.CombatActionListeners;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.PlayerStatsListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.traits.AbilityModifierTraits;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.traits.StatsModifierTraits;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Inventory;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnEquip;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnHitReceived;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnUse;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.resource.VisualEffectCollection;
public final class ActorStatsController {
private final ControllerContext controllers;

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
public final class AttackResult {
public final boolean isHit;

View File

@@ -1,30 +1,30 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import java.util.ArrayList;
import android.os.Handler;
import android.os.Message;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.VisualEffectController.VisualEffectCompletedCallback;
import com.gpl.rpg.AndorsTrail.controller.listeners.CombatActionListeners;
import com.gpl.rpg.AndorsTrail.controller.listeners.CombatSelectionListeners;
import com.gpl.rpg.AndorsTrail.controller.listeners.CombatTurnListeners;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.MonsterType;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.ItemContainer;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnHitReceived;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnUse;
import com.gpl.rpg.AndorsTrail.model.item.Loot;
import com.gpl.rpg.AndorsTrail.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail.resource.VisualEffectCollection;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.VisualEffectController.VisualEffectCompletedCallback;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.CombatActionListeners;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.CombatSelectionListeners;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.CombatTurnListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.MonsterType;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemContainer;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnHitReceived;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnUse;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Loot;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail_beta1.resource.VisualEffectCollection;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import static java.lang.Math.max;

View File

@@ -1,10 +1,10 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import java.util.Random;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.util.ConstRange;
import com.gpl.rpg.AndorsTrail.util.Range;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.util.ConstRange;
import com.gpl.rpg.AndorsTrail_beta1.util.Range;
public final class Constants {
public static final int PERCENT_EXP_LOST_WHEN_DIED = 30;

View File

@@ -1,35 +1,35 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import java.util.ArrayList;
import android.content.res.Resources;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.GameStatistics;
import com.gpl.rpg.AndorsTrail.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.ability.SkillInfo;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.conversation.ConversationCollection;
import com.gpl.rpg.AndorsTrail.model.conversation.Phrase;
import com.gpl.rpg.AndorsTrail.model.conversation.Reply;
import com.gpl.rpg.AndorsTrail.model.item.ItemTypeCollection;
import com.gpl.rpg.AndorsTrail.model.item.Loot;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.model.quest.QuestLogEntry;
import com.gpl.rpg.AndorsTrail.model.quest.QuestProgress;
import com.gpl.rpg.AndorsTrail.model.script.Requirement;
import com.gpl.rpg.AndorsTrail.model.script.ScriptEffect;
import com.gpl.rpg.AndorsTrail.util.ConstRange;
import com.gpl.rpg.AndorsTrail.util.L;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.GameStatistics;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillInfo;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.conversation.ConversationCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.conversation.Phrase;
import com.gpl.rpg.AndorsTrail_beta1.model.conversation.Reply;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTypeCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Loot;
import com.gpl.rpg.AndorsTrail_beta1.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.model.quest.QuestLogEntry;
import com.gpl.rpg.AndorsTrail_beta1.model.quest.QuestProgress;
import com.gpl.rpg.AndorsTrail_beta1.model.script.Requirement;
import com.gpl.rpg.AndorsTrail_beta1.model.script.ScriptEffect;
import com.gpl.rpg.AndorsTrail_beta1.util.ConstRange;
import com.gpl.rpg.AndorsTrail_beta1.util.L;
public final class ConversationController {

View File

@@ -1,10 +1,10 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.listeners.GameRoundListeners;
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.util.TimedMessageTask;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.GameRoundListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapObject;
import com.gpl.rpg.AndorsTrail_beta1.util.TimedMessageTask;
public final class GameRoundController implements TimedMessageTask.Callback {

View File

@@ -1,13 +1,13 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
public final class InputController implements OnClickListener, OnLongClickListener{
private final ControllerContext controllers;

View File

@@ -1,446 +1,446 @@
package com.gpl.rpg.AndorsTrail.controller;
import java.util.ArrayList;
import java.util.Collection;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.listeners.QuickSlotListeners;
import com.gpl.rpg.AndorsTrail.model.ModelContainer;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.ability.traits.AbilityModifierTraits;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.Inventory;
import com.gpl.rpg.AndorsTrail.model.item.ItemContainer;
import com.gpl.rpg.AndorsTrail.model.item.ItemContainer.ItemEntry;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnHitReceived;
import com.gpl.rpg.AndorsTrail.model.item.ItemTraits_OnUse;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.model.item.Loot;
import static java.lang.Math.min;
public final class ItemController {
private final ControllerContext controllers;
private final WorldContext world;
public final QuickSlotListeners quickSlotListeners = new QuickSlotListeners();
public ItemController(ControllerContext controllers, WorldContext world) {
this.controllers = controllers;
this.world = world;
}
public void dropItem(ItemType type, int quantity) {
if (world.model.player.inventory.getItemQuantity(type.id) < quantity) return;
world.model.player.inventory.removeItem(type.id, quantity);
world.model.currentMaps.map.itemDropped(type, quantity, world.model.player.position);
}
public void equipItem(ItemType type, Inventory.WearSlot slot) {
if (!type.isEquippable()) return;
final Player player = world.model.player;
if (world.model.uiSelections.isInCombat) {
boolean changed = controllers.actorStatsController.useAPs(player, player.getReequipCost());
if (!changed) return;
}
if (!player.inventory.removeItem(type.id, 1)) return;
unequipSlot(player, slot);
if (type.isTwohandWeapon()) unequipSlot(player, Inventory.WearSlot.shield);
else if (slot == Inventory.WearSlot.shield) {
ItemType currentWeapon = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
if (currentWeapon != null && currentWeapon.isTwohandWeapon()) unequipSlot(player, Inventory.WearSlot.weapon);
}
player.inventory.setItemTypeInWearSlot(slot, type);
controllers.actorStatsController.addConditionsFromEquippedItem(player, type);
controllers.actorStatsController.recalculatePlayerStats(player);
if (world.model.uiSelections.isInCombat && !controllers.combatController.playerHasApLeft()) {
controllers.combatController.endPlayerTurn();
}
}
public void unequipSlot(ItemType type, Inventory.WearSlot slot) {
if (!type.isEquippable()) return;
final Player player = world.model.player;
if (player.inventory.isEmptySlot(slot)) return;
if (world.model.uiSelections.isInCombat) {
boolean changed = controllers.actorStatsController.useAPs(player, player.getReequipCost());
if (!changed) return;
}
unequipSlot(player, slot);
controllers.actorStatsController.recalculatePlayerStats(player);
if (world.model.uiSelections.isInCombat && !controllers.combatController.playerHasApLeft()) {
controllers.combatController.endPlayerTurn();
}
}
private void unequipSlot(Player player, Inventory.WearSlot slot) {
ItemType removedItemType = player.inventory.getItemTypeInWearSlot(slot);
if (removedItemType == null) return;
player.inventory.addItem(removedItemType);
player.inventory.setItemTypeInWearSlot(slot, null);
controllers.actorStatsController.removeConditionsFromUnequippedItem(player, removedItemType);
}
public void useItem(ItemType type) {
if (!type.isUsable()) return;
final Player player = world.model.player;
if (world.model.uiSelections.isInCombat) {
boolean changed = controllers.actorStatsController.useAPs(player, player.getUseItemCost());
if (!changed) return;
}
if (!player.inventory.removeItem(type.id, 1)) return;
world.model.combatLog.append(controllers.getResources().getString(R.string.inventory_item_used, type.getName(player)));
controllers.actorStatsController.applyUseEffect(player, null, type.effects_use);
world.model.statistics.addItemUsage(type);
if (world.model.uiSelections.isInCombat && !controllers.combatController.playerHasApLeft()) {
controllers.combatController.endPlayerTurn();
}
}
public void playerSteppedOnLootBag(Loot loot) {
if (pickupLootBagWithoutConfirmation(loot)) {
controllers.mapController.worldEventListeners.onPlayerPickedUpGroundLoot(loot);
pickupAll(loot);
removeLootBagIfEmpty(loot);
} else {
controllers.mapController.worldEventListeners.onPlayerSteppedOnGroundLoot(loot);
consumeNonItemLoot(loot);
}
}
public void lootMonsterBags(Collection<Loot> killedMonsterBags, int totalExpThisFight) {
if (pickupLootBagsWithoutConfirmation(killedMonsterBags)) {
controllers.mapController.worldEventListeners.onPlayerPickedUpMonsterLoot(killedMonsterBags, totalExpThisFight);
pickupAll(killedMonsterBags);
removeLootBagIfEmpty(killedMonsterBags);
controllers.gameRoundController.resume();
} else {
controllers.mapController.worldEventListeners.onPlayerFoundMonsterLoot(killedMonsterBags, totalExpThisFight);
consumeNonItemLoot(killedMonsterBags);
}
}
private boolean pickupLootBagWithoutConfirmation(Loot bag) {
if (bag.isContainer()) return false;
switch (controllers.preferences.displayLoot) {
case AndorsTrailPreferences.DISPLAYLOOT_DIALOG_ALWAYS:
return false;
case AndorsTrailPreferences.DISPLAYLOOT_DIALOG_FOR_ITEMS:
case AndorsTrailPreferences.DISPLAYLOOT_DIALOG_FOR_ITEMS_ELSE_TOAST:
if (bag.hasItems()) return false;
}
return true;
}
private boolean pickupLootBagsWithoutConfirmation(Collection<Loot> bags) {
if (controllers.preferences.displayLoot == AndorsTrailPreferences.DISPLAYLOOT_DIALOG_ALWAYS) return false;
for (Loot bag : bags) {
if (!pickupLootBagWithoutConfirmation(bag)) return false;
}
return true;
}
public void applyInventoryEffects(Player player) {
ItemType weapon = getMainWeapon(player);
if (weapon != null) {
player.attackCost = 0;
player.criticalMultiplier = weapon.effects_equip.stats.setCriticalMultiplier;
}
applyInventoryEffects(player, Inventory.WearSlot.weapon);
applyInventoryEffects(player, Inventory.WearSlot.shield);
SkillController.applySkillEffectsFromFightingStyles(player);
applyInventoryEffects(player, Inventory.WearSlot.head);
applyInventoryEffects(player, Inventory.WearSlot.body);
applyInventoryEffects(player, Inventory.WearSlot.hand);
applyInventoryEffects(player, Inventory.WearSlot.feet);
applyInventoryEffects(player, Inventory.WearSlot.neck);
applyInventoryEffects(player, Inventory.WearSlot.leftring);
applyInventoryEffects(player, Inventory.WearSlot.rightring);
SkillController.applySkillEffectsFromItemProficiencies(player);
}
public static ItemType getMainWeapon(Player player) {
ItemType itemType = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
if (itemType != null) return itemType;
itemType = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.shield);
if (itemType != null && itemType.isWeapon()) return itemType;
return null;
}
private void applyInventoryEffects(Player player, Inventory.WearSlot slot) {
ItemType type = player.inventory.getItemTypeInWearSlot(slot);
if (type == null) return;
if (slot == Inventory.WearSlot.shield) {
ItemType mainHandItem = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
// The stats for off-hand weapons will be added later in SkillController.applySkillEffectsFromFightingStyles
if (SkillController.isDualWielding(mainHandItem, type)) return;
}
if (type.effects_equip != null && type.effects_equip.stats != null) {
controllers.actorStatsController.applyAbilityEffects(player, type.effects_equip.stats, 1);
if (type.isWeapon()) {
controllers.actorStatsController.addPlayerWeaponDamage(player, type.effects_equip.stats.increaseMinDamage, type.effects_equip.stats.increaseMaxDamage);
}
}
}
public static void recalculateHitEffectsFromWornItems(Player player) {
ArrayList<ItemTraits_OnUse> effects_onHit = null;
ArrayList<ItemTraits_OnHitReceived> effects_onHitReceived = null;
for (Inventory.WearSlot slot : Inventory.WearSlot.values()) {
ItemType type = player.inventory.getItemTypeInWearSlot(slot);
if (type == null) continue;
ItemTraits_OnUse eh = type.effects_hit;
ItemTraits_OnHitReceived ehr = type.effects_hitReceived;
if (eh == null && ehr == null) continue;
if (effects_onHit == null) effects_onHit = new ArrayList<ItemTraits_OnUse>();
if (eh != null) effects_onHit.add(eh);
if (effects_onHitReceived == null) effects_onHitReceived = new ArrayList<ItemTraits_OnHitReceived>();
if (ehr != null) effects_onHitReceived.add(ehr);
}
if (effects_onHit != null) {
ItemTraits_OnUse[] effects_ = new ItemTraits_OnUse[effects_onHit.size()];
effects_ = effects_onHit.toArray(effects_);
player.onHitEffects = effects_;
} else {
player.onHitEffects = null;
}
if (effects_onHitReceived != null) {
ItemTraits_OnHitReceived[] effects_ = new ItemTraits_OnHitReceived[effects_onHitReceived.size()];
effects_ = effects_onHitReceived.toArray(effects_);
player.onHitReceivedEffects = effects_;
} else {
player.onHitReceivedEffects = null;
}
}
public void consumeNonItemLoot(Loot loot) {
// Experience will be given as soon as the monster is killed.
world.model.player.inventory.gold += loot.gold;
loot.gold = 0;
removeLootBagIfEmpty(loot);
}
public void consumeNonItemLoot(Iterable<Loot> lootBags) {
for(Loot l : lootBags) {
consumeNonItemLoot(l);
}
}
public void pickupAll(Loot loot) {
world.model.player.inventory.add(loot.items);
consumeNonItemLoot(loot);
checkQuickslotItemLooted(loot.items);
loot.clear();
}
public void pickupAll(Iterable<Loot> lootBags) {
for(Loot l : lootBags) {
pickupAll(l);
}
}
public boolean removeLootBagIfEmpty(final Loot loot) {
if (loot.hasItemsOrGold()) return false;
world.model.currentMaps.map.removeGroundLoot(loot);
controllers.mapController.mapLayoutListeners.onLootBagRemoved(world.model.currentMaps.map, loot.position);
return true; // The bag was removed.
}
public boolean removeLootBagIfEmpty(final Iterable<Loot> lootBags) {
boolean isEmpty = true;
for (Loot l : lootBags) {
if (!removeLootBagIfEmpty(l)) isEmpty = false;
}
return isEmpty;
}
private static int getMarketPriceFactor(Player player) {
return Constants.MARKET_PRICEFACTOR_PERCENT
- player.getSkillLevel(SkillCollection.SkillID.barter) * SkillCollection.PER_SKILLPOINT_INCREASE_BARTER_PRICEFACTOR_PERCENTAGE;
}
public static int getBuyingPrice(Player player, ItemType itemType) {
return itemType.baseMarketCost + itemType.baseMarketCost * getMarketPriceFactor(player) / 100;
}
public static int getSellingPrice(Player player, ItemType itemType) {
return itemType.baseMarketCost - itemType.baseMarketCost * getMarketPriceFactor(player) / 100;
}
public static boolean canAfford(Player player, ItemType itemType) {
return player.inventory.gold >= getBuyingPrice(player, itemType);
}
public static boolean canAfford(Player player, int price) {
return player.inventory.gold >= price;
}
public static boolean maySellItem(Player player, ItemType itemType) {
if (!itemType.isSellable()) return false;
return true;
}
public static boolean sell(Player player, ItemType itemType, ItemContainer merchant, int quantity) {
int price = getSellingPrice(player, 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 boolean buy(ModelContainer model, Player player, ItemType itemType, ItemContainer merchant, int quantity) {
int price = getBuyingPrice(player, itemType) * quantity;
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;
}
public static String describeItemForListView(ItemEntry item, Player player) {
StringBuilder sb = new StringBuilder(item.itemType.getName(player));
if (item.quantity > 1) {
sb.append(" (");
sb.append(item.quantity);
sb.append(')');
}
if (item.itemType.effects_equip != null) {
AbilityModifierTraits t = item.itemType.effects_equip.stats;
if (t != null) {
if (t.increaseAttackChance != 0
|| t.increaseMinDamage != 0
|| t.increaseMaxDamage != 0
|| t.increaseCriticalSkill != 0
|| t.setCriticalMultiplier != 0) {
sb.append(" [");
describeAttackEffect(t.increaseAttackChance, t.increaseMinDamage, t.increaseMaxDamage, t.increaseCriticalSkill, t.setCriticalMultiplier, sb);
sb.append(']');
}
if (t.increaseBlockChance != 0
|| t.increaseDamageResistance != 0) {
sb.append(" [");
describeBlockEffect(t.increaseBlockChance, t.increaseDamageResistance, sb);
sb.append(']');
}
}
}
return sb.toString();
}
public static void describeAttackEffect(int attackChance, int minDamage, int maxDamage, int criticalSkill, float criticalMultiplier, StringBuilder sb) {
boolean addSpace = false;
if (attackChance != 0) {
sb.append(attackChance);
addSpace = true;
}
if (minDamage != 0 || maxDamage != 0) {
if (addSpace) sb.append(' ');
sb.append(minDamage);
if (minDamage != maxDamage) {
sb.append('-');
sb.append(maxDamage);
}
addSpace = true;
}
if (criticalSkill != 0) {
if (addSpace) sb.append(' ');
if (criticalSkill >= 0) {
sb.append('+');
}
sb.append(criticalSkill);
}
if (criticalMultiplier != 0 && criticalMultiplier != 1) {
sb.append('x');
sb.append(criticalMultiplier);
}
}
public static void describeBlockEffect(int blockChance, int damageResistance, StringBuilder sb) {
if (blockChance != 0) {
sb.append(blockChance);
}
if (damageResistance != 0) {
sb.append('/');
sb.append(damageResistance);
}
}
public void quickitemUse(int quickSlotId) {
useItem(world.model.player.inventory.quickitem[quickSlotId]);
quickSlotListeners.onQuickSlotUsed(quickSlotId);
}
public void setQuickItem(ItemType itemType, int quickSlotId) {
world.model.player.inventory.quickitem[quickSlotId] = itemType;
quickSlotListeners.onQuickSlotChanged(quickSlotId);
}
private void checkQuickslotItemLooted(ItemContainer items) {
for (ItemEntry item : items.items) {
if (item.itemType.isUsable()) {
for (int i = 0; i < world.model.player.inventory.quickitem.length; i++) {
if (item.itemType == world.model.player.inventory.quickitem[i]) {
quickSlotListeners.onQuickSlotChanged(i);
}
}
}
}
}
public int removeEquippedItem(String itemTypeID, int count) {
int removed = 0;
final Player player = world.model.player;
for (Inventory.WearSlot slot : Inventory.WearSlot.values()) {
ItemType type = player.inventory.getItemTypeInWearSlot(slot);
if (type != null && type.id.equals(itemTypeID)) {
player.inventory.setItemTypeInWearSlot(slot, null);
controllers.actorStatsController.removeConditionsFromUnequippedItem(player, type);
controllers.actorStatsController.recalculatePlayerStats(player);
removed++;
if (removed >= count) {
break;
}
}
}
return removed;
}
public static void applyDamageModifier(Player player) {
ItemType itemType = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
int modifier1 = -1;
int modifier2 = -1;
if (itemType != null) modifier1 = itemType.effects_equip.stats.setNonWeaponDamageModifier;
itemType = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.shield);
if (itemType != null && itemType.isWeapon()) modifier2 = itemType.effects_equip.stats.setNonWeaponDamageModifier;
int modifier = 100;
if (modifier1 >= 0 && modifier2 >= 0) {
int skillLevelFightStyle = player.getSkillLevel(SkillCollection.SkillID.fightstyleDualWield);
if (skillLevelFightStyle == 2) {
modifier = Math.max(modifier1, modifier2);
} else if (skillLevelFightStyle == 1) {
modifier = (modifier1 + modifier2) / 2;
} else {
modifier = Math.min(modifier1, modifier2);
}
}
else if (modifier1 <= 0 && modifier2 >= 0) modifier = modifier2;
else if (modifier2 <= 0 && modifier1 >= 0) modifier = modifier1;
if (modifier != 100) {
final int minBaseDamage = player.damagePotential.current - player.weaponDamage.current;
final int maxBaseDamage = player.damagePotential.max - player.weaponDamage.max;
player.damagePotential.add(Math.round(minBaseDamage * ((modifier - 100)/100f)), true);
player.damagePotential.addToMax(Math.round(maxBaseDamage * ((modifier - 100)/100f)));
}
}
}
package com.gpl.rpg.AndorsTrail_beta1.controller;
import java.util.ArrayList;
import java.util.Collection;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.QuickSlotListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.ModelContainer;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.traits.AbilityModifierTraits;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Inventory;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemContainer;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemContainer.ItemEntry;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnHitReceived;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTraits_OnUse;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Loot;
import static java.lang.Math.min;
public final class ItemController {
private final ControllerContext controllers;
private final WorldContext world;
public final QuickSlotListeners quickSlotListeners = new QuickSlotListeners();
public ItemController(ControllerContext controllers, WorldContext world) {
this.controllers = controllers;
this.world = world;
}
public void dropItem(ItemType type, int quantity) {
if (world.model.player.inventory.getItemQuantity(type.id) < quantity) return;
world.model.player.inventory.removeItem(type.id, quantity);
world.model.currentMaps.map.itemDropped(type, quantity, world.model.player.position);
}
public void equipItem(ItemType type, Inventory.WearSlot slot) {
if (!type.isEquippable()) return;
final Player player = world.model.player;
if (world.model.uiSelections.isInCombat) {
boolean changed = controllers.actorStatsController.useAPs(player, player.getReequipCost());
if (!changed) return;
}
if (!player.inventory.removeItem(type.id, 1)) return;
unequipSlot(player, slot);
if (type.isTwohandWeapon()) unequipSlot(player, Inventory.WearSlot.shield);
else if (slot == Inventory.WearSlot.shield) {
ItemType currentWeapon = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
if (currentWeapon != null && currentWeapon.isTwohandWeapon()) unequipSlot(player, Inventory.WearSlot.weapon);
}
player.inventory.setItemTypeInWearSlot(slot, type);
controllers.actorStatsController.addConditionsFromEquippedItem(player, type);
controllers.actorStatsController.recalculatePlayerStats(player);
if (world.model.uiSelections.isInCombat && !controllers.combatController.playerHasApLeft()) {
controllers.combatController.endPlayerTurn();
}
}
public void unequipSlot(ItemType type, Inventory.WearSlot slot) {
if (!type.isEquippable()) return;
final Player player = world.model.player;
if (player.inventory.isEmptySlot(slot)) return;
if (world.model.uiSelections.isInCombat) {
boolean changed = controllers.actorStatsController.useAPs(player, player.getReequipCost());
if (!changed) return;
}
unequipSlot(player, slot);
controllers.actorStatsController.recalculatePlayerStats(player);
if (world.model.uiSelections.isInCombat && !controllers.combatController.playerHasApLeft()) {
controllers.combatController.endPlayerTurn();
}
}
private void unequipSlot(Player player, Inventory.WearSlot slot) {
ItemType removedItemType = player.inventory.getItemTypeInWearSlot(slot);
if (removedItemType == null) return;
player.inventory.addItem(removedItemType);
player.inventory.setItemTypeInWearSlot(slot, null);
controllers.actorStatsController.removeConditionsFromUnequippedItem(player, removedItemType);
}
public void useItem(ItemType type) {
if (!type.isUsable()) return;
final Player player = world.model.player;
if (world.model.uiSelections.isInCombat) {
boolean changed = controllers.actorStatsController.useAPs(player, player.getUseItemCost());
if (!changed) return;
}
if (!player.inventory.removeItem(type.id, 1)) return;
world.model.combatLog.append(controllers.getResources().getString(R.string.inventory_item_used, type.getName(player)));
controllers.actorStatsController.applyUseEffect(player, null, type.effects_use);
world.model.statistics.addItemUsage(type);
if (world.model.uiSelections.isInCombat && !controllers.combatController.playerHasApLeft()) {
controllers.combatController.endPlayerTurn();
}
}
public void playerSteppedOnLootBag(Loot loot) {
if (pickupLootBagWithoutConfirmation(loot)) {
controllers.mapController.worldEventListeners.onPlayerPickedUpGroundLoot(loot);
pickupAll(loot);
removeLootBagIfEmpty(loot);
} else {
controllers.mapController.worldEventListeners.onPlayerSteppedOnGroundLoot(loot);
consumeNonItemLoot(loot);
}
}
public void lootMonsterBags(Collection<Loot> killedMonsterBags, int totalExpThisFight) {
if (pickupLootBagsWithoutConfirmation(killedMonsterBags)) {
controllers.mapController.worldEventListeners.onPlayerPickedUpMonsterLoot(killedMonsterBags, totalExpThisFight);
pickupAll(killedMonsterBags);
removeLootBagIfEmpty(killedMonsterBags);
controllers.gameRoundController.resume();
} else {
controllers.mapController.worldEventListeners.onPlayerFoundMonsterLoot(killedMonsterBags, totalExpThisFight);
consumeNonItemLoot(killedMonsterBags);
}
}
private boolean pickupLootBagWithoutConfirmation(Loot bag) {
if (bag.isContainer()) return false;
switch (controllers.preferences.displayLoot) {
case AndorsTrailPreferences.DISPLAYLOOT_DIALOG_ALWAYS:
return false;
case AndorsTrailPreferences.DISPLAYLOOT_DIALOG_FOR_ITEMS:
case AndorsTrailPreferences.DISPLAYLOOT_DIALOG_FOR_ITEMS_ELSE_TOAST:
if (bag.hasItems()) return false;
}
return true;
}
private boolean pickupLootBagsWithoutConfirmation(Collection<Loot> bags) {
if (controllers.preferences.displayLoot == AndorsTrailPreferences.DISPLAYLOOT_DIALOG_ALWAYS) return false;
for (Loot bag : bags) {
if (!pickupLootBagWithoutConfirmation(bag)) return false;
}
return true;
}
public void applyInventoryEffects(Player player) {
ItemType weapon = getMainWeapon(player);
if (weapon != null) {
player.attackCost = 0;
player.criticalMultiplier = weapon.effects_equip.stats.setCriticalMultiplier;
}
applyInventoryEffects(player, Inventory.WearSlot.weapon);
applyInventoryEffects(player, Inventory.WearSlot.shield);
SkillController.applySkillEffectsFromFightingStyles(player);
applyInventoryEffects(player, Inventory.WearSlot.head);
applyInventoryEffects(player, Inventory.WearSlot.body);
applyInventoryEffects(player, Inventory.WearSlot.hand);
applyInventoryEffects(player, Inventory.WearSlot.feet);
applyInventoryEffects(player, Inventory.WearSlot.neck);
applyInventoryEffects(player, Inventory.WearSlot.leftring);
applyInventoryEffects(player, Inventory.WearSlot.rightring);
SkillController.applySkillEffectsFromItemProficiencies(player);
}
public static ItemType getMainWeapon(Player player) {
ItemType itemType = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
if (itemType != null) return itemType;
itemType = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.shield);
if (itemType != null && itemType.isWeapon()) return itemType;
return null;
}
private void applyInventoryEffects(Player player, Inventory.WearSlot slot) {
ItemType type = player.inventory.getItemTypeInWearSlot(slot);
if (type == null) return;
if (slot == Inventory.WearSlot.shield) {
ItemType mainHandItem = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
// The stats for off-hand weapons will be added later in SkillController.applySkillEffectsFromFightingStyles
if (SkillController.isDualWielding(mainHandItem, type)) return;
}
if (type.effects_equip != null && type.effects_equip.stats != null) {
controllers.actorStatsController.applyAbilityEffects(player, type.effects_equip.stats, 1);
if (type.isWeapon()) {
controllers.actorStatsController.addPlayerWeaponDamage(player, type.effects_equip.stats.increaseMinDamage, type.effects_equip.stats.increaseMaxDamage);
}
}
}
public static void recalculateHitEffectsFromWornItems(Player player) {
ArrayList<ItemTraits_OnUse> effects_onHit = null;
ArrayList<ItemTraits_OnHitReceived> effects_onHitReceived = null;
for (Inventory.WearSlot slot : Inventory.WearSlot.values()) {
ItemType type = player.inventory.getItemTypeInWearSlot(slot);
if (type == null) continue;
ItemTraits_OnUse eh = type.effects_hit;
ItemTraits_OnHitReceived ehr = type.effects_hitReceived;
if (eh == null && ehr == null) continue;
if (effects_onHit == null) effects_onHit = new ArrayList<ItemTraits_OnUse>();
if (eh != null) effects_onHit.add(eh);
if (effects_onHitReceived == null) effects_onHitReceived = new ArrayList<ItemTraits_OnHitReceived>();
if (ehr != null) effects_onHitReceived.add(ehr);
}
if (effects_onHit != null) {
ItemTraits_OnUse[] effects_ = new ItemTraits_OnUse[effects_onHit.size()];
effects_ = effects_onHit.toArray(effects_);
player.onHitEffects = effects_;
} else {
player.onHitEffects = null;
}
if (effects_onHitReceived != null) {
ItemTraits_OnHitReceived[] effects_ = new ItemTraits_OnHitReceived[effects_onHitReceived.size()];
effects_ = effects_onHitReceived.toArray(effects_);
player.onHitReceivedEffects = effects_;
} else {
player.onHitReceivedEffects = null;
}
}
public void consumeNonItemLoot(Loot loot) {
// Experience will be given as soon as the monster is killed.
world.model.player.inventory.gold += loot.gold;
loot.gold = 0;
removeLootBagIfEmpty(loot);
}
public void consumeNonItemLoot(Iterable<Loot> lootBags) {
for(Loot l : lootBags) {
consumeNonItemLoot(l);
}
}
public void pickupAll(Loot loot) {
world.model.player.inventory.add(loot.items);
consumeNonItemLoot(loot);
checkQuickslotItemLooted(loot.items);
loot.clear();
}
public void pickupAll(Iterable<Loot> lootBags) {
for(Loot l : lootBags) {
pickupAll(l);
}
}
public boolean removeLootBagIfEmpty(final Loot loot) {
if (loot.hasItemsOrGold()) return false;
world.model.currentMaps.map.removeGroundLoot(loot);
controllers.mapController.mapLayoutListeners.onLootBagRemoved(world.model.currentMaps.map, loot.position);
return true; // The bag was removed.
}
public boolean removeLootBagIfEmpty(final Iterable<Loot> lootBags) {
boolean isEmpty = true;
for (Loot l : lootBags) {
if (!removeLootBagIfEmpty(l)) isEmpty = false;
}
return isEmpty;
}
private static int getMarketPriceFactor(Player player) {
return Constants.MARKET_PRICEFACTOR_PERCENT
- player.getSkillLevel(SkillCollection.SkillID.barter) * SkillCollection.PER_SKILLPOINT_INCREASE_BARTER_PRICEFACTOR_PERCENTAGE;
}
public static int getBuyingPrice(Player player, ItemType itemType) {
return itemType.baseMarketCost + itemType.baseMarketCost * getMarketPriceFactor(player) / 100;
}
public static int getSellingPrice(Player player, ItemType itemType) {
return itemType.baseMarketCost - itemType.baseMarketCost * getMarketPriceFactor(player) / 100;
}
public static boolean canAfford(Player player, ItemType itemType) {
return player.inventory.gold >= getBuyingPrice(player, itemType);
}
public static boolean canAfford(Player player, int price) {
return player.inventory.gold >= price;
}
public static boolean maySellItem(Player player, ItemType itemType) {
if (!itemType.isSellable()) return false;
return true;
}
public static boolean sell(Player player, ItemType itemType, ItemContainer merchant, int quantity) {
int price = getSellingPrice(player, 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 boolean buy(ModelContainer model, Player player, ItemType itemType, ItemContainer merchant, int quantity) {
int price = getBuyingPrice(player, itemType) * quantity;
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;
}
public static String describeItemForListView(ItemEntry item, Player player) {
StringBuilder sb = new StringBuilder(item.itemType.getName(player));
if (item.quantity > 1) {
sb.append(" (");
sb.append(item.quantity);
sb.append(')');
}
if (item.itemType.effects_equip != null) {
AbilityModifierTraits t = item.itemType.effects_equip.stats;
if (t != null) {
if (t.increaseAttackChance != 0
|| t.increaseMinDamage != 0
|| t.increaseMaxDamage != 0
|| t.increaseCriticalSkill != 0
|| t.setCriticalMultiplier != 0) {
sb.append(" [");
describeAttackEffect(t.increaseAttackChance, t.increaseMinDamage, t.increaseMaxDamage, t.increaseCriticalSkill, t.setCriticalMultiplier, sb);
sb.append(']');
}
if (t.increaseBlockChance != 0
|| t.increaseDamageResistance != 0) {
sb.append(" [");
describeBlockEffect(t.increaseBlockChance, t.increaseDamageResistance, sb);
sb.append(']');
}
}
}
return sb.toString();
}
public static void describeAttackEffect(int attackChance, int minDamage, int maxDamage, int criticalSkill, float criticalMultiplier, StringBuilder sb) {
boolean addSpace = false;
if (attackChance != 0) {
sb.append(attackChance);
addSpace = true;
}
if (minDamage != 0 || maxDamage != 0) {
if (addSpace) sb.append(' ');
sb.append(minDamage);
if (minDamage != maxDamage) {
sb.append('-');
sb.append(maxDamage);
}
addSpace = true;
}
if (criticalSkill != 0) {
if (addSpace) sb.append(' ');
if (criticalSkill >= 0) {
sb.append('+');
}
sb.append(criticalSkill);
}
if (criticalMultiplier != 0 && criticalMultiplier != 1) {
sb.append('x');
sb.append(criticalMultiplier);
}
}
public static void describeBlockEffect(int blockChance, int damageResistance, StringBuilder sb) {
if (blockChance != 0) {
sb.append(blockChance);
}
if (damageResistance != 0) {
sb.append('/');
sb.append(damageResistance);
}
}
public void quickitemUse(int quickSlotId) {
useItem(world.model.player.inventory.quickitem[quickSlotId]);
quickSlotListeners.onQuickSlotUsed(quickSlotId);
}
public void setQuickItem(ItemType itemType, int quickSlotId) {
world.model.player.inventory.quickitem[quickSlotId] = itemType;
quickSlotListeners.onQuickSlotChanged(quickSlotId);
}
private void checkQuickslotItemLooted(ItemContainer items) {
for (ItemEntry item : items.items) {
if (item.itemType.isUsable()) {
for (int i = 0; i < world.model.player.inventory.quickitem.length; i++) {
if (item.itemType == world.model.player.inventory.quickitem[i]) {
quickSlotListeners.onQuickSlotChanged(i);
}
}
}
}
}
public int removeEquippedItem(String itemTypeID, int count) {
int removed = 0;
final Player player = world.model.player;
for (Inventory.WearSlot slot : Inventory.WearSlot.values()) {
ItemType type = player.inventory.getItemTypeInWearSlot(slot);
if (type != null && type.id.equals(itemTypeID)) {
player.inventory.setItemTypeInWearSlot(slot, null);
controllers.actorStatsController.removeConditionsFromUnequippedItem(player, type);
controllers.actorStatsController.recalculatePlayerStats(player);
removed++;
if (removed >= count) {
break;
}
}
}
return removed;
}
public static void applyDamageModifier(Player player) {
ItemType itemType = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.weapon);
int modifier1 = -1;
int modifier2 = -1;
if (itemType != null) modifier1 = itemType.effects_equip.stats.setNonWeaponDamageModifier;
itemType = player.inventory.getItemTypeInWearSlot(Inventory.WearSlot.shield);
if (itemType != null && itemType.isWeapon()) modifier2 = itemType.effects_equip.stats.setNonWeaponDamageModifier;
int modifier = 100;
if (modifier1 >= 0 && modifier2 >= 0) {
int skillLevelFightStyle = player.getSkillLevel(SkillCollection.SkillID.fightstyleDualWield);
if (skillLevelFightStyle == 2) {
modifier = Math.max(modifier1, modifier2);
} else if (skillLevelFightStyle == 1) {
modifier = (modifier1 + modifier2) / 2;
} else {
modifier = Math.min(modifier1, modifier2);
}
}
else if (modifier1 <= 0 && modifier2 >= 0) modifier = modifier2;
else if (modifier2 <= 0 && modifier1 >= 0) modifier = modifier1;
if (modifier != 100) {
final int minBaseDamage = player.damagePotential.current - player.weaponDamage.current;
final int maxBaseDamage = player.damagePotential.max - player.weaponDamage.max;
player.damagePotential.add(Math.round(minBaseDamage * ((modifier - 100)/100f)), true);
player.damagePotential.addToMax(Math.round(maxBaseDamage * ((modifier - 100)/100f)));
}
}
}

View File

@@ -1,23 +1,23 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import java.util.List;
import android.content.res.Resources;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.listeners.MapLayoutListeners;
import com.gpl.rpg.AndorsTrail.controller.listeners.WorldEventListeners;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.conversation.Reply;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.model.map.ReplaceableMapSection;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.MapLayoutListeners;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.WorldEventListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.conversation.Reply;
import com.gpl.rpg.AndorsTrail_beta1.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapObject;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.ReplaceableMapSection;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
public final class MapController {

View File

@@ -1,18 +1,18 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.PathFinder.EvaluateWalkable;
import com.gpl.rpg.AndorsTrail.controller.listeners.MonsterMovementListeners;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.MonsterType;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.PathFinder.EvaluateWalkable;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.MonsterMovementListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.MonsterType;
import com.gpl.rpg.AndorsTrail_beta1.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapObject;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
public final class MonsterMovementController implements EvaluateWalkable {
private final ControllerContext controllers;

View File

@@ -1,16 +1,16 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.listeners.MonsterSpawnListeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.MonsterType;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail.util.Size;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.MonsterSpawnListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.MonsterType;
import com.gpl.rpg.AndorsTrail_beta1.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.util.Size;
public final class MonsterSpawningController {
private final ControllerContext controllers;

View File

@@ -1,26 +1,26 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import android.content.res.Resources;
import android.os.AsyncTask;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.listeners.PlayerMovementListeners;
import com.gpl.rpg.AndorsTrail.model.MapBundle;
import com.gpl.rpg.AndorsTrail.model.ModelContainer;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.Loot;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.MapObject;
import com.gpl.rpg.AndorsTrail.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.model.map.TMXMapTranslator;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.L;
import com.gpl.rpg.AndorsTrail.util.TimedMessageTask;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.PlayerMovementListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.MapBundle;
import com.gpl.rpg.AndorsTrail_beta1.model.ModelContainer;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Loot;
import com.gpl.rpg.AndorsTrail_beta1.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapObject;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MonsterSpawnArea;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.TMXMapTranslator;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.L;
import com.gpl.rpg.AndorsTrail_beta1.util.TimedMessageTask;
public final class MovementController implements TimedMessageTask.Callback {
private final ControllerContext controllers;

View File

@@ -1,10 +1,10 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import java.util.Arrays;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
public class PathFinder {
private final int maxWidth;

View File

@@ -1,22 +1,22 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.listeners.CombatActionListeners;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail.model.ability.SkillCollection.SkillID;
import com.gpl.rpg.AndorsTrail.model.ability.SkillInfo;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.model.item.DropList.DropItem;
import com.gpl.rpg.AndorsTrail.model.item.Inventory;
import com.gpl.rpg.AndorsTrail.model.item.ItemCategory;
import com.gpl.rpg.AndorsTrail.model.item.ItemType;
import com.gpl.rpg.AndorsTrail.model.item.ItemTypeCollection;
import com.gpl.rpg.AndorsTrail.util.ConstRange;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.CombatActionListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionType;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillCollection.SkillID;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.SkillInfo;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.item.DropList.DropItem;
import com.gpl.rpg.AndorsTrail_beta1.model.item.Inventory;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemCategory;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemType;
import com.gpl.rpg.AndorsTrail_beta1.model.item.ItemTypeCollection;
import com.gpl.rpg.AndorsTrail_beta1.util.ConstRange;
public final class SkillController {
private final ControllerContext controllers;

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.controller;
package com.gpl.rpg.AndorsTrail_beta1.controller;
import android.graphics.Color;
import android.graphics.Paint;
@@ -6,20 +6,20 @@ import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.os.Handler;
import com.gpl.rpg.AndorsTrail.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail.context.ControllerContext;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.controller.listeners.VisualEffectFrameListeners;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.actor.MonsterType;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.resource.VisualEffectCollection;
import com.gpl.rpg.AndorsTrail.resource.VisualEffectCollection.VisualEffect;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail.util.Size;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailPreferences;
import com.gpl.rpg.AndorsTrail_beta1.context.ControllerContext;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.controller.listeners.VisualEffectFrameListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.MonsterType;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.resource.VisualEffectCollection;
import com.gpl.rpg.AndorsTrail_beta1.resource.VisualEffectCollection.VisualEffect;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileManager;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.util.Size;
public final class VisualEffectController {
private int effectCount = 0;

View File

@@ -1,317 +1,317 @@
package com.gpl.rpg.AndorsTrail.controller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail.R;
import com.gpl.rpg.AndorsTrail.activity.DisplayWorldMapActivity;
import com.gpl.rpg.AndorsTrail.context.WorldContext;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.MapLayer;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.model.map.WorldMapSegment;
import com.gpl.rpg.AndorsTrail.model.map.WorldMapSegment.NamedWorldMapArea;
import com.gpl.rpg.AndorsTrail.model.map.WorldMapSegment.WorldMapSegmentMap;
import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail.util.AndroidStorage;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail.util.L;
import com.gpl.rpg.AndorsTrail.util.Size;
public final class WorldMapController {
private static final int WORLDMAP_SCREENSHOT_TILESIZE = 8;
public static final int WORLDMAP_DISPLAY_TILESIZE = WORLDMAP_SCREENSHOT_TILESIZE;
public static void updateWorldMap(Context context, final WorldContext world, final Resources res) {
updateWorldMap(context, world, world.model.currentMaps.map, world.model.currentMaps.tileMap, world.model.currentMaps.tiles, res);
}
private static void updateWorldMap(
Context context, final WorldContext world,
final PredefinedMap map,
final LayeredTileMap mapTiles,
final TileCollection cachedTiles,
final Resources res) {
final String worldMapSegmentName = world.maps.getWorldMapSegmentNameForMap(map.name);
if (worldMapSegmentName == null) return;
if (!shouldUpdateWorldMap(context, map, worldMapSegmentName, world.maps.worldMapRequiresUpdate)) return;
(new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... arg0) {
final MapRenderer renderer = new MapRenderer(world, map, mapTiles, cachedTiles);
try {
updateCachedBitmap(context, map, renderer);
updateWorldMapSegment(context, res, world, worldMapSegmentName);
world.maps.worldMapRequiresUpdate = false;
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) {
L.log("WorldMapController: Updated worldmap segment " + worldMapSegmentName + " for map " + map.name);
}
} catch (IOException e) {
L.log("Error creating worldmap file for map " + map.name + " : " + e.toString());
}
return null;
}
}).execute();
}
private static boolean shouldUpdateWorldMap(Context context, PredefinedMap map, String worldMapSegmentName, boolean forceUpdate) {
if (forceUpdate) return true;
if (!map.visited) return true;
File file = getFileForMap(context, map, false);
if (!file.exists()) return true;
file = getCombinedWorldMapFile(context, worldMapSegmentName);
if (!file.exists()) return true;
return false;
}
private static void updateCachedBitmap(Context context, PredefinedMap map, MapRenderer renderer) throws IOException {
ensureWorldmapDirectoryExists(context);
File file = getFileForMap(context, map, false);
if (file.exists()) return;
Bitmap image = renderer.drawMap();
FileOutputStream fos = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.PNG, 70, fos);
fos.flush();
fos.close();
image.recycle();
L.log("WorldMapController: Wrote " + file.getAbsolutePath());
}
private static final class MapRenderer {
private final PredefinedMap map;
private final LayeredTileMap mapTiles;
private final TileCollection cachedTiles;
private final int tileSize;
private final float scale;
private final Paint mPaint = new Paint();
public MapRenderer(final WorldContext world, final PredefinedMap map, final LayeredTileMap mapTiles, final TileCollection cachedTiles) {
this.map = map;
this.mapTiles = mapTiles;
this.cachedTiles = cachedTiles;
this.tileSize = world.tileManager.tileSize;
this.scale = (float) WORLDMAP_SCREENSHOT_TILESIZE / world.tileManager.tileSize;
mapTiles.setColorFilter(mPaint, null, true);
}
public Bitmap drawMap() {
Bitmap image = Bitmap.createBitmap(map.size.width * WORLDMAP_SCREENSHOT_TILESIZE, map.size.height * WORLDMAP_SCREENSHOT_TILESIZE, Config.RGB_565);
image.setDensity(Bitmap.DENSITY_NONE);
Canvas canvas = new Canvas(image);
canvas.scale(scale, scale);
synchronized (cachedTiles) {
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerBase);
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerGround);
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerObjects);
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerAbove);
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerTop);
}
return image;
}
private void tryDrawMapLayer(Canvas canvas, final MapLayer layer) {
if (layer != null) drawMapLayer(canvas, layer);
}
private void drawMapLayer(Canvas canvas, final MapLayer layer) {
int py = 0;
for (int y = 0; y < map.size.height; ++y, py += tileSize) {
int px = 0;
for (int x = 0; x < map.size.width; ++x, px += tileSize) {
final int tile = layer.tiles[x][y];
if (tile == 0) continue;
cachedTiles.drawTile(canvas, tile, px, py, mPaint);
}
}
}
}
private static void ensureWorldmapDirectoryExists(Context context) throws IOException {
File dir = AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
if (!dir.exists()) dir.mkdir();
dir = new File(dir, Constants.FILENAME_WORLDMAP_DIRECTORY);
if (!dir.exists()) dir.mkdir();
File noMediaFile = new File(dir, ".nomedia");
if (!noMediaFile.exists()) noMediaFile.createNewFile();
}
public static boolean fileForMapExists(Context context, PredefinedMap map) {
if (map.lastSeenLayoutHash.length() > 0) {
return getPngFile(context, map.name + '.' + map.lastSeenLayoutHash).exists();
}
return getPngFile(context, map.name).exists();
}
private static File getFileForMap(Context context, PredefinedMap map, boolean verifyFileExists) {
if (map.lastSeenLayoutHash.length() > 0) {
File fileWithHash = getPngFile(context, map.name + '.' + map.lastSeenLayoutHash);
if (!verifyFileExists) return fileWithHash;
else if (fileWithHash.exists()) return fileWithHash;
}
return getPngFile(context, map.name);
}
private static File getPngFile(Context context, String fileName) {
return new File(getWorldmapDirectory(context), fileName + ".png");
}
private static File getWorldmapDirectory(Context context) {
File dir = AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
return new File(dir, Constants.FILENAME_WORLDMAP_DIRECTORY);
}
public static File getCombinedWorldMapFile(Context context, String segmentName) {
return new File(getWorldmapDirectory(context), Constants.FILENAME_WORLDMAP_HTMLFILE_PREFIX + segmentName + Constants.FILENAME_WORLDMAP_HTMLFILE_SUFFIX);
}
private static String getWorldMapSegmentAsHtml(Context context, Resources res, WorldContext world, String segmentName) {
WorldMapSegment segment = world.maps.worldMapSegments.get(segmentName);
Map<String, File> displayedMapFilenamesPerMapName = new HashMap<String, File>(segment.maps.size());
Coord offsetWorldmapTo = new Coord(999999, 999999);
for (WorldMapSegmentMap map : segment.maps.values()) {
PredefinedMap predefinedMap = world.maps.findPredefinedMap(map.mapName);
if (predefinedMap == null) continue;
if (!predefinedMap.visited) continue;
File f = WorldMapController.getFileForMap(context, predefinedMap, true);
if (!f.exists()) continue;
displayedMapFilenamesPerMapName.put(map.mapName, f);
offsetWorldmapTo.x = Math.min(offsetWorldmapTo.x, map.worldPosition.x);
offsetWorldmapTo.y = Math.min(offsetWorldmapTo.y, map.worldPosition.y);
}
Coord bottomRight = new Coord(0, 0);
StringBuilder mapsAsHtml = new StringBuilder(1000);
for (WorldMapSegmentMap segmentMap : segment.maps.values()) {
File f = displayedMapFilenamesPerMapName.get(segmentMap.mapName);
if (f == null) continue;
Size size = getMapSize(segmentMap, world);
mapsAsHtml
.append("<img src=\"")
.append(f.getName())
.append("\" id=\"")
.append(segmentMap.mapName)
.append("\" style=\"width:")
.append(size.width * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; height:")
.append(size.height * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; left:")
.append((segmentMap.worldPosition.x - offsetWorldmapTo.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; top:")
.append((segmentMap.worldPosition.y - offsetWorldmapTo.y) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px;\" />");
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) mapsAsHtml.append('\n');
bottomRight.x = Math.max(bottomRight.x, segmentMap.worldPosition.x + size.width);
bottomRight.y = Math.max(bottomRight.y, segmentMap.worldPosition.y + size.height);
}
Size worldmapSegmentSize = new Size(
(bottomRight.x - offsetWorldmapTo.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE
,(bottomRight.y - offsetWorldmapTo.y) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE
);
StringBuilder namedAreasAsHtml = new StringBuilder(500);
for (NamedWorldMapArea area : segment.namedAreas.values()) {
CoordRect r = determineNamedAreaBoundary(area, segment, world, displayedMapFilenamesPerMapName.keySet());
if (r == null) continue;
namedAreasAsHtml
.append("<div class=\"namedarea ")
.append(area.type)
.append("\" style=\"width:")
.append(r.size.width * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; line-height:")
.append(r.size.height * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; left:")
.append((r.topLeft.x - offsetWorldmapTo.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; top:")
.append((r.topLeft.y - offsetWorldmapTo.y) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px;\"><span>")
.append(area.name)
.append("</span></div>");
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) namedAreasAsHtml.append('\n');
}
return res.getString(R.string.worldmap_template)
.replace("{{maps}}", mapsAsHtml.toString())
.replace("{{areas}}", namedAreasAsHtml.toString())
.replace("{{sizex}}", Integer.toString(worldmapSegmentSize.width))
.replace("{{sizey}}", Integer.toString(worldmapSegmentSize.height))
.replace("{{offsetx}}", Integer.toString(offsetWorldmapTo.x * WorldMapController.WORLDMAP_DISPLAY_TILESIZE))
.replace("{{offsety}}", Integer.toString(offsetWorldmapTo.y * WorldMapController.WORLDMAP_DISPLAY_TILESIZE));
}
private static Size getMapSize(WorldMapSegmentMap map, WorldContext world) {
return world.maps.findPredefinedMap(map.mapName).size;
}
private static CoordRect determineNamedAreaBoundary(NamedWorldMapArea area, WorldMapSegment segment, WorldContext world, Set<String> displayedMapNames) {
Coord topLeft = null;
Coord bottomRight = null;
for (String mapName : area.mapNames) {
if (!displayedMapNames.contains(mapName)) continue;
WorldMapSegmentMap map = segment.maps.get(mapName);
Size size = getMapSize(map, world);
if (topLeft == null) {
topLeft = new Coord(map.worldPosition);
} else {
topLeft.x = Math.min(topLeft.x, map.worldPosition.x);
topLeft.y = Math.min(topLeft.y, map.worldPosition.y);
}
if (bottomRight == null) {
bottomRight = new Coord(map.worldPosition.x + size.width, map.worldPosition.y + size.height);
} else {
bottomRight.x = Math.max(bottomRight.x, map.worldPosition.x + size.width);
bottomRight.y = Math.max(bottomRight.y, map.worldPosition.y + size.height);
}
}
if (topLeft == null) return null;
return new CoordRect(topLeft, new Size(bottomRight.x - topLeft.x, bottomRight.y - topLeft.y));
}
public static void updateWorldMapSegment(Context context, Resources res, WorldContext world, String segmentName) throws IOException {
String mapAsHtml = getWorldMapSegmentAsHtml(context, res, world, segmentName);
File outputFile = getCombinedWorldMapFile(context, segmentName);
PrintWriter pw = new PrintWriter(outputFile);
pw.write(mapAsHtml);
pw.close();
}
public static boolean displayWorldMap(Context context, WorldContext world) {
String worldMapSegmentName = world.maps.getWorldMapSegmentNameForMap(world.model.currentMaps.map.name);
if (worldMapSegmentName == null) {
Toast.makeText(context, context.getResources().getString(R.string.display_worldmap_not_available), Toast.LENGTH_LONG).show();
return false;
}
Intent intent = new Intent(context, DisplayWorldMapActivity.class);
intent.putExtra("worldMapSegmentName", worldMapSegmentName);
context.startActivity(intent);
return true;
}
}
package com.gpl.rpg.AndorsTrail_beta1.controller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.widget.Toast;
import com.gpl.rpg.AndorsTrail_beta1.AndorsTrailApplication;
import com.gpl.rpg.AndorsTrail_beta1.R;
import com.gpl.rpg.AndorsTrail_beta1.activity.DisplayWorldMapActivity;
import com.gpl.rpg.AndorsTrail_beta1.context.WorldContext;
import com.gpl.rpg.AndorsTrail_beta1.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.MapLayer;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.WorldMapSegment;
import com.gpl.rpg.AndorsTrail_beta1.model.map.WorldMapSegment.NamedWorldMapArea;
import com.gpl.rpg.AndorsTrail_beta1.model.map.WorldMapSegment.WorldMapSegmentMap;
import com.gpl.rpg.AndorsTrail_beta1.resource.tiles.TileCollection;
import com.gpl.rpg.AndorsTrail_beta1.util.AndroidStorage;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.util.L;
import com.gpl.rpg.AndorsTrail_beta1.util.Size;
public final class WorldMapController {
private static final int WORLDMAP_SCREENSHOT_TILESIZE = 8;
public static final int WORLDMAP_DISPLAY_TILESIZE = WORLDMAP_SCREENSHOT_TILESIZE;
public static void updateWorldMap(Context context, final WorldContext world, final Resources res) {
updateWorldMap(context, world, world.model.currentMaps.map, world.model.currentMaps.tileMap, world.model.currentMaps.tiles, res);
}
private static void updateWorldMap(
Context context, final WorldContext world,
final PredefinedMap map,
final LayeredTileMap mapTiles,
final TileCollection cachedTiles,
final Resources res) {
final String worldMapSegmentName = world.maps.getWorldMapSegmentNameForMap(map.name);
if (worldMapSegmentName == null) return;
if (!shouldUpdateWorldMap(context, map, worldMapSegmentName, world.maps.worldMapRequiresUpdate)) return;
(new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... arg0) {
final MapRenderer renderer = new MapRenderer(world, map, mapTiles, cachedTiles);
try {
updateCachedBitmap(context, map, renderer);
updateWorldMapSegment(context, res, world, worldMapSegmentName);
world.maps.worldMapRequiresUpdate = false;
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) {
L.log("WorldMapController: Updated worldmap segment " + worldMapSegmentName + " for map " + map.name);
}
} catch (IOException e) {
L.log("Error creating worldmap file for map " + map.name + " : " + e.toString());
}
return null;
}
}).execute();
}
private static boolean shouldUpdateWorldMap(Context context, PredefinedMap map, String worldMapSegmentName, boolean forceUpdate) {
if (forceUpdate) return true;
if (!map.visited) return true;
File file = getFileForMap(context, map, false);
if (!file.exists()) return true;
file = getCombinedWorldMapFile(context, worldMapSegmentName);
if (!file.exists()) return true;
return false;
}
private static void updateCachedBitmap(Context context, PredefinedMap map, MapRenderer renderer) throws IOException {
ensureWorldmapDirectoryExists(context);
File file = getFileForMap(context, map, false);
if (file.exists()) return;
Bitmap image = renderer.drawMap();
FileOutputStream fos = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.PNG, 70, fos);
fos.flush();
fos.close();
image.recycle();
L.log("WorldMapController: Wrote " + file.getAbsolutePath());
}
private static final class MapRenderer {
private final PredefinedMap map;
private final LayeredTileMap mapTiles;
private final TileCollection cachedTiles;
private final int tileSize;
private final float scale;
private final Paint mPaint = new Paint();
public MapRenderer(final WorldContext world, final PredefinedMap map, final LayeredTileMap mapTiles, final TileCollection cachedTiles) {
this.map = map;
this.mapTiles = mapTiles;
this.cachedTiles = cachedTiles;
this.tileSize = world.tileManager.tileSize;
this.scale = (float) WORLDMAP_SCREENSHOT_TILESIZE / world.tileManager.tileSize;
mapTiles.setColorFilter(mPaint, null, true);
}
public Bitmap drawMap() {
Bitmap image = Bitmap.createBitmap(map.size.width * WORLDMAP_SCREENSHOT_TILESIZE, map.size.height * WORLDMAP_SCREENSHOT_TILESIZE, Config.RGB_565);
image.setDensity(Bitmap.DENSITY_NONE);
Canvas canvas = new Canvas(image);
canvas.scale(scale, scale);
synchronized (cachedTiles) {
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerBase);
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerGround);
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerObjects);
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerAbove);
tryDrawMapLayer(canvas, mapTiles.currentLayout.layerTop);
}
return image;
}
private void tryDrawMapLayer(Canvas canvas, final MapLayer layer) {
if (layer != null) drawMapLayer(canvas, layer);
}
private void drawMapLayer(Canvas canvas, final MapLayer layer) {
int py = 0;
for (int y = 0; y < map.size.height; ++y, py += tileSize) {
int px = 0;
for (int x = 0; x < map.size.width; ++x, px += tileSize) {
final int tile = layer.tiles[x][y];
if (tile == 0) continue;
cachedTiles.drawTile(canvas, tile, px, py, mPaint);
}
}
}
}
private static void ensureWorldmapDirectoryExists(Context context) throws IOException {
File dir = AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
if (!dir.exists()) dir.mkdir();
dir = new File(dir, Constants.FILENAME_WORLDMAP_DIRECTORY);
if (!dir.exists()) dir.mkdir();
File noMediaFile = new File(dir, ".nomedia");
if (!noMediaFile.exists()) noMediaFile.createNewFile();
}
public static boolean fileForMapExists(Context context, PredefinedMap map) {
if (map.lastSeenLayoutHash.length() > 0) {
return getPngFile(context, map.name + '.' + map.lastSeenLayoutHash).exists();
}
return getPngFile(context, map.name).exists();
}
private static File getFileForMap(Context context, PredefinedMap map, boolean verifyFileExists) {
if (map.lastSeenLayoutHash.length() > 0) {
File fileWithHash = getPngFile(context, map.name + '.' + map.lastSeenLayoutHash);
if (!verifyFileExists) return fileWithHash;
else if (fileWithHash.exists()) return fileWithHash;
}
return getPngFile(context, map.name);
}
private static File getPngFile(Context context, String fileName) {
return new File(getWorldmapDirectory(context), fileName + ".png");
}
private static File getWorldmapDirectory(Context context) {
File dir = AndroidStorage.getStorageDirectory(context, Constants.FILENAME_SAVEGAME_DIRECTORY);
return new File(dir, Constants.FILENAME_WORLDMAP_DIRECTORY);
}
public static File getCombinedWorldMapFile(Context context, String segmentName) {
return new File(getWorldmapDirectory(context), Constants.FILENAME_WORLDMAP_HTMLFILE_PREFIX + segmentName + Constants.FILENAME_WORLDMAP_HTMLFILE_SUFFIX);
}
private static String getWorldMapSegmentAsHtml(Context context, Resources res, WorldContext world, String segmentName) {
WorldMapSegment segment = world.maps.worldMapSegments.get(segmentName);
Map<String, File> displayedMapFilenamesPerMapName = new HashMap<String, File>(segment.maps.size());
Coord offsetWorldmapTo = new Coord(999999, 999999);
for (WorldMapSegmentMap map : segment.maps.values()) {
PredefinedMap predefinedMap = world.maps.findPredefinedMap(map.mapName);
if (predefinedMap == null) continue;
if (!predefinedMap.visited) continue;
File f = WorldMapController.getFileForMap(context, predefinedMap, true);
if (!f.exists()) continue;
displayedMapFilenamesPerMapName.put(map.mapName, f);
offsetWorldmapTo.x = Math.min(offsetWorldmapTo.x, map.worldPosition.x);
offsetWorldmapTo.y = Math.min(offsetWorldmapTo.y, map.worldPosition.y);
}
Coord bottomRight = new Coord(0, 0);
StringBuilder mapsAsHtml = new StringBuilder(1000);
for (WorldMapSegmentMap segmentMap : segment.maps.values()) {
File f = displayedMapFilenamesPerMapName.get(segmentMap.mapName);
if (f == null) continue;
Size size = getMapSize(segmentMap, world);
mapsAsHtml
.append("<img src=\"")
.append(f.getName())
.append("\" id=\"")
.append(segmentMap.mapName)
.append("\" style=\"width:")
.append(size.width * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; height:")
.append(size.height * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; left:")
.append((segmentMap.worldPosition.x - offsetWorldmapTo.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; top:")
.append((segmentMap.worldPosition.y - offsetWorldmapTo.y) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px;\" />");
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) mapsAsHtml.append('\n');
bottomRight.x = Math.max(bottomRight.x, segmentMap.worldPosition.x + size.width);
bottomRight.y = Math.max(bottomRight.y, segmentMap.worldPosition.y + size.height);
}
Size worldmapSegmentSize = new Size(
(bottomRight.x - offsetWorldmapTo.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE
,(bottomRight.y - offsetWorldmapTo.y) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE
);
StringBuilder namedAreasAsHtml = new StringBuilder(500);
for (NamedWorldMapArea area : segment.namedAreas.values()) {
CoordRect r = determineNamedAreaBoundary(area, segment, world, displayedMapFilenamesPerMapName.keySet());
if (r == null) continue;
namedAreasAsHtml
.append("<div class=\"namedarea ")
.append(area.type)
.append("\" style=\"width:")
.append(r.size.width * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; line-height:")
.append(r.size.height * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; left:")
.append((r.topLeft.x - offsetWorldmapTo.x) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px; top:")
.append((r.topLeft.y - offsetWorldmapTo.y) * WorldMapController.WORLDMAP_DISPLAY_TILESIZE)
.append("px;\"><span>")
.append(area.name)
.append("</span></div>");
if (AndorsTrailApplication.DEVELOPMENT_DEBUGMESSAGES) namedAreasAsHtml.append('\n');
}
return res.getString(R.string.worldmap_template)
.replace("{{maps}}", mapsAsHtml.toString())
.replace("{{areas}}", namedAreasAsHtml.toString())
.replace("{{sizex}}", Integer.toString(worldmapSegmentSize.width))
.replace("{{sizey}}", Integer.toString(worldmapSegmentSize.height))
.replace("{{offsetx}}", Integer.toString(offsetWorldmapTo.x * WorldMapController.WORLDMAP_DISPLAY_TILESIZE))
.replace("{{offsety}}", Integer.toString(offsetWorldmapTo.y * WorldMapController.WORLDMAP_DISPLAY_TILESIZE));
}
private static Size getMapSize(WorldMapSegmentMap map, WorldContext world) {
return world.maps.findPredefinedMap(map.mapName).size;
}
private static CoordRect determineNamedAreaBoundary(NamedWorldMapArea area, WorldMapSegment segment, WorldContext world, Set<String> displayedMapNames) {
Coord topLeft = null;
Coord bottomRight = null;
for (String mapName : area.mapNames) {
if (!displayedMapNames.contains(mapName)) continue;
WorldMapSegmentMap map = segment.maps.get(mapName);
Size size = getMapSize(map, world);
if (topLeft == null) {
topLeft = new Coord(map.worldPosition);
} else {
topLeft.x = Math.min(topLeft.x, map.worldPosition.x);
topLeft.y = Math.min(topLeft.y, map.worldPosition.y);
}
if (bottomRight == null) {
bottomRight = new Coord(map.worldPosition.x + size.width, map.worldPosition.y + size.height);
} else {
bottomRight.x = Math.max(bottomRight.x, map.worldPosition.x + size.width);
bottomRight.y = Math.max(bottomRight.y, map.worldPosition.y + size.height);
}
}
if (topLeft == null) return null;
return new CoordRect(topLeft, new Size(bottomRight.x - topLeft.x, bottomRight.y - topLeft.y));
}
public static void updateWorldMapSegment(Context context, Resources res, WorldContext world, String segmentName) throws IOException {
String mapAsHtml = getWorldMapSegmentAsHtml(context, res, world, segmentName);
File outputFile = getCombinedWorldMapFile(context, segmentName);
PrintWriter pw = new PrintWriter(outputFile);
pw.write(mapAsHtml);
pw.close();
}
public static boolean displayWorldMap(Context context, WorldContext world) {
String worldMapSegmentName = world.maps.getWorldMapSegmentNameForMap(world.model.currentMaps.map.name);
if (worldMapSegmentName == null) {
Toast.makeText(context, context.getResources().getString(R.string.display_worldmap_not_available), Toast.LENGTH_LONG).show();
return false;
}
Intent intent = new Intent(context, DisplayWorldMapActivity.class);
intent.putExtra("worldMapSegmentName", worldMapSegmentName);
context.startActivity(intent);
return true;
}
}

View File

@@ -1,7 +1,7 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
public interface ActorConditionListener {
public void onActorConditionAdded(Actor actor, ActorCondition condition);

View File

@@ -1,8 +1,8 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorCondition;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class ActorConditionListeners extends ListOfListeners<ActorConditionListener> implements ActorConditionListener {

View File

@@ -1,7 +1,7 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
public interface ActorStatsListener {
void onActorHealthChanged(Actor actor);

View File

@@ -1,8 +1,8 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Actor;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class ActorStatsListeners extends ListOfListeners<ActorStatsListener> implements ActorStatsListener {

View File

@@ -1,8 +1,8 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.controller.AttackResult;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.controller.AttackResult;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
public interface CombatActionListener {
void onPlayerAttackMissed(Monster target, AttackResult attackResult);

View File

@@ -1,9 +1,9 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.controller.AttackResult;
import com.gpl.rpg.AndorsTrail.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.controller.AttackResult;
import com.gpl.rpg.AndorsTrail_beta1.model.ability.ActorConditionEffect;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class CombatActionListeners extends ListOfListeners<CombatActionListener> implements CombatActionListener {

View File

@@ -1,7 +1,7 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
public interface CombatSelectionListener {
void onMonsterSelected(Monster m, Coord selectedPosition, Coord previousSelection);

View File

@@ -1,8 +1,8 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class CombatSelectionListeners extends ListOfListeners<CombatSelectionListener> implements CombatSelectionListener {

View File

@@ -1,6 +1,6 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
public interface CombatTurnListener {
void onCombatStarted();

View File

@@ -1,7 +1,7 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class CombatTurnListeners extends ListOfListeners<CombatTurnListener> implements CombatTurnListener {

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
public interface GameRoundListener {
void onNewTick();

View File

@@ -1,6 +1,6 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class GameRoundListeners extends ListOfListeners<GameRoundListener> implements GameRoundListener {

View File

@@ -0,0 +1,11 @@
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail_beta1.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
public interface MapLayoutListener {
void onLootBagCreated(PredefinedMap map, Coord p);
void onLootBagRemoved(PredefinedMap map, Coord p);
void onMapTilesChanged(PredefinedMap map, LayeredTileMap tileMap);
}

View File

@@ -1,9 +1,9 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.map.LayeredTileMap;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class MapLayoutListeners extends ListOfListeners<MapLayoutListener> implements MapLayoutListener {

View File

@@ -0,0 +1,10 @@
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
public interface MonsterMovementListener {
void onMonsterSteppedOnPlayer(Monster m);
void onMonsterMoved(PredefinedMap map, Monster m, CoordRect previousPosition);
}

View File

@@ -1,9 +1,9 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class MonsterMovementListeners extends ListOfListeners<MonsterMovementListener> implements MonsterMovementListener {

View File

@@ -1,9 +1,9 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
public interface MonsterSpawnListener {
void onMonsterSpawned(PredefinedMap map, Monster m);

View File

@@ -1,10 +1,10 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Monster;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Monster;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class MonsterSpawnListeners extends ListOfListeners<MonsterSpawnListener> implements MonsterSpawnListener {

View File

@@ -1,7 +1,7 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
public interface PlayerMovementListener {
void onPlayerMoved(PredefinedMap map, Coord newPosition, Coord previousPosition);

View File

@@ -1,8 +1,8 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail.util.Coord;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.map.PredefinedMap;
import com.gpl.rpg.AndorsTrail_beta1.util.Coord;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class PlayerMovementListeners extends ListOfListeners<PlayerMovementListener> implements PlayerMovementListener {

View File

@@ -0,0 +1,7 @@
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
public interface PlayerStatsListener {
void onPlayerExperienceChanged(Player p);
}

View File

@@ -1,7 +1,7 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.model.actor.Player;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.model.actor.Player;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class PlayerStatsListeners extends ListOfListeners<PlayerStatsListener> implements PlayerStatsListener {

View File

@@ -1,4 +1,4 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
public interface QuickSlotListener {
void onQuickSlotChanged(int slotId);

View File

@@ -1,6 +1,6 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.util.ListOfListeners;
import com.gpl.rpg.AndorsTrail_beta1.util.ListOfListeners;
public final class QuickSlotListeners extends ListOfListeners<QuickSlotListener> implements QuickSlotListener {

View File

@@ -1,8 +1,8 @@
package com.gpl.rpg.AndorsTrail.controller.listeners;
package com.gpl.rpg.AndorsTrail_beta1.controller.listeners;
import com.gpl.rpg.AndorsTrail.controller.VisualEffectController.SpriteMoveAnimation;
import com.gpl.rpg.AndorsTrail.controller.VisualEffectController.VisualEffectAnimation;
import com.gpl.rpg.AndorsTrail.util.CoordRect;
import com.gpl.rpg.AndorsTrail_beta1.controller.VisualEffectController.SpriteMoveAnimation;
import com.gpl.rpg.AndorsTrail_beta1.controller.VisualEffectController.VisualEffectAnimation;
import com.gpl.rpg.AndorsTrail_beta1.util.CoordRect;
public interface VisualEffectFrameListener {
void onNewAnimationFrame(VisualEffectAnimation animation, int tileID, int textYOffset);

Some files were not shown because too many files have changed in this diff Show More