Showing posts with label UI. Show all posts
Showing posts with label UI. Show all posts

Friday, May 4, 2018

ProductiveGame 2 Trees Update #1

Making a tooltip implementation has been on my todo list for years, for multiple project.  I finally buckled down and made one for ProducteGame 2 - Trees.

It's not perfect, but it works pretty well.   It took much longer to get working right than I had anticipated.  There were many hurdles I didn't expect.  There is one panel prefab, with a text object, and a content size fitter, and a horizontal layout group.  It also has a script that makes the prefab instance a public static.  Another script attached to the other ui objects, sets the initial position of the tooltip based upon the center of it's parent.  Then it waits for half a second.  If the cursor is still within the parent object,  it enables the tooltip.  If the tooltip edges are within the game window, it stays in the same position.  If the tooltip edges are outside the game window it repositions the tooltip and saves the new position to be reused.  Whenever the cursor leaves the parent UI object, the tooltip disables.

Multiline text is kind of hacky, but it works.  The text is assigned in the inspector, and in the Windows Unity Editor, "\n" for new line doesn't work when it is typed in the editor for some reason.  So instead I use "\\n" with some code that replaces the text in the string, at runtime.  Like this:
tooltipText = tooltipText.Replace("\\n", "\n");

Because the code finds the tooltip position based upon its size, and its size is being driven by the  unity ui(content size fitter and horizontal layout group), the code has to wait until the end of the frame to find the position.  This causes the tooltip to sort of pop in to place, which is noticeable.  However, the code stores the position, so this only happens when the game first starts, or when the window is resized.  There might be a way I could calculate if the tooltip will fall outside the window beforehand, but I don't know how to do that, and the pop-in isn't very noticeable since it only happens once after a resize, or at start.

ChangeLog:
04/21
0.008
Added Hover over text.
Messed around with font sizes for the header, to try to make things a little more compact and a little more uniform

Monday, April 16, 2018

ProductiveGame 2 Trees

I've started working on a new project. I've been using the Forest APP to help me stay focused, and to help me start working when I'm not really feeling it. Mostly it's just a timer, that I use like a pomodoro timer. However, when I'm working on the pc, I'd rather just not mess with my phone at all. Luckily there is a chrome extension. However the chrome extension has no audible alert when it finishes. I also wanted to show people on my steam friends list that I was working in the Unity game engine. However, after adding Unity as non-steam game and starting Unity through steam, steam seemed to think Unity was still open even after it was shut down. It was all a hassle. So I decided to create my own rudimentary version of the forest app with Unity. Thus "ProductiveGame 2 - Trees" was born.

Screenshot of Version 0.001:
 

(A gif of the latest build is at the bottom of this post)

I use it like a Pomodoro tracker.  So for each 25 minute increment, the Trees Planted number increases.  I have also added a tree count for the current session, and I create a new session at the start of each work day.  There is a history of those sessions as well so I can compare how many "trees" I created for each session, and when I created them.  An audio alert sounds when the timer has finished, and a volume slider lets me set the volume of the alert.  The sound I'm using is the "PointScore" sound from Pongball, created by Kyle Wynn.  I added the productive game to my steam, and launch it from steam so all my steam friends can see it.

 I've been developing it organically, with the target audience as myself, and adding features that I felt would be most useful to me.

I plan on releasing it to the public (soon?), but some work needs to be done to get it ready.  Specifically, the current version has very basic syncing with Habitica.com that is hard-coded for my API UID and Token and I need to create a login screen to handles that elegantly.

The current changelog is listed below:
03/23
Version 0.001
Initial version.
Basic clone of Forest App.
Working Timer,  image of tree does nothing,  type in number of minutes and click start to start timer.  Previous time is saved, so typing in time is unnecessary if time is correct.  Sound when timer finishes.  Volume control via Control Panel/Button represented by gear image.  Previous volume is saved.
I had to switch from Unity 2017.4.0f1 LTS to 2018.0b12 because, in Windows 10, there was a bug with the resize icon

03/25
Version 0.002
Added break timer and pause.  Break timer starts automatic 5 minute timer.  Tree count does not increase.  Press start a second time to pause.

03/28
0.003
Added "Current Session" count, Next Session button that resets Current Session, and adds Current Session Count to history of Previous Sessions.
Added History Panel and button to show list of Previous Session counts.  Still need scroll bar for when list gets longer than the panel can show.

04/03
0.004
Added date array to keep track of the date each Session was created, and added that information to History Panel
Added FPS limiter for 30 fps.  Should reduce CPU usage

04/04
0.005
Added simple Habitica.com integration.
Added script that handles scoring a Habitica habit when a tree is completed.
If the habit does not exist, the habit is created.
Attempted to use built-in json and webrequest from unity.  Had some difficulties.
JsonUtility does not handle nested objects, which prevented the processing of some JSON data.  Particularly getting the api user id and token by using the login username and password.
The API uid and token are currently hard coded.
REST POST is working, but it required a workaround use a custom UploadHandler, as UnityWebRequest applies URL encoding to POST message payloads, which mangles the JSON.

04/04
0.006
Added plus and minus buttons to adjust the number of trees.  Added so I could adjust the tree count when I forget to click "next" at the beginning of a new sessions.
adjustment buttons do not UpScore Habitica
Adjusted the inputfield so that it clears at the end of an edit.

04/16
0.007
Added a rudimentary tree scene
clicking the tree on the timer screen will change to it, but the tree can only be clicked when the timer is not active.
If you have paused the timer, your current time will be lost.

Tuesday, October 13, 2015

Dev Update # 12: Pausing Audio, UI Elements Correctly Scaling


I've decided to add  more pictures and more technical information into my dev updates.  I've also decided to do a write up on my progress/lack thereof immediately after I've made the progress/lack thereof.  Instead of making a lot of dev updates, I will add to them until I feel like I have enough material before posting.

10/12/2015 I found a way to pause and play the music in the game, using "AudioListener.pause" instead of turning on and off the SoundManager object. One benefit to this, is that the music will begin playing where it left off instead of restarting every time. Also, Unity can't find an object when it's not active, and this is why the sound breaks using my current "reset game" code. One downside the AudioListener pauses all of the audio including the music and sound effects. Apparently can "set the ignoreListenerPause property" to true for sound effects, to prevent this, but I'm not entirely sure how to do this yet. A snippet of my code is below. This is the body of a function I have that runs when the music button is pressed, or the "M" button is pressed.
if (AudioListener.pause == false)
        { AudioListener.pause = true; }
        else
        { AudioListener.pause = false; }

10/13/2015  I readjusted some of the UI elements that weren't scaling with everything else, so they would scale correctly.  I changed the anchors to top horizontal stretch(not sure if the top part is important, but I know that adding vertical stretch will generally break everything. see Image 1).  Anchors and pivots with the new UI system are a bit confusing.  I think maybe I'm starting to understand them a little.

I was having trouble getting the left and right panels to scale with the game board in the middle.  I created a panel that mimics the game board, to make it easier.  The game board is always square, 1x1, so as the window scales the game board gets bigger or smaller in the middle.  Initially, the left and right panels stayed the same width, because there was no width scaling which would create large black areas on the left and right of the game board(see image 2), or the panels would overlap the game board.  Every time I changed the anchors, the panels would scale, but they would scale incorrectly.

To fix this, after a LOT of trial and error, I set the inside anchors to the middle of the screen.  Don't ask me why this works or how I thought of trying it.  I have a very vague idea, but I couldn't explain it.
Success!!! UI Elements scale correctly.

Image 1: vertical scaling breaking UI elements, before I fixed it

Image 2: Gaps between Game Board and Panels