Skip to content

Commit 05aaff1

Browse files
committed
1,悬浮窗增加记录双方墓地的功能。
1 parent f9f970d commit 05aaff1

File tree

7 files changed

+157
-40
lines changed

7 files changed

+157
-40
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
applicationId "com.ke.hs_tracker.app"
1414
minSdk libs.versions.minsdk.get().toInteger()
1515
targetSdk libs.versions.targetsdk.get().toInteger()
16-
versionCode 18
17-
versionName "1.1.8"
16+
versionCode 19
17+
versionName "1.1.9"
1818

1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020

module/src/main/java/com/ke/hs_tracker/module/entity/GameEvent.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.ke.hs_tracker.module.db.Game
77
*/
88
sealed interface GameEvent {
99

10-
object None : GameEvent
10+
1111

1212

1313
/**
@@ -36,4 +36,9 @@ sealed interface GameEvent {
3636
data class RemoveCardFromUserDeck(
3737
val cardId: String
3838
) : GameEvent
39+
40+
/**
41+
* 插入一张卡牌到墓地
42+
*/
43+
data class InsertCardToGraveyard(val cardId: String, val isUser: Boolean) : GameEvent
3944
}

module/src/main/java/com/ke/hs_tracker/module/parser/DeckCardObserver.kt

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ interface DeckCardObserver {
2525
*/
2626
val deckCardList: StateFlow<List<CardBean>>
2727

28+
/**
29+
* 自己的墓地
30+
*/
31+
val userGraveyardCardList: StateFlow<List<CardBean>>
32+
33+
/**
34+
* 对手的墓地
35+
*/
36+
val opponentGraveyardCardList: StateFlow<List<CardBean>>
37+
2838
/**
2939
* 初始化
3040
*/
@@ -59,6 +69,15 @@ class DeckCardObserverImpl @Inject constructor(
5969
override val deckCardList: StateFlow<List<CardBean>>
6070
get() = _deckCardList
6171

72+
private val _userGraveyardCardList = MutableStateFlow<List<CardBean>>(emptyList())
73+
74+
override val userGraveyardCardList: StateFlow<List<CardBean>>
75+
get() = _userGraveyardCardList
76+
77+
private val _opponentGraveyardCardList = MutableStateFlow<List<CardBean>>(emptyList())
78+
override val opponentGraveyardCardList: StateFlow<List<CardBean>>
79+
get() = _opponentGraveyardCardList
80+
6281
/**
6382
* 所有卡牌
6483
*/
@@ -73,21 +92,7 @@ class DeckCardObserverImpl @Inject constructor(
7392
* 当前卡组剩余的卡牌
7493
*/
7594
private var deckLeftCardList: List<CardBean> = listOf()
76-
set(value) {
77-
// "设置了剩余卡牌 ${
78-
// value.map {
79-
// it.count
80-
// }.reduce { acc, i ->
81-
// acc + i
82-
// }
83-
// }".log()
84-
var count = 0
85-
value.forEach {
86-
count += it.count
87-
}
88-
"设置了剩余卡牌 $count".log()
89-
field = value
90-
}
95+
9196

9297
/**
9398
* 获取炉石log文件夹
@@ -152,21 +157,21 @@ class DeckCardObserverImpl @Inject constructor(
152157
scope.launch {
153158
powerTagHandler.gameEventFlow.collect {
154159
when (it) {
160+
null -> {
155161

162+
}
156163

157164
is GameEvent.OnGameOver -> {
158165

166+
_userGraveyardCardList.value = emptyList()
167+
_opponentGraveyardCardList.value = emptyList()
159168

160169
clearPowerLogFile()
161-
"清空卡牌 OnGameOver ,deckLeftCardList ${deckLeftCardList.size} , currentDeckList ${currentDeckList.size} , _deckCardList = ${_deckCardList.value.size}".log()
162170

163-
// deckLeftCardList.clear()
164-
// deckLeftCardList.addAll(currentDeckList)
165171
deckLeftCardList = currentDeckList.toList()
166172
_deckCardList.value = deckLeftCardList.toList()
167173
// _deckCardList.send(deckLeftCardList)
168174

169-
"清空卡牌 OnGameOver ,deckLeftCardList ${deckLeftCardList.size} , currentDeckList ${currentDeckList.size} , _deckCardList = ${_deckCardList.value.size}".log()
170175

171176
it.game.apply {
172177
userDeckCode = currentUserDeck?.code ?: ""
@@ -176,6 +181,9 @@ class DeckCardObserverImpl @Inject constructor(
176181
powerFileObserver.reset()
177182
}
178183
GameEvent.OnGameStart -> {
184+
185+
_userGraveyardCardList.value = emptyList()
186+
_opponentGraveyardCardList.value = emptyList()
179187
// deckLeftCardList = currentDeckList
180188
"清空卡牌 OnGameStart ,deckLeftCardList ${deckLeftCardList.size} , currentDeckList ${currentDeckList.size}".log()
181189
// deckLeftCardList.clear()
@@ -192,8 +200,9 @@ class DeckCardObserverImpl @Inject constructor(
192200
is GameEvent.InsertCardToUserDeck -> {
193201
onUserDeckCardListChanged(it.cardId, false)
194202
}
195-
GameEvent.None -> {
196203

204+
is GameEvent.InsertCardToGraveyard -> {
205+
onGraveyardCardsChanged(it.cardId, it.isUser)
197206
}
198207
}
199208
}
@@ -218,6 +227,34 @@ class DeckCardObserverImpl @Inject constructor(
218227

219228
}
220229

230+
private fun onGraveyardCardsChanged(cardId: String, isUser: Boolean) {
231+
232+
//TAG_CHANGE Entity=[entityName=UNKNOWN ENTITY [cardType=INVALID] id=106 zone=PLAY zonePos=0 cardId= player=1] tag=ZONE value=GRAVEYARD
233+
//TAG_CHANGE Entity=[entityName=UNKNOWN ENTITY [cardType=INVALID] id=5 zone=SECRET zonePos=0 cardId= player=1] tag=COST value=2
234+
//如果对面打出一张奥秘拍 会直接进入墓地
235+
// ?: throw RuntimeException("没有id $entity")
236+
237+
val card = allCards.find {
238+
it.id == cardId
239+
} ?: return
240+
241+
if (card.type == CardType.Enchantment) {
242+
// "衍生牌 $card 不能放到墓地去".log()
243+
return
244+
}
245+
246+
// "插入一张牌到墓地 $card $entity".log()
247+
248+
//TAG_CHANGE Entity=[entityName=破霰元素 id=62 zone=PLAY zonePos=1 cardId=AV_260 player=2] tag=ZONE value=GRAVEYARD
249+
if (isUser) {
250+
_userGraveyardCardList.value += CardBean(card, 1)
251+
} else {
252+
_opponentGraveyardCardList.value += CardBean(card, 1)
253+
}
254+
255+
256+
}
257+
221258
/**
222259
* 清空log文件
223260
*/

module/src/main/java/com/ke/hs_tracker/module/parser/PowerTagHandler.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface PowerTagHandler {
2222
/**
2323
* 游戏事件流
2424
*/
25-
val gameEventFlow: Flow<GameEvent>
25+
val gameEventFlow: Flow<GameEvent?>
2626
}
2727

2828
class PowerTagHandlerImpl @Inject constructor(
@@ -31,9 +31,9 @@ class PowerTagHandlerImpl @Inject constructor(
3131

3232
private val _gameEventFlow =
3333
// Channel<GameEvent>(capacity = Channel.UNLIMITED)
34-
MutableStateFlow<GameEvent>(GameEvent.None)
34+
MutableStateFlow<GameEvent?>(null)
3535

36-
override val gameEventFlow: Flow<GameEvent>
36+
override val gameEventFlow: Flow<GameEvent?>
3737
get() = _gameEventFlow
3838

3939

@@ -227,7 +227,7 @@ class PowerTagHandlerImpl @Inject constructor(
227227
insertCardToDeck(cardId)
228228

229229
} else if (it.currentZone == Zone.Play && it.newZone == Zone.Graveyard) {
230-
// onGraveyardCardsChanged(cardId, it.isUser)
230+
onGraveyardCardsChanged(cardId, it.isUser)
231231
} else if (it.newZone == Zone.Hand || it.currentZone == Zone.Hand) {
232232
//手牌
233233
if (!it.isUser) {
@@ -241,6 +241,13 @@ class PowerTagHandlerImpl @Inject constructor(
241241

242242
}
243243

244+
private fun onGraveyardCardsChanged(cardId: String?, user: Boolean) {
245+
if (cardId == null) {
246+
return
247+
}
248+
_gameEventFlow.value = GameEvent.InsertCardToGraveyard(cardId, user)
249+
}
250+
244251

245252
// private fun findCardById(cardId: String) =
246253
// allCard.find { it.id == cardId } ?: throw RuntimeException("id为 $cardId 没有这张牌")

module/src/main/java/com/ke/hs_tracker/module/service/WindowService.kt

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import android.os.Build
55
import android.os.IBinder
66
import android.view.Gravity
77
import android.view.LayoutInflater
8+
import android.view.View
89
import android.view.ViewGroup.LayoutParams
910
import android.view.WindowManager
10-
import androidx.core.view.isVisible
11+
import android.widget.AdapterView
12+
import android.widget.AdapterView.OnItemSelectedListener
13+
import android.widget.ArrayAdapter
1114
import androidx.lifecycle.LifecycleService
1215
import androidx.lifecycle.lifecycleScope
16+
import com.ke.hs_tracker.module.R
1317
import com.ke.hs_tracker.module.databinding.ModuleFloatingWindowBinding
1418
import com.ke.hs_tracker.module.log
1519
import com.ke.hs_tracker.module.parser.DeckCardObserver
@@ -32,8 +36,11 @@ class WindowService : LifecycleService() {
3236
ModuleFloatingWindowBinding.inflate(layoutInflater)
3337
}
3438

35-
private val adapter = CardAdapter()
39+
private val deckAdapter = CardAdapter()
3640

41+
private val graveyardAdapter = CardAdapter()
42+
43+
private val opponentGraveyardAdapter = CardAdapter()
3744

3845
@Inject
3946
lateinit var deckCardObserver: DeckCardObserver
@@ -58,17 +65,50 @@ class WindowService : LifecycleService() {
5865

5966
windowManager.addView(binding.root, layoutParams)
6067

61-
binding.recyclerView.adapter = adapter
68+
binding.recyclerView.adapter = deckAdapter
6269

63-
binding.zoom.setOnClickListener {
64-
binding.recyclerView.isVisible = !binding.recyclerView.isVisible
65-
}
70+
// binding.zoom.setOnClickListener {
71+
// binding.recyclerView.isVisible = !binding.recyclerView.isVisible
72+
// }
6673

6774
binding.close.setOnClickListener {
6875
windowManager.removeView(binding.root)
6976
stopSelf()
7077
}
7178

79+
binding.spinner.adapter = ArrayAdapter.createFromResource(
80+
applicationContext,
81+
R.array.module_spinner,
82+
android.R.layout.simple_list_item_1
83+
)
84+
binding.spinner.onItemSelectedListener = object : OnItemSelectedListener {
85+
override fun onItemSelected(
86+
parent: AdapterView<*>,
87+
view: View,
88+
position: Int,
89+
id: Long
90+
) {
91+
when (position) {
92+
0 -> {
93+
binding.recyclerView.adapter = deckAdapter
94+
}
95+
1 -> {
96+
binding.recyclerView.adapter = graveyardAdapter
97+
}
98+
2 -> {
99+
binding.recyclerView.adapter = opponentGraveyardAdapter
100+
}
101+
}
102+
}
103+
104+
override fun onNothingSelected(parent: AdapterView<*>?) {
105+
106+
}
107+
108+
}
109+
110+
binding.spinner.setSelection(0)
111+
72112
binding.root.setOnTouchListener(
73113
ItemViewTouchListener(
74114
layoutParams,
@@ -89,10 +129,21 @@ class WindowService : LifecycleService() {
89129
lifecycleScope.launch {
90130
deckCardObserver.deckCardList.collect {
91131
// adapter.setList(it)
92-
adapter.setDiffNewData(it.toMutableList())
132+
deckAdapter.setDiffNewData(it.toMutableList())
93133
}
94134
}
95135

136+
lifecycleScope.launch {
137+
deckCardObserver.userGraveyardCardList.collect {
138+
graveyardAdapter.setDiffNewData(it.toMutableList())
139+
}
140+
}
141+
142+
lifecycleScope.launch {
143+
deckCardObserver.opponentGraveyardCardList.collect {
144+
opponentGraveyardAdapter.setDiffNewData(it.toMutableList())
145+
}
146+
}
96147

97148
}
98149

module/src/main/res/layout/module_floating_window.xml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:background="#33000000"
78
android:orientation="vertical">
89

910

@@ -19,32 +20,41 @@
1920
app:layout_constraintTop_toTopOf="parent" />
2021

2122
<ImageView
22-
app:layout_constraintStart_toStartOf="parent"
23-
app:layout_constraintTop_toBottomOf="@id/header"
2423
android:id="@+id/zoom"
2524
android:layout_width="wrap_content"
2625
android:layout_height="wrap_content"
2726
android:contentDescription="@null"
2827
android:padding="8dp"
29-
android:src="@drawable/module_baseline_zoom_out_map_white_24dp" />
28+
android:src="@drawable/module_baseline_zoom_out_map_white_24dp"
29+
app:layout_constraintStart_toStartOf="parent"
30+
app:layout_constraintTop_toBottomOf="@id/header" />
3031

3132
<ImageView
3233
android:id="@+id/close"
3334
android:layout_width="wrap_content"
3435
android:layout_height="wrap_content"
3536
android:contentDescription="@null"
3637
android:padding="8dp"
38+
android:src="@drawable/module_baseline_clear_red_500_24dp"
3739
app:layout_constraintStart_toEndOf="@id/zoom"
38-
app:layout_constraintTop_toTopOf="@id/zoom"
39-
android:src="@drawable/module_baseline_clear_red_500_24dp" />
40+
app:layout_constraintTop_toTopOf="@id/zoom" />
41+
42+
<Spinner
43+
android:id="@+id/spinner"
44+
android:layout_width="50dp"
45+
android:layout_height="wrap_content"
46+
android:spinnerMode="dropdown"
47+
app:layout_constraintBottom_toBottomOf="@id/close"
48+
app:layout_constraintEnd_toEndOf="parent"
49+
app:layout_constraintTop_toTopOf="@id/close" />
4050

4151

4252
<androidx.recyclerview.widget.RecyclerView
4353
android:id="@+id/recycler_view"
4454
android:layout_width="match_parent"
4555
android:layout_height="wrap_content"
46-
app:layout_constraintTop_toBottomOf="@id/zoom"
4756
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
57+
app:layout_constraintTop_toBottomOf="@id/zoom"
4858
tools:listitem="@layout/module_item_card" />
4959

5060
</androidx.constraintlayout.widget.ConstraintLayout>

module/src/main/res/values/arrays.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
<item>时间正序</item>
88
<item>时间倒序</item>
99
</string-array>
10+
11+
<string-array name="module_spinner">
12+
<item>@string/module_deck</item>
13+
<item>@string/module_graveyard</item>
14+
<item>@string/module_opponent_graveyard</item>
15+
16+
</string-array>
1017
</resources>

0 commit comments

Comments
 (0)