Skip to content

Commit

Permalink
typo
Browse files Browse the repository at this point in the history
  • Loading branch information
kleidis committed Oct 29, 2024
1 parent a0a5c27 commit a2dc49c
Showing 1 changed file with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class NetPlayDialog(context: Context) : BaseSheetDialog(context) {
binding.listMultiplayer.layoutManager = LinearLayoutManager(context)
binding.listMultiplayer.adapter = adapter
adapter.loadMultiplayerMenu()

binding.btnLeave.setOnClickListener {
NetPlayManager.netPlayLeaveRoom()
dismiss()
}
} else {
val binding = DialogMultiplayerInitialBinding.inflate(layoutInflater)
setContentView(binding.root)
Expand Down Expand Up @@ -62,10 +67,13 @@ class NetPlayDialog(context: Context) : BaseSheetDialog(context) {
const val MULTIPLAYER_JOIN_ROOM = 2
const val MULTIPLAYER_ROOM_MEMBER = 3
const val MULTIPLAYER_EXIT_ROOM = 4
const val MULTIPLAYER_SEPARATOR = 5
const val MULTIPLAYER_ROOM_COUNT = 6

// view type
const val TYPE_BUTTON = 0
const val TYPE_TEXT = 1
const val TYPE_SEPARATOR = 2
}
}

Expand Down Expand Up @@ -100,7 +108,18 @@ class NetPlayDialog(context: Context) : BaseSheetDialog(context) {

override fun bind(item: NetPlayItems) {
netPlayItem = item
binding.itemTextNetplayName.text = netPlayItem.name
binding.itemTextNetplayName.text = item.name
binding.itemIcon.apply {
val iconRes = when (item.option) {
NetPlayItems.MULTIPLAYER_ROOM_TEXT -> R.drawable.ic_system
NetPlayItems.MULTIPLAYER_ROOM_COUNT -> R.drawable.ic_joined
else -> 0
}
visibility = if (iconRes != 0) {
setImageResource(iconRes)
View.VISIBLE
} else View.GONE
}
}
}

Expand Down Expand Up @@ -137,31 +156,47 @@ class NetPlayDialog(context: Context) : BaseSheetDialog(context) {
val infos = NetPlayManager.netPlayRoomInfo()

if (infos.isNotEmpty()) {
val roomTitle = context.getString(R.string.multiplayer_room_title, infos[0])
netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_ROOM_TEXT, roomTitle, NetPlayItems.TYPE_TEXT))
val roomInfo = infos[0].split("|")
val roomName = roomInfo[0]
val maxPlayers = roomInfo[1].toInt()

netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_ROOM_TEXT, roomName, NetPlayItems.TYPE_TEXT))

netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_ROOM_COUNT,
"${infos.size - 1}/$maxPlayers", NetPlayItems.TYPE_TEXT))

netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_SEPARATOR, "", NetPlayItems.TYPE_SEPARATOR))

for (i in 1 until infos.size) {
netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_ROOM_MEMBER, infos[i], NetPlayItems.TYPE_TEXT))
netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_ROOM_MEMBER,
infos[i], NetPlayItems.TYPE_BUTTON))
}
netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_EXIT_ROOM, context.getString(R.string.multiplayer_exit_room), NetPlayItems.TYPE_TEXT))
} else {
val consoleTitle = context.getString(R.string.multiplayer_console_id, NetPlayManager.netPlayGetConsoleId())
netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_ROOM_TEXT, consoleTitle, NetPlayItems.TYPE_TEXT))
netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_CREATE_ROOM, context.getString(R.string.multiplayer_create_room), NetPlayItems.TYPE_TEXT))
netPlayItems.add(NetPlayItems(NetPlayItems.MULTIPLAYER_JOIN_ROOM, context.getString(R.string.multiplayer_join_room), NetPlayItems.TYPE_TEXT))
}
}

fun refresh() {
netPlayItems.clear()
loadMultiplayerMenu()
notifyDataSetChanged()
}

override fun getItemViewType(position: Int): Int {
return netPlayItems[position].type
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NetPlayViewHolder {
val inflater = LayoutInflater.from(parent.context)
val textBinding = ItemTextNetplayBinding.inflate(inflater, parent, false)
val buttonBinding = ItemButtonNetplayBinding.inflate(inflater, parent, false)
return when (viewType) {
NetPlayItems.TYPE_TEXT -> TextNetPlayViewHolder(textBinding)
NetPlayItems.TYPE_BUTTON -> ButtonNetPlayViewHolder(buttonBinding)
NetPlayItems.TYPE_TEXT -> TextNetPlayViewHolder(
ItemTextNetplayBinding.inflate(inflater, parent, false))
NetPlayItems.TYPE_BUTTON -> ButtonNetPlayViewHolder(
ItemButtonNetplayBinding.inflate(inflater, parent, false))
NetPlayItems.TYPE_SEPARATOR -> object : NetPlayViewHolder(
inflater.inflate(R.layout.item_separator_netplay, parent, false)
) {
override fun bind(item: NetPlayItems) {}
override fun onClick(clicked: View) {}
}
else -> throw IllegalStateException("Unsupported view type")
}
}
Expand Down Expand Up @@ -194,6 +229,8 @@ class NetPlayDialog(context: Context) : BaseSheetDialog(context) {

binding.maxPlayersContainer.visibility = if (isCreateRoom) View.VISIBLE else View.GONE

binding.maxPlayersLabel.text = context.getString(R.string.multiplayer_max_players_value, binding.maxPlayers.value.toInt())

binding.maxPlayers.addOnChangeListener { _, value, _ ->
binding.maxPlayersLabel.text = context.getString(R.string.multiplayer_max_players_value, value.toInt())
}
Expand Down

0 comments on commit a2dc49c

Please sign in to comment.