I can’t find any tutorial about this, which surprises me, but here I am. I’m trying to create a Combat Log like those one can see in some turn-based combat games, showing the dice rolls and such. For some reason the only example I can think about is Blood Bowl 2, but I know I’ve seen this elsewhere too. Maybe in Baldur’s Gate, Pillars of Eternity and the likes.
I’ve been trying on my own and did not really manage to get what I want. I can have one line display what I want but not two and making them move on the UI is a whole other story (like, when a line is set it moves one row up to make room for the next line).
Of course I’m not asking people to solve this for me, but if anyone knows a tutorial or has some piece of knowledge that can send me in the right direction, that would be much appreciated.
Ok, maybe that’s why I can’t find anything about this. So here is what I am talking about.
In games where players have a lot of dice rolls to do (in RPGs for example), there is a part of the screen showing the results of these rolls. For example if one is attacking with a bow, the roll is going to look like “accuracy (10) + rolled d6 (3) = 10 + 3 = 13 = passed”. I’m making stuff up, but I hope you get the idea. And this is what would be displayed in a part of the screen that I call “combat log” because it seemed appropriate, but maybe that’s not the right term.
And every action requiring a dice roll is sort of printed in that area, pushing the previous lines up or down, and when one entry is pushed one too many times it just disappears.
yes, now is clear!
Here what you need to have a widget that shows , 10 text , how you set the text to change and “move upward”
Create a widget, with inside a scroll box with lets say 10 text.
Create 10 variable string in the widget andd bind them to the text. (You can use an array too)
Create 2 custom event in the widget
1 for setting the text using the “append” with variable and text, so like “Playername” “Action” makes a damage of “VariableDamage”
1 for shift all the string variables ,
lets say your upper Text is binded to String0 and the lower to string10
you want to use a loop to set the string0 like string 1, and string 1 like string 2… and string 10 is the new string you want to set .
Now use your character or whatever to create the widget in runtime and add it to the viewport of your player, (surely player0)
we’ll need 2 widgets for this: 1 representing the log itself (wCombatLog) and 1 representing a line of text (wLogLine)
the *wLogLine *has a Text Block bound text variable (Log Line Text), it’s Instance Editable & Exposed on Spawn - so it shows up when the line widget is created, as seen below. It’s used to feed data to the wLogLine
the *wCombatLog *has a scroll box to which it adds *wLogLines *via a custom event:
The player creates the *wCombatLog *and uses the reference to call the custom event inside it; here sending info about what we collided with and the keypresses. (you will surely have a plethora of events that may want to add to the log)
I’ll just add that while the above might be OK for prototyping and testing stuff, if you really want something proper, do look into List View - a more elegant & efficient way to handle hundreds / thousands of widgets.
Haha, agreed! The upfront cost of wrapping one’s mind around it is quite something indeed. Made my head spin when I was setting it up for the first time.
No problem, if you want to experiment with the List View instead:
create an Object class blueprint in the content browser with an exposed text variable - it will be used to store data in the list view, called Entry Data below.
once you have it, you can do this in the wLogLine’s class settings:
The Implemented Interfaces bit on the left is the critical part here! It allows you to pull the data from a list view object and assign it to the widget’s variable. The wCombatLog’s List View widget below will then need its Entry Widget Class set to the above-mentioned wLogLine:
From now on, the List View handles the lifespan of the widgets it creates. Even though I have 200+ entries here (after mashing the spacebar like a madman)…
… the list view displays 12 widgets and holds around 20 active at a time. So, having a potentially huge list is not that much of a hindrance and / or performance hog. Not sure about the memory footprint but it should be be lower providing the widget lines are complex enough.
Well, it did it! I went directly for the list view combined with a scroll box, and it works very well. I still need to iron out some issues regarding the text display and to explore the various options a bit more, but that is excellent, so thank you guys again!