Spaces:
Running
Running
Refactor UI and enhance styling for score panel
Browse filesUpdated the version to 0.1.12. Added new CSS classes `.bold-text` and `.blue-background` for improved text and background styling. Modified `.shiny-border` to adjust padding and border-radius for a more polished appearance.
Refactored `_render_score_panel` to replace the `st.expander`-based layout with an HTML-based table, introducing independent column backgrounds, visible gaps, and a new "extra points" calculation. Added a total row with enhanced styling.
Reorganized `run_app` for better layout structure and removed redundant state assignment.
- README.md +5 -0
- battlewords/__init__.py +1 -1
- battlewords/ui.py +48 -22
README.md
CHANGED
|
@@ -104,6 +104,11 @@ docker run -p 8501:8501 battlewords
|
|
| 104 |
4. **The game ends when all six words are found or all word letters are revealed. Your score tier is displayed.**
|
| 105 |
|
| 106 |
## Changelog
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
- 0.1.11
|
| 108 |
- Added game-ending condition: the game now ends when all six words are guessed or all word letters are revealed.
|
| 109 |
- implemented word spacing logic to prevent adjacent partial words and allow for future enhancements like overlaps.
|
|
|
|
| 104 |
4. **The game ends when all six words are found or all word letters are revealed. Your score tier is displayed.**
|
| 105 |
|
| 106 |
## Changelog
|
| 107 |
+
- 0.1.12
|
| 108 |
+
- Updated the version to 0.1.12. Added new CSS classes `.bold-text` and `.blue-background` for improved text and background styling. Modified `.shiny-border` to adjust padding and border-radius for a more polished appearance.
|
| 109 |
+
- Refactored `_render_score_panel` to replace the `st.expander`-based layout with an HTML-based table, introducing independent column backgrounds, visible gaps, and a new "extra points" calculation. Added a total row with enhanced styling.
|
| 110 |
+
- Reorganized `run_app` for better layout structure and removed redundant state assignment.
|
| 111 |
+
|
| 112 |
- 0.1.11
|
| 113 |
- Added game-ending condition: the game now ends when all six words are guessed or all word letters are revealed.
|
| 114 |
- implemented word spacing logic to prevent adjacent partial words and allow for future enhancements like overlaps.
|
battlewords/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
__version__ = "0.1.
|
| 2 |
__all__ = ["models", "generator", "logic", "ui"]
|
|
|
|
| 1 |
+
__version__ = "0.1.12"
|
| 2 |
__all__ = ["models", "generator", "logic", "ui"]
|
battlewords/ui.py
CHANGED
|
@@ -230,6 +230,13 @@ def inject_styles() -> None:
|
|
| 230 |
}
|
| 231 |
}
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
.metal-border {
|
| 234 |
position: relative;
|
| 235 |
padding: 20px;
|
|
@@ -242,10 +249,10 @@ def inject_styles() -> None:
|
|
| 242 |
|
| 243 |
.shiny-border {
|
| 244 |
position: relative;
|
| 245 |
-
padding:
|
| 246 |
background: #333;
|
| 247 |
color: white;
|
| 248 |
-
border-radius:
|
| 249 |
overflow: hidden;
|
| 250 |
}
|
| 251 |
|
|
@@ -835,22 +842,42 @@ def _render_score_panel(state: GameState):
|
|
| 835 |
if is_game_over(state):
|
| 836 |
_render_game_over(state)
|
| 837 |
else:
|
| 838 |
-
with
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 854 |
|
| 855 |
|
| 856 |
def _render_game_over(state: GameState):
|
|
@@ -915,10 +942,6 @@ def run_app():
|
|
| 915 |
# Anchor to target the main two-column layout for mobile reversal
|
| 916 |
st.markdown('<div id="bw-main-anchor"></div>', unsafe_allow_html=True)
|
| 917 |
left, right = st.columns([2, 2], gap="medium")
|
| 918 |
-
with left:
|
| 919 |
-
_render_grid(state, st.session_state.letter_map, show_grid_ticks=st.session_state.get("show_grid_ticks", True))
|
| 920 |
-
st.button("New Game", width=125, on_click=_new_game, key="new_game_btn")
|
| 921 |
-
|
| 922 |
with right:
|
| 923 |
_render_radar(state.puzzle, size=state.grid_size, r_max=0.8, max_frames=25, sinusoid_expand=True, stagger_radar=False, show_ticks=st.session_state.get("show_grid_ticks", False))
|
| 924 |
one, two = st.columns([1, 3], gap="medium")
|
|
@@ -929,6 +952,9 @@ def run_app():
|
|
| 929 |
_render_guess_form(state)
|
| 930 |
#st.divider()
|
| 931 |
_render_score_panel(state)
|
|
|
|
|
|
|
|
|
|
| 932 |
|
| 933 |
|
| 934 |
# End condition
|
|
|
|
| 230 |
}
|
| 231 |
}
|
| 232 |
|
| 233 |
+
.bold-text {
|
| 234 |
+
font-weight: 700;
|
| 235 |
+
}
|
| 236 |
+
.blue-background {
|
| 237 |
+
background:#1d64c8;
|
| 238 |
+
opacity:0.9;
|
| 239 |
+
}
|
| 240 |
.metal-border {
|
| 241 |
position: relative;
|
| 242 |
padding: 20px;
|
|
|
|
| 249 |
|
| 250 |
.shiny-border {
|
| 251 |
position: relative;
|
| 252 |
+
padding: 12px;
|
| 253 |
background: #333;
|
| 254 |
color: white;
|
| 255 |
+
border-radius: 1.25rem;
|
| 256 |
overflow: hidden;
|
| 257 |
}
|
| 258 |
|
|
|
|
| 842 |
if is_game_over(state):
|
| 843 |
_render_game_over(state)
|
| 844 |
else:
|
| 845 |
+
# Build a simple table with independent column backgrounds and visible gaps
|
| 846 |
+
rows_html = []
|
| 847 |
+
# Header row
|
| 848 |
+
header_html = (
|
| 849 |
+
"<tr>"
|
| 850 |
+
"<th class=\"blue-background bold-text\">Word</th>"
|
| 851 |
+
"<th class=\"blue-background bold-text\">Letters</th>"
|
| 852 |
+
"<th class=\"blue-background bold-text\">Extra</th>"
|
| 853 |
+
"</tr>"
|
| 854 |
+
)
|
| 855 |
+
rows_html.append(header_html)
|
| 856 |
+
|
| 857 |
+
for w in state.puzzle.words:
|
| 858 |
+
pts = state.points_by_word.get(w.text, 0)
|
| 859 |
+
if pts > 0 or state.game_mode == "too easy":
|
| 860 |
+
word_display = w.text
|
| 861 |
+
letters_display = len(w.text)
|
| 862 |
+
# Extra = total points for the word minus its length (bonus earned)
|
| 863 |
+
extra_pts = max(0, pts - letters_display)
|
| 864 |
+
row_html = (
|
| 865 |
+
"<tr>"
|
| 866 |
+
f"<td class=\"blue-background \">{word_display}</td>"
|
| 867 |
+
f"<td class=\"blue-background \">{letters_display}</td>"
|
| 868 |
+
f"<td class=\"blue-background \">{extra_pts}</td>"
|
| 869 |
+
"</tr>"
|
| 870 |
+
)
|
| 871 |
+
rows_html.append(row_html)
|
| 872 |
+
total_row_html = (f"<tr class=\"blue-background\"><td colspan='3'><h3 class=\"bold-text\">Total: {state.score}</h3></td></tr>")
|
| 873 |
+
rows_html.append(total_row_html)
|
| 874 |
+
table_html = (
|
| 875 |
+
"<table class='shiny-border' style=\"background: linear-gradient(-45deg, #a1a1a1, #ffffff, #a1a1a1, #666666); width:100%; margin: 0 auto;border-collapse:separate; border-spacing:0;\">"
|
| 876 |
+
f"{''.join(rows_html)}"
|
| 877 |
+
"</table>"
|
| 878 |
+
)
|
| 879 |
+
st.markdown(table_html, unsafe_allow_html=True)
|
| 880 |
+
|
| 881 |
|
| 882 |
|
| 883 |
def _render_game_over(state: GameState):
|
|
|
|
| 942 |
# Anchor to target the main two-column layout for mobile reversal
|
| 943 |
st.markdown('<div id="bw-main-anchor"></div>', unsafe_allow_html=True)
|
| 944 |
left, right = st.columns([2, 2], gap="medium")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 945 |
with right:
|
| 946 |
_render_radar(state.puzzle, size=state.grid_size, r_max=0.8, max_frames=25, sinusoid_expand=True, stagger_radar=False, show_ticks=st.session_state.get("show_grid_ticks", False))
|
| 947 |
one, two = st.columns([1, 3], gap="medium")
|
|
|
|
| 952 |
_render_guess_form(state)
|
| 953 |
#st.divider()
|
| 954 |
_render_score_panel(state)
|
| 955 |
+
with left:
|
| 956 |
+
_render_grid(state, st.session_state.letter_map, show_grid_ticks=st.session_state.get("show_grid_ticks", True))
|
| 957 |
+
st.button("New Game", width=125, on_click=_new_game, key="new_game_btn")
|
| 958 |
|
| 959 |
|
| 960 |
# End condition
|